ATLAS Offline Software
Loading...
Searching...
No Matches
createSimpleDistributions.py
Go to the documentation of this file.
1# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2
3
4# External dependencies
5import ROOT
6import sys
7import argparse
8import os.path
9
10# Control switch
11IsDebug = False
12
13
16
17parser = argparse.ArgumentParser(description='Create distributions for many variables and save them in a ROT file')
18
19parser.add_argument('inputFile', type=str)
20parser.add_argument('outputFile', type=str, default="")
21parser.add_argument('--treeName', type=str, default="physics")
22parser.add_argument('--binDic', type=str, default="")
23parser.add_argument('-b' , '--saveBinning', action='store_true')
24parser.add_argument('-pdf' , '--savePDF', action='store_true')
25parser.add_argument('--branchPattern', type=str, default=["jet_","MET_"], nargs='*')
26parser.add_argument('--histoType', type=str, default="leadingJetSel")
27
28args = parser.parse_args()
29
30
31
32
33inFileList = args.inputFile.split(',')
34
35print ("inFileList ", inFileList)
36print ('outputFile', args.outputFile)
37
38inChain = ROOT.TChain(args.treeName)
39
40for f in inFileList:
41 inChain.AddFile(f)
42tree = inChain
43
44
45
48
49from JetValidation.D3PDHistoBuildLib import HistoBuilderFromD3PD,isSupportedType, JetType
50
51builder = HistoBuilderFromD3PD(tree)
52
53patterns = args.branchPattern
54
55def addAllHistos( aBranch ):
56 if isSupportedType(tree.GetBranchType(aBranch)):
57 builder.addHistos(aBranch)
59 if ("LC" in aBranch or "EM" in aBranch) and isSupportedType(tree.GetBranchType(aBranch)):
60 builder.addHistosWithLeadingJetSelectors( JetType(aBranch), aBranch )
61
62if args.histoType == "leadingJetSel":
63 histoAdder = addleadinJetSelectorHistos
64else:
65 histoAdder = addAllHistos
66
67print ("Adding branches...")
68for aBranch in sorted(tree.GetSetOfTreeBranchNames()):
69
70 if any( aBranch.startswith( p ) for p in patterns):
71 histoAdder( aBranch)
72
73if args.binDic :
74 if os.path.exists(args.binDic):
75 builder.readHistoBins( args.binDic )
76 else:
77 print ("ERROR : requested to read binning from non existent file : ", args.binDic)
78 exit(2)
79
80
81print ("\nRunning event loop...")
82builder.eventLoop()
83print ("Done event loop!")
84
85
86builder.saveHistos(args.outputFile)
87if args.savePDF:
88 print ("Building a structured pdf...")
89 builder.dumpStructuredPDF(args.outputFile.replace('.root','.pdf'))
90if args.saveBinning:
91 print ("Saving histo binning...")
92 builder.saveHistoBins(args.outputFile.replace('.root','.pck'))
93
94#inChain.Close()
95
96