diff --git a/Tracker/TrackerRecAlgs/PairVertex/scripts/PairVertexReader.py b/Tracker/TrackerRecAlgs/PairVertex/scripts/PairVertexReader.py index ee1e0396d1fdfa62502c8761cd952a611aff29bb..27875efcac07a0b56d81c13129bd6eb0e72f31d9 100644 --- a/Tracker/TrackerRecAlgs/PairVertex/scripts/PairVertexReader.py +++ b/Tracker/TrackerRecAlgs/PairVertex/scripts/PairVertexReader.py @@ -108,7 +108,7 @@ def CountSharedCluster(event,filter=None): sharedcount=0 for c in range(len(event.clusterEFracPos)): if event.clusterETotPos[c]>0 and event.clusterETotNeg[c]>0 and event.clusterEFracPos[c]<0.99 and event.clusterEFracNeg[c]<0.99: sharedcount+=1 - if (filter and filter(event)) or not filter: + if not filter or filter(event): return sharedcount else: return nan @@ -143,10 +143,6 @@ def ClusterLocation(event): if event.clusterIsDaughter: starr+=[int(str(loc).split()[0])] return starr -def ClusterLocation2(event): - for loc in event.clusterLocation: - print(loc) - def MakeCompareArray(event,getvaluelambda,filters): val = getvaluelambda(event) countarr=[0 for i in range(len(filters))] @@ -156,6 +152,9 @@ def MakeCompareArray(event,getvaluelambda,filters): return countarr + +#BOOLEAN FUNCTIONS + def BoolDaughterCut(event): #both daughter particles are matched to tracks if event.TrackCount>=2 and len(event.tracksTruthBarcode)>=2: @@ -325,56 +324,50 @@ MainArrDict={ }, 'NumClusters':{ 'array':[], - 'lambda': lambda event: len(event.clusterLocation), + 'lambda': lambda event: event.clusterCount, 'plotterfunc': configBasicHist, - 'plotkwargs' :{}, + 'plotkwargs' :{'kwargs':{'range':[0,200]}}, + }, + 'NumClustersBool':{ + 'array':[], + 'lambda': lambda event: event.clusterCount<200, + 'plotterfunc': PrintBoolPercent, + 'plotkwargs' :{'kwargs':{'range':[0,200]}}, }, } - - #energy deposited hist - #frac of energy deposited hist - # - - - -TestArrDict=dict() -testname='AllClusterLocations' #Any key from MainArrDict -TestArrDict[testname]=MainArrDict[testname] -# for k in MainArrDict.keys(): -# if 'Check' in k: -# TestArrDict[k]=MainArrDict[k] +def MakePlotDict(entry): + TestArrDict=dict() + testname=entry #Any key from MainArrDict + TestArrDict[testname]=MainArrDict[testname] + return TestArrDict def GeneralPlotter(arrDict,dcuts=[],lcuts=[],showplot=True,savefig=False): nans=0 for event in t: - #ClusterLocation2(event) - if ApplyAllCuts(event,dcuts,lcuts): + if ApplyAllCuts(event,dcuts,lcuts): #Check that event passes given cuts before doing anything with it for name in arrDict.keys(): + #Get value that will go in arrray for plotting value=nan if 'lkwargs' in list(arrDict[name].keys()): value = arrDict[name]['lambda'](event,**arrDict[name]['lkwargs']) else: value = arrDict[name]['lambda'](event) + + #Check that all values to be added to the plot-array are valid checkReal=True if type(value)==list: checkReal = all([v != inf and v !=nan and v !=-1*inf for v in value]) else: checkReal = value != inf and value !=nan and value !=-1*inf - #if 'SepHist' in list(arrDict[name].keys()): checkReal=False - - if checkReal and type(value)==list: - if arrDict[name]['plotterfunc'] in [configBasicHist]: arrDict[name]['array']+=value - else: + #If the value is valid, add it to the plot array. + if checkReal and type(value)==list: + if arrDict[name]['plotterfunc'] in [configBasicHist]: arrDict[name]['array']+=value #when plotting on a subset of items like tracks instead of events + else: #MultiHist for iv in range(len(value)): arrDict[name]['array'][iv]+=[value[iv]] - elif checkReal: arrDict[name]['array']+=[value] - elif 'SepHist' in list(arrDict[name].keys()): - # if type(value[0])==list: - # for vi in range(len(value)): - # checkList=[v != inf and v !=nan and v !=-1*inf for v in value[vi]] - # for ivch in len(checkList): - # if checkList[ivch]: arrDict[name]['array'][vi]+=[value[vi][ivch]] - checkList=[v != inf and v !=nan and v !=-1*inf for v in value] + elif checkReal: arrDict[name]['array']+=[value] #Basic histogram + elif 'SepHist' in list(arrDict[name].keys()): #are subarrays allowed to have different lengths? + checkList=[v != inf and v !=nan and v !=-1*inf for v in value] #if yes, check each value returned for nans (may be nan if cut; actual nancount doesnt apply here) for ich in len(checkList): if checkList[ich]: arrDict[name]['array'][ich]+=[value[ich]] @@ -382,15 +375,16 @@ def GeneralPlotter(arrDict,dcuts=[],lcuts=[],showplot=True,savefig=False): print(f"# of NaNs:{nans}") for name in arrDict.keys(): - isPrintout= arrDict[name]['plotterfunc'] in [PrintBoolPercent] + isPrintout= arrDict[name]['plotterfunc'] in [PrintBoolPercent] #Is it text-only output? print(name) - print('LEN:',len(arrDict[name]['array'])) - arrDict[name]['plotterfunc']( arrDict[name]['array'], **arrDict[name]['plotkwargs']) + print('LEN:',len(arrDict[name]['array'])) #how many events remain after the cut? + arrDict[name]['plotterfunc']( arrDict[name]['array'], **arrDict[name]['plotkwargs']) #plot using the given function if not isPrintout: plt.title(user_input+name) if savefig: plt.savefig(user_input+name) if showplot: plt.show() + #EXECUTE if __name__ == "__main__": DP_fnames=['Ntuple_Aee_100MeV_1Em5_']# Ntuple_Aee_10MeV_1Em5_ Ntuple_Amm_316MeV_2Em6_ Ntuple_Aee_10MeV_1Em4_ @@ -401,5 +395,5 @@ if __name__ == "__main__": nfiles += t.Add("/eos/home-s/sshively/CALYPZONE/run/"+user_input+".root") print(f) - GeneralPlotter(TestArrDict,dcuts=[{}],lcuts=[]) + GeneralPlotter(MakePlotDict('CountSharedCluster_Compare'),dcuts=[{'clusterCount':[None,200,None,None]}],lcuts=[]) #print(GetPBounds(lcuts=[BoolDaughterCut])) diff --git a/Tracker/TrackerRecAlgs/PairVertex/scripts/PlotHelper.py b/Tracker/TrackerRecAlgs/PairVertex/scripts/PlotHelper.py index 5ebbdf55462c15b5d2f31ce8c326fdadaa41c298..bcb70ac0f785d5c5f2c1d6f988c93d3f229eeca6 100644 --- a/Tracker/TrackerRecAlgs/PairVertex/scripts/PlotHelper.py +++ b/Tracker/TrackerRecAlgs/PairVertex/scripts/PlotHelper.py @@ -25,10 +25,10 @@ def configHitMap(arrays,bins=(50,50),pckwargs={'xlabel':"X (mm)",'ylabel':"Y (mm if counts: plt.text(50,-185,"#EVENTS: {}".format(len(arrayx))) PlotConfigs(**pckwargs) -def configBasicHist(arr,bins=25,pckwargs={'xscale':'linear'},kwargs={}): +def configBasicHist(arr,bins=25,label=None,pckwargs={'xscale':'linear'},kwargs={}): #1D Histogram if 'log' in pckwargs['xscale']: bins=CorrectBinsForLog(arr,bins,pckwargs['xscale']) - n, binsOut, patches = plt.hist(arr,bins=bins,align="left",histtype=u'step',**kwargs) + n, binsOut, patches = plt.hist(arr,bins=bins,label=label,align="left",histtype=u'step',**kwargs) PlotConfigs(**pckwargs) return n,binsOut diff --git a/Tracker/TrackerRecAlgs/PairVertex/src/PairVertexAlg.cxx b/Tracker/TrackerRecAlgs/PairVertex/src/PairVertexAlg.cxx index de4341798db3b341c88b3fd7ba776e171b3e5763..dc19cb211c06f92b909a48728d38fed48afb0011 100644 --- a/Tracker/TrackerRecAlgs/PairVertex/src/PairVertexAlg.cxx +++ b/Tracker/TrackerRecAlgs/PairVertex/src/PairVertexAlg.cxx @@ -195,9 +195,15 @@ StatusCode PairVertexAlg::initialize() m_tree->Branch("clusterETot", &m_clusterETot); m_tree->Branch("clusterETotPos", &m_clusterETotPos); m_tree->Branch("clusterETotNeg", &m_clusterETotNeg); - m_tree->Branch("clusterLocation", &m_clusterLocation); m_tree->Branch("clusterIsDaughter", &m_clusterIsDaughter); + m_tree->Branch("clusterLocStation", &m_clusterLocStation); + m_tree->Branch("clusterLocLayer", &m_clusterLocLayer); + m_tree->Branch("clusterLocPhiMod", &m_clusterLocPhiMod); + m_tree->Branch("clusterLocEtaMod", &m_clusterLocEtaMod); + m_tree->Branch("clusterLocSide", &m_clusterLocSide); + + @@ -463,7 +469,6 @@ StatusCode PairVertexAlg::execute(const EventContext &ctx) const float TotalEnergyDeposited_daughterPos=0; float TotalEnergyDeposited_daughterNeg=0; bool isDaughter=false; - std::string clusterLocation = std::to_string(m_idHelper->station(clusterID))+' '+std::to_string(m_idHelper->layer(clusterID))+' '+std::to_string(m_idHelper->phi_module(clusterID))+' '+std::to_string(m_idHelper->eta_module(clusterID))+' '+std::to_string(m_idHelper->side(clusterID)); //loop over all RDOs in the cluster for (auto rdoID : clusterRDOList) @@ -499,7 +504,6 @@ StatusCode PairVertexAlg::execute(const EventContext &ctx) const m_clusterETotPos.push_back(TotalEnergyDeposited_daughterPos); m_clusterETotNeg.push_back(TotalEnergyDeposited_daughterNeg); m_clusterETot.push_back(TotalEnergyDeposited); - m_clusterLocation.push_back(clusterLocation); m_clusterIsDaughter.push_back(isDaughter); if (TotalEnergyDeposited>0) { @@ -511,7 +515,15 @@ StatusCode PairVertexAlg::execute(const EventContext &ctx) const m_clusterEFracPos.push_back(NaN); m_clusterEFracNeg.push_back(NaN); } + m_clusterLocStation.push_back(m_idHelper->station(clusterID)); + m_clusterLocLayer.push_back(m_idHelper->layer(clusterID)); + m_clusterLocPhiMod.push_back(m_idHelper->phi_module(clusterID)); + m_clusterLocEtaMod.push_back(m_idHelper->eta_module(clusterID)); + m_clusterLocSide.push_back(m_idHelper->side(clusterID)); + + clustercount++; + } m_clusterCount=clustercount; @@ -608,9 +620,14 @@ void PairVertexAlg::clearTree() const m_clusterETot.clear(); m_clusterETotPos.clear(); m_clusterETotNeg.clear(); - m_clusterLocation.clear(); m_clusterIsDaughter.clear(); + m_clusterLocStation.clear(); + m_clusterLocLayer.clear(); + m_clusterLocPhiMod.clear(); + m_clusterLocEtaMod.clear(); + m_clusterLocSide.clear(); + } } // end Tracker diff --git a/Tracker/TrackerRecAlgs/PairVertex/src/PairVertexAlg.h b/Tracker/TrackerRecAlgs/PairVertex/src/PairVertexAlg.h index 44442898e81699bfdbcc1718befb4da6aaa56545..6c91d42061be43b6cc115bdcb4d50a0bc3d8af7b 100644 --- a/Tracker/TrackerRecAlgs/PairVertex/src/PairVertexAlg.h +++ b/Tracker/TrackerRecAlgs/PairVertex/src/PairVertexAlg.h @@ -211,8 +211,15 @@ namespace Tracker mutable std::vector<float> m_clusterETot; mutable std::vector<float> m_clusterETotPos; mutable std::vector<float> m_clusterETotNeg; - mutable std::vector<std::string> m_clusterLocation; mutable std::vector<bool> m_clusterIsDaughter; + + mutable std::vector<int> m_clusterLocStation; + mutable std::vector<int> m_clusterLocLayer; + mutable std::vector<int> m_clusterLocPhiMod; + mutable std::vector<int> m_clusterLocEtaMod; + mutable std::vector<int> m_clusterLocSide; + +