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