diff --git a/DrawHits/FitHistogram.py b/DrawHits/FitHistogram.py new file mode 100644 index 0000000..39470fa --- /dev/null +++ b/DrawHits/FitHistogram.py @@ -0,0 +1,438 @@ +import ROOT + +class FitHistogram: + ''' Helper class to extract various quantities from a 1D histogram + ''' + def interpolate(y,y1,y2,x1=0.,x2=1.): + ''' Linear interpolation between two points (x1,y1) and (x2,y2) + to yield x corresponding to the target value y. + ''' + return x1 + (y-y1)/(y2-y1)*(x2-x1) + + def __init__(self,histogram): + ''' Store input histogram and prepare caches for various intermediate quantities + ''' + self.hist = histogram + self.graph_ = None + self.cumulativeGraph_ = None + self.cumNormGraph_ = None + self.cumNormTGraph_ = None + self.cumNormSpline_ = None # spline corresponding to normalized cumulative graph + + def graph(self): + ''' Histogram converted to list of (x,y) coordinates with x = bin center and y = bin contents. + Ignores under- / overflow. + ''' + if self.graph_==None: + self.graph_ = [ ] + + for i in range(self.hist.GetNbinsX()): + xbin = self.hist.GetBinLowEdge(i+1) + self.hist.GetBinWidth(i+1)/2. + self.graph_.append( (xbin,self.hist.GetBinContent(i+1)) ) + + return self.graph_ + + def cumulativeGraph(self): + ''' Histogram converted to list of (x,y) coordinates with x = bin center and y = cumulated bin contents. + Ignores under- / overflow. + ''' + if self.cumulativeGraph_==None: + self.cumulativeGraph_ = [ ] + sum = 0. + for i in range(self.hist.GetNbinsX()): + xbin = self.hist.GetBinLowEdge(i+1) + self.hist.GetBinWidth(i+1)/2. + sum += self.hist.GetBinContent(i+1) + self.cumulativeGraph_.append( (xbin,sum) ) + + return self.cumulativeGraph_ + + def cumulativeNormGraph(self): + ''' Histogram converted to list of (x,y) coordinates with x = bin center and y = cumulated bin contents. + Normalized to total histogram contents (including under- / overflow). + ''' + if self.cumNormGraph_==None: + cg = self.cumulativeGraph() + sum = self.hist.GetSumOfWeights() + self.cumNormGraph_ = [ ( x,y/sum ) for x,y in cg ] + + return self.cumNormGraph_ + + def cumulativeNormSpline(self): + ''' Create (TGraph and) TSpline3 from cumulativeNormGraph + ''' + if self.cumNormTGraph_==None: + self.cumNormTGraph_ = ROOT.TGraph() + for x,y in self.cumulativeNormGraph(): + self.cumNormTGraph_.SetPoint(self.cumNormTGraph_.GetN(),x,y) + + if self.cumNormSpline_==None: + self.cumNormSpline_ = ROOT.TSpline3(self.hist.GetName()+"-spline",self.cumNormTGraph_) + + return self.cumNormSpline_ + + + def intersects(self,value,cumulative=False,norm=False,direction=0): + ''' Calculate x-coordinates for intersection(s) of a graph defined by a list of (x,y) points sorted in x + with y==value. Uses linear interpolation. + Arguments: + value ....... target value + cumulative .. if true, use cumulative graph + norm ........ if true, use normalized cumulative graph + direction ... three possible values: 0 = any intersection, +1/-1 = consider only segments + with positive / negative slope. + ''' + # + # Get graph and do basic check + # + graph = None + if cumulative: + graph = self.cumulativeNormGraph() if norm else self.cumulativeGraph() + else: + assert norm==False + graph = self.graph() + + result = [ ] + if len(graph)<2: + return result + # + # loop over adjacent pairs of points + # + x1 = None + y1 = None + for x2,y2 in graph: + # + # start checking at 2nd point + # + if x1!=None: + assert x2>x1 + # + # value in interval? + # + if value>=min(y1,y2) and value<=max(y1,y2): + # check if dy is positive or negative, and compare with required sign of direction + if direction==0 or direction*(y2-y1)>0: + result.append(FitHistogram.interpolate(value,y2,y1,x2,x1)) + # + # move to next point + # + x1 = x2 + y1 = y2 + + return result + + def fwhm(self): + ''' Return lowest / highest x corresponding to ymax/2, and ymax/2 + ''' + # + # target y value (1/2 maximum) + # + y = self.hist.GetBinContent(self.hist.GetMaximumBin())/2. + # + # use first intersection with upward slope + # + xups = self.intersects(y,cumulative=False,direction=1) + #print("xups",xups) + xlow = xups[0] if xups else None + # + # use last intersection with downward slope + # + xdowns = self.intersects(y,cumulative=False,direction=-1) + #print("xdowns",xdowns) + xhigh = xdowns[-1] if xdowns else None + + # + # require result ( assumes that first and last bins are < ymax/2 ) and + # correct for bin width / 2 ( assumes that bin value corresponds to center of bin ) + assert xlow!=None and xhigh!=None + return (xlow,xhigh,y) + #return (xlow+dx,xhigh+dx,y) + + def quantile(self,prob): + ''' Return x-value to quantile q. + ''' + # + # basic check - refuse to calculate quantile for probabilities beyond 1st / last non-empty bin + # + # use tail probability + # + nb = self.hist.GetNbinsX() + sumw = self.hist.GetSumOfWeights() + if prob<=0.5: + # check first non-empty bin from low -> high + cmax = prob*sumw + rng = range(1,nb+1) + else: + # check first non-empty bin from high -> low + cmax = (1-prob)*sumw + rng = range(nb,0,-1) + # find first non-empty bin + for ib in rng: + c = self.hist.GetBinContent(ib) + if c>1.e-10: + # return invalid result if first bin exceeds the threshold + if c>cmax: + #print("<<<",self.hist.GetName(),prob,nb,cmax,range,ib,c) + return None + break + # + # now determine quantile + # + result = self.intersects(prob,cumulative=True,norm=True,direction=1) + #print(prob,result) + if len(result)>1: + result = None + + return result[0] if result else None + + def findRootSpline(self,value,eps=0.001): + ''' Find position where spline derived from cumulative NormGraph= value. Assumes that the spline is \ + monotonously increasing. Tolerance is eps*value or cGraph[-1][1]=ymax: + print("findRootSpline: last value <= first value") + return None + # + # Check if inside values spanned by spline + # + if valueymax: + print("findRootSpline: required value outside range") + return None + # + # tolerance for distance between points + # + dxmax = eps*(ymax-ymin) + # + # loop with cutoff in case of non-convergence + # + found = False + for i in range(1000): + if (xh-xl)prob1 + result = ( None, None ) + xmin = self.hist.GetXaxis().GetXmin() + if prob1>0.: + xmin = self.findRootSpline(prob1) + if xmin==None: + return result + xmax = self.hist.GetXaxis().GetXmax() + if prob2<1.: + xmax = self.findRootSpline(prob2) + if xmin==None: + return result + + fitFunc = ROOT.TF1("mygaus","gaus(0)",xmin,xmax) + fitFunc.SetParameter(0,self.hist.GetMaximum()) + fitFunc.SetParameter(1,0.) + fitFunc.SetParLimits(1,-10.,10.) + fitFunc.SetParameter(2,self.hist.GetRMS()) + + fitPtr = self.hist.Fit(fitFunc,"S0") + #fitPtr = self.hist.Fit("gaus","S0","",xmin,xmax) + if ( not fitPtr.IsValid() ) or fitPtr.IsEmpty(): + return result + + #return fitPtr,self.hist.GetFunction("gaus") + return fitPtr,fitFunc + + +if __name__=="__main__": + # + # test of fitting for my canvases + # + import sys + from math import sqrt,log + from fnmatch import fnmatch + import argparse + + def fromQuantiles(fitHisto,isig): + xqs = [ ] + for sgn in [ -1, 0, 1 ]: + xqs.append(fitHisto.quantile(ROOT.TMath.Freq(sgn*isig))) + if None in xqs: + return None + return [ ( xqs[1], 0. ), ( (xqs[2]-xqs[0])/2./isig, 0. ) ] + + parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument('--list', '-l', help='list pads / histograms', action='store_true', default=False) + parser.add_argument('--algorithms', '-a', help='comma-separated list of algorithms used for fit results', \ + type=str, default='prefit' ) + parser.add_argument('--padName', help='pad name (fnmatch pattern)', type=str, default='*') + parser.add_argument('--histogramName', help='histogram name (fnmatch pattern)', type=str, default='*') + parser.add_argument('file', help='root file', type=str, nargs=1) + args = parser.parse_args() + + # + # select pad and histogram + # + mainPads = [ ] + tf = ROOT.TFile(args.file[0]) + + for k in tf.GetListOfKeys(): + oName = k.GetName() + o = tf.Get(oName) + if o.InheritsFrom(ROOT.TVirtualPad.Class()): + mainPads.append(o) + assert len(mainPads)==1 + + selectedPads = [ ] + for p in mainPads[0].GetListOfPrimitives(): + oName = p.GetName() + if args.list or fnmatch(oName,args.padName): + selectedPads.append(p) + if not args.list: + assert len(selectedPads)==1 + + selectedHistograms = [ ] + for p in selectedPads: + if args.list: + print("Pad ",p.GetName(),":") + for o in p.GetListOfPrimitives(): + if o.InheritsFrom(ROOT.TH1.Class()) and o.GetDimension()==1: + oName = o.GetName() + if args.list: + print(" Histogram 1D ",oName,type(o)) + if fnmatch(oName,args.histogramName): + selectedHistograms.append(o) + + if args.list: + sys.exit(0) + + selPad = selectedPads[0] + + assert len(selectedHistograms)==1 + + ROOT.gROOT.cd() + cnv = ROOT.TCanvas("c","c",800,800) + if selPad.GetLogy(): + cnv.SetLogy(1) + padHisto = selectedHistograms[0].Clone() + fitHisto = FitHistogram(padHisto) + padHisto.SetLineWidth(1) + padHisto.SetMarkerStyle(20) + padHisto.Draw("LP") + cnv.SetGridx(1) + cnv.SetGridy(1) + cnv.Update() + tf.Close() + + result = None + fitHisto = FitHistogram(padHisto) + + + # + # FWHM + # + xmin,xmax,y = fitHisto.fwhm() + result = [ ( (xmax+xmin)/2., 0. ), ( (xmax-xmin)/2/sqrt(2*log(2.)), 0. ) ] + print("FWHM",[ x[0] for x in result ]) + fwhmArrow = ROOT.TArrow() + fwhmArrow.SetLineColor(2) + fwhmArrow.SetLineWidth(3) + fwhmArrow.DrawArrow(xmin,y,xmax,y,0.005,"<>") + # + # prefit + # + gaus = None + for f in padHisto.GetListOfFunctions(): + if f.GetName()=="gaus": + assert gaus==None + gaus = f + #gaus = f.Clone() + n = gaus.GetNpar() + assert n==3 + result = [ ] + for i in range(1,3): + result.append((gaus.GetParameter(i),gaus.GetParError(i))) + gaus.SetLineColor(ROOT.kCyan) + #gaus.Draw() + print("Prefit",[ x[0] for x in result ]) + # + # gaus fit + # + fitPtr,fitFunc = fitHisto.fitGaus() + result = [ ] + if fitPtr!=None: + for i in range(1,3): + result.append((fitPtr.Parameter(i),fitPtr.ParError(i))) + if fitFunc!=None: + print(fitFunc.GetParameter(0),fitFunc.GetParameter(1),fitFunc.GetParameter(2)) + fitFunc.SetLineColor(ROOT.kMagenta) + fitFunc.SetLineWidth(3) + fitFunc.Draw("same") + print("Gaus fit",[ x[0] for x in result ]) + # + # quantiles (1 sigma equivalent) + # + quantLines = [ ] + quantColors = [ ROOT.kBlack, ROOT.kBlue, 8, ROOT.kRed ] + for i in range(4): + quantLine = ROOT.TLine() + #quantLine.SetLineColor(4-i) + quantLine.SetLineColor(quantColors[i]) + #quantLine.SetLineColor(4-i) + quantLine.SetLineWidth(3) + quantLine.SetLineStyle(2) + #quantLine.SetLineStyle(i+1) + quantLines.append(quantLine) + for isigma,sigma in enumerate([1,2,3]): + qs = [ ] + for sgn in [-1,0,1]: + p = ROOT.TMath.Freq(sgn*sigma) + qs.append(fitHisto.findRootSpline(p)) + #print(sigma,sgn,type(fitHisto)) + #print(sigma,sgn,p,qs[-1]) + #print(isigma,sigma,qs) + result = fromQuantiles(fitHisto,sigma) + if result!=None: + print("Sig",sigma,[ x[0] if x!=None else None for x in result ]) + else: + print("Sig",result) + + for iq in range(3): + il = 0 if iq==1 else isigma+1 + qlmax = padHisto.GetBinContent(padHisto.FindBin(qs[iq])) + quantLines[il].DrawLine(qs[iq],0.,qs[iq],qlmax) + #if iq==0: + # line = " from sigma = {:3.1f} quantile: ".format(sigma) + # line += "median = {:6.1f}um, half-width/sigma = {:6.1f}um".format(10000*qs[1], \ + # 10000*(qs[2]-qs[0])/2/sigma) + # print(line) + + cnv.Update() + diff --git a/DrawHits/compareHistogramConfigs.py b/DrawHits/compareHistogramConfigs.py new file mode 100644 index 0000000..9865e7b --- /dev/null +++ b/DrawHits/compareHistogramConfigs.py @@ -0,0 +1,95 @@ +import sys,os +import subprocess +import csv + +allFiles = { } +allDirs = set() +# +# loop over directories with text files +# +for d in sys.argv[1:]: + # + # assume last part of directory name is unique + # + dn = os.path.basename(os.path.normpath(d)) + assert not dn in allDirs + allDirs.add(dn) + # + # retrieve cksums for all text files + # + filePattern = os.path.join(d,"*.txt") + result = subprocess.run("cksum "+filePattern, text=True, capture_output=True, shell=True) + result.check_returncode() + # + # loop over output + # + for l in result.stdout.split(chr(10)): + if l=="": + continue + # + # decode output line + # + fields = l.split() + assert len(fields)==3 + cksum = int(fields[0]) + size = int(fields[1]) + name = os.path.splitext(os.path.basename(fields[2]))[0] + # + # store result by name ( directory, cksum, and size ) + # + if not name in allFiles: + allFiles[name] = [ ( dn, cksum, size ) ] + else: + allFiles[name].append( ( dn, cksum, size ) ) +# +allDirs = sorted(allDirs) +# +# write result to output file +# +with open("compareHistogramConfigs.csv","wt") as csvFile: + csvwriter = csv.writer(csvFile) + # header row 1 + row = [ "Name" ] + for d in allDirs: + row.extend([ d, "", "" ]) + row.append("#ids") + row.append("#dirs") + csvwriter.writerow(row) + # header row 2 + row = [ "" ] + for d in allDirs: + row.extend([ "size", "cksum", "id" ]) + row.append("") + row.append("") + csvwriter.writerow(row) + # + # loop over all definitions + # + for n in sorted(allFiles.keys()): + # + row = [ n ] + # + # create list of all unique file ids (defined by size and cksum) + # + cksums = set([ ( x[2], x[1] ) for x in allFiles[n] ]) + cksums = sorted(cksums) + # + # add information for each directory + # + for dn in allDirs: + rowExt = [ "", "", "" ] + # + # (try to) find directory in list for this name + # + for d,c,s in allFiles[n]: + if d==dn: + idx = cksums.index((s,c)) + rowExt = [s,c,idx] + break + row.extend(rowExt) + # + row.append(len(cksums)) + row.append(len(allFiles[n])) + csvwriter.writerow(row) + csvFile.close() + diff --git a/DrawHits/drawHits.py b/DrawHits/drawHits.py index 3748b9f..a140072 100755 --- a/DrawHits/drawHits.py +++ b/DrawHits/drawHits.py @@ -254,6 +254,8 @@ def fillHistoByDef(tree,hDef,extraCuts): if hDef.vetoMType(mType): continue is1D = hDef.getParameter('yNbins',mType)==None + is2D = hDef.getParameter('yNbins',mType)!=None and hDef.getParameter('zNbins',mType)==None + is3D = hDef.getParameter('yNbins',mType)!=None and hDef.getParameter('zNbins',mType)!=None isProfile = hDef.getParameter('profile',mType)!=None and hDef.getParameter('profile',mType) effCuts = hDef.getParameter('effCuts',mType) variable = hDef.getParameter('variable',mType) @@ -278,6 +280,7 @@ def fillHistoByDef(tree,hDef,extraCuts): tree.Project(hName+"_2",variable, \ cutString(extraCuts,hDef.getParameter('baseCuts',mType),"moduleType=="+str(mType),effCuts)) histos[mType][3] = ROOT.TEfficiency(histos[mType][1],histos[mType][0]) + histos[mType][3].SetMarkerStyle(20) else: # always keep final histogram in 4th position histos[mType][3] = histos[mType][0] @@ -290,7 +293,7 @@ def fillHistoByDef(tree,hDef,extraCuts): cutString(extraCuts,hDef.getParameter('baseCuts',mType),"moduleType=="+str(mType))) # always keep final histogram in 4th position histos[mType][3] = histos[mType][0] - else: + elif is2D: nby = hDef.getParameter('yNbins',mType) ymin = hDef.getParameter('yMin',mType) ymax = hDef.getParameter('yMax',mType) @@ -310,13 +313,27 @@ def fillHistoByDef(tree,hDef,extraCuts): else: # always keep final histogram in 4th position histos[mType][3] = histos[mType][0] + elif is3D: + nby = hDef.getParameter('yNbins',mType) + ymin = hDef.getParameter('yMin',mType) + ymax = hDef.getParameter('yMax',mType) + nbz = hDef.getParameter('zNbins',mType) + zmin = hDef.getParameter('zMin',mType) + zmax = hDef.getParameter('zMax',mType) + histos[mType] = [ ROOT.TH3F(hName+"_1",hName+"_1",nbx,xmin,xmax,nby,ymin,ymax,nbz,zmin,zmax), \ + None, None, None ] + tree.Project(hName+"_1",variable, \ + cutString(extraCuts,hDef.getParameter('baseCuts',mType),"moduleType=="+str(mType))) + assert effCuts==None + # always keep final histogram in 4th position + histos[mType][3] = histos[mType][0] #print("Ending for ",hDef.name,hName,hTitle) savedDir.cd() return histos -def drawHistoByDef(histos,hDef,logY=False,same=False): +def drawHistoByDef(histos,hDef,logY=False,logZ=False,same=False): result = { 'cnv' : None, 'histos' : histos, 'pave' : None } savedDir = ROOT.gDirectory @@ -344,6 +361,8 @@ def drawHistoByDef(histos,hDef,logY=False,same=False): if hDef.vetoMType(mType): continue is1D = hDef.getParameter('yNbins',mType)==None + is2D = hDef.getParameter('yNbins',mType)!=None and hDef.getParameter('zNbins',mType)==None + is3D = hDef.getParameter('yNbins',mType)!=None and hDef.getParameter('zNbins',mType)!=None isProfile = hDef.getParameter('profile',mType)!=None and hDef.getParameter('profile',mType) effCuts = hDef.getParameter('effCuts',mType) variable = hDef.getParameter('variable',mType) @@ -362,6 +381,7 @@ def drawHistoByDef(histos,hDef,logY=False,same=False): xmax = hDef.getParameter('xMax',mType) ytitle = hDef.getParameter('yTitle',mType) if hDef.getParameter('yTitle',mType) else "" + ztitle = hDef.getParameter('zTitle',mType) if hDef.getParameter('zTitle',mType) else "" if is1D and ( not isProfile ): ymin = hDef.getParameter('yMin',mType) if hDef.getParameter('yMin',mType)!=None else 0. ymax = hDef.getParameter('yMax',mType) if hDef.getParameter('yMax',mType)!=None else 1.05 @@ -372,13 +392,16 @@ def drawHistoByDef(histos,hDef,logY=False,same=False): histos[mType][2].GetXaxis().SetTitle(xtitle) histos[mType][2].GetYaxis().SetTitle(ytitle) histos[mType][3] = ROOT.TEfficiency(histos[mType][1],histos[mType][0]) - histos[mType][3].SetMarkerSize(0.3) + histos[mType][3].SetMarkerStyle(20) histos[mType][3].Draw("same Z") else: histos[mType][0].SetTitle(hTitle) histos[mType][0].GetXaxis().SetTitle(xtitle) histos[mType][0].GetYaxis().SetTitle(ytitle) histos[mType][0].Draw("same" if same else "") + fitFunc = hDef.getParameter('fit') + if fitFunc!=None: + histos[mType][0].Fit(fitFunc,"Q","same") elif isProfile: histos[mType][0].SetTitle(hTitle) histos[mType][0].GetXaxis().SetTitle(xtitle) @@ -387,7 +410,7 @@ def drawHistoByDef(histos,hDef,logY=False,same=False): #histos[mType][0].SetFillColor(ROOT.TColor.GetColorBright(ROOT.kGray)) #histos[mType][0].SetFillColor(ROOT.kGray) histos[mType][0].Draw("same" if same else "") - else: + elif is2D: assert not same zmin = hDef.getParameter('zMin',mType) if hDef.getParameter('zMin',mType)!=None else 0. zmax = hDef.getParameter('zMax',mType) if hDef.getParameter('zMax',mType)!=None else 1.05 @@ -403,8 +426,20 @@ def drawHistoByDef(histos,hDef,logY=False,same=False): histos[mType][0].GetXaxis().SetTitle(xtitle) histos[mType][0].GetYaxis().SetTitle(ytitle) histos[mType][0].Draw("ZCOL") + elif is3D: + assert not same + zmin = hDef.getParameter('zMin',mType) if hDef.getParameter('zMin',mType)!=None else 0. + zmax = hDef.getParameter('zMax',mType) if hDef.getParameter('zMax',mType)!=None else 1.05 + assert effCuts==None + histos[mType][0].SetTitle(hTitle) + histos[mType][0].GetXaxis().SetTitle(xtitle) + histos[mType][0].GetYaxis().SetTitle(ytitle) + histos[mType][0].GetZaxis().SetTitle(ztitle) + histos[mType][0].Draw() if logY or hDef.getParameter('logY',mType): ROOT.gPad.SetLogy(1) + if is2D and ( logZ or hDef.getParameter('logZ',mType) ): + ROOT.gPad.SetLogz(1) ROOT.gPad.Update() #cnv.cd() @@ -484,10 +519,13 @@ def addHistogram(varString,cuts,effCuts=None,name='userHist'): type=str, default='*') parser.add_argument('--vetoedHistograms', help='comma-separated names of histogram definitions not to be used', type=str, default='') -parser.add_argument('--logY', help='use log scale', action='store_true', default=False) +parser.add_argument('--logY', help='use log scale for y axis', action='store_true', default=False) +parser.add_argument('--logZ', help='use log scale for z axis', action='store_true', default=False) parser.add_argument('--printTree', '-p', help='print TTree contents', action='store_true', default=False) parser.add_argument('--listHistograms', '-l', help='list predefined and selected histograms', \ action='store_true', default=False) +parser.add_argument('--zone', '-z', help='restrict to zone in OT (barrel, tilted, endcap)', type=str, \ + choices=['barrel','tilted','endcap'], default=None) parser.add_argument('file', help='input file', type=str, nargs='+', default=None) args = parser.parse_args() outputFormats = [ ] @@ -498,6 +536,19 @@ def addHistogram(varString,cuts,effCuts=None,name='userHist'): fitResiduals = args.fitResiduals.split(",") if args.fitResiduals else [ ] selectedHistoNames = args.selectedHistograms.split(",") vetoedHistoNames = args.vetoedHistograms.split(",") +# +# add cut for zone definition? +# +if args.zone=="barrel": + zoneCuts = "detNormal.Rho()>0.99" +elif args.zone=="endcap": + zoneCuts = "detNormal.Rho()<0.01" +elif args.zone=="tilted": + zoneCuts = "detNormal.Rho()>0.05&&detNormal.Rho()<0.095" +else: + zoneCuts = "" +args.cuts = cutString(args.cuts,zoneCuts) + # # load histogram definitions # @@ -591,7 +642,8 @@ def addHistogram(varString,cuts,effCuts=None,name='userHist'): for hName in allHDefs.byCanvas[cName]: print("Processing histogram",hName,"in canvas",cName) cHistos[hName] = fillHistoByDef(simHitTree,allHDefs.byCanvas[cName][hName],extraCuts) - allObjects.append(drawHistoByDef(cHistos[hName],allHDefs.byCanvas[cName][hName],logY=args.logY,same=same)) + allObjects.append(drawHistoByDef(cHistos[hName],allHDefs.byCanvas[cName][hName], \ + logY=args.logY,logZ=args.logZ,same=same)) same = True if args.output!=None: c = allObjects[-1]['cnv'] @@ -599,6 +651,8 @@ def addHistogram(varString,cuts,effCuts=None,name='userHist'): basename = os.path.join(args.output,c.GetName()) if args.sampleName!=None: basename += "_" + args.sampleName + if args.zone!=None: + basename += "_" + args.zone print(basename) for fmt in outputFormats: c.SaveAs(basename+"."+fmt) diff --git a/HitAnalyzer/test/histogramDefinition.py b/DrawHits/drawHitsConfiguration.py similarity index 51% rename from HitAnalyzer/test/histogramDefinition.py rename to DrawHits/drawHitsConfiguration.py index 8bfc321..c8b8095 100644 --- a/HitAnalyzer/test/histogramDefinition.py +++ b/DrawHits/drawHitsConfiguration.py @@ -1,20 +1,30 @@ # # Definitions for histograms from a configuration file # +import yaml from fnmatch import fnmatch class HistogramDefinition: ''' A single histogram definition. ''' - reqGenFields = [ 'canvasName', 'histogramName', 'histogramTitle', 'variable', 'baseCuts' ] + # fields that have to be present in the general section + reqGenFields = [ 'canvasName' ] + # fields that have to be present in a histogram section reqHistFields = [ ] - requiredFields = reqGenFields + reqHistFields - optGenFields = [ 'effCuts', 'logY' ] - optHistFields = [ 'xNbins', 'xMin', 'xMax', 'xTitle', 'yTitle', 'yNbins', 'yMin', 'yMax', \ - 'zMin', 'zMax', 'display', 'profile' ] - optionalFields = optGenFields + optHistFields - allFields = requiredFields + optionalFields - allHistFields = reqHistFields + optHistFields + requiredFields = list(set(reqGenFields + reqHistFields)) + # optional fields in the general section + optGenFields = [ 'variable', 'baseCuts', 'effCuts', 'logY', 'logZ' ] + # optional fields in the histogram section + optHistFields = [ 'variable', 'histogramName', 'histogramTitle', 'fit', \ + 'xNbins', 'xMin', 'xMax', 'xTitle', 'yTitle', 'zTitle', \ + 'yNbins', 'yMin', 'yMax', \ + 'zNbins', 'zMin', 'zMax', 'display', 'profile' ] + optionalFields = list(set(optGenFields + optHistFields)) + allFields = list(set(requiredFields + optionalFields)) + allHistFields = list(set(reqHistFields + optHistFields)) + # fields that cannot be present for a single module type + vetoMtypeFields = [ 'variable', 'baseCuts', 'effCuts', 'profile' ] + vetoMtypeFields = [ 'profile' ] def __init__(self,name,inputDict): ''' Define histogram and drawing parameters from dictionary. @@ -98,6 +108,9 @@ def getParameter(self,name,mType=None): if ( mTName in self.parameters ) and ( name in self.parameters[mTName] ): result = self.parameters[mTName][name] if result!=None: + # check for parameters that can only be general + if name in HistogramDefinition.vetoMtypeFields: + raise Exception('Parameter '+name+' cannot be present in the section for an individual module type') return self.parameters[mTName][name] # # not found: use general parameter @@ -106,6 +119,11 @@ def getParameter(self,name,mType=None): return self.parameters[name] return None + def __call__(self,name,mType=None): + ''' Make access to parameters easier - use function call + ''' + return self.getParameter(name,mType) + def vetoMType(self,mType): ''' Check for an mType entry with display = False ''' @@ -151,29 +169,124 @@ def __getitem__(self,name): return self.allDefinitions[name] return None -def loadHistogramDefinitions(configName,selectedNames=[],vetoedNames=[]): - ''' Load histogram definitions from a configuration file. The configuration file +class VarMaskCombinations: + ''' Combinations of a variable and a mask for use with RDF.Histo*. + ''' + def __init__(self): + # + # variable+mask name indexed by variable+selection string + # + self.varMaskDefinitions = { } + + def __call__(self,rdf,varName,selection): + ''' Return the name of a variable+mask combination. Define if necessary. + Arguments: + rdf ........ RDataFrame to be used for definition + varName .... name of the variable + selection .. selection string to be used as mask + ''' + # + # use variable name and normalized selection string (remove spaces) + # + selNorm = selection.replace(" ","") + varMask = "(" + varName + ")["+selNorm+"]" + if varMask in self.varMaskDefinitions: + # combination exists (assume that it's also defined in the RDataFrame) + varMaskName = self.varMaskDefinitions[varMask] + assert varMaskName in rdf.GetDefinedColumnNames() + else: + # create name for combination and define it in the RDataFrame + n = len(self.varMaskDefinitions) + varMaskName = "varMask{:03d}".format(n) + self.varMaskDefinitions[varMask] = varMaskName + rdf = rdf.Define(varMaskName,varMask) + #print("+++ defined new var + mask combinations:",varMaskName,varMask) + #print(rdf.GetDefinedColumnNames()) + #print("+++") + return rdf,varMaskName + +class RDFWrapper: + ''' Wrapper of RDataFrame with possibility to define variable+mask combinations + ''' + def __init__(self,rdf): + # + # variable+mask name indexed by variable+selection string + # + self.rdf = rdf + self.varMaskDefinitions = { } + + def __call__(self): + ''' Easy access to RDataFrame + ''' + return self.rdf + + def defineVarMask(self,varName,selection): + ''' Return the name of a variable+mask combination. Define if necessary. + Arguments: + rdf ........ RDataFrame to be used for definition + varName .... name of the variable + selection .. selection string to be used as mask + ''' + # + # use variable name and normalized selection string (remove spaces) + # + selNorm = selection.replace(" ","") + varMask = "(" + varName + ")["+selNorm+"]" + if varMask in self.varMaskDefinitions: + # combination exists (assume that it's also defined in the RDataFrame) + varMaskName = self.varMaskDefinitions[varMask] + assert varMaskName in self.rdf.GetDefinedColumnNames() + else: + # create name for combination and define it in the RDataFrame + n = len(self.varMaskDefinitions) + varMaskName = "varMask{:03d}".format(n) + self.varMaskDefinitions[varMask] = varMaskName + self.rdf = self.rdf.Define(varMaskName,varMask) + #print("+++ defined new var + mask combinations:",varMaskName,varMask) + #print(rdf.GetDefinedColumnNames()) + #print("+++") + return varMaskName + + +def loadConfiguration(configName,selectedNames=[],vetoedNames=[]): + ''' Load variable and histogram definitions from a configuration file. The configuration file + is expected to contain a "variables" and a "histograms" section. The "histogram" section defines dictionaries with the definitions as variable. The name of the variable serves as name of the HistogramDefinition. Arguments: configName ..... name of the module to import from / python file name selectedNames .. explicit list of histogram names to be imported (filename wildcard syntax) vetoedNames .... explicit list of histogram names to be skipped (filename wildcard syntax) + Result: + Tuple with dictionary of variable definitions and HistogramDefinitions object ''' # load histogram definitions # - result = HistogramDefinitions() + vDefs = { } + hDefs = HistogramDefinitions() if configName==None: - return result + return ( vDefs, hDefs ) - moduleName = configName[:-3] if configName.endswith(".py") else configName - module = __import__(moduleName) - for n in dir(module): - if n.startswith('__'): - continue - hDict = getattr(module,n) - #print(n,type(hDict)) - #sys.exit() + with open(configName,"rt") as yamlFile: + allDicts = yaml.load(yamlFile,Loader=yaml.Loader) + yamlFile.close() + # + # store variable definitions as read from configuration + # + if 'variables' in allDicts: + vDefs = allDicts['variables'] + # + # backward compatibility for histograms: treat full input as "histograms" section + # in case neither variables nor histograms sections are defined + # + if 'histograms' in allDicts: + histDicts = allDicts['histograms'] + else: + assert not ( 'variables' in allDicts ) + histDicts = allDicts + # + for n,hDict in histDicts.items(): + # assert type(hDict)==dict # # check if in list of histograms to be displayed @@ -199,8 +312,8 @@ def loadHistogramDefinitions(configName,selectedNames=[],vetoedNames=[]): # add histogram # hDef = HistogramDefinition(n,hDict) - result.add(hDef) + hDefs.add(hDef) print("Added",hDef.getParameter('canvasName')) - - return result + + return ( vDefs, hDefs ) diff --git a/DrawHits/drawHitsEffRDF.yaml b/DrawHits/drawHitsEffRDF.yaml new file mode 100644 index 0000000..e8fb202 --- /dev/null +++ b/DrawHits/drawHitsEffRDF.yaml @@ -0,0 +1,614 @@ +# +# sensor dimensions: +# +# PSp: 5 x 10 cm2; 32 x 960 pixel at 100 μm x 1.5 mm +# PS: 5 x 10 cm2; 2 x 960 strips at 100 μm x 2.5 cm +# 2S: 10 x 10 cm2; 2 x 1016 strips at 90 μm x 5 cm + +# +# definitions of new variables +# +variables: + pathX: 'path.fCoordinates.fX' + pathY: 'path.fCoordinates.fY' + pathZ: 'path.fCoordinates.fZ' + dxdz: 'pathX/pathZ' + alpha: 'atan2(abs(pathX),abs(pathZ))/3.1415*180' + localPosX: 'localPos.fCoordinates.fX' + localPosY: 'localPos.fCoordinates.fY' + globalPosZ: 'globalPos.fCoordinates.fZ' + rhLocalPosX: 'rhLocalPos.fCoordinates.fX' + rhLocalPosY: 'rhLocalPos.fCoordinates.fY' + rhLocalErrX: 'rhLocalErr.fCoordinates.fX' + rhLocalErrY: 'rhLocalErr.fCoordinates.fY' + localPosXMod90: 'floatMod(10000*localPos.fCoordinates.fX,90)' + localPosXMod100: 'floatMod(10000*localPos.fCoordinates.fX,100)' + localPosYMod500: 'floatMod(10*localPosY,50)/10.' + localPosYMod250: 'floatMod(10*localPosY,25)/10.' + localPosYMod15: 'floatMod(100*localPosY,15)/10' + globRho2: 'globalDir.fCoordinates.fX*globalDir.fCoordinates.fX+globalDir.fCoordinates.fY*globalDir.fCoordinates.fY' + globR2: 'globRho2+globalDir.fCoordinates.fZ*globalDir.fCoordinates.fZ' + globPt: 'pabs*sqrt(globRho2/globR2)' + detNormalT: 'detNormal.fCoordinates.fX*detNormal.fCoordinates.fX+detNormal.fCoordinates.fY*detNormal.fCoordinates.fY' +# +# histogram section +# +histograms: + # + # + # + effAlphaTight: + baseCuts: 'tof<12.5&&pabs>0.3' + effCuts: 'hasRecHit>0&&abs(localPosX-rhLocalPosX)<0.0075' + histogramTitle: 'Efficiency vs. alpha(xz) tight' + variable: 'alpha' + xMax: 100.0 + xMin: 0 + xNbins: 100 + xTitle: '#alpha(xz) from path [deg]' + yMax: 1.05 + yMin: 0.5 + yTitle: 'efficiency' + # + # + # + effAlphaLoose: + baseCuts: 'tof<12.5&&pabs>0.3' + effCuts: 'hasRecHit>0&&abs(localPosX-rhLocalPosX)<0.1' + histogramTitle: 'Efficiency vs. alpha(xz) loose' + variable: 'alpha' + xMax: 100.0 + xMin: 0 + xNbins: 100 + xTitle: '#alpha(xz) from path [deg]' + yMax: 1.05 + yMin: 0.5 + yTitle: 'efficiency' + # + # + # + effVsModX: + baseCuts: 'tof<12.5&&pabs>0.3' + effCuts: 'hasRecHit>0&&abs(localPosX-rhLocalPosX)<0.0075' + yMin: 0 + yMax: 1.05 + mType23: + histogramTitle: 'Efficiency vs. x % 100 #mum' + variable: 'localPosXMod100' + xTitle: 'x modulo 100 #mum [#mum]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType24: + histogramTitle: 'Efficiency vs. x % 100 #mum' + variable: 'localPosXMod100' + xTitle: 'x modulo 100 #mum [#mum]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType25: + histogramTitle: 'Efficiency vs. x % 90 #mum' + variable: 'localPosXMod90' + xTitle: 'x modulo 90 #mum [#mum]' + xNbins: 200 + xMax: 95 + xMin: -5 + + effVsModX1: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5&&hasRecHit>0' + effCuts: 'clusterSize==1' + yMin: 0 + yMax: 1.05 + mType23: + histogramTitle: 'Prob. (1 strip) vs. x % 100 #mum' + variable: 'localPosXMod100' + xTitle: 'x modulo 100 #mum [#mum]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType24: + histogramTitle: 'Prob. (1 strip) vs. x % 100 #mum' + variable: 'localPosXMod100' + xTitle: 'x modulo 100 #mum [#mum]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType25: + histogramTitle: 'Prob. (1 strip) vs. x % 90 #mum' + variable: 'localPosXMod90' + xTitle: 'x modulo 90 #mum [#mum]' + xNbins: 200 + xMax: 95 + xMin: -5 + + effVsModX2: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5&&hasRecHit>0' + effCuts: 'clusterSize==2' + yMin: 0 + yMax: 1.05 + mType23: + histogramTitle: 'Prob. (2 strips) vs. x % 100 #mum' + variable: 'localPosXMod100' + xTitle: 'x modulo 100 #mum [#mum]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType24: + histogramTitle: 'Prob. (2 strips) vs. x % 100 #mum' + variable: 'localPosXMod100' + xTitle: 'x modulo 100 #mum [#mum]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType25: + histogramTitle: 'Prob. (2 strips) vs. x % 90 #mum' + variable: 'localPosXMod90' + xTitle: 'x modulo 90 #mum [#mum]' + xNbins: 200 + xMax: 95 + xMin: -5 + + effVsModX3p: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5&&hasRecHit>0' + effCuts: 'clusterSize>2' + yMin: 0 + yMax: 1.05 + mType23: + histogramTitle: 'Prob. (>2 strips) vs. x % 100 #mum' + variable: 'localPosXMod100' + xTitle: 'x modulo 100 #mum [#mum]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType24: + histogramTitle: 'Prob. (>2 strips) vs. x % 100 #mum' + variable: 'localPosXMod100' + xTitle: 'x modulo 100 #mum [#mum]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType25: + histogramTitle: 'Prob. (>2 strips) vs. x % 90 #mum' + variable: 'localPosXMod90' + xTitle: 'x modulo 90 #mum [#mum]' + xNbins: 200 + xMax: 95 + xMin: -5 + + effVsMod2DX1: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5&&hasRecHit>0' + effCuts: 'clusterSize==1' + yNbins: 80 + yMin: -1. + yMax: 1. + yTitle: 'dx/dz' + zMax: 1. + mType23: + histogramTitle: 'Prob. (1 strip) vs. x%100#mum and dx/dz' + variable: 'dxdz:localPosXMod100' + xTitle: 'x modulo 100 #mum [#mum]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType24: + histogramTitle: 'Prob. (1 strip) vs. x%100#mum and dx/dz' + variable: 'dxdz:localPosXMod100' + xTitle: 'x modulo 100 #mum [#mum]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType25: + histogramTitle: 'Prob. (1 strip) vs. x%90#mum' + variable: 'dxdz:localPosXMod90' + xTitle: 'x modulo 90 #mum [#mum]' + xNbins: 200 + xMax: 95 + xMin: -5 + + effVsMod2DX2: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5&&hasRecHit>0' + effCuts: 'clusterSize==2' + yNbins: 80 + yMin: -1. + yMax: 1. + yTitle: 'dx/dz' + zMax: 1. + mType23: + histogramTitle: 'Prob. (2 strips) vs. x%100#mum and dx/dz' + variable: 'dxdz:localPosXMod100' + xTitle: 'x modulo 100 #mum [#mum]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType24: + histogramTitle: 'Prob. (2 strips) vs. x%100#mum and dx/dz' + variable: 'dxdz:localPosXMod100' + xTitle: 'x modulo 100 #mum [#mum]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType25: + histogramTitle: 'Prob. (2 strips) vs. x%90#mum' + variable: 'dxdz:localPosXMod90' + xTitle: 'x modulo 90 #mum [#mum]' + xNbins: 200 + xMax: 95 + xMin: -5 + + effVsMod2DX3p: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5&&hasRecHit>0' + effCuts: 'clusterSize>2' + yNbins: 80 + yMin: -1. + yMax: 1. + yTitle: 'dx/dz' + zMax: 1. + mType23: + histogramTitle: 'Prob. (>2 strips) vs. x%100#mum and dx/dz' + variable: 'dxdz:localPosXMod100' + xTitle: 'x modulo 100 #mum [#mum]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType24: + histogramTitle: 'Prob. (>2 strips) vs. x%100#mum and dx/dz' + variable: 'dxdz:localPosXMod100' + xTitle: 'x modulo 100 #mum [#mum]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType25: + histogramTitle: 'Prob. (>2 strips) vs. x%90#mum' + variable: 'dxdz:localPosXMod90' + xTitle: 'x modulo 90 #mum [#mum]' + xNbins: 200 + xMax: 95 + xMin: -5 + + + # + # + # + effVsModY: + baseCuts: 'tof<12.5&&pabs>0.3' + effCuts: 'hasRecHit>0&&abs(localPosX-rhLocalPosX)<0.0075' + yMin: 0 + yMax: 1.05 + mType23: + histogramTitle: 'Efficiency vs. y % 1.5 mm' + variable: 'localPosYMod15' + xTitle: 'y modulo 1.5mm [mm]' + xNbins: 400 + xMax: 1.75 + xMin: -0.25 + mType24: + histogramTitle: 'Efficiency vs. y % 2.5 cm' + variable: 'localPosYMod250' + xTitle: 'y modulo 2.5cm [cm]' + xNbins: 600 + xMax: 2.75 + xMin: -0.25 + mType25: + histogramTitle: 'Efficiency vs. y % 5 cm' + variable: 'localPosYMod500' + xTitle: 'y modulo 5cm [cm]' + xNbins: 550 + xMax: 5.25 + xMin: -0.25 + # + # + # + effX: + baseCuts: 'tof<12.5&&pabs>0.3' + effCuts: 'hasRecHit>0&&abs(localPosX-rhLocalPosX)<0.0075' + histogramTitle: 'Efficiency X 1D' + variable: 'localPosX' + xTitle: 'local x [cm]' + yMax: 1.05 + yMin: 0.8 + yTitle: 'efficiency' + mType23: + xMax: 5.5 + xMin: -5.5 + xNbins: 550 + mType24: + xMax: 5.0 + xMin: -5.0 + xNbins: 250 + mType25: + xMax: 5 + xMin: -5 + xNbins: 250 + # + # + # + effY: + baseCuts: 'tof<12.5&&pabs>0.3' + effCuts: 'hasRecHit>0&&abs(localPosX-rhLocalPosX)<0.0075' + histogramTitle: 'Efficiency Y 1D' + variable: 'localPosY' + xTitle: 'local y [cm]' + yTitle: 'efficiency' + yMax: 1.05 + yMin: 0.8 + mType23: + xMax: 3 + xMin: -3 + xNbins: 120 + mType24: + xMax: 3.0 + xMin: -3.0 + xNbins: 120 + mType25: + xMax: 5.5 + xMin: -5.5 + xNbins: 220 + + # + # + # + effXY: + baseCuts: 'tof<12.5&&pabs>0.3' + effCuts: 'hasRecHit>0&&abs(localPosX-rhLocalPosX)<0.0075' + histogramTitle: 'Efficiency XY 2D' + variable: 'localPosY:localPosX' + xTitle: 'local x [cm]' + yTitle: 'local y [cm]' + zMax: 1.0 + zMin: 0.5 + mType23: + xMax: 5.5 + xMin: -5.5 + xNbins: 55 + yMax: 3 + yMin: -3 + yNbins: 24 + mType24: + xMax: 5.0 + xMin: -5.0 + xNbins: 50 + yMax: 3.0 + yMin: -3.0 + yNbins: 40 + mType25: + xMax: 5 + xMin: -5 + xNbins: 50 + yMax: 6 + yMin: -6 + yNbins: 40 +# +# +# + nrhEffVsModX1: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5' + effCuts: 'rhNMatched==1' + yTitle: 'Efficieny (nrh==1)' + yMin: 0 + yMax: 1.05 + mType23: + histogramTitle: 'Efficiency (nrh=1) vs. x % 100 #mu m' + variable: 'localPosXMod100' + xTitle: 'x modulo 100 #mu m [#mu m]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType24: + histogramTitle: 'Efficiency (nrh=1) vs. x % 100 #mu m' + variable: 'localPosXMod100' + xTitle: 'x modulo 100 #mu m [#mu m]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType25: + histogramTitle: 'Efficiency (nrh=1) vs. x % 90 #mu m' + variable: 'localPosXMod90' + xTitle: 'x modulo 90 #mu m [#mu m]' + xNbins: 200 + xMax: 95 + xMin: -5 + + nrhEffVsModX2: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5' + effCuts: 'rhNMatched==2' + yTitle: 'Efficieny (nrh==2)' + yMin: 0 + yMax: 1.05 + mType23: + histogramTitle: 'Efficiency (nrh=2) vs. x % 100 #mu m' + variable: 'localPosXMod100' + xTitle: 'x modulo 100 #mu m [#mu m]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType24: + histogramTitle: 'Efficiency (nrh=2) vs. x % 100 #mu m' + variable: 'localPosXMod100' + xTitle: 'x modulo 100 #mu m [#mu m]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType25: + histogramTitle: 'Efficiency (nrh=2) vs. x % 90 #mu m' + variable: 'localPosXMod90' + xTitle: 'x modulo 90 #mu m [#mu m]' + xNbins: 200 + xMax: 95 + xMin: -5 + + nrhEffVsModX3p: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5' + effCuts: 'rhNMatched>2' + yTitle: 'Efficieny (nrh>2)' + yMin: 0 + yMax: 1.05 + mType23: + histogramTitle: 'Efficiency (nrh>2) vs. x % 100 #mu m' + variable: 'localPosXMod100' + xTitle: 'x modulo 100 #mu m [#mu m]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType24: + histogramTitle: 'Efficiency (nrh>2) vs. x % 100 #mu m' + variable: 'localPosXMod100' + xTitle: 'x modulo 100 #mu m [#mu m]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType25: + histogramTitle: 'Efficiency (nrh>2) vs. x % 90 #mu m' + variable: 'localPosXMod90' + xTitle: 'x modulo 90 #mu m [#mu m]' + xNbins: 200 + xMax: 95 + xMin: -5 +# +# +# + nrhEffVsModY1: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5' + effCuts: 'rhNMatched==1' + yTitle: 'Efficieny (nrh==1)' + yMin: 0 + yMax: 1.05 + mType23: + histogramTitle: 'Efficiency (nrh=1) vs. y % 1.5 mm' + variable: 'localPosYMod15' + xTitle: 'y modulo 1.5mm [mm]' + xNbins: 400 + xMax: 1.75 + xMin: -0.25 + mType24: + histogramTitle: 'Efficiency (nrh=1) vs. y % 2.5 cm' + variable: 'localPosYMod250' + xTitle: 'y modulo 2.5cm [cm]' + xNbins: 600 + xMax: 2.75 + xMin: -0.25 + mType25: + histogramTitle: 'Efficiency (nrh=1) vs. y % 5 cm' + variable: 'localPosYMod500' + xTitle: 'y modulo 5cm [cm]' + xNbins: 550 + xMax: 5.25 + xMin: -0.25 + + nrhEffVsModY2: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5' + effCuts: 'rhNMatched==2' + yTitle: 'Efficiency (nrh==2)' + yMin: 0 + yMax: 1.05 + mType23: + histogramTitle: 'Efficiency (nrh=2) vs. y % 1.5 mm' + variable: 'localPosYMod15' + xTitle: 'y modulo 1.5mm [mm]' + xNbins: 400 + xMax: 1.75 + xMin: -0.25 + mType24: + histogramTitle: 'Efficiency (nrh=2) vs. y % 2.5 cm' + variable: 'localPosYMod250' + xTitle: 'y modulo 2.5cm [cm]' + xNbins: 600 + xMax: 2.75 + xMin: -0.25 + mType25: + histogramTitle: 'Efficiency (nrh=2) vs. y % 5 cm' + variable: 'localPosYMod500' + xTitle: 'y modulo 5cm [cm]' + xNbins: 550 + xMax: 5.25 + xMin: -0.25 + + nrhEffVsModY3p: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5' + effCuts: 'rhNMatched>2' + yTitle: 'Efficiency (nrh>2)' + yMin: 0 + yMax: 1.05 + mType23: + histogramTitle: 'Efficiency (nrh>2) vs. y % 1.5 mm' + variable: 'localPosYMod15' + xTitle: 'y modulo 1.5mm [mm]' + xNbins: 400 + xMax: 1.75 + xMin: -0.25 + mType24: + histogramTitle: 'Efficiency (nrh>2) vs. y % 2.5 cm' + variable: 'localPosYMod250' + xTitle: 'y modulo 2.5cm [cm]' + xNbins: 600 + xMax: 2.75 + xMin: -0.25 + mType25: + histogramTitle: 'Efficiency (nrh>2) vs. y % 5 cm' + variable: 'localPosYMod500' + xTitle: 'y modulo 5cm [cm]' + xNbins: 550 + xMax: 5.25 + xMin: -0.25 + +# +# test case for nrh==1 efficiency +# + + nrhEffVsY1: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5' + effCuts: 'rhNMatched==1' + yTitle: 'Efficieny (nrh==1)' + yMin: 0 + yMax: 1.05 + mType23: + histogramTitle: 'Efficiency (nrh=1) vs. y % 1.5 mm' + variable: 'localPosY' + xTitle: 'y [cm]' + xNbins: 5100 + xMax: 2.55 + xMin: -2.55 + mType24: + histogramTitle: 'Efficiency (nrh=1) vs. y % 2.5 cm' + variable: 'localPosY' + xTitle: 'y [cm]' + xNbins: 520 + xMax: 2.6 + xMin: -2.6 + mType25: + histogramTitle: 'Efficiency (nrh=1) vs. y % 2.5 cm' + variable: 'localPosY' + xTitle: 'y [cm]' + xNbins: 880 + xMax: 5.5 + xMin: -5.5 + + effDxDz: + variable: 'dxdz' + histogramTitle: 'efficiency (dx/dz)' + baseCuts: 'tof<12.5' + effCuts: 'hasRecHit>0' + xTitle: 'local dx/dz' + xNbins: 21 + xMin: -1.05 + xMax: 1.05 + + effDxDzW1: + variable: 'dxdz' + histogramTitle: 'efficiency, 1-strip clusters (dx/dz)' + baseCuts: 'tof<12.5' + effCuts: 'hasRecHit>0&&clusterSize==1' + xTitle: 'local dx/dz' + xNbins: 21 + xMin: -1.05 + xMax: 1.05 + + effDxDzW2: + variable: 'dxdz' + histogramTitle: 'efficiency, 2-strip clusters (dx/dz)' + baseCuts: 'tof<12.5' + effCuts: 'hasRecHit>0&&clusterSize==2' + xTitle: 'local dx/dz' + xNbins: 21 + xMin: -1.05 + xMax: 1.05 + diff --git a/DrawHits/drawHitsRDF.py b/DrawHits/drawHitsRDF.py new file mode 100755 index 0000000..bc294ad --- /dev/null +++ b/DrawHits/drawHitsRDF.py @@ -0,0 +1,735 @@ +#! /bin/env python3 +import sys,os +from drawHitsConfiguration import * +import ROOT +import argparse +from fnmatch import fnmatch + +def divideRatios(cnv,nx,ny,widthRatios,heightRatios,canvasTopMargin=0.,canvasLeftMargin=0.): + result = [ ] + cnv.cd() + + wrs = len(widthRatios) + hrs = len(heightRatios) + nxl = min(nx,wrs) + nyl = min(ny,hrs) + + if wrs==0: nxl = nx + if hrs==0: nyl = ny + + pn = 1 + xr = 0. + yr = 0. + x = 0. + y = 1. + # Check the validity of the margins + if canvasTopMargin<0 or canvasTopMargin>1: + raise Exception("DivideRatios: The canvas top margin must be >= 0 and <= 1") + else: + y = 1.- canvasTopMargin + if canvasLeftMargin <0 or canvasLeftMargin >1: + raise Exception("DivideRatios", "The canvas left margin must be >= 0 and <= 1") + + # Check the validity of the ratios + sumOfHeightRatios = canvasTopMargin + if hrs: + for i in range(nyl): + yr = heightRatios[i] + sumOfHeightRatios = sumOfHeightRatios + yr + if yr<0 or yr>1: + raise Exception("DivideRatios", "Y ratios plus the top margin must be >= 0 and <= 1") + + if sumOfHeightRatios>1.: + raise Exception("DivideRatios", "The sum of Y ratios plus the top margin must be <= 1 %g",sumOfHeightRatios) + sumOfWidthRatios = canvasLeftMargin + if wrs: + for j in range(nxl): + xr = widthRatios[j] + sumOfWidthRatios = sumOfWidthRatios + xr + if xr <0 or xr >1: + raise Exception("DivideRatios", "X ratios must be >= 0 and <= 1") + if sumOfWidthRatios>1.: + raise Exception("DivideRatios", "The sum of X ratios must be <= 1 %g ",sumOfWidthRatios) + + # Create the pads according to the ratios + for i in range(nyl): + x = canvasLeftMargin + if hrs: + yr = heightRatios[i] + else: + yr = 1./nyl + for j in range(nxl): + if wrs: + xr = widthRatios[j] + else: + xr = 1./nxl + x1 = max(0., x) + y1 = max(0., y - yr) + x2 = min(1., x + xr) + y2 = min(1., y) + pad = ROOT.TPad(cnv.GetName()+str(pn),cnv.GetName()+str(pn),x1, y1, x2 ,y2) + result.append(pad) + pad.SetNumber(pn) + pad.Draw() + x = x + xr + pn += 1 + y = y - yr + + return result + +def fitHistogram(mType,h): + assert h.GetDimension()==1 + f1name = "f1"+str(mType) + f1 = ROOT.TF1(f1name,"gaus(0)") + f1.SetParameter(0,h.GetMaximum()) + f1.SetParLimits(0,0.,2*h.GetMaximum()) + f1.SetParameter(1,0.) + f1.SetParameter(2,h.GetRMS()/10.) + h.Fit(f1name) + f2name = "f2"+str(mType) + f2 = ROOT.TF1(f2name,"gaus(0)+gaus(3)") + f2.SetParameter(0,f1.GetParameter(0)) + f2.SetParameter(1,f1.GetParameter(1)) + f2.SetParameter(2,f1.GetParameter(2)) + f2.SetParameter(3,f1.GetParameter(0)/100.) + f2.SetParameter(4,f1.GetParameter(1)) + f2.SetParameter(5,5*f1.GetParameter(2)) + f2.SetParLimits(5,f1.GetParameter(2),10*f1.GetParameter(2)) + h.Fit(f2name) + func = h.GetFunction(f2name) + func.SetLineWidth(5) + ROOT.gPad.SetLogy(1) + ROOT.gPad.Update() + + +def cutString(*cuts): + if len(cuts)>0 and cuts[0]!=None: + return "&&".join([ c for c in cuts if ( c!=None and c.strip()!="" ) ]) + return None + +def cutLines(cuts,maxChar=40): + result = [ ] + line = "" + for ic,c in enumerate(cuts): + line += c + if ic<(len(cuts)-1): + line += "&&" + if len(line)>maxChar: + result.append(line) + line = "" + if line!="": + result.append(line) + return result + +# def drawString(pave,title,s=""): +# t = pave.AddText(title) +# t.SetTextFont(43) +# t.SetTextSize(0.06) +# t.SetTextSize(16) +# t.SetTextAlign(13) +# #yt += 14 +# if s!="": +# #t = pave.AddText("") +# t = pave.AddText(" "+s) +# t.SetTextFont(43) +# t.SetTextSize(14) +# t.SetTextAlign(13) +# #t = pave.AddText("") + +# def drawCuts(pave,title,cuts): +# #t = pave.AddText(title) +# #t = pave.AddText("") +# lines = [ ] +# line = "" +# for ic,c in enumerate(cuts): +# line += c +# if ic<(len(cuts)-1): +# line += "&&" +# if len(line)>40: +# lines.append(line) +# line = "" +# if line!="": +# lines.append(line) +# for l in lines: +# if l!="": +# t = pave.AddText(" "+l) +# t.SetTextFont(43) +# t.SetTextSize(0.04) +# t.SetTextSize(14) +# t.SetTextAlign(13) +# #l = " " + c +# #if ic<(len(cuts)-1): +# # l += " &&" +# ## if len(l +# #if +# #t = pave.AddText(l) + + +def drawCutPave(cnv,ic,variable,cuts,effcuts=None): + indBaseCuts = cuts.split("&&") + indEffCuts = None if effcuts==None else effcuts.split("&&") + cnv.cd(ic+3) + #hpave = 3*0.06+(len(indBaseCuts)+1)*0.04 + #if indEffCuts!=None: + # hpave += (len(indEffCuts)+2)*0.04 + + allLines = [ ] + allLines.append(('hdr','Variable(s)')) + allLines.append(('txt',variable)) + allLines.append(('hdr','Basic selection')) + for l in cutLines(indBaseCuts): + if l!="": + allLines.append(('txt',l)) + if indEffCuts!=None: + allLines.append(('hdr','Efficiency selection')) + for l in cutLines(indEffCuts): + if l!="": + allLines.append(('txt',l)) + + hdrPixels = 16 + txtPixels = 14 + #pave = ROOT.TPaveText(0.05,max(0,1.0-hpave),0.95,1.0) + hpave = ((hdrPixels+txtPixels+2)*len([ x for x in allLines if x[0]=='hdr' ]) + \ + (txtPixels+2)*len([ x for x in allLines if x[0]=='txt' ])) / (ROOT.gPad.VtoPixel(0.)-ROOT.gPad.VtoPixel(1.)) + if hpave>1.: + scale = 1./hpave + hpave = 1 + else: + scale = 1 + + pave = ROOT.TPaveText(0.,1.-hpave,1.,1.) + pave.SetBorderSize(0) + pave.SetFillStyle(0) + pave.SetTextFont(43) + #pave.SetMargin(0) + #pave.SetTextSize(0.04) + pave.SetTextSize(int(scale*txtPixels)) + pave.SetTextAlign(13) + nhdr = 0 + for x,y in allLines: + if x=='hdr': + if nhdr>0: + t = pave.AddText("") + t.SetTextSize(int(scale*txtPixels)) + t = pave.AddText(y) + t.SetTextFont(63) + t.SetTextSize(int(scale*hdrPixels)) + nhdr += 1 + else: + t = pave.AddText(" "+y) + t.SetTextSize(int(scale*txtPixels)) + #drawString(pave,"Variable(s)",variable) + #drawString(pave,"Basic selection") + #drawCuts(pave,"Basic selection",indBaseCuts) + #if indEffCuts!=None: + # #t = pave.AddText("") + # drawString(pave,"Efficiency selection") + # drawCuts(pave,"Efficiency selection",indEffCuts) + + pave.Draw() + ROOT.gPad.Update() + return pave + +#def createHistoByDef(rdf,hDef,extraCuts,varMaskCombs): +def createHistoByDef(rdfWrapper,hDef,extraCuts): + histos = { } + + for mType in range(23,26): + #print("Checking mType",mType,"for",hDef.name) + # + # draw histogram? + # + if hDef.vetoMType(mType): + continue + is1D = hDef.getParameter('yNbins',mType)==None + is2D = hDef.getParameter('yNbins',mType)!=None and hDef.getParameter('zNbins',mType)==None + is3D = hDef.getParameter('yNbins',mType)!=None and hDef.getParameter('zNbins',mType)!=None + isProfile = hDef.getParameter('profile',mType)!=None and hDef.getParameter('profile',mType) + effCuts = hDef.getParameter('effCuts',mType) + variable = hDef.getParameter('variable',mType) + ## + #cnv.cd(ic) + #ROOT.gPad.SetGridx(1) + #ROOT.gPad.SetGridy(1) + #if not is1D: + # ROOT.gPad.SetRightMargin(0.125) + hName = hDef.getParameter('histogramName',mType) + str(mType) + hTitle = hDef.getParameter('histogramTitle',mType) + " module type " +str(mType) + nbx = hDef.getParameter('xNbins',mType) + xmin = hDef.getParameter('xMin',mType) + xmax = hDef.getParameter('xMax',mType) + #print("Starting for ",hDef.name,hName,hTitle) + if is1D and ( not isProfile ): + cuts = cutString(extraCuts,hDef.getParameter('baseCuts',mType),"moduleType=="+str(mType)) +#!# rdf,varMask = varMaskCombs(rdf,variable,cuts) + varMask = rdfWrapper.defineVarMask(variable,cuts) + model = (hName+"_1",hName+"_1",nbx,xmin,xmax) + histos[mType] = [ rdfWrapper().Histo1D(model,varMask), None, None, None ] + if effCuts!=None: + cuts = cutString(extraCuts,hDef.getParameter('baseCuts',mType),"moduleType=="+str(mType),effCuts) +#!# rdf,varMask = varMaskCombs(rdf,variable,cuts) + varMask = rdfWrapper.defineVarMask(variable,cuts) + model = (hName+"_2",hName+"_2",nbx,xmin,xmax) + histos[mType][1] = rdfWrapper().Histo1D(model,varMask) + #sys.exit() + elif isProfile: + ymin = hDef.getParameter('yMin',mType) + ymax = hDef.getParameter('yMax',mType) + v2,v1 = variable.split(":") + cuts = cutString(extraCuts,hDef.getParameter('baseCuts',mType),"moduleType=="+str(mType)) +#!# rdf,varMask1 = varMaskCombs(rdf,v1,cuts) + varMask1 = rdfWrapper.defineVarMask(v1,cuts) +#!# rdf,varMask2 = varMaskCombs(rdf,v2,cuts) + varMask2 = rdfWrapper.defineVarMask(v2,cuts) + model = (hName+"_1",hName+"_1",nbx,xmin,xmax,ymin,ymax) + histos[mType] = [ rdfWrapper().Profile1D(model,varMask1,varMask2), None, None, None ] + #histos[mType] = [ rdf.Profile1D((hName+"_1",hName+"_1",nbx,xmin,xmax,ymin,ymax,'S'), \ + # v1+"["+cutString(extraCuts,hDef.getParameter('baseCuts',mType),"moduleType=="+str(mType))+"]",v2), \ + # None, None, None ] + elif is2D: + nby = hDef.getParameter('yNbins',mType) + ymin = hDef.getParameter('yMin',mType) + ymax = hDef.getParameter('yMax',mType) + v2,v1 = variable.split(":") + cuts = cutString(extraCuts,hDef.getParameter('baseCuts',mType),"moduleType=="+str(mType)) +#!# rdf,varMask1 = varMaskCombs(rdf,v1,cuts) + varMask1 = rdfWrapper.defineVarMask(v1,cuts) +#!# rdf,varMask2 = varMaskCombs(rdf,v2,cuts) + varMask2 = rdfWrapper.defineVarMask(v2,cuts) + model = (hName+"_1",hName+"_1",nbx,xmin,xmax,nby,ymin,ymax) + histos[mType] = [ rdfWrapper().Histo2D(model,varMask1,varMask2), None, None, None ] + if effCuts!=None: + cuts = cutString(extraCuts,hDef.getParameter('baseCuts',mType),"moduleType=="+str(mType),effCuts) +#!# rdf,varMask1 = varMaskCombs(rdf,v1,cuts) + varMask1 = rdfWrapper.defineVarMask(v1,cuts) +#!# rdf,varMask2 = varMaskCombs(rdf,v2,cuts) + varMask2 = rdfWrapper.defineVarMask(v2,cuts) + model = (hName+"_2",hName+"_2",nbx,xmin,xmax,nby,ymin,ymax) + histos[mType][1] = rdfWrapper().Histo2D(model,varMask1,varMask2) + elif is3D: + nby = hDef.getParameter('yNbins',mType) + ymin = hDef.getParameter('yMin',mType) + ymax = hDef.getParameter('yMax',mType) + nbz = hDef.getParameter('zNbins',mType) + zmin = hDef.getParameter('zMin',mType) + zmax = hDef.getParameter('zMax',mType) + v3,v2,v1 = variable.split(":") + cuts = cutString(extraCuts,hDef.getParameter('baseCuts',mType),"moduleType=="+str(mType)) +#!# rdf,varMask1 = varMaskCombs(rdf,v1,cuts) + varMask1 = rdfWrapper.defineVarMask(v1,cuts) +#!# rdf,varMask2 = varMaskCombs(rdf,v2,cuts) + varMask2 = rdfWrapper.defineVarMask(v2,cuts) +#!# rdf,varMask3 = varMaskCombs(rdf,v3,cuts) + varMask3 = rdfWrapper.defineVarMask(v3,cuts) + model = (hName+"_1",hName+"_1",nbx,xmin,xmax,nby,ymin,ymax,nbz,zmin,zmax) + histos[mType] = [ rdfWrapper().Histo3D(model,varMask1,varMask2,varMask3), None, None, None ] + assert effCuts==None + #print("Ending for ",hDef.name,hName,hTitle) + + return histos + + + +def fillHistoByDef(tree,hDef,extraCuts,histos): + #histos = { } + + savedDir = ROOT.gDirectory + ROOT.gROOT.cd() + + ic = 0 + for mType in range(23,26): + #print("Checking mType",mType,"for",hDef.name) + ic += 1 + # + # draw histogram? + # + if hDef.vetoMType(mType): + continue + is1D = hDef.getParameter('yNbins',mType)==None + is2D = hDef.getParameter('yNbins',mType)!=None and hDef.getParameter('zNbins',mType)==None + is3D = hDef.getParameter('yNbins',mType)!=None and hDef.getParameter('zNbins',mType)!=None + isProfile = hDef.getParameter('profile',mType)!=None and hDef.getParameter('profile',mType) + effCuts = hDef.getParameter('effCuts',mType) + variable = hDef.getParameter('variable',mType) + ## + #cnv.cd(ic) + hName = hDef.getParameter('histogramName',mType) + str(mType) + hTitle = hDef.getParameter('histogramTitle',mType) + " module type " +str(mType) + nbx = hDef.getParameter('xNbins',mType) + xmin = hDef.getParameter('xMin',mType) + xmax = hDef.getParameter('xMax',mType) + #print("Starting for ",hDef.name,hName,hTitle) + if is1D and ( not isProfile ): + if effCuts!=None: + histos[mType][3] = ROOT.TEfficiency(histos[mType][1].GetValue(),histos[mType][0].GetValue()) + histos[mType][3].SetMarkerStyle(20) + else: + # always keep final histogram in 4th position + histos[mType][3] = histos[mType][0] + elif isProfile: + # always keep final histogram in 4th position + histos[mType][3] = histos[mType][0] + elif is2D: + if effCuts!=None: + # always keep final histogram in 4th position + histos[mType][3] = histos[mType][1].Divide(histos[mType][0].GetValue()) + else: + # always keep final histogram in 4th position + histos[mType][3] = histos[mType][0] + elif is3D: + # always keep final histogram in 4th position + histos[mType][3] = histos[mType][0] + #print("Ending for ",hDef.name,hName,hTitle) + + savedDir.cd() + return histos + + +def drawHistoByDef(histos,hDef,logY=False,logZ=False,same=False): + result = { 'cnv' : None, 'histos' : histos, 'pave' : None } + + savedDir = ROOT.gDirectory + ROOT.gROOT.cd() + cnvName = hDef.getParameter('canvasName') + cnv = ROOT.TCanvas(cnvName,cnvName,1500,800) + result['cnv'] = cnv + #cnv.Divide(3,2) + result['pads'] = divideRatios(cnv,3,2,[1./3.,1./3.,1/3.],[2/3.,1/3.]) + + #print(hDef['canvasName'],'is',is1D) + + ic = 0 + #hEffVs = { } + for mType in range(23,26): + #print("Checking mType",mType,"for",hDef.name) + ic += 1 + cnv.cd(ic) + #padNameUp = cnvName+str(mType)+'up' + #result[padNameUp] = ROOT.TPad(padNameUp,padNameUp,(ic-1)/3.,1/3.,ic/3.,1.) + #result[padNameUp].Draw() + # + # draw histogram? + # + if hDef.vetoMType(mType): + continue + is1D = hDef.getParameter('yNbins',mType)==None + is2D = hDef.getParameter('yNbins',mType)!=None and hDef.getParameter('zNbins',mType)==None + is3D = hDef.getParameter('yNbins',mType)!=None and hDef.getParameter('zNbins',mType)!=None + isProfile = hDef.getParameter('profile',mType)!=None and hDef.getParameter('profile',mType) + effCuts = hDef.getParameter('effCuts',mType) + variable = hDef.getParameter('variable',mType) + # + #result[padNameUp].cd() + ROOT.gPad.SetGridx(1) + ROOT.gPad.SetGridy(1) + if not is1D: + ROOT.gPad.SetRightMargin(0.125) + hName = hDef.getParameter('histogramName',mType) + str(mType) + hTitle = hDef.getParameter('histogramTitle',mType) + " module type " +str(mType) + + xtitle = hDef.getParameter('xTitle',mType) if hDef.getParameter('xTitle',mType) else variable + nbx = hDef.getParameter('xNbins',mType) + xmin = hDef.getParameter('xMin',mType) + xmax = hDef.getParameter('xMax',mType) + + ytitle = hDef.getParameter('yTitle',mType) if hDef.getParameter('yTitle',mType) else "" + ztitle = hDef.getParameter('zTitle',mType) if hDef.getParameter('zTitle',mType) else "" + if is1D and ( not isProfile ): + ymin = hDef.getParameter('yMin',mType) if hDef.getParameter('yMin',mType)!=None else 0. + ymax = hDef.getParameter('yMax',mType) if hDef.getParameter('yMax',mType)!=None else 1.05 + if effCuts!=None: + if not same: + histos[mType][2] = ROOT.gPad.DrawFrame(xmin,ymin,xmax,ymax) + histos[mType][2].SetTitle(hTitle) + histos[mType][2].GetXaxis().SetTitle(xtitle) + histos[mType][2].GetYaxis().SetTitle(ytitle) + histos[mType][3] = ROOT.TEfficiency(histos[mType][1].GetValue(),histos[mType][0].GetValue()) + histos[mType][3].SetMarkerStyle(20) + histos[mType][3].SetLineWidth(3) + histos[mType][3].Draw("same Z") + else: + histos[mType][0].SetTitle(hTitle) + histos[mType][0].GetXaxis().SetTitle(xtitle) + histos[mType][0].GetYaxis().SetTitle(ytitle) + histos[mType][0].SetLineWidth(3) + histos[mType][0].Draw("same" if same else "") + fitFunc = hDef.getParameter('fit') + if fitFunc!=None: + histos[mType][0].Fit(fitFunc,"Q","same") + elif isProfile: + histos[mType][0].SetTitle(hTitle) + histos[mType][0].GetXaxis().SetTitle(xtitle) + histos[mType][0].GetYaxis().SetTitle(ytitle) + histos[mType][0].SetMarkerSize(0.5) + #histos[mType][0].SetFillColor(ROOT.TColor.GetColorBright(ROOT.kGray)) + #histos[mType][0].SetFillColor(ROOT.kGray) + histos[mType][0].Draw("same" if same else "") + elif is2D: + assert not same + zmin = hDef.getParameter('zMin',mType) if hDef.getParameter('zMin',mType)!=None else 0. + zmax = hDef.getParameter('zMax',mType) if hDef.getParameter('zMax',mType)!=None else 1.05 + if effCuts!=None: + histos[mType][1].SetTitle(hTitle) + histos[mType][1].GetXaxis().SetTitle(xtitle) + histos[mType][1].GetYaxis().SetTitle(ytitle) + histos[mType][1].SetMinimum(zmin) + histos[mType][1].SetMaximum(zmax) + histos[mType][1].Draw("ZCOL") + else: + histos[mType][0].SetTitle(hTitle) + histos[mType][0].GetXaxis().SetTitle(xtitle) + histos[mType][0].GetYaxis().SetTitle(ytitle) + histos[mType][0].Draw("ZCOL") + elif is3D: + assert not same + zmin = hDef.getParameter('zMin',mType) if hDef.getParameter('zMin',mType)!=None else 0. + zmax = hDef.getParameter('zMax',mType) if hDef.getParameter('zMax',mType)!=None else 1.05 + assert effCuts==None + histos[mType][0].SetTitle(hTitle) + histos[mType][0].GetXaxis().SetTitle(xtitle) + histos[mType][0].GetYaxis().SetTitle(ytitle) + histos[mType][0].GetZaxis().SetTitle(ztitle) + histos[mType][0].Draw() + if logY or hDef.getParameter('logY',mType): + ROOT.gPad.SetLogy(1) + if is2D and ( logZ or hDef.getParameter('logZ',mType) ): + ROOT.gPad.SetLogz(1) + ROOT.gPad.Update() + + #cnv.cd() + #padNameDown = cnvName+str(mType)+'down' + #result[padNameDown] = ROOT.TPad(padNameDown,padNameDown,(ic-1)/3.,0.,ic/3.,1/3.) + #result[padNameDown].Draw() + result['pave'+str(mType)] = drawCutPave(cnv,ic,hDef.getParameter('variable',mType), \ + cutString(extraCuts,hDef.getParameter('baseCuts',mType)), \ + cutString(hDef.getParameter('effCuts',mType))) + + #for k,v in result.items(): + # print(k,v) + savedDir.cd() + return result + +def addHistogram(varString,cuts,effCuts=None,name='userHist'): + extraHDict = { } + # split into string defining the variable(s) and (1 or 2) axis definition(s) + fields1 = varString.split(";") + assert len(fields1)<=3 + extraHDict['variable'] = fields1[0] + #extraHDict['canvasName'] = "cEffArg" + #extraHDict['histogramName'] = "hEffArg" + extraHDict['histogramTitle'] = name + # x-axis + fields2 = fields1[1].split(",") + assert len(fields2)==3 + extraHDict['xNbins'] = int(fields2[0]) + extraHDict['xMin'] = float(fields2[1]) + extraHDict['xMax'] = float(fields2[2]) + # check for info on y axis (== presence of 2nd variable) + if len(fields1)==3: + assert ":" in extraHDict['variable'] + fields3 = fields1[2].split(",") + extraHDict['yNbins'] = int(fields3[0]) + extraHDict['yMin'] = float(fields3[1]) + extraHDict['yMax'] = float(fields3[2]) + extraHDict['xTitle'] = extraHDict['variable'].split(":")[1] + extraHDict['yTitle'] = extraHDict['variable'].split(":")[0] + else: + extraHDict['yMin'] = 0. + extraHDict['yMax'] = 1.05 + extraHDict['xTitle'] = extraHDict['variable'] + extraHDict['yTitle'] = 'efficiency' if effCuts!=None else 'events/bin' + extraHDict['baseCuts'] = cuts + if effCuts!=None: + extraHDict['effCuts'] = effCuts + return HistogramDefinition(name,extraHDict) + + + +parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) +parser.add_argument('--definitions', '-d', help='python module with dictionaries defining efficiency histograms', \ + type=str, default=None) +parser.add_argument('--histogram', \ + help='definition of extra histogram (format ;,,[;,,)', \ + action='append', type=str, default=[]) +parser.add_argument('--batch', '-b', help='ROOT batch mode', action='store_true', default=False) +parser.add_argument('--dxMax', help='max. local dx for efficiency plots', type=float, default=0.0075) +parser.add_argument('--cuts', '-c', help="basic cut string", type=str, default="") +parser.add_argument('--effCuts', '-e', help="basic cut string", type=str, default=None) +parser.add_argument('--output', '-o', help='output directory for graphic output', type=str, default=None) +parser.add_argument('--formats', help='comma-separated list of extensions for output files', \ + type=str, default="pdf,png") +parser.add_argument('--sampleName', help='sample label for output', type=str, default=None) +parser.add_argument('--fitResiduals', '-f', \ + help='comma-separated list of names of histogram sets with residuals to be fit', \ + type=str, default=None) +parser.add_argument('--selectedHistograms', help='comma-separated names of histogram definitions to be used', \ + type=str, default='*') +parser.add_argument('--vetoedHistograms', help='comma-separated names of histogram definitions not to be used', + type=str, default='') +parser.add_argument('--logY', help='use log scale for y axis', action='store_true', default=False) +parser.add_argument('--logZ', help='use log scale for z axis', action='store_true', default=False) +parser.add_argument('--printTree', '-p', help='print TTree contents', action='store_true', default=False) +parser.add_argument('--listHistograms', '-l', help='list predefined and selected histograms', \ + action='store_true', default=False) +parser.add_argument('--zone', '-z', help='restrict to zone in OT (barrel, tilted, endcap)', type=str, \ + choices=['barrel','tilted','endcap'], default=None) +parser.add_argument('file', help='input file', type=str, nargs='+', default=None) +args = parser.parse_args() +outputFormats = [ ] +if args.output!=None: + assert os.path.isdir(args.output) + print("***",args.output) + outputFormats = [ x.strip() for x in args.formats.strip().split(",") ] +fitResiduals = args.fitResiduals.split(",") if args.fitResiduals else [ ] +selectedHistoNames = args.selectedHistograms.split(",") +vetoedHistoNames = args.vetoedHistograms.split(",") +# +# add cut for zone definition? +# +if args.zone=="barrel": + zoneCuts = "detNormalT>0.99" +elif args.zone=="endcap": + zoneCuts = "detNormalT<0.01" +elif args.zone=="tilted": + zoneCuts = "detNormalT>0.05&&detNormalT<0.95" +else: + zoneCuts = "" +args.cuts = cutString(args.cuts,zoneCuts) + +# +# load histogram definitions +# +allVDefs,allHDefs = loadConfiguration(args.definitions,selectedHistoNames,vetoedHistoNames) +if args.listHistograms: + hnames = sorted(allHDefs.allHistoNames) + for hn in hnames: + print(hn) + sys.exit() + +for ih,h in enumerate(args.histogram): + allHDefs.add(addHistogram(h,args.cuts,args.effCuts,name="userH"+str(ih+1))) + + +#extraCuts = "abs(particleType)==13" +#extraCuts = "tof<12.5" +extraCuts = args.cuts + +if args.batch: + ROOT.gROOT.SetBatch(1) +ROOT.gROOT.ProcessLine(".L setTDRStyle.C") +ROOT.gROOT.ProcessLine(".L floatMod.C+") +ROOT.setTDRStyle() +ROOT.gStyle.SetOptStat(0) +ROOT.gStyle.SetOptFit(1) +ROOT.gStyle.SetTitleFont(42) +ROOT.gStyle.SetTitleFontSize(0.03) +ROOT.gStyle.SetTitleX(0.12) +ROOT.gStyle.SetTitleY(1.00) +ROOT.gStyle.SetTitleAlign(13) +ROOT.gStyle.SetTitleBorderSize(0) +#ROOT.gStyle.SetTitleFillColor(0) +ROOT.gStyle.SetOptTitle(1) +#tf = ROOT.TFile(args.file[0]) +#simHitTree = simHitTree = tf.Get("analysis").Get("SimHitTree") +simHitTree = ROOT.TChain("analysis/SimHitTree") +for fn in args.file: + simHitTree.Add(fn) +#print(type(tchain)) +#tchain.Print() +if args.printTree: + simHitTree.Print() + sys.exit() +# +# create RDataFrame and define additional columns +# +#simHitRDF = ROOT.RDataFrame(simHitTree) +simHitRDF = ROOT.RDataFrame("analysis/SimHitTree",args.file) +for k,v in allVDefs.items(): + simHitRDF = simHitRDF.Define(k,v) + +canvases = [ ] +histos = { } +paves = [ ] +#varMaskCombs = VarMaskCombinations() +simHitRDFW = RDFWrapper(simHitRDF) + +allHistos = { } +for cName in allHDefs.canvasNames(): + allHistos[cName] = {} + for hName in allHDefs.byCanvas[cName]: + print("Processing histogram",hName,"in canvas",cName) + try: + allHistos[cName][hName] = \ + createHistoByDef(simHitRDFW,allHDefs.byCanvas[cName][hName],extraCuts) +# simHitRDF,allHistos[cName][hName] = \ +# createHistoByDef(simHitRDF,allHDefs.byCanvas[cName][hName],extraCuts,varMaskCombs) + except: + print("Exception for",cName,hName) + raise +# keep reference to RDF with all definitions +simHitRDF = simHitRDFW() + +allObjects = [ ] +for cName in allHDefs.canvasNames(): + same = False + cHistos = { } + for hName in allHDefs.byCanvas[cName]: + print("Processing histogram",hName,"in canvas",cName) + #print(allHistos[cName][hName]) + fillHistoByDef(simHitTree,allHDefs.byCanvas[cName][hName],extraCuts,allHistos[cName][hName]) + allObjects.append(drawHistoByDef(allHistos[cName][hName],allHDefs.byCanvas[cName][hName], \ + logY=args.logY,logZ=args.logZ,same=same)) + #!# + print(allHDefs.byCanvas[cName][hName]) + print(allHDefs.byCanvas[cName][hName].name) + hdef = allHDefs.byCanvas[cName][hName] + fitHisto = False + for fr in fitResiduals: + if fnmatch(hdef.name,fr): + fitHisto = True + break + if fitHisto: + objects = allObjects[-1] + cnv = objects['cnv'] + # fit and redraw each panel + ic = 0 + for mType in range(23,26): + ic += 1 + cnv.cd(ic) + f = fitHistogram(mType,objects['histos'][mType][0]) + #!# + same = True + if args.output!=None: + c = allObjects[-1]['cnv'] + #for c in [ x['cnv'] for x in allObjects ]: + basename = os.path.join(args.output,c.GetName()) + if args.sampleName!=None: + basename += "_" + args.sampleName + if args.zone!=None: + basename += "_" + args.zone + print(basename) + for fmt in outputFormats: + c.SaveAs(basename+"."+fmt) + +# yMin = min([ x.GetMinimum() for x in cHistos +#sys.exit() + +#!# allObjects = [ ] +#!# for hdef in allHDefs.allDefinitions.values(): +#!# # +#!# # draw histograms according to definition +#!# # +#!# histos = fillHistoByDef(simHitTree,hdef,extraCuts) +#!# allObjects.append(drawHistoByDef(histos,hdef)) +#!# # +#!# # perform fit of resolution histogram +#!# # +#!# if hdef.name in fitResiduals: +#!# objects = allObjects[-1] +#!# cnv = objects['cnv'] +#!# # fit and redraw each panel +#!# ic = 0 +#!# for mType in range(23,26): +#!# ic += 1 +#!# cnv.cd(ic) +#!# f = fitHistogram(mType,objects['histos'][mType][0]) diff --git a/DrawHits/drawHitsResRDF.yaml b/DrawHits/drawHitsResRDF.yaml new file mode 100644 index 0000000..1ee9875 --- /dev/null +++ b/DrawHits/drawHitsResRDF.yaml @@ -0,0 +1,378 @@ +# +# definitions of new variables +# +variables: + pathX: 'path.fCoordinates.fX' + pathY: 'path.fCoordinates.fY' + pathZ: 'path.fCoordinates.fZ' + dxdz: 'pathX/pathZ' + alpha: 'atan2(abs(pathX),abs(pathZ))/3.1415*180' + localPosX: 'localPos.fCoordinates.fX' + localPosY: 'localPos.fCoordinates.fY' + rhLocalPosX: 'rhLocalPos.fCoordinates.fX' + rhLocalPosY: 'rhLocalPos.fCoordinates.fY' + rhLocalErrX: 'rhLocalErr.fCoordinates.fX' + rhLocalErrY: 'rhLocalErr.fCoordinates.fY' + localPosXMod90: 'floatMod(10000*localPos.fCoordinates.fX,90)' + localPosXMod100: 'floatMod(10000*localPos.fCoordinates.fX,100)' + localPosYMod500: 'floatMod(10*localPosY,50)/10.' + localPosYMod250: 'floatMod(10*localPosY,25)/10.' + localPosYMod15: 'floatMod(100*localPosY,15)/10' + globRho2: 'globalDir.fCoordinates.fX*globalDir.fCoordinates.fX+globalDir.fCoordinates.fY*globalDir.fCoordinates.fY' + globR2: 'globRho2+globalDir.fCoordinates.fZ*globalDir.fCoordinates.fZ' + globPt: 'pabs*sqrt(globRho2/globR2)' + detNormalT: 'detNormal.fCoordinates.fX*detNormal.fCoordinates.fX+detNormal.fCoordinates.fY*detNormal.fCoordinates.fY' +# +# +# +histograms: + + pullX: + histogramTitle: 'pulls (x)' + variable: '(localPosX-rhLocalPosX)/rhLocalErrX' + baseCuts: 'tof<12.5&&hasRecHit>0' + xTitle: 'pull local x' + xNbins: 200 + xMax: 5 + xMin: -5 + fit: 'gaus' + logY: true + pullXW1: + histogramTitle: 'pulls (x)' + variable: '(localPosX-rhLocalPosX)/rhLocalErrX' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize==1' + xTitle: 'pull local x' + xNbins: 200 + xMax: 5 + xMin: -5 + fit: 'gaus' + logY: true + pullXW2: + histogramTitle: 'pulls (x)' + variable: '(localPosX-rhLocalPosX)/rhLocalErrX' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize==2' + xTitle: 'pull local x' + xNbins: 200 + xMax: 5 + xMin: -5 + fit: 'gaus' + logY: true + pullY: + histogramTitle: 'pulls (y)' + variable: '(localPosY-rhLocalPosY)/rhLocalErrY' + baseCuts: 'tof<12.5&&hasRecHit>0' + xTitle: 'pull local y' + xNbins: 200 + xMax: 5 + xMin: -5 + logY: true +# +# +# + resX: + histogramTitle: 'residuals (x)' + variable: 'localPosX-rhLocalPosX' + baseCuts: 'tof<12.5&&hasRecHit>0' + xTitle: '#Delta x [cm]' + xNbins: 300 + xMax: 0.075 + xMin: -0.075 + fit: 'gaus' + logY: true +# +# +# + resX1: + histogramTitle: 'residuals (x) - cluster size 1' + variable: 'localPosX-rhLocalPosX' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize==1' + xTitle: '#Delta x [cm]' + xNbins: 300 + xMax: 0.075 + xMin: -0.075 + fit: 'gaus' + logY: true +# +# +# + resX2: + histogramTitle: 'residuals (x) - cluster size 2' + variable: 'localPosX-rhLocalPosX' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize==2' + xTitle: '#Delta x [cm]' + xNbins: 800 + xMax: 0.040 + xMin: -0.040 + fit: 'gaus' + logY: true +# +# +# + resX3P: + histogramTitle: 'residuals (x) - cluster size >2' + variable: 'localPosX-rhLocalPosX' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize>2' + xTitle: '#Delta x [cm]' + xNbins: 300 + xMax: 0.075 + xMin: -0.075 + fit: 'gaus' + logY: true +# +# +# + stdRes2D: + histogramTitle: 'my resolution' + variable: 'abs(pathX):localPosX-rhLocalPosX' + baseCuts: 'tof<12.5&&hasRecHit>0' + xTitle: 'residual x [cm]' + xNbins: 200 + xMin: -0.1 + xMax: 0.1 + yTitle: 'dx [cm]' + yNbins: 20 + yMin: 0.0 + yMax: 0.1 +# +# +# + res2DX1: + histogramTitle: 'track dx/dz vs. residuals (x) - cluster size 1' + variable: 'pathX/pathZ:localPosX-rhLocalPosX' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize==1' + xTitle: '#Delta x [cm]' + xNbins: 300 + xMax: 0.075 + xMin: -0.075 + yNbins: 21 + yMin: -1.05 + yMax: 1.05 + logZ: true +# +# +# + res2DX2: + histogramTitle: 'track dz/dx vs. residuals (x) - cluster size 2' + variable: 'pathX/pathZ:localPosX-rhLocalPosX' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize==2' + xTitle: '#Delta x [cm]' + xNbins: 800 + xMax: 0.040 + xMin: -0.040 + yNbins: 21 + yMin: -1.05 + yMax: 1.05 + logZ: true +# +# +# + res3DXVsDxDzModX: + histogramTitle: 'residuals 3D (x)' + baseCuts: 'tof<12.5&&hasRecHit>0' + xTitle: '#Delta x [#mum]' + xNbins: 100 + xMin: -500 + xMax: 500 + zTitle: 'local dx/dz' + zNbins: 21 + zMin: -1.05 + zMax: 1.05 + mType23: + variable: 'dxdz:localPosXMod100:10000*(localPosX-rhLocalPosX)' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 20 + yMin: 0 + yMax: 100 + mType24: + variable: 'dxdz:localPosXMod100:10000*(localPosX-rhLocalPosX)' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 20 + yMin: 0 + yMax: 100 + mType25: + variable: 'dxdz:localPosXMod90:10000*(localPosX-rhLocalPosX)' + yTitle: 'x modulo 90 #mum [#mum]' + yNbins: 18 + yMin: 0 + yMax: 90 + + res3DXVsDxDz: + histogramTitle: 'residuals 3D (x)' + baseCuts: 'tof<12.5&&hasRecHit>0' + xTitle: '#Delta x [#mum]' + xNbins: 100 + xMin: -200 + xMax: 200 + zTitle: 'local dx/dz' + zNbins: 21 + zMin: -1.05 + zMax: 1.05 + mType23: + variable: 'dxdz:localPosXMod100:10000*(localPosX-rhLocalPosX)' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType24: + variable: 'dxdz:localPosXMod100:10000*(localPosX-rhLocalPosX)' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType25: + variable: 'dxdz:localPosXMod90:10000*(localPosX-rhLocalPosX)' + yTitle: 'x modulo 90 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 90 + + res3DXVsDxDzW1: + histogramTitle: 'residuals 3D (x)' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize==1' + xTitle: '#Delta x [#mum]' + xNbins: 100 + xMin: -200 + xMax: 200 + zTitle: 'local dx/dz' + zNbins: 21 + zMin: -1.05 + zMax: 1.05 + mType23: + variable: 'dxdz:localPosXMod100:10000*(localPosX-rhLocalPosX)' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType24: + variable: 'dxdz:localPosXMod100:10000*(localPosX-rhLocalPosX)' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType25: + variable: 'dxdz:localPosXMod90:10000*(localPosX-rhLocalPosX)' + yTitle: 'x modulo 90 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 90 + + res3DXVsDxDzW2: + histogramTitle: 'residuals 3D (x)' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize==2' + xTitle: '#Delta x [#mum]' + xNbins: 100 + xMin: -200 + xMax: 200 + zTitle: 'local dx/dz' + zNbins: 21 + zMin: -1.05 + zMax: 1.05 + mType23: + variable: 'dxdz:localPosXMod100:10000*(localPosX-rhLocalPosX)' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType24: + variable: 'dxdz:localPosXMod100:10000*(localPosX-rhLocalPosX)' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType25: + variable: 'dxdz:localPosXMod90:10000*(localPosX-rhLocalPosX)' + yTitle: 'x modulo 90 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 90 + + pull3DXVsDxDz: + histogramTitle: 'pulls 3D (x)' + baseCuts: 'tof<12.5&&hasRecHit>0' + xTitle: '#Delta x [#mum]' + xNbins: 100 + xMin: -10 + xMax: 10 + zTitle: 'local dx/dz' + zNbins: 21 + zMin: -1.05 + zMax: 1.05 + mType23: + variable: 'dxdz:localPosXMod100:(localPosX-rhLocalPosX)/rhLocalErrX' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType24: + variable: 'dxdz:localPosXMod100:(localPosX-rhLocalPosX)/rhLocalErrX' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType25: + variable: 'dxdz:localPosXMod90:(localPosX-rhLocalPosX)/rhLocalErrX' + yTitle: 'x modulo 90 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 90 + + pull3DXVsDxDzW1: + histogramTitle: 'pulls 3D (x)' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize==1' + xTitle: '#Delta x [#mum]' + xNbins: 100 + xMin: -10 + xMax: 10 + zTitle: 'local dx/dz' + zNbins: 21 + zMin: -1.05 + zMax: 1.05 + mType23: + variable: 'dxdz:localPosXMod100:(localPosX-rhLocalPosX)/rhLocalErrX' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType24: + variable: 'dxdz:localPosXMod100:(localPosX-rhLocalPosX)/rhLocalErrX' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType25: + variable: 'dxdz:localPosXMod90:(localPosX-rhLocalPosX)/rhLocalErrX' + yTitle: 'x modulo 90 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 90 + + pull3DXVsDxDzW2: + histogramTitle: 'pulls 3D (x)' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize==2' + xTitle: '#Delta x [#mum]' + xNbins: 100 + xMin: -10 + xMax: 10 + zTitle: 'local dx/dz' + zNbins: 21 + zMin: -1.05 + zMax: 1.05 + mType23: + variable: 'dxdz:localPosXMod100:(localPosX-rhLocalPosX)/rhLocalErrX' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType24: + variable: 'dxdz:localPosXMod100:(localPosX-rhLocalPosX)/rhLocalErrX' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType25: + variable: 'dxdz:localPosXMod90:(localPosX-rhLocalPosX)/rhLocalErrX' + yTitle: 'x modulo 90 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 90 + diff --git a/DrawHits/drawHitsTmp.yaml b/DrawHits/drawHitsTmp.yaml index 67873c4..3915a9f 100644 --- a/DrawHits/drawHitsTmp.yaml +++ b/DrawHits/drawHitsTmp.yaml @@ -1,7 +1,7 @@ # # # -effAlphaLoose: +effAlphaTight: baseCuts: 'tof<12.5&&pabs>0.3' effCuts: 'hasRecHit>0&&abs(localPos.x()-rhLocalPos.x())<0.0075' histogramTitle: 'Efficiency vs. alpha(xz) tight' @@ -16,7 +16,7 @@ effAlphaLoose: # # # -effAlphaTight: +effAlphaLoose: baseCuts: 'tof<12.5&&pabs>0.3' effCuts: 'hasRecHit>0&&abs(localPos.x()-rhLocalPos.x())<0.1' histogramTitle: 'Efficiency vs. alpha(xz) loose' @@ -421,3 +421,244 @@ widthVsPath: yNbins: 25 yMin: 0.0 yMax: 25 + +res3DXVsDxDzModX: + histogramTitle: 'residuals 3D (x)' + baseCuts: 'tof<12.5&&hasRecHit>0' + xTitle: '#Delta x [#mum]' + xNbins: 100 + xMin: -500 + xMax: 500 + zTitle: 'local dx/dz' + zNbins: 21 + zMin: -1.05 + zMax: 1.05 + mType23: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),100):10000*(localPos.x()-rhLocalPos.x())' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 20 + yMin: 0 + yMax: 100 + mType24: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),100):10000*(localPos.x()-rhLocalPos.x())' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 20 + yMin: 0 + yMax: 100 + mType25: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),90):10000*(localPos.x()-rhLocalPos.x())' + yTitle: 'x modulo 90 #mum [#mum]' + yNbins: 18 + yMin: 0 + yMax: 90 + +res3DXVsDxDz: + histogramTitle: 'residuals 3D (x)' + baseCuts: 'tof<12.5&&hasRecHit>0' + xTitle: '#Delta x [#mum]' + xNbins: 100 + xMin: -200 + xMax: 200 + zTitle: 'local dx/dz' + zNbins: 21 + zMin: -1.05 + zMax: 1.05 + mType23: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),100):10000*(localPos.x()-rhLocalPos.x())' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType24: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),100):10000*(localPos.x()-rhLocalPos.x())' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType25: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),90):10000*(localPos.x()-rhLocalPos.x())' + yTitle: 'x modulo 90 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 90 + +res3DXVsDxDzW1: + histogramTitle: 'residuals 3D (x)' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize==1' + xTitle: '#Delta x [#mum]' + xNbins: 100 + xMin: -200 + xMax: 200 + zTitle: 'local dx/dz' + zNbins: 21 + zMin: -1.05 + zMax: 1.05 + mType23: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),100):10000*(localPos.x()-rhLocalPos.x())' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType24: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),100):10000*(localPos.x()-rhLocalPos.x())' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType25: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),90):10000*(localPos.x()-rhLocalPos.x())' + yTitle: 'x modulo 90 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 90 + +res3DXVsDxDzW2: + histogramTitle: 'residuals 3D (x)' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize==2' + xTitle: '#Delta x [#mum]' + xNbins: 100 + xMin: -200 + xMax: 200 + zTitle: 'local dx/dz' + zNbins: 21 + zMin: -1.05 + zMax: 1.05 + mType23: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),100):10000*(localPos.x()-rhLocalPos.x())' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType24: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),100):10000*(localPos.x()-rhLocalPos.x())' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType25: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),90):10000*(localPos.x()-rhLocalPos.x())' + yTitle: 'x modulo 90 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 90 + +pull3DXVsDxDz: + histogramTitle: 'pulls 3D (x)' + baseCuts: 'tof<12.5&&hasRecHit>0' + xTitle: '#Delta x [#mum]' + xNbins: 100 + xMin: -10 + xMax: 10 + zTitle: 'local dx/dz' + zNbins: 21 + zMin: -1.05 + zMax: 1.05 + mType23: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),100):(localPos.x()-rhLocalPos.x())/rhLocalErr.x()' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType24: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),100):(localPos.x()-rhLocalPos.x())/rhLocalErr.x()' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType25: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),90):(localPos.x()-rhLocalPos.x())/rhLocalErr.x()' + yTitle: 'x modulo 90 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 90 + +pull3DXVsDxDzW1: + histogramTitle: 'pulls 3D (x)' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize==1' + xTitle: '#Delta x [#mum]' + xNbins: 100 + xMin: -10 + xMax: 10 + zTitle: 'local dx/dz' + zNbins: 21 + zMin: -1.05 + zMax: 1.05 + mType23: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),100):(localPos.x()-rhLocalPos.x())/rhLocalErr.x()' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType24: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),100):(localPos.x()-rhLocalPos.x())/rhLocalErr.x()' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType25: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),90):(localPos.x()-rhLocalPos.x())/rhLocalErr.x()' + yTitle: 'x modulo 90 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 90 + +pull3DXVsDxDzW2: + histogramTitle: 'pulls 3D (x)' + baseCuts: 'tof<12.5&&hasRecHit>0&&clusterSize==2' + xTitle: '#Delta x [#mum]' + xNbins: 100 + xMin: -10 + xMax: 10 + zTitle: 'local dx/dz' + zNbins: 21 + zMin: -1.05 + zMax: 1.05 + mType23: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),100):(localPos.x()-rhLocalPos.x())/rhLocalErr.x()' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType24: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),100):(localPos.x()-rhLocalPos.x())/rhLocalErr.x()' + yTitle: 'x modulo 100 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 100 + mType25: + variable: 'path.x()/path.z():floatMod(10000*localPos.x(),90):(localPos.x()-rhLocalPos.x())/rhLocalErr.x()' + yTitle: 'x modulo 90 #mum [#mum]' + yNbins: 1 + yMin: 0 + yMax: 90 + +effDxDz: + variable: 'path.x()/path.z()' + histogramTitle: 'efficiency (dx/dz)' + baseCuts: 'tof<12.5' + effCuts: 'hasRecHit>0' + xTitle: 'local dx/dz' + xNbins: 21 + xMin: -1.05 + xMax: 1.05 + +effDxDzW1: + variable: 'path.x()/path.z()' + histogramTitle: 'efficiency, 1-strip clusters (dx/dz)' + baseCuts: 'tof<12.5' + effCuts: 'hasRecHit>0&&clusterSize==1' + xTitle: 'local dx/dz' + xNbins: 21 + xMin: -1.05 + xMax: 1.05 + +effDxDzW2: + variable: 'path.x()/path.z()' + histogramTitle: 'efficiency, 2-strip clusters (dx/dz)' + baseCuts: 'tof<12.5' + effCuts: 'hasRecHit>0&&clusterSize==2' + xTitle: 'local dx/dz' + xNbins: 21 + xMin: -1.05 + xMax: 1.05 + diff --git a/DrawHits/drawHitsTmpRDF.yaml b/DrawHits/drawHitsTmpRDF.yaml new file mode 100644 index 0000000..a9d67a3 --- /dev/null +++ b/DrawHits/drawHitsTmpRDF.yaml @@ -0,0 +1,254 @@ +# +# sensor dimensions: +# +# 2S: 10 x 10 cm2; 2 x 1016 strips at 90 μm x 5 cm +# PS: 5 x 10 cm2; 2 x 960 strips at 100 μm x 2.5 cm +# PSp: 5 x 10 cm2; 32 x 960 pixel at 100 μm x 1.5 mm + +# +# definitions of new variables +# +variables: + pathX: 'path.fCoordinates.fX' + pathY: 'path.fCoordinates.fY' + pathZ: 'path.fCoordinates.fZ' + dxdz: 'pathX/pathZ' + alpha: 'atan2(abs(pathX),abs(pathZ))/3.1415*180' + localPosX: 'localPos.fCoordinates.fX' + localPosY: 'localPos.fCoordinates.fY' + rhLocalPosX: 'rhLocalPos.fCoordinates.fX' + rhLocalPosY: 'rhLocalPos.fCoordinates.fY' + rhLocalErrX: 'rhLocalErr.fCoordinates.fX' + rhLocalErrY: 'rhLocalErr.fCoordinates.fY' + localPosXMod90: 'floatMod(10000*localPos.fCoordinates.fX,90)' + localPosXMod100: 'floatMod(10000*localPos.fCoordinates.fX,100)' + localPosYMod500: 'floatMod(10*localPosY,50)/10.' + localPosYMod250: 'floatMod(10*localPosY,25)/10.' + localPosYMod15: 'floatMod(100*localPosY,15)/10' + globRho2: 'globalDir.fCoordinates.fX*globalDir.fCoordinates.fX+globalDir.fCoordinates.fY*globalDir.fCoordinates.fY' + globR2: 'globRho2+globalDir.fCoordinates.fZ*globalDir.fCoordinates.fZ' + globPt: 'pabs*sqrt(globRho2/globR2)' + detNormalT: 'detNormal.fCoordinates.fX*detNormal.fCoordinates.fX+detNormal.fCoordinates.fY*detNormal.fCoordinates.fY' +# +# definitions of canvases and histograms +# +histograms: + +# +# +# + pathX: + histogramTitle: 'path (x)' + variable: '10000*abs(pathX)' + baseCuts: 'tof<12.5&&pabs>0.3' + xTitle: 'SimHit path (x) [#mum]' + xNbins: 200 + xMax: 1000 + xMin: 0 +# +# +# + pathY: + histogramTitle: 'path (y)' + variable: '10000*abs(pathY)' + baseCuts: 'tof<12.5&&pabs>0.3' + xTitle: 'SimHit path (y [#mum])' + xNbins: 200 + xMax: 2000 + xMin: 0 +# +# +# + widthVsMod2DX: + baseCuts: 'tof<12.5&&pabs>0.3' + yTitle: 'cluster width' + yNbins: 10 + yMin: 0 + yMax: 10 + mType23: + histogramTitle: 'width vs x modula 100 #mu m' + variable: 'clusterSize:localPosXMod100' + xTitle: 'x modulo 100 #mu m [#mu m]' + xNbins: 110 + xMin: -5 + xMax: 105 + mType24: + histogramTitle: 'width vs x modula 100 #mu m' + variable: 'clusterSize:localPosXMod100' + xTitle: 'x modulo 100 #mu m [#mu m]' + xNbins: 110 + xMin: -5 + xMax: 105 + mType25: + histogramTitle: 'width vs x modula 90 #mu m' + variable: 'clusterSize:localPosXMod90' + xTitle: 'x modulo 90 #mu m [#mu m]' + xNbins: 100 + xMin: -5 + xMax: 95 +# +# +# + widthVsModX: + baseCuts: 'tof<12.5&&pabs>0.3' + profile: true + yTitle: 'cluster width' + yMin: 0 + yMax: 25 + mType23: + histogramTitle: 'width vs x modula 100 #mu m' + variable: 'clusterSize:localPosXMod100' + xTitle: 'x modulo 100 #mu m [#mu m]' + xNbins: 110 + xMin: -5 + xMax: 105 + mType24: + histogramTitle: 'width vs x modula 100 #mu m' + variable: 'clusterSize:localPosXMod100' + xTitle: 'x modulo 100 #mu m [#mu m]' + xNbins: 110 + xMin: -5 + xMax: 105 + mType25: + histogramTitle: 'width vs x modula 90 #mu m' + variable: 'clusterSize:localPosXMod90' + xTitle: 'x modulo 90 #mu m [#mu m]' + xNbins: 100 + xMin: -5 + xMax: 95 +# +# +# + widthVsModY: + baseCuts: 'tof<12.5&&pabs>0.3' + yTitle: 'cluster width' + yMin: 0 + yMax: 25 + profile: true + mType23: + histogramTitle: 'Width vs. y % 1.5 mm' + variable: 'clusterSize:localPosYMod15' + xTitle: 'y modulo 1.5mm [mm]' + xNbins: 200 + xMin: -0.25 + xMax: 1.75 + mType24: + histogramTitle: 'Width vs. y % 2.5 cm' + variable: 'clusterSize:localPosYMod250' + xTitle: 'y modulo 2.5cm [cm]' + xNbins: 300 + xMin: -0.25 + xMax: 2.75 + mType25: + histogramTitle: 'Width vs. y % 5 cm' + variable: 'clusterSize:localPosYMod500' + xTitle: 'y modulo 5cm [cm]' + xNbins: 275 + xMin: -0.25 + xMax: 5.25 +# +# +# + widthVsPath: + histogramTitle: 'width vs path' + variable: 'clusterSize:abs(pathX)' + baseCuts: 'tof<12.5&&hasRecHit>0' + profile: true + xTitle: 'SimHit path (x)' + xNbins: 100 + xMin: 0 + xMax: 0.2 + yTitle: 'clustersize' + yNbins: 25 + yMin: 0.0 + yMax: 25 + + nrhVsModX: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5' + yTitle: 'nr of rechits' + yNbins: 10 + yMin: 0 + yMax: 10 + mType23: + histogramTitle: 'nr of rechits vs. x % 100 #mu m' + variable: 'rhNMatched:localPosXMod100' + xTitle: 'x modulo 100 #mu m [#mu m]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType24: + histogramTitle: 'nr of rechits vs. x % 100 #mu m' + variable: 'rhNMatched:localPosXMod100' + xTitle: 'x modulo 100 #mu m [#mu m]' + xNbins: 220 + xMax: 105 + xMin: -5 + mType25: + histogramTitle: 'nr of rechits vs. x % 90 #mu m' + variable: 'rhNMatched:localPosXMod90' + xTitle: 'x modulo 90 #mu m [#mu m]' + xNbins: 200 + xMax: 95 + xMin: -5 + + + nrhVsModY: + baseCuts: 'tof<12.5&&pabs>0.3&&globPt>0.5' + yTitle: 'nr of rechits' + yNbins: 10 + yMin: 0 + yMax: 10 + variable: 'rhNMatched:localPosY' + histogramTitle: 'nr of rechits vs. local y' + mType23: + histogramTitle: 'nr of rechits vs. y % 1.5 mm' + variable: 'rhNMatched:localPosYMod15' + xTitle: 'y modulo 1.5mm [mm]' + xNbins: 400 + xMax: 1.75 + xMin: -0.25 + mType24: + histogramTitle: 'nr of rechits vs. y % 2.5 cm' + variable: 'rhNMatched:localPosYMod250' + xTitle: 'y modulo 2.5cm [cm]' + xNbins: 600 + xMax: 2.75 + xMin: -0.25 + mType25: + histogramTitle: 'nr of rechits vs. y % 5 cm' + variable: 'rhNMatched:localPosYMod500' + xTitle: 'y modulo 5cm [cm]' + xNbins: 550 + xMax: 5.25 + xMin: -0.25 + + nrRecHitsAll: + baseCuts: 'tof<12.' + histogramTitle: 'Number of RecHits (all)' + variable: 'rhNMatched' + xTitle: 'number of matched RecHits' + xNbins: 100 + xMax: 99.5 + xMin: -0.5 + logY: true + + nrRecHitsPabs: + baseCuts: 'tof<12.&&pabs>3.' + histogramTitle: 'Number of RecHits (all)' + variable: 'rhNMatched' + xTitle: 'number of matched RecHits' + xNbins: 100 + xMax: 99.5 + xMin: -0.5 + logY: true + + nrRecHitsPt: + baseCuts: 'tof<12.&&pabs>0.3&&globPt>0.5' + histogramTitle: 'Number of RecHits (all)' + variable: 'rhNMatched' + xTitle: 'number of matched RecHits' + xNbins: 100 + xMax: 99.5 + xMin: -0.5 + logY: true + diff --git a/DrawHits/fitRes.py b/DrawHits/fitRes.py new file mode 100644 index 0000000..9233ec1 --- /dev/null +++ b/DrawHits/fitRes.py @@ -0,0 +1,577 @@ +import sys,os +from math import sqrt,log +import ROOT +import FitHistogram +import argparse + + +class FitCanvas: + + def __init__(self,canvas,mtype): + self.canvas = canvas + self.mtype = mtype + self.pad = None + self.fhist = None + + padName = canvas.GetName()+str(mtype-22) + for o in canvas.GetListOfPrimitives(): + if o.InheritsFrom(ROOT.TPad.Class()) and o.GetName()==padName: + assert self.pad==None + self.pad = o + assert self.pad!=None + + histNameBase = "h"+canvas.GetName()[1:]+str(mtype) + self.fhist = None + for o in self.pad.GetListOfPrimitives(): + if o.InheritsFrom(ROOT.TH1.Class()) and o.GetName().startswith(histNameBase): + assert self.fhist==None + self.fhist = FitHistogram(o) + assert self.fhist!=None + + def histogram(self): + #print("fhist",self.fhist,self.fhist.hist) + return self.fhist.hist + + def fwhm(self): + return self.fhist.fwhm() + +def saveCanvas(canvas,inputName,outputDir,formats): + canvasName = canvas.GetName() + outputBaseName = os.path.splitext(os.path.basename(inputName))[0] + outputName = os.path.join(outputDir,outputBaseName) + if canvasName.split("_")[0]==outputBaseName.split("_")[0]: + canvasName = "_".join(canvasName.split("_")[1:]) + elif canvasName.startswith("c"): + canvasName = canvasName[1].lower() + canvasName[2:] + outputName += "_" + canvasName + for fmt in formats: + print("Saving canvas as",outputName+"."+fmt) + canvas.SaveAs(outputName+"."+fmt) + +def setHistogramMinMax(histo,limits,margins=0.05): + ''' Set minimum / maximum for histogram considering values within a range. + Arguments: + histo ...... histogram (TH1 or TH2) + limits ..... lower/upper limit of the range defining values to be considered + margins .... add this fraction of the min-max range below and above + Return value: + min / max value found within range + ''' + # + # min / max value can't be outside the range + # + vmin = limits[1] + vmax = limits[0] + # + # loop over all bins and updated vmin/vmax + # + for ibx in range(histo.GetNbinsX()): + for iby in range(histo.GetNbinsY()): + c = histo.GetBinContent(ibx+1,iby+1) + if c>=limits[0] and c<=limits[1]: + vmin = min(vmin,c) + vmax = max(vmax,c) + # + # apply min / max and return result + # + if (vmax-vmin)/(limits[1]-limits[0])<0.0001: + vmin,vmax = limits + histo.SetMinimum(vmin-margins*(vmax-vmin)) + histo.SetMaximum(vmax+margins*(vmax-vmin)) + + return (vmin,vmax) + +def defineWidthVsSigma(h,sigmas): + hwName = h.GetName()+"Qw1D" + hwTitle = h.GetTitle()+" (half-width from quantiles)" + hwAxis1Title = "quantiles in units of #sigmas" + hwAxis2Title = "half width from quantiles" + hhalfwidth = ROOT.TH1F(hwName,hwTitle,len(sigmas),-0.5,len(sigmas)-0.5) + hhalfwidth.SetStats(0) + hhalfwidth.SetMinimum(0.) + hhalfwidth.GetXaxis().SetTitle(hwAxis1Title) + hhalfwidth.GetYaxis().SetTitle(hwAxis2Title) + xaxis = hhalfwidth.GetXaxis() + for i,s in enumerate(sigmas): + xaxis.SetBinLabel(i+1,"{:3.1f}#sigma".format(s)) + + return hhalfwidth + +def defineMeanWidthHistograms(h,nby,ymin,ymax,nbz,zmin,zmax,isigma=None,sigma=None): + if isigma!=None: + y1 = ROOT.TMath.Freq(-sigma) + y2 = ROOT.TMath.Freq(sigma) + hcName = h.GetName()+"Qc"+str(isigma) + hcTitle = h.GetTitle()+" (median)" + hwName = h.GetName()+"Qhw"+str(isigma) + hwTitle = h.GetTitle()+" (#sigma from quantiles)".format(y1,y2) + hwAxis1Title = "median [#mum]" + hwAxis2Title = "#sigma from {:4.1%}/{:4.1%} quantiles [#mum]".format(y1,y2) + else: + y1 = None + y2 = None + hcName = h.GetName()+"Qc fit" + hcTitle = h.GetTitle()+" (fitted mean)" + hwName = h.GetName()+"Qhw fit" + hwTitle = h.GetTitle()+" (fitted sigma)" + hwAxis1Title = "mean [#mum]" + hwAxis2Title = "#sigma from fit [#mum]".format(y1,y2) + if nby==1: + hcentre = ROOT.TH1F(hcName,hcTitle,nbz,zmin,zmax) + hcentre.GetXaxis().SetTitle(h.GetZaxis().GetTitle()) + hcentre.GetYaxis().SetTitle(hwAxis1Title) + hhalfwidth = ROOT.TH1F(hwName,hwTitle,nbz,zmin,zmax) + hhalfwidth.GetXaxis().SetTitle(h.GetZaxis().GetTitle()) + hhalfwidth.GetYaxis().SetTitle(hwAxis2Title) + elif nbz==1: + hcentre = ROOT.TH1F(hcName,hcTitle,nby,ymin,ymax) + hcentre.GetXaxis().SetTitle(h.GetYaxis().GetTitle()) + hcentre.GetYaxis().SetTitle(hwAxis1Title) + hhalfwidth = ROOT.TH2F(hwName,hwTitle,nby,ymin,ymax) + hhalfwidth.GetXaxis().SetTitle(h.GetYaxis().GetTitle()) + hhalfwidth.GetYaxis().SetTitle(hwAxis2Title) + else: + hcentre = ROOT.TH2F(hcName,hctitle,nby,ymin,ymax,nbz,zmin,zmax) + hcentre.GetXaxis().SetTitle(h.GetYaxis().GetTitle()) + hcentre.GetYaxis().SetTitle(h.GetZaxis().GetTitle()) + hcentre.GetZaxis().SetTitle(hwAxis1Title) + hhalfwidth = ROOT.TH2F(hwName,hwTitle,nby,ymin,ymax,nbz,zmin,zmax) + hhalfwidth.GetXaxis().SetTitle(h.GetYaxis().GetTitle()) + hhalfwidth.GetYaxis().SetTitle(h.GetZaxis().GetTitle()) + hhalfwidth.GetZaxis().SetTitle(hwAxis2Title) + hhalfwidth.SetMinimum(0.) + + return hcentre,hhalfwidth + + +parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) +#parser.add_argument('--moduleType', '-m', help='module type', type=int, choices=[23,24,25], default=23) +parser.add_argument('--moduleTypes', '-m', help='comma-separated list of module types', type=str, default="23,24,25") +parser.add_argument('--fwhm', help='determining FWHM', action='store_true', default=False) +parser.add_argument('--slices', '-s', help='fit in slices in y', action='store_true', default=False) +parser.add_argument('--quantile', '-q', help='calculate quantiles corresponding to +- x sigma (can be repeated)', \ + action='append', type=float, default=[]) +parser.add_argument('--dbgQuantiles', help='modX,dxdz pairs defining individual bins for the quantile determination', \ + action='append', type=str, default=[ ]) +parser.add_argument('--dbgAllQuantiles', help='show residuals distributions for all bins', \ + action='store_true', default=False) +parser.add_argument('--output', '-o', help='output directory', type=str, default=None) +parser.add_argument('--formats', help='comma-separated list of extensions for output files', \ + type=str, default="pdf,png") +parser.add_argument('file', help='input file', type=str, nargs=1, default=None) +args = parser.parse_args() + +moduleTypes = sorted(set([ int(x) for x in args.moduleTypes.split(",") ])) +assert moduleTypes[0]>=23 and moduleTypes[-1]<=25 +moduleType = moduleTypes[0] + +tf = ROOT.TFile(args.file[0]) +tf.ls() +mainCnv = None +for k in tf.GetListOfKeys(): + o = k.ReadObj() + if o.IsA()==ROOT.TCanvas.Class(): + assert mainCnv==None + mainCnv = k.ReadObj() +assert mainCnv!=None + +dbgQuantPoints = [ ] +for qp in args.dbgQuantiles: + dbgQuantPoints.append( tuple([float(x.strip()) for x in qp.strip().split(",")]) ) + +if args.output!=None: + assert os.path.isdir(args.output) + outputFormats = [ x.strip() for x in args.formats.strip().split(",") ] + +canvases = [ ] +slices = [ ] + +mainCnv.Draw() +fitCanvases = { x:FitCanvas(mainCnv,x) for x in moduleTypes } +fitCanvas = fitCanvases[moduleType] +#fitCanvas = FitCanvas(mainCnv,moduleType) +fwhmArrow = ROOT.TArrow() +fwhmArrow.SetLineColor(2) +fwhmArrow.SetLineWidth(2) +quantLines = [ ] +for i in range(len(args.quantile)+1): + quantLine = ROOT.TLine() + quantLine.SetLineColor(4-i) + #quantLine.SetLineWidth(2) + #quantLine.SetLineStyle(i+1) + quantLines.append(quantLine) +#quantLine.SetLineWidth(2) +if fitCanvas.histogram().GetDimension()==1 and ( not args.slices ): + summaries = [ ] + for im in moduleTypes: + print("Module type",im) + fc = fitCanvases[im] + print(type(fc)) + assert fc.histogram().GetDimension()==1 + slices = [ fc.fhist ] + #print(fc.fwhm()) + x1,x2,y = fc.fwhm() + print(" FWHM: = {:6.1f}um, dx = {:6.1f}um, sig = {:6.1f}um ( interval {:6.4f} - {:6.4f}cm )".format( \ + 10000*(x1+x2)/2.,10000*(x2-x1),10000*(x2-x1)/2/sqrt(2*log(2)),x1,x2)) + + fc.pad.cd() + fwhmArrow.DrawArrow(x1,y,x2,y,0.005,"<>") + + # + # define summary histograms + # + summaries.append(defineWidthVsSigma(fc.histogram(),args.quantile)) + + quantiles = [ ] + qlmax = slices[-1].hist.GetMaximum()/10. + for isigma,sigma in enumerate(args.quantile): + qs = [ ] + for sgn in [-1,0,1]: + p = ROOT.TMath.Freq(sgn*sigma) + #qs.append(slices[-1].quantile(p)) + qs.append(slices[-1].findRootSpline(p)) + print(sigma,sgn,type(slices[-1])) + #print(sigma,sgn,p,qs[-1]) + quantiles.append(qs) + if not ( None in qs ): + for iq in range(3): + il = 0 if iq==1 else isigma+1 + h = slices[-1].hist + qlmax = h.GetBinContent(h.FindBin(qs[iq])) + quantLines[il].DrawLine(qs[iq],0.,qs[iq],qlmax) + line = " from sigma = {:3.1f} quantile: ".format(sigma) + line += "median = {:6.1f}um, half-width/sigma = {:6.1f}um".format(10000*qs[1], \ + 10000*(qs[2]-qs[0])/2/sigma) + print(line) + summaries[-1].SetBinContent(isigma+1,10000*(qs[2]-qs[0])/2/sigma) + #quantLines[isigma].DrawLine(qs[0],0.,qs[0],qlmax) + #quantLines[0].DrawLine(qs[1],0.,qs[1],qlmax) + #quantLines[isigma].DrawLine(qs[2],0.,qs[2],qlmax) + else: + print("(At least) one quantile computation failed: sigma =",sigma," p =",ROOT.TMath.Freq(-sigma),qs) + print(" ",slices[-1].hist.GetSumOfWeights(),slices[-1].hist.GetMaximum()) + + fc.pad.Update() + + nmod = len(moduleTypes) + cName = "c"+"_".join(h.GetName()[1:].split("_")[:-1]) + cName = cName[:-2] + "_mT" + cName[-2:] + "_Widths" + cName = "cResWidths_mT"+str(moduleType) + c = ROOT.TCanvas(cName,h.GetTitle()+" (width summary)",500*nmod,500) + c.Divide(nmod,1) + # set common maximum for all plots + hmax = max([ x.GetMaximum() for x in summaries ]) + for i in range(nmod): + c.cd(i+1) + #setHistogramMinMax(summaries[i],(-250,250),margins=0.05) + summaries[i].SetMaximum(hmax*1.05) + summaries[i].Draw("HIST") + ROOT.gPad.Update() + c.Update() + if args.output!=None: + saveCanvas(c,args.file[0],args.output,outputFormats) + +elif fitCanvas.histogram().GetDimension()==2 and args.slices: + hist2D = fitCanvas.histogram() + assert hist2D.GetDimension()==2 + yaxis = hist2D.GetYaxis() + nby = hist2D.GetNbinsY() + ncol = int(sqrt(nby)) + while ncol*ncol") + + if hProj.GetMaximum()>100: + quantiles = [ ] + qlmax = slices[-1].hist.GetMaximum()/10. + for sigma in args.quantile: + qs = [ ] + for sgn in [-1,0,1]: + p = ROOT.TMath.Freq(sgn*sigma) + #qs.append(slices[-1].quantile(p)) + qs.append(slices[-1].findRootSpline(p)) + #print(sigma,sgn,p,qs[-1]) + quantiles.append(qs) + if not ( None in qs ): + quantLine.DrawLine(qs[0],0.,qs[0],qlmax) + quantLine.DrawLine(qs[1],0.,qs[1],qlmax) + quantLine.DrawLine(qs[2],0.,qs[2],qlmax) + + ROOT.gPad.Update() + +elif fitCanvas.histogram().GetDimension()==3: + # + # calculate summary of quantiles in x + # + h = fitCanvas.histogram() + nby = h.GetNbinsY() + ymin = h.GetYaxis().GetXmin() + ymax = h.GetYaxis().GetXmax() + nbz = h.GetNbinsZ() + zmin = h.GetZaxis().GetXmin() + zmax = h.GetZaxis().GetXmax() + # + # define summary histograms + # + summaries = [ ] + for isigma,sigma in enumerate(args.quantile): +#!# y1 = ROOT.TMath.Freq(-sigma) +#!# y2 = ROOT.TMath.Freq(sigma) +#!# if nby==1: +#!# hcentre = ROOT.TH1F(h.GetName()+"Qc"+str(isigma), \ +#!# h.GetTitle()+" (median)", \ +#!# nbz,zmin,zmax) +#!# hcentre.GetXaxis().SetTitle(h.GetZaxis().GetTitle()) +#!# hcentre.GetYaxis().SetTitle("median [#mum]") +#!# hhalfwidth = ROOT.TH1F(h.GetName()+"Qhw"+str(isigma), \ +#!# h.GetTitle()+" (#sigma from quantiles)".format(y1,y2), \ +#!# nbz,zmin,zmax) +#!# hhalfwidth.GetXaxis().SetTitle(h.GetZaxis().GetTitle()) +#!# hhalfwidth.GetYaxis().SetTitle("#sigma from {:4.1%}/{:4.1%} quantiles [#mum]".format(y1,y2)) +#!# elif nbz==1: +#!# hcentre = ROOT.TH1F(h.GetName()+"Qc"+str(isigma), \ +#!# h.GetTitle()+" (median)", \ +#!# nby,ymin,ymax) +#!# hcentre.GetXaxis().SetTitle(h.GetYaxis().GetTitle()) +#!# hcentre.GetYaxis().SetTitle("median [#mum]") +#!# hhalfwidth = ROOT.TH2F(h.GetName()+"Qhw"+str(isigma), \ +#!# h.GetTitle()+" (#sigma from quantiles)".format(y1,y2), \ +#!# nby,ymin,ymax) +#!# hhalfwidth.GetXaxis().SetTitle(h.GetYaxis().GetTitle()) +#!# hhalfwidth.GetYaxis().SetTitle("#sigma from {:4.1%}/{:4.1%} quantiles [#mum]".format(y1,y2)) +#!# else: +#!# hcentre = ROOT.TH2F(h.GetName()+"Qc"+str(isigma), \ +#!# h.GetTitle()+" (median)", \ +#!# nby,ymin,ymax,nbz,zmin,zmax) +#!# hcentre.GetXaxis().SetTitle(h.GetYaxis().GetTitle()) +#!# hcentre.GetYaxis().SetTitle(h.GetZaxis().GetTitle()) +#!# hcentre.GetZaxis().SetTitle("median [#mum]") + #!# hhalfwidth = ROOT.TH2F(h.GetName()+"Qhw"+str(isigma), \ +#!# h.GetTitle()+" (#sigma from quantiles)".format(y1,y2), \ +#!# nby,ymin,ymax,nbz,zmin,zmax) +#!# hhalfwidth.GetXaxis().SetTitle(h.GetYaxis().GetTitle()) +#!# hhalfwidth.GetYaxis().SetTitle(h.GetZaxis().GetTitle()) +#!# hhalfwidth.GetZaxis().SetTitle("#sigma from {:4.1%}/{:4.1%} quantiles [#mum]".format(y1,y2)) + #!# hhalfwidth.SetMinimum(0.) + hcentre,hhalfwidth = defineMeanWidthHistograms(h,nby,ymin,ymax,nbz,zmin,zmax,isigma,sigma) + summaries.append((hcentre,hhalfwidth)) + hcentre,hhalfwidth = defineMeanWidthHistograms(h,nby,ymin,ymax,nbz,zmin,zmax,None,None) + summaries.append((hcentre,hhalfwidth)) + + dbgBins = set() + if args.dbgAllQuantiles: + # get histograms for all bins + for iy in range(nby): + for iz in range(nbz): + dbgBins.add((iy+1,iz+1)) + else: + for y,z in dbgQuantPoints: + dbgBins.add( (h.GetYaxis().FindBin(y), h.GetZaxis().FindBin(z)) ) + dbgBins = sorted(dbgBins) + + allDbgObjects = { x:[ ] for x in range(len(args.quantile)) } + allFitObjects = [ ] + nDbg = len(dbgBins) + nrow = ncol = int(sqrt(nDbg)) + while nrow*ncol100: + # ensure sufficient statistics + p1 = ROOT.TMath.Freq(-sigma) + if htmp.GetSumOfWeights()>3/p1: + #q1 = fhtmp.quantile(ROOT.TMath.Freq(-sigma)) + #q2 = fhtmp.quantile(ROOT.TMath.Freq(sigma)) + qm1 = fhtmp.findRootSpline(ROOT.TMath.Freq(-sigma)) + q0 = fhtmp.findRootSpline(ROOT.TMath.Freq(0)) + qp1 = fhtmp.findRootSpline(ROOT.TMath.Freq(sigma)) + else: + qm1 = None + q0 = None + qp1 = None + quantiles.append((qm1,q0,qp1)) + hsum = summaries[isigma][0] + if nby==1: + ibin = hsum.GetBin(iz+1) + elif nbz==1: + ibin = hsum.GetBin(iy+1) + else: + ibin = hsum.GetBin(iy+1,iz+1) + if q0!=None: + hsum.SetBinContent(ibin,q0) + else: + print("No median for bins",iy+1,iz+1,"of",htmp.GetName()) + hsum.SetBinContent(ibin,-999999) + if htmp.GetName()=="hPull3DXVsDxDzW223_1_px" and (iy+1)==1 and (iz+1)==3: + print("...",isigma,sigma,qm1,q0,qp1,htmp.GetSumOfWeights()) + hsum = summaries[isigma][1] + if qm1!=None and qp1!=None: + hsum.SetBinContent(ibin,(qp1-qm1)/2./sigma) + + #allDbgObjects[isigma] = [ ] + if (iy+1,iz+1) in dbgBins: + y1 = htmp.GetYaxis().GetBinLowEdge(iy+1) + y2 = y1 + htmp.GetYaxis().GetBinWidth(iy+1) + z1 = htmp.GetZaxis().GetBinLowEdge(iz+1) + z2 = z1 + htmp.GetZaxis().GetBinWidth(iz+1) + + hResName = "hResDbg_mT"+str(moduleType)+"_y{:02d}_z{:02d}".format(iy+1,iz+1) + hResTitle = "residual mType "+str(moduleType) + if nby>1: + hResTitle += " {:6.3f}1: + hResTitle += " {:6.3f}100: + fitPtr,fitFunc = fhtmp.fitGaus(ROOT.TMath.Freq(-2.),ROOT.TMath.Freq(2.)) + print(fitPtr,fitFunc) + if fitPtr!=None: + fitFunc2 = fitFunc.Clone() + fitFunc2.SetParameter(0,fitFunc.GetParameter(0)/hResDbgMax) + fitFunc2.Draw("same") + allFitObjects.append((fitPtr,fitFunc2)) + dbgObjects[0].Update() + hsum = summaries[-1][0] + if nby==1: + ibin = hsum.GetBin(iz+1) + elif nbz==1: + ibin = hsum.GetBin(iy+1) + else: + ibin = hsum.GetBin(iy+1,iz+1) + hsum.SetBinContent(ibin,fitPtr.Parameter(1)) + hsum.SetBinError(ibin,fitPtr.Error(1)) + hsum = summaries[-1][1] + if nby==1: + ibin = hsum.GetBin(iz+1) + elif nbz==1: + ibin = hsum.GetBin(iy+1) + else: + ibin = hsum.GetBin(iy+1,iz+1) + hsum.SetBinContent(ibin,fitPtr.Parameter(2)) + hsum.SetBinError(ibin,fitPtr.Error(2)) + else: + print("No median for bins",iy+1,iz+1,"of",htmp.GetName()) + hsum.SetBinContent(ibin,-999999) + + + allDbgObjects['canvas'].Update() + + if args.output: + saveCanvas(allDbgObjects['canvas'],args.file[0],args.output,outputFormats) + savePad.cd() + + nsigma = len(args.quantile) + # create from histogram name (remove version number last "_", split of last two digits (mod. type) + + cName = "c"+"_".join(h.GetName()[1:].split("_")[:-1]) + cName = cName[:-2] + "_mT" + cName[-2:] + "_MeanWidth" + cName = "cResMeanWidth_mT"+str(moduleType) + c = ROOT.TCanvas(cName,h.GetTitle()+" (mean/width summary)",500*nsigma,1000) + c.Divide(nsigma+1,2) + for i in range(nsigma+1): + hopt = "HIST" if i=3: + break + assert len(pads)==3 + + results = [ ] + #ctmp = ROOT.TCanvas("ctmp","ctmp",1200,800) + for p in pads: + print("Processing pad in",rootfile,p.GetName(),"with algo",algo) + #p.Draw() + #ctmp.Update() + result = processPad(p,algo) + results.append(result) + print(result) + #input("Enter") + + return results + +parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) +parser.add_argument('--zones', '-z', help='zone name(s) (trailing part of input file names, with wildcard)', \ + type=str, default='*') +parser.add_argument('--csv', help='csv output file', type=str, default=None) +parser.add_argument('--output', '-o', help='output directory for graphic output', type=str, default=None) +parser.add_argument('--formats', '-f', help='comma-separated list of extensions for output files', \ + type=str, default="pdf,png") +parser.add_argument('--mtypes', help='comma-separated list of module types', \ + type=str, default="23,24,25") +parser.add_argument('--names', help='comma-separated list of patterns to match file names', \ + type=str, default="*") +parser.add_argument('--algorithms', '-a', help='comma-separated list of algorithms used for fit results', \ + type=str, default='prefit' ) +parser.add_argument('--verbose', '-v', help='verbose output', action='store_true', default=False) +parser.add_argument('directories', help='directories with stored canvases in root format', type=str, nargs='+') +args = parser.parse_args() +if args.output!=None: + assert os.path.isdir(args.output) +zones = [ x.strip() for x in args.zones.split(",") ] +reqFNames = [ x.strip() for x in args.names.split(",") ] +reqMTypes = [ int(x.strip()) for x in args.mtypes.split(",") ] +allAlgos = [ 'prefit', 'gaus', 'fwhm', 'q1sig', 'q2sig', 'q3sig' ] +reqAlgos = [ ] +for a in [ x.strip().lower() for x in args.algorithms.split(",") ]: + assert a in allAlgos + reqAlgos.append(a) + +ROOT.gStyle.SetOptStat(0) +allResults = { } +allFnGens = set() +newFnGens = { } +for d in args.directories: + assert os.path.isdir(d) + dn = os.path.basename(os.path.normpath(d)) + assert not dn in allResults + allResults[dn] = { } + dnResults = allResults[dn] + + fncode = None + for root,dirs,files in os.walk(d): + for f in files: + fname,fext = os.path.splitext(f) + if fext!=".root": + continue + if not any([ fnmatch(fname,x) for x in reqFNames ]): + continue + fields = fname.split("_") + fngen = ( fields[0],"_".join(fields[2:]) ) + if not any([ fnmatch(fngen[1],x) for x in zones ]): + continue + if fncode!=None: + assert fields[1]==fncode + else: + fncode = fields[1] + dnResults[fngen] = { } + for algo in reqAlgos: + results = processFile(os.path.join(root,f),algo) + #print("processFile",os.path.join(root,f),algo,results) + nNone = sum([ x==None for x in results ]) + if nNone>0 and nNone<3: + print("*** 1 or 2 invalide results",fname,results) + #assert nNone==0 or nNone==3 + #!#if nNone==0: + #fngen = "_".join(fields[:1]+fields[2:]) + fngen = ( fields[0],"_".join(fields[2:]) ) + allFnGens.add(fngen) + #assert not fngen in dnResults + dnResults[fngen][algo] = results + print("Algo =",algo) + +if args.verbose: + for dn in allResults: + print(dn) + for fngen in allResults[dn]: + print(" fngen",fngen,type(allResults[dn])) + for algo in allResults[dn][fngen]: + print(" ",algo) + for ir,r in enumerate(allResults[dn][fngen][algo]): + print(" ",ir,r) +#print(dnResults) +#print(allFnGens) + +allMTypes = range(23,26) +mTypes = reqMTypes +parNames = [ 'mean', 'width' ] +dns = sorted(allResults.keys()) +nDns = len(dns) + +#!# if args.csv!=None: +#!# with open("tmpFitResults.csv","wt") as csvFile: +#!# csvWriter = csv.writer(csvFile) + +#!# hdrRow1 = [ 'Canvas' ] +#!# hdrRow2 = [ '' ] +#!# hdrRow3 = [ '' ] +#!# for pn in parNames: +#!# hdrRow1.append(pn) +#!# hdrRow1.extend((nDns*len(mTypes)-1)*['']) +#!# for mtype in mTypes: +#!# hdrRow2.append("mType "+str(mtype)) +#!# hdrRow2.extend((nDns-1)*['']) +#!# for dn in dns: +#!# hdrRow3.append(dn) +#!# csvWriter.writerow(hdrRow1) +#!# csvWriter.writerow(hdrRow2) +#!# csvWriter.writerow(hdrRow3) + +#!# for fnGen in sorted(allFnGens): +#!# row = len(hdrRow1)*[ '' ] +#!# row[0] = "_".join(fnGen) +#!# idx = 1 +#!# for ipn in range(len(parNames)): +#!# for im in range(len(mTypes)): +#!# for idn,dn in enumerate(dns): +#!# dnResults = allResults[dn] +#!# if fnGen in dnResults: +#!# fnResults = dnResults[fnGen] +#!# if fnGen=='cPullXW1_barrel': +#!# print(ipn,im,idn,dn) +#!# print(" ",fnResults[im][ipn]) +#!# idx = 1 + idn + im*len(dns) + ipn*len(dns)*len(mTypes) +#!# v = fnResults[im][ipn][0] +#!# r = "{:4g}".format(v) +#!# if "pull" in fnGen.lower(): +#!# if parNames[ipn]=='mean': +#!# r = '{:7.3f}'.format(v) +#!# elif parNames[ipn]=='width': +#!# r = '{:7.3f}'.format(v) +#!# if "res" in fnGen.lower(): +#!# if parNames[ipn]=='mean': +#!# r = '{:7.2f}'.format(10000*v) +#!# elif parNames[ipn]=='width': +#!# r = '{:7.2f}'.format(10000*v) +#!# #row[idx] = str(fnResults[im][ipn][0]) +#!# row[idx] = r +#!# csvWriter.writerow(row) + +#!# csvFile.close() + +cnvs = { } +frames = [ ] +legs = [ ] +graphs = { } +fnRoots = set( [ x[0] for x in allFnGens ] ) +fnZones = set( [ x[1] for x in allFnGens ] ) +for fnRoot in sorted(fnRoots): + cnvs[fnRoot] = { x:{ } for x in parNames } + graphs[fnRoot] = { x:{ } for x in parNames } + for ipn,pn in enumerate(parNames): + cnvName = fnRoot+"-"+pn + cnv = ROOT.TCanvas(cnvName,cnvName,600,600) + cnv.SetBottomMargin(0.15) + cnvs[fnRoot][pn] = cnv + graphs[fnRoot][pn] = { } + for fnZone in fnZones: + graphs[fnRoot][pn][fnZone] = { } + for mt in reqMTypes: + graphs[fnRoot][pn][fnZone][mt] = { } + for a in reqAlgos: + graphs[fnRoot][pn][fnZone][mt][a] = { } + + #graphs[fnRoot][pn] = { x:{ } for x in mTypes } + frames.append(ROOT.TH1F("h"+fnRoot[1:]+"-"+pn,fnRoot[1:]+"-"+pn,nDns,-0.5,nDns-0.5)) + if pn=='mean': + #frames.append(cnv.DrawFrame(-0.5,-1,nDns-0.5,1)) + if "pull" in fnRoot.lower(): + frames[-1].GetYaxis().SetTitle('mean (pull)') + elif "res" in fnRoot.lower(): + frames[-1].GetYaxis().SetTitle('mean (residual) #mm') + elif pn=='width': + #frames.append(cnv.DrawFrame(-0.5,0,nDns-0.5,100)) + if "pull" in fnRoot.lower(): + frames[-1].GetYaxis().SetTitle('sigma (pull)') + elif "res" in fnRoot.lower(): + frames[-1].GetYaxis().SetTitle('sigma (residual) #mm') + for idn,dn in enumerate(dns): + frames[-1].GetXaxis().SetBinLabel(idn+1,dn) + frames[-1].GetXaxis().SetLabelSize(0.05) + ymin,ymax = 1.e30,-1.e30 + lstyle = MyColors([1,2,3]) + for iz,fnZone in enumerate(sorted(fnZones)): + istyle = lstyle.next() + mstyle = MyColors(list(range(20,28))) + style = iz + 1 + for im,mt in enumerate(allMTypes): + if not mt in reqMTypes: + continue + color = MyColors() + marker = mstyle.next() + for ia,algo in enumerate(reqAlgos): + ic = color.next() + #marker = ia + 20 + graph = ROOT.TGraphErrors() + graph.SetName("g"+fnZone+"-"+pn+"-"+str(mt)+"-"+algo) + graph.SetTitle("g"+fnZone+"-"+pn+"-"+str(mt)+"-"+algo) + graph.SetLineWidth(2) + #ic = color.next() + graph.SetLineColor(ic) + graph.SetLineStyle(istyle) + graph.SetMarkerStyle(marker) + #marker += 1 + graph.SetMarkerColor(ic) + graphs[fnRoot][pn][fnZone][mt][algo] = graph + fnGen = ( fnRoot, fnZone ) + for idn,dn in enumerate(dns): + dnResults = allResults[dn] + if fnGen in dnResults: + fnResults = dnResults[fnGen] + if ( algo in fnResults ) and fnResults[algo][im]!=None: + v,e = fnResults[algo][im][ipn] + print("Results",fnRoot,pn,fnZone,mt,algo,dn,v) + print(" ",algo,fnResults[algo]) + print(" ",algo,im,fnResults[algo][im]) + if "res" in fnRoot.lower(): + v *= 10000 + e *= 10000 + graph.AddPointError(idn+nDns*iz/50,v,0.,e) + #if graph.GetName().startswith("gendcap-width-25-q") and \ + # graph.GetName().endswith("sig"): + # print("+++",graph.GetName(),fnRoot,pn,fnZone,mt,algo,dn,v) + ymin = min(ymin,v-e) + ymax = max(ymax,v+e) + if pn=='mean': + dy = ymax - ymin + ymin -= dy*0.05 + ymax += dy*0.15 + elif pn=='width': + ymin -= (ymax-ymin)*0.05 + ymax *= 1.15 + frames[-1].SetMinimum(ymin) + frames[-1].SetMaximum(ymax) + frames[-1].Draw() + legArguments = [ ] + for fnZone in sorted(fnZones): + for algo in reqAlgos: + legArguments.append(("",fnZone+" "+algo,"")) + for mt in allMTypes: + if mt in mTypes: + legArguments.append((graphs[fnRoot][pn][fnZone][mt][algo],"mType "+str(mt),"LP")) + graphs[fnRoot][pn][fnZone][mt][algo].Draw("PL") + else: + legArguments.append((""," ","")) + + leg = ROOT.TLegend(0.10,0.90-0.02*len(legArguments)/4,0.90,0.90) + leg.SetNColumns(4) + leg.SetBorderSize(0) + leg.SetFillStyle(0) + legs.append(leg) + for largs in legArguments: + leg.AddEntry(*largs) + leg.Draw() + cnv.Update() + if args.output!=None: + for fmt in [ x.strip() for x in args.formats.split(",") ]: + fnout = os.path.join(args.output,cnv.GetName()+"."+fmt) + cnv.SaveAs(fnout) + + diff --git a/DrawHits/floatMod.C b/DrawHits/floatMod.C index 1950020..5c1585a 100644 --- a/DrawHits/floatMod.C +++ b/DrawHits/floatMod.C @@ -1,5 +1,7 @@ #include #include +#include +using RVecF = ROOT::VecOps::RVec; float floatMod(float a, float b) { // @@ -10,3 +12,15 @@ float floatMod(float a, float b) { if ( result < 0. ) result += b; return result; } + + +RVecF floatMod(const RVecF& a, float b) { + // + // apply floatMod to RVec of floats + // + RVecF result = RVecF(a.size()); + for ( unsigned int i=0; i0.3 + alpha_loose: tof<12.5 && pabs>0.3 & hasRecHit>0 & abs(localPosX-rhLocalPosX)<0.1 + alpha_tight: tof<12.5 && pabs>0.3 & hasRecHit>0 & abs(localPosX-rhLocalPosX)<0.0075 + variables: + - alpha + 2d_plots: + effVsModXM23: + selections: + modXM23_base: tof<12.5 && pabs>0.3 && moduleType==23 + modXM23_tight: tof<12.5 && pabs>0.3 && hasRecHit>0 && abs(localPosX-rhLocalPosX)<0.0075 && moduleType==23 + variables: + - localPosXMod100 + 2d_plots: + effVsModXM24: + selections: + modXM24_base: tof<12.5 && pabs>0.3 && moduleType==24 + modXM24_tight: tof<12.5 && pabs>0.3 && hasRecHit>0 && abs(localPosX-rhLocalPosX)<0.0075 && moduleType==24 + variables: + - localPosXMod100 + 2d_plots: + effVsModXM25: + selections: + modXM25_base: tof<12.5 && pabs>0.3 && moduleType==25 + modXM25_tight: tof<12.5 && pabs>0.3 && hasRecHit>0 && abs(localPosX-rhLocalPosX)<0.0075 && moduleType==25 + variables: + - localPosXMod90 + 2d_plots: + effVsModX1M23: + selections: + modX1M23_base: tof<12.5 && pabs>0.3 && pabs*globPt>0.5 && hasRecHit>0 + modX1M23_1: clusterSize==1 + variables: + - localPosXMod100 + 2d_plots: + effVsModX2M23: + selections: + modX2M23_base: tof<12.5 && pabs>0.3 && pabs*globPt>0.5 && hasRecHit>0 + modX2M23_2: clusterSize==2 + variables: + - localPosXMod100 + 2d_plots: + effVsModX3pM23: + selections: + modX3pM23_base: tof<12.5 && pabs>0.3 && pabs*globPt>0.5 && hasRecHit>0 + modX3pM23_3p: clusterSize>2 + variables: + - localPosXMod100 + 2d_plots: + +# effVsModXM24: +# selections: +# modXM24_base: tof<12.5 && pabs>0.3 +# modXM24_tight: tof<12.5 && pabs>0.3 & hasRecHit>0 & abs(localPosX-rhLocalPosX)<0.0075 & moduleType=24 +# variables: +# - localPosXMod100 +# 2d_plots: +# effVsModXM25: +# selections: +# modXM25_base: tof<12.5 && pabs>0.3 +# modXM25_tight: tof<12.5 && pabs>0.3 & hasRecHit>0 & abs(localPosX-rhLocalPosX)<0.0075 & moduleType=25 +# variables: +# - localPosXMod90 +# 2d_plots: + effRecHits: + selections: + dxdz_all: tof<12.5 + dxdz_recHit: tof<12.5 & hasRecHit>0 + variables: + - dxdz + 2d_plots: + + +### PLOT SETTING +# This section defines the name, titles, binning of histograms +# usage: variable_name: [name,title,number of bins,range mininum,range maximum] +plot_setting: + dxdz: [dxdz,'dx/dz (all):local dx/dz:entries / bin',21,-1.05,1.05] + alpha: [alpha,'Efficiency vs. alpha(xz): alpha(xz) [deg]:entries / bin',100,0.,100.] + localPosXMod100: [localPosXMod100,'Efficiency vs. x % 100 #mu m: x modulo 100 #mu m [#mu m]:entries/bin',220,-5,105] + localPosXMod90: [localPosXMod90,'Efficiency vs. x % 90 #mu m: x modulo 90 #mu m [#mu m]:entries/bin',220,-5,95] diff --git a/DrawHits/showHitsConfiguration.py b/DrawHits/showHitsConfiguration.py new file mode 100644 index 0000000..925a7c7 --- /dev/null +++ b/DrawHits/showHitsConfiguration.py @@ -0,0 +1,50 @@ +# +# Show definitions for histograms from a configuration file +# +import sys +from drawHitsConfiguration import * +import argparse + +def printDict(d,indent=0): + for k,v in d.items(): + if type(v)==dict: + print(indent*" "+k+":") + printDict(v,indent+2) + else: + print(indent*" "+k+":",v) + +if __name__=="__main__": + parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument('--isEff', help='Select efficiency plots', action='store_true', default=False) + parser.add_argument('--isNoEff', help='Veto efficiency plots', action='store_true', default=False) + parser.add_argument('--isProfile', help='Select profile histograms', action='store_true', default=False) + parser.add_argument('--isNoProfile', help='Veto profile histograms', action='store_true', default=False) + parser.add_argument('--is1D', help='Select 1D histograms', action='store_true', default=False) + parser.add_argument('--is2D', help='Select 2D histograms', action='store_true', default=False) + parser.add_argument('--is3D', help='Select 3D histograms', action='store_true', default=False) + parser.add_argument('--verbose', '-v', help='Show details for selected histograms', \ + action='store_true', default=False) + parser.add_argument('file', help='yaml defining efficiency histograms', type=str, nargs=1, default=None) + args = parser.parse_args() + + allVDefs,allHDefs = loadConfiguration(args.file[0],['*']) + print() + + for hDef in allHDefs.allDefinitions.values(): + skip = True + if args.is1D and hDef('yNbins')==None: + skip = False + if args.is2D and hDef('yNbins')!=None and hDef('zNbins')==None: + skip = False + if args.is3D and hDef('zNbins')!=None: + skip = False + if skip: + continue + if ( args.isEff and hDef('effCuts')==None ) or ( args.isNoEff and hDef('effCuts')!=None ) : + continue + if ( args.isProfile and hDef('profile')==None ) or ( args.isNoProfile and hDef('profile')!=None ) : + continue + print(hDef.name) + if args.verbose: + printDict(hDef.parameters,2) + diff --git a/HitAnalyzer/interface/ClusterSimTracks.h b/HitAnalyzer/interface/ClusterSimTracks.h new file mode 100644 index 0000000..e84dfd0 --- /dev/null +++ b/HitAnalyzer/interface/ClusterSimTracks.h @@ -0,0 +1,49 @@ +#ifndef HITANALYZER_CLUSTERSIMTRACKS_H +#define HITANALYZER_CLUSTERSIMTRACKS_H + +#include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h" +#include "DataFormats/Phase2TrackerCluster/interface/Phase2TrackerCluster1D.h" +/* #include "DataFormats/TrackerRecHit2D/interface/Phase2TrackerRecHit1D.h" */ +#include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h" +#include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/Common/interface/DetSetVector.h" + +class ClusterSimTracks { + // + // Class to return (and cache) SimTrack ids for a cluster + // + public: + + ClusterSimTracks(const Phase2TrackerCluster1D& cluster, const DetId& detId, + const edm::DetSetVector& pixelSimLinks): + cluster_(cluster), detId_(detId), pixelSimLinks_(pixelSimLinks), simTracksValid_(false) {}; + + // + // Get SimTrack ids for specific channel + // + std::set simTrackIdsPerChannel(unsigned int channel) const; + // + // Check if SimTrack id contributed to cluster + // + bool simTrackInCluster(unsigned int simTrackId) const; + // + // All SimTrack ids contributing to cluster + // + const std::set& simTrackIds() const; + // + // Access to DetId (for reference) + // + const DetId& detId() const {return detId_;}; + // + // Verify if DetId matches with current object + // + bool sameDet(const DetId& detId) const {return detId_==detId;}; + + private: + const Phase2TrackerCluster1D& cluster_; // Pointer to cluster + const DetId detId_; // DetId (for reference) + const edm::DetSetVector& pixelSimLinks_; // PixelDigiSimLinks for finding SimTrack contributions + mutable bool simTracksValid_; // Has cache been filled? + mutable std::set simTrackIds_; // Cache of all SimTrack ids +}; +#endif diff --git a/HitAnalyzer/interface/CommonHitInfo.h b/HitAnalyzer/interface/CommonHitInfo.h new file mode 100644 index 0000000..5689f04 --- /dev/null +++ b/HitAnalyzer/interface/CommonHitInfo.h @@ -0,0 +1,101 @@ +#ifndef HITANALYZER_COMMONHITINFO_H +#define HITANALYZER_COMMONHITINFO_H + +#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" + +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h" +#include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h" +#include "DataFormats/TrackerRecHit2D/interface/Phase2TrackerRecHit1D.h" +#include "SimDataFormats/Track/interface/SimTrack.h" +#include "Phase2Tracking/HitAnalyzer/interface/ClusterSimTracks.h" + +#include "DataFormats/Math/interface/Point3D.h" +#include "DataFormats/Math/interface/Vector3D.h" +#include + +#include "TTree.h" + +/// spatial vector with cartesian internal representation +typedef ROOT::Math::DisplacementVector2D > XYVectorF; + +class CommonHitInfo { + + public: + + typedef std::map< unsigned int, std::vector > DetSimHitsMap; + typedef std::pair< unsigned int, std::vector > DetSimHitsPair; + typedef std::map< unsigned int, std::vector > DetRecHitsMap; + typedef std::pair< unsigned int, std::vector > DetRecHitsPair; + typedef std::map RecHitClusterMap; + + typedef std::pair RecHitDistancePair; + typedef std::vector RecHitDistancePairs; + + typedef std::map TrackIdSimTrackMap; + + typedef std::map ClusterSimTracksMap; + + CommonHitInfo() { + tTopo_ = 0; + tkGeom_ = 0; + simTracksById_ = 0; + }; + + ~CommonHitInfo() {} + + std::vector getSimTrackId(const DetId&, unsigned int); + + void fillSimHitsPerDet(const std::vector& simHitsRaw); + + void fillRecHitsPerDet(const Phase2TrackerRecHit1DCollectionNew& rechits); + + RecHitDistancePairs matchRecHitOnDet(const PSimHit* simHit, const DetId& detId, + const std::vector& detRecHits); + + + void setupEvent(const TrackerTopology* topo, const TrackerGeometry* geom, + const edm::DetSetVector* links, + const std::vector& simHitsRaw, + const Phase2TrackerRecHit1DCollectionNew& rechits, + const TrackIdSimTrackMap* simTrackMap) { + tTopo_ = topo; + tkGeom_ = geom; + pixelSimLinks = links; + simTracksById_ = simTrackMap; + // + // fill SimHit map + // + fillSimHitsPerDet(simHitsRaw); + // + // fill RecHit map (uses SimHit map!) + // + fillRecHitsPerDet(rechits); + // + // reset cluster map + // + clustersByHit_.clear(); + } + + const DetSimHitsMap& simHitsPerDet() { + return simHitsPerDet_; + } + + const DetRecHitsMap& recHitsPerDet() { + return recHitsPerDet_; + } + + protected: + const TrackerTopology* tTopo_; + const TrackerGeometry* tkGeom_; + const edm::DetSetVector* pixelSimLinks; + const TrackIdSimTrackMap* simTracksById_; + + private: + DetSimHitsMap simHitsPerDet_; + DetRecHitsMap recHitsPerDet_; + RecHitClusterMap clustersByHit_; + ClusterSimTracksMap cstByCluster_; +}; + +#endif diff --git a/HitAnalyzer/interface/RecHitInfo.h b/HitAnalyzer/interface/RecHitInfo.h index 1c1e561..5771c81 100644 --- a/HitAnalyzer/interface/RecHitInfo.h +++ b/HitAnalyzer/interface/RecHitInfo.h @@ -1,6 +1,7 @@ #ifndef HITANALYZER_RECHITINFO_H #define HITANALYZER_RECHITINFO_H +#include "Phase2Tracking/HitAnalyzer/interface/CommonHitInfo.h" #include "DataFormats/Common/interface/DetSetVector.h" #include "DataFormats/TrackerRecHit2D/interface/Phase2TrackerRecHit1D.h" @@ -18,7 +19,7 @@ #include "TTree.h" -class RecHitInfo { +class RecHitInfo : public CommonHitInfo { public: struct RecHitData @@ -59,44 +60,46 @@ class RecHitInfo { std::vector moduleType; std::vector detNormal; std::vector trackId; + std::vector nSimTracks; }; RecHitData recHitData; RecHitInfo() { - tTopo = 0; - tkGeom = 0; + /* tTopo = 0; */ + /* tkGeom = 0; */ }; ~RecHitInfo() {} void setBranches(TTree& tree); - std::vector getSimTrackId( - edm::Handle >& pixelSimLinks, - const DetId& detId, unsigned int channel); + /* std::vector getSimTrackId( */ + /* edm::Handle >& pixelSimLinks, */ + /* const DetId& detId, unsigned int channel); */ void fillSimHitInfo(const PSimHit& simHit); void fillRecHitInfo(const Phase2TrackerRecHit1D& recHit, unsigned int rawid, const GeomDetUnit* geomDetUnit, - edm::Handle >* pixelSimLinks, - std::map& simTracks, edm::Handle* simHitsRaw, + // edm::Handle >* pixelSimLinks, + // std::map& simTracks, + const std::vector& simHitsRaw, bool debugHitMatch); void clear(); - void setTopology(const TrackerTopology* topo) { - tTopo = topo; - } + /* void setTopology(const TrackerTopology* topo) { */ + /* tTopo = topo; */ + /* } */ - void setGeometry(const TrackerGeometry* geom) { - tkGeom = geom; - } + /* void setGeometry(const TrackerGeometry* geom) { */ + /* tkGeom = geom; */ + /* } */ private: - const TrackerTopology* tTopo; - const TrackerGeometry* tkGeom; + /* const TrackerTopology* tTopo; */ + /* const TrackerGeometry* tkGeom; */ }; #endif diff --git a/HitAnalyzer/interface/SimHitInfo.h b/HitAnalyzer/interface/SimHitInfo.h index 18aa7e1..3daa0fe 100644 --- a/HitAnalyzer/interface/SimHitInfo.h +++ b/HitAnalyzer/interface/SimHitInfo.h @@ -1,6 +1,7 @@ #ifndef HITANALYZER_SIMHITINFO_H #define HITANALYZER_SIMHITINFO_H +#include "Phase2Tracking/HitAnalyzer/interface/CommonHitInfo.h" #include "DataFormats/TrackerCommon/interface/TrackerTopology.h" #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" @@ -18,17 +19,17 @@ /// spatial vector with cartesian internal representation typedef ROOT::Math::DisplacementVector2D > XYVectorF; -class SimHitInfo { +class SimHitInfo : public CommonHitInfo { - typedef std::map< unsigned int, std::vector > DetSimHitsMap; - typedef std::pair< unsigned int, std::vector > DetSimHitsPair; - typedef std::map< unsigned int, std::vector > DetRecHitsMap; - typedef std::pair< unsigned int, std::vector > DetRecHitsPair; + /* typedef std::map< unsigned int, std::vector > DetSimHitsMap; */ + /* typedef std::pair< unsigned int, std::vector > DetSimHitsPair; */ + /* typedef std::map< unsigned int, std::vector > DetRecHitsMap; */ + /* typedef std::pair< unsigned int, std::vector > DetRecHitsPair; */ - typedef std::pair RecHitDistancePair; - typedef std::vector RecHitDistancePairs; + /* typedef std::pair RecHitDistancePair; */ + /* typedef std::vector RecHitDistancePairs; */ - typedef std::map TrackIdSimTrackMap; + /* typedef std::map TrackIdSimTrackMap; */ public: struct SimHitData { @@ -73,60 +74,65 @@ class SimHitInfo { SimHitData simHitData; SimHitInfo() { - tTopo_ = 0; - tkGeom_ = 0; - simTracksById_ = 0; + /* tTopo_ = 0; */ + /* tkGeom_ = 0; */ + /* simTracksById_ = 0; */ }; ~SimHitInfo() {} void setBranches(TTree& tree); - std::vector getSimTrackId(const DetId&, unsigned int); + /* std::vector getSimTrackId(const DetId&, unsigned int); */ - void fillSimHitsPerDet(edm::Handle *simHitsRaw); + /* void fillSimHitsPerDet(const std::vector& simHitsRaw); */ - void fillRecHitsPerDet(const Phase2TrackerRecHit1DCollectionNew& rechits); + /* void fillRecHitsPerDet(const Phase2TrackerRecHit1DCollectionNew& rechits); */ // const Phase2TrackerRecHit1D* matchRecHitOnDet(const PSimHit* simHit, const DetId& detId, // const std::vector& detRecHits); - RecHitDistancePairs matchRecHitOnDet(const PSimHit* simHit, const DetId& detId, - const std::vector& detRecHits); + /* RecHitDistancePairs matchRecHitOnDet(const PSimHit* simHit, const DetId& detId, */ + /* const std::vector& detRecHits); */ void fillSimHitInfo(const PSimHit& simHit); void clear(); - void setupEvent(const TrackerTopology* topo, const TrackerGeometry* geom, - const edm::DetSetVector* links, - edm::Handle *simHitsRaw, - const Phase2TrackerRecHit1DCollectionNew& rechits, - const TrackIdSimTrackMap* simTrackMap) { - tTopo_ = topo; - tkGeom_ = geom; - pixelSimLinks = links; - simTracksById_ = simTrackMap; - // fill SimHit map - // - // simHitsPerDet_.clear(); - fillSimHitsPerDet(simHitsRaw); - // - // fill RecHit map (uses SimHit map!) - // - // recHitsPerDet_.clear(); - fillRecHitsPerDet(rechits); - } + /* void setupEvent(const TrackerTopology* topo, const TrackerGeometry* geom, */ + /* const edm::DetSetVector* links, */ + /* const std::vector& simHitsRaw, */ + /* const Phase2TrackerRecHit1DCollectionNew& rechits, */ + /* const TrackIdSimTrackMap* simTrackMap) { */ + + /* commonHitInfo.setupEvent(topo,geom,links,simHitsRaw,rechits,simTrackMap); */ + + /* tTopo_ = topo; */ + /* tkGeom_ = geom; */ + /* pixelSimLinks = links; */ + /* simTracksById_ = simTrackMap; */ + /* /\* // fill SimHit map *\/ */ + /* /\* // *\/ */ + /* /\* // simHitsPerDet_.clear(); *\/ */ + /* /\* fillSimHitsPerDet(simHitsRaw); *\/ */ + /* /\* // *\/ */ + /* /\* // fill RecHit map (uses SimHit map!) *\/ */ + /* /\* // *\/ */ + /* /\* // recHitsPerDet_.clear(); *\/ */ + /* /\* fillRecHitsPerDet(rechits); *\/ */ + /* } */ private: - const TrackerTopology* tTopo_; - const TrackerGeometry* tkGeom_; - const edm::DetSetVector* pixelSimLinks; + /* const TrackerTopology* tTopo_; */ + /* const TrackerGeometry* tkGeom_; */ + /* const edm::DetSetVector* pixelSimLinks; */ + + /* DetSimHitsMap simHitsPerDet_; */ + /* DetRecHitsMap recHitsPerDet_; */ - DetSimHitsMap simHitsPerDet_; - DetRecHitsMap recHitsPerDet_; + /* const TrackIdSimTrackMap* simTracksById_; */ - const TrackIdSimTrackMap* simTracksById_; + CommonHitInfo commonHitInfo_; }; #endif diff --git a/HitAnalyzer/plugins/RecHitTreeWA.cc b/HitAnalyzer/plugins/RecHitTreeWA.cc index 5794b93..376521a 100644 --- a/HitAnalyzer/plugins/RecHitTreeWA.cc +++ b/HitAnalyzer/plugins/RecHitTreeWA.cc @@ -66,6 +66,9 @@ class RecHitTreeWA : public edm::one::EDAnalyzer { const edm::EDGetTokenT tokenSimHitsE_; const edm::EDGetTokenT tokenSimTracks_; + std::vector> shInfoSimHitTokens_; + std::vector> rhInfoSimHitTokens_; + const double simtrackminpt_; SimHitInfo simHitInfo_; @@ -105,6 +108,26 @@ RecHitTreeWA::RecHitTreeWA(const edm::ParameterSet& cfg) simtrackminpt_(cfg.getParameter("SimTrackMinPt")), debugHitMatch_(cfg.getParameter("debugHitMatch")) { + // + // SimHit collections for the SimHitInfo part + // + const edm::ParameterSet shInfoPSet(cfg.getParameter("simHitInfo")); + const std::vector + shInfoSimHitTags(shInfoPSet.getParameter>("simHits")); + for ( auto vpsetIt=shInfoSimHitTags.begin(); vpsetIt!=shInfoSimHitTags.end(); ++vpsetIt ) { + std::cout << "Getting shInfoSimHitToken" << std::endl; + shInfoSimHitTokens_.push_back(consumes(*vpsetIt)); + } + // + // RecHit collections for the RecHitInfo part + // + const edm::ParameterSet rhInfoPSet(cfg.getParameter("recHitInfo")); + const std::vector + rhInfoSimHitTags(rhInfoPSet.getParameter>("simHits")); + for ( auto vpsetIt=rhInfoSimHitTags.begin(); vpsetIt!=rhInfoSimHitTags.end(); ++vpsetIt ) { + std::cout << "Getting rhInfoSimHitToken" << std::endl; + rhInfoSimHitTokens_.push_back(consumes(*vpsetIt)); + } //recHitInfo_ = new RecHitInfo; //simTrackInfo = new SimTrackInfo; //simHitInfo_ = new SimHitInfo(); @@ -133,18 +156,40 @@ void RecHitTreeWA::analyze(const edm::Event& event, const edm::EventSetup& event // Get the PixelDigiSimLinks edm::Handle > pixelSimLinks; event.getByToken(tokenLinks_, pixelSimLinks); - - // Get the SimHits - edm::Handle simHitsRaw[2]; - event.getByToken(tokenSimHitsB_, simHitsRaw[0]); - event.getByToken(tokenSimHitsE_, simHitsRaw[1]); + // + // Get the SimHits for SimHitInfo + // + edm::Handle simHitHandle; + // edm::Handle simHitsRaw[2]; + // event.getByToken(tokenSimHitsB_, simHitsRaw[0]); + // event.getByToken(tokenSimHitsE_, simHitsRaw[1]); + std::vector shInfoSimHitsRaw; + for ( auto tokenIt=shInfoSimHitTokens_.begin(); tokenIt!=shInfoSimHitTokens_.end(); ++tokenIt ) { + event.getByToken(*tokenIt, simHitHandle); + shInfoSimHitsRaw.push_back(simHitHandle.product()); + } + // + // Get the SimHits for RecHitInfo + // + // edm::Handle simHitHandle; + std::vector rhInfoSimHitsRaw; + for ( auto tokenIt=rhInfoSimHitTokens_.begin(); tokenIt!=rhInfoSimHitTokens_.end(); ++tokenIt ) { + event.getByToken(*tokenIt, simHitHandle); + rhInfoSimHitsRaw.push_back(simHitHandle.product()); + } + + // event.getByToken(tokenSimHitsB_, simHitHandle); + // shInfoSimHitsRaw.push_back(simHitHandle.product()); + // event.getByToken(tokenSimHitsE_, simHitHandle); + // shInfoSimHitsRaw.push_back(simHitHandle.product()); // Get the SimTracks edm::Handle simTracksRaw; event.getByToken(tokenSimTracks_, simTracksRaw); // std::cout << "#simTracks " << simTracksRaw.product()->size() << std::endl; - + // // Rearrange the simTracks for ease of use + // std::map simTracks; for (edm::SimTrackContainer::const_iterator simTrackIt(simTracksRaw->begin()); simTrackIt != simTracksRaw->end(); ++simTrackIt) { @@ -156,63 +201,126 @@ void RecHitTreeWA::analyze(const edm::Event& event, const edm::EventSetup& event simTrackInfo_.fillSimTrackInfo(*simTrackIt); } simTrackTree->Fill(); + // + // Prepare SimHitInfo - setup new event + // + simHitInfo_.setupEvent(tTopo,tkGeom,pixelSimLinks.product(),shInfoSimHitsRaw,*rechits.product(),&simTracks); + // + // loop over dets + // + for (auto detHitsIt=simHitInfo_.simHitsPerDet().begin(); detHitsIt!=simHitInfo_.simHitsPerDet().end(); ++detHitsIt ) { + DetId detId(detHitsIt->first); + unsigned int layer = (tTopo->side(detId) != 0) * 1000; // don't split up endcap sides + layer += tTopo->layer(detId); + //hitInfo->Hit_ModuleType.push_back((unsigned short)(tkGeom->getDetectorType(detId))); + TrackerGeometry::ModuleType mType = tkGeom->getDetectorType(detId); + // Restrict to Phase2 OT + if ( mType!=TrackerGeometry::ModuleType::Ph2PSP && + mType!=TrackerGeometry::ModuleType::Ph2PSS && + mType!=TrackerGeometry::ModuleType::Ph2SS ) continue; - simHitInfo_.setupEvent(tTopo,tkGeom,pixelSimLinks.product(),simHitsRaw,*rechits.product(),&simTracks); - for (unsigned int simhitidx = 0; simhitidx < 2; ++simhitidx) { // loop over both barrel and endcap hits - for (edm::PSimHitContainer::const_iterator simhitIt(simHitsRaw[simhitidx]->begin()); - simhitIt != simHitsRaw[simhitidx]->end(); ++simhitIt) { - // Get the detector unit's id - DetId detId(simhitIt->detUnitId()); - unsigned int layer = (tTopo->side(detId) != 0) * 1000; // don't split up endcap sides - layer += tTopo->layer(detId); - //hitInfo->Hit_ModuleType.push_back((unsigned short)(tkGeom->getDetectorType(detId))); - TrackerGeometry::ModuleType mType = tkGeom->getDetectorType(detId); - // Restrict to Phase2 OT - if ( mType!=TrackerGeometry::ModuleType::Ph2PSP && - mType!=TrackerGeometry::ModuleType::Ph2PSS && - mType!=TrackerGeometry::ModuleType::Ph2SS ) continue; - - // Get the geomdet - const GeomDetUnit* geomDetUnit(tkGeom->idToDetUnit(detId)); - if (!geomDetUnit) { - std::cout << "*** did not find geomDetUnit ***" << std::endl; - continue; - } - + // Get the geomdet + const GeomDetUnit* geomDetUnit(tkGeom->idToDetUnit(detId)); + if (!geomDetUnit) { + std::cout << "*** did not find geomDetUnit ***" << std::endl; + continue; + } + // std::cout << "Found " << detHitsIt->second.size() << " SimHits on DetId " << detHitsIt->first + // << std::endl << std::flush; + // + // loop over SimHits on Det + // + for (auto simhitIt=detHitsIt->second.begin(); simhitIt!=detHitsIt->second.end(); ++simhitIt) { // std::cout << "Filling sim hit info" << std::endl; - simHitInfo_.fillSimHitInfo(*simhitIt); - + simHitInfo_.fillSimHitInfo(**simhitIt); } + // std::cout << "... done" << std::endl << std::flush; } + // // for (unsigned int simhitidx = 0; simhitidx < 2; ++simhitidx) { // loop over both barrel and endcap hits + // // for (edm::PSimHitContainer::const_iterator simhitIt(shInfoSimHitsRaw[simhitidx]->begin()); + // // simhitIt != shInfoSimHitsRaw[simhitidx]->end(); ++simhitIt) { + // // loop over both barrel and endcap hits + // for (auto simhitsId=shInfoSimHitsRaw.begin(); simhitsId!=shInfoSimHitsRaw.end(); ++simhitsId ) { + // for (auto simhitIt=(**simhitsId).begin(); simhitIt!=(**simhitsId).end(); ++simhitIt) { + // // Get the detector unit's id + // DetId detId(simhitIt->detUnitId()); + // unsigned int layer = (tTopo->side(detId) != 0) * 1000; // don't split up endcap sides + // layer += tTopo->layer(detId); + // //hitInfo->Hit_ModuleType.push_back((unsigned short)(tkGeom->getDetectorType(detId))); + // TrackerGeometry::ModuleType mType = tkGeom->getDetectorType(detId); + // // Restrict to Phase2 OT + // if ( mType!=TrackerGeometry::ModuleType::Ph2PSP && + // mType!=TrackerGeometry::ModuleType::Ph2PSS && + // mType!=TrackerGeometry::ModuleType::Ph2SS ) continue; + + // // Get the geomdet + // const GeomDetUnit* geomDetUnit(tkGeom->idToDetUnit(detId)); + // if (!geomDetUnit) { + // std::cout << "*** did not find geomDetUnit ***" << std::endl; + // continue; + // } + + // // std::cout << "Filling sim hit info" << std::endl; + // simHitInfo_.fillSimHitInfo(*simhitIt); + + // } + // } simHitTree->Fill(); - + // + // Prepare RecHitInfo - setup new event + // + recHitInfo_.setupEvent(tTopo,tkGeom,pixelSimLinks.product(),rhInfoSimHitsRaw,*rechits.product(),&simTracks); for (Phase2TrackerRecHit1DCollectionNew::const_iterator DSViter = rechits->begin(); DSViter != rechits->end(); ++DSViter) { + // for (auto detHitsIt=recHitInfo_.recHitsPerDet().begin(); detHitsIt!=recHitInfo_.recHitsPerDet().end(); ++detHitsIt ) { + // DetId detId(detHitsIt->first); + // unsigned int rawid(detId.rawId()); + // unsigned int layer = (tTopo->side(detId) != 0) * 1000; // don't split up endcap sides + // layer += tTopo->layer(detId); + // TrackerGeometry::ModuleType mType = tkGeom->getDetectorType(detId); + // // Restrict to Phase2 OT + // if ( mType!=TrackerGeometry::ModuleType::Ph2PSP && + // mType!=TrackerGeometry::ModuleType::Ph2PSS && + // mType!=TrackerGeometry::ModuleType::Ph2SS ) continue; + // Get the detector unit's id unsigned int rawid(DSViter->detId()); DetId detId(rawid); unsigned int layer = (tTopo->side(detId) != 0) * 1000; // don't split up endcap sides layer += tTopo->layer(detId); + TrackerGeometry::ModuleType mType = tkGeom->getDetectorType(detId); + // Restrict to Phase2 OT + if ( mType!=TrackerGeometry::ModuleType::Ph2PSP && + mType!=TrackerGeometry::ModuleType::Ph2PSS && + mType!=TrackerGeometry::ModuleType::Ph2SS ) continue; // Get the geomdet const GeomDetUnit* geomDetUnit(tkGeom->idToDetUnit(detId)); if (!geomDetUnit) continue; - recHitInfo_.setTopology(tTopo); - recHitInfo_.setGeometry(tkGeom); + // recHitInfo_.setTopology(tTopo); + // recHitInfo_.setGeometry(tkGeom); + // std::cout << "Found " << DSViter->size() << " RecHits on DetId " << rawid << std::endl << std::flush; + // // Loop over the rechits in the detector unit + // for (edmNew::DetSet::const_iterator rechitIt = DSViter->begin(); - rechitIt != DSViter->end(); ++rechitIt) { - recHitInfo_.fillRecHitInfo(*rechitIt,rawid,geomDetUnit,&pixelSimLinks,simTracks,simHitsRaw,debugHitMatch_); + rechitIt != DSViter->end(); ++rechitIt) { + // // + // // loop over RecHits on Det + // // + // for (auto rechitIt=detHitsIt->second.begin(); rechitIt!=detHitsIt->second.end(); ++rechitIt) { + // std::cout << "Filling sim hit info" << std::endl; + recHitInfo_.fillRecHitInfo(*rechitIt,rawid,geomDetUnit, // &pixelSimLinks,simTracks, + rhInfoSimHitsRaw,debugHitMatch_); } } recHitTree->Fill(); } - void RecHitTreeWA::beginJob() { edm::Service fs; @@ -241,4 +349,3 @@ void RecHitTreeWA::initEventStructure() } DEFINE_FWK_MODULE(RecHitTreeWA); - diff --git a/HitAnalyzer/src/ClusterSimTracks.cc b/HitAnalyzer/src/ClusterSimTracks.cc new file mode 100644 index 0000000..16f7b8a --- /dev/null +++ b/HitAnalyzer/src/ClusterSimTracks.cc @@ -0,0 +1,48 @@ +#include "Phase2Tracking/HitAnalyzer/interface/ClusterSimTracks.h" +// #include "Phase2Tracking/HitAnalyzer/interface/CommonHitInfo.h" +// #include "DataFormats/DetId/interface/DetId.h" +// +// return SimTrack ids for a given DetId / channel +// +std::set ClusterSimTracks::simTrackIdsPerChannel(unsigned int channel) const { + std::set result; + edm::DetSetVector::const_iterator DSViter(pixelSimLinks_.find(detId_)); + if (DSViter == pixelSimLinks_.end()) return result; + for (edm::DetSet::const_iterator it = DSViter->data.begin(); it != DSViter->data.end(); ++it) { + if (channel == it->channel()) { + result.insert(it->SimTrackId()); + } + } + return result; +}; + +bool ClusterSimTracks::simTrackInCluster(unsigned int simTrackId) const { + // + // Return true if contributed to one or more channels of + // + // caching handled by simTrackIds() + // + const std::set& trackIds = simTrackIds(); + + return std::find(trackIds.begin(),trackIds.end(),simTrackId)!=trackIds.end(); +}; + +const std::set& ClusterSimTracks::simTrackIds() const { + // + // List of all SimTrackIds associated to this cluster + // + if ( simTracksValid_ ) return simTrackIds_; + // + // Loop over all channels + // + for ( unsigned int ic=0; ic trackIds(simTrackIdsPerChannel(channel)); + simTrackIds_.insert(trackIds.begin(),trackIds.end()); + } + + simTracksValid_ = true; + return simTrackIds_; +}; diff --git a/HitAnalyzer/src/CommonHitInfo.cc b/HitAnalyzer/src/CommonHitInfo.cc new file mode 100644 index 0000000..fa0540f --- /dev/null +++ b/HitAnalyzer/src/CommonHitInfo.cc @@ -0,0 +1,197 @@ +#include "Phase2Tracking/HitAnalyzer/interface/CommonHitInfo.h" +#include "DataFormats/DetId/interface/DetId.h" + +// #include + +// #include + + +std::vector CommonHitInfo::getSimTrackId(const DetId& detId, unsigned int channel) { + std::vector retvec; + edm::DetSetVector::const_iterator DSViter(pixelSimLinks->find(detId)); + if (DSViter == pixelSimLinks->end()) return retvec; + for (edm::DetSet::const_iterator it = DSViter->data.begin(); it != DSViter->data.end(); ++it) { + if (channel == it->channel()) { + retvec.push_back(it->SimTrackId()); + } + } + return retvec; +}; + +void CommonHitInfo::fillSimHitsPerDet(const std::vector& simHitsRaw) { + // + // fill map of SimHits / detId + // + simHitsPerDet_.clear(); + // for (unsigned int simhitidx = 0; simhitidx < 2; ++simhitidx) { // loop over both barrel and endcap hits + // // std::cout<< simhitidx << " " << simHitsRaw[simhitidx]->size() << std::endl; + // for (edm::PSimHitContainer::const_iterator simhitIt(simHitsRaw[simhitidx]->begin()); + // simhitIt != simHitsRaw[simhitidx]->end(); ++simhitIt) { + // loop over both barrel and endcap hits + for (auto simhitsIt=simHitsRaw.begin(); simhitsIt!=simHitsRaw.end(); ++simhitsIt) { + for (auto simhitIt=(**simhitsIt).begin(); simhitIt!=(**simhitsIt).end(); ++simhitIt) { + const PSimHit* simhit(&*simhitIt); + unsigned int rawid(simhit->detUnitId()); + DetSimHitsMap::iterator idet(simHitsPerDet_.find(rawid)); + if ( idet!=simHitsPerDet_.end() ) { + // std::cout << "CommonHitInfoadding sim entry for det id " << rawid << std::endl; + idet->second.push_back(simhit); + } + else { + // std::cout << "CommonHitInfonew sim entry for det id " << rawid << std::endl; + simHitsPerDet_.insert(DetSimHitsPair(rawid,std::vector{simhit})); + } + } + } + // for (auto it(simHitsPerDet_.begin()); it!=simHitsPerDet_.end(); ++it ) { + // std::cout << it->second.size() << " sim hits for det id "<< it->first << std::endl; + // } + // std::cout << std::endl; + +}; + +void CommonHitInfo::fillRecHitsPerDet(const Phase2TrackerRecHit1DCollectionNew& rechits) { + // + // create map of RecHits + // + recHitsPerDet_.clear(); + for (Phase2TrackerRecHit1DCollectionNew::const_iterator DSViter = rechits.begin(); + DSViter != rechits.end(); ++DSViter) { + // Get the detector unit's id + unsigned int rawid(DSViter->detId()); + // only consider dets with SimHits + if ( simHitsPerDet_.find(rawid)!=simHitsPerDet_.end() ) { + // Loop over the rechits in the detector unit + for (edmNew::DetSet::const_iterator rechitIt = DSViter->begin(); + rechitIt != DSViter->end(); ++rechitIt) { + const Phase2TrackerRecHit1D* rechit(&*rechitIt); + DetRecHitsMap::iterator idet(recHitsPerDet_.find(rawid)); + if ( idet!=recHitsPerDet_.end() ) { + // std::cout << "CommonHitInfoadding rec entry for det id " << rawid << std::endl; + idet->second.push_back(rechit); + } + else { + // std::cout << "CommonHitInfonew rec entry for det id " << rawid << std::endl; + recHitsPerDet_.insert(DetRecHitsPair(rawid,std::vector{rechit})); + } + } + + } + } + // for (auto it(recHitsPerDet_.begin()); it!=recHitsPerDet_.end(); ++it ) { + // std::cout << it->second.size() << " rec hits for det id "<< it->first << std::endl; + // } + // std::cout << std::endl; + +}; + +//const Phase2TrackerRecHit1D* CommonHitInfo::matchRecHitOnDet(const PSimHit* simHit, const DetId& detId, +// const std::vector& detRecHits) { +CommonHitInfo::RecHitDistancePairs +CommonHitInfo::matchRecHitOnDet(const PSimHit* simHit, const DetId& detId, + const std::vector& detRecHits) { + // + // loop over RecHits (assumes simHit and detRecHits are on the same DetUnit!!) + // + // std::cout << "CommonHitInfo Checking SimHit at " << simHit << " detid " << simHit->detUnitId() << " loc pos " + // << simHit->localPosition().x() << " / " << simHit->localPosition().y() << std::endl; + // const Phase2TrackerRecHit1D* rechit(0); + // std::vector< const Phase2TrackerRecHit1D* rechit(0); + // + // prepare result + // + CommonHitInfo::RecHitDistancePairs matchedRecHits; + // + // restart cache of ClusterSimTracks objects with new detid (only useful + // if SimHits on same Det are treated in sequence) + // + if ( cstByCluster_.size()>0 ) { + const ClusterSimTracks& cst = cstByCluster_.begin()->second; + // std::cout << " Existing *detId = " << &cst.detId() << " " << cst.detId().rawId() << + // " / new *detId = " << &detId << " " << detId.rawId() << std::endl; + if ( !cst.sameDet(detId) ) { + // std::cout << " Changed DetId" << std::endl; + cstByCluster_.clear(); + } + } + // else { + // std::cout << " cstByCluster is empty" << std::endl; + // } + + // float dxmin(1.e30); + for ( std::vector::const_iterator irh=detRecHits.begin(); + irh!=detRecHits.end(); ++irh ) { + // Get the cluster from the rechit and loop over channels + RecHitClusterMap::const_iterator icl(clustersByHit_.find(*irh)); + const Phase2TrackerCluster1D* clusterPtr(0); + if ( icl==clustersByHit_.end() ) { + clusterPtr = &(*(**irh).cluster()); + clustersByHit_.insert(std::pair(*irh,clusterPtr)); + } + else { + clusterPtr = icl->second; + } + const Phase2TrackerCluster1D& cluster = *(**irh).cluster(); + + const ClusterSimTracks* cst(0); + ClusterSimTracksMap::const_iterator cstit = cstByCluster_.find(&cluster); + // std::cout << " #entries of cstByCluster_ = " << cstByCluster_.size() << std::endl; + // for ( auto it=cstByCluster_.begin(); it!=cstByCluster_.end(); ++it ) + // std::cout << " cluster pointer = " << it->first << " cst pointer " << &(it->second) + // << " rawid " << (it->second).detId().rawId() << std::endl; + if ( cstit==cstByCluster_.end() ) { + // std::cout << " Adding CST for cluster at " << &cluster << " on det " << detId << std::endl; + cstit = + cstByCluster_.insert({&cluster,ClusterSimTracks(cluster,detId,*pixelSimLinks)}).first; + } + // else { + // std::cout << " Reusing CST for cluster at " << &cluster << " on det " << detId << std::endl; + // } + cst = &(cstit->second); + // ClusterSimTracks cSimTrackIds(cluster,detId,*pixelSimLinks); + bool matched = cst->simTrackInCluster(simHit->trackId()); + // // std::cout << "CommonHitInfo cluster size " << cluster.size() << std::endl; + // // std::cout << "CommonHitInfo Checking RecHit at " << *irh + // // << " 1st strip " << (**irh).cluster()->firstStrip() + // // << " 1st row " << (**irh).cluster()->firstRow() + // // << " columns "<< (**irh).cluster()->column() + // // << " detid " << (**irh).geographicalId() << std::endl; + // bool matched(false); + // for (unsigned int i(0); i < cluster.size(); ++i) { + // // std::cout << "CommonHitInfo channel " << i << std::endl; + // // const Phase2TrackerCluster1D& cluster = *(**irh).cluster(); + // // // std::cout << "CommonHitInfo cluster size " << cluster.size() << std::endl; + // // find SimTracks contributing to the channel + // unsigned int channel(Phase2TrackerDigi::pixelToChannel(cluster.firstRow() + i, cluster.column())); + // std::vector simTrackIds = getSimTrackId(detId,channel); + // // // std::cout << "CommonHitInfo " << simTrackIds.size() << " simTracks" << std::endl; + // matched = std::find(simTrackIds.begin(),simTrackIds.end(),(*simHit).trackId())!=simTrackIds.end(); + // // if match was found: consider RecHit + // // std::cout << "CommonHitInfo matched : " << matched << std::endl; + // if ( matched ) break; + // } + // + // select closest RecHit + // + if ( matched ) { + float dx = fabs((**irh).localPosition().x()-(*simHit).localPosition().x()); + matchedRecHits.push_back(RecHitDistancePair(&(**irh),dx)); + // // std::cout << "CommonHitInfo dx, dxmin " << dx << " " << dxmin; + // if ( !rechit || dx RecHitInfo::getSimTrackId( - edm::Handle >& pixelSimLinks, - const DetId& detId, unsigned int channel) { - std::vector retvec; - edm::DetSetVector::const_iterator DSViter(pixelSimLinks->find(detId)); - if (DSViter == pixelSimLinks->end()) - return retvec; - for (edm::DetSet::const_iterator it = DSViter->data.begin(); it != DSViter->data.end(); ++it) { - if (channel == it->channel()) { - retvec.push_back(it->SimTrackId()); - } - } - return retvec; -} +// std::vector RecHitInfo::getSimTrackId( +// edm::Handle >& pixelSimLinks, +// const DetId& detId, unsigned int channel) { +// std::vector retvec; +// edm::DetSetVector::const_iterator DSViter(pixelSimLinks->find(detId)); +// if (DSViter == pixelSimLinks->end()) +// return retvec; +// for (edm::DetSet::const_iterator it = DSViter->data.begin(); it != DSViter->data.end(); ++it) { +// if (channel == it->channel()) { +// retvec.push_back(it->SimTrackId()); +// } +// } +// return retvec; +// } void RecHitInfo::fillSimHitInfo(const PSimHit& simHit) { // // Get the detector unit's id // DetId detId(simHit.detUnitId()); - unsigned int layer = (tTopo->side(detId) != 0) * 1000; // don't split up endcap sides - layer += tTopo->layer(detId); - TrackerGeometry::ModuleType mType = tkGeom->getDetectorType(detId); + unsigned int layer = (tTopo_->side(detId) != 0) * 1000; // don't split up endcap sides + layer += tTopo_->layer(detId); + TrackerGeometry::ModuleType mType = tkGeom_->getDetectorType(detId); // Get the geomdet - const GeomDetUnit* geomDetUnit(tkGeom->idToDetUnit(detId)); + const GeomDetUnit* geomDetUnit(tkGeom_->idToDetUnit(detId)); if (!geomDetUnit) { std::cout << "*** did not find geomDetUnit ***" << std::endl; return; @@ -107,14 +109,14 @@ void RecHitInfo::fillSimHitInfo(const PSimHit& simHit) { void RecHitInfo::fillRecHitInfo(const Phase2TrackerRecHit1D& recHit, unsigned int rawid, const GeomDetUnit* geomDetUnit, - edm::Handle >* pixelSimLinks, - std::map& simTracks, - edm::Handle* simHitsRaw, + // edm::Handle >* pixelSimLinks, + // std::map& simTracks, + const std::vector& simHitsRaw, bool debugHitMatch) { // get DetUnit DetId detId(rawid); - unsigned int layer = (tTopo->side(detId) != 0) * 1000; // don't split up endcap sides - layer += tTopo->layer(detId); + unsigned int layer = (tTopo_->side(detId) != 0) * 1000; // don't split up endcap sides + layer += tTopo_->layer(detId); // determine the position LocalPoint localPosClu = recHit.localPosition(); Global3DPoint globalPosClu = geomDetUnit->surface().toGlobal(localPosClu); @@ -124,43 +126,56 @@ void RecHitInfo::fillRecHitInfo(const Phase2TrackerRecHit1D& recHit, unsigned in const Phase2TrackerCluster1D* clustIt = &*recHit.cluster(); // Get all the simTracks that form the cluster - std::vector clusterSimTrackIds; - for (unsigned int i(0); i < clustIt->size(); ++i) { - unsigned int channel(Phase2TrackerDigi::pixelToChannel(clustIt->firstRow() + i, clustIt->column())); - std::vector simTrackIds_unselected(getSimTrackId(*pixelSimLinks, detId, channel)); - std::vector simTrackIds; - for (auto istId : simTrackIds_unselected) { - std::map::const_iterator istfind(simTracks.find(istId)); - if (istfind != simTracks.end()) - simTrackIds.push_back(istId); - } - for (unsigned int i = 0; i < simTrackIds.size(); ++i) { - bool add = true; - for (unsigned int j = 0; j < clusterSimTrackIds.size(); ++j) { - // only save simtrackids that are not present yet - if (simTrackIds.at(i) == clusterSimTrackIds.at(j)) - add = false; - } - if (add) - clusterSimTrackIds.push_back(simTrackIds.at(i)); - } - } - + ClusterSimTracks cSimTrackIds(*clustIt,detId,*pixelSimLinks); + const std::set& clusterSimTrackIds = cSimTrackIds.simTrackIds(); + // for (unsigned int i(0); i < clustIt->size(); ++i) { + // unsigned int channel(Phase2TrackerDigi::pixelToChannel(clustIt->firstRow() + i, clustIt->column())); + // // std::vector simTrackIds_unselected(getSimTrackId(*pixelSimLinks, detId, channel)); + // std::vector simTrackIds_unselected(getSimTrackId(detId, channel)); + // std::vector simTrackIds; + // for (auto istId : simTrackIds_unselected) { + // std::map::const_iterator istfind(simTracksById_->find(istId)); + // if (istfind != simTracksById_->end()) + // simTrackIds.push_back(istId); + // } + // clusterSimTrackIds.insert(simTrackIds.begin(),simTrackIds.end()); + // } + // debug + // if ( clusterSimTrackIds.size()==0 ) { + // std::cout << "** RecHit without SimTrackIds on detId " << rawid << " layer " << layer + // << " module type " << (unsigned int)tkGeom_->getDetectorType(detId) << std::endl; + // for (unsigned int i(0); i < clustIt->size(); ++i) { + // unsigned int channel(Phase2TrackerDigi::pixelToChannel(clustIt->firstRow() + i, clustIt->column())); + // std::cout << " channel " << clustIt->firstRow()+i << " " << clustIt->column() << std::endl; + // std::vector simTrackIds_unselected(getSimTrackId(*pixelSimLinks, detId, channel)); + // std::cout << " simTrackIds"; + // for ( auto istid=simTrackIds_unselected.begin(); + // istid!=simTrackIds_unselected.end(); ++istid ) std::cout << " " << *istid; + // std::cout << std::endl; + // } + // } + // debug // find the closest simhit // this is needed because otherwise you get cases with simhits and clusters being swapped // when there are more than 1 cluster with common simtrackids const PSimHit* simhit = 0; // bad naming to avoid changing code below. This is the closest simhit in x float minx = 10000; std::vector trackSimHits; - for (unsigned int simhitidx = 0; simhitidx < 2; ++simhitidx) { // loop over both barrel and endcap hits - for (edm::PSimHitContainer::const_iterator simhitIt(simHitsRaw[simhitidx]->begin()); - simhitIt != simHitsRaw[simhitidx]->end(); - ++simhitIt) { + // for (unsigned int simhitidx = 0; simhitidx < 2; ++simhitidx) { // loop over both barrel and endcap hits + // for (edm::PSimHitContainer::const_iterator simhitIt(simHitsRaw[simhitidx]->begin()); + // simhitIt != simHitsRaw[simhitidx]->end(); + // ++simhitIt) { + + // std::cout << "#hits ="; + // std::cout << clusterSimTrackIds.size() << " trackIds for cluster" << std::endl; + for (auto simhitsIt=simHitsRaw.begin(); simhitsIt!=simHitsRaw.end(); ++simhitsIt) { + // std::cout << " " << (**simhitsIt).size(); + for (auto simhitIt=(**simhitsIt).begin(); simhitIt!=(**simhitsIt).end(); ++simhitIt) { // check SimHit detId is the same with the RecHit if (rawid == simhitIt->detUnitId()) { - auto it = std::lower_bound(clusterSimTrackIds.begin(), clusterSimTrackIds.end(), simhitIt->trackId()); - // check SimHit track id is included in the cluster - if (it != clusterSimTrackIds.end() && *it == simhitIt->trackId()) { + // auto it = std::lower_bound(clusterSimTrackIds.begin(), clusterSimTrackIds.end(), simhitIt->trackId()); + // // check SimHit track id is included in the cluster + if ( clusterSimTrackIds.find(simhitIt->trackId()) != clusterSimTrackIds.end() ) { trackSimHits.push_back(&*simhitIt); if (!simhit || fabs(simhitIt->localPosition().x() - localPosClu.x()) < minx) { minx = fabs(simhitIt->localPosition().x() - localPosClu.x()); @@ -170,9 +185,10 @@ void RecHitInfo::fillRecHitInfo(const Phase2TrackerRecHit1D& recHit, unsigned in } } } + // std::cout << " hasSimHit " << (simhit!=0) << std::endl; if ( debugHitMatch ) { if ( trackSimHits.size()==0 || trackSimHits.size()>1 ) { - TrackerGeometry::ModuleType mType = tkGeom->getDetectorType(detId); + TrackerGeometry::ModuleType mType = tkGeom_->getDetectorType(detId); std::cout << "RecHit on rawid " << rawid <<", layer " << layer << ", mType "<< (unsigned int)mType << std::endl; std::cout << " localPos " << localPosClu.x() << " / " << localPosClu.y() << std::endl; @@ -195,17 +211,23 @@ void RecHitInfo::fillRecHitInfo(const Phase2TrackerRecHit1D& recHit, unsigned in << ", entry-exit (y) " << (**itsh).entryPoint().y() << " / " << (**itsh).exitPoint().y() << std::endl; } if ( trackSimHits.size()==0 ) { + std::cout << "--- clusterSimTrackIds " << clusterSimTrackIds.size() + << " clusterSize " << recHit.cluster()->size() << std::endl; for (unsigned int simhitidx = 0; simhitidx < 2; ++simhitidx) { // loop over both barrel and endcap hits for (edm::PSimHitContainer::const_iterator simhitIt(simHitsRaw[simhitidx]->begin()); simhitIt != simHitsRaw[simhitidx]->end(); ++simhitIt) { // check SimHit detId is the same with the RecHit if (rawid == simhitIt->detUnitId()) { + float shxMin = std::min(simhitIt->entryPoint().x(),simhitIt->exitPoint().x()); + float shxMax = std::max(simhitIt->entryPoint().x(),simhitIt->exitPoint().x()); + if ( ( localPosClu.x()>=shxMin ) && ( localPosClu.x()<=shxMax ) ) { std::cout << " SimHit: pabs = " << simhitIt->pabs() << " loss " << simhitIt->energyLoss() << ", pdgId " << simhitIt->particleType() << ", entry-exit (x) " << simhitIt->entryPoint().x() << " / " << simhitIt->exitPoint().x() << ", " << ", entry-exit (y) " << simhitIt->entryPoint().y() << " / " << simhitIt->exitPoint().y() << std::endl; + } } } } @@ -217,7 +239,7 @@ void RecHitInfo::fillRecHitInfo(const Phase2TrackerRecHit1D& recHit, unsigned in recHitData.Hit_cluster_global_y.push_back(globalPosClu.y()); recHitData.Hit_cluster_global_z.push_back(globalPosClu.z()); recHitData.Hit_layer.push_back(layer); - recHitData.Hit_ModuleType.push_back((unsigned short)(tkGeom->getDetectorType(detId))); + recHitData.Hit_ModuleType.push_back((unsigned short)(tkGeom_->getDetectorType(detId))); recHitData.Hit_cluster_size.push_back(clustIt->size()); recHitData.Hit_cluster_SimTrack_size.push_back(clusterSimTrackIds.size()); recHitData.Hit_cluster_local_x.push_back(localPosClu.x()); @@ -255,13 +277,14 @@ void RecHitInfo::fillRecHitInfo(const Phase2TrackerRecHit1D& recHit, unsigned in recHitData.Hit_cluster_closestSimHit_local_z.push_back(simhit->localPosition().z()); fillSimHitInfo(*simhit); } + recHitData.nSimTracks.push_back(clusterSimTrackIds.size()); recHitData.Hit_det_rawid.push_back(rawid); recHitData.Hit_cluster_firstStrip.push_back(clustIt->firstStrip()); recHitData.Hit_cluster_firstRow.push_back(clustIt->firstRow()); recHitData.Hit_cluster_column.push_back(clustIt->column()); recHitData.Hit_cluster_edge.push_back(clustIt->edge()); recHitData.Hit_cluster_threshold.push_back(clustIt->threshold()); - + }; void RecHitInfo::clear() { @@ -301,4 +324,5 @@ void RecHitInfo::clear() { recHitData.moduleType.clear(); recHitData.detNormal.clear(); recHitData.trackId.clear(); + recHitData.nSimTracks.clear(); }; diff --git a/HitAnalyzer/src/SimHitInfo.cc b/HitAnalyzer/src/SimHitInfo.cc index 99dfa18..a89040e 100644 --- a/HitAnalyzer/src/SimHitInfo.cc +++ b/HitAnalyzer/src/SimHitInfo.cc @@ -1,4 +1,5 @@ #include "Phase2Tracking/HitAnalyzer/interface/SimHitInfo.h" +#include "Phase2Tracking/HitAnalyzer/interface/CommonHitInfo.h" #include "DataFormats/DetId/interface/DetId.h" // #include @@ -41,157 +42,155 @@ void SimHitInfo::setBranches(TTree& tree) { tree.Branch("clusterThreshold", &simHitData.clusterThreshold); }; -std::vector SimHitInfo::getSimTrackId(const DetId& detId, unsigned int channel) { - std::vector retvec; - edm::DetSetVector::const_iterator DSViter(pixelSimLinks->find(detId)); - if (DSViter == pixelSimLinks->end()) return retvec; - for (edm::DetSet::const_iterator it = DSViter->data.begin(); it != DSViter->data.end(); ++it) { - if (channel == it->channel()) { - retvec.push_back(it->SimTrackId()); - } - } - return retvec; -}; +// std::vector SimHitInfo::getSimTrackId(const DetId& detId, unsigned int channel) { +// std::vector retvec; +// edm::DetSetVector::const_iterator DSViter(pixelSimLinks->find(detId)); +// if (DSViter == pixelSimLinks->end()) return retvec; +// for (edm::DetSet::const_iterator it = DSViter->data.begin(); it != DSViter->data.end(); ++it) { +// if (channel == it->channel()) { +// retvec.push_back(it->SimTrackId()); +// } +// } +// return retvec; +// }; -void SimHitInfo::fillSimHitsPerDet(edm::Handle *simHitsRaw) { - // - // fill map of SimHits / detId - // - simHitsPerDet_.clear(); - for (unsigned int simhitidx = 0; simhitidx < 2; ++simhitidx) { // loop over both barrel and endcap hits - // std::cout << simhitidx << " " << simHitsRaw[simhitidx]->size() << std::endl; - for (edm::PSimHitContainer::const_iterator simhitIt(simHitsRaw[simhitidx]->begin()); - simhitIt != simHitsRaw[simhitidx]->end(); ++simhitIt) { - const PSimHit* simhit(&*simhitIt); - unsigned int rawid(simhit->detUnitId()); - DetSimHitsMap::iterator idet(simHitsPerDet_.find(rawid)); - if ( idet!=simHitsPerDet_.end() ) { - // std::cout << "SimHitInfoadding sim entry for det id " << rawid << std::endl; - idet->second.push_back(simhit); - } - else { - // std::cout << "SimHitInfonew sim entry for det id " << rawid << std::endl; - simHitsPerDet_.insert(DetSimHitsPair(rawid,std::vector{simhit})); - } - } - } - // for (auto it(simHitsPerDet_.begin()); it!=simHitsPerDet_.end(); ++it ) { - // std::cout << it->second.size() << " sim hits for det id "<< it->first << std::endl; - // } - // std::cout << std::endl; +// void SimHitInfo::fillSimHitsPerDet(const std::vector& simHitsRaw) { +// // +// // fill map of SimHits / detId +// // +// commonHitInfo.fillSimHitsPerDet(simHitsRaw); +// // simHitsPerDet_.clear(); +// // // for (unsigned int simhitidx = 0; simhitidx < 2; ++simhitidx) { // loop over both barrel and endcap hits +// // // // std::cout << simhitidx << " " << simHitsRaw[simhitidx]->size() << std::endl; +// // // for (edm::PSimHitContainer::const_iterator simhitIt(simHitsRaw[simhitidx]->begin()); +// // // simhitIt != simHitsRaw[simhitidx]->end(); ++simhitIt) { +// // // loop over both barrel and endcap hits +// // for (auto simhitsIt=simHitsRaw.begin(); simhitsIt!=simHitsRaw.end(); ++simhitsIt) { +// // for (auto simhitIt=(**simhitsIt).begin(); simhitIt!=(**simhitsIt).end(); ++simhitIt) { +// // const PSimHit* simhit(&*simhitIt); +// // unsigned int rawid(simhit->detUnitId()); +// // DetSimHitsMap::iterator idet(simHitsPerDet_.find(rawid)); +// // if ( idet!=simHitsPerDet_.end() ) { +// // // std::cout << "SimHitInfoadding sim entry for det id " << rawid << std::endl; +// // idet->second.push_back(simhit); +// // } +// // else { +// // // std::cout << "SimHitInfonew sim entry for det id " << rawid << std::endl; +// // simHitsPerDet_.insert(DetSimHitsPair(rawid,std::vector{simhit})); +// // } +// // } +// // } +// // // for (auto it(simHitsPerDet_.begin()); it!=simHitsPerDet_.end(); ++it ) { +// // // std::cout << it->second.size() << " sim hits for det id "<< it->first << std::endl; +// // // } +// // // std::cout << std::endl; -}; +// }; -void SimHitInfo::fillRecHitsPerDet(const Phase2TrackerRecHit1DCollectionNew& rechits) { - // - // create map of RecHits - // - recHitsPerDet_.clear(); - for (Phase2TrackerRecHit1DCollectionNew::const_iterator DSViter = rechits.begin(); - DSViter != rechits.end(); ++DSViter) { - // Get the detector unit's id - unsigned int rawid(DSViter->detId()); - // only consider dets with SimHits - if ( simHitsPerDet_.find(rawid)!=simHitsPerDet_.end() ) { - // Loop over the rechits in the detector unit - for (edmNew::DetSet::const_iterator rechitIt = DSViter->begin(); - rechitIt != DSViter->end(); ++rechitIt) { - const Phase2TrackerRecHit1D* rechit(&*rechitIt); - DetRecHitsMap::iterator idet(recHitsPerDet_.find(rawid)); - if ( idet!=recHitsPerDet_.end() ) { - // std::cout << "SimHitInfoadding rec entry for det id " << rawid << std::endl; - idet->second.push_back(rechit); - } - else { - // std::cout << "SimHitInfonew rec entry for det id " << rawid << std::endl; - recHitsPerDet_.insert(DetRecHitsPair(rawid,std::vector{rechit})); - } - } +// void SimHitInfo::fillRecHitsPerDet(const Phase2TrackerRecHit1DCollectionNew& rechits) { +// // +// // create map of RecHits +// // +// commonHitInfo.fillRecHitsPerDet(rechits); +// // recHitsPerDet_.clear(); +// // for (Phase2TrackerRecHit1DCollectionNew::const_iterator DSViter = rechits.begin(); +// // DSViter != rechits.end(); ++DSViter) { +// // // Get the detector unit's id +// // unsigned int rawid(DSViter->detId()); +// // // only consider dets with SimHits +// // if ( simHitsPerDet_.find(rawid)!=simHitsPerDet_.end() ) { +// // // Loop over the rechits in the detector unit +// // for (edmNew::DetSet::const_iterator rechitIt = DSViter->begin(); +// // rechitIt != DSViter->end(); ++rechitIt) { +// // const Phase2TrackerRecHit1D* rechit(&*rechitIt); +// // DetRecHitsMap::iterator idet(recHitsPerDet_.find(rawid)); +// // if ( idet!=recHitsPerDet_.end() ) { +// // // std::cout << "SimHitInfoadding rec entry for det id " << rawid << std::endl; +// // idet->second.push_back(rechit); +// // } +// // else { +// // // std::cout << "SimHitInfonew rec entry for det id " << rawid << std::endl; +// // recHitsPerDet_.insert(DetRecHitsPair(rawid,std::vector{rechit})); +// // } +// // } - } - } - // for (auto it(recHitsPerDet_.begin()); it!=recHitsPerDet_.end(); ++it ) { - // std::cout << it->second.size() << " rec hits for det id "<< it->first << std::endl; - // } - // std::cout << std::endl; +// // } +// } +// // for (auto it(recHitsPerDet_.begin()); it!=recHitsPerDet_.end(); ++it ) { +// // std::cout << it->second.size() << " rec hits for det id "<< it->first << std::endl; +// // } +// // std::cout << std::endl; -}; +// }; //const Phase2TrackerRecHit1D* SimHitInfo::matchRecHitOnDet(const PSimHit* simHit, const DetId& detId, // const std::vector& detRecHits) { -SimHitInfo::RecHitDistancePairs -SimHitInfo::matchRecHitOnDet(const PSimHit* simHit, const DetId& detId, - const std::vector& detRecHits) { - // - // loop over RecHits (assumes simHit and detRecHits are on the same DetUnit!!) - // - // std::cout << "SimHitInfo Checking SimHit at " << simHit << " detid " << simHit->detUnitId() << " loc pos " - // << simHit->localPosition().x() << " / " << simHit->localPosition().y() << std::endl; - // const Phase2TrackerRecHit1D* rechit(0); - // std::vector< const Phase2TrackerRecHit1D* rechit(0); - SimHitInfo::RecHitDistancePairs matchedRecHits; +// SimHitInfo::RecHitDistancePairs +// SimHitInfo::matchRecHitOnDet(const PSimHit* simHit, const DetId& detId, +// const std::vector& detRecHits) { +// // +// // loop over RecHits (assumes simHit and detRecHits are on the same DetUnit!!) +// // +// // std::cout << "SimHitInfo Checking SimHit at " << simHit << " detid " << simHit->detUnitId() << " loc pos " +// // << simHit->localPosition().x() << " / " << simHit->localPosition().y() << std::endl; +// // const Phase2TrackerRecHit1D* rechit(0); +// // std::vector< const Phase2TrackerRecHit1D* rechit(0); +// SimHitInfo::RecHitDistancePairs matchedRecHits; - // float dxmin(1.e30); - for ( std::vector::const_iterator irh=detRecHits.begin(); - irh!=detRecHits.end(); ++irh ) { - // std::cout << "SimHitInfo Checking RecHit at " << *irh - // << " 1st strip " << (**irh).cluster()->firstStrip() - // << " 1st row " << (**irh).cluster()->firstRow() - // << " columns "<< (**irh).cluster()->column() - // << " detid " << (**irh).geographicalId() << std::endl; - bool matched(false); - // Get the cluster from the rechit and loop over channels - const Phase2TrackerCluster1D& cluster = *(**irh).cluster(); - // std::cout << "SimHitInfo cluster size " << cluster.size() << std::endl; - for (unsigned int i(0); i < cluster.size(); ++i) { - // std::cout << "SimHitInfo channel " << i << std::endl; - // find SimTracks contributing to the channel - unsigned int channel(Phase2TrackerDigi::pixelToChannel(cluster.firstRow() + i, cluster.column())); - std::vector simTrackIds = getSimTrackId(detId,channel); - // std::cout << "SimHitInfo " << simTrackIds.size() << " simTracks" << std::endl; - for ( std::vector::const_iterator ist=simTrackIds.begin(); ist!=simTrackIds.end(); ++ist ) { - // std::cout << "SimHitInfo track id " << *ist << " (simhit track id " << (*simHit).trackId() << " ) " - // << std::endl; - // compare to track id of the SimHit - if ( (*ist)==(*simHit).trackId() ) { - matched = true; - break; - } - } - // if match was found: consider RecHit - // std::cout << "SimHitInfo matched : " << matched << std::endl; - if ( matched ) break; - } - // - // select closest RecHit - // - if ( matched ) { - float dx = fabs((**irh).localPosition().x()-(*simHit).localPosition().x()); - matchedRecHits.push_back(RecHitDistancePair(&(**irh),dx)); - // // std::cout << "SimHitInfo dx, dxmin " << dx << " " << dxmin; - // if ( !rechit || dx::const_iterator irh=detRecHits.begin(); +// irh!=detRecHits.end(); ++irh ) { +// // std::cout << "SimHitInfo Checking RecHit at " << *irh +// // << " 1st strip " << (**irh).cluster()->firstStrip() +// // << " 1st row " << (**irh).cluster()->firstRow() +// // << " columns "<< (**irh).cluster()->column() +// // << " detid " << (**irh).geographicalId() << std::endl; +// bool matched(false); +// // Get the cluster from the rechit and loop over channels +// const Phase2TrackerCluster1D& cluster = *(**irh).cluster(); +// // std::cout << "SimHitInfo cluster size " << cluster.size() << std::endl; +// for (unsigned int i(0); i < cluster.size(); ++i) { +// // std::cout << "SimHitInfo channel " << i << std::endl; +// // find SimTracks contributing to the channel +// unsigned int channel(Phase2TrackerDigi::pixelToChannel(cluster.firstRow() + i, cluster.column())); +// std::vector simTrackIds = getSimTrackId(detId,channel); +// // // std::cout << "SimHitInfo " << simTrackIds.size() << " simTracks" << std::endl; +// matched = std::find(simTrackIds.begin(),simTrackIds.end(),(*simHit).trackId())!=simTrackIds.end(); +// // if match was found: consider RecHit +// // std::cout << "SimHitInfo matched : " << matched << std::endl; +// if ( matched ) break; +// } +// // +// // select closest RecHit +// // +// if ( matched ) { +// float dx = fabs((**irh).localPosition().x()-(*simHit).localPosition().x()); +// matchedRecHits.push_back(RecHitDistancePair(&(**irh),dx)); +// // // std::cout << "SimHitInfo dx, dxmin " << dx << " " << dxmin; +// // if ( !rechit || dxside(detId) != 0) * 1000; // don't split up endcap sides layer += tTopo_->layer(detId); @@ -247,17 +246,35 @@ void SimHitInfo::fillSimHitInfo(const PSimHit& simHit) { const Phase2TrackerRecHit1D* rechit(0); - DetRecHitsMap::const_iterator ivrh = recHitsPerDet_.find(rawid); + DetRecHitsMap::const_iterator ivrh = recHitsPerDet().find(rawid); // if ( ivrh==recHitsPerDet_.end() ) { // std::cout << "SimHitInfo- Skipping det - no RecHits" << std::endl; // } // else { unsigned int nMatched(0); - if ( ivrh!=recHitsPerDet_.end() ) { + if ( ivrh!=recHitsPerDet().end() ) { // // find all rechits with contributions from the SimTrack related to simHit // RecHitDistancePairs matchedRecHits = matchRecHitOnDet(&simHit,detId,ivrh->second); + // //// + // if ( matchedRecHits.size()>50 ) { + // std::cout << "SimHit with " << matchedRecHits.size() << " matched hits" << std::endl; + // std::cout << " " << "at " << &simHit << " detid " << simHit.detUnitId() << " loc pos " + // << simHit.localPosition().x() << " / " << simHit.localPosition().y() << std::endl; + // std::cout << " " << "entry " << simHit.entryPoint().x() << " / " << simHit.entryPoint().y() + // << " ; exit " << simHit.exitPoint().x() << " / " << simHit.exitPoint().y() << std::endl; + // std::cout << " " << "trackId " << simHit.trackId() << " ; pType " << simHit.particleType() + // << " ; pabs " << simHit.pabs() << std::endl; + // for ( SimHitInfo::RecHitDistancePairs::const_iterator irrr=matchedRecHits.begin(); + // irrr!=matchedRecHits.end(); ++irrr ) { + // std::cout << " RecHit on detid " << irrr->first->geographicalId() << " loc pos " + // << irrr->first->localPosition().x() << " / " << irrr->first->localPosition().y() << std::endl; + // const Phase2TrackerCluster1D& cluster = *(irrr->first->cluster()); + // std::cout << " first row / column " << cluster.firstRow() << " / " << cluster.column() << std::endl; + // } + // } + // //// // store best match (if any) nMatched = matchedRecHits.size(); if ( nMatched>0 ) rechit = matchedRecHits[0].first; diff --git a/HitAnalyzer/test/floatMod.C b/HitAnalyzer/test/floatMod.C deleted file mode 100644 index 1950020..0000000 --- a/HitAnalyzer/test/floatMod.C +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -float floatMod(float a, float b) { - // - // change fmod behaviour for negative numbers - // (fmod will return -fmod(|a|,b) for a<0) - // - float result = std::fmod(a,b); - if ( result < 0. ) result += b; - return result; -} diff --git a/HitAnalyzer/test/rechittreewa_mu10_cfg.py b/HitAnalyzer/test/rechittreewa_mu10_cfg.py index 994ce7c..88e7cdb 100644 --- a/HitAnalyzer/test/rechittreewa_mu10_cfg.py +++ b/HitAnalyzer/test/rechittreewa_mu10_cfg.py @@ -18,18 +18,27 @@ # Number of events (-1 = all) process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) - #input = cms.untracked.int32(100) + #input = cms.untracked.int32(10) ) - +# Dataset: /RelValSingleMuPt10/CMSSW_15_1_0-150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/GEN-SIM-RECO # Input file process.source = cms.Source('PoolSource', - #fileNames = cms.untracked.vstring('file:/afs/cern.ch/work/l/lian/public/Phase2Tracker/CMSSW_15_0_0_pre3/src/29617.0_SingleMuPt1Extended+Run4D110/step3.root') - fileNames = cms.untracked.vstring('file:/eos/user/a/adamwo/CMS/Phase2DPG/Data/0b0d313e-56e1-4e64-aa58-8a2e61767bf5.root') + fileNames = cms.untracked.vstring( \ + '/store/relval/CMSSW_15_1_0/RelValSingleMuPt10/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/0166e3ce-e26d-483c-8226-cac472af699c.root', \ + '/store/relval/CMSSW_15_1_0/RelValSingleMuPt10/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/0562962b-66c8-488b-89d5-6df21d71f0b6.root', \ + '/store/relval/CMSSW_15_1_0/RelValSingleMuPt10/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/319ecc54-5d83-4e72-8d4a-3f73563e6d37.root', \ + '/store/relval/CMSSW_15_1_0/RelValSingleMuPt10/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/34e25999-54a2-4134-8703-241898703fed.root', \ + '/store/relval/CMSSW_15_1_0/RelValSingleMuPt10/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/37360339-d4dc-4270-85d1-8b89448a6504.root', \ + '/store/relval/CMSSW_15_1_0/RelValSingleMuPt10/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/49967669-571d-4a2b-aca2-6a148ebdb729.root', \ + '/store/relval/CMSSW_15_1_0/RelValSingleMuPt10/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/a88d679b-a909-47a4-8006-2455d1db2d5c.root', \ + '/store/relval/CMSSW_15_1_0/RelValSingleMuPt10/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/ae60ec5b-9009-4a17-8bcb-760c22430149.root', \ + '/store/relval/CMSSW_15_1_0/RelValSingleMuPt10/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/f931e711-1c11-47ce-9de3-49bd3966438d.root' + ) ) # Output process.TFileService = cms.Service('TFileService', - fileName = cms.string('file:rechits_tree.root') + fileName = cms.string('file:rechits_tree_mu10.root') ) process.load('RecoLocalTracker.SiPhase2Clusterizer.phase2TrackerClusterizer_cfi') @@ -53,7 +62,21 @@ #MakeEtaPlots = cms.bool(False), #MinEta = cms.double(0.), #MaxEta = cms.double(10.) - debugHitMatch = cms.bool(False) + debugHitMatch = cms.bool(False), + simHitInfo = cms.PSet( + simHits = cms.VInputTag( + cms.InputTag("g4SimHits", "TrackerHitsPixelBarrelLowTof"), + cms.InputTag("g4SimHits", "TrackerHitsPixelEndcapLowTof") + ) + ), + recHitInfo = cms.PSet( + simHits = cms.VInputTag( + cms.InputTag("g4SimHits", "TrackerHitsPixelBarrelLowTof"), + #cms.InputTag("g4SimHits", "TrackerHitsPixelBarrelHighTof"), + cms.InputTag("g4SimHits", "TrackerHitsPixelEndcapLowTof") #, + #cms.InputTag("g4SimHits", "TrackerHitsPixelEndcapHighTof") + ) + ) ) # Processes to run diff --git a/HitAnalyzer/test/rechittreewa_tt_cfg.py b/HitAnalyzer/test/rechittreewa_tt_cfg.py index 245fcfb..c863fd3 100644 --- a/HitAnalyzer/test/rechittreewa_tt_cfg.py +++ b/HitAnalyzer/test/rechittreewa_tt_cfg.py @@ -17,41 +17,25 @@ # Number of events (-1 = all) process.maxEvents = cms.untracked.PSet( - input = cms.untracked.int32(-1) - #input = cms.untracked.int32(100) + #input = cms.untracked.int32(-1) + input = cms.untracked.int32(3) ) # Input file -# dataset: /RelValTTbar_14TeV/CMSSW_15_0_0-141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/GEN-SIM-RECO +# dataset: /RelValTTbar_14TeV/CMSSW_15_1_0-150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/GEN-SIM-RECO process.source = cms.Source('PoolSource', - - #fileNames = cms.untracked.vstring('file:/afs/cern.ch/work/l/lian/public/Phase2Tracker/CMSSW_15_0_0_pre3/src/29617.0_SingleMuPt1Extended+Run4D110/step3.root') - #fileNames = cms.untracked.vstring('file:/eos/user/a/adamwo/CMS/Phase2DPG/Data/0b0d313e-56e1-4e64-aa58-8a2e61767bf5.root') fileNames = cms.untracked.vstring( - '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/061404ed-7c65-4f6e-88e9-b45a468f1cbe.root', \ - '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/162e0007-7588-46d8-9c93-a2b4b243885e.root') - #fileNames = cms.untracked.vstring( - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/061404ed-7c65-4f6e-88e9-b45a468f1cbe.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/162e0007-7588-46d8-9c93-a2b4b243885e.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/1bb480aa-0bad-439e-a6a4-a75780d0be9c.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/3db44076-4bb3-415b-b3a9-feb742460636.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/41d76683-9927-42e5-8c22-dfa056c56294.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/4bfe3713-82f0-43ac-8bd6-b16afd9d93e5.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/4c1b3277-7e2b-48c1-83b2-36ca12ea1a81.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/739566a2-723b-4c45-a40b-9d7a0f9e5434.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/75a2a485-cea5-4b7c-ab46-f08964fd9ac0.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/8490e1fb-3678-42b9-8010-d82ee3ec2a88.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/99ee730a-ec1c-4c3e-a345-71c82d1f2f41.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/a448fde4-b759-45ad-8c7e-45e1ec9d5f6e.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/b3c656c1-6e89-4491-b70d-2003eeb7fa72.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/c0f20d8b-f32b-40b5-bc5f-86fe17e90525.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/d7b6f571-25f9-44c4-812b-d040281b9d6a.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/db97a912-0690-46a1-80e7-ea6759b771ef.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/f542885d-c2a0-4a1f-9189-30a3995bcd61.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/fb22dfc2-87a5-40d5-b8c3-feb1e6df4047.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/fb6db36e-f813-4f25-92ea-afd7ed1ac961.root', \ - # '/store/relval/CMSSW_15_0_0/RelValTTbar_14TeV/GEN-SIM-RECO/141X_mcRun4_realistic_v3_STD_RegeneratedGS_Run4D110_noPU-v2/2580000/fc0a3df9-3f08-4355-9a91-12c1b3bd74ef.root' - #) + '/store/relval/CMSSW_15_1_0/RelValTTbar_14TeV/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/002a6949-6471-46fd-8c44-1f09e7717c8f.root', \ + '/store/relval/CMSSW_15_1_0/RelValTTbar_14TeV/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/0e60c3b1-0c21-41d2-94de-435382ae2b44.root', \ + '/store/relval/CMSSW_15_1_0/RelValTTbar_14TeV/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/3342a947-891b-41b1-9ed1-dc0a79e52e2c.root', \ + '/store/relval/CMSSW_15_1_0/RelValTTbar_14TeV/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/43fa9e06-8d30-423d-a656-7a136aa58dc6.root', \ + '/store/relval/CMSSW_15_1_0/RelValTTbar_14TeV/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/93b9335c-5bb3-46a9-9851-3a982b4df225.root', \ + '/store/relval/CMSSW_15_1_0/RelValTTbar_14TeV/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/9f157d02-3a77-4ed3-a64b-013ab978ad3d.root', \ + '/store/relval/CMSSW_15_1_0/RelValTTbar_14TeV/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/a9b19378-c427-4f38-8cc9-0a6c7212bbd7.root', \ + '/store/relval/CMSSW_15_1_0/RelValTTbar_14TeV/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/ab55d910-204b-451d-862d-2a2c35af456a.root', \ + '/store/relval/CMSSW_15_1_0/RelValTTbar_14TeV/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/ddebeaf9-afd7-478f-8803-cc1c66bbc7d1.root', \ + '/store/relval/CMSSW_15_1_0/RelValTTbar_14TeV/GEN-SIM-RECO/150X_mcRun4_realistic_v1_STD_RegeneratedGS_Run4D110_noPU-v1/2590000/f00daee7-b0bd-47ab-96fe-dfc16c78f923.root' + ) ) # Output @@ -80,7 +64,22 @@ #MakeEtaPlots = cms.bool(False), #MinEta = cms.double(0.), #MaxEta = cms.double(10.) - debugHitMatch = cms.bool(False) + debugHitMatch = cms.bool(False), + simHitInfo = cms.PSet( + simHits = cms.VInputTag( + cms.InputTag("g4SimHits", "TrackerHitsPixelBarrelLowTof"), + cms.InputTag("g4SimHits", "TrackerHitsPixelEndcapLowTof") + ) + ), + recHitInfo = cms.PSet( + simHits = cms.VInputTag( + cms.InputTag("g4SimHits", "TrackerHitsPixelBarrelLowTof"), + #cms.InputTag("g4SimHits", "TrackerHitsPixelBarrelHighTof"), + cms.InputTag("g4SimHits", "TrackerHitsPixelEndcapLowTof") #, + #cms.InputTag("g4SimHits", "TrackerHitsPixelEndcapHighTof") + ) + ) + ) # Processes to run @@ -91,3 +90,4 @@ process.schedule = cms.Schedule(process.rechits_step, process.analyze_step) + diff --git a/Plotter/autoplotter.py b/Plotter/autoplotter.py index 31d33af..d4cb4c9 100644 --- a/Plotter/autoplotter.py +++ b/Plotter/autoplotter.py @@ -2,7 +2,7 @@ import math import uuid import shutil -import Phase2Tracking.Plotter.plotter as p +import Phase2Tracking.Plotter.python.plotter as p import argparse @@ -45,6 +45,8 @@ def getFileList(inputdir): help='The number of jobs to submit for each sample. Could be a list of a single value.') parser.add_argument('--nfiles', type=int, default=-1, help='The number of files per job to submit for each sample. Could be a list of a single value.') +parser.add_argument('--loadMacro', type=str, nargs='*', default=[ ], \ + help='File name for C++ macro(s) to be loaded (can be repeated)') args = parser.parse_args() @@ -137,6 +139,6 @@ def getFileList(inputdir): else: if not os.path.exists(args.filelist): raise Exception("file list not given for plotting") - plotter = p.Plotter(name=args.name,treeName=str(args.treeName),outputDir=args.output,input_filelist=args.filelist,config=args.config,isData=args.data,postfix=args.postfix) + plotter = p.Plotter(name=args.name,treeName=str(args.treeName),outputDir=args.output,input_filelist=args.filelist,config=args.config,isData=args.data,postfix=args.postfix,macros=args.loadMacro) plotter.makeHistFiles() diff --git a/Plotter/filelist.txt b/Plotter/filelist.txt index 6d254cb..d487306 100644 --- a/Plotter/filelist.txt +++ b/Plotter/filelist.txt @@ -1 +1 @@ -root://eos.grid.vbc.ac.at//eos/vbc/experiments/cms/store/user/lian/RelValSingleMuPt10/SingleMuPt10_noPU_2_lian/250916_143902/0000/rechits_tree_1.root \ No newline at end of file +../HitAnalyzer/test/rechits_tree_tt_3.root diff --git a/Plotter/python/plotter.py b/Plotter/python/plotter.py index c299674..8e66213 100644 --- a/Plotter/python/plotter.py +++ b/Plotter/python/plotter.py @@ -11,7 +11,8 @@ ROOT.gStyle.SetOptStat(0) class Plotter: - def __init__(self,name,treeName,outputDir="./",input_filelist=None,config="",isData=False,postfix=""): + def __init__(self,name,treeName,outputDir="./",input_filelist=None,config="",isData=False,postfix="", \ + macros=[]): self.name = name self.treeName = treeName self.outputDir = outputDir @@ -21,6 +22,8 @@ def __init__(self,name,treeName,outputDir="./",input_filelist=None,config="",isD with open(config, "r") as f_cfg: cfg = yaml.load(f_cfg, Loader=yaml.FullLoader) self.cfg = cfg + for m in macros: + ROOT.gROOT.ProcessLine(".L "+m+"+") def getFileList(self): self.filelist = [] @@ -35,11 +38,13 @@ def getFileList(self): print("No files provided as input!") def AddVars(self,d): + print(type(self.cfg)) vars_to_define = ['new_variables'] for v in vars_to_define: if (not v in self.cfg) or (self.cfg[v] is None): continue if self.cfg[v] is not None: + print(v,type(self.cfg[v])) for newvar in self.cfg[v]: if isinstance(self.cfg[v][newvar],list): formatstr = [self.cfg[self.cfg[v][newvar][i]] for i in range(1,len(self.cfg[v][newvar]))] @@ -47,6 +52,7 @@ def AddVars(self,d): elif isinstance(self.cfg[v][newvar],str): var_define = self.cfg[v][newvar] d = d.Define(newvar,var_define) + print("*** Define AddVars",newvar,var_define) return d def AddVarsWithSelection(self,d): @@ -59,8 +65,10 @@ def AddVarsWithSelection(self,d): for v in variables: if selections[sel]: d = d.Define(v+sel,"{0}[{1}]".format(v,selections[sel])) + print("*** Define AddVarsWithSelection1",sel,v+sel,"{0}[{1}]".format(v,selections[sel])) else: d = d.Define(v+sel,"{0}".format(v)) + print("*** Define AddVarsWithSelection",sel,v+sel,"{0}".format(v)) if ('nm1' in self.cfg['objects'][obj]) and (self.cfg['objects'][obj]['nm1']): nm1s = self.cfg['objects'][obj]['nm1'] cutstr_objsel = "" @@ -75,16 +83,19 @@ def AddVarsWithSelection(self,d): cutstr = "&&".join(cutstrs) cutstr = cutstr_objsel + "({})".format(cutstr) d = d.Define(nm1s[i][0]+sel+'_nm1',"{0}[{1}]".format(nm1s[i][0],cutstr)) + print("*** Define AddVarsWithSelection2",nm1s[i][0]+sel+'_nm1',"{0}[{1}]".format(nm1s[i][0],cutstr)) #print("define {}: {}".format(nm1s[i][0]+sel+'_nm1',"{0}[{1}]".format(nm1s[i][0],cutstr))) return d def FilterEvents(self,d): d_filter = d.Filter(self.presel) + print("*** Filter",self.presel) return d_filter def AddWeights(self,d,weight): d = d.Define("evt_weight","{0}".format(weight)) + print("*** Define AddWeights","evt_weight","{0}".format(weight)) return d def getRDF(self): @@ -99,6 +110,7 @@ def getRDF(self): d = self.AddVarsWithSelection(d) if self.cfg['presel'] is not None: d = d.Filter(self.cfg['presel']) + print("*** Filter getRDF",self.cfg['presel']) xsec_weights = 1 d = self.AddWeights(d,xsec_weights) return d,xsec_weights @@ -111,14 +123,18 @@ def getplots(self,d,weight,plots_1d,plots_2d,plots_nm1,varlabel): plots_2d = [] if plots_nm1 is None: plots_nm1 = [] - +#!# + self.isData = True +#!# for plt in plots_1d: if not plt in self.cfg['plot_setting']: print("{} not registered in plot setting!".format(plt)) if self.isData: h = d.Histo1D(tuple(self.cfg['plot_setting'][plt]),plt+varlabel) + print("*** Histo1D getplots",plt,self.isData,tuple(self.cfg['plot_setting'][plt]),plt+varlabel) else: h = d.Histo1D(tuple(self.cfg['plot_setting'][plt]),plt+varlabel,weight) + print("*** Histo1D getplots",plt,self.isData,tuple(self.cfg['plot_setting'][plt]),plt+varlabel,weight) hs.append(h) for plt in plots_nm1: @@ -179,6 +195,7 @@ def makeHistFiles(self): d_sr = d if self.cfg['regions'][sr] is not None: d_sr = d_sr.Filter(self.cfg['regions'][sr]) + print("*** Filter makeHistFiles1",sr,self.cfg['regions'][sr]) newd_evt = fout.mkdir("{}_evt".format(sr)) hs = self.getplots(d_sr,weight="evt_weight",plots_1d=self.cfg['event_variables'],plots_2d=self.cfg['event_2d_plots'],plots_nm1=self.cfg.get('event_nm1'),varlabel="")