ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Reconstruction
Jet
JetValidation
scripts
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
5
import
ROOT
6
import
sys
7
import
argparse
8
import
os.path
9
10
# Control switch
11
IsDebug =
False
12
13
16
17
parser = argparse.ArgumentParser(description=
'Create distributions for many variables and save them in a ROT file'
)
18
19
parser.add_argument(
'inputFile'
, type=str)
20
parser.add_argument(
'outputFile'
, type=str, default=
""
)
21
parser.add_argument(
'--treeName'
, type=str, default=
"physics"
)
22
parser.add_argument(
'--binDic'
, type=str, default=
""
)
23
parser.add_argument(
'-b'
,
'--saveBinning'
, action=
'store_true'
)
24
parser.add_argument(
'-pdf'
,
'--savePDF'
, action=
'store_true'
)
25
parser.add_argument(
'--branchPattern'
, type=str, default=[
"jet_"
,
"MET_"
], nargs=
'*'
)
26
parser.add_argument(
'--histoType'
, type=str, default=
"leadingJetSel"
)
27
28
args = parser.parse_args()
29
30
31
32
33
inFileList = args.inputFile.split(
','
)
34
35
print
(
"inFileList "
, inFileList)
36
print
(
'outputFile'
, args.outputFile)
37
38
inChain = ROOT.TChain(args.treeName)
39
40
for
f
in
inFileList:
41
inChain.AddFile(f)
42
tree = inChain
43
44
45
48
49
from
JetValidation.D3PDHistoBuildLib
import
HistoBuilderFromD3PD,isSupportedType, JetType
50
51
builder = HistoBuilderFromD3PD(tree)
52
53
patterns = args.branchPattern
54
55
def
addAllHistos
( aBranch ):
56
if
isSupportedType(tree.GetBranchType(aBranch)):
57
builder.addHistos(aBranch)
58
def
addleadinJetSelectorHistos
( aBranch ):
59
if
(
"LC"
in
aBranch
or
"EM"
in
aBranch)
and
isSupportedType(tree.GetBranchType(aBranch)):
60
builder.addHistosWithLeadingJetSelectors( JetType(aBranch), aBranch )
61
62
if
args.histoType ==
"leadingJetSel"
:
63
histoAdder = addleadinJetSelectorHistos
64
else
:
65
histoAdder = addAllHistos
66
67
print
(
"Adding branches..."
)
68
for
aBranch
in
sorted(tree.GetSetOfTreeBranchNames()):
69
70
if
any( aBranch.startswith( p )
for
p
in
patterns):
71
histoAdder
( aBranch)
72
73
if
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
81
print
(
"\nRunning event loop..."
)
82
builder.eventLoop()
83
print
(
"Done event loop!"
)
84
85
86
builder.saveHistos(args.outputFile)
87
if
args.savePDF:
88
print
(
"Building a structured pdf..."
)
89
builder.dumpStructuredPDF(args.outputFile.replace(
'.root'
,
'.pdf'
))
90
if
args.saveBinning:
91
print
(
"Saving histo binning..."
)
92
builder.saveHistoBins(args.outputFile.replace(
'.root'
,
'.pck'
))
93
94
#inChain.Close()
95
96
createSimpleDistributions.addleadinJetSelectorHistos
addleadinJetSelectorHistos(aBranch)
Definition
createSimpleDistributions.py:58
createSimpleDistributions.addAllHistos
addAllHistos(aBranch)
Definition
createSimpleDistributions.py:55
createSimpleDistributions.histoAdder
histoAdder
Definition
createSimpleDistributions.py:63
Generated on
for ATLAS Offline Software by
1.17.0