ATLAS Offline Software
JetMonitoringExample.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 #
4 
5 '''@file JetMonitoringExample.py
6 @author P-A. Delsart
7 @date 2019-03-12
8 @brief Example python configuration for the Run III Jet Monitoring
9 '''
10 
11 
13  '''Function to configures some algorithms in the monitoring system.'''
14 
15 
16 
17  # The following class will make a sequence, configure algorithms, and link
18  # them to GenericMonitoringTools
19  from AthenaMonitoring import AthMonitorCfgHelper
20  helper = AthMonitorCfgHelper(inputFlags,'ExampleAthMonitorCfg')
21 
22 
24  from JetMonitoring.JetMonitoringConfig import JetMonAlgSpec, HistoSpec, SelectSpec, ToolSpec
25  #from JetMonitoring.JetStandardHistoSpecs import knownHistos
26 
27  # we use a specialized dictionnary (JetMonAlgSpec) which will be translated into the final C++ tool
28  ak4conf = JetMonAlgSpec(
29  "ak4lcMon",
30  JetContainerName = "AntiKt4LCTopoJets",
31  # TriggerChain = '' , --> no trigger filter yet.
32  )
33 
34  # Then set the list of all histos we want to fill with this alg.
35  # We append each histo specification as arguments of the appendHistos()
36  # method of our specialized dictionnary.
37  # (again, each of this histo spec will be translated as C++ tool and then passed into
38  # 'FillerTools' property of the actual JetMonitoring C++ class)
39 
40  # Now start filling the histo spec list
41  ak4conf.appendHistos(
42  # This python list can be filled with various type of entries :
43  # We can give aliases of standard spec :
44  "pt",
45  "highpt",
46  "m",
47  "eta",
48 
49  "leadingJetsRel",
50 
51  # See knownHistos in JetStandardHistoSpecs.py for the list of standard specification.
52 
53 
54  # or we can directly add our custom histo specification in the form of a HistoSpec :
55  HistoSpec('HECFrac', (50,-0.1,1.4), title="HEC E fraction;HEC frac;" ),
56  # the basic call is : HistoSpec( variable, histobins, title='histotile;xtitle,ytitle')
57 
58 
59  # Say we want a 2nd 'pt' plot but with different a binning than in the standard spec.
60  # WARNING : we can not re-use the same spec name in a given JetMonitoringAlg !!!
61  # so we give a new name AND we specify the actual variable with the argument 'xvar'
62  # (the ':GeV' means the variable is to be set at GeV scale)
63  HistoSpec( 'lowpt', (100,0,150) , title='p_{T};p_{T} [GeV];', xvar='pt:GeV'),
64  # An equivalent solution would have been to clone the existing spec like in :
65  # knownHistos.pt.clone('lowpt',bins= (100,0,200) ),
66 
67 
68  # 2D histos are usually refered to by concatenating vars with a ';' as in 'varx;vary'
69  "pt;m",
70  # if the 'vax;vary' alias doesn't exist in knownHistos but 'varx' and 'vary'
71  # do exist, then a spec fot 'vax;vary' will be automatically generated.
72  "pt;eta",
73 
74 
75  # TProfile : to be done ...
76 
77  # TProfile2D : just use 3 variables. For now the sytem will automatically
78  # interpret it as a TProfile2D (the 3rd variable being profiled)
79  "phi;eta;e", # --> Average Energy vs pt and eta
80 
81 
82  # Histograms build from a selection of filtered jets.
83  # we declare a selection using a SelectSpec dictionnary. Here for central jets :
84  SelectSpec( 'central', # the name of the selection
85  '|eta|<0.5', # selection expression. The form 'min<var<max' is automatically interpreted.
86 
87  # Then give a list of histo specs for the filtered jets
88  # these histos will be put under the 'central/' sub-directory
89  FillerTools = [
90  # exactly the same type of entries as for the JetMonAlgSpec/
91  # we can re-use aliases since we're going in a different path.
92  "pt",
93  "m",
94  "eta",
95  ] ),
96 
97  # another selection : only sub-leading jets
98  SelectSpec( 'subleading',
99  '', # no selection on variables
100  SelectedIndex=1, # force 2nd (sub-leading) jet (we would set 0 for leading jets)
101  path='standardHistos', # force the path where the histos are saved in the final ROOT file
102  FillerTools = [
103  "pt",
104  "m",
105  ] ),
106 
107 
108  SelectSpec( 'highJVF',
109  '0.3<JVF[0]', # JVF is a vector<float> for each jets. Here we cut on the 0th entry of this vector
110  FillerTools = [
111  "pt",
112  ] ),
113  # Selecting jets passing the LooseBad selection from the JetCleaningTool.
114  SelectSpec( 'LooseBadJets',
115  'LooseBad', # this is not in the form 'min<x<max', so it will be assumed 'LooseBad' is an entry existing in JetStandardHistoSpecs.knownSelector
116  FillerTools = [
117  "pt",
118  ] ),
119 
120 
121  )
122 
123 
124 
125  # then we turn the full specification into properly configured algorithm and tools.
126  # we use the method 'toAlg()' defined for the specialized dictionnary 'JetMonAlgSpec'
127  ak4conf.toAlg(helper)
128 
129 
130 
136  def defineHistoForJetTrigg(conf, parentAlg, monhelper , path):
137  # create a monitoring group with the histo path starting from the parentAlg
138  group = monhelper.addGroup(parentAlg, conf.Group, 'Jets/'+parentAlg.JetContainerName)
139  # define the histogram
140  group.defineHistogram('trigPassed,jetVar',title='titletrig', type="TEfficiency", path='jetTrigg', xbins=100 , xmin=0, xmax=500000. ,)
141 
142 
143  from JetMonitoring.JetMonitoringConfig import retrieveVarToolConf
144  trigConf = JetMonAlgSpec( # the usual JetMonAlgSpec
145  "ak4lcTrigMon",
146  JetContainerName = "AntiKt4LCTopoJets",
147  TriggerChain = "HLT_j260",
148  )
149  trigConf.appendHistos(
150  # we pass directly the ToolSpec
151  ToolSpec('JetHistoTriggEfficiency', 'jetTrigg',
152  # below we pass the Properties of this JetHistoTriggEfficiency tool :
153  Group='jetTrigGroup',
154  Var=retrieveVarToolConf("pt"), # In this context we can not just pass a str alias to describe a histo variable
155  # so we use retrieveVarToolConf("pt") which returns a full specification for the "pt" histo variable.
156  ProbeTrigChain="HLT_j260",defineHistoFunc=defineHistoForJetTrigg),
157  )
158 
159  trigConf.toAlg(helper)
160 
161  return helper.result() # the AthMonitorCfgHelper returns an accumulator to be used by the general configuration system.
162 
163 if __name__=='__main__':
164  # Setup logs
165  from AthenaCommon.Logging import log
166  from AthenaCommon.Constants import INFO #,DEBUG
167  log.setLevel(INFO)
168 
169  # Set the Athena configuration flags
170  from AthenaConfiguration.AllConfigFlags import initConfigFlags
171  #fileName = 'TestAOD.root'
172  fileName = '/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/CommonInputs/data16_13TeV.00311321.physics_Main.recon.AOD.r9264/AOD.11038520._000001.pool.root.1'
173  flags = initConfigFlags()
174  flags.Input.Files = [fileName]
175  flags.Input.isMC = False
176  flags.Output.HISTFileName = 'JetExampleMonitorOutput.root'
177  flags.lock()
178 
179  # Initialize configuration object, add accumulator, merge, and run.
180  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
181  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
182  cfg = MainServicesCfg(flags)
183  cfg.merge(PoolReadCfg(flags))
184 
185  exampleMonitorAcc = jetMonitoringExampleConfig(flags)
186 
187  cfg.merge(exampleMonitorAcc)
188  #cfg.run()
189  cfg.run(100)
JetMonitoringConfig.retrieveVarToolConf
def retrieveVarToolConf(alias)
Definition: JetMonitoringConfig.py:584
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:256
Constants
some useful constants -------------------------------------------------—
JetMonitoringExample.jetMonitoringExampleConfig
def jetMonitoringExampleConfig(inputFlags)
Definition: JetMonitoringExample.py:12
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69