import sys,os sys.path.append('/home/mberger/fopiroot/fopiroot_dev/macro/tpc/FOPI/mberger') pandapath=os.environ.get('PANDAPATH') sys.path.append(pandapath+'/macro/tpc/FOPI/python/argparse-1.2.1') import glob,math,argparse from functions import Divideh,set_palette,setRange,getColors,getColors2 from anaFile import anaFile def writeHist(histos): for hl in histos: for h in hl: h.Write() def drawAngles(c,h,i,col,opt): for j in range(len(h)): c.cd(j+1) h[j][i].SetLineColor(col[i]) h[j][i].Draw(opt) def draw2DAngles(c,i,h): for k in h: for j in range(3): c[k].cd(j+1) c[k].cd(j+1).SetLogz() h[k][j][i].Draw('colz') def drawClSizes(c,graphs,opt): gcounter=-1 for g in graphs: gcounter+=1 c.cd(gcounter*2+1) g['RMS'].Draw(opt) c.cd(gcounter*2+2) g['Mean'].Draw(opt) def sign(x): return(x/abs(x)) def setCanvas(c,d1,d2,leg=None): c.Divide(2,1) c.cd(1).SetPad(0,0,0.8,1) c.cd(1).Divide(d1,d2) c.cd(2).SetPad(0.8,0,1,1) if leg!=None: c.cd(2) leg.Draw() def setGraph(g,title,col=1): #colors=getColors() g.SetTitle(title) g.SetMarkerStyle(20) g.SetMarkerSize(0.5) g.SetMarkerColor(colors[col]) return def fillGraph(hist,graph,fnum=0,mini=[],maxi=[]): nbins=hist.GetNbinsX() projs=[] graph.append({}) graph[-1]['RMS']=ROOT.TGraph() setGraph(graph[-1]['RMS'],'RMS '+hist.GetTitle(),fnum) graph[-1]['Mean']=ROOT.TGraph() setGraph(graph[-1]['Mean'],'Mean '+hist.GetTitle(),fnum) pcounter=0 i=args.binwidth while 1: projs.append(hist.ProjectionY(hist.GetName()+titles[fnum]+'_'+str(i),i-args.binwidth,i)) graph[-1]['RMS'].SetPoint(pcounter,i-args.binwidth+1,projs[-1].GetRMS()) graph[-1]['Mean'].SetPoint(pcounter,i-args.binwidth+1,projs[-1].GetMean()) mini['RMS']=min(mini['RMS'],projs[-1].GetRMS()) maxi['RMS']=max(maxi['RMS'],projs[-1].GetRMS()) mini['Mean']=min(mini['Mean'],projs[-1].GetMean()) maxi['Mean']=max(maxi['Mean'],projs[-1].GetMean()) pcounter+=1 i+=1 if (i>=nbins): break ''' for i in range(args.binwidth,nbins,args.binwidth): projs.append(hist.ProjectionY(hist.GetName()+'_'+str(i),i-args.binwidth,i)) graph[-1]['RMS'].SetPoint(pcounter,i,projs[-1].GetRMS()) graph[-1]['Mean'].SetPoint(pcounter,i,projs[-1].GetMean()) mini['RMS']=min(mini['RMS'],projs[-1].GetRMS()) maxi['RMS']=max(maxi['RMS'],projs[-1].GetRMS()) mini['Mean']=min(mini['Mean'],projs[-1].GetMean()) maxi['Mean']=max(maxi['Mean'],projs[-1].GetMean()) pcounter+=1 ''' return projs def fillClusterSizes(cl,e,phi=-1): #xsize=[cl.pos().X(),cl.pos().X()] #ysize=[cl.pos().Y(),cl.pos().Y()] xsize=[0,99] ysize=[0,99] #zsize=[cl.pos().Z(),cl.pos().Z()] zsize=[0,511] lsize=[0,99]#[cl.pos().Z(),cl.pos().Z()] p1size=[0,99]#[cl.pos().Z(),cl.pos().Z()] p2size=[0,99]#[cl.pos().Z(),cl.pos().Z()] a1size=[0,99] a2size=[0,99] a3size=[0,99] if args.recalcClSize: digimap=cl.getDigiMap() for dig in digimap: digi=e.TpcDigi.At(dig.first) if type(digi)!=ROOT.TpcDigi: print 'no digi',type(digi) continue dx=float(DigiMapper[digi.padId()][0]) dy=float(DigiMapper[digi.padId()][1]) #dz=(digi.t()*args.ftbin+args.ft0)*args.vd+args.fzGem dz=digi.t() xsize[0]=max(xsize[0],dx) ysize[0]=max(ysize[0],dy) zsize[0]=max(zsize[0],dz) xsize[1]=min(xsize[1],dx) ysize[1]=min(ysize[1],dy) zsize[1]=min(zsize[1],dz) dPos=ROOT.TVector3(dx,dy,dz) dist=dPos-cl.pos() if phi!=-1: alpha=dist.Phi()-phi # print 'alpha=',alpha*ROOT.TMath.RadToDeg(),'dphi=',dist.Phi()*ROOT.TMath.RadToDeg(),'phi=',phi*ROOT.TMath.RadToDeg() # dPos.Print() # cl.pos().Print() longi=math.cos(alpha)*dist.Perp() perp=math.sin(alpha)*dist.Perp() lsize[0]=max(lsize[0],longi) p1size[0]=max(p1size[0],perp) lsize[1]=min(lsize[1],longi) p1size[1]=min(p1size[1],perp) # cl.axis(1).Print() # cl.cov().Print() # if cl.cov().Determinant()==0: # cl.cov().Print() # cl.pos().Print() # dPos.Print() a1=cl.axis(0)*dist a2=cl.axis(1)*dist a3=cl.axis(2)*dist a1size[0]=max(a1size[0],a1) a1size[1]=min(a1size[1],a1) a2size[0]=max(a2size[0],a2) a2size[1]=min(a2size[1],a2) a3size[0]=max(a3size[0],a3) a3size[1]=min(a3size[1],a3) xlen=0 ylen=0 zlen=0 llen=0 p1len=0 p2len=0 a1len=0 a2len=0 a3len=0 xlen=xsize[0]-xsize[1] ylen=ysize[0]-ysize[1] zlen=zsize[0]-zsize[1] # if zsize[0]==zsize[1]: # zlen=-0.5 # print zsize[0],zsize[1],zlen if lsize[0]*lsize[1]<0: llen=lsize[0]-lsize[1] else: llen=max(lsize) if p1size[0]*p1size[1]<0: p1len=p1size[0]-p1size[1] else: p1len=max(p1size) p2len=zlen a1len=a1size[0]-a1size[1] a2len=a2size[0]-a2size[1] a3len=a3size[0]-a3size[1] else: xlen=0 ylen=0 zlen=0 llen=0 p1len=0 p2len=0 a1len=0 a2len=0 a3len=0 xyzlen=tr.GetFullClusterSize()[clcounter] xlen=xyzlen.X() ylen=xyzlen.Y() zlen=xyzlen.Z() lpplen=tr.GetFullClusterSizeTrack()[clcounter] llen=lpplen.X() p1len=lpplen.Y() p2len=xyzlen.Z() axlen=tr.GetFullClusterSizeAxis()[clcounter] a1len=axlen.X() a2len=axlen.Y() a3len=axlen.Z() hClustersizes[0][fcounter].Fill(cl.pos().Z(),xlen) hClustersizes[1][fcounter].Fill(cl.pos().Z(),ylen) hClustersizes[2][fcounter].Fill(cl.pos().Z(),zlen) if lsize[1]==99 and args.recalcClSize: pass else: hClustersizes[3][fcounter].Fill(cl.pos().Z(),llen) hClustersizes[4][fcounter].Fill(cl.pos().Z(),p1len) hClustersizes[5][fcounter].Fill(cl.pos().Z(),p2len) hClustersizes[6][fcounter].Fill(cl.pos().Z(),a1len) hClustersizes[7][fcounter].Fill(cl.pos().Z(),a2len) hClustersizes[8][fcounter].Fill(cl.pos().Z(),a3len) return def fill2dAngles(key,fcounter,Z,vals): for i in range(len(vals)): all2DAngles[key][i][fcounter].Fill(Z,vals[i]) parser=argparse.ArgumentParser(description="plots track related infos like cluster per cm, cluster per track ...") parser.add_argument('files',help='the histo file',type=str,nargs="+") parser.add_argument('--digifiles',help='the digifiles',type=str,nargs='+') parser.add_argument('--titles',help='the titles to use',type=str,default=['None'],nargs='+') parser.add_argument('--sqrt',help='plot a sqrt dependence',action='store_true') parser.add_argument('--nevts',help='number of events to analyze',type=int,default=-1) parser.add_argument('--list',help='do for all files in list',action='store_true') parser.add_argument('--raw',help='use raw cluster information, not TpcCosmics',action='store_true') parser.add_argument('--new',help='create new analysis',action='store_true') parser.add_argument('--histfile',help='name of the histfile',type=str,default='clusdist_hists.root') parser.add_argument('--basepath',help='the path to save all hists',type=str,default='./') parser.add_argument('--pfile',help='the file to save all canvas',type=str,default='None') parser.add_argument('--padf',help='the padplane file to use',type=str,default='tpc/parfiles/padPlane_FOPI.dat') parser.add_argument('--ft0',help='ft for digi z calc',type=float,default=0) parser.add_argument('--ftbin',help='ftbin for digi z calc',type=float,default=64.3087) parser.add_argument('--vd',help='drift velocity for digi z calc',type=float,default=0.00237708) parser.add_argument('--fzGem',help='z gem for digi z calc',type=float,default=0) parser.add_argument('--binwidth',help='width of bins',type=int,default=5) parser.add_argument('--anima',help='create phi and theta animation',action='store_true') parser.add_argument('--mc',help='user MC angles',action='store_true') parser.add_argument('--phicut',help='window for cut. only inside is taken',type=float,nargs=2) parser.add_argument('--clsizes',help='plot all clustersizes',action='store_true') parser.add_argument('--recalcClSize',help='recalculate cluster sizes',action='store_true') parser.add_argument('--correct',help='do corrections',action='store_true') parser.add_argument('--batch',help='no plotting',action='store_true') parser.add_argument('--hlp',help='display help',action='store_true') args=parser.parse_args() if args.hlp: parser.print_help() exit(0) if args.batch: sys.argv.append( '-b-' ) import ROOT if args.batch: ROOT.gROOT.SetBatch(True) ROOT.gROOT.ProcessLine(".x rootlogon.C") ROOT.gROOT.ProcessLine('gROOT->SetStyle("Plain")') ROOT.gROOT.LoadMacro("stlPYROOT.h+") set_palette() if args.mc and args.histfile=='clusdist_hists.root': args.histfile.replace('.root','_mc.root') DigiMapper = [] file=open(args.padf,'r') lines=file.readlines() file.close() lines.reverse() for line in lines: koord = line.split(" ") DigiMapper.append([koord[3], koord[4]]) hClustersizes=[] for i in range(9): hClustersizes.append([]) hdphi=[] hdphi2=[] hdtheta=[] hdangle=[] hdangleAZ=[] hdsorted=[] hphiA=[] hthetaA=[] hphiT=[] hthetaT=[] #hthetaAZ=[] #hphiAZ=[] all2DAngles={'phiVsZ':[],'thetaVsZ':[],'dphiVsZ':[],'dthetaVsZ':[],'dangleVsZ':[],'dangleAZVsZ':[]} for a in all2DAngles.values(): for i in range(3): a.append([]) for i in range(3): hdphi.append([]) hdtheta.append([]) hdsorted.append([]) hphiA.append([]) hthetaA.append([]) hphiT.append([]) hthetaT.append([]) hdphi2.append([]) hdangle.append([]) hdangleAZ.append([]) #hthetaAZ.append([]) #hphiAZ.append([]) hphiUV=[] hthetaUV=[] hdphiUV=[] hdthetaUV=[] hdangleUV=[] for i in range(2): hphiUV.append([]) hthetaUV.append([]) hdphiUV.append([]) hdthetaUV.append([]) hdangleUV.append([]) if args.list: listfile=open(args.files[0],'r') files=[] digifiles=[] titles=[] for line in listfile: if line[0]=='#' or line[0]=='\n': continue words=line.split(';') files.append(str(words[0])) titles.append(str(words[1]).replace('\n','')) digifiles.append(str(words[2]).replace('\n','')) listfile.close() else: files=args.files digifiles=args.digifiles titles=[] if args.titles[0]=='None': for i in range(len(files)): titles=str(i) elif len(titles)args.nevts: break if evt%100==0: print evt if args.raw: for cl in e.TpcCluster: fillClusterSizes(cl,e) else: if e.TrackFitStat_0.GetEntries()>1: continue trackCounter=-1 for tr in e.TrackFitStat_0: trackCounter+=1 # if tr.GetStatFlag()!=0: # continue #track=e.TrackPostFit.At(trackCounter) #rep = track.getTrackRep(0) posX=tr.GetHitPositionsX() posY=tr.GetHitPositionsY() planeU=tr.GetPlaneU() planeV=tr.GetPlaneV() if args.mc: PosMoms=tr.GetMcPosMom() else: PosMoms=tr.GetProjectionPointsMom() clcounter=-1 if len(tr.GetHitIDs())!=len(PosMoms): print len(tr.GetHitIDs()),len(PosMoms) continue ''' if not args.recalcClSize: for clsize in range(len(tr.GetFullClusterSize())): fillClusterSizes(clsize,e,PosMoms[clcounter].Phi()) ''' for clid in tr.GetHitIDs(): clcounter+=1 SpHit=e.TpcSPHit.At(clid) cl=e.TpcCluster.At(SpHit.getClusterID()) if args.recalcClSize: fillClusterSizes(cl,e,PosMoms[clcounter].Phi()) else: fillClusterSizes(cl,e,PosMoms[clcounter].Phi()) phidiff1=(cl.axis(0).Phi()-PosMoms[clcounter].Phi())*ROOT.TMath.RadToDeg() phidiff2=(cl.axis(1).Phi()-PosMoms[clcounter].Phi())*ROOT.TMath.RadToDeg() phidiff3=(cl.axis(2).Phi()-PosMoms[clcounter].Phi())*ROOT.TMath.RadToDeg() hdphi[0][-1].Fill(phidiff1) hdphi[1][-1].Fill(phidiff2) hdphi[2][-1].Fill(phidiff3) if cl.axis(0)*PosMoms[clcounter]<0 and args.correct: thetadiff1=((ROOT.TMath.Pi()-cl.axis(0).Theta())-PosMoms[clcounter].Theta())*ROOT.TMath.RadToDeg() thetadiff1*=-1 else: thetadiff1=(cl.axis(0).Theta()-PosMoms[clcounter].Theta())*ROOT.TMath.RadToDeg() thetadiff2=(cl.axis(1).Theta()-PosMoms[clcounter].Theta())*ROOT.TMath.RadToDeg() if cl.axis(2)*Yaxis>0: thetadiff3=((ROOT.TMath.Pi()-cl.axis(2).Theta())-PosMoms[clcounter].Theta())*ROOT.TMath.RadToDeg() else: thetadiff3=(cl.axis(2).Theta()-PosMoms[clcounter].Theta())*ROOT.TMath.RadToDeg() hdtheta[0][-1].Fill(thetadiff1) hdtheta[1][-1].Fill(thetadiff2) hdtheta[2][-1].Fill(thetadiff3) fill2dAngles('dthetaVsZ',fcounter,cl.pos().Z(),[thetadiff1,thetadiff2,thetadiff3]) if abs(cl.axis(0).DeltaPhi(PosMoms[clcounter]))