11 from __future__
import print_function
12 from histoStyle
import *
14 from optparse
import OptionParser
15 usage=
"""%prog [options]"""
16 description=
"""A simple script to generate validation plots"""
18 plotFactory.py -f BTagRelVal_TTbar_Startup_600.root -F BTagRelVal_TTbar_Startup_600gspre3.root -r 600 -R 600gspre3 -s TTbar_Startup -S TTbar_Startup
20 parser = OptionParser(usage=usage,add_help_option=
True,description=description,epilog=epilog)
21 parser.add_option(
"-f",
"--valInputFile", dest=
"valPath", default=fileNameVal,
22 help=
"Read input file for sample to validated", metavar=
"VALFILE")
23 parser.add_option(
"-F",
"--refInputFile", dest=
"refPath", default=fileNameRef,
24 help=
"Read input file for reference sample", metavar=
"RAFFILE")
25 parser.add_option(
"-r",
"--valReleaseName", dest=
"ValRel", default=ValRel,
26 help=
"Name to refer to the release/conditions to validate, ex: 600, GTV18 ...", metavar=
"VALREL")
27 parser.add_option(
"-R",
"--refReleaseName", dest=
"RefRel", default=RefRel,
28 help=
"Name to refer to the reference release/conditions, ex: 600pre11, GTV16 ...", metavar=
"REFREL")
29 parser.add_option(
"-s",
"--valSampleName", dest=
"ValSample", default=ValSample,
30 help=
"Name to refer to the sample name to validate, ex: TTbar_FullSim, 2012C ...", metavar=
"VALSAMPLE")
31 parser.add_option(
"-S",
"--refSampleName", dest=
"RefSample", default=RefSample,
32 help=
"Name to refer to the reference sample name, ex: TTbar_FullSim, 2012C ...", metavar=
"REFSAMPLE")
33 parser.add_option(
"-b",
"--batch", dest=
"batch", default=batch,
34 action=
"store_true", help=
"if False, the script will run in batch mode")
35 parser.add_option(
"-l",
"--drawLegend", dest=
"drawLegend", default=drawLegend,
36 action=
"store_true", help=
"if True the legend will be drawn on top of the plots")
37 parser.add_option(
"-p",
"--printBanner", dest=
"printBanner", default=printBanner,
38 action=
"store_true", help=
"if True, a banner will be print on top of the plots")
39 parser.add_option(
"-B",
"--Banner", dest=
"Banner", default=Banner,
40 help=
"String to write as banner on top of the plots, option -B should be used")
41 parser.add_option(
"-n",
"--noRatio", dest=
"doRatio", default=doRatio,
42 action=
"store_false", help=
"if True, ratios plots will be created")
43 (options, args) = parser.parse_args()
44 print(
"file for validation", options.valPath,
"file for reference", options.refPath)
45 print(
"Validation release:", options.ValRel,
"Reference release:", options.RefRel)
46 print(
"Validation sample:", options.ValSample,
"Reference sample:", options.RefSample)
47 print(
"Options : batch mode ?", options.batch,
"draw legend ?", options.drawLegend,
"print banner ?", options.printBanner,
"banner is ", options.Banner,
"make ratio plots ?", options.doRatio)
49 if options.valPath
and options.refPath :
50 fileVal = TFile(options.valPath,
"READ")
51 fileRef = TFile(options.refPath,
"READ")
53 if options.batch : ROOT.gROOT.SetBatch()
58 if options.ValSample==options.RefSample : title=options.ValRel+
"vs"+options.RefRel+
" "+options.ValSample+
" "
59 elif options.ValRel==options.RefRel : title=options.ValRel+
" "+options.ValSample+
"_vs_"+options.RefSample+
" "
60 else : title=options.ValRel+
"vs"+options.RefRel+
" "+options.ValSample+
"_vs_"+options.RefSample+
" "
74 for f
in listFlavors :
78 if h.listTagger
is None : h.listTagger=listTag
79 for tag
in h.listTagger :
80 keyHisto = tag+
"_"+h.name+
"_"+b
82 keyHisto = tag+
"_performance_vs_"+h.tagFlavor
87 for f
in listFlavors :
88 path = pathInFile+tag+
"_"+b+
"/"+h.name+
"_"+tag+
"_"+b+f
90 path=path.replace(
"_B_",
"_"+f+
"_")
91 path=path.replace(b+f,b)
94 h_Val[f] = fileVal.Get(path)
95 h_Ref[f] = fileRef.Get(path)
97 print(
"ERROR :", path,
"not found in the roofiles, please check the spelling or check if this histogram is present in the rootdile")
101 if h.name==
"FlavEffVsBEff_B_discr" :
102 for f
in listFlavors :
103 perfAll_Val[f][tag]=h_Val[f]
104 perfAll_Ref[f][tag]=h_Ref[f]
105 perfAll_keys.append(tag)
110 refHistos[keyHisto]=
graphProducer(plot=h,histos=h_Ref,isVal=
False)
112 valHistos[keyHisto]=
histoProducer(plot=h,histos=h_Val,keys=listFlavors,isVal=
True)
113 refHistos[keyHisto]=
histoProducer(plot=h,histos=h_Ref,keys=listFlavors,isVal=
False)
114 if valHistos[keyHisto]
is None or refHistos[keyHisto]
is None :
continue
115 if len(valHistos[keyHisto])!=len(refHistos[keyHisto]) :
print(
"ERROR")
121 ratiosList =
createRatio(valHistos[keyHisto],refHistos[keyHisto])
122 ratios[keyHisto] = ratiosList
126 if options.ValSample == options.RefSample : saveName=options.ValRel+
"vs"+options.RefRel+
"_"+options.ValSample+
"_Val_"+keyHisto+
"_all"
127 elif options.ValRel==options.RefRel : saveName=options.ValRel+
"_"+options.ValSample+
"_vs_"+options.RefSample+
"_Val_"+keyHisto+
"_all"
128 else : saveName=options.ValRel+
"vs"+options.RefRel+
"_"+options.ValSample+
"_vs_"+options.RefSample+
"_Val_"+keyHisto+
"_all"
130 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)
132 if h.name==
"FlavEffVsBEff_B_discr" :
133 for f
in [
"C",
"DUSG"] :
134 for isVal
in [
True,
False] :
135 keyHisto=f+
str(isVal)
137 if isVal : Histos[keyHisto]=
histoProducer(plot=h,histos=perfAll_Val[f],keys=perfAll_keys,isVal=isVal)
138 else : Histos[keyHisto]=
histoProducer(plot=h,histos=perfAll_Ref[f],keys=perfAll_keys,isVal=isVal)
140 if isVal : saveName=options.ValRel+
"_"+options.ValSample+
"_performance_Bvs"+f+
"_allTaggers"
141 else : saveName=options.RefRel+
"_"+options.RefSample+
"_performance_Bvs"+f+
"_allTaggers"
143 if isVal : titleFlav = options.ValRel+
"_"+options.ValSample+
"_performance_Bvs"+f+
"_allTaggers"
144 else : titleFlav = options.RefRel+
"_"+options.RefSample+
"_performanceBvs"+f+
"_allTaggers"
146 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))