diff --git a/NtupleAna/bin/BTagAnalyzer.cc b/NtupleAna/bin/BTagAnalyzer.cc index 100a152..73675c8 100644 --- a/NtupleAna/bin/BTagAnalyzer.cc +++ b/NtupleAna/bin/BTagAnalyzer.cc @@ -60,6 +60,7 @@ int main(int argc, char * argv[]){ const edm::ParameterSet& parameters = process.getParameter("BTagAnalyzer"); bool debug = parameters.getParameter("debug"); + double minJetPt = parameters.getParameter("minJetPt"); bool isMC = parameters.getParameter("isMC"); bool isTurnOnStudy = parameters.getParameter("isTurnOnStudy"); bool doLeptonSel = parameters.getParameter("doLeptonSel"); @@ -130,8 +131,9 @@ int main(int argc, char * argv[]){ a.eventLoop(maxEvents); } else{ - std::cout << "BTagAnalysis " << std::endl; - BTagAnalysis a = BTagAnalysis(treeRAW, treeAOD, fsh, isMC, year, histogramming, debug, PUFileName, jetDetailString, nnParameters, pfJetName); + std::cout << "BTagAnalysis with minJetPt " << minJetPt << std::endl; + + BTagAnalysis a = BTagAnalysis(treeRAW, treeAOD, fsh, isMC, year, histogramming, debug, minJetPt, PUFileName, jetDetailString, nnParameters, pfJetName); a.doLeptonSel = doLeptonSel; //if(!isMC){ // a.lumiMask = lumiMask; diff --git a/NtupleAna/bin/BTagAnalyzerHLT.cc b/NtupleAna/bin/BTagAnalyzerHLT.cc index 28caaad..30ff813 100644 --- a/NtupleAna/bin/BTagAnalyzerHLT.cc +++ b/NtupleAna/bin/BTagAnalyzerHLT.cc @@ -56,6 +56,7 @@ int main(int argc, char * argv[]){ const edm::ParameterSet& parameters = process.getParameter("BTagAnalyzer"); bool debug = parameters.getParameter("debug"); + double minJetPt = parameters.getParameter("minJetPt"); bool isMC = parameters.getParameter("isMC"); int histogramming = parameters.getParameter("histogramming"); int skipEvents = parameters.getParameter("skipEvents"); diff --git a/NtupleAna/interface/BTagAnalysis.h b/NtupleAna/interface/BTagAnalysis.h index 25c15b0..857ab82 100644 --- a/NtupleAna/interface/BTagAnalysis.h +++ b/NtupleAna/interface/BTagAnalysis.h @@ -34,6 +34,7 @@ namespace TriggerStudies { TChain* eventsRAW; bool debug = false; + float minJetPt = 30; std::string year; bool isMC = false; TFileDirectory dir; @@ -382,7 +383,7 @@ namespace TriggerStudies { std::shared_ptr neuralNet; - BTagAnalysis(TChain* _eventsRAW, TChain* _eventsAOD, fwlite::TFileService& fs, bool _isMC, std::string _year, int _histogramming, bool _debug, std::string PUFileName, std::string jetDetailString, const edm::ParameterSet& nnConfig, std::string pfJetName); + BTagAnalysis(TChain* _eventsRAW, TChain* _eventsAOD, fwlite::TFileService& fs, bool _isMC, std::string _year, int _histogramming, bool _debug, float minJetPt, std::string PUFileName, std::string jetDetailString, const edm::ParameterSet& nnConfig, std::string pfJetName); void monitor(long int); int eventLoop(int, int nSkipEvents = 0); int processEvent(); diff --git a/NtupleAna/scripts/BTagAnalyzer_cfg.py b/NtupleAna/scripts/BTagAnalyzer_cfg.py index 6fba1ca..f9e37c3 100644 --- a/NtupleAna/scripts/BTagAnalyzer_cfg.py +++ b/NtupleAna/scripts/BTagAnalyzer_cfg.py @@ -7,8 +7,8 @@ #sys.path.insert(0, 'TriggerStudies/nTupleAnalysis/scripts/') #from cfgHelper import * -print "Input command" -print " ".join(sys.argv) +print( "Input command") +print( " ".join(sys.argv)) parser = optparse.OptionParser() @@ -27,6 +27,7 @@ parser.add_option('-o', '--outputBase', dest="outputBase", default="/uscms/home/bryantp/nobackup/TriggerStudies/", help="Base path for storing output histograms and picoAOD") parser.add_option('--puFile', dest="puFile", default="", help="PUFileName") parser.add_option('-n', '--nevents', dest="nevents", default="-1", help="Number of events to process. Default -1 for no limit.") +parser.add_option( '--minJetPt', dest="minJetPt", default="30", help="Minimm jet pt") parser.add_option( '--histogramming', dest="histogramming", default="1e6", help="Histogramming level. 0 to make no kinematic histograms. 1: only make histograms for full event selection, larger numbers add hists in reverse cutflow order.") parser.add_option( '--skipEvents', dest="skipEvents", default="0", help="") parser.add_option( '--nnConfig', default=None, help="") @@ -156,10 +157,11 @@ #Setup event loop object -if o.inputAOD is 'None': +if o.inputAOD == 'None': print('Configuring HLTOnly...') process.BTagAnalyzer = cms.PSet( debug = cms.bool(o.debug), + minJetPt = cms.double(float(o.minJetPt)), isMC = cms.bool(o.isMC), year = cms.string(o.year), jetDetailString = cms.string(jetDetailString), @@ -173,6 +175,7 @@ print('Configuring RAW+AOD...') process.BTagAnalyzer = cms.PSet( debug = cms.bool(o.debug), + minJetPt = cms.double(float(o.minJetPt)), fileNamesAOD = cms.vstring(fileNamesAOD), isMC = cms.bool(o.isMC), isTurnOnStudy = cms.bool(o.isTurnOnStudy), diff --git a/NtupleAna/src/BTagAnalysis.cc b/NtupleAna/src/BTagAnalysis.cc index 1f3e6eb..6162866 100644 --- a/NtupleAna/src/BTagAnalysis.cc +++ b/NtupleAna/src/BTagAnalysis.cc @@ -44,13 +44,15 @@ const float OfflineDeepFlavourMediumCut2017 = 0.3033; const float OfflineDeepFlavourLooseCut2017 = 0.0521; //const float drTrackToJet = 0.29; -const float drTrackToJet = 1e6; +//const float drTrackToJet = 1e6; +const float drTrackToJet = 0.25; -BTagAnalysis::BTagAnalysis(TChain* _eventsRAW, TChain* _eventsAOD, fwlite::TFileService& fs, bool _isMC, std::string _year, int _histogramming, bool _debug, std::string PUFileName, std::string jetDetailString, const edm::ParameterSet& nnConfig, std::string pfJetName){ +BTagAnalysis::BTagAnalysis(TChain* _eventsRAW, TChain* _eventsAOD, fwlite::TFileService& fs, bool _isMC, std::string _year, int _histogramming, bool _debug, float _minJetPt, std::string PUFileName, std::string jetDetailString, const edm::ParameterSet& nnConfig, std::string pfJetName){ if(_debug) cout<<"In BTagAnalysis constructor"<eta) > 4) continue; - if(offJet->pt < 30) continue; + if(offJet->pt < minJetPt) continue; if(nTupleAnalysis::failOverlap(offJet->p,event->elecs,0.4)) continue; @@ -466,7 +468,7 @@ int BTagAnalysis::processEvent(){ if(fabs(offJet->eta) > 4) continue; cutflowJets->Fill("eta", eventWeight); - if(offJet->pt < 30) continue; + if(offJet->pt < minJetPt) continue; cutflowJets->Fill("pt", eventWeight); ++nOffJetsPreOLap; @@ -496,7 +498,7 @@ int BTagAnalysis::processEvent(){ if(offJetOther == offJet) continue; - if(offJetOther->pt < 30) continue; + if(offJetOther->pt < minJetPt) continue; if(fabs(offJetOther->eta) > 4) continue; if(nTupleAnalysis::failOverlap(offJetOther->p,event->elecs,0.4)) continue; if(nTupleAnalysis::failOverlap(offJetOther->p,event->muons,0.4)) continue; @@ -712,7 +714,7 @@ int BTagAnalysis::processEvent(){ // for(const nTupleAnalysis::jetPtr& pfJet : event->pfJets){ if(fabs(pfJet->eta) > 4) continue; - if(pfJet->pt < 30) continue; + if(pfJet->pt < minJetPt) continue; //pfJetHistsPreOLap.Fill(pfJet); @@ -744,7 +746,7 @@ int BTagAnalysis::processEvent(){ if(doCaloJets){ for(const nTupleAnalysis::jetPtr& caloJet : event->caloJets){ if(fabs(caloJet->eta) > 4) continue; - if(caloJet->pt < 30) continue; + if(caloJet->pt < minJetPt) continue; //caloJetHistsPreOLap.Fill(caloJet); if(nTupleAnalysis::failOverlap(caloJet->p,event->elecs, 0.4)) continue; @@ -788,7 +790,7 @@ int BTagAnalysis::processEvent(){ if(doPuppiJets){ for(const nTupleAnalysis::jetPtr& puppiJet : event->puppiJets){ if(fabs(puppiJet->eta) > 4) continue; - if(puppiJet->pt < 30) continue; + if(puppiJet->pt < minJetPt) continue; //puppiJetHistsPreOLap.Fill(puppiJet); if(nTupleAnalysis::failOverlap(puppiJet->p,event->elecs, 0.4)) continue; diff --git a/plotting/CMSlogo_outline_black_red_nolabel_May2014.pdf b/plotting/CMSlogo_outline_black_red_nolabel_May2014.pdf new file mode 100644 index 0000000..7c150fd Binary files /dev/null and b/plotting/CMSlogo_outline_black_red_nolabel_May2014.pdf differ diff --git a/plotting/CMU_Logo_Stack_Red.eps b/plotting/CMU_Logo_Stack_Red.eps new file mode 100755 index 0000000..04f7ced Binary files /dev/null and b/plotting/CMU_Logo_Stack_Red.eps differ diff --git a/plotting/JetLevelPlotUtils.py b/plotting/JetLevelPlotUtils.py index 2aa33e6..9bd7ed2 100644 --- a/plotting/JetLevelPlotUtils.py +++ b/plotting/JetLevelPlotUtils.py @@ -137,7 +137,7 @@ def makeEff(var,dirs,inFile,binning,bayesRatio=1,histForXBarycenterCalc=None): numHist = getHist(inFile,dirs, var[0],binning,color=ROOT.kBlue) denHist = getHist(inFile,dirs, var[1],binning,color=ROOT.kBlue) else: - print "ERROR",var,dirs + print( "ERROR",var,dirs) #print "max num is ",numHist.GetXaxis().GetXmax() @@ -201,15 +201,15 @@ def drawComp(name,inputHists,yTitle,xTitle,outDir,otherText="",setLogy=1,yMax= 1 if doFit: xAve = (ratio_axis.GetXaxis().GetXmin() + ratio_axis.GetXaxis().GetXmax()) /2 xmin = max(30,ratio_axis.GetXaxis().GetXmin()) - print "Setting Range",xmin, ratio_axis.GetXaxis().GetXmax() + print( "Setting Range",xmin, ratio_axis.GetXaxis().GetXmax()) sigmoid = ROOT.TF1("func", "(1.0/(1+ TMath::Exp(-[0]*(x-[1]))))", xmin, ratio_axis.GetXaxis().GetXmax()) sigmoid.SetParameters(0.01, xAve) inputHists[0][0].Fit(sigmoid) sigmoid.Draw("same") - print hInfo[0].GetName(),":", - print sigmoid.GetParameter(0), - print sigmoid.GetParameter(1) + print( hInfo[0].GetName(),":",) + print( sigmoid.GetParameter(0),) + print( sigmoid.GetParameter(1)) textFits = [] for i in range(2): @@ -228,7 +228,7 @@ def drawComp(name,inputHists,yTitle,xTitle,outDir,otherText="",setLogy=1,yMax= 1 if doFit: xAve = (ratio_axis.GetXaxis().GetXmin() + ratio_axis.GetXaxis().GetXmax()) /2 xmin = max(30,ratio_axis.GetXaxis().GetXmin()) - print "Setting Range",xmin, ratio_axis.GetXaxis().GetXmax() + print( "Setting Range",xmin, ratio_axis.GetXaxis().GetXmax()) sigmoid = ROOT.TF1("func", "(1.0/(1+ TMath::Exp(-[0]*(x-[1]))))", xmin, ratio_axis.GetXaxis().GetXmax()) sigmoid.SetParameters(0.01, xAve) inputHists[0][0].Fit(sigmoid,"q") @@ -236,9 +236,9 @@ def drawComp(name,inputHists,yTitle,xTitle,outDir,otherText="",setLogy=1,yMax= 1 sigmoid.SetLineColor(ROOT.kRed) sigmoid.Draw("same") - print hInfo[0].GetName(),":", - print sigmoid.GetParameter(0), - print sigmoid.GetParameter(1) + print( hInfo[0].GetName(),":", ) + print( sigmoid.GetParameter(0),) + print( sigmoid.GetParameter(1) ) textFits = [] for i in range(2): @@ -405,7 +405,6 @@ def drawCompRatioGraphs(name,inputHists,ratioHistBinning,yTitle,xTitle,outDir,ot yWidth = 0 for hInfo in inputHists: yWidth += 0.06 - print hInfo[1] legInfo.append((hInfo[0],"#scale[0.7]]{"+hInfo[1]+"}","LP")) #leg = getLegend([(effHist,"#scale[0.7]]{Data}","PE"),(effHistMC,"#scale[0.7]{t#bar{t} MC}","PE")], xStart=0.2, xWidth=0.3, yStart=0.6, yWidth=0.16) leg = getLegend(legInfo, xStart=xLeg, xWidth=0.3, yStart=yLeg-yWidth, yWidth=yWidth) diff --git a/plotting/MakeOffToOffComparison.py b/plotting/MakeOffToOffComparison.py new file mode 100644 index 0000000..bf57aa4 --- /dev/null +++ b/plotting/MakeOffToOffComparison.py @@ -0,0 +1,138 @@ +import ROOT + + +ROOT.gROOT.SetBatch(True) +ROOT.gErrorIgnoreLevel = ROOT.kWarning + + +import sys +sys.path.insert(0, '../../') +import ROOTHelp.FancyROOTStyle + +from JetLevelPlotUtils import makeEff, drawComp # , drawStackCompRatio, makeStack, makeInverseTurnOn, make2DComp, makeInverseTurnOnAll,plotRatio + +def getOpts(): + from optparse import OptionParser + p = OptionParser() + #p.add_option('--inputData', type = 'string', dest = 'inFileData', help = 'intput File' ) + p.add_option('--inputFile', type = 'string', help = 'intput File' ) + p.add_option('--outDir', type = 'string', help = 'output dir' ) + p.add_option('--labName', type = 'string', default = "Reference,Monitored", help = '' ) + #p.add_option('--doAlgoStudy', action="store_true" ) + (o,a) = p.parse_args() + + return o, a + + +def doTrackEffs(): + + + # + # Offline Turnon curves: + # + #effBinning=5 + vars = [ + "phi" , + "Chi2", + "DecayLenVal" , + "DecayLenVal_l" , + "DeltaR" , + "DeltaR_l" , + "Eta" , + "EtaRel" , + "HasInnerPixHit", + "IsFromSV" , + "IsFromV0" , + "JetDistVal" , + "Momentum" , + "NPixelHits" , + "NStripHits" , + "NTotalHits" , + "PPar" , + "PParRatio" , + "PV" , + "PVweight" , + "Phi" , + "PtRatio" , + "PtRel" , + "Pt_logx" , + "pt_s" , + "pt_m" , + "SV" , + "SVweight" , + "algo" , + "origAlgo" , + "charge" , + "eta" , + "ip2d" , + "ip2d_err" , + "ip2d_err_l" , + "ip2d_l" , + "ip2d_sig" , + "ip2d_sig_l" , + "ip3d" , + "ip3d_err" , + "ip3d_err_l" , + "ip3d_l" , + "ip3d_sig" , + "ip3d_sig_l" , + ] + + + + for v in vars: + binning = 1 + + eff_Matched_Ref = makeEff(v , ["offTracks_matched","offTracks"],inFileMC,binning=binning) + eff_Matched_Mon = makeEff(v , ["pfTracks_matched","pfTracks"],inFileMC,binning=binning) + + vBtag = "track"+v + if v=="phi": vBtag = "trackPhi" + if v=="eta": vBtag = "trackEta" + + yLeg = 0.93 + xLeg = 0.5 + + drawComp("Eff_"+v,[(eff_Matched_Ref,labName[0],ROOT.kBlack), + # (eff_Matched_noV0,"t#bar{t} MC (After V0 veto)",ROOT.kRed), + (eff_Matched_Mon,labName[1],ROOT.kRed), + #(eff_Matched_BTag,"t#bar{t} MC ",ROOT.kBlue), + #(eff_Matched_BTag_noV0,"t#bar{t} MC ",ROOT.kGreen) + ] + ,yTitle="Online Track Efficiency Relative to Offline",xTitle=eff_Matched_Ref.GetXaxis().GetTitle(),outDir=o.outDir,yMax=1.2,yLeg=yLeg,xLeg=xLeg, + xMax=eff_Matched_Ref.GetXaxis().GetXmax(), + xMin=eff_Matched_Ref.GetXaxis().GetXmin() + ) + + + + + fake_Matched_Ref = makeEff(v , ["pfTracks_unmatched","pfTracks"], inFileMC,binning=1) + fake_Matched_Mon = makeEff(v , ["offTracks_unmatched","offTracks"],inFileMC,binning=1) + drawComp("Fake_"+v,[(fake_Matched_Ref,labName[0],ROOT.kBlack), + (fake_Matched_Mon,labName[1],ROOT.kRed), + ] + ,yTitle="Online Track Fake-Rate Relative to Offline",xTitle=fake_Matched_Mon.GetXaxis().GetTitle(),outDir=o.outDir,yMax=0.4,yLeg=0.9,xLeg=0.6, + xMax=fake_Matched_Mon.GetXaxis().GetXmax(), + xMin=fake_Matched_Mon.GetXaxis().GetXmin() + ) + + + + + + +if __name__ == "__main__": + o, a = getOpts() + + labName = o.labName.split(",") + + #inFileData = ROOT.TFile(o.inFileData, "READ") + inFileMC = ROOT.TFile(o.inputFile, "READ") + + import os + if not os.path.exists(o.outDir): + os.makedirs(o.outDir) + + + doTrackEffs() diff --git a/plotting/OffToOffPlots.py b/plotting/OffToOffPlots.py new file mode 100644 index 0000000..c575a7c --- /dev/null +++ b/plotting/OffToOffPlots.py @@ -0,0 +1,208 @@ +#import sys +#sys.path.insert(0, '../../') +#import ROOTHelp.FancyROOTStyle + +#from iPlotLoadPath import loadPath +#loadPath() + + +from iUtils import getPM, setBatch, plot +from Rebinning import rebinningDB +setBatch() + +from iUtils import parseOpts as parseOpts +(options, args) = parseOpts() +pm = getPM(options) + +print options.labName +labName = options.labName.split(",") +print labName + + + + + +# +# Logy +# + +for v in ["tracks/ip3d_sig", + "tracks/ip2d_sig", + "DeepCSV_l", + "deepFlavB", + + "btags/sv_Flight2D", + "btags/sv_FlightSig2D", + "btags/sv_FlightSig", + "btags/sv_Flight", + "btags/flightDistance2dSig", + "btags/flightDistance2dVal", + "btags/flightDistance3dSig", + "btags/flightDistance3dVal", + "tracks/ip2d", + "tracks/ip2d_l", + "tracks/ip2d_sig", + "tracks/ip2d_sig_l", + "tracks/ip3d", + "tracks/ip3d_l", + "tracks/ip3d_sig", + "tracks/ip3d_sig_l", + "tracks/pt_s", + + "btags/ip2d", + "btags/ip2d_l", + "btags/ip2d_sig", + "btags/ip2d_sig_l", + "btags/ip3d", + "btags/ip3d_l", + "btags/ip3d_sig", + "btags/ip3d_sig_l", + + "pt_s", + "pt_m", + #"trackJetPt", + # "trackSip2dSigAboveCharm", + # "trackSip2dValAboveCharm", + # "trackSip3dSigAboveCharm", + # "trackSip3dValAboveCharm", + # "trackSumJetDeltaR", + #"vertexFitProb", + + "tracks/PtRel" , + "tracks/PtRatio" , + "tracks/PPar" , + "tracks/PParRatio" , + "tracks/Momentum" , + "tracks/DecayLenVal_l" , + "tracks/DecayLenVal" , + "tracks/algo", + "tracks/origAlgo", + + "btags/sv_Pt", + ]: + + vName = v.split("/")[-1] + if vName in rebinningDB: + binning = rebinningDB[vName] + else: + binning = 1 + + try: + plot(v,["offJets_matchedJet","offJets_matched"],binning=binning,doratio=1,labels=["Monitored","Reference"],rMax=1.2,rMin=0.8,logy=1) + except: + print "failed",v + import sys + sys.exit(-1) + +# +# No Logy +# +for v in [ + "tracks/eta", + "tracks/ip2d_err", + "tracks/ip2d_err_l", + "tracks/ip3d_err", + "tracks/ip3d_err_l", + + # "neMult", + "phi", + "eta", + + "btags/sv_BoostOverSqrtJetPt", + "btags/vertexEnergyRatio", + "btags/sv_EnergyRatio", + "btags/sv_Eta", + "btags/sv_NDF", + "btags/sv_Phi", + "btags/sv_R", + "btags/sv_Z", + "btags/sv_massVertexEnergyFraction", + "btags/sv_Chi2", + "btags/vertexJetDeltaR", + "btags/sv_JetDeltaR", + "btags/sv_DistJetAxis", + + + "tracks/JetDistVal" , + + "tracks/eta" , + "tracks/phi" , + + "tracks/DeltaR" , + "btags/etaRel" , + + #"mult", + #"nTrk", + "btags/jetNTracksEtaRel", + + "btags/chargedHadronMultiplicity", + "btags/chargedMultiplicity", + "btags/elecMultiplicity", + "btags/muonMultiplicity", + "btags/neutralHadronMultiplicity", + "btags/neutralMultiplicity", + "btags/photonMultiplicity", + "btags/totalMultiplicity", + + "btags/vertexCategory", + "btags/sv_Mass", + "btags/vertexMass", + "tracks/Chi2", + + ]: + + vName = v.split("/")[-1] + if vName in rebinningDB: + binning = rebinningDB[vName] + else: + binning = 2 + + try: + plot(v,["offJets_matchedJet","offJets_matched"],binning=binning,doratio=1,labels=["Monitored","Reference"],rMax=1.2,rMin=0.8,logy=0) + except: + print "failed",v + import sys + sys.exit(-1) + + + + +# +# No Rebin +# +for v in [ + "btags/chargedEmEnergyFraction", + "btags/chargedHadronEnergyFraction", + "btags/elecEnergyFraction", + "btags/muonEnergyFraction", + "btags/neutralEmEnergyFraction", + "btags/neutralHadronEnergyFraction", + "btags/photonEnergyFraction", + "btags/sv_nSVs", + #"jetNSelectedTracks", + "tracks/HasInnerPixHit", + "tracks/NPixelHits", + "tracks/NTotalHits", + "tracks/NStripHits", + + "tracks/nTracks", + #"btags_noV0/nTracks", + "btags/vertexNTracks", + "btags/sv_NTracks", + #"ip2d", + + + "tracks/IsFromV0", + "tracks/IsFromSV", + # "neutralHadronEnergyFraction", + # "trackSumJetEtRatio", + ]: + + try: + plot(v,["offJets_matchedJet","offJets_matched"],doratio=1,labels=["Monitored","Reference"],rMax=1.2,rMin=0.8,logy=0) + except: + print "failed",v + import sys + sys.exit(-1) + + diff --git a/plotting/OffvsOff_BvL.py b/plotting/OffvsOff_BvL.py new file mode 100644 index 0000000..1d0d7c0 --- /dev/null +++ b/plotting/OffvsOff_BvL.py @@ -0,0 +1,543 @@ +import ROOT + + +ROOT.gROOT.SetBatch(True) +ROOT.gErrorIgnoreLevel = ROOT.kWarning + +import ROOTHelp.FancyROOTStyle + +from optparse import OptionParser +p = OptionParser() +p.add_option('--input', type = 'string', default = "outBTag.FTKBtagging.ttbar.mwt2.All.root", dest = 'inFile', help = 'intput File' ) +p.add_option('--output', type = 'string', default = "makeRocCurves", dest = 'outDir', help = 'output dir' ) +p.add_option('--cmsText', type = 'string', default = "Work in Progress", help = '' ) +p.add_option('--labName', type = 'string', default = "Reference,Monitored", help = '' ) +#p.add_option('--lumiText', default = "", help = '' ) +(o,a) = p.parse_args() + + + +from ROOTHelp.Utils import do_variable_rebinning, makeCanvas +from ROOTHelp.Plotting import makeRatio +#from rocCurveUtils import drawWaterMarks +#import rebinning +from Rebinning import rebinningDB + +from JetLevelPlotUtils import getCMSText + +inFile = ROOT.TFile(o.inFile, "READ") + +labName = o.labName.split(",") + +import os +if not os.path.exists(o.outDir): + os.makedirs(o.outDir) + + +maxDict = {"jetNSelectedTracks":20, + "jetNTracks":30, + } + + +def getHist(inFile,dir,var,binning,color): + hist = inFile.Get(dir+"/"+var) + print( dir+"/"+var) + if type(binning ) == type(list()): + hist = do_variable_rebinning(hist,binning) + else: + hist.Rebin(binning) + + hist.SetLineColor(color) + hist.SetMarkerColor(color) + hist.Sumw2() + if hist.Integral(): + hist.Scale(1./hist.Integral()) + return hist + + + +def doVarRatioPlot(var, offLF, hltLF, offBQ, hltBQ, xTitle, setLogy=1, minX=None, maxX=None, minY=None, yAxisSF=1.0): + maxY = max(offLF.GetMaximum(),offBQ.GetMaximum(), + hltLF.GetMaximum(),hltBQ.GetMaximum()) + + maxY = maxY*yAxisSF + if setLogy: + offLF.SetMaximum(4e0*maxY) + offLF.SetMinimum(1.01e-5) + else: + offLF.SetMaximum(1.2*maxY) + + if not minY == None : + offLF.SetMinimum(minY) + + + offLF.GetYaxis().SetTitle("Normalized") + offLF.GetXaxis().SetTitle(xTitle ) + + if maxX: + offLF.GetXaxis().SetRangeUser(minX,maxX) + offBQ.GetXaxis().SetRangeUser(minX,maxX) + hltLF.GetXaxis().SetRangeUser(minX,maxX) + hltBQ.GetXaxis().SetRangeUser(minX,maxX) + + + LFRatio = makeRatio(num = hltLF.Clone(), den = offLF.Clone()) + BQRatio = makeRatio(num = hltBQ.Clone(), den = offBQ.Clone()) + + xpos = 0.5 + ypos = 0.675 + xwidth = 0.4 + ywidth = 0.2 + + leg = ROOT.TLegend(xpos, ypos, xpos+xwidth, ypos+ywidth) + leg.SetNColumns(1) + leg.AddEntry(offBQ,labName[0]+" b-jets","L") + leg.AddEntry(offLF,labName[0]+" light-flavor","L") + leg.AddEntry(hltBQ,labName[1]+" b-jets" ,"PEL") + leg.AddEntry(hltLF,labName[1]+" light-flavor" ,"PEL") + + canvas = makeCanvas(var, var, width=600, height=600) + split=0.3 + top_pad = ROOT.TPad("pad1", "The pad 80% of the height",0,split,1,1,0) + bottom_pad = ROOT.TPad("pad2", "The pad 20% of the height",0,0,1,split,0) + top_pad.Draw() + bottom_pad.Draw() + + axissep = 0.02 + top_pad.cd() + top_pad.SetLogy(setLogy) + top_pad.SetTopMargin(canvas.GetTopMargin()*1.0/(1.0-split)) + top_pad.SetBottomMargin(0.5*axissep) + top_pad.SetRightMargin(canvas.GetRightMargin()) + top_pad.SetLeftMargin(canvas.GetLeftMargin()); + top_pad.SetFillStyle(0) # transparent + top_pad.SetBorderSize(0) + + if var in maxDict.keys(): + offLF.GetXaxis().SetRangeUser(offLF.GetXaxis().GetXmin(),maxDict[var] ) + + offLF.Draw("hist") + # hltLF.SetMarkerSize(0.75) + hltLF.SetMarkerSize(0.5) + #hltLF.SetMarkerStyle(21) + hltLF.Draw("same pe") + offBQ.Draw("hist same") + hltBQ.SetMarkerSize(0.5) + #hltBQ.SetMarkerStyle(21) + hltBQ.Draw("same pe") + leg.Draw("same") + + + + + + + cmsLines = getCMSText(xStart=0.2,yStart=0.85,subtext=o.cmsText) + for cmsl in cmsLines: + cmsl.Draw("same") + + + + bottom_pad.cd() + bottom_pad.SetTopMargin(2*axissep) + bottom_pad.SetBottomMargin(canvas.GetBottomMargin()*1.0/split) + bottom_pad.SetRightMargin(canvas.GetRightMargin()) + bottom_pad.SetLeftMargin(canvas.GetLeftMargin()); + bottom_pad.SetFillStyle(0) # transparent + bottom_pad.SetBorderSize(0) + ratio_axis = offLF.Clone() + ratio_axis.GetYaxis().SetTitle("Ratio") + ratio_axis.GetXaxis().SetTitle(offLF.GetXaxis().GetTitle()) + ratio_axis.GetYaxis().SetNdivisions(507) + rMin = 0.5 + rMax = 1.5 + + + if var in maxDict.keys(): + LFRatio.GetXaxis().SetRangeUser(LFRatio.GetXaxis().GetXmin(),maxDict[var] ) + + ratio_axis.GetYaxis().SetRangeUser(rMin, rMax) + LFRatio.GetYaxis().SetRangeUser(rMin, rMax) + LFRatio.GetYaxis().SetTitle("Ratio") + + + LFRatio.Draw("PE") + LFRatio.Draw("PE same") + # oldSize = LFRatio.GetMarkerSize() + oldSize = hltLF.GetMarkerSize() + LFRatio.SetMarkerSize(0) + LFRatio.DrawCopy("same e0") + LFRatio.SetMarkerSize(oldSize) + LFRatio.Draw("PE same") + + + BQRatio.Draw("PE same") + BQRatio.Draw("PE same") + # oldSize = BQRatio.GetMarkerSize() + oldSize = hltBQ.GetMarkerSize() + BQRatio.SetMarkerSize(0) + BQRatio.DrawCopy("same e0") + BQRatio.SetMarkerSize(oldSize) + BQRatio.Draw("PE same") + + + + line = ROOT.TLine() + line.DrawLine(offLF.GetXaxis().GetXmin(), 1.0, offLF.GetXaxis().GetXmax(), 1.0) + + ndivs=[505,503] + + pads = [top_pad, bottom_pad] + factors = [0.8/(1.0-split), 0.7/split] + for i_pad, pad in enumerate(pads): + + factor = factors[i_pad] + ndiv = ndivs[i_pad] + + prims = [ p.GetName() for p in pad.GetListOfPrimitives() ] + + # + # Protection for scaling hists multiple times + # + procedHist = [] + + for name in prims: + + if name in procedHist: continue + procedHist.append(name) + + h = pad.GetPrimitive(name) + if isinstance(h, ROOT.TH1) or isinstance(h, ROOT.THStack) or isinstance(h, ROOT.TGraph) or isinstance(h, ROOT.TGraphErrors) or isinstance(h, ROOT.TGraphAsymmErrors): + if isinstance(h, ROOT.TGraph) or isinstance(h, ROOT.THStack) or isinstance(h, ROOT.TGraphErrors) or isinstance(h, ROOT.TGraphAsymmErrors): + h = h.GetHistogram() + #print "factor is",factor,h.GetName(),split + + if i_pad == 1: + h.SetLabelSize(h.GetLabelSize('Y')*factor, 'Y') + h.SetTitleSize(h.GetTitleSize('X')*factor, 'X') + h.SetTitleSize(h.GetTitleSize('Y')*factor, 'Y') + h.SetTitleOffset(h.GetTitleOffset('Y')/factor, 'Y') + + if i_pad == 1: + h.GetYaxis().SetNdivisions(ndiv) + h.GetXaxis().SetNdivisions() + if i_pad == 0: + h.SetLabelSize(0.0, 'X') + h.GetXaxis().SetTitle("") + else: + h.SetLabelSize(h.GetLabelSize('X')*factor, 'X') + ## Trying to remove overlapping y-axis labels. Doesn't work. + # h.GetYaxis().Set(4, h.GetYaxis().GetXmin(), h.GetYaxis().GetXmax()) + # h.GetYaxis().SetBinLabel( h.GetYaxis().GetLast(), '') + + + + + + ##xatlas, yatlas = 0.18, 0.88 + ##atlas = ROOT.TLatex(xatlas+0.01, yatlas, "ATLAS") + ###simulation = ROOT.TLatex(xatlas+0.11, yatlas, "Simulation Internal") + ##simulation = ROOT.TLatex(xatlas+0.11, yatlas, "Simulation Preliminary") + ##lumi = ROOT.TLatex(xatlas+0.01, yatlas-0.05, "#sqrt{s}=13 TeV, t#bar{t}") + ##jetText = ROOT.TLatex(xatlas+0.02, yatlas-0.1, "p_{T}^{jet} > 40 GeV, |#eta^{jet}| < 2.5" ) + ##wm = [atlas, simulation, lumi, jetText] + + #watermarks = drawWaterMarks(wm) + + #varName = var.replace("tracks/","").replace("btags/","btags_") + varName = var.replace("tracks/","track_").replace("btags/","btag_").replace("btags_noV0/","btag_noV0_") + varName = varName.replace("tracks_innerPixHit/","track_innerPixHit_").replace("tracks_noInnerPixHit/","track_noInnerPixHit_") + canvas.SaveAs(o.outDir+"/BvL_"+varName+".pdf") + #canvas.SaveAs(o.outDir+"/"+var+".eps") + #canvas.SaveAs(o.outDir+"/"+var+".png") + + + +def doVarRatio(var, binning, xTitle, setLogy=1, minX=None, maxX=None, minY=None, yAxisSF=1.0): + offLF = getHist(inFile,"offJets_matched_L", var,binning,ROOT.kBlack) + hltLF = getHist(inFile,"offJets_matchedJet_L",var,binning,ROOT.kBlack) + offBQ = getHist(inFile,"offJets_matched_B", var,binning,ROOT.kRed) + hltBQ = getHist(inFile,"offJets_matchedJet_B",var,binning,ROOT.kRed) + doVarRatioPlot(var, offLF, hltLF, offBQ, hltBQ, xTitle=xTitle, setLogy=setLogy, minX=minX, maxX=maxX, minY=minY, yAxisSF=yAxisSF) + +def doVarRatioInnerPixel(var, binning, xTitle, setLogy=1, minX=None, maxX=None, minY=None, yAxisSF=1.0): + offLF = getHist(inFile,"offJets_matched_L/tracks_innerPixHit", var,binning,ROOT.kBlack) + hltLF = getHist(inFile,"offJets_matched_L/tracks_noInnerPixHit", var,binning,ROOT.kBlack) + offBQ = getHist(inFile,"offJets_matched_B/tracks_innerPixHit", var,binning,ROOT.kRed) + hltBQ = getHist(inFile,"offJets_matched_B/tracks_noInnerPixHit",var,binning,ROOT.kRed) + doVarRatioPlot(var+"_compInnerPix", offLF, hltLF, offBQ, hltBQ, xTitle=xTitle, setLogy=setLogy, minX=minX, maxX=maxX, minY=minY, yAxisSF=yAxisSF) +# doVarRatioPlot(offLF, hltLF, offBQ, hltBQ, xTitle, setLogy=1, minX=None, maxX=None, minY=None, yAxisSF=1.0) + + +#doVar("ip3d_sig_l", +# xTitle = "ip3d significance", +# #binning = [-20,-18,-16,-14,-12,-11,-10,-8,-6,-5,-4,-3,-2.5,-2,-1.5,-1,-0.5,0,0.5,1,1.5,2,2.5,3,4,5,6,8,10,11,12,14,16,18,20,22,24,28,32,36,40] +# binning = [-100 , -90,-80 , -70 , -60 , -50 , -40 , -34 , -32 , -30 , -28 , -26 , -24 , -22 , -20 , -18 , -16 , -14 , -12 , -10 , -8 , -6 , -4 , -2 , 0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 , 18 , 20 , 22 , 24 , 26 , 28 , 30 , 32 , 34 , 40 , 50 , 60 , 70 , 80, 90 , 100] +# #binning = [-100,-90,-80,-70,-60,-50,-40,-30,-20,-10,-5,0,5,10,15,20,30,40,50,60,70,80,90,100] +# ) + +for v in ["tracks/ip3d_sig", + "tracks/ip2d_sig", + # "CSVv2_l", + "DeepCSV_l", + "deepFlavB", + "Bprob", + "Proba", + "Svx", + "SvxHP", + "Ip2P", + "Ip3P", + "Ip2P_l", + "Ip3P_l", + + #"deepcsv_bb", + "btags/sv_Flight2D", + "btags/sv_FlightSig2D", + "btags/sv_FlightSig", + "btags/sv_Flight", + "tracks/ip2d", + "tracks/ip2d_l", + "tracks/ip2d_sig", + "tracks/ip2d_sig_l", + "tracks/ip3d", + "tracks/ip3d_l", + "tracks/ip3d_sig", + "tracks/ip3d_sig_l", + + + "tracks_innerPixHit/ip2d", + "tracks_innerPixHit/ip2d_l", + "tracks_innerPixHit/ip2d_sig", + "tracks_innerPixHit/ip2d_sig_l", + "tracks_innerPixHit/ip3d", + "tracks_innerPixHit/ip3d_l", + "tracks_innerPixHit/ip3d_sig", + "tracks_innerPixHit/ip3d_sig_l", + + "tracks_noInnerPixHit/ip2d", + "tracks_noInnerPixHit/ip2d_l", + "tracks_noInnerPixHit/ip2d_sig", + "tracks_noInnerPixHit/ip2d_sig_l", + "tracks_noInnerPixHit/ip3d", + "tracks_noInnerPixHit/ip3d_l", + "tracks_noInnerPixHit/ip3d_sig", + "tracks_noInnerPixHit/ip3d_sig_l", + + "tracks/pt_s", + # "tracks/dz", + # "tracks/dxy", + + "btags/ip2d", + "btags/ip2d_l", + "btags/ip2d_sig", + "btags/ip2d_sig_l", + "btags/ip3d", + "btags/ip3d_l", + "btags/ip3d_sig", + "btags/ip3d_sig_l", + +# "btags_noV0/ip2d", +# "btags_noV0/ip2d_l", +# "btags_noV0/ip2d_sig", +# "btags_noV0/ip2d_sig_l", +# "btags_noV0/ip3d", +# "btags_noV0/ip3d_l", +# "btags_noV0/ip3d_sig", +# "btags_noV0/ip3d_sig_l", + + + "btags/trackPt", + "btags/trackEta", + "btags/trackPhi", + "btags/trackNPixelHits", + "btags/trackNTotalHits", + + "eta", + + "pt_s", + "pt_m", + "phi", + "nJets", + "DeepCSVb_l", + "DeepCSVbb_l", +# "DeepJetb_l", +# "DeepJetbb_l", +# "DeepJetlepb_l", + #"trackJetPt", + #"trackSip2dSigAboveCharm", + #"trackSip2dValAboveCharm", + #"trackSip3dSigAboveCharm", + #"trackSip3dValAboveCharm", + #"trackSumJetDeltaR", + #"vertexFitProb", + + "tracks/PtRel" , + "tracks/PtRatio" , + "tracks/PPar" , + "tracks/PParRatio" , + "tracks/Momentum" , + "tracks/DecayLenVal_l" , + "tracks/DecayLenVal" , + "tracks/algo", + "tracks/origAlgo", + + "btags/sv_Pt", + + ]: + + vName = v.split("/")[-1] + if vName in rebinningDB: + binning = rebinningDB[vName] + else: + binning = 2 + + doVarRatio(v, + xTitle = v, + binning = binning, + yAxisSF = 100 + ) + + + + +for v in [ + "tracks/eta", + "tracks/ip2d_err", + "tracks/ip2d_err_l", + "tracks/ip3d_err", + "tracks/ip3d_err_l", +# "neMult", + "eta", + + "phi", + "btags/sv_BoostOverSqrtJetPt", + "btags/sv_EnergyRatio", + "btags/sv_Eta", + "btags/sv_NDF", + "btags/sv_Phi", + "btags/sv_R", + "btags/sv_Z", + "btags/sv_massVertexEnergyFraction", + "btags/sv_Chi2", + "btags/sv_JetDeltaR", + "btags/sv_DistJetAxis", + "tracks/JetDistVal" , + "tracks/eta" , + "tracks/phi" , + "tracks/DeltaR" , + #"trackEtaRel" , + #"jetNSelectedTracks", + #"mult", + # "nTrk", + #"jetNTracksEtaRel", + + "btags/chargedHadronMultiplicity", + "btags/chargedMultiplicity", + "btags/elecMultiplicity", + "btags/muonMultiplicity", + "btags/neutralHadronMultiplicity", + "btags/neutralMultiplicity", + "btags/photonMultiplicity", + "btags/totalMultiplicity", + + #"vertexCategory", + #"ip2d", + "tracks/Chi2", + ]: + + + vName = v.split("/")[-1] + if vName in rebinningDB: + binning = rebinningDB[vName] + else: + binning = 2 + + + doVarRatio(v, + xTitle = v, + binning = binning, + setLogy = 0, + yAxisSF = 1.25 + ) + + + + +for v in [ + "tracks/HasInnerPixHit", + "tracks/NPixelHits", + "tracks/NTotalHits", + "tracks/NStripHits", + "btags/sv_nSVs", + "tracks/nTracks", +# "btags_noV0/nTracks", + "btags/nTracks", + "btags/sv_NTracks", + ]: + + doVarRatio(v, + xTitle = v, + binning = 1, + setLogy = 0, + yAxisSF = 1.25 + ) + + +for v in [ + "btags/chargedEmEnergyFraction", + "btags/chargedHadronEnergyFraction", + "btags/elecEnergyFraction", + "btags/muonEnergyFraction", + "btags/neutralEmEnergyFraction", + "btags/neutralHadronEnergyFraction", + "btags/photonEnergyFraction", + + "tracks/IsFromV0", + "tracks/IsFromSV", + # "btags/trackIsFromV0", + # "btags_noV0/trackIsFromV0", + # "btags/trackIsFromSV", + # "btags_noV0/trackIsFromSV", + # "neutralHadronEnergyFraction", + # "trackSumJetEtRatio", + ]: + doVarRatio(v, + xTitle = v, + binning = 1, + setLogy = 0, + minY = 0, + yAxisSF = 1.25 + ) + +# +# +#for v in [ +# "muonEnergyFraction", +# "muEF", +# +# ]: +# doVarRatio(v, +# xTitle = v, +# binning = 1, +# setLogy = 1, +# ) +# +for v in [ + "btags/sv_Mass", + "m", + ]: + doVarRatio(v, + xTitle = v, + binning = 1, + setLogy = 0, + minX = 0, + maxX = 15 + ) + + + +#doVar("trk_z0Sig_signed", +# xTitle = "z_{0} Significance", +# #binning = [-25,-20,-18,-14,-10,-8,-6,-5,-4,-3,-2.5,-2,-1.5,-1,-0.5,0,0.5,1,1.5,2,2.5,3,4,5,6,8,10,12,14,16,18,20,24,25] +# binning = [-12,-10,-8,-6,-5,-4,-3,-2.5,-2,-1.5,-1,-0.5,0,0.5,1,1.5,2,2.5,3,4,5,6,8,10,12,15,20] +# ) diff --git a/plotting/innerHitvsNoInnerHit.py b/plotting/innerHitvsNoInnerHit.py new file mode 100644 index 0000000..7778a04 --- /dev/null +++ b/plotting/innerHitvsNoInnerHit.py @@ -0,0 +1,302 @@ +import ROOT + + +ROOT.gROOT.SetBatch(True) +ROOT.gErrorIgnoreLevel = ROOT.kWarning + +import ROOTHelp.FancyROOTStyle + +from optparse import OptionParser +p = OptionParser() +p.add_option('--input', type = 'string', default = "outBTag.FTKBtagging.ttbar.mwt2.All.root", dest = 'inFile', help = 'intput File' ) +p.add_option('--output', type = 'string', default = "makeRocCurves", dest = 'outDir', help = 'output dir' ) +p.add_option('--cmsText', type = 'string', default = "Work in Progress", help = '' ) +p.add_option('--labName', type = 'string', default = "Reference,Monitored", help = '' ) +#p.add_option('--lumiText', default = "", help = '' ) +(o,a) = p.parse_args() + + + +from ROOTHelp.Utils import do_variable_rebinning, makeCanvas +from ROOTHelp.Plotting import makeRatio +#from rocCurveUtils import drawWaterMarks +#import rebinning +from Rebinning import rebinningDB + +from JetLevelPlotUtils import getCMSText + +inFile = ROOT.TFile(o.inFile, "READ") + +labName = o.labName.split(",") + +import os +if not os.path.exists(o.outDir): + os.makedirs(o.outDir) + + +maxDict = {"jetNSelectedTracks":20, + "jetNTracks":30, + } + + +def getHist(inFile,dir,var,binning,color): + hist = inFile.Get(dir+"/"+var) + print( dir+"/"+var) + if type(binning ) == type(list()): + hist = do_variable_rebinning(hist,binning) + else: + hist.Rebin(binning) + + hist.SetLineColor(color) + hist.SetMarkerColor(color) + hist.Sumw2() + if hist.Integral(): + hist.Scale(1./hist.Integral()) + return hist + + + + +def doVarRatioPlot(var, offLF, hltLF, offBQ, hltBQ, xTitle, setLogy=1, minX=None, maxX=None, minY=None, yAxisSF=1.0): + maxY = max(offLF.GetMaximum(),offBQ.GetMaximum(), + hltLF.GetMaximum(),hltBQ.GetMaximum()) + + maxY = maxY*yAxisSF + if setLogy: + offLF.SetMaximum(4e0*maxY) + offLF.SetMinimum(1.01e-5) + else: + offLF.SetMaximum(1.2*maxY) + + if not minY == None : + offLF.SetMinimum(minY) + + + offLF.GetYaxis().SetTitle("Normalized") + offLF.GetXaxis().SetTitle(xTitle ) + + if maxX: + offLF.GetXaxis().SetRangeUser(minX,maxX) + offBQ.GetXaxis().SetRangeUser(minX,maxX) + hltLF.GetXaxis().SetRangeUser(minX,maxX) + hltBQ.GetXaxis().SetRangeUser(minX,maxX) + + + LFRatio = makeRatio(num = hltLF.Clone(), den = offLF.Clone()) + BQRatio = makeRatio(num = hltBQ.Clone(), den = offBQ.Clone()) + + xpos = 0.5 + ypos = 0.675 + xwidth = 0.4 + ywidth = 0.2 + + leg = ROOT.TLegend(xpos, ypos, xpos+xwidth, ypos+ywidth) + leg.SetNColumns(1) + leg.AddEntry(offBQ,"inner Pix Hit b-jets","L") + leg.AddEntry(offLF,"inner Pix Hit light-flavor","L") + leg.AddEntry(hltBQ,"no Inner Pix Hit b-jets" ,"PEL") + leg.AddEntry(hltLF,"no Inner Pix Hit light-flavor" ,"PEL") + + canvas = makeCanvas(var, var, width=600, height=600) + split=0.3 + top_pad = ROOT.TPad("pad1", "The pad 80% of the height",0,split,1,1,0) + bottom_pad = ROOT.TPad("pad2", "The pad 20% of the height",0,0,1,split,0) + top_pad.Draw() + bottom_pad.Draw() + + axissep = 0.02 + top_pad.cd() + top_pad.SetLogy(setLogy) + top_pad.SetTopMargin(canvas.GetTopMargin()*1.0/(1.0-split)) + top_pad.SetBottomMargin(0.5*axissep) + top_pad.SetRightMargin(canvas.GetRightMargin()) + top_pad.SetLeftMargin(canvas.GetLeftMargin()); + top_pad.SetFillStyle(0) # transparent + top_pad.SetBorderSize(0) + + if var in maxDict.keys(): + offLF.GetXaxis().SetRangeUser(offLF.GetXaxis().GetXmin(),maxDict[var] ) + + offLF.Draw("hist") + # hltLF.SetMarkerSize(0.75) + hltLF.SetMarkerSize(0.5) + #hltLF.SetMarkerStyle(21) + hltLF.Draw("same pe") + offBQ.Draw("hist same") + hltBQ.SetMarkerSize(0.5) + #hltBQ.SetMarkerStyle(21) + hltBQ.Draw("same pe") + leg.Draw("same") + + + + + + + cmsLines = getCMSText(xStart=0.2,yStart=0.85,subtext=o.cmsText) + for cmsl in cmsLines: + cmsl.Draw("same") + + + + bottom_pad.cd() + bottom_pad.SetTopMargin(2*axissep) + bottom_pad.SetBottomMargin(canvas.GetBottomMargin()*1.0/split) + bottom_pad.SetRightMargin(canvas.GetRightMargin()) + bottom_pad.SetLeftMargin(canvas.GetLeftMargin()); + bottom_pad.SetFillStyle(0) # transparent + bottom_pad.SetBorderSize(0) + ratio_axis = offLF.Clone() + ratio_axis.GetYaxis().SetTitle("Ratio") + ratio_axis.GetXaxis().SetTitle(offLF.GetXaxis().GetTitle()) + ratio_axis.GetYaxis().SetNdivisions(507) + rMin = 0.0 + rMax = 2.0 + + + if var in maxDict.keys(): + LFRatio.GetXaxis().SetRangeUser(LFRatio.GetXaxis().GetXmin(),maxDict[var] ) + + ratio_axis.GetYaxis().SetRangeUser(rMin, rMax) + LFRatio.GetYaxis().SetRangeUser(rMin, rMax) + LFRatio.GetYaxis().SetTitle("Ratio") + + + LFRatio.Draw("PE") + LFRatio.Draw("PE same") + # oldSize = LFRatio.GetMarkerSize() + oldSize = hltLF.GetMarkerSize() + LFRatio.SetMarkerSize(0) + LFRatio.DrawCopy("same e0") + LFRatio.SetMarkerSize(oldSize) + LFRatio.Draw("PE same") + + + BQRatio.Draw("PE same") + BQRatio.Draw("PE same") + # oldSize = BQRatio.GetMarkerSize() + oldSize = hltBQ.GetMarkerSize() + BQRatio.SetMarkerSize(0) + BQRatio.DrawCopy("same e0") + BQRatio.SetMarkerSize(oldSize) + BQRatio.Draw("PE same") + + + + line = ROOT.TLine() + line.DrawLine(offLF.GetXaxis().GetXmin(), 1.0, offLF.GetXaxis().GetXmax(), 1.0) + + ndivs=[505,503] + + pads = [top_pad, bottom_pad] + factors = [0.8/(1.0-split), 0.7/split] + for i_pad, pad in enumerate(pads): + + factor = factors[i_pad] + ndiv = ndivs[i_pad] + + prims = [ p.GetName() for p in pad.GetListOfPrimitives() ] + + # + # Protection for scaling hists multiple times + # + procedHist = [] + + for name in prims: + + if name in procedHist: continue + procedHist.append(name) + + h = pad.GetPrimitive(name) + if isinstance(h, ROOT.TH1) or isinstance(h, ROOT.THStack) or isinstance(h, ROOT.TGraph) or isinstance(h, ROOT.TGraphErrors) or isinstance(h, ROOT.TGraphAsymmErrors): + if isinstance(h, ROOT.TGraph) or isinstance(h, ROOT.THStack) or isinstance(h, ROOT.TGraphErrors) or isinstance(h, ROOT.TGraphAsymmErrors): + h = h.GetHistogram() + #print "factor is",factor,h.GetName(),split + + if i_pad == 1: + h.SetLabelSize(h.GetLabelSize('Y')*factor, 'Y') + h.SetTitleSize(h.GetTitleSize('X')*factor, 'X') + h.SetTitleSize(h.GetTitleSize('Y')*factor, 'Y') + h.SetTitleOffset(h.GetTitleOffset('Y')/factor, 'Y') + + if i_pad == 1: + h.GetYaxis().SetNdivisions(ndiv) + h.GetXaxis().SetNdivisions() + if i_pad == 0: + h.SetLabelSize(0.0, 'X') + h.GetXaxis().SetTitle("") + else: + h.SetLabelSize(h.GetLabelSize('X')*factor, 'X') + ## Trying to remove overlapping y-axis labels. Doesn't work. + # h.GetYaxis().Set(4, h.GetYaxis().GetXmin(), h.GetYaxis().GetXmax()) + # h.GetYaxis().SetBinLabel( h.GetYaxis().GetLast(), '') + + + + + + ##xatlas, yatlas = 0.18, 0.88 + ##atlas = ROOT.TLatex(xatlas+0.01, yatlas, "ATLAS") + ###simulation = ROOT.TLatex(xatlas+0.11, yatlas, "Simulation Internal") + ##simulation = ROOT.TLatex(xatlas+0.11, yatlas, "Simulation Preliminary") + ##lumi = ROOT.TLatex(xatlas+0.01, yatlas-0.05, "#sqrt{s}=13 TeV, t#bar{t}") + ##jetText = ROOT.TLatex(xatlas+0.02, yatlas-0.1, "p_{T}^{jet} > 40 GeV, |#eta^{jet}| < 2.5" ) + ##wm = [atlas, simulation, lumi, jetText] + + #watermarks = drawWaterMarks(wm) + + #varName = var.replace("tracks/","").replace("btags/","btags_") + varName = var.replace("tracks/","track_").replace("btags/","btag_").replace("btags_noV0/","btag_noV0_") + varName = varName.replace("tracks_innerPixHit/","track_innerPixHit_").replace("tracks_noInnerPixHit/","track_noInnerPixHit_") + canvas.SaveAs(o.outDir+"/BvL_"+varName+".pdf") + #canvas.SaveAs(o.outDir+"/"+var+".eps") + #canvas.SaveAs(o.outDir+"/"+var+".png") + + + +def doVarRatioInnerPixel(var, binning, xTitle, setLogy=1, minX=None, maxX=None, minY=None, yAxisSF=1.0): + offLF = getHist(inFile,"offJets_matched_L/tracks_innerPixHit", var,binning,ROOT.kBlack) + hltLF = getHist(inFile,"offJets_matched_L/tracks_noInnerPixHit", var,binning,ROOT.kBlack) + offBQ = getHist(inFile,"offJets_matched_B/tracks_innerPixHit", var,binning,ROOT.kRed) + hltBQ = getHist(inFile,"offJets_matched_B/tracks_noInnerPixHit",var,binning,ROOT.kRed) + doVarRatioPlot(var+"_compInnerPix", offLF, hltLF, offBQ, hltBQ, xTitle=xTitle, setLogy=setLogy, minX=minX, maxX=maxX, minY=minY, yAxisSF=yAxisSF) +# doVarRatioPlot(offLF, hltLF, offBQ, hltBQ, xTitle, setLogy=1, minX=None, maxX=None, minY=None, yAxisSF=1.0) + + +#doVar("ip3d_sig_l", +# xTitle = "ip3d significance", +# #binning = [-20,-18,-16,-14,-12,-11,-10,-8,-6,-5,-4,-3,-2.5,-2,-1.5,-1,-0.5,0,0.5,1,1.5,2,2.5,3,4,5,6,8,10,11,12,14,16,18,20,22,24,28,32,36,40] +# binning = [-100 , -90,-80 , -70 , -60 , -50 , -40 , -34 , -32 , -30 , -28 , -26 , -24 , -22 , -20 , -18 , -16 , -14 , -12 , -10 , -8 , -6 , -4 , -2 , 0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 , 18 , 20 , 22 , 24 , 26 , 28 , 30 , 32 , 34 , 40 , 50 , 60 , 70 , 80, 90 , 100] +# #binning = [-100,-90,-80,-70,-60,-50,-40,-30,-20,-10,-5,0,5,10,15,20,30,40,50,60,70,80,90,100] +# ) + +for v in [ + "ip2d", + "ip2d_l", + "ip2d_sig", + "ip2d_sig_l", + "ip3d", + "ip3d_l", + "ip3d_sig", + "ip3d_sig_l", + ]: + + vName = v.split("/")[-1] + if vName in rebinningDB: + binning = rebinningDB[vName] + else: + binning = 2 + + doVarRatioInnerPixel(v, + xTitle = v, + binning = binning, + yAxisSF = 100 + ) + + +#doVar("trk_z0Sig_signed", +# xTitle = "z_{0} Significance", +# #binning = [-25,-20,-18,-14,-10,-8,-6,-5,-4,-3,-2.5,-2,-1.5,-1,-0.5,0,0.5,1,1.5,2,2.5,3,4,5,6,8,10,12,14,16,18,20,24,25] +# binning = [-12,-10,-8,-6,-5,-4,-3,-2.5,-2,-1.5,-1,-0.5,0,0.5,1,1.5,2,2.5,3,4,5,6,8,10,12,15,20] +# ) + diff --git a/plotting/jetDeltaHists_BvL.py b/plotting/jetDeltaHists_BvL.py new file mode 100644 index 0000000..c00ee57 --- /dev/null +++ b/plotting/jetDeltaHists_BvL.py @@ -0,0 +1,284 @@ +import ROOT + + +ROOT.gROOT.SetBatch(True) +ROOT.gErrorIgnoreLevel = ROOT.kWarning + +import ROOTHelp.FancyROOTStyle + +from optparse import OptionParser +p = OptionParser() +p.add_option('--input', type = 'string', default = "outBTag.FTKBtagging.ttbar.mwt2.All.root", dest = 'inFile', help = 'intput File' ) +p.add_option('--output', type = 'string', default = "makeRocCurves", dest = 'outDir', help = 'output dir' ) +p.add_option('--cmsText', type = 'string', default = "Work in Progress", help = '' ) +p.add_option('--labName', type = 'string', default = "Reference,Monitored", help = '' ) +#p.add_option('--lumiText', default = "", help = '' ) +(o,a) = p.parse_args() + + + +from ROOTHelp.Utils import do_variable_rebinning, makeCanvas +from ROOTHelp.Plotting import makeRatio +#from rocCurveUtils import drawWaterMarks +#import rebinning +from Rebinning import rebinningDB + +from JetLevelPlotUtils import getCMSText + +inFile = ROOT.TFile(o.inFile, "READ") + +labName = o.labName.split(",") + +import os +if not os.path.exists(o.outDir): + os.makedirs(o.outDir) + + +maxDict = {"jetNSelectedTracks":20, + "jetNTracks":30, + } + + +def getHist(inFile,dir,var,binning,color): + hist = inFile.Get(dir+"/"+var) + if not hist: + print( "ERROR getting",dir+"/"+var) + if type(binning ) == type(list()): + hist = do_variable_rebinning(hist,binning) + else: + hist.Rebin(binning) + + hist.SetLineColor(color) + hist.SetMarkerColor(color) + hist.Sumw2() + if hist.Integral(): + hist.Scale(1./hist.Integral()) + return hist + + + +def doVarRatio(var, binning, xTitle, setLogy=1, minX=None, maxX=None, minY=None, yAxisSF=1.0): + offLF = getHist(inFile,"offJets_matched_L", var,binning,ROOT.kBlack) + offBQ = getHist(inFile,"offJets_matched_B", var,binning,ROOT.kRed) + + + maxY = max(offLF.GetMaximum(),offBQ.GetMaximum(), + ) + + maxY = maxY*yAxisSF + if setLogy: + offLF.SetMaximum(4e0*maxY) + offLF.SetMinimum(1.01e-5) + else: + offLF.SetMaximum(1.2*maxY) + + if not minY == None : + offLF.SetMinimum(minY) + + + offLF.GetYaxis().SetTitle("Normalized") + offLF.GetXaxis().SetTitle(xTitle ) + + if maxX: + offLF.GetXaxis().SetRangeUser(minX,maxX) + offBQ.GetXaxis().SetRangeUser(minX,maxX) + + + + xpos = 0.675 + ypos = 0.775 + xwidth = 0.25 + ywidth = 0.10 + + leg = ROOT.TLegend(xpos, ypos, xpos+xwidth, ypos+ywidth) + leg.SetNColumns(1) + leg.AddEntry(offBQ,"b-jets","L") + leg.AddEntry(offLF,"light-flavor","L") + leg.SetFillStyle(0) + leg.SetBorderSize(0) + canvas = makeCanvas(var, var, width=800, height=600) + canvas.cd() + canvas.SetLogy(setLogy) + + + if var in maxDict.keys(): + offLF.GetXaxis().SetRangeUser(offLF.GetXaxis().GetXmin(),maxDict[var] ) + + offLF.Draw("hist") + offBQ.Draw("hist same") + leg.Draw("same") + + cmsLines = getCMSText(xStart=0.2,yStart=0.85,subtext=o.cmsText) + for cmsl in cmsLines: + cmsl.Draw("same") + + + + #varName = var.replace("tracks/","").replace("btags/","btags_") + varName = var.replace("tracks/","track_").replace("btags/","btag_").replace("btags_noV0/","btag_noV0_").replace("matchedJet/","matchedJet_") + canvas.SaveAs(o.outDir+"/BvL_"+varName+".pdf") + #canvas.SaveAs(o.outDir+"/"+var+".eps") + #canvas.SaveAs(o.outDir+"/"+var+".png") + + + +for v in [ + "dPt", + "dEta", + "dPhi", + "dR", + "dcsv", + + "dDeepcsv", + "ddeepFlavB", + "dnTracks", + "dnSelTracks", + "dIp2N" , + "dIp2P" , + "dIp3N" , + "dIp3P" , + "dProbaN" , + "dProba" , + "dBprobN" , + "dBprob" , + "dSvx" , + "dSvxHP" , + "dCombIVF" , + "dCombIVF_N" , + "dSoftMuN" , + "dSoftMu" , + "dSoftElN" , + "dSoftEl" , + "dcMVAv2" , + "dcMVAv2N" , + + ]: + + binning = 1 + doVarRatio("matchedJet/"+v, + xTitle = "(per Jet) "+("#Delta"+v).replace("#Deltad","#Delta"), + binning = binning, + setLogy = 1, + #yAxisSF = 100 + ) + + +for v in [ + "dsv_NTracks" , + "dsv_Mass" , + "dsv_JetDeltaR" , + "dsv_EnergyRatio" , + "dsv_R" , + "dsv_Z" , + "dsv_Chi2" , + "dsv_Chi2_l" , + "dsv_NDF" , + "dsv_Flight" , + "dsv_FlightSig" , + "dsv_Flight2D" , + "dsv_FlightSig2D" , + "dsv_Pt" , + "dsv_Eta" , + "dsv_Phi" , + "dsv_DistJetAxis" , + "dsv_BoostOverSqrtJetPt" , + "dsv_massVertexEnergyFraction" , + "dsv_totCharge" , + ]: + + binning = 1 + doVarRatio("matchedJet/btags/"+v, + xTitle = "(per SV) "+("#Delta"+v).replace("#Deltad","#Delta"), + binning = binning, + setLogy = 1, + #yAxisSF = 100 + ) + + + +for v in [ + "dip3d_l", + "dip3d", + "dip3d_sig_l", + "dip3d_sig", + "dip3d_err_l", + "dip3d_err", + "dip2d_l", + "dip2d", + "dip2d_sig_l", + "dip2d_sig", + "dip2d_err_l", + "dip2d_err", + "dtrackDecayLenVal_l" , + "dtrackDecayLenVal" , + "dtrackJetDistVal" , + "dtrackPtRel" , + "dtrackPt" , + "dtrackMomentum" , + + "dtrackEta" , + "dtrackPhi" , + "dtrackPPar" , + "dtrackDeltaR" , + "dtrackDeltaR_l" , + "dtrackEtaRel" , + "dtrackPtRatio" , + "dtrackPParRatio" , + + "dtrackChi2" , + "dtrackNTotalHits" , + "dtrackNPixelHits" , + "dtrackIsFromV0" , + + + + + + ]: + + binning = 1 + doVarRatio("matchedJet/btags/"+v, + xTitle = "(per Track) "+("#Delta"+v).replace("#Deltad","#Delta"), + binning = binning, + setLogy = 1, + #yAxisSF = 100 + ) + + + + + +for v in [ + "djetNTracks" , + "djetNSecondaryVertices" , + + "dchargedMultiplicity" , + "dchargedHadronEnergyFraction" , + "dchargedHadronMultiplicity" , + "dchargedEmEnergyFraction" , + + "dneutralMultiplicity" , + "dneutralHadronEnergyFraction" , + "dneutralHadronMultiplicity" , + "dneutralEmEnergyFraction" , + + "dphotonMultiplicity" , + "dphotonEnergyFraction" , + + "dmuonMultiplicity" , + "dmuonEnergyFraction" , + + "delecMultiplicity" , + "delecEnergyFraction" , + + "dtotalMultiplicity" , + + ]: + + binning = 1 + doVarRatio("matchedJet/btags/"+v, + xTitle = "(per Jet) "+("#Delta"+v).replace("#Deltad","#Delta"), + binning = binning, + setLogy = 1, + #yAxisSF = 100 + ) diff --git a/plotting/makeOfflineDQMPresentation.py b/plotting/makeOfflineDQMPresentation.py new file mode 100644 index 0000000..c15a95a --- /dev/null +++ b/plotting/makeOfflineDQMPresentation.py @@ -0,0 +1,514 @@ +import optparse +parser = optparse.OptionParser() +parser.add_option('-n', '--name', dest="name", help="Run in loop mode") +parser.add_option('-p', '--prefix', dest="prefix", help="Run in loop mode") +#parser.add_option( '--period', dest="period", help="Run in loop mode") +parser.add_option('-d', '--dirWithPdfs', dest="dirWithPdfs", help="Run in loop mode") +parser.add_option('-t', '--tag', default="four", help="four is default") +#parser.add_option('--rocPlot', dest="rocPlot", help="Run in loop mode") +#parser.add_option('--flavPlotDir', help="Run in loop mode") +#parser.add_option('--effDir', help="Run in loop mode") +#parser.add_option('--mcAlgoDir', help="Run in loop mode") +#parser.add_option('--dataAlgoDir', help="Run in loop mode") +#parser.add_option('--doCaloJets', action="store_true", help="Run in loop mode") +o, a = parser.parse_args() + + +def makeHeader(outFile): + outFile.write("\documentclass{beamer} \n") + outFile.write("\mode\n") + outFile.write("\setbeamertemplate{footline}[frame number]\n") + outFile.write("\\addtobeamertemplate{frametitle}{\\vspace*{0.4cm}}{\\vspace*{-0.4cm}}\n") + outFile.write("{ \\usetheme{boxes} }\n") + outFile.write("\\usepackage{times} % fonts are up to you\n") + outFile.write("\\usefonttheme{serif} % fonts are up to you\n") + outFile.write("\\usepackage{graphicx}\n") + outFile.write("\\usepackage{tikz}\n") + outFile.write("\\usepackage{colortbl}\n") + outFile.write("\setlength{\pdfpagewidth}{2\paperwidth}\n") + outFile.write("\setlength{\pdfpageheight}{2\paperheight}\n") + outFile.write("\\title{\huge \\textcolor{myblue}{{BTV DQM Study }}}\n") + outFile.write("\\author{\\textcolor{cmured}{{\Large \\\\John Alison\\\\}}\n") + outFile.write(" \\textit{\Large Carnegie Mellon University}\n") + outFile.write("}\n") + + outFile.write("\date{ } \n") + outFile.write("\n") + #outFile.write("\logo{\n") + #outFile.write("\\begin{picture}(10,8) %university_of_chicago_logo\n") + #outFile.write("\put(-2.5,7.6){\includegraphics[height=0.5in]{CMSlogo_outline_black_red_nolabel_May2014.pdf}}\n") + #outFile.write("\put(8.2,7.7){\includegraphics[height=0.45in]{CMU_Logo_Stack_Red.eps}}\n") + #outFile.write("\end{picture}\n") + #outFile.write("}\n") + outFile.write("\n") + outFile.write("\\beamertemplatenavigationsymbolsempty\n") + outFile.write("\n") + outFile.write("\\unitlength=1cm\n") + outFile.write("\definecolor{myblue}{RGB}{33,100,158}\n") + outFile.write("\definecolor{myblack}{RGB}{0,0,0}\n") + outFile.write("\definecolor{myred}{RGB}{168,56,39}\n") + outFile.write("\definecolor{cmured}{RGB}{173,29,53}\n") + outFile.write("\definecolor{UCred}{RGB}{154,52,38}\n") + outFile.write("\definecolor{mygreen}{RGB}{0,204,0}\n") + outFile.write("\\begin{document}\n") + outFile.write("\n") + outFile.write("\n") + outFile.write("\\begin{frame}\n") + outFile.write("\\titlepage\n") + outFile.write("\end{frame}\n") + #outFile.write("\\begin{frame}{Overview}\n") + #outFile.write("\\tableofcontents\n") + #outFile.write("\end{frame}\n") + outFile.write("\logo{\n") + #outFile.write("\\begin{picture}(10,8) %university_of_chicago_logo\n") + #outFile.write("\put(-2.5,7.6){\includegraphics[height=0.5in]{CMSlogo_outline_black_red_nolabel_May2014.pdf}}\n") + #outFile.write("\put(8.2,7.7){\includegraphics[height=0.45in]{CMU_Logo_Stack_Red.eps}}\n") + #outFile.write("\end{picture}\n") + outFile.write("}\n") + + + +def make1x2(outFile,title,files): + outFile.write("\n") + outFile.write("\\begin{frame}\n") + outFile.write("\\frametitle{\centerline{ \huge \\textcolor{myblack}{"+title+"}}} \n") + outFile.write("\\begin{picture}(10,8) \n") + + # for the fig + width = 2.6 + xStart = -1.1 + xOffSet = 6.4 + yStart = 1 + outFile.write(" \put("+str(xStart)+","+str(yStart)+"){\includegraphics[width="+str(width)+"in]{"+files[0]+".pdf}}\n") + if len(files) > 1: + outFile.write(" \put("+str(xStart+xOffSet)+" ,"+str(yStart)+"){\includegraphics[width="+str(width)+"in]{"+files[1]+".pdf}}\n") + + + + outFile.write("\end{picture}\n") + outFile.write("\end{frame}\n") + + + + +def make2x2_ratio(outFile,title,files): + outFile.write("\n") + outFile.write("\\begin{frame}\n") + #outFile.write("\\frametitle{\centerline{\\textcolor{myblack}{"+title+"}}} \n") + outFile.write("\\begin{picture}(10,8) \n") + + + # for the fig + width = 1.8 + xStart = 0.45 + xOffSet = 5.0 + yOffSet = 4.2 + yStart = -1.2 + if len(files) > 0: + outFile.write(" \put("+str(xStart)+" ,"+str(yStart+yOffSet)+"){\includegraphics[width="+str(width)+"in]{"+files[0]+".pdf}}\n") + if len(files) > 1: + outFile.write(" \put("+str(xStart+xOffSet)+" ,"+str(yStart+yOffSet)+"){\includegraphics[width="+str(width)+"in]{"+files[1]+".pdf}}\n") + if len(files) > 2: + outFile.write(" \put("+str(xStart)+","+str(yStart)+"){\includegraphics[width="+str(width)+"in]{"+files[2]+".pdf}}\n") + if len(files) > 3: + outFile.write(" \put("+str(xStart+xOffSet)+" ,"+str(yStart)+"){\includegraphics[width="+str(width)+"in]{"+files[3]+".pdf}}\n") + + outFile.write(" \put("+str(1)+","+str(7.5)+"){\huge{"+title+"}}\n") + + outFile.write("\end{picture}\n") + outFile.write("\end{frame}\n") + + +def make2x2(outFile,title,files): + outFile.write("\n") + outFile.write("\\begin{frame}\n") + #outFile.write("\\frametitle{\centerline{\\textcolor{myblack}{"+title+"}}} \n") + outFile.write("\\begin{picture}(10,8) \n") + + + # for the fig + width = 2.2 + xStart = -0.5 + xOffSet = 5.8 + yOffSet = 4.2 + yStart = -1. + if len(files) > 0: + outFile.write(" \put("+str(xStart)+" ,"+str(yStart+yOffSet)+"){\includegraphics[width="+str(width)+"in]{"+files[0]+".pdf}}\n") + if len(files) > 1: + outFile.write(" \put("+str(xStart+xOffSet)+" ,"+str(yStart+yOffSet)+"){\includegraphics[width="+str(width)+"in]{"+files[1]+".pdf}}\n") + if len(files) > 2: + outFile.write(" \put("+str(xStart)+","+str(yStart)+"){\includegraphics[width="+str(width)+"in]{"+files[2]+".pdf}}\n") + if len(files) > 3: + outFile.write(" \put("+str(xStart+xOffSet)+" ,"+str(yStart)+"){\includegraphics[width="+str(width)+"in]{"+files[3]+".pdf}}\n") + + outFile.write(" \put("+str(1)+","+str(7.5)+"){\huge{"+title+"}}\n") + + outFile.write("\end{picture}\n") + outFile.write("\end{frame}\n") + + + +def make2x3(outFile,title,files): + outFile.write("\n") + outFile.write("\\begin{frame}\n") + outFile.write("\\frametitle{\centerline{ \huge \\textcolor{myblack}{"+title+"}}} \n") + outFile.write("\\begin{picture}(10,8) \n") + + # for the fig + width = 1.75 + xStart = -1.0 + xOffSet = 4.25 + yOffSet = 4.0 + yStart = -0.8 + + outFile.write(" \put("+str(xStart)+" ,"+str(yStart+yOffSet)+"){\includegraphics[width="+str(width)+"in]{"+files[0]+".pdf}}\n") + outFile.write(" \put("+str(xStart+xOffSet)+" ,"+str(yStart+yOffSet)+"){\includegraphics[width="+str(width)+"in]{"+files[1]+".pdf}}\n") + outFile.write(" \put("+str(xStart+xOffSet+xOffSet)+" ,"+str(yStart+yOffSet)+"){\includegraphics[width="+str(width)+"in]{"+files[2]+".pdf}}\n") + + if len(files) > 3: + outFile.write(" \put("+str(xStart)+" ,"+str(yStart)+"){\includegraphics[width="+str(width)+"in]{"+files[3]+".pdf}}\n") + outFile.write(" \put("+str(xStart+xOffSet)+" ,"+str(yStart)+"){\includegraphics[width="+str(width)+"in]{"+files[4]+".pdf}}\n") + outFile.write(" \put("+str(xStart+xOffSet+xOffSet)+" ,"+str(yStart)+"){\includegraphics[width="+str(width)+"in]{"+files[5]+".pdf}}\n") + + + + + outFile.write("\end{picture}\n") + outFile.write("\end{frame}\n") + + +def make1x1(outFile,title,file,text,xText,yText): + outFile.write("\n") + outFile.write("\\begin{frame}\n") + outFile.write("\\frametitle{\centerline{ \huge \\textcolor{myblack}{"+title+"}}} \n") + outFile.write("\\begin{picture}(10,8) \n") + + # for the fig + width = 4.5 + xStart = -0.5 + yStart = -0.2 + outFile.write(" \put("+str(xStart)+","+str(yStart)+"){\includegraphics[width="+str(width)+"in]{"+file+"}}\n") + + + # for the text + #textHeight = 7. + outFile.write(" \put("+str(xText[0])+","+str(yText[0])+"){"+text[0]+"}\n") + + outFile.write("\end{picture}\n") + outFile.write("\end{frame}\n") + +def makeWholeSlide(outFile,inputPDF): + outFile.write("\n") + outFile.write("\\begin{frame}\n") + #outFile.write("\\frametitle{\centerline{ \huge \\textcolor{myblack}{TEst}}} \n") + outFile.write("\\begin{picture}(10,8) \n") + + outFile.write(" \put("+str(-1)+","+str(-1)+"){\includegraphics[width="+str(5)+"in]{"+inputPDF+"}}\n") + + + outFile.write("\end{picture}\n") + outFile.write("\end{frame}\n") + + + +def make1x3(outFile,title,files,text): + outFile.write("\n") + outFile.write("\\begin{frame}\n") + outFile.write("\\frametitle{\centerline{ \huge \\textcolor{myblack}{"+title+"}}} \n") + outFile.write("\\begin{picture}(10,8) \n") + + # for the fig + width = 1.75 + xStart = -1. + xOffSet = 4.25 + yStart = 1 + outFile.write(" \put("+str(xStart)+","+str(yStart)+"){\includegraphics[width="+str(width)+"in]{"+files[0]+".pdf}}\n") + if len(files) > 1: + outFile.write(" \put("+str(xStart+xOffSet)+" ,"+str(yStart)+"){\includegraphics[width="+str(width)+"in]{"+files[1]+".pdf}}\n") + if len(files) > 2: + outFile.write(" \put("+str(xStart+2*xOffSet)+" ,"+str(yStart)+"){\includegraphics[width="+str(width)+"in]{"+files[2]+".pdf}}\n") + + # for the text + textHeight = 5.2 + textStart = -0.25 + outFile.write(" \put("+str(textStart)+","+str(textHeight)+"){\\textcolor{myred}{\large "+text[0]+"}}\n") + if len(text) > 1: + outFile.write(" \put("+str(textStart+xOffSet)+","+str(textHeight)+"){\\textcolor{myred}{\large "+text[1]+" }}\n") + if len(text) > 2: + outFile.write(" \put("+str(textStart+(2*xOffSet))+","+str(textHeight)+"){\\textcolor{myred}{\large "+text[2]+" }}\n") + + outFile.write("\end{picture}\n") + outFile.write("\end{frame}\n") + + +def makeTransition(outFile,text,doHuge=True): + outFile.write("\n") + outFile.write("\\begin{frame}\n") + #outFile.write("\\frametitle{\centerline{ \huge \\textcolor{myblack}{"+title+"}}} \n") + outFile.write("\\begin{picture}(10,8) \n") + + # for the text + textHeight = 4 + if doHuge: + outFile.write(" \put("+str(0)+","+str(textHeight)+"){\\textcolor{myred}{\Huge \\textit{"+text+"}}}\n") + else: + outFile.write(" \put("+str(0)+","+str(textHeight)+"){\\textcolor{myred}{\Large \\textit{"+text+"}}}\n") + outFile.write("\end{picture}\n") + outFile.write("\end{frame}\n") + + +def makeText(outFile,text,title=""): + outFile.write("\n") + outFile.write("\\begin{frame}\n") + outFile.write("\\frametitle{\centerline{ \huge \\textcolor{myblack}{"+title+"}}} \n") + for t in text: + outFile.write(t+"\n") + outFile.write("\end{frame}\n") + + + + + +def makePresentation(): + + outFile = open(o.name+".tex","w") + makeHeader(outFile) + + + cut = "passMDRs" + pdfDir = o.dirWithPdfs + prefix = o.prefix + + + #outFile.write("\subsection{ROCs} \n") + + for slideConfig in [ + ("roc_All_Eff","roc_All_C_Eff","",""), + ]: + files = [] + for i in range(4): + if slideConfig[i]: files += [pdfDir+"/"+slideConfig[i]] + make1x2(outFile,"ROCs", + files = files, + ) + + #outFile.write("\subsection{Inputs} \n") + makeTransition(outFile,"Inputs") + + + # + # Jet-Level Inputs + # + for slideConfig in [ + ("DeepCSV_l","deepFlavB","pt_m","eta"), + ("Ip2P","Ip3P","Ip2P_l","Ip3P_l"), + ("Bprob","Proba","Svx","SvxHP"), + ("track_nTracks","btag_sv_nSVs","btag_chargedMultiplicity","btag_neutralMultiplicity"), + ]: + files = [] + for i in range(4): + if slideConfig[i]: files += [pdfDir+"/BvL_"+slideConfig[i]] + make2x2_ratio(outFile,"Jet-Level Inputs", + files = files, + ) + + + # + # Tracks + # + for slideConfig in [ + ("eta","pt_s","DeltaR","PtRel"), + ("NPixelHits","HasInnerPixHit","NStripHits","NTotalHits"), + ("ip2d","ip2d_l","ip2d_sig","ip2d_sig_l"), + ("ip3d","ip3d_l","ip3d_sig","ip3d_sig_l"), + #("Chi2","","",""), + ]: + files = [] + for i in range(4): + if slideConfig[i]: files += [pdfDir+"/BvL_track_"+slideConfig[i]] + make2x2_ratio(outFile,"Track-Level Inputs", + files = files, + ) + + + + # + # Secondary Vertex + # + for slideConfig in [ + ("Mass","NTracks","R","Z"), + ("Eta", "Pt","JetDeltaR","Chi2"), + ("Flight","FlightSig","Flight2D","FlightSig2D"), + #("Chi2","","",""), + ]: + files = [] + for i in range(4): + if slideConfig[i]: files += [pdfDir+"/BvL_btag_sv_"+slideConfig[i]] + make2x2_ratio(outFile,"Secondary Vertex Inputs", + files = files, + ) + + + + # + # Event-by-Event Matching + # + makeTransition(outFile,"Event Matching") + for slideConfig in [ + ("dR","dPt","dPhi","dEta"), + ("dDeepcsv","ddeepFlavB","dProba","dBprob"), + ("dSvx" ,"dSvxHP" ,"dIp2P" , "dIp3P"), + ("btag_djetNTracks","btag_djetNSecondaryVertices","btag_dchargedHadronMultiplicity","btag_dneutralMultiplicity"), + ]: + files = [] + for i in range(4): + if slideConfig[i]: files += [pdfDir+"/BvL_matchedJet_"+slideConfig[i]] + make2x2(outFile,"Event-by-Event Jet Matching", + files = files, + ) + + + + for slideConfig in [ + ("R" ,"Z" , "Eta" , "Phi" ), + ("totCharge", "NTracks" ,"Mass" ,"Pt") , + ("JetDeltaR" , "totCharge" , "Chi2" ,"EnergyRatio" ), + ("Flight" ,"FlightSig" ,"Flight2D" ,"FlightSig2D") , + + + ]: + files = [] + for i in range(4): + if slideConfig[i]: files += [pdfDir+"/BvL_matchedJet_btag_dsv_"+slideConfig[i]] + make2x2(outFile,"Event-by-Event SV Matching", + files = files, + ) + + + + + for slideConfig in [ + + ("dtrackEta" ,"dtrackPhi" , "dtrackPt" , "dtrackMomentum" ), + ("dtrackChi2" , "dtrackNTotalHits" , "dtrackNPixelHits" , "dtrackIsFromV0" ), + ("dip2d","dip2d_sig","dip2d_sig_l","dip2d_err",), + ("dip3d","dip3d_sig","dip3d_sig_l","dip3d_err",), + ("dtrackPtRel" ,"dtrackDeltaR" ,"dtrackJetDistVal" ,"dtrackPPar" ), + + + + ]: + + + + files = [] + for i in range(4): + if slideConfig[i]: files += [pdfDir+"/BvL_matchedJet_btag_"+slideConfig[i]] + make2x2(outFile,"Event-by-Event Track Matching", + files = files, + ) + + + + + makeTransition(outFile,"Back-up") + + for slideConfig in [ + ("roc_All_Eff","roc_All_C_Eff","",""), + ("roc_Bprob_Eff","roc_Bprob_C_Eff","",""), + ("roc_cMVAv2_Eff", "roc_cMVAv2_C_Eff", "",""), + ("roc_CombIVF_Eff", "roc_CombIVF_C_Eff", "",""), + ("roc_Svx_Eff", "roc_Svx_C_Eff", "",""), + ("roc_SvxHP_Eff", "roc_SvxHP_C_Eff", "",""), + ("roc_Bprob_Eff", "roc_Bprob_C_Eff", "",""), + ("roc_Proba_Eff", "roc_Proba_C_Eff", "",""), + ("roc_Ip2P_Eff", "roc_Ip2P_C_Eff", "",""), + ("roc_Ip3P_Eff", "roc_Ip3P_C_Eff", "",""), + ("roc_SoftMu_Eff", "roc_SoftMu_C_Eff", "",""), + ("roc_SoftEl_Eff", "roc_SoftEl_C_Eff", "",""), + + + ]: + files = [] + for i in range(4): + if slideConfig[i]: files += [pdfDir+"/"+slideConfig[i]] + make1x2(outFile,"ROCs", + files = files, + ) + + + # + # Track Efficiiences + # + for slideConfig in [ + ("Eta","Phi","pt_s","pt_m"), + ("NPixelHits","HasInnerPixHit","NStripHits","NTotalHits"), + ("ip2d","ip2d_l","ip2d_sig","ip2d_sig_l"), + ("ip3d","ip3d_l","ip3d_sig","ip3d_sig_l"), + ("DeltaR","","",""), + + #("Chi2","","",""), + ]: + files = [] + for i in range(4): + if slideConfig[i]: files += [pdfDir+"/Eff_"+slideConfig[i]] + make2x2(outFile,"Tracking Relative Efficiencies", + files = files, + ) + + + # + # Track Fakes + # + for slideConfig in [ + ("Eta","Phi","pt_s","pt_m"), + ("NPixelHits","HasInnerPixHit","NStripHits","NTotalHits"), + ("ip2d","ip2d_l","ip2d_sig","ip2d_sig_l"), + ("ip3d","ip3d_l","ip3d_sig","ip3d_sig_l"), + ("DeltaR","","",""), + + #("Chi2","","",""), + ]: + files = [] + for i in range(4): + if slideConfig[i]: files += [pdfDir+"/Fake_"+slideConfig[i]] + make2x2(outFile,"Tracking Relative Fake Rates", + files = files, + ) + + + + outFile.write("\n") + outFile.write("\end{document}\n") + + + +if __name__ == "__main__": + makePresentation() + import os + + fileName = o.name + filePathAndName = o.name + if len(o.name.split("/")): + fileName = o.name.split("/")[-1] + filePath = "/".join(o.name.split("/")[0:-1]) + print( "fileName:",fileName) + print( "filePath:",filePath) + + + os.system("rm "+fileName+".aux") + + os.system("pdflatex "+filePathAndName+".tex") + os.system("pdflatex "+filePathAndName+".tex") + os.system("pdflatex "+filePathAndName+".tex") + + + os.system("rm "+fileName+".out") + os.system("rm "+fileName+".toc") + os.system("rm "+fileName+".snm") + os.system("rm "+fileName+".aux") + os.system("rm "+fileName+".nav") + os.system("rm "+fileName+".log") + + if len(o.name.split("/")): + os.system("mv "+fileName+".pdf "+filePath) diff --git a/plotting/makeRocCurvesOffToOff.py b/plotting/makeRocCurvesOffToOff.py new file mode 100644 index 0000000..0f0bff2 --- /dev/null +++ b/plotting/makeRocCurvesOffToOff.py @@ -0,0 +1,476 @@ +import ROOT +ROOT.gErrorIgnoreLevel = ROOT.kWarning + + +ROOT.gROOT.SetBatch(True) + +import ROOTHelp.FancyROOTStyle + +from optparse import OptionParser +p = OptionParser() +p.add_option('--input', type = 'string', default = "outBTag.FTKBtagging.ttbar.mwt2.All.root", dest = 'inFile', help = 'intput File' ) +p.add_option('--output', type = 'string', default = "makeRocCurves", dest = 'outDir', help = 'output dir' ) +p.add_option('--cmsText', type = 'string', default = "Work in Progress", help = '' ) +p.add_option('--labName', type = 'string', default = "Reference,Monitored", help = '' ) +(o,a) = p.parse_args() + +inFile = ROOT.TFile(o.inFile, "READ") + +labName = o.labName.split(",") + +import os +if not os.path.exists(o.outDir): + os.makedirs(o.outDir) + +from rocCurveUtils import makeRoc +from JetLevelPlotUtils import getCMSText, getText + + + +def getWorkingPoint(var, bkg, sig, dir, varNorm): + sigHist = inFile.Get(dir+"_"+sig+"/"+var) + bkgHist = inFile.Get(dir+"_"+bkg+"/"+var) + + sigNormHist = inFile.Get(dir+"_"+sig+"/"+varNorm) + bkgNormHist = inFile.Get(dir+"_"+bkg+"/"+varNorm) + + + rocPlot = makeRoc(sigHist, sigNormHist, bkgHist, bkgNormHist,doErr=False,bkgMode="Rej") + + nbins = sigHist.GetNbinsX() + + thisSig = sigHist .Integral(0,nbins+1) + thisSigDen = sigNormHist.Integral(0,nbins+1) + if not thisSigDen: thisSigDen = 1 + sigEff = float(thisSig) / float(thisSigDen) + + thisBkg = bkgHist .Integral(0,nbins+1) + thisBkgDen = bkgNormHist.Integral(0,nbins+1) + if not thisBkgDen: thisBkgDen = 1 + bkgEff = float(thisBkg) / float(thisBkgDen) + if bkgEff: bkgRej = 1./bkgEff + else: bkgRej = 1 + + + return (sigEff, bkgRej) + +def makeRocPlot(name, var, bkg, sig, dir, varNorm=None,debug=False,vsLight=True): + sigHist = inFile.Get(dir+"_"+sig+"/"+var) + bkgHist = inFile.Get(dir+"_"+bkg+"/"+var) + + if varNorm: + sigNormHist = inFile.Get(dir+"_"+sig+"/"+varNorm) + bkgNormHist = inFile.Get(dir+"_"+bkg+"/"+varNorm) + else : + sigNormHist = sigHist + bkgNormHist = bkgHist + + rocPlots = [] + for config in [("Rej",1,5e4),("Eff",5e-4,1)]: + rocPlots.append(makeRoc(sigHist, sigNormHist, bkgHist, bkgNormHist,doErr=False,bkgMode=config[0],cleanNoCut=True,debug=debug)) + + can = ROOT.TCanvas(name+"_"+config[0], name+"_"+config[0]) + can.cd().SetLogy(1) + rocPlots[-1].SetLineWidth(5) + rocPlots[-1].GetXaxis().SetTitle("B-Jet Efficiency") + rocPlots[-1].GetXaxis().SetRangeUser(0.4,1) + if vsLight: yTitle = "Light Flavor " + else: yTitle = "C-Jet " + + if config[0] == "Rej": yTitle +="Rejection" + elif config[0] == "Eff": yTitle +="Efficiency" + rocPlots[-1].GetYaxis().SetTitle(yTitle) + rocPlots[-1].GetYaxis().SetRangeUser(config[1],config[2]) + rocPlots[-1].Draw("AL") + # can.SaveAs(o.outDir+"/roc_"+name+"_"+config[0]+".pdf") + # can.SaveAs(o.outDir+"/roc_"+name+"_"+config[0]+".png") + return rocPlots + + +def plotSame(name,graphs,colors,styles, workingPts= None,rocType=None,plotDeepCSV=False,plotDeepJet=False, taggerNames=[], coloredText=[], logy=True, yMin=1e-4, xMin=0.3): + + can = ROOT.TCanvas(name,name) + if logy: + can.cd().SetLogy(1) + hist_axis = ROOT.TH1F("hist_axis","hist_axis",1,xMin,1) + hist_axis.GetYaxis().SetTitle(graphs[0].GetYaxis().GetTitle()) + hist_axis.GetXaxis().SetTitle(graphs[0].GetXaxis().GetTitle()) + hist_axis.Draw() + + xMax = 1 + hist_axis.GetXaxis().SetRangeUser(xMin,xMax) + hist_axis.GetYaxis().SetRangeUser(yMin,1) + + line = ROOT.TF1("guessing","x",xMin,xMax) + line.SetLineColor(ROOT.kGray) + line.SetLineStyle(10) + line.Draw("same") + #line.DrawLine(max(xMin,yMin), 1*max(xMin,yMin), xMax, 1.0*xMax) + + for gItr, g in enumerate(graphs): + g.SetLineColor(colors[gItr]) + g.SetLineStyle(styles[gItr]) + #if not gItr: + # g.Draw("AL") + #else: + # g.Draw("L") + g.Draw("L") + + if not workingPts == None: + g_wrkPts = ROOT.TGraph(len(workingPts)) + g_wrkPts.SetMarkerSize(2) + g_wrkPts.SetMarkerColor(colors[1]) + g_wrkPts.SetMarkerStyle(34) + for wpItr, wp in enumerate(workingPts): + #print wpItr,wp + + g_wrkPts.SetPoint(wpItr, wp[0],wp[1]) + + g_wrkPts.Draw("P") + + cmsLine1, cmsLine2 = getCMSText(xStart=0.2,yStart=0.875,subtext=o.cmsText) + cmsLine1.Draw("same") + cmsLine2.Draw("same") + + yStart = 0.75 + xStart = 0.2 + if rocType == "Rej": + xStart = 0.5 + yStart = 0.875 + + + + offJetText = getText(labName[0]+" Jets (Solid) ",xStart=xStart,yStart=yStart,size=0.04,color=ROOT.kBlack) + yStart = yStart - 0.05 + offJetText.Draw("same") + + pfJetText = getText(labName[1]+" Jet (Dashed) ",xStart=xStart,yStart=yStart,size=0.04,color=ROOT.kBlack) + pfJetText.Draw("same") + + #offJetTextDeep = getText("Offline DeepCSV (Dashed) ",xStart=0.6,yStart=0.36,size=0.03,color=ROOT.kBlack) + + #offJetText = getText("Offline Jet ",xStart=0.6,yStart=0.4,size=0.03,color=ROOT.kBlack) + + + + for t in taggerNames: + yStart = yStart - 0.05 + deepCSVText = getText(t,xStart=xStart,yStart=yStart,size=0.04,color=ROOT.kRed+2) + deepCSVText.Draw("same") + + + cTexts = [ ] + for iCt, ct in enumerate(coloredText): + yStart = yStart - 0.05 + cTexts.append(getText(ct,xStart=xStart,yStart=yStart,size=0.04,color=colors[2*iCt])) + cTexts[-1].Draw("same") + + + + yStart = yStart - 0.05 + if plotDeepCSV: + if plotDeepJet: + deepCSVText = getText("DeepCSV",xStart=xStart,yStart=yStart,size=0.04,color=ROOT.kBlue) + else: + deepCSVText = getText("DeepJet",xStart=xStart,yStart=yStart,size=0.04,color=ROOT.kBlack) + + deepCSVText.Draw("same") + yStart = yStart - 0.05 + + if plotDeepJet: + if plotDeepCSV: + deepJetText = getText("DeepJet",xStart=xStart,yStart=yStart,size=0.04,color=ROOT.kBlack) + else: + deepJetText = getText("DeepCSV",xStart=xStart,yStart=yStart,size=0.04,color=ROOT.kBlue) + deepJetText.Draw("same") + yStart = yStart - 0.05 + + + + + + #offJetTextDeep.Draw("same") + + can.SaveAs(o.outDir+"/roc_"+name+".pdf") + + + + + +def main(): + + mon_roc = {} + ref_roc = {} + + mon_roc_C = {} + ref_roc_C = {} + + taggers = [("DeepCSV","DeepCSV_l"), + ("DeepJet","deepFlavB"), + ("cMVAv2", "cMVAv2"), + ("CombIVF", "CombIVF"), + ("Svx", "Svx"), + ("SvxHP", "SvxHP"), + ("Bprob", "Bprob"), + ("Proba", "Proba",{"xMin":0}), + ("Ip2P", "Ip2P_l"), + ("Ip3P", "Ip3P_l"), + ("SoftMu", "SoftMu"), + ("SoftEl", "SoftEl"), + ("neutralHadronMultiplicity","btags/neutralHadronMultiplicity",{"logy":False,"yMin":0.1}), + ("chargedHadronMultiplicity","btags/chargedHadronMultiplicity",{"logy":False,"yMin":0.1}), + ("photonMultiplicity","btags/photonMultiplicity",{"logy":False,"yMin":0.1}), + ] + + for tag in taggers: + + mon_roc[tag[0]] = makeRocPlot("Mon_"+tag[0], tag[1], bkg="matchedJet_L", sig="matched_B", dir="offJets") + mon_roc_C[tag[0]] = makeRocPlot("Mon_C_"+tag[0], tag[1], bkg="matchedJet_C", sig="matched_B", dir="offJets", vsLight=False) + + ref_roc[tag[0]] = makeRocPlot("Ref_"+tag[0], tag[1], bkg="matched_L", sig="matchedJet_B",dir="offJets") + ref_roc_C[tag[0]] = makeRocPlot("Ref_C_"+tag[0], tag[1], bkg="matched_C", sig="matchedJet_B",dir="offJets", vsLight=False) + + + + + # + # Pt Study + # + ptBins = ["50","100","300","10000"] + + mon_roc_pt = {} + ref_roc_pt = {} + + mon_roc_C_pt = {} + ref_roc_C_pt = {} + + + for ptB in ptBins: + + mon_roc_pt[ptB] = makeRocPlot("Mon_DeepJet_pt"+ptB, "deepFlavB_pt"+ptB, bkg="matchedJet_L", sig="matched_B", dir="offJets") + mon_roc_C_pt[ptB] = makeRocPlot("Mon_DeepJet_C_pt"+ptB, "deepFlavB_pt"+ptB, bkg="matchedJet_C", sig="matched_B", dir="offJets", vsLight=False) + + ref_roc_pt[ptB] = makeRocPlot("Ref_DeepJet_pt"+ptB, "deepFlavB_pt"+ptB, bkg="matched_L", sig="matchedJet_B",dir="offJets") + ref_roc_C_pt[ptB] = makeRocPlot("Ref_DeepJet_C_pt"+ptB, "deepFlavB_pt"+ptB, bkg="matched_C", sig="matchedJet_B",dir="offJets", vsLight=False) + + + # + # Eta Study + # + etaBins = ["0.5","1","1.5","2","2.5"] + + mon_roc_eta = {} + ref_roc_eta = {} + + mon_roc_C_eta = {} + ref_roc_C_eta = {} + + + for etaB in etaBins: + + mon_roc_eta[etaB] = makeRocPlot("Mon_DeepJet_eta"+etaB, "deepFlavB_eta"+etaB, bkg="matchedJet_L", sig="matched_B", dir="offJets") + mon_roc_C_eta[etaB] = makeRocPlot("Mon_DeepJet_C_eta"+etaB, "deepFlavB_eta"+etaB, bkg="matchedJet_C", sig="matched_B", dir="offJets", vsLight=False) + + ref_roc_eta[etaB] = makeRocPlot("Ref_DeepJet_eta"+etaB, "deepFlavB_eta"+etaB, bkg="matched_L", sig="matchedJet_B",dir="offJets") + ref_roc_C_eta[etaB] = makeRocPlot("Ref_DeepJet_C_eta"+etaB, "deepFlavB_eta"+etaB, bkg="matched_C", sig="matchedJet_B",dir="offJets", vsLight=False) + + + + for i, rocType in enumerate(["Rej","Eff"]): + + + for tag in taggers: + kw = {} + if len(tag) > 2: + kw = tag[2] + + + + plotSame(tag[0]+"_"+rocType, + [mon_roc[tag[0]][i], ref_roc[tag[0]][i]], + [ROOT.kBlack, ROOT.kBlack], + [ROOT.kDashed, ROOT.kSolid], + taggerNames = [tag[0]], + plotDeepJet = False, + plotDeepCSV = False, + rocType = rocType, + **kw + ) + + + + plotSame(tag[0]+"_C_"+rocType, + [mon_roc_C[tag[0]][i], ref_roc_C[tag[0]][i]], + [ROOT.kBlack, ROOT.kBlack], + [ROOT.kDashed, ROOT.kSolid], + taggerNames = [tag[0]], + plotDeepJet = False, + plotDeepCSV = False, + rocType = rocType, + **kw + ) + + + + all_rocs = [] + all_rocs_C = [] + all_styles = [] + all_colors = [] + + def addToAll(roc,roc_c,style,color): + all_rocs.append(roc) + all_rocs_C.append(roc_c) + all_styles.append(style) + all_colors.append(color) + + def addTaggerToAll(name, color): + addToAll(mon_roc[name][i], mon_roc_C[name][i], ROOT.kDashed, color) + addToAll(ref_roc[name][i], ref_roc_C[name][i], ROOT.kSolid, color) + + + + addTaggerToAll("DeepCSV", ROOT.kBlue) + addTaggerToAll("DeepJet", ROOT.kBlack) + + + plotSame("All_"+rocType, + all_rocs, all_colors, all_styles, + plotDeepCSV = True, + plotDeepJet = True, + rocType = rocType + ) + + + + plotSame("All_C_"+rocType, + all_rocs_C, all_colors, all_styles, + plotDeepCSV = True, + plotDeepJet = True, + rocType = rocType, + ) + + + addTaggerToAll("cMVAv2", ROOT.kRed) + addTaggerToAll("CombIVF", ROOT.kOrange) + addTaggerToAll("Svx", ROOT.kPink) + addTaggerToAll("SvxHP", ROOT.kRed+2) + addTaggerToAll("Bprob", ROOT.kGray) + addTaggerToAll("Proba", ROOT.kGray+2) + addTaggerToAll("Ip2P" , ROOT.kGreen+2) + addTaggerToAll("Ip3P" , ROOT.kGreen) + addTaggerToAll("SoftMu", ROOT.kMagenta) + addTaggerToAll("SoftEl", ROOT.kMagenta+1) + + + + plotSame("All_Extra_"+rocType, + all_rocs, all_colors, all_styles, + rocType = rocType + ) + + + + plotSame("All_Extra_C_"+rocType, + all_rocs_C, all_colors, all_styles, + rocType = rocType + ) + + + + # + # Pt Study + # + pt_rocs = [] + pt_rocs_C = [] + pt_styles = [] + pt_colors = [] + pt_text = [] + + def addToPt(roc,roc_c,style,color): + pt_rocs.append(roc) + pt_rocs_C.append(roc_c) + pt_styles.append(style) + pt_colors.append(color) + + def addPtToPt(name, color, text): + pt_text.append(text) + addToPt(mon_roc_pt[name][i], mon_roc_C_pt[name][i], ROOT.kDashed, color) + addToPt(ref_roc_pt[name][i], ref_roc_C_pt[name][i], ROOT.kSolid, color) + + + addPtToPt("50", ROOT.kBlack, "pt < 50 GeV") + addPtToPt("100", ROOT.kBlue, "50 - 100 GeV") + addPtToPt("300", ROOT.kOrange, "100 - 300 GeV") + addPtToPt("10000",ROOT.kRed, "pt > 300 GeV") + + plotSame("DeepJetPtBins_"+rocType, + pt_rocs, pt_colors, pt_styles, + plotDeepJet = False, + plotDeepCSV = False, + rocType = rocType, + coloredText = pt_text, + ) + + + plotSame("DeepJetPtBins_C_"+rocType, + pt_rocs_C, pt_colors, pt_styles, + plotDeepJet = False, + plotDeepCSV = False, + rocType = rocType, + coloredText = pt_text, + ) + + + + + # + # Eta Study + # + eta_rocs = [] + eta_rocs_C = [] + eta_styles = [] + eta_colors = [] + eta_text = [] + + def addToEta(roc,roc_c,style,color): + eta_rocs.append(roc) + eta_rocs_C.append(roc_c) + eta_styles.append(style) + eta_colors.append(color) + + def addEtaToEta(name, color, text): + eta_text.append(text) + addToEta(mon_roc_eta[name][i], mon_roc_C_eta[name][i], ROOT.kDashed, color) + addToEta(ref_roc_eta[name][i], ref_roc_C_eta[name][i], ROOT.kSolid, color) + + + addEtaToEta("0.5", ROOT.kBlack, "|eta| < 0.5") + addEtaToEta("1", ROOT.kBlue, "0.5 - 1.0") + addEtaToEta("1.5", ROOT.kRed, "1.0 - 1.5") + addEtaToEta("2", ROOT.kOrange, "1.5 - 2.0") + addEtaToEta("2.5", ROOT.kGreen+2, "2.0 - 2.5") + + plotSame("DeepJetEtaBins_"+rocType, + eta_rocs, eta_colors, eta_styles, + plotDeepJet = False, + plotDeepCSV = False, + rocType = rocType, + coloredText = eta_text, + ) + + + plotSame("DeepJetEtaBins_C_"+rocType, + eta_rocs_C, eta_colors, eta_styles, + plotDeepJet = False, + plotDeepCSV = False, + rocType = rocType, + coloredText = eta_text, + ) + + + + + + +if __name__ == "__main__": + main() diff --git a/plotting/offlineDQMPlots.sh b/plotting/offlineDQMPlots.sh new file mode 100755 index 0000000..4cade63 --- /dev/null +++ b/plotting/offlineDQMPlots.sh @@ -0,0 +1,19 @@ +input=$1 +echo $input +output=$2 +monName=$3 + + + +cmd=${4:-echo python3} +echo cmd=$cmd + +#echo $cmd + +$cmd TriggerStudies/plotting/MakeOffToOffComparison.py --in $input --out $output --labName Reference,$monName +#$cmd TriggerStudies/plotting/OffToOffPlots.py $input --labName Monitored,Reference --out $output +$cmd TriggerStudies/plotting/OffvsOff_BvL.py --input $input --out $output --labName Reference,$monName +$cmd TriggerStudies/plotting/innerHitvsNoInnerHit.py --in $input --out $output +$cmd TriggerStudies/plotting/jetDeltaHists_BvL.py --input $input --out $output --labName Reference,$monName +$cmd TriggerStudies/plotting/makeRocCurvesOffToOff.py --in $input --out $output --labName Reference,$monName +$cmd TriggerStudies/plotting/makeOfflineDQMPresentation.py -d $output -n ${output}/${output}_slides diff --git a/plotting/rocCurveUtils.py b/plotting/rocCurveUtils.py index af2e70c..78b9fca 100644 --- a/plotting/rocCurveUtils.py +++ b/plotting/rocCurveUtils.py @@ -1,4 +1,5 @@ import ROOT +import ctypes def drawWaterMarks(watermarks): @@ -35,8 +36,8 @@ def getEffErrors(num,den): errHigh = eff.GetErrorYhigh(0) errLow = eff.GetErrorYlow(0) - xValue = ROOT.Double(0) - theEff = ROOT.Double(0) + xValue = ctypes.c_double(0) + theEff = ctypes.c_double(0) eff.GetPoint(0,xValue,theEff) return (theEff,errHigh,errLow) @@ -68,7 +69,7 @@ def makeRoc(sigNum,sigDen,bkgNum,bkgDen,bkgMode="Eff",doErr = False, cutAbove=Fa for i in range(nbins): bin = i - if debug: print bin + if debug: print( bin) if cutAbove: @@ -92,9 +93,9 @@ def makeRoc(sigNum,sigDen,bkgNum,bkgDen,bkgMode="Eff",doErr = False, cutAbove=Fa #print "\t",thisBkg, bkgTot if debug: - print "bkgEff",bkgEff, - print "sigEff",sigEff - print "\tbkg:",thisBkg,"total",bkgTot + print( "bkgEff",bkgEff,) + print( "sigEff",sigEff) + print( "\tbkg:",thisBkg,"total",bkgTot) if bkgEff: bkgRej = 1.0/bkgEff bkgRejErr = bkgEffErr/(bkgEff*bkgEff) @@ -116,9 +117,9 @@ def makeRoc(sigNum,sigDen,bkgNum,bkgDen,bkgMode="Eff",doErr = False, cutAbove=Fa #roc.Set(roc.GetN()-2) #print roc.GetN() #continue - xValue = ROOT.Double(0) - yValue = ROOT.Double(0) - theEff = ROOT.Double(0) + xValue = ctypes.c_double(0) + yValue = ctypes.c_double(0) + theEff = ctypes.c_double(0) #print bin #roc.GetPoint(bin-1,xValue,yValue) #print xValue,yValue @@ -226,9 +227,9 @@ def GetRoc(inFile, sigNameNum,sigNameDen,bkgNameNum,bkgNameDen,doErr=False,mode= hbkgDen = inFile.Get(bkgNameDen) if not hsigNum: - print "Cannot get ",hsigNum,sigNameNum + print( "Cannot get ",hsigNum,sigNameNum) if not hbkgNum: - print "Cannot get ",hbkgNum + print( "Cannot get ",hbkgNum) rocCurve = makeRoc(hsigNum,hsigDen,hbkgNum,hbkgDen,bkgMode=mode,doErr=doErr, cutAbove=cutAbove) @@ -242,7 +243,7 @@ def GetPt(inFile,numSigName,denSigName,numBkgName, denBkgName,doErr=False,mode=" hnumBkg = inFile.Get(numBkgName) hdenBkg = inFile.Get(denBkgName) - if not hnumSig: print "Cannot get",hnumSig,numSigName + if not hnumSig: print( "Cannot get",hnumSig,numSigName) opPt = makePt(hnumSig,hdenSig,hnumBkg,hdenBkg,bkgMode=mode,doErr=doErr)