ATLAS Offline Software
JetMonitoringStandard.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2023 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 Main python configuration for the Run III Jet Monitoring
9 '''
10 from AthenaMonitoring.DQConfigFlags import DQDataType
11 from JetMonitoring.JetMonitoringConfig import JetMonAlgSpec, HistoSpec, EventHistoSpec, SelectSpec, VarSpec
12 
13 # *********************************************
14 # Define a list of histograms we want to draw for all jet containers.
15 # Write this list as a list of Jet histo specifications. Read comments below for details on specifications
16 commonHistoSpecs = [
17  # Specification can be simple string.
18  # in this case they are aliases to standard spec has defined in JetStandardHistoSpecs.knownHistos
19  "pt",
20  "highpt",
21  "m",
22  "eta",
23  "rapidity",
24  "phi",
25  "EMFrac",
26  "LArQuality",
27  "AverageLArQF",
28  "HECQuality",
29  "HECFrac",
30  "FracSamplingMax",
31  "FracSamplingMaxIndex",
32  "EM3Frac",
33  "Tile0Frac",
34  "CentroidR",
35  "OotFracClusters5",
36  "OotFracClusters10",
37  "JVF",
38  "JVF[0]",
39  "JVF[1]",
40  "Jvt",
41  "nconstit",
42  "N90Constituents",
43  "leadingJetsRel",
44  "JetConstitScaleMomentum_pt","JetEMScaleMomentum_pt","JetPileupScaleMomentum_pt","JetEtaJESScaleMomentum_pt",
45  "JetConstitScaleMomentum_eta","JetEMScaleMomentum_eta","JetPileupScaleMomentum_eta","JetEtaJESScaleMomentum_eta",
46  "JetConstitScaleMomentum_phi","JetEMScaleMomentum_phi","JetPileupScaleMomentum_phi","JetEtaJESScaleMomentum_phi",
47 
48 
49  # or we can directly add our custom histo specification in the form of a HistoSpec
50  # (HistoSpec is nothing more than a specialized python dictionnary)
51  EventHistoSpec('njets',(100,0.,100.),title="Number of Jets;Njets;"),
52  EventHistoSpec('njetsPt20',(100,0.,100.),title="Number of Jets pT>20 GeV;Njets;"),
53  EventHistoSpec('njetsPt200',(800,0.,8000.),title="Number of Jets pT>200 GeV;Njets;"),
54  # the basic call is : HistoSpec( variable, histobins, title='histotile;xtitle,ytitle')
55 
56 
57  # 2D histos, by concatenating 1D histo specifications :
58  "m;pt",
59  "eta;pt",
60  "eta;phi",
61 
62 
63  # TProfile2D : just use 3 variables. For now the sytem will automatically
64  # interpret it as a TProfile2D (the 3rd variable being profiled)
65  "eta;phi;e", # --> Average Energy vs pt and eta
66  "eta;phi;pt", # --> Average pt vs phi and eta
67 
68  # Histograms build from a selection of filtered jets.
69  # Use a SelectSpec dictionary to define the selection, and the histo to be drawn from it.
70  SelectSpec( 'central', # the name of the selection
71  '|eta|<0.5', # selection expression. The form 'min<var<max' is automatically interpreted.
72  path='CentralJets', # force the path where the histos are saved in the final ROOT file
73  FillerTools = ["pt","m","eta","phi","EMFrac","Tile0Frac","LArQuality","nconstit","N90Constituents",
74  "JetConstitScaleMomentum_pt","JetEMScaleMomentum_pt","JetPileupScaleMomentum_pt","JetEtaJESScaleMomentum_pt",
75  "JetConstitScaleMomentum_eta","JetEMScaleMomentum_eta","JetPileupScaleMomentum_eta","JetEtaJESScaleMomentum_eta",
76  "JetConstitScaleMomentum_phi","JetEMScaleMomentum_phi","JetPileupScaleMomentum_phi","JetEtaJESScaleMomentum_phi",
77  ] ),
78 
79  SelectSpec( 'tilegap3', # the name of the selection
80  '1.0<|eta|<1.4', # selection expression. The form 'min<var<max' is automatically interpreted.
81  path='TileGap3', # force the path where the histos are saved in the final ROOT file
82  FillerTools = ["pt","m","eta","phi","EMFrac","Tile0Frac","HECFrac","LArQuality","nconstit","N90Constituents",
83  ] ),
84 
85  # another selection : only leading jets
86  SelectSpec( 'leading',
87  '', # no selection on variables
88  SelectedIndex=0, # force 1st (leading) jet (we would set 1 for sub-leading jets)
89  path='LeadingJets', # force the path where the histos are saved in the final ROOT file
90  FillerTools = ["pt","m","eta","phi","EMFrac","Tile0Frac","HECFrac","LArQuality","nconstit","N90Constituents",
91  "JetConstitScaleMomentum_pt","JetEMScaleMomentum_pt","JetPileupScaleMomentum_pt","JetEtaJESScaleMomentum_pt",
92  "JetConstitScaleMomentum_eta","JetEMScaleMomentum_eta","JetPileupScaleMomentum_eta","JetEtaJESScaleMomentum_eta",
93  "JetConstitScaleMomentum_phi","JetEMScaleMomentum_phi","JetPileupScaleMomentum_phi","JetEtaJESScaleMomentum_phi",
94  ] ),
95 
96  # another selection : only subleading jets
97  SelectSpec( 'subleading',
98  '', # no selection on variables
99  SelectedIndex=1, # force 2nd (sub-leading) jet
100  path='SubleadingJets', # force the path where the histos are saved in the final ROOT file
101  FillerTools = ["pt","m","eta","phi","EMFrac","Tile0Frac","HECFrac","LArQuality","nconstit","N90Constituents",
102  "JetConstitScaleMomentum_pt","JetEMScaleMomentum_pt","JetPileupScaleMomentum_pt","JetEtaJESScaleMomentum_pt",
103  "JetConstitScaleMomentum_eta","JetEMScaleMomentum_eta","JetPileupScaleMomentum_eta","JetEtaJESScaleMomentum_eta",
104  "JetConstitScaleMomentum_phi","JetEMScaleMomentum_phi","JetPileupScaleMomentum_phi","JetEtaJESScaleMomentum_phi",
105  ] ),
106 
107  # another selection : only very high pT jets
108  SelectSpec( 'highptrange2TeVto8TeV','2000<pt:GeV<8000',path='highptrange2TeVto8TeV',FillerTools = ["highpt","m","eta","phi","eta;phi",] ),
109  SelectSpec( 'highptrange1TeVto2TeV','1000<pt:GeV<2000',path='highptrange1TeVto2TeV',FillerTools = ["highpt","m","eta","phi","eta;phi",] ),
110  SelectSpec( 'highptrange500GeVto1TeV','500<pt:GeV<1000',path='highptrange500GeVto1TeV',FillerTools = ["highpt","m","eta","phi","eta;phi",] ),
111  SelectSpec( 'highptrange200GeVto500GeV','200<pt:GeV<500',path='highptrange200GeVto500GeV',FillerTools = ["highpt","m","eta","phi","eta;phi",] ),
112 
113  # Selecting jets failing the LooseBad selection from the JetCleaningTool.
114  SelectSpec( 'LooseBadFailedJets', 'LooseBad', InverseJetSel=True,
115  FillerTools = ["pt","phi","eta","m","EMFrac","LArQuality","Tile0Frac","HECFrac","nconstit","N90Constituents",
116  "phi;eta","phi;eta;e","phi;eta;pt",
117  ]),
118 
119  # Selecting jets passing the LooseBad selection from the JetCleaningTool.
120  SelectSpec( 'LooseBadJets',
121  'LooseBad', # this is not in the form 'min<x<max', so it will be assumed 'LooseBad' is an entry existing in JetStandardHistoSpecs.knownSelector
122  FillerTools = [ "pt","eta","phi","m","EMFrac","LArQuality","Tile0Frac","HECFrac","nconstit","N90Constituents",
123  "phi;eta","phi;eta;e","phi;eta;pt",
124  ] ),
125  ] # end commonHistoSpecs
126 
127 # Separate these out because they cannot run in cosmics
128 jvfHistosSpec = [
129  SelectSpec( 'highJVF',
130  '0.3<JVF[0]', # JVF is a vector<float> for each jets. Here we cut on the 0th entry of this vector
131  FillerTools = ["pt","m","eta","phi",
132  ] ),
133 ]
134 
135 topoHistosSpec = [
136  # histos common to all topo jets. Energy By Sampling layer plots.
137  HistoSpec("PreSamplerB",(100,0.,200.),title="Energy in PreSamplerB;E;Entries",xvar=VarSpec('EnergyPerSampling[0]')),
138  HistoSpec("EMB1",(100,0.,200.),title="Energy in EMB1;E;Entries",xvar=VarSpec('EnergyPerSampling[1]')),
139  HistoSpec("EMB2",(100,0.,200.),title="Energy in EMB2;E;Entries",xvar=VarSpec('EnergyPerSampling[2]')),
140  HistoSpec("EMB3",(100,0.,200.),title="Energy in EMB3;E;Entries",xvar=VarSpec('EnergyPerSampling[3]')),
141  HistoSpec("PreSamplerE",(100,0.,200.),title="Energy in PreSamplerE;E;Entries",xvar=VarSpec('EnergyPerSampling[4]')),
142  HistoSpec("EME1",(100,0.,200.),title="Energy in EME2;E;Entries",xvar=VarSpec('EnergyPerSampling[5]')),
143  HistoSpec("EME2",(100,0.,200.),title="Energy in EME2;E;Entries",xvar=VarSpec('EnergyPerSampling[6]')),
144  HistoSpec("EME3",(100,0.,200.),title="Energy in EME3;E;Entries",xvar=VarSpec('EnergyPerSampling[7]')),
145  HistoSpec("HEC0",(100,0.,200.),title="Energy in HEC0;E;Entries",xvar=VarSpec('EnergyPerSampling[8]')),
146  HistoSpec("HEC1",(100,0.,200.),title="Energy in HEC1;E;Entries",xvar=VarSpec('EnergyPerSampling[9]')),
147  HistoSpec("HEC2",(100,0.,200.),title="Energy in HEC2;E;Entries",xvar=VarSpec('EnergyPerSampling[10]')),
148  HistoSpec("HEC3",(100,0.,200.),title="Energy in HEC3;E;Entries",xvar=VarSpec('EnergyPerSampling[11]')),
149  HistoSpec("TileBar0",(100,0.,200.),title="Energy in TileBar0;E;Entries",xvar=VarSpec('EnergyPerSampling[12]')),
150  HistoSpec("TileBar1",(100,0.,200.),title="Energy in TileBar1;E;Entries",xvar=VarSpec('EnergyPerSampling[13]')),
151  HistoSpec("TileBar2",(100,0.,200.),title="Energy in TileBar1;E;Entries",xvar=VarSpec('EnergyPerSampling[14]')),
152  HistoSpec("TileGap1",(100,0.,200.),title="Energy in TileGap1;E;Entries",xvar=VarSpec('EnergyPerSampling[15]')),
153  HistoSpec("TileGap2",(100,0.,200.),title="Energy in TileGap2;E;Entries",xvar=VarSpec('EnergyPerSampling[16]')),
154  HistoSpec("TileGap3",(100,0.,200.),title="Energy in TileGap3;E;Entries",xvar=VarSpec('EnergyPerSampling[17]')),
155  HistoSpec("TileExt0",(100,0.,200.),title="Energy in TileExt0;E;Entries",xvar=VarSpec('EnergyPerSampling[18]')),
156  HistoSpec("TileExt1",(100,0.,200.),title="Energy in TileExt1;E;Entries",xvar=VarSpec('EnergyPerSampling[19]')),
157  HistoSpec("TileExt2",(100,0.,200.),title="Energy in TileExt2;E;Entries",xvar=VarSpec('EnergyPerSampling[20]')),
158  HistoSpec("FCAL0",(100,0.,200.),title="Energy in FCAL0;E;Entries",xvar=VarSpec('EnergyPerSampling[21]')),
159  HistoSpec("FCAL1",(100,0.,200.),title="Energy in FCAL1;E;Entries",xvar=VarSpec('EnergyPerSampling[22]')),
160  HistoSpec("FCAL2",(100,0.,200.),title="Energy in FCAL2;E;Entries",xvar=VarSpec('EnergyPerSampling[23]')),
161 ]
162 
163 pflowHistosSpec = [
164  # histos common to all PFlow jets. These are defined in JetStandardHistoSpecs.py
165  "SumPtChargedPFOPt500[0]",
166  "SumPtTrkPt500[0]",
167  "NumTrkPt500[0]",
168  "NumTrkPt1000[0]",
169  "fCharged",
170 ]
171 
172 
173 
174 def jetMonAlgConfig( jetName, inputFlags, truthJetName='', trigger=''):
175  """returns a specification of a JetMonitoringAlg (in the form of a JetMonAlgSpec dictionnary).
176  """
177 
178  # we use a specialized dictionnary (JetMonAlgSpec) which will be translated into the final C++ tool
179  jetAlgConfig = JetMonAlgSpec(
180  jetName+"MonAlg",
181  JetContainerName = jetName,
182  TriggerChain = trigger ,
183  )
184 
185  # the list of histos specifications
186  histoSpecs = []
187 
188  # then add pre-defined lists as defined above :
189  histoSpecs += commonHistoSpecs
190 
191  if inputFlags.DQ.DataType is not DQDataType.Cosmics:
192  histoSpecs += jvfHistosSpec
193 
194  if 'Topo' in jetName:
195  histoSpecs += topoHistosSpec
196  if 'PFlow' in jetName:
197  histoSpecs += pflowHistosSpec
198 
199 
200  if truthJetName != "" :
201  # then add histos showing efficiency and pT responses vs True
202  from JetMonitoring.JetStandardHistoSpecs import responseAndEffSpecMap
203  if truthJetName not in responseAndEffSpecMap:
204  print( "ERROR !! can't schedule a JetHistoResponseAndEff for truth container : ",truthJetName, ". No specification available" )
205  return None
206 
207  histoSpecs +=[ responseAndEffSpecMap[truthJetName] ]
208 
209  # finally all all histos specs to our JetMonitoringAlg specification :
210  jetAlgConfig.appendHistos( * histoSpecs)
211 
212  return jetAlgConfig
213 
214 
215 
216 def standardJetMonitoring(inputFlags):
217  """Standard jet monitoring function to be inserted from top-level algs.
218  returns an a component accumulator as given by AthMonitorCfgHelper.result()
219  Details of what goes into jet monitoring is implemented by dedicated functions such as jetMonAlgConfig().
220  """
221 
222  from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
223  rv = ComponentAccumulator()
224 
225  # do not run monitoring in RAWtoESD
226  if inputFlags.DQ.Environment == 'tier0Raw':
227  return rv
228 
229  from AthenaMonitoring import AthMonitorCfgHelper
230  helper = AthMonitorCfgHelper(inputFlags,'JetMonitoring')
231 
232  # create a list of JetMonitoringAlg specifications
233  jetAlgConfs = []
234 
235  if inputFlags.Reco.EnableHI:
236  if inputFlags.Tracking.doUPC:
237  jetAlgConfs.append(jetMonAlgConfig( "AntiKt4EMPFlowJets", inputFlags))
238  else:
239  jetAlgConfs.append(jetMonAlgConfig( "AntiKt4HIJets", inputFlags))
240  else:
241  # use the helper function defined above :
242  #jetMonAlgConfig( "AntiKt4LCTopoJets", truthJetName="AntiKt4TruthJets"), #How can we make sure truth jets are available ??
243  jetAlgConfs.append(jetMonAlgConfig( "AntiKt4LCTopoJets", inputFlags))
244  jetAlgConfs.append(jetMonAlgConfig( "AntiKt4EMTopoJets", inputFlags))
245  jetAlgConfs.append(jetMonAlgConfig( "AntiKt4EMPFlowJets", inputFlags))
246 
247  # Configure filter tools
248  from AthenaMonitoring.EventFlagFilterToolConfig import EventFlagFilterToolCfg
249 # from AthenaMonitoring.AtlasReadyFilterConfig import AtlasReadyFilterCfg
250  from AthenaMonitoring.BadLBFilterToolConfig import LArBadLBFilterToolCfg
251 # from AthenaMonitoring.FilledBunchFilterToolConfig import FilledBunchFilterToolCfg
252 
253  # schedule each JetMonitoringAlg by invoking the toAlg() methods of the config specification
254  for conf in jetAlgConfs:
255  alg = conf.toAlg(helper)
256  alg.FilterTools = [ EventFlagFilterToolCfg(inputFlags),helper.resobj.popToolsAndMerge(LArBadLBFilterToolCfg(inputFlags))]
257 
258  rv.merge(helper.result()) # the AthMonitorCfgHelper returns an accumulator to be used by the general configuration system.
259  return rv
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
JetMonitoringStandard.jetMonAlgConfig
def jetMonAlgConfig(jetName, inputFlags, truthJetName='', trigger='')
Definition: JetMonitoringStandard.py:174
python.BadLBFilterToolConfig.LArBadLBFilterToolCfg
def LArBadLBFilterToolCfg(inputFlags, origDbTag=None)
Definition: BadLBFilterToolConfig.py:100
JetMonitoringStandard.standardJetMonitoring
def standardJetMonitoring(inputFlags)
Definition: JetMonitoringStandard.py:216
python.EventFlagFilterToolConfig.EventFlagFilterToolCfg
def EventFlagFilterToolCfg(flags, name="EventFlagFilter", doLAr=True, doTile=True, doSCT=True, doCore=True, alwaysReturnTrue=False)
Definition: EventFlagFilterToolConfig.py:5
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28