import sys,os,time,math, array 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,ROOT from functions import set_palette, openTree, thisIsTheEnd, getSlices def makePCov(cov,xpos,ypos): tcov=ROOT.TMatrixDSym(2,cov.GetMatrixArray()) eigenproblem=ROOT.TMatrixDEigen(ROOT.TMatrixD(tcov)) eigenwert=eigenproblem.GetEigenValues() eigenvector=eigenproblem.GetEigenVectors() teigenvector=ROOT.TVector2(eigenvector[0][0],eigenvector[1][0]) teigenvector2=ROOT.TVector2(eigenvector[0][1],eigenvector[1][1]) eigenvector_i=ROOT.TMatrixD(ROOT.TMatrixD.kInverted,eigenvector) print math.sqrt(abs(eigenwert[0][0])),math.sqrt(abs(eigenwert[1][1])) pcov=ROOT.TEllipse(xpos,ypos,math.sqrt(abs(eigenwert[0][0])),math.sqrt(abs(eigenwert[1][1])),0,360,ROOT.TMath.RadToDeg()*teigenvector.Phi()) pcov.SetLineColor(3) pcov.SetFillStyle(4000) #pcov.Draw('same') return pcov parser=argparse.ArgumentParser(description="generate prelim clusters and plot inof") parser.add_argument('recofile',help='the recofile',type=str) parser.add_argument('paramfile',help='the parameter file',type=str) parser.add_argument('digifile',help='the digifile',type=str) parser.add_argument('--runs', help='if data, the runs to use (%(default)s)', type=str, default='3888') parser.add_argument('--pattern', help='if data, the file name patters ('')', type=str, default='') args=parser.parse_args() ROOT.gROOT.ProcessLine(".x rootlogon.C") ROOT.gROOT.ProcessLine('gROOT->SetStyle("Plain")') ROOT.gROOT.LoadMacro("stlPYROOT.h+") set_palette("palette",99) tree=openTree(args.recofile,args.runs,args.pattern) tree.AddFriend('cbmsim',args.digifile) tree.SetBranchStatus("*", 0) tree.SetBranchStatus("CutCosmics.*", 1) tree.SetBranchStatus("TpcSPHit.*",1) tree.SetBranchStatus("TpcCluster.*",1) tree.SetBranchStatus("TpcDigi.*",1) errScaler = ROOT.TpcClusterErrorScaler.getInstance() errScaler.SetNoFairRun(True) errScaler.init("./tpc/FOPI/par/tpc.errorParam.86.par", 61) if os.path.isfile(args.paramfile): parfile = ROOT.TFile.Open(args.paramfile) digiPar = parfile.Get('TpcDigiPar') digiMap = ROOT.TpcDigiMapper.getInstance() digiMap.init(digiPar) padplane=digiPar.getPadPlane() hplane=ROOT.TH2D("hdetplane","Detplane",1000,-0.3,0.3,1000,-0.3,0.3) cplane=ROOT.TCanvas("cdetplane","DetPlane",1000,1000) hplane.Draw() for e in tree: for tr in e.CutCosmics: for icl in range(tr.nhits()): pdigi=ROOT.TPolyMarker() pnewcluster=ROOT.TPolyMarker() pcog=ROOT.TPolyMarker() pclusterStd=ROOT.TPolyMarker() pmcPoint=ROOT.TPolyMarker() digipos = tr.GetDigiPos(icl) digiamp = tr.GetDigisOnPlaneAmp(icl) mcpos=tr.GetResMC(icl) zpos=tr.GetHitPosistionXYZ(icl).Z() #if zpos>10: # continue hitid=tr.GetHitID(icl) print hitid sphit=e.TpcSPHit.At(hitid) cluster=e.TpcCluster.At(sphit.getClusterID()) digimap=cluster.getDigiMap() midplane=cluster.midPlane() print digimap prelim=ROOT.TpcPrelimCluster(padplane,icl,1,14) prelimStd=ROOT.TpcPrelimCluster(padplane,icl,-1,22) for idi in digimap: print idi.first,idi.second digi=e.TpcDigi.At(idi.first) prelim.addHit(digi,midplane,idi.second) prelimStd.addHit(digi,midplane,idi.second) prelim.setPhi(midplane.getNormal().Phi()); prelim.setDir(midplane.getNormal()); prelim.setMidPos(midplane.getO()); prelim.setMidPlane(midplane); prelimStd.setPhi(midplane.getNormal().Phi()); prelimStd.setDir(midplane.getNormal()); prelimStd.setMidPos(midplane.getO()); prelimStd.setMidPlane(midplane); newCluster=prelim.convTpcCluster(0,0.152867,True,True) newClusterStd=prelimStd.convTpcCluster(0,0.152867,True,False) print "fitted position: (", prelim.getPosOnPlane().X(),",",prelim.getPosOnPlane().Y(),")" print "cog positiopn: (", prelim.getCogOnPlane().X(),",",prelim.getCogOnPlane().Y(),")" print "fitted position Std: (", prelimStd.getPosOnPlane().X(),",",prelimStd.getPosOnPlane().Y(),")" print "cog positiopn Std: (", prelimStd.getCogOnPlane().X(),",",prelimStd.getCogOnPlane().Y(),")" print "fit was good:",newCluster.fitGood() pnewcluster.SetPoint(0,prelim.getPosOnPlane().X(),prelim.getPosOnPlane().Y()) pnewcluster.SetMarkerColor(3) pnewcluster.SetMarkerStyle(20) pnewcluster.Draw("same") pcog.SetPoint(0,prelim.getCogOnPlane().X(),prelim.getCogOnPlane().Y()) pcog.SetMarkerStyle(20) pcog.SetMarkerColor(2) pcog.Draw("same") pclusterStd.SetPoint(0,prelimStd.getCogOnPlane().X(),prelimStd.getCogOnPlane().Y()) pclusterStd.SetMarkerColor(6) pclusterStd.SetMarkerStyle(20) pclusterStd.Draw("same") pmcPoint.SetPoint(0,mcpos.X(),mcpos.Y()) pmcPoint.SetMarkerColor(4) pmcPoint.SetMarkerStyle(20) pmcPoint.Draw("same") #hplane.GetXaxis().SetRangeUser(prelim.getPosOnPlane().X()-1,prelim.getPosOnPlane().X()+1) #hplane.GetYaxis().SetRangeUser(prelim.getPosOnPlane().Y()-1,prelim.getPosOnPlane().Y()+1) pcov=makePCov(newCluster.covOnPlane(), prelim.getPosOnPlane().X(),prelim.getPosOnPlane().Y()) pcov.Draw("same") cplane.Update() u=raw_input('next?')