3 from __future__
import print_function
18 parser = argparse.ArgumentParser(description=
'Create distributions for many variables and save them in a ROT file')
20 parser.add_argument(
'inputFile', type=str)
21 parser.add_argument(
'outputFile', type=str, default=
"")
22 parser.add_argument(
'--treeName', type=str, default=
"physics")
23 parser.add_argument(
'--binDic', type=str, default=
"")
24 parser.add_argument(
'-b' ,
'--saveBinning', action=
'store_true')
25 parser.add_argument(
'-pdf' ,
'--savePDF', action=
'store_true')
26 parser.add_argument(
'--branchPattern', type=str, default=[
"jet_",
"MET_"], nargs=
'*')
27 parser.add_argument(
'--histoType', type=str, default=
"leadingJetSel")
29 args = parser.parse_args()
34 inFileList = args.inputFile.split(
',')
36 print (
"inFileList ", inFileList)
37 print (
'outputFile', args.outputFile)
39 inChain = ROOT.TChain(args.treeName)
50 from JetValidation.D3PDHistoBuildLib
import HistoBuilderFromD3PD,isSupportedType, JetType
52 builder = HistoBuilderFromD3PD(tree)
54 patterns = args.branchPattern
57 if isSupportedType(tree.GetBranchType(aBranch)):
58 builder.addHistos(aBranch)
60 if (
"LC" in aBranch
or "EM" in aBranch)
and isSupportedType(tree.GetBranchType(aBranch)):
61 builder.addHistosWithLeadingJetSelectors( JetType(aBranch), aBranch )
63 if args.histoType ==
"leadingJetSel":
64 histoAdder = addleadinJetSelectorHistos
66 histoAdder = addAllHistos
68 print (
"Adding branches...")
69 for aBranch
in sorted(tree.GetSetOfTreeBranchNames()):
71 if any( aBranch.startswith( p )
for p
in patterns):
75 if os.path.exists(args.binDic):
76 builder.readHistoBins( args.binDic )
78 print (
"ERROR : requested to read binning from non existent file : ", args.binDic)
82 print (
"\nRunning event loop...")
84 print (
"Done event loop!")
87 builder.saveHistos(args.outputFile)
89 print (
"Building a structured pdf...")
90 builder.dumpStructuredPDF(args.outputFile.replace(
'.root',
'.pdf'))
92 print (
"Saving histo binning...")
93 builder.saveHistoBins(args.outputFile.replace(
'.root',
'.pck'))