ATLAS Offline Software
createSimpleDistributions.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 from __future__ import print_function
4 
5 # External dependencies
6 import ROOT
7 import sys
8 import argparse
9 import os.path
10 
11 # Control switch
12 IsDebug = False
13 
14 
17 
18 parser = argparse.ArgumentParser(description='Create distributions for many variables and save them in a ROT file')
19 
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")
28 
29 args = parser.parse_args()
30 
31 
32 
33 
34 inFileList = args.inputFile.split(',')
35 
36 print ("inFileList ", inFileList)
37 print ('outputFile', args.outputFile)
38 
39 inChain = ROOT.TChain(args.treeName)
40 
41 for f in inFileList:
42  inChain.AddFile(f)
43 tree = inChain
44 
45 
46 
49 
50 from JetValidation.D3PDHistoBuildLib import HistoBuilderFromD3PD,isSupportedType, JetType
51 
52 builder = HistoBuilderFromD3PD(tree)
53 
54 patterns = args.branchPattern
55 
56 def addAllHistos( aBranch ):
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 )
62 
63 if args.histoType == "leadingJetSel":
64  histoAdder = addleadinJetSelectorHistos
65 else:
66  histoAdder = addAllHistos
67 
68 print ("Adding branches...")
69 for aBranch in sorted(tree.GetSetOfTreeBranchNames()):
70 
71  if any( aBranch.startswith( p ) for p in patterns):
72  histoAdder( aBranch)
73 
74 if args.binDic :
75  if os.path.exists(args.binDic):
76  builder.readHistoBins( args.binDic )
77  else:
78  print ("ERROR : requested to read binning from non existent file : ", args.binDic)
79  exit(2)
80 
81 
82 print ("\nRunning event loop...")
83 builder.eventLoop()
84 print ("Done event loop!")
85 
86 
87 builder.saveHistos(args.outputFile)
88 if args.savePDF:
89  print ("Building a structured pdf...")
90  builder.dumpStructuredPDF(args.outputFile.replace('.root','.pdf'))
91 if args.saveBinning:
92  print ("Saving histo binning...")
93  builder.saveHistoBins(args.outputFile.replace('.root','.pck'))
94 
95 #inChain.Close()
96 
97 
createSimpleDistributions.histoAdder
def histoAdder
Definition: createSimpleDistributions.py:64
createSimpleDistributions.addleadinJetSelectorHistos
def addleadinJetSelectorHistos(aBranch)
Definition: createSimpleDistributions.py:59
calibdata.exit
exit
Definition: calibdata.py:236
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
createSimpleDistributions.addAllHistos
def addAllHistos(aBranch)
Definition: createSimpleDistributions.py:56