コード例 #1
0
ファイル: histos.py プロジェクト: saramuel/PhD
def histo1D(tF, histn, title, log, rleft=0, rright=0, xlabel='log10(r) [m]', ylabel='#N', rfac=1):
    f = TFile(tF)
    histoAll1D=f.Get(histn)
    h, redges = ToNumpy(histoAll1D)
    h, redges = binReduce1D(h, redges, rfac)
    if rright-rleft == 0:       #no bounds set
       plt.xlim(min(redges), max(redges))
    else:                       #bounds set
       plt.xlim(min(rleft), max(rright))
    if log=="log":
        plt.xlabel('log10(r) [m]')
        plt.ylabel('#N')
    else:    
        plt.xlabel('r [m]')
        plt.ylabel('dN/rdr')
    plt.title(title)
    plot_hist(redges,h)          #pyik!
    #plt.semilogy(nonposy="clip")
    #bins = 0.5*(redges[1:] + redges[:-1])
    #plt.plot(bins, h)           #smooth
    #plt.show()   
    ### Resolution ###
    binsiz = np.zeros(redges.size-1)
    for i in xrange(binsiz.size):
        binsiz[i] = 10**redges[i+1]-10**redges[i]
コード例 #2
0
ファイル: angleHistos.py プロジェクト: saramuel/PhD
    def histoLat(self,hname,ax,b=None):  
        #todo ueberlegen was man hier braucht! 
        if b is None: b = self
        xmin, xmax = ax.get_xlim()
        msk = (xmin<self.xedges[:-1])*(self.xedges[:-1]<xmax)
        ws = self.means[hname]/self.lb.area(hname) #density       
        v=ws[msk]
        vsort = sorted(v) 
        for i in np.arange(len(vsort)):
          if (vsort[i]>0):
            vmin = vsort[i]
            break
        vmax = v.max()
        if (self.par in ['r','L','E']):
          vmax = vmax*10.
          vmin = vmin*0.1
        if (vmin <= self.ymin and vmin>0):
          self.ymin = vmin
        if (vmax >= self.ymax):
          self.ymax = vmax

        #labels
        lb = r"$r/\mathrm{m}$ = "+self.lb.labels(hname)[0] #murks, wie geht das richtig???
        #plotting
        plot_hist(xedges=self.xedges,ws=ws,axes=ax,label=lb) 
コード例 #3
0
ファイル: histos.py プロジェクト: saramuel/PhD
    def histoLat(self,hname,ax,b=None):  
        if b is None: b = self
        if (self.par in ['r','L','E','LM']): #todo also for M?
          xmin, xmax = ax.get_xlim()
          msk = (xmin<self.xedges[:-1])*(self.xedges[:-1]<xmax)
          if (self.par in ['r','L','LM']):
            ws = self.means[hname]/self.area           #density
          elif (self.par == 'E'):
            ws = self.means[hname]/self.lb.area(hname) #density       
          v=ws[msk]
          vsort = sorted(v) 
          for i in np.arange(len(vsort)):
            if (vsort[i]>0):
              vmin = vsort[i]
              break
          vmax = v.max()
          if (self.par in ['r','L','E']):
            vmax = vmax*10.
            vmin = vmin*0.1
          if (vmin <= self.ymin and vmin>0):
            self.ymin = vmin
          if (vmax >= self.ymax):
            self.ymax = vmax

        ### color code for plotting ###
        if (self.par in ['X','L','M','LM']): 
          if (self.primary=='proton'):
            c='c'
          elif (self.primary=='carbon'):
            c='r'
          elif (self.primary=='iron'):
            c='b'
          elif (self.primary=='helium'):
            c='m'
          elif (self.primary=='nitrogen'):
            c='y'
          elif (self.primary=='silicon'):
            c='g'
        ### Plot X ###
        if (self.par == 'X'):
          points = (np.vstack((self.xMax[hname],np.log10(self.hSum[hname])))).T
          innerpoints, hullpoints = Quantile(points,.684)
          hullpoints = np.vstack((hullpoints, hullpoints[0]))
          #f2 = interp1d(x, y, kind='cubic')
          ax.plot(hullpoints[:,0], hullpoints[:,1], 'k-', c=c)
          ax.scatter(points[:,0], points[:,1], marker='o', c=c,alpha=0.5, lw=0, s=6)
          ax.scatter(hullpoints[:,0], hullpoints[:,1], marker='o', c=c, lw=0, s=6, label=self.primary)
          ax.scatter(innerpoints[:,0], innerpoints[:,1], marker='o', c=c, lw=0, s=6)

          vy = np.log10(self.hSum[hname])
          vx = self.xMax[hname]
          vysort = sorted(vy) 
          vxsort = sorted(vx) 
          vymax = vy.max()
          vxmax = vx.max()
          for i in np.arange(len(vysort)):
            if (vysort[i]>0):
              vymin = vysort[i]
              break
          for i in np.arange(len(vxsort)):
            if (vxsort[i]>0):
              vxmin = vxsort[i]
              break
          if (self.primary == 'proton'): #hack!!!! does not work with iron 10**20 !
            ymin = vymin
            xmin = vxmin
            ymax = vymax
            xmax = vxmax
          else:  
            ymin, ymax = ax.get_ylim()
            xmin, xmax = ax.get_xlim()
          if (vymin <= ymin and vymin>0):
            ymin = vymin
          if (vxmin <= xmin and vxmin>0):
            xmin = vxmin
          if (vymax >= ymax):
            ymax = vymax
          if (vxmax >= xmax):
            xmax = vxmax
          ax.set_ylim(ymin,ymax)
          ax.set_xlim(xmin,xmax)

        ### Plot r,E,L ###
        else:
          #labels
          if (self.par == 'r'):
            if (self.particle == 'muon'):
              lb = r"$E_{\mu}/\mathrm{GeV} \geq\ $"+self.lb.labels(hname)[0]
            elif (self.particle == 'electron'):
              lb = r"$E_e/\mathrm{MeV} \geq\ $"+self.lb.labels(hname)[0]
            elif (self.particle == 'photon'):
              lb = r"$E_{\gamma}/\mathrm{MeV} \geq\ $"+self.lb.labels(hname)[0]
          elif (self.par == 'E'):
            lb = r"$r/\mathrm{m}$ = "+self.lb.labels(hname)[0] #murks, wie geht das richtig???
          elif (self.par == 'L'): #todo anders loesen???
            if (hname == "histoGa0MeV1D"):
              lb = r'$\gamma$'
            elif (hname == "histoE0MeV1D"):
              lb = r'$e^{\pm}$'
            elif (hname == "histoMu0GeV1D"):
              lb = r'$\mu^{\pm}$'
            elif (hname == "histoRest0GeV1D"):
              lb = 'rest'
          #plotting
          if (self.par == 'L'):
            if (self.rnge=='all'):    #plot e,mu,ga and REST
              cond = (hname != "histoAll1D")
            elif (self.rnge=='zoom'): #only plot e,mu,ga
              cond = (hname != "histoAll1D" and hname != "histoRest0GeV1D")
            if cond:
              xmeans = self.xmeans[hname]
              means  = self.means[hname]/self.area
              stds   = self.stds[hname]/self.area
              if (hname == "histoMu0GeV1D"):
                ax.plot(xmeans,means,label=str(self.primary),lw=0.5,color=c)
              else:
                ax.plot(xmeans,means,lw=0.5,color=c)
              positive = means-stds > 0
              ax.fill_between(xmeans,means-stds,means+stds,where=positive,color=c,alpha=.4)
              if (self.primary == 'proton'):
                #ax.annotate(lb, xy=None, xytext=((self.xmeans[hname])[20],(self.means[hname])[20]+2*(self.stds[hname])[20]), xycoords='data',textcoords='data', arrowprops=None, **kwargs)
                #annotate(lb, xy=((self.xmeans[hname])[20],(self.means[hname])[20]+2*(self.stds[hname])[20]), xytext=None, xycoords='data',textcoords='data', arrowprops=None, **kwargs)
                ax.text(xmeans[75],means[75]+3*stds[75],lb,fontsize=20)
          elif (self.par == 'LM'):
            xmeans = self.xmeans[hname]
            means  = self.means[hname]/self.area
            stds   = self.stds[hname]/self.area
            #set_trace()
            ax.plot(xmeans,means,label=str(self.primary),lw=1,color=c)
            positive = means-stds > 0
            ax.fill_between(xmeans,means-stds,means+stds,where=positive,color=c,alpha=.4)
          elif (self.par == 'M'):
            xmeans1 = self.xmeans[hname]
            means1  = self.means[hname]/self.area
            stds1   = self.stds[hname]/self.area
            xmeans2 = b.xmeans[hname]
            means2  = b.means[hname]/b.area
            stds2   = b.stds[hname]/b.area
            y = (self.means[hname]-b.means[hname])/np.sqrt(self.stds[hname]**2+b.stds[hname]**2)
            #y = (means1-means2)/np.sqrt(stds1**2+stds2**2)
            #print "np.sqrt(stds1**2+stds2**2)", np.sqrt(stds1**2+stds2**2)
            #print "std "+str(self.primary), stds1
            #print "std "+str(b.primary), stds2
            #print "meandiff", means1-means2
            #print str(self.primary), means1 
            #print str(b.primary), means2 
            prims = {'proton': 'p', 'iron': 'Fe', 'helium': 'He', 'nitrogen': 'Ni', 'carbon': 'C', 'silicon': 'Si'}
            lb = prims[self.primary]+" - "+prims[b.primary]
            if (b.primary in ['nitrogen','carbon']): c='c'
            if (b.primary == 'silicon'): c='y'
            ax.plot(xmeans1,y,lw=2,color=c,label=lb)
          else: #i.e. E or r
            plot_hist(xedges=self.xedges,ws=ws,axes=ax,label=lb)