diff --git a/Tracker/TrackerRecAlgs/PairVertex/python/PairVertexAlgConfig.py b/Tracker/TrackerRecAlgs/PairVertex/python/PairVertexAlgConfig.py index 4243fe99559a9ff4f16753f0e53c51c9d8ea1d2a..378692f459e389c332c3757bad933102e7ceec2b 100644 --- a/Tracker/TrackerRecAlgs/PairVertex/python/PairVertexAlgConfig.py +++ b/Tracker/TrackerRecAlgs/PairVertex/python/PairVertexAlgConfig.py @@ -9,22 +9,27 @@ from MagFieldServices.MagFieldServicesConfig import MagneticFieldSvcCfg #Command line config from argparse import ArgumentParser - -test_file = '/eos/experiment/faser/sim/mdc/foresee/110001/rec/r0009/FaserMC-MDC_FS_Aee_100MeV_1Em5_shift-110001-00000-00009-s0007-r0009-xAOD.root' + +test_file = "/eos/experiment/faser/sim/mc22/foresee/110033/rec/r0013/FaserMC-MC22_FS_Aee_010MeV_1Em5-110033-00000-00009-s0008-r0013-xAOD.root" #'/eos/experiment/faser/sim/mdc/foresee/110001/rec/r0009/FaserMC-MDC_FS_Aee_100MeV_1Em5_shift-110001-00000-00009-s0007-r0009-xAOD.root' parser=ArgumentParser(description="EventLooper") parser.add_argument("-i","--inputfile",type=str,default=test_file) parser.add_argument("-e", "--events", type=int, default=1000) # Max events processed in alg. Set to -1 to process all events. -parser.add_argument("-r","--runnum",type=int,default=110001) # 110001-4 +parser.add_argument("-r","--runnum",type=int,default=1100033) # 110001-4 +parser.add_argument("-v","--version",type=str,default='r0013') # 110001-4 ui=parser.parse_args() inputIsMC = 'FaserMC' in ui.inputfile +# if test_file!=ui.input: +# ui.version=ui.input.split('/')[8] +# ui.runnum=ui.input.split('/')[6] + #Get/Make input/output file names from ROOT import TFile from glob import glob -dataDir=f"/eos/experiment/faser/sim/mdc/foresee/{ui.runnum}/rec/r0009/" +dataDir=ui.inputfile #f"/eos/experiment/faser/sim/mdc/foresee/{ui.runnum}/rec/{ui.version}/" files=sorted(glob(f"{dataDir}/Faser*")) -name=files[0].split("r0009/")[-1].split("MDC_FS")[-1].split("shift")[0] #Generate output file name from input file name +name=files[0].split(ui.version+"/")[-1].split("_FS_")[-1].split("shift")[0] #Generate output file name from input file name #------------------- @@ -37,7 +42,7 @@ def PairVertexAlgCfg(flags, **kwargs): #Hist output thistSvc = CompFactory.THistSvc() - thistSvc.Output = [f"HIST DATAFILE='Ntuple{name}.root' OPT='RECREATE'"] + thistSvc.Output = [f"HIST DATAFILE='Ntuple_{ui.version}_{name}.root' OPT='RECREATE'"] acc.addService(thistSvc) return acc diff --git a/Tracker/TrackerRecAlgs/PairVertex/scripts/PairVertexReader.py b/Tracker/TrackerRecAlgs/PairVertex/scripts/PairVertexReader.py index 27875efcac07a0b56d81c13129bd6eb0e72f31d9..8f380a827816cbb782d85531c202e1f90d494642 100644 --- a/Tracker/TrackerRecAlgs/PairVertex/scripts/PairVertexReader.py +++ b/Tracker/TrackerRecAlgs/PairVertex/scripts/PairVertexReader.py @@ -1,8 +1,21 @@ #!/usr/bin/env python from PlotHelper import * from Utilities import * +from copy import deepcopy +WaveformCuts = { + 'Preshower0_integral':[0,None,None,None], + 'Preshower1_integral':[0,None,None,None], + 'VetoNu0_integral':[None,None,0,None], + 'VetoNu1_integral':[None,None,0,None], + 'VetoSt10_integral':[None,None,0,None], + 'VetoSt11_integral':[None,None,0,None], + 'VetoSt20_integral':[None,None,0,None]} +WaveformCuts2 = [ + lambda e: e.Calo0_integral+e.Calo1_integral+e.Calo2_integral+e.Calo3_integral>0, + lambda e: e.Timing0_integral+e.Timing1_integral+e.Timing2_integral+e.Timing3_integral>0] + #Q/P METHODS def GetPBounds(dcuts=[],lcuts=[]): TotalTracks=0 @@ -101,7 +114,7 @@ def GetAllTrackMomentum(event): p_r=event.tracksPmag[ti] measarr+=[p_r*10**-3] - return finalval + return measarr def CountSharedCluster(event,filter=None): #How many clusters have energy contributions from both daughter particles? @@ -120,13 +133,31 @@ def CountSharedClusterCompare(event): if event.clusterETotPos[c]>0 and event.clusterETotNeg[c]>0 and event.clusterEFracPos[c]<0.99 and event.clusterEFracNeg[c]<0.99: sharedcount+=1 - filters = [lambda e:True,BoolDaughterCut2,BoolDaughterCut3] + filters = [lambda e:True,BoolDaughtersMatchedFiducial,BoolDaughtersUnmatchedFiducial] for i in range(len(filters)): if filters[i](event): sharedcountarr[i]=sharedcount else: sharedcountarr[i]=nan return sharedcountarr +def SharedClusterLocation(event): + #How many clusters have energy contributions from both daughter particles? + sharedcount=0 + sharedcountarr=[[],[]] + for c in range(len(event.clusterLocStation)): + val = event.clusterLocStation[c] + check= event.clusterETotPos[c]>0 and event.clusterETotNeg[c]>0 and event.clusterEFracPos[c]<0.99 and event.clusterEFracNeg[c]<0.99 + sharedcountarr[0]+=[val] + if check: sharedcountarr[1]+=[val] + + # filters = [lambda e:True,BoolDaughtersMatchedFiducial,BoolDaughtersUnmatchedFiducial] + # for i in range(len(filters)): + # if filters[i](event): sharedcountarr[i]=sharedcount + # else: sharedcountarr[i]=nan + + return sharedcountarr[1] + + def VertexZCompare(event): val = event.vertexPos[2] countarr=[0,0,0] #[No filter, HasShared, NoShared] @@ -137,9 +168,9 @@ def VertexZCompare(event): return countarr -def ClusterLocation(event): +def ClusterLocation(event,locList,filter): starr=[] - for loc in event.clusterLocation: + for loc in locList: if event.clusterIsDaughter: starr+=[int(str(loc).split()[0])] return starr @@ -147,25 +178,79 @@ def MakeCompareArray(event,getvaluelambda,filters): val = getvaluelambda(event) countarr=[0 for i in range(len(filters))] for fi in range(len(filters)): - if filters[i](event): countarr[i]=val - else: countarr[i]=nan + if filters[fi](event): + countarr[fi]=val + else: countarr[fi]=nan return countarr +def ClustersPerDaughter(event): + #How many clusters does a daughter particle cause? (Expect most efficient to be 12 bc of the Kalman Filter as it is) + dp=0 + dn=0 + for c in range(event.clusterCount): + if event.clusterIsDaughter[c]: + if event.clusterEFracPos[c]>0.01: dp+=1 + if event.clusterEFracNeg[c]>0.01: dn+=1 + return [dp,dn] + +def PercentDaughterClusterShared(event): + #How many clusters does a daughter particle cause? (Expect most efficient to be 12 bc of the Kalman Filter as it is) + dp=0 + dn=0 + sharedcount=0 + for c in range(event.clusterCount): + if event.clusterIsDaughter[c]: + if event.clusterEFracPos[c]>0.01: dp+=1 + if event.clusterEFracNeg[c]>0.01: dn+=1 + if event.clusterETotPos[c]>0 and event.clusterETotNeg[c]>0 and event.clusterEFracPos[c]<0.99 and event.clusterEFracNeg[c]<0.99: sharedcount+=1 + answer=[0,0] + if dp==0: answer[0]=nan + else: answer[0]=100*sharedcount/dp + if dn==0: answer[1]=nan + else: answer[0]=100*sharedcount/dn + return answer + +def Chi2DoF(event): + a=[] + for tr in range(event.TrackCount): + if event.tracksDoF[tr]>0: a+=[event.tracksChi2[tr]/event.tracksDoF[tr]] + return a + #BOOLEAN FUNCTIONS -def BoolDaughterCut(event): +def BoolDaughtersMatched(event): #both daughter particles are matched to tracks if event.TrackCount>=2 and len(event.tracksTruthBarcode)>=2: return 2 in event.tracksTruthBarcode and 3 in event.tracksTruthBarcode else: return False -def BoolDaughterCut2(event): +def BoolDaughtersFiducial(event): + return event.truthd0_IsFiducial and event.truthd1_IsFiducial + +def BoolDaughtersUltraFiducial(event): + layermapPos=[[0,0,0],[0,0,0],[0,0,0],[0,0,0]] + layermapNeg=[[0,0,0],[0,0,0],[0,0,0],[0,0,0]] + for li in range(len(event.clusterLocStation)): + if event.clusterIsDaughter[li]: + if event.clusterEFracPos[li]>0.01: layermapPos[event.clusterLocStation[li]][event.clusterLocLayer[li]]=1 + if event.clusterEFracNeg[li]>0.01: layermapNeg[event.clusterLocStation[li]][event.clusterLocLayer[li]]=1 + + plcount=0 + nlcount=0 + for s in range(1,len(layermapPos)): + for l in range(len(layermapPos[s])): + plcount+=layermapPos[s][l] + nlcount+=layermapNeg[s][l] + + return plcount>6 and nlcount>6 + +def BoolDaughtersMatchedFiducial(event): #passes track cuts and is fiducial return event.TrackCount>=2 and 2 in event.tracksTruthBarcode and 3 in event.tracksTruthBarcode and event.truthd0_IsFiducial and event.truthd1_IsFiducial -def BoolDaughterCut3(event): +def BoolDaughtersUnmatchedFiducial(event): #fails track cuts and is not fiducial return any([event.TrackCount<2, 2 not in event.tracksTruthBarcode, 3 not in event.tracksTruthBarcode]) and event.truthd0_IsFiducial and event.truthd1_IsFiducial @@ -183,6 +268,63 @@ def BoolNotHasSharedCluster(event): if event.clusterETotPos[c]>0 and event.clusterETotNeg[c]>0 and event.clusterEFracPos[c]<0.99 and event.clusterEFracNeg[c]<0.99: sharedcount+=1 return sharedcount==0 +def BoolWhatever(event): + boollist=[ + BoolDaughtersMatched(event), + event.TrackCount>=2] + + td2i=None + td3i=None + for i in range(event.TrackCount): + if event.tracksTruthBarcode[i]==2: td2i=i + if event.tracksTruthBarcode[i]==3: td3i=i + if event.tracksDoF[i]==0: boollist+= [False] + else: boollist+= [event.tracksChi2[i]/event.tracksDoF[i]<=10] + + if type(td2i)==int and type(td3i)==int: + boollist+= [event.tracksNLayersHit[td2i]>=7 and event.tracksNLayersHit[td3i]>=7] + else: boollist+= [False] + + + return all(boollist) + +def FlexiBool(event,stage=0): + if stage==0: return all([BoolDaughtersMatched(event) and BoolDaughtersFiducial(event)]) + boollist=[BoolDaughtersMatched(event)] + + #numerator 1 + if stage==1: return BoolDaughtersFiducial(event) and BoolTrackCut(event) and BoolHasSharedCluster(event) and BoolDaughtersMatched(event) + + #num 2 + if stage==2: return BoolDaughtersFiducial(event) and BoolTrackCut(event) and BoolNotHasSharedCluster(event) and BoolDaughtersMatched(event) + + #denom 1 + if stage==3: return BoolDaughtersFiducial(event) and BoolHasSharedCluster(event) + + #denom 2 + if stage==4: return BoolDaughtersFiducial(event) and BoolNotHasSharedCluster(event) + + #num 3 + if stage==5: return BoolTrackCut(event) + + #denom 3 + if stage==6: return event.vertexPos[2]>-1585 and event.vertexPos[2]<-45 and sqrt(event.vertexPos[0]**2+event.vertexPos[1]**2)<=100 + +def BoolChi2DoF(event): + return all([event.tracksDoF[i]>0 and event.tracksChi2[i]/event.tracksDoF[i]<10 for i in range(event.TrackCount)]) + +def BoolLayersHit(event): + return all([event.tracksNLayersHit[i]>=7 for i in range(event.TrackCount)]) + +def BoolAntiTrack(event): + return not BoolChi2DoF(event) or not BoolLayersHit(event) + +def BoolRecoCut(event): + return event.TrackCount==2 and ApplyAllCuts(event,[WaveformCuts],WaveformCuts2) and BoolChi2DoF(event) and BoolLayersHit(event) + +def BoolTrackCut(event): + return event.TrackCount==2 and BoolLayersHit(event) #and BoolChi2DoF(event) + #For storing different plot configurations MainArrDict={ 'RecoX':{ @@ -197,153 +339,194 @@ MainArrDict={ 'plotterfunc': configBasicHist, 'plotkwargs' : {'pckwargs':{'xscale':'log'}} }, - 'TruthMaxMomentum':{ + 'CountSharedCluster':{ 'array':[], - 'lambda': lambda event:max(event.tracksTruthPmag), + 'lambda': CountSharedCluster, 'plotterfunc': configBasicHist, - 'plotkwargs' : {'pckwargs':{'xscale':'log'}} + 'plotkwargs' : {'bins':25,'kwargs':{'range':[0,25]},'pckwargs':{'xlabel':'# Shared Clusters'}}, + 'descr':'How many clusters have energy deposits from both daughter particles and fail track cuts?' }, - 'RecoVsTruthMaxMomentum':{ - 'array':[[],[]], - 'lambda': lambda event:[max(event.tracksPmag),max(event.tracksTruthPmag)], + 'CountSharedCluster_Compare':{ + 'array':[[],[],[]], + 'lambda': CountSharedClusterCompare, 'plotterfunc': configMultiHist, - 'plotkwargs' : {'label':['Reco','Truth'],'pckwargs':{'xscale':'log','legend':True}} + 'plotkwargs' : {'label':['No Cuts','Passes Track Cuts','Fails Track Cuts'],'bins':25,'kwargs':{'range':[0,26]},'pckwargs':{'xscale':'linear','legend':True}}, + 'descr':'How many clusters have energy deposits from both daughter particles?', + 'SepHist':'arrays allowed to have different lengths' }, - 'RecoVsTruthMaxMomentumScatter':{ - 'array':[[],[]], - 'lambda': lambda event:[max(event.tracksPmag),max(event.tracksTruthPmag)], - 'plotterfunc': config2DScatter, - 'plotkwargs' : {} + 'DPDecayVertexZ':{ + 'array':[], + 'lambda': lambda event: event.vertexPos[2], + 'plotterfunc': configBasicHist, + 'plotkwargs' : {}, + 'descr':'Dark photon decay vertex coordinate along beamline' }, - 'QP_reco Vs QP_truth':{ - 'array':[[],[],[],[]], - 'lambda': RecoVsTruthQPMatched, + 'DPDecayVertexZ_Compare':{ + 'array':[[],[],[]], + 'lambda': VertexZCompare, 'plotterfunc': configMultiHist, - 'plotkwargs' : {'label':['Reco +','Truth +','Reco -','Truth -'],'kwargs':{'range':[-10**-5,10**-5]},'pckwargs':{'xscale':'linear','xlabel':"Q/P",'legend':True}} + 'plotkwargs' : {'label':['No Cuts','Has Shared Clusters','No Shared Clusters'],'bins':25,'kwargs':{'range':[-1600,0]},'pckwargs':{'xscale':'linear','legend':True,'legloc':'center right'}}, + 'descr':'Compare dp-decay z-coordinate cuts', + 'SepHist':'arrays allowed to have different lengths' }, - 'QP_truth_vs_Residual':{ - 'array':[[],[]], - 'lambda': ResidualVSQP_truth, - 'plotterfunc': config2DScatter, - 'plotkwargs' : {'kwargs':{},'pckwargs':{'xlabel':"Q/P_truth",'ylabel':"Residual"}} + 'NumClusters':{ + 'array':[], + 'lambda': lambda event: event.clusterCount, + 'plotterfunc': configBasicHist, + 'plotkwargs' :{'kwargs':{'range':[0,200]}}, }, - 'NormalizedResidual':{ - 'array':[[],[]], - 'lambda': NormalizedResidual2, - 'plotterfunc': configMultiHist, - 'plotkwargs' : {'bins':20,'kwargs':{'range':[-10,11]},'label':['Positive','Negative'],'pckwargs':{'xscale':'linear','xlabel':"Residual",'legend':True}} + 'NumClustersBool':{ + 'array':[], + 'lambda': lambda event: event.clusterCount<200, + 'plotterfunc': PrintBoolPercent, + 'plotkwargs' :{}, + 'descr':'How many events have a cluster count in a certain range?' }, - 'AllTracksQP_reco':{ + 'ClusterStation':{ 'array':[], - 'lambda': GetAllTrackQPReco, + 'lambda': lambda event: [i for i in event.clusterLocStation], 'plotterfunc': configBasicHist, - 'plotkwargs' :{'bins':100,'kwargs':{'range':[2*-10**-3,2*10**-3]}}, + 'plotkwargs' :{'bins':8,'kwargs':{'range':[0,4]},'pckwargs':{'xlabel':'Station #','ylabel':'#Clusters'}}, + 'descr':'Where are any clusters?' }, - 'AllTracksQP_truth':{ + 'SharedClusterLocation':{ 'array':[], - 'lambda': GetAllTrackQPTruth, + 'lambda': SharedClusterLocation, 'plotterfunc': configBasicHist, - 'plotkwargs' :{'kwargs':{'range':[2*-10**-3,2*10**-3]}}, + 'plotkwargs' :{'bins':8,'kwargs':{'range':[0,4]},'pckwargs':{'xlabel':'Station #','ylabel':'#Clusters'}}, + 'descr': 'Where are the shared clusters?' }, - 'AllMomentum_Reco':{ + 'FiducialDaughters':{ 'array':[], - 'lambda': GetAllTrackMomentum, - 'plotterfunc': configBasicHist, - 'plotkwargs' : {'kwargs':{'range':[0,4000]}} + 'lambda': BoolDaughtersFiducial, + 'plotterfunc': PrintBoolPercent, + 'plotkwargs' :{}, + 'descr':'' }, - 'AllTracksQP_reco':{ + 'FiducialMatchedDaughters':{ 'array':[], - 'lambda': GetAllTrackQPReco, - 'plotterfunc': configBasicHist, - 'plotkwargs' :{'bins':50,'kwargs':{'range':[2*-10**-3,2*10**-3]}}, - 'lkwargs' : {'tar':2000*10**3} + 'lambda': BoolDaughtersMatchedFiducial, + 'plotterfunc': PrintBoolPercent, + 'plotkwargs' :{}, + 'descr':'' }, - 'AllTracksTruthPmag':{ + 'BoolDaughtersUltraFiducial':{ 'array':[], - 'lambda': lambda event: list(event.tracksTruthPmag), - 'plotterfunc': configBasicHist, - 'plotkwargs' :{'bins':50,'pckwargs':{'xscale':'log'}}, + 'lambda': BoolDaughtersUltraFiducial, + 'plotterfunc': PrintBoolPercent, + 'plotkwargs' :{}, + 'descr':'' }, - 'NormalizedResidualSum':{ + 'BoolDaughtersUltraFiducialMatched':{ 'array':[], - 'lambda': NormalizedResidual2, - 'plotterfunc': configBasicHist, - 'plotkwargs' : {'bins':20,'kwargs':{'range':[-10,11]},'pckwargs':{'xscale':'linear','xlabel':"Residual"}} + 'lambda':BoolDaughtersUltraFiducial, + 'plotterfunc': PrintBoolPercent, + 'plotkwargs' :{}, + 'descr':'' }, - 'CountSharedCluster':{ + 'BoolWhatever':{ 'array':[], - 'lambda': CountSharedCluster, + 'lambda': BoolWhatever, + 'plotterfunc': PrintBoolPercent, + 'plotkwargs' :{}, + 'descr':'something with efficiency' + }, + 'ClustersPerDaughter':{ + 'array':[], + 'lambda': ClustersPerDaughter, 'plotterfunc': configBasicHist, - 'plotkwargs' : {'bins':25,'kwargs':{'range':[0,26]}}, - 'descr':'How many clusters have energy deposits from both daughter particles and fail track cuts?' + 'plotkwargs' :{'bins':41,'kwargs':{'range':[0,41]},'pckwargs':{'xlabel':'# of Clusters','ylabel':'# Daughter Particle'}}, + 'descr': 'How many clusters does a daughter particle cause?' }, - 'CountSharedCluster_PassTrackCuts':{ + 'PercentDaughterClusterShared':{ 'array':[], - 'lambda': CountSharedCluster, - 'lkwargs':{'filter':BoolDaughterCut2}, + 'lambda': PercentDaughterClusterShared, 'plotterfunc': configBasicHist, - 'plotkwargs' : {'bins':25,'kwargs':{'range':[0,26]}}, - 'descr':'How many clusters have energy deposits from both daughter particles and pass track cuts?' + 'plotkwargs' :{'pckwargs':{'xlabel':'Percent of clusters shared','ylabel':'# Daughter Paricles'}}, + 'descr': 'How many clusters does a daughter particle cause?' }, - 'CountSharedCluster_FailTrackCuts':{ + 'Chi2DoF':{ 'array':[], - 'lambda': CountSharedCluster, - 'lkwargs':{'filter':BoolDaughterCut3}, + 'lambda': Chi2DoF, 'plotterfunc': configBasicHist, - 'plotkwargs' : {'bins':25,'kwargs':{'range':[0,26]}}, - 'descr':'How many clusters have energy deposits from both daughter particles and fail track cuts?' + 'plotkwargs' :{'kwargs':{'range':[0,20]},'pckwargs':{'xlabel':'Chi2/DoF','ylabel':'# Tracks'}}, + 'descr': 'How many clusters does a daughter particle cause?' }, - 'CountSharedCluster_Compare':{ - 'array':[[],[],[]], - 'lambda': CountSharedClusterCompare, - 'plotterfunc': configMultiHist, - 'plotkwargs' : {'label':['No Cuts','Passes Track Cuts','Fails Track Cuts'],'bins':25,'kwargs':{'range':[0,26]},'pckwargs':{'xscale':'linear','legend':True}}, - 'descr':'How many clusters have energy deposits from both daughter particles?', - 'SepHist':'arrays allowed to have different lengths' + # 1-24-23 plots + 'Efficiency0':{ + 'array':[], + 'lambda': FlexiBool, + 'lkwargs':{'stage':0}, + 'plotterfunc': PrintBoolPercent, + 'plotkwargs' :{}, }, - 'DPDecayVertexZ':{ + 'Efficiency1':{ 'array':[], - 'lambda': lambda event: event.vertexPos[2], - 'plotterfunc': configBasicHist, - 'plotkwargs' : {}, - 'descr':'Dark photon decay vertex coordinate along beamline' + 'lambda': FlexiBool, + 'lkwargs':{'stage':1}, + 'plotterfunc': PrintBoolPercent, + 'plotkwargs' :{}, }, - 'DPDecayVertexZ_Compare':{ - 'array':[[],[],[]], - 'lambda': VertexZCompare, - 'plotterfunc': configMultiHist, - 'plotkwargs' : {'label':['No Cuts','Has Shared Clusters','No Shared Clusters'],'bins':25,'kwargs':{'range':[-1600,0]},'pckwargs':{'xscale':'linear','legend':True,'legloc':'center right'}}, - 'descr':'Compare dp-decay z-coordinate cuts', - 'SepHist':'arrays allowed to have different lengths' + 'Efficiency2':{ + 'array':[], + 'lambda': FlexiBool, + 'lkwargs':{'stage':2}, + 'plotterfunc': PrintBoolPercent, + 'plotkwargs' :{}, }, - 'AllClusterLocations':{ + 'Efficiency3':{ 'array':[], - 'lambda': ClusterLocation, - 'plotterfunc': configBasicHist, - 'plotkwargs' :{},#'bins':5,'kwargs':{'range':[0,5]} + 'lambda': FlexiBool, + 'lkwargs':{'stage':3}, + 'plotterfunc': PrintBoolPercent, + 'plotkwargs' :{}, }, - 'NumClusters':{ + 'Efficiency4':{ 'array':[], - 'lambda': lambda event: event.clusterCount, - 'plotterfunc': configBasicHist, - 'plotkwargs' :{'kwargs':{'range':[0,200]}}, + 'lambda': FlexiBool, + 'lkwargs':{'stage':4}, + 'plotterfunc': PrintBoolPercent, + 'plotkwargs' :{}, }, - 'NumClustersBool':{ + 'Efficiency5':{ 'array':[], - 'lambda': lambda event: event.clusterCount<200, + 'lambda': FlexiBool, + 'lkwargs':{'stage':5}, 'plotterfunc': PrintBoolPercent, - 'plotkwargs' :{'kwargs':{'range':[0,200]}}, + 'plotkwargs' :{}, }, + 'Efficiency6':{ + 'array':[], + 'lambda': FlexiBool, + 'lkwargs':{'stage':6}, + 'plotterfunc': PrintBoolPercent, + 'plotkwargs' :{}, + }, + 'RecoMinMomentum':{ + 'array':[], + 'lambda': lambda event:min(event.tracksPmag), + 'plotterfunc': configBasicHist, + 'plotkwargs' : {'pckwargs':{'xscale':'log'}} + }, + } def MakePlotDict(entry): TestArrDict=dict() - testname=entry #Any key from MainArrDict - TestArrDict[testname]=MainArrDict[testname] + if type(entry)==list: + for e in entry: + testname=e #Any key from MainArrDict + TestArrDict[testname]=deepcopy(MainArrDict[testname]) + else: + testname=entry #Any key from MainArrDict + TestArrDict[testname]=deepcopy(MainArrDict[testname]) return TestArrDict -def GeneralPlotter(arrDict,dcuts=[],lcuts=[],showplot=True,savefig=False): +def GeneralPlotter(arrDict,dcuts=[],lcuts=[],showplot=True,savefig=False,titleextra='',label=None): nans=0 + for name in arrDict.keys(): + arrDict[name]=deepcopy(MainArrDict[name]) + print(arrDict[name]['array']) for event in t: if ApplyAllCuts(event,dcuts,lcuts): #Check that event passes given cuts before doing anything with it @@ -378,12 +561,18 @@ def GeneralPlotter(arrDict,dcuts=[],lcuts=[],showplot=True,savefig=False): isPrintout= arrDict[name]['plotterfunc'] in [PrintBoolPercent] #Is it text-only output? print(name) print('LEN:',len(arrDict[name]['array'])) #how many events remain after the cut? + if label: + arrDict[name]['plotkwargs'].update({'label':label}) + arrDict[name]['plotkwargs']['pckwargs'].update({'legend':True}) + arrDict[name]['plotterfunc']( arrDict[name]['array'], **arrDict[name]['plotkwargs']) #plot using the given function if not isPrintout: - plt.title(user_input+name) + plt.title(user_input+name+titleextra) if savefig: plt.savefig(user_input+name) if showplot: plt.show() + print() + #EXECUTE if __name__ == "__main__": @@ -392,8 +581,36 @@ if __name__ == "__main__": user_input=f t = TChain("events") nfiles = 0 - nfiles += t.Add("/eos/home-s/sshively/CALYPZONE/run/"+user_input+".root") + nfiles += t.Add("/eos/home-s/sshively/CALYPZONE/run/BackUp2/"+user_input+".root") print(f) - - GeneralPlotter(MakePlotDict('CountSharedCluster_Compare'),dcuts=[{'clusterCount':[None,200,None,None]}],lcuts=[]) - #print(GetPBounds(lcuts=[BoolDaughterCut])) + + #1-24-23 Plots + # GeneralPlotter(MakePlotDict('Efficiency0'),dcuts=[{}],lcuts=[]) + # GeneralPlotter(MakePlotDict([f'Efficiency{i}' for i in range(1,7)]),dcuts=[{}],lcuts=[]) + # print() + # GeneralPlotter(MakePlotDict('Efficiency4'),dcuts=[{}],lcuts=[BoolDaughtersFiducial,BoolHasSharedCluster]) + # GeneralPlotter(MakePlotDict('Efficiency4'),dcuts=[{}],lcuts=[BoolDaughtersFiducial,BoolNotHasSharedCluster]) + + # GeneralPlotter(MakePlotDict('Chi2DoF'),dcuts=[{'TrackCount':[0,None,None,None]}],lcuts=[],label='All Events',showplot=False) + # GeneralPlotter(MakePlotDict('Chi2DoF'),dcuts=[{'TrackCount':[0,None,None,None]}],lcuts=[BoolDaughtersMatched,BoolDaughtersFiducial],label='Daughters Matched & Fiducial') + + # GeneralPlotter(MakePlotDict('CountSharedCluster'),dcuts=[],lcuts=[],label='All Events',showplot=False) + # GeneralPlotter(MakePlotDict('CountSharedCluster'),dcuts=[{'TrackCount':[1,None,None,None]}],lcuts=[BoolDaughtersMatched,BoolDaughtersFiducial,BoolChi2DoF, BoolLayersHit],label='Passes Track Cuts',showplot=False) + # GeneralPlotter(MakePlotDict('CountSharedCluster'),dcuts=[{'TrackCount':[None,None,None,2]}],lcuts=[BoolDaughtersMatched,BoolDaughtersFiducial,BoolAntiTrack],label='Fails Track Cuts') + + ####GeneralPlotter(MakePlotDict('ClusterStation'),dcuts=[],lcuts=[],label='All Clusters',showplot=False) #meh + #GeneralPlotter(MakePlotDict('SharedClusterLocation'),dcuts=[],lcuts=[],label='Shared Cllusters') + + #GeneralPlotter(MakePlotDict('DPDecayVertexZ_Compare'),dcuts=[],lcuts=[]) + + #GeneralPlotter(MakePlotDict('RecoMinMomentum'),dcuts=[{'TrackCount':[None,None,2,None]},WaveformCuts],lcuts=[BoolDaughtersMatched,BoolDaughtersFiducial,BoolChi2DoF, BoolLayersHit]+WaveformCuts2) + + #1-25-23 + #GeneralPlotter(MakePlotDict('FiducialDaughters'),dcuts=[{}],lcuts=[]) + # GeneralPlotter(MakePlotDict([f'Efficiency{i}' for i in range(6,7)]),dcuts=[{}],lcuts=[]) + + # GeneralPlotter(MakePlotDict('Chi2DoF'),dcuts=[{}],lcuts=[BoolDaughtersMatched,BoolTrackCut,BoolNotHasSharedCluster],label='No Shared',showplot=False) + # GeneralPlotter(MakePlotDict('Chi2DoF'),dcuts=[{}],lcuts=[BoolDaughtersMatched,BoolTrackCut,BoolHasSharedCluster],label='Shared') + + + diff --git a/Tracker/TrackerRecAlgs/PairVertex/scripts/PlotHelper.py b/Tracker/TrackerRecAlgs/PairVertex/scripts/PlotHelper.py index bcb70ac0f785d5c5f2c1d6f988c93d3f229eeca6..e3da186362c8f90e0f931c1182b1d56070f40fbc 100644 --- a/Tracker/TrackerRecAlgs/PairVertex/scripts/PlotHelper.py +++ b/Tracker/TrackerRecAlgs/PairVertex/scripts/PlotHelper.py @@ -27,7 +27,7 @@ def configHitMap(arrays,bins=(50,50),pckwargs={'xlabel':"X (mm)",'ylabel':"Y (mm def configBasicHist(arr,bins=25,label=None,pckwargs={'xscale':'linear'},kwargs={}): #1D Histogram - if 'log' in pckwargs['xscale']: bins=CorrectBinsForLog(arr,bins,pckwargs['xscale']) + if 'xscale' in pckwargs.keys() and 'log' in pckwargs['xscale']: bins=CorrectBinsForLog(arr,bins,pckwargs['xscale']) n, binsOut, patches = plt.hist(arr,bins=bins,label=label,align="left",histtype=u'step',**kwargs) PlotConfigs(**pckwargs) diff --git a/Tracker/TrackerRecAlgs/PairVertex/scripts/Storage.py b/Tracker/TrackerRecAlgs/PairVertex/scripts/Storage.py new file mode 100644 index 0000000000000000000000000000000000000000..b13fab4a0a5700d9eb4ca23e21b4e23ab05ca9f8 --- /dev/null +++ b/Tracker/TrackerRecAlgs/PairVertex/scripts/Storage.py @@ -0,0 +1,91 @@ +from PairVertexReader import * + +ArrayStorageDict={ 'TruthMaxMomentum':{ + 'array':[], + 'lambda': lambda event:max(event.tracksTruthPmag), + 'plotterfunc': configBasicHist, + 'plotkwargs' : {'pckwargs':{'xscale':'log'}} + }, + 'RecoVsTruthMaxMomentum':{ + 'array':[[],[]], + 'lambda': lambda event:[max(event.tracksPmag),max(event.tracksTruthPmag)], + 'plotterfunc': configMultiHist, + 'plotkwargs' : {'label':['Reco','Truth'],'pckwargs':{'xscale':'log','legend':True}} + }, + 'RecoVsTruthMaxMomentumScatter':{ + 'array':[[],[]], + 'lambda': lambda event:[max(event.tracksPmag),max(event.tracksTruthPmag)], + 'plotterfunc': config2DScatter, + 'plotkwargs' : {} + }, + 'QP_reco Vs QP_truth':{ + 'array':[[],[],[],[]], + 'lambda': RecoVsTruthQPMatched, + 'plotterfunc': configMultiHist, + 'plotkwargs' : {'label':['Reco +','Truth +','Reco -','Truth -'],'kwargs':{'range':[-10**-5,10**-5]},'pckwargs':{'xscale':'linear','xlabel':"Q/P",'legend':True}} + }, + 'QP_truth_vs_Residual':{ + 'array':[[],[]], + 'lambda': ResidualVSQP_truth, + 'plotterfunc': config2DScatter, + 'plotkwargs' : {'kwargs':{},'pckwargs':{'xlabel':"Q/P_truth",'ylabel':"Residual"}} + }, + 'NormalizedResidual':{ + 'array':[[],[]], + 'lambda': NormalizedResidual2, + 'plotterfunc': configMultiHist, + 'plotkwargs' : {'bins':20,'kwargs':{'range':[-10,11]},'label':['Positive','Negative'],'pckwargs':{'xscale':'linear','xlabel':"Residual",'legend':True}} + }, + 'AllTracksQP_reco':{ + 'array':[], + 'lambda': GetAllTrackQPReco, + 'plotterfunc': configBasicHist, + 'plotkwargs' :{'bins':100,'kwargs':{'range':[2*-10**-3,2*10**-3]}}, + }, + 'AllTracksQP_truth':{ + 'array':[], + 'lambda': GetAllTrackQPTruth, + 'plotterfunc': configBasicHist, + 'plotkwargs' :{'kwargs':{'range':[2*-10**-3,2*10**-3]}}, + }, + 'AllMomentum_Reco':{ + 'array':[], + 'lambda': GetAllTrackMomentum, + 'plotterfunc': configBasicHist, + 'plotkwargs' : {'pckwargs':{'xscale':'log'},'kwargs':{'range':[0,4000]}} + }, + 'AllTracksQP_reco':{ + 'array':[], + 'lambda': GetAllTrackQPReco, + 'plotterfunc': configBasicHist, + 'plotkwargs' :{'bins':50,'kwargs':{'range':[2*-10**-3,2*10**-3]}}, + 'lkwargs' : {'tar':2000*10**3} + }, + 'AllTracksTruthPmag':{ + 'array':[], + 'lambda': lambda event: list(event.tracksTruthPmag), + 'plotterfunc': configBasicHist, + 'plotkwargs' :{'bins':50,'pckwargs':{'xscale':'log'}}, + }, + 'NormalizedResidualSum':{ + 'array':[], + 'lambda': NormalizedResidual2, + 'plotterfunc': configBasicHist, + 'plotkwargs' : {'bins':20,'kwargs':{'range':[-10,11]},'pckwargs':{'xscale':'linear','xlabel':"Residual"}} + }, + 'CountSharedCluster_PassTrackCuts':{ + 'array':[], + 'lambda': CountSharedCluster, + 'lkwargs':{'filter':BoolDaughtersMatchedFiducial}, + 'plotterfunc': configBasicHist, + 'plotkwargs' : {'bins':25,'kwargs':{'range':[0,26]}}, + 'descr':'How many clusters have energy deposits from both daughter particles and pass track cuts?' + }, + 'CountSharedCluster_FailTrackCuts':{ + 'array':[], + 'lambda': CountSharedCluster, + 'lkwargs':{'filter':BoolDaughtersUnmatchedFiducial}, + 'plotterfunc': configBasicHist, + 'plotkwargs' : {'bins':25,'kwargs':{'range':[0,25]}}, + 'descr':'How many clusters have energy deposits from both daughter particles and fail track cuts?' + },} \ No newline at end of file