diff --git a/Validation/RecoB/scripts/histoStyle.py b/Validation/RecoB/scripts/histoStyle.py new file mode 100644 index 0000000000000..7d3c4dd2922aa --- /dev/null +++ b/Validation/RecoB/scripts/histoStyle.py @@ -0,0 +1,509 @@ + +####### + +# automatized plots generator for b-tagging performances +# Adrien Caudron, 2013, UCL + +####### + +#do all import +import os, sys + +try: + import ROOT +except: + print "\nCannot load PYROOT, make sure you have setup ROOT in the path" + print "and pyroot library is also defined in the variable PYTHONPATH, try:\n" + if (os.getenv("PYTHONPATH")): + print " setenv PYTHONPATH ${PYTHONPATH}:$ROOTSYS/lib\n" + else: + print " setenv PYTHONPATH $ROOTSYS/lib\n" + sys.exit() + +from ROOT import TFile +from ROOT import TCanvas +from ROOT import TPad +from ROOT import TLegend +from ROOT import TLatex +from ROOT import TH1F +from ROOT import TF1 +from ROOT import TVectorD +from ROOT import TGraphErrors +from ROOT import Double + +import Style +from listHistos import * + +#define the input root files +#fileVal = TFile("BTagRelVal_TTbar_Startup_14_612SLHC2.root","READ") +#fileRef = TFile("BTagRelVal_TTbar_Startup_612SLHC1_14.root","READ") +fileNameVal = "BTagRelVal_TTbar_Startup_14_612SLHC2.root" +fileNameRef = "BTagRelVal_TTbar_Startup_612SLHC1_14.root" +#define the val/ref labels +ValRel = "612SLHC2_14" +RefRel = "612SLHC1_14" +#define the sample labels +ValSample = "TTbar_FullSim" +RefSample = "TTbar_FullSim" +#define different settings +batch = False #run on batch mode ? +weight = 1. #rescale the histos according to this weight +drawLegend = False #draw legend ? +printBanner = False #draw text Banner on top of the histos +Banner = "CMS Preliminary" +doRatio = True #plot the ratios +drawOption = "" # "" or "HIST" +#path in the file +pathInFile = "/DQMData/Run 1/Btag/Run summary/" +#ETA/PT bins, GLOBAL ? +EtaPtBin =[ + "GLOBAL", + #"ETA_0-1v4", + #"ETA_1v4-2v4", + #"PT_50-80", + #"PT_80-120", + ] +#list of taggers to look at +listTag = [ + "CSV", + "CSVMVA", + "JP", + "JBP", + "TCHE", + "TCHP", + "SSVHE", + "SSVHP", + "SMT", + #"SMTIP3d", + #"SMTPt", + "SET", + ] +#list of flavors to look at +listFlavors = [ + #"ALL", + "B", + "C", + #"G", + #"DUS", + "DUSG", + #"NI", + ] +#map for marker color for flav-col and tag-col +mapColor = { + "ALL" : 4 , + "B" : 3 , + "C" : 1 , + "G" : 2 , + "DUS" : 2 , + "DUSG" : 2 , + "NI" : 5 , + "CSV" : 5 , + "CSVMVA" : 6 , + "JP" : 3 , + "JBP" : 9 , + "TCHE" : 1, + "TCHP" : 2, + "SSVHE" : 4, + "SSVHP" : 7, + "SMT" : 8 , + "SMTIP3d" : 11 , + "SMTPt" : 12 + } +#marker style map for Val/Ref +mapMarker = { + "Val" : 22, + "Ref" : 8 + } +mapLineWidth = { + "Val" : 3, + "Ref" : 2 + } +mapLineStyle = { + "Val" : 2, + "Ref" : 1 + } +#choose the formats to save the plots +listFromats = [ + "gif", + ] +#unity function +unity = TF1("unity","1",-1000,1000) +unity.SetLineColor(8) +unity.SetLineWidth(1) +unity.SetLineStyle(1) +#list of histos to plots +listHistos = [ + jetPt, + jetEta, + discr, + effVsDiscrCut_discr, + FlavEffVsBEff_discr, + performance, + #performanceC, + + #IP, + #IPe, + #IPs, + #NTracks, + #decayLength, + #distToJetAxis, + #NHits, + #NPixelHits, + #NormChi2, + #trackPt, + + + #flightDist3Dval, + #flightDist3Dsig, + #jetNSecondaryVertices, + + #vertexMass, + #vertexNTracks, + #vertexJetDeltaR, + #vertexEnergyRatio, + + #vertexCategory, + #trackSip3dVal, + #trackSip3dSig, + #trackSip3dSigAboveCharm, + #trackDeltaR, + #trackEtaRel, + #trackDecayLenVal, + #trackSumJetDeltaR, + #trackJetDist, + #trackSumJetEtRatio, + #trackPtRel, + #trackPtRatio, + #trackMomentum, + #trackPPar, + #trackPParRatio, + ] + +#methode to do a plot from histos +def histoProducer(plot,histos,keys,isVal=True): + if histos is None : return + if isVal : sample = "Val" + else : sample = "Ref" + outhistos = [] + minY=9999. + maxY=0. + for k in keys : + #Binning + if plot.binning and len(plot.binning)==3 : + histos[k].SetBins(plot.binning[0],plot.binning[1],plot.binning[2]) + elif plot.binning and len(plot.binning)==2 : + nbins=plot.binning[1]+1-plot.binning[0] + xmin=histos[k].GetBinLowEdge(plot.binning[0]) + xmax=histos[k].GetBinLowEdge(plot.binning[1]+1) + valtmp=TH1F(histos[k].GetName(),histos[k].GetTitle(),nbins,xmin,xmax) + i=1 + for bin in range(plot.binning[0],plot.binning[1]+1) : + valtmp.SetBinContent(i,histos[k].GetBinContent(bin)) + i+=1 + histos[k]=valtmp + if plot.Rebin and plot.Rebin > 0 : + histos[k].Rebin(plot.Rebin) + #Style + histos[k].SetLineColor(mapColor[k]) + histos[k].SetMarkerColor(mapColor[k]) + histos[k].SetMarkerStyle(mapMarker[sample]) + if drawOption == "HIST" : + histos[k].SetLineWidth(mapLineWidth[sample]) + histos[k].SetLineStyle(mapLineStyle[sample]) + #compute errors + histos[k].Sumw2() + #do the norm + if plot.doNormalization : + histos[k].Scale(1./histos[k].Integral()) + elif weight!=1 : + histos[k].Scale(weight) + #get Y min + if histos[k].GetMinimum(0.) < minY : + minY = histos[k].GetMinimum(0.) + #get Y max + if histos[k].GetBinContent(histos[k].GetMaximumBin()) > maxY : + maxY = histos[k].GetBinContent(histos[k].GetMaximumBin())+histos[k].GetBinError(histos[k].GetMaximumBin()) + #Axis + if plot.Xlabel : + histos[k].SetXTitle(plot.Xlabel) + if plot.Ylabel : + histos[k].SetYTitle(plot.Ylabel) + outhistos.append(histos[k]) + #Range + if not plot.logY : outhistos[0].GetYaxis().SetRangeUser(0,1.1*maxY) + #else : outhistos[0].GetYaxis().SetRangeUser(0.0001,1.05) + else : outhistos[0].GetYaxis().SetRangeUser(max(0.0001,0.5*minY),1.1*maxY) + return outhistos + +#method to do a plot from a graph +def graphProducer(plot,histos,tagFlav="B",mistagFlav=["C","DUSG"],isVal=True): + if histos is None : return + if isVal : sample = "Val" + else : sample = "Ref" + #define graphs + g = {} + g_out = [] + if tagFlav not in listFlavors : + return + if plot.tagFlavor and plot.mistagFlavor : + tagFlav = plot.tagFlavor + mistagFlav = plot.mistagFlavor + for f in listFlavors : + #compute errors, in case not already done + histos[f].Sumw2() + #efficiency lists + Eff = {} + EffErr = {} + for f in listFlavors : + Eff[f] = [] + EffErr[f] = [] + #define mapping points for the histos + maxnpoints = histos[tagFlav].GetNbinsX() + for f in listFlavors : + Eff[f].append(histos[f].GetBinContent(1)) + EffErr[f].append(histos[f].GetBinError(1)) + for bin in range(2,maxnpoints+1) : + #check if we add the point to the graph for Val sample + if len(Eff[tagFlav])>0 : + delta = Eff[tagFlav][-1]-histos[tagFlav].GetBinContent(bin) + if delta>max(0.005,EffErr[tagFlav][-1]) : + #get efficiencies + for f in listFlavors : + Eff[f].append(histos[f].GetBinContent(bin)) + EffErr[f].append(histos[f].GetBinError(bin)) + #create TVector + len_ = len(Eff[tagFlav]) + TVec_Eff = {} + TVec_EffErr = {} + for f in listFlavors : + TVec_Eff[f] = TVectorD(len_) + TVec_EffErr[f] = TVectorD(len_) + #Fill the vector + for j in range(0,len_) : + for f in listFlavors : + TVec_Eff[f][j] = Eff[f][j] + TVec_EffErr[f][j] = EffErr[f][j] + #fill TGraph + for mis in mistagFlav : + g[tagFlav+mis]=TGraphErrors(TVec_Eff[tagFlav],TVec_Eff[mis],TVec_EffErr[tagFlav],TVec_EffErr[mis]) + #style + for f in listFlavors : + if f not in mistagFlav : continue + g[tagFlav+f].SetLineColor(mapColor[f]) + g[tagFlav+f].SetMarkerStyle(mapMarker[sample]) + g[tagFlav+f].SetMarkerColor(mapColor[f]) + g_out.append(g[tagFlav+f]) + index = -1 + for g_i in g_out : + index+=1 + if g_i is not None : break + #Axis + g_out[index].GetXaxis().SetRangeUser(0,1) + g_out[index].GetYaxis().SetRangeUser(0.0001,1) + if plot.Xlabel : + g_out[index].GetXaxis().SetTitle(plot.Xlabel) + if plot.Ylabel : + g_out[index].GetYaxis().SetTitle(plot.Ylabel) + #add in the list None for element in listFlavors for which no TGraph is computed + for index,f in enumerate(listFlavors) : + if f not in mistagFlav : g_out.insert(index,None) + return g_out + +#method to draw the plot and save it +def savePlots(title,saveName,listFromats,plot,Histos,keyHisto,listLegend,options,ratios=None,legendName="") : + #create canvas + c = {} + pads = {} + if options.doRatio : + c[keyHisto] = TCanvas(saveName,keyHisto+plot.title,700,700+24*len(listFlavors)) + pads["hist"] = TPad("hist", saveName+plot.title,0,0.11*len(listFlavors),1.0,1.0) + else : + c[keyHisto] = TCanvas(keyHisto,saveName+plot.title,700,700) + pads["hist"] = TPad("hist", saveName+plot.title,0,0.,1.0,1.0) + pads["hist"].Draw() + if ratios : + for r in range(0,len(ratios)) : + pads["ratio_"+str(r)] = TPad("ratio_"+str(r), saveName+plot.title+str(r),0,0.11*r,1.0,0.11*(r+1)) + pads["ratio_"+str(r)].Draw() + pads["hist"].cd() + #canvas style + if plot.logY : pads["hist"].SetLogy() + if plot.grid : pads["hist"].SetGrid() + #legend + leg = TLegend(0.6,0.4,0.8,0.6) + leg.SetMargin(0.12) + leg.SetTextSize(0.035) + leg.SetFillColor(10) + leg.SetBorderSize(0) + #draw histos + first = True + option = drawOption + optionSame = drawOption+"same" + if plot.doPerformance : + option = "AP" + optionSame = "sameP" + for i in range(0,len(Histos)) : + if Histos[i] is None : continue + if first : + if not plot.doPerformance : Histos[i].GetPainter().PaintStat(ROOT.gStyle.GetOptStat(),0) + Histos[i].SetTitle(title) + Histos[i].Draw(option) + first = False + else : Histos[i].Draw(optionSame) + #Fill legend + if plot.legend and len(Histos)%len(listLegend)==0: + r=len(Histos)/len(listLegend) + index=i-r*len(listLegend) + while(index<0): + index+=len(listLegend) + legName = legendName.replace("KEY",listLegend[index]) + if ix : + if p==0 : continue + xbiserr = hVal[g_i].GetErrorX(p-1) + ybiserr = hVal[g_i].GetErrorY(p-1) + hVal[g_i].GetPoint(p-1,xbis,ybis) + else : + xbiserr = hVal[g_i].GetErrorX(p+1) + ybiserr = hVal[g_i].GetErrorY(p+1) + hVal[g_i].GetPoint(p+1,xbis,ybis) + if ybis==y : + #just take y at x + bin_p_valContent = y + bin_p_valContent_errP = y+yerr + bin_p_valContent_errM = y-yerr + else : + #do a linear extrapolation (equivalent to do Eval(xHist)) + a=(ybis-y)/(xbis-x) + b=y-a*x + bin_p_valContent = a*xHist+b + #extrapolate the error + aerrP = ( (ybis+ybiserr)-(y+yerr) ) / (xbis-x) + berrP = (y+yerr)-aerrP*x + bin_p_valContent_errP = aerrP*xHist+berrP + aerrM = ( (ybis-ybiserr)-(y-yerr) ) / (xbis-x) + berrM = (y-yerr)-aerrM*x + bin_p_valContent_errM = aerrM*xHist+berrM + #fill val hist + histVal.SetBinContent(bin_p,bin_p_valContent) + histVal.SetBinError(bin_p,(bin_p_valContent_errP-bin_p_valContent_errM)/2) + #loop over the reference TGraph to get the corresponding point + for pRef in range(0,hRef[g_i].GetN()): + #get point pRef + xRef = Double(0) + yRef = Double(0) + hRef[g_i].GetPoint(pRef,xRef,yRef) + #take the first point as xRef < xHist + if xRef > xHist : continue + xReferr = hRef[g_i].GetErrorX(pRef) + yReferr = hRef[g_i].GetErrorY(pRef) + #get the other point as xHist in [xRef,xRefbis] + xRefbis = Double(0) + yRefbis = Double(0) + xRefbiserr = hRef[g_i].GetErrorX(pRef+1) + yRefbiserr = hRef[g_i].GetErrorY(pRef+1) + hRef[g_i].GetPoint(pRef+1,xRefbis,yRefbis) + if yRefbis==yRef : + #just take yRef at xRef + bin_p_refContent = yRef + bin_p_refContent_errP = yRef+yReferr + bin_p_refContent_errM = yRef-yReferr + else : + #do a linear extrapolation (equivalent to do Eval(xHist)) + aRef=(ybis-y)/(xbis-x) + bRef=yRef-aRef*xRef + bin_p_refContent = aRef*xHist+bRef + #extrapolate the error + aReferrP = ((yRefbis+yRefbiserr)-(yRef+yReferr))/((xRefbis)-(xRef)) + bReferrP = (yRef+yReferr)-aReferrP*(xRef-xReferr) + bin_p_refContent_errP = aReferrP*xHist+bReferrP + aReferrM = ((yRefbis-yRefbiserr)-(yRef-yReferr))/((xRefbis)-(xRef)) + bReferrM = (yRef-yReferr)-aReferrM*(xRef+xReferr) + bin_p_refContent_errM = aReferrM*xHist+bReferrM + break + #fill ref hist + histRef.SetBinContent(bin_p,bin_p_refContent) + histRef.SetBinError(bin_p,(bin_p_refContent_errP-bin_p_refContent_errM)/2) + #do the ratio + histVal.Sumw2() + histRef.Sumw2() + histVal.Divide(histRef) + #ratio style + histVal.GetXaxis().SetRangeUser(0.,1.) + #histRef.GetXaxis().SetRangeUser(0.,1.) + histVal.GetYaxis().SetRangeUser(0.25,1.75) + histVal.SetMarkerColor(hVal[g_i].GetMarkerColor()) + histVal.SetLineColor(hVal[g_i].GetLineColor()) + histVal.GetYaxis().SetLabelSize(0.15) + histVal.GetXaxis().SetLabelSize(0.15) + ratio.append(histVal) + return ratio diff --git a/Validation/RecoB/scripts/listHistos.py b/Validation/RecoB/scripts/listHistos.py new file mode 100644 index 0000000000000..a05204bdd92a2 --- /dev/null +++ b/Validation/RecoB/scripts/listHistos.py @@ -0,0 +1,237 @@ + +####### + +# automatized plots generator for b-tagging performances +# Adrien Caudron, 2013, UCL + +####### + +class plotInfo : + def __init__ (self, name, title, #mandatory + legend="", Xlabel="", Ylabel="", logY=False, grid=False, + binning=None, Rebin=None, + doNormalization=False, + listTagger=None, + doPerformance=False, tagFlavor="B", mistagFlavor=["C","DUSG"]): + self.name = name #name of the histos without postfix as PT/ETA bin or flavor + self.title = title #title of the histograms : better if specific for the histogram + self.legend = legend #legend name, if contain 'KEY', it will be replace by the list of keys you provide (as flavor, tagger ...) + self.Xlabel = Xlabel #label of the X axis + self.Ylabel = Ylabel #label of the Y axis + self.logY = logY #if True : Y axis will be in log scale + self.grid = grid #if True : a grid will be drawn + self.binning = binning #if you want to change the binning put a list with [nBins,xmin,xmax] + self.Rebin = Rebin #if you want to rebin the histos + self.doNormalization = doNormalization #if you want to normalize to 1 all the histos + self.doPerformance = doPerformance #if you want to draw the performance as TGraph + if self.doPerformance : + #replace TAG by the tag flavor choosen (B, C, UDSG ...) + self.title = name.replace("TAG",tagFlavor) + self.Xlabel = Xlabel.replace("TAG",tagFlavor) + self.Ylabel = Ylabel.replace("TAG",tagFlavor) + self.legend = legend.replace("TAG",tagFlavor) + self.tagFlavor = tagFlavor + self.mistagFlavor = mistagFlavor + if listTagger is None : + self.listTagger=None #you will take the list of tagger defined centrally + else : + self.listTagger=listTagger #you take the list passed as argument +#define here the histograms you interested by +#by jets +jetPt = plotInfo(name="jetPt", title="Pt of all jets", legend="isVAL KEY-jets", Xlabel="Pt (GeV/c)", Ylabel="abitrary units", + logY=False, grid=False, + binning=[300,10.,310.], Rebin=20, doNormalization=True, + listTagger=["CSV"] + ) +jetEta = plotInfo(name="jetEta", title="Eta of all jets", legend="isVAL KEY-jets", Xlabel="#eta", Ylabel="abitrary units", + logY=False, grid=False, + binning=[11,90], Rebin=4, doNormalization=True, + listTagger=["CSV"] + ) +discr = plotInfo(name="discr", title="Discriminant of all jets", legend="isVAL KEY-jets", Xlabel="Discriminant", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True + ) +effVsDiscrCut_discr = plotInfo(name="effVsDiscrCut_discr", title="Efficiency versus discriminant cut for all jets", legend="isVAL KEY-jets", Xlabel="Discriminant", Ylabel="efficiency", + logY=True, grid=True + ) +#MC only +FlavEffVsBEff_discr = plotInfo(name="FlavEffVsBEff_B_discr", title="b-tag efficiency versus non b-tag efficiency", + legend="KEY FLAV-jets versus b-jets", Xlabel="b-tag efficiency", Ylabel="non b-tag efficiency", + logY=True, grid=True + ) +#MC only +performance = plotInfo(name="effVsDiscrCut_discr", title="TAG-tag efficiency versus non TAG-tag efficiency", + legend="isVAL KEY-jets versus TAG-jets", Xlabel="TAG-tag efficiency", Ylabel="non TAG-tag efficiency", + logY=True, grid=True, + doPerformance=True, tagFlavor="B", mistagFlavor=["C","DUSG"] + ) +#MC only, to do C vs B and C vs light +performanceC = plotInfo(name="effVsDiscrCut_discr", title="TAG-tag efficiency versus non TAG-tag efficiency", + legend="isVAL KEY-jets versus TAG-jets", Xlabel="TAG-tag efficiency", Ylabel="non TAG-tag efficiency", + logY=True, grid=True, + doPerformance=True, tagFlavor="C", mistagFlavor=["B","DUSG"] + ) +#by tracks +IP = plotInfo(name="ip_3D", title="Impact parameter", legend="isVAL KEY-jets", Xlabel="IP [cm]", Ylabel="abitrary units", + logY=False, grid=False, + binning=None,Rebin=None, doNormalization=True, + listTagger=["IPTag"] + ) +IPe = plotInfo(name="ipe_3D", title="Impact parameter error", legend="isVAL KEY-jets", Xlabel="IPE [cm]", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["IPTag"] + ) +IPs = plotInfo(name="ips_3D", title="Impact parameter significance", legend="isVAL KEY-jets", Xlabel="IPS", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["IPTag"] + ) +NTracks = plotInfo(name="selTrksNbr_3D", title="number of selected tracks", legend="isVAL KEY-jets", Xlabel="number of selected tracks", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["IPTag"] + ) +distToJetAxis = plotInfo(name="jetDist_3D", title="track distance to the jet axis", legend="isVAL KEY-jets", Xlabel="distance to the jet axis [cm]", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["IPTag"] + ) +decayLength = plotInfo(name="decLen_3D", title="track decay length", legend="isVAL KEY-jets", Xlabel="decay length [cm]", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, listTagger=["IPTag"] + ) +NHits = plotInfo(name="tkNHits_3D", title="Number of Hits / selected tracks", legend="isVAL KEY-jets", Xlabel="Number of Hits", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["IPTag"] + ) +NPixelHits = plotInfo(name="tkNPixelHits_3D", title="Number of Pixel Hits / selected tracks", legend="isVAL KEY-jets", Xlabel="Number of Pixel Hits", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["IPTag"] + ) +NormChi2 = plotInfo(name="tkNChiSqr_3D", title="Normalized Chi2", legend="isVAL KEY-jets", Xlabel="Normilized Chi2", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["IPTag"] + ) +trackPt = plotInfo(name="tkPt_3D", title="track Pt", legend="isVAL KEY-jets", Xlabel="track Pt", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["IPTag"] + ) +#by SV and for CSV information +flightDist3Dval = plotInfo(name="flightDistance3dVal", title="3D flight distance value", legend="isVAL KEY-jets", Xlabel="3D flight distance value [cm]", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +flightDist3Dsig = plotInfo(name="flightDistance3dSig", title="3D flight distance significance", legend="isVAL KEY-jets", Xlabel="3D flight distance significance", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +jetNSecondaryVertices = plotInfo(name="jetNSecondaryVertices", title="Number of SV / jet", legend="isVAL KEY-jets", Xlabel="Number of SV / jet", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +#Reco and pseudo vertex information +vertexMass = plotInfo(name="vertexMass", title="vertex mass", legend="isVAL KEY-jets", Xlabel="vertex mass GeV/c^2", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +vertexNTracks = plotInfo(name="vertexNTracks", title="number of tracks at SV", legend="isVAL KEY-jets", Xlabel="number of tracks at SV", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +vertexJetDeltaR = plotInfo(name="vertexJetDeltaR", title="Delta R between the SV and the jet axis", legend="isVAL KEY-jets", Xlabel="Delta R between the SV and the jet axis", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +vertexEnergyRatio = plotInfo(name="vertexEnergyRatio", title="Energy Ratio between SV and the jet", legend="isVAL KEY-jets", Xlabel="Energy Ratio between SV and the jet", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +#Reco, pseudo and no vertex information +vertexCategory = plotInfo(name="vertexCategory", title="Reco, Pseudo, No vertex", legend="isVAL KEY-jets", Xlabel="Reco, Pseudo, No vertex", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +trackSip3dVal = plotInfo(name="trackSip3dVal", title="track IP 3D", legend="isVAL KEY-jets", Xlabel="track IP 3D [cm]", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +trackSip3dSig = plotInfo(name="trackSip3dSig", title="track IPS 3D", legend="isVAL KEY-jets", Xlabel="track IPS 3D", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +trackSip3dSigAboveCharm = plotInfo(name="trackSip3dSigAboveCharm", title="first track IPS 3D lifting SV mass above charm", legend="isVAL KEY-jets", Xlabel="first track IPS 3D lifting SV mass above charm", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +trackDeltaR = plotInfo(name="trackDeltaR", title="Delta R between the track and the jet axis", legend="isVAL KEY-jets", Xlabel="DeltaR(track,jet axis)", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +trackEtaRel = plotInfo(name="trackEtaRel", title="track eta relative to the jet axis", legend="isVAL KEY-jets", Xlabel="track eta relative to the jet axis", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +trackDecayLenVal = plotInfo(name="trackDecayLenVal", title="track decay length", legend="isVAL KEY-jets", Xlabel="track decay length", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +trackSumJetDeltaR = plotInfo(name="trackSumJetDeltaR", title="Delta R between track 4-vector sum and jet axis", legend="isVAL KEY-jets", Xlabel="Delta R between track 4-vector sum and jet axis", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +trackJetDist = plotInfo(name="trackJetDist", title="track distance to jet axis", legend="isVAL KEY-jets", Xlabel="track distance to jet axis", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +trackSumJetEtRatio = plotInfo(name="trackSumJetEtRatio", title="track sum Et / jet energy", legend="isVAL KEY-jets", Xlabel="track sum Et / jet energy", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +trackPtRel = plotInfo(name="trackPtRel", title="track Pt relative to jet axis", legend="isVAL KEY-jets", Xlabel="track Pt relative to jet axis", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +trackPtRatio = plotInfo(name="trackPtRatio", title="track Pt relative to jet axis, normalized to its energy", legend="isVAL KEY-jets", Xlabel="track Pt relative to jet axis, normalized to its energy", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +trackMomentum = plotInfo(name="trackMomentum", title="track momentum", legend="isVAL KEY-jets", Xlabel="track momentum [GeV/c]", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +trackPPar = plotInfo(name="trackPPar", title="track parallel momentum along the jet axis", legend="isVAL KEY-jets", Xlabel="track parallel momentum along the jet axis", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) +trackPParRatio = plotInfo(name="trackPParRatio", title="track parallel momentum along the jet axis, normalized to its energy", legend="isVAL KEY-jets", Xlabel="track parallel momentum along the jet axis, normalized to its energy", Ylabel="abitrary units", + logY=False, grid=False, + binning=None, Rebin=None, doNormalization=True, + listTagger=["CSVTag"] + ) diff --git a/Validation/RecoB/scripts/plotFactory.py b/Validation/RecoB/scripts/plotFactory.py new file mode 100755 index 0000000000000..835db3ab1699d --- /dev/null +++ b/Validation/RecoB/scripts/plotFactory.py @@ -0,0 +1,145 @@ +#!/usr/bin/env python + +####### + +# automatized plots generator for b-tagging performances +# Adrien Caudron, 2013, UCL + +####### + +#import all what is needed +from histoStyle import * +#parser options +from optparse import OptionParser +usage="""%prog [options]""" +description="""A simple script to generate validation plots""" +epilog="""Example: +plotFactory.py -f BTagRelVal_TTbar_Startup_600.root -F BTagRelVal_TTbar_Startup_600gspre3.root -r 600 -R 600gspre3 -s TTbar_Startup -S TTbar_Startup +""" +parser = OptionParser(usage=usage,add_help_option=True,description=description,epilog=epilog) +parser.add_option("-f", "--valInputFile", dest="valPath", default=fileNameVal, + help="Read input file for sample to validated", metavar="VALFILE") +parser.add_option("-F", "--refInputFile", dest="refPath", default=fileNameRef, + help="Read input file for reference sample", metavar="RAFFILE") +parser.add_option("-r", "--valReleaseName", dest="ValRel", default=ValRel, + help="Name to refer to the release/conditions to validate, ex: 600, GTV18 ...", metavar="VALREL") +parser.add_option("-R", "--refReleaseName", dest="RefRel", default=RefRel, + help="Name to refer to the reference release/conditions, ex: 600pre11, GTV16 ...", metavar="REFREL") +parser.add_option("-s", "--valSampleName", dest="ValSample", default=ValSample, + help="Name to refer to the sample name to validate, ex: TTbar_FullSim, 2012C ...", metavar="VALSAMPLE") +parser.add_option("-S", "--refSampleName", dest="RefSample", default=RefSample, + help="Name to refer to the reference sample name, ex: TTbar_FullSim, 2012C ...", metavar="REFSAMPLE") +parser.add_option("-b", "--batch", dest="batch", default=batch, + action="store_true", help="if False, the script will run in batch mode") +parser.add_option("-l", "--drawLegend", dest="drawLegend", default=drawLegend, + action="store_true", help="if True the legend will be drawn on top of the plots") +parser.add_option("-p", "--printBanner", dest="printBanner", default=printBanner, + action="store_true", help="if True, a banner will be print on top of the plots") +parser.add_option("-B", "--Banner", dest="Banner", default=Banner, + help="String to write as banner on top of the plots, option -B should be used") +parser.add_option("-n", "--noRatio", dest="doRatio", default=doRatio, + action="store_false", help="if True, ratios plots will be created") +(options, args) = parser.parse_args() +print "file for validation", options.valPath, "file for reference", options.refPath +print "Validation release:", options.ValRel, "Reference release:", options.RefRel +print "Validation sample:", options.ValSample, "Reference sample:", options.RefSample +print "Options : batch mode ?", options.batch, "draw legend ?", options.drawLegend, "print banner ?", options.printBanner, "banner is ", options.Banner, "make ratio plots ?", options.doRatio +#define the input root files +if options.valPath and options.refPath : + fileVal = TFile(options.valPath,"READ") + fileRef = TFile(options.refPath,"READ") +#batch mode ? +if options.batch : ROOT.gROOT.SetBatch() +# style +_style = Style.Style() +_style.SetStyle() +#title +if options.ValSample==options.RefSample : title=options.ValRel+"vs"+options.RefRel+" "+options.ValSample+" " +elif options.ValRel==options.RefRel : title=options.ValRel+" "+options.ValSample+"_vs_"+options.RefSample+" " +else : title=options.ValRel+"vs"+options.RefRel+" "+options.ValSample+"_vs_"+options.RefSample+" " +#declaration +c = {} +perfAll_Val = {} +perfAll_Ref = {} +perfAll_keys = [] +valHistos = {} +refHistos ={} +Histos = {} +ratios = {} +#loop over eta an pt bins +for b in EtaPtBin : + #loop over the histos + for h in listHistos : + for f in listFlavors : + perfAll_Val[f] = {} + perfAll_Ref[f] = {} + #loop over the list of taggers + if h.listTagger is None : h.listTagger=listTag + for tag in h.listTagger : + keyHisto = tag+"_"+h.name+"_"+b + if h.doPerformance : + keyHisto = tag+"_performance_vs_"+h.tagFlavor + #loop over the flavours + h_Val = {} + h_Ref = {} + passH = False + for f in listFlavors : + path = pathInFile+tag+"_"+b+"/"+h.name+"_"+tag+"_"+b+f + if "_B_" in path : + path=path.replace("_B_","_"+f+"_") + path=path.replace(b+f,b) + print path + #get histos + h_Val[f] = fileVal.Get(path) + h_Ref[f] = fileRef.Get(path) + if not h_Val[f] : + print "ERROR :", path, "not found in the roofiles, please check the spelling or check if this histogram is present in the rootdile" + passH = True + if passH : continue + #stop if FlavEffVsBEff_?_discr plot for all the taggers + if h.name=="FlavEffVsBEff_B_discr" : + for f in listFlavors : + perfAll_Val[f][tag]=h_Val[f] + perfAll_Ref[f][tag]=h_Ref[f] + perfAll_keys.append(tag) + continue + #create final histos + if h.doPerformance : + valHistos[keyHisto]=graphProducer(plot=h,histos=h_Val,isVal=True) + refHistos[keyHisto]=graphProducer(plot=h,histos=h_Ref,isVal=False) + else : + valHistos[keyHisto]=histoProducer(plot=h,histos=h_Val,keys=listFlavors,isVal=True) + refHistos[keyHisto]=histoProducer(plot=h,histos=h_Ref,keys=listFlavors,isVal=False) + if valHistos[keyHisto] is None or refHistos[keyHisto] is None : continue + if len(valHistos[keyHisto])!=len(refHistos[keyHisto]) : print "ERROR" + #compute ratios + if options.doRatio : + if h.doPerformance: + ratiosList = createRatioFromGraph(valHistos[keyHisto],refHistos[keyHisto]) + else : + ratiosList = createRatio(valHistos[keyHisto],refHistos[keyHisto]) + ratios[keyHisto] = ratiosList + else : + ratiosList = None + #set name file + if options.ValSample == options.RefSample : saveName=options.ValRel+"vs"+options.RefRel+"_"+options.ValSample+"_Val_"+keyHisto+"_all" + elif options.ValRel==options.RefRel : saveName=options.ValRel+"_"+options.ValSample+"_vs_"+options.RefSample+"_Val_"+keyHisto+"_all" + else : saveName=options.ValRel+"vs"+options.RefRel+"_"+options.ValSample+"_vs_"+options.RefSample+"_Val_"+keyHisto+"_all" + #save canvas + c[keyHisto] = savePlots(title=title+tag,saveName=saveName,listFromats=listFromats,plot=h,Histos=valHistos[keyHisto]+refHistos[keyHisto],options=options,ratios=ratiosList,keyHisto=keyHisto,listLegend=listFlavors,legendName=h.legend) + #for FlavEffVsBEff_B_discr + if h.name=="FlavEffVsBEff_B_discr" : + for f in ["C","DUSG"] : + for isVal in [True,False] : + keyHisto=f+str(isVal) + #setup the histos + if isVal : Histos[keyHisto]=histoProducer(plot=h,histos=perfAll_Val[f],keys=perfAll_keys,isVal=isVal) + else : Histos[keyHisto]=histoProducer(plot=h,histos=perfAll_Ref[f],keys=perfAll_keys,isVal=isVal) + #set name file + if isVal : saveName=options.ValRel+"_"+options.ValSample+"_performance_Bvs"+f+"_allTaggers" + else : saveName=options.RefRel+"_"+options.RefSample+"_performance_Bvs"+f+"_allTaggers" + #set title + if isVal : titleFlav = options.ValRel+"_"+options.ValSample+"_performance_Bvs"+f+"_allTaggers" + else : titleFlav = options.RefRel+"_"+options.RefSample+"_performanceBvs"+f+"_allTaggers" + #save canvas + c[keyHisto] = savePlots(title=titleFlav,saveName=saveName,listFromats=listFromats,plot=h,Histos=Histos[keyHisto],keyHisto=keyHisto,listLegend=h.listTagger,options=options,legendName=h.legend.replace("FLAV",f)) diff --git a/Validation/RecoB/test/RelValnewFinal.csh b/Validation/RecoB/test/RelValnewFinal.csh new file mode 100755 index 0000000000000..6712b5ad41b22 --- /dev/null +++ b/Validation/RecoB/test/RelValnewFinal.csh @@ -0,0 +1,86 @@ +#!/bin/tcsh + +#change release version : $1=release to validate, $2=reference release, $3=working directory (where is lacated yours CMSSW instances), $4=release name for DQM inputs to validate, $5=the same for reference DQM inputs +valrel=$1 +refrel=$2 +workdir=$3 +valdir=$4 +refdir=$5 + +mkdir TTbar_${valrel}_vs_${refrel}_Startup +mkdir TTbar_${valrel}_vs_${refrel}_Startup_PU +mkdir TTbar_${valrel}_vs_${refrel}_FastSim +mkdir QCD_${valrel}_vs_${refrel}_Startup +mkdir FastSim_TTbar_${valrel}_vs_TTbar_${valrel} + +cd TTbar_${valrel}_vs_${refrel}_Startup +plotFactory.py -b -f ${workdir}/CMSSW_${valdir}/src/Validation/RecoB/test/BTagRelVal_TTbar_Startup_${valrel}.root -F ${workdir}/CMSSW_${refdir}/src/Validation/RecoB/test/BTagRelVal_TTbar_Startup_${refrel}.root -r ${valrel} -R ${refrel} -s TTbar_Startup -S TTbar_Startup +cp /afs/cern.ch/cms/btag/www/validation/img/0_leg*.gif . +mv 0_leg1.gif 0_leg4.gif +for File in `ls ${valrel}_*_allTaggers*.gif`; do mv ${File} 1_${File}; done +for File in `ls ${valrel}*jetPt*.gif`; do mv ${File} 2_${File}; done +for File in `ls ${refrel}_*_allTaggers*.gif`; do mv ${File} 3_${File}; done +for File in `ls ${valrel}*jetEta*.gif`; do mv ${File} 4_${File}; done +cd .. + +cd TTbar_${valrel}_vs_${refrel}_Startup_PU +plotFactory.py -b -f ${workdir}/CMSSW_${valdir}/src/Validation/RecoB/test/BTagRelVal_TTbar_Startup_PU_${valrel}.root -F ${workdir}/CMSSW_${refdir}/src/Validation/RecoB/test/BTagRelVal_TTbar_Startup_PU_${refrel}.root -r ${valrel} -R ${refrel} -s TTbar_Startup_PU -S TTbar_Startup_PU +cp /afs/cern.ch/cms/btag/www/validation/img/0_leg*.gif . +mv 0_leg1.gif 0_leg4.gif +for File in `ls ${valrel}_*_allTaggers*.gif`; do mv ${File} 1_${File}; done +for File in `ls ${valrel}*jetPt*.gif`; do mv ${File} 2_${File}; done +for File in `ls ${refrel}_*_allTaggers*.gif`; do mv ${File} 3_${File}; done +for File in `ls ${valrel}*jetEta*.gif`; do mv ${File} 4_${File}; done +cd .. + +cd TTbar_${valrel}_vs_${refrel}_FastSim +plotFactory.py -b -f ${workdir}/CMSSW_${valdir}/src/Validation/RecoB/test/BTagRelVal_TTbar_FastSim_${valrel}.root -F ${workdir}/CMSSW_${refdir}/src/Validation/RecoB/test/BTagRelVal_TTbar_FastSim_${refrel}.root -r ${valrel} -R ${refrel} -s TTbar_FastSim -S TTbar_FastSim +cp /afs/cern.ch/cms/btag/www/validation/img/0_leg*.gif . +mv 0_leg1.gif 0_leg4.gif +for File in `ls ${valrel}_*_allTaggers*.gif`; do mv ${File} 1_${File}; done +for File in `ls ${valrel}*jetPt*.gif`; do mv ${File} 2_${File}; done +for File in `ls ${refrel}_*_allTaggers*.gif`; do mv ${File} 3_${File}; done +for File in `ls ${valrel}*jetEta*.gif`; do mv ${File} 4_${File}; done +cd .. + + +cd QCD_${valrel}_vs_${refrel}_Startup +plotFactory.py -b -f ${workdir}/CMSSW_${valdir}/src/Validation/RecoB/test/BTagRelVal_QCD_Startup_${valrel}.root -F ${workdir}/CMSSW_${refdir}/src/Validation/RecoB/test/BTagRelVal_QCD_Startup_${refrel}.root -r ${valrel} -R ${refrel} -s QCD_Startup -S QCD_Startup +cp /afs/cern.ch/cms/btag/www/validation/img/0_leg*.gif . +mv 0_leg1.gif 0_leg4.gif +for File in `ls ${valrel}_*_allTaggers*.gif`; do mv ${File} 1_${File}; done +for File in `ls ${valrel}*jetPt*.gif`; do mv ${File} 2_${File}; done +for File in `ls ${refrel}_*_allTaggers*.gif`; do mv ${File} 3_${File}; done +for File in `ls ${valrel}*jetEta*.gif`; do mv ${File} 4_${File}; done +cd .. + +cd FastSim_TTbar_${valrel}_vs_TTbar_${valrel} +plotFactory.py -b -f ${workdir}/CMSSW_${valdir}/src/Validation/RecoB/test/BTagRelVal_TTbar_FastSim_${valrel}.root -F ${workdir}/CMSSW_${valdir}/src/Validation/RecoB/test/BTagRelVal_TTbar_Startup_${valrel}.root -r ${valrel} -R ${valrel} -s TTbar_FastSim -S TTbar_Startup +cp /afs/cern.ch/cms/btag/www/validation/img/0_leg*.gif . +mv 0_leg1.gif 0_leg4.gif +for File in `ls ${valrel}*FastSim*_allTaggers*.gif`; do mv ${File} 1_${File}; done +for File in `ls ${valrel}*jetPt*.gif`; do mv ${File} 2_${File}; done +for File in `ls ${valrel}*Startup*_allTaggers*.gif`; do mv ${File} 3_${File}; done +for File in `ls ${valrel}*jetEta*.gif`; do mv ${File} 4_${File}; done +cd .. + +mkdir CMSSW_${valdir} +mv *_${valrel}_vs_${refrel}_* CMSSW_${valdir}/ +mv FastSim_TTbar_${valrel}_vs_TTbar_${valrel} CMSSW_${valdir}/ + +echo ''TTbar_${valrel}_vs_${refrel}_Startup'
' >> index.html + +echo ''TTbar_${valrel}_vs_${refrel}_Startup_PU'
' >> index.html + +echo ''TTbar_${valrel}_vs_${refrel}_FastSim'
' >> index.html + +echo ''QCD_${valrel}_vs_${refrel}_Startup'
' >> index.html + +echo ''FastSim_TTbar_${valrel}_vs_TTbar_${valrel}'
' >> index.html + + + +#mv index.html /afs/cern.ch/cms/btag/www/validation/CMSSW_${valdir}_topdir.html + + +echo "https://cms-btag-validation.web.cern.ch/cms-btag-validation/validation/CMSSW_${valdir}_topdir.html" >& webpage.txt