Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
EfexMonitorAlgorithm.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 #
4 def EfexMonitoringConfig(inputFlags):
5  '''Function to configure LVL1 Efex monitoring algorithm'''
6 
7  # get the component factory - used for merging the algorithm results
8  from AthenaConfiguration.ComponentFactory import CompFactory
9  from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
10  result = ComponentAccumulator()
11 
12  # add algorithm to the helper
13  result.addEventAlgo( CompFactory.EfexMonitorAlgorithm('EfexMonAlg',
14  PackageName='EfexMonitor',
15  LowPtCut = 0.0,
16  HiPtCut = 15000.0,
17  eFexEMTobKeyList = ['L1_eEMRoI', 'L1_eEMxRoI'],
18  eFexTauTobKeyList = ['L1_eTauRoI', 'L1_eTauxRoI']
19  ) )
20 
21  return result
22 
23 
24 def EfexMonitoringHistConfig(flags, eFexAlg):
25  """
26  Book the histograms for the efex monitoring. This is done in a separate method
27  to the algorithm creation (above) because the histograms are based on the list of container keys
28  given to the algorithm, which can be customized by the user before calling this method.
29  """
30  import math
31  from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
32  result = ComponentAccumulator()
33 
34 
35  # make the athena monitoring helper again so we can add groups
36  from TrigT1CaloMonitoring.LVL1CaloMonitoringConfig import L1CaloMonitorCfgHelper
37  helper = L1CaloMonitorCfgHelper(flags,None,'EfexMonitoringCfg')
38  helper.alg = eFexAlg
39 
40  # we don't add the algorithm again, use the supplied one
41  EfexMonAlg = eFexAlg
42  baseGroupName = EfexMonAlg.PackageName
43 
44  # Some helpful variables for declaring the histograms
45  # mainDir = 'L1Calo'
46  trigPath = f'Developer/{eFexAlg.name}/' # Default Directory trigger path for output histos
47  # Map from the key name to the output directory substructure.
48 
49  def pathFromKey(key,prefix="Nominal/"):
50  path=prefix
51  if "DAODSim" in key: path = "DAODSim/"
52  elif "ReSim" in key: path = "ReSim/"
53  elif "Sim" in key: path = "Sim/"
54  if "_eEMx" in key: path += "eEMx"
55  elif "_eEM" in key: path += "eEM"
56  elif "_eTaux" in key: path += "eTAUx"
57  elif "_eTau" in key: path += "eTAU"
58  return path
59 
60  cut_names = ["LowPtCut", "HiPtCut"] # List of cut names, for looping over to separate out histograms into directories
61  cut_vals = [EfexMonAlg.LowPtCut, EfexMonAlg.HiPtCut] # List of values, for looping over to add to histogram titles
62 
63  # First, define the histograms with no Pt cut
64  # add monitoring algorithm to group, with group name and main directory
65 
66  locIdxs = []
67  for phiOct in range(0,8):
68  for etaIdx in range(-25,25):
69  locIdxs += [str(phiOct) + ":" + str(etaIdx)]
70 
71  for containerKey in (list(EfexMonAlg.eFexEMTobKeyList) + list(EfexMonAlg.eFexTauTobKeyList)):
72  helper.defineHistogram(containerKey + '_nTOBs_nocut;h_n'+containerKey+'_nocut', title='Number of '+containerKey+';Number of '+containerKey+';Events',
73  fillGroup = baseGroupName,
74  path=trigPath+pathFromKey(containerKey)+"NoCut",
75  type='TH1I', xbins=100,xmin=-0.5,xmax=99.5)
76  if "Sim" not in containerKey:
77  # don't make these expensive plots for simulation
78  helper.defineHistogram(f"LBN,{containerKey}_nTOBs_nocut;h_"+containerKey+"_nTOBs", title = "Average # of " + containerKey + " TOBs;LBN",
79  fillGroup = baseGroupName + "_" + containerKey,
80  path=trigPath+pathFromKey(containerKey)+"NoCut",
81  type="TH2I",
82  xbins=1,xmin=0,xmax=1,ybins=20,ymin=-0.5,ymax=19.5, opt=['kAddBinsDynamically'])
83 
84 
85  helper.defineDQAlgorithm("Efex_eEM_etaThiMapFilled",
86  hanConfig={"libname":"libdqm_summaries.so","name":"Bins_Equal_Threshold","BinThreshold":"0."},
87  thresholdConfig={"NBins":[1,64*50]}, # currently there is 1 known deadspot in eEM, so that is allowed, anything else is a warning. Error if fully empty
88  )
89  helper.defineDQAlgorithm("Efex_eTAU_etaThiMapFilled",
90  hanConfig={"libname":"libdqm_summaries.so","name":"Bins_Equal_Threshold","BinThreshold":"0."},
91  thresholdConfig={"NBins":[0,64*50]}, # everywhere should be filled, otherwise a warning (error if entirely empty)
92  )
93 
94  # Now define the histograms with low/hi Pt cut
95  for cut_name, cut_val in zip(cut_names, cut_vals):
96  cut_title_addition = '' if (cut_val == 0.0) else ' [Et>=' + '%.1f'%(cut_val/1000) + 'GeV]'
97  # Em first
98  for containerKey in EfexMonAlg.eFexEMTobKeyList:
99  fillGroup = baseGroupName+'_'+containerKey+'_'+cut_name
100  tobStr = containerKey
101  # histograms of eEM variables
102  helper.defineHistogram('nEMTOBs;h_nEmTOBs', title='Number of '+tobStr+'s'+cut_title_addition+';EM '+tobStr+'s;Number of EM '+tobStr+'s',
103  fillGroup=fillGroup,
104  type='TH1I', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=10,xmin=0,xmax=10)
105 
106  helper.defineHistogram('TOBTransverseEnergy;h_TOBTransverseEnergy', title=tobStr+' ET [MeV]'+cut_title_addition,
107  fillGroup=fillGroup,
108  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=100,xmin=0,xmax=50000)
109 
110  helper.defineHistogram('TOBEta;h_TOBEta', title=tobStr+' Eta'+cut_title_addition,
111  fillGroup=fillGroup,
112  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=50,xmin=-2.5,xmax=2.5)
113 
114  helper.defineHistogram('TOBPhi;h_TOBPhi', title=tobStr+' Phi'+cut_title_addition,
115  fillGroup=fillGroup,
116  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=64,xmin=-math.pi,xmax=math.pi)
117 
118  helper.defineHistogram(f"TOBEta,TOBPhi;h_{containerKey}_{cut_name}_EtaPhiMap", title=tobStr+' Count'+cut_title_addition+';#eta;#phi',
119  fillGroup=fillGroup,
120  hanConfig={"display":"SetPalette(55)",
121  "description":f"Inspect for hot/cold spots - check help for list of known hot/coldspots, then check <a href='./detail/h_{containerKey}_{cut_name}_posVsLBN'>detail timeseries</a>. Warning if more than 1 deadspot, but could just be low stats","algorithm":"Efex_eEM_etaThiMapFilled"},
122  type='TH2F',
123  path=(("Expert/Outputs/"+pathFromKey(containerKey,"")) if "Sim" not in containerKey and "x" not in containerKey else trigPath+pathFromKey(containerKey)+cut_name),
124  xbins=50,xmin=-2.5,xmax=2.5,ybins=64,ymin=-math.pi,ymax=math.pi,opt=['kAlwaysCreate'])
125 
126  if "Sim" not in containerKey and "x" not in containerKey:
127  helper.defineHistogram(f"LBN,binNumber;h_{containerKey}_{cut_name}_posVsLBN", title=tobStr+' Count'+cut_title_addition+';LB;50(y-1)+x',
128  fillGroup=fillGroup,
129  hanConfig={"description":f"Timeseries of TOB counts at each location ... y-axis relates to x and y bin numbers from <a href='../h_{containerKey}_{cut_name}_EtaPhiMap'>eta-phi map</a>. Use Projection X1 for 1D plot"},
130  type='TH2I',
131  path="Expert/Outputs/"+pathFromKey(containerKey,"")+"/detail",
132  xbins=1,xmin=0,xmax=10,
133  ybins=64*50,ymin=0.5,ymax=64*50+0.5,opt=['kAddBinsDynamically'])
134 
135  helper.defineHistogram('TOBshelfNumber;h_TOBshelfNumber', title=tobStr+' EM Shelf Number'+cut_title_addition,
136  fillGroup=fillGroup,
137  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=2,xmin=0,xmax=2)
138 
139  helper.defineHistogram('TOBeFEXNumberSh0;h_TOBeFEXNumberShelf0', title=tobStr+' EM Module Number Shelf 0'+cut_title_addition,
140  fillGroup=fillGroup,
141  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=12,xmin=0,xmax=12)
142 
143  helper.defineHistogram('TOBeFEXNumberSh1;h_TOBeFEXNumberShelf1', title=tobStr+' EM Module Number Shelf 1'+cut_title_addition,
144  fillGroup=fillGroup,
145  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=12,xmin=0,xmax=12)
146 
147  helper.defineHistogram('TOBfpga;h_TOBfpga', title=tobStr+' EM FPGA'+cut_title_addition,
148  fillGroup=fillGroup,
149  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=4,xmin=0,xmax=4)
150 
151  helper.defineHistogram('TOBReta;h_TOBReta', title=tobStr+' EM Reta'+cut_title_addition,
152  fillGroup=fillGroup,
153  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name,xbins=250,xmin=0,xmax=1)
154 
155  helper.defineHistogram('TOBRhad;h_TOBRhad', title=tobStr+' EM Rhad'+cut_title_addition,
156  fillGroup=fillGroup,
157  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=250,xmin=0,xmax=1)
158 
159  helper.defineHistogram('TOBWstot;h_TOBWstot', title=tobStr+' EM Wstot'+cut_title_addition,
160  fillGroup=fillGroup,
161  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=250,xmin=0,xmax=1)
162 
163  threshold_labels = ['fail','loose','medium','tight']
164  helper.defineHistogram('TOBReta_threshold;h_TOBReta_threshold', title=tobStr+' EM Reta threshold'+cut_title_addition,
165  fillGroup=fillGroup,
166  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name,xbins=4,xmin=0,xmax=4.0,xlabels=threshold_labels)
167 
168  helper.defineHistogram('TOBRhad_threshold;h_TOBRhad_threshold', title=tobStr+' EM Rhad threshold'+cut_title_addition,
169  fillGroup=fillGroup,
170  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=4,xmin=0,xmax=4.0,xlabels=threshold_labels)
171 
172  helper.defineHistogram('TOBWstot_threshold;h_TOBWstot_threshold', title=tobStr+' EM Wstot threshold'+cut_title_addition,
173  fillGroup=fillGroup,
174  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=4,xmin=0,xmax=4.0,xlabels=threshold_labels)
175 
176  # Now Tau
177  for containerKey in EfexMonAlg.eFexTauTobKeyList:
178  fillGroup = baseGroupName+'_'+containerKey+'_'+cut_name
179  tobStr = containerKey
180  # plotting of eTau variables
181  helper.defineHistogram('nTauTOBs;h_nTauTOBs', title='Number of '+tobStr+'s'+cut_title_addition+';Tau '+tobStr+'s;Number of Tau '+tobStr+'s',
182  fillGroup = fillGroup,
183  type='TH1I', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=10,xmin=0,xmax=10)
184 
185  helper.defineHistogram('tauTOBTransverseEnergy;h_tauTOBTransverseEnergy', title=tobStr+' Tau Transverse Energy [MeV]'+cut_title_addition,
186  fillGroup = fillGroup,
187  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=100,xmin=0,xmax=50000)
188 
189  helper.defineHistogram('tauTOBEta;h_tauTOBEta', title=tobStr+' Tau Eta'+cut_title_addition,
190  fillGroup = fillGroup,
191  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=60,xmin=-2.5,xmax=2.5)
192 
193  helper.defineHistogram('tauTOBPhi;h_tauTOBPhi', title=tobStr+' Tau Phi'+cut_title_addition,
194  fillGroup = fillGroup,
195  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=100,xmin=-math.pi,xmax=math.pi)
196 
197  helper.defineHistogram(f"tauTOBEta,tauTOBPhi;h_{containerKey}_{cut_name}_EtaPhiMap", title='eTAU '+tobStr+' Count'+cut_title_addition+';#eta;#phi',
198  fillGroup = fillGroup,
199  hanConfig={"display":"SetPalette(55)",
200  "description":f"Inspect for hot/cold spots - check help for list of known hot/coldspots, then check <a href='./detail/h_{containerKey}_{cut_name}_posVsLBN'>detail timeseries</a>. Warning if any deadspots/empty, but could just be low stats","algorithm":"Efex_eTAU_etaThiMapFilled"},
201  type='TH2F',
202  path=(("Expert/Outputs/"+pathFromKey(containerKey,"")) if "Sim" not in containerKey and "x" not in containerKey else (trigPath+pathFromKey(containerKey)+cut_name)),
203  xbins=50,xmin=-2.5,xmax=2.5,ybins=64,ymin=-math.pi,ymax=math.pi,opt=['kAlwaysCreate'])
204 
205  if "Sim" not in containerKey and "x" not in containerKey:
206  helper.defineHistogram(f"LBN,binNumber;h_{containerKey}_{cut_name}_posVsLBN", title='eTAU '+tobStr+' Count'+cut_title_addition+';LB;50(y-1)+x',
207  fillGroup=fillGroup,
208  hanConfig={"description":f"Timeseries of TOB counts at each location ... y-axis relates to x and y bin numbers from <a href='../h_{containerKey}_{cut_name}_EtaPhiMap'>eta-phi map</a>. Use Projection X1 for 1D plot"},
209  type='TH2I',
210  path="Expert/Outputs/"+pathFromKey(containerKey,"")+"/detail",
211  xbins=1,xmin=0,xmax=10,
212  ybins=64*50,ymin=0.5,ymax=64*50+0.5,opt=['kAddBinsDynamically'])
213 
214  helper.defineHistogram('tauTOBshelfNumber;h_tauTOBshelfNumber', title=tobStr+' Tau Shelf Number'+cut_title_addition,
215  fillGroup = fillGroup,
216  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=2,xmin=0,xmax=2)
217 
218  helper.defineHistogram('tauTOBeFEXNumberSh0;h_tauTOBeFEXNumberShelf0', title=tobStr+' Tau Module Number Shelf 0'+cut_title_addition,
219  fillGroup = fillGroup,
220  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=12,xmin=0,xmax=12)
221 
222  helper.defineHistogram('tauTOBeFEXNumberSh1;h_tauTOBeFEXNumberShelf1', title=tobStr+' Tau Module Number Shelf 1'+cut_title_addition,
223  fillGroup = fillGroup,
224  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=12,xmin=0,xmax=12)
225 
226 
227  helper.defineHistogram('tauTOBfpga;h_tauTOBfpga', title=tobStr+' Tau FPGA'+cut_title_addition,
228  fillGroup = fillGroup,
229  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=4,xmin=0,xmax=4)
230 
231  helper.defineHistogram('tauTOBRcore;h_tauTOBRcore', title=tobStr+' Tau rCore'+cut_title_addition,
232  fillGroup = fillGroup,
233  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=250,xmin=0,xmax=1)
234 
235  helper.defineHistogram('tauTOBRhad;h_tauTOBRhad', title=tobStr+' Tau rHad'+cut_title_addition,
236  fillGroup = fillGroup,
237  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=250,xmin=0,xmax=1)
238 
239  helper.defineHistogram('tauTOBRcore_threshold;h_tauTOBRcore_threshold', title=tobStr+' Tau rCore threshold'+cut_title_addition,
240  fillGroup = fillGroup,
241  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=4,xmin=0,xmax=4.0, xlabels=threshold_labels)
242 
243  helper.defineHistogram('tauTOBRhad_threshold;h_tauTOBRhad_threshold', title=tobStr+' Tau rHad threshold'+cut_title_addition,
244  fillGroup = fillGroup,
245  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=4,xmin=0,xmax=4.0, xlabels=threshold_labels)
246 
247  helper.defineHistogram('tauTOBthree_threshold;h_tauTOBthree_threshold', title=tobStr+' Tau 3 taus threshold'+cut_title_addition,
248  fillGroup = fillGroup,
249  type='TH1F', path=trigPath+pathFromKey(containerKey)+cut_name, xbins=4,xmin=0,xmax=4.0, xlabels=threshold_labels)
250 
251  acc = helper.result()
252  result.merge(acc)
253  return result
254 
255 
256 if __name__=='__main__':
257  # set input file and config options
258  from AthenaConfiguration.AllConfigFlags import initConfigFlags
259  import glob
260 
261  # MCs processed adding L1_eEMRoI
262  inputs = glob.glob('/eos/user/t/thompson/ATLAS/LVL1_mon/MC_ESD/l1calo.361024.Pythia8EvtGen_A14NNPDF23LO_jetjet_JZ4W.eFex_gFex_2022-01-13T2101.root')
263 
264  flags = initConfigFlags()
265  flags.Input.Files = inputs
266  flags.Output.HISTFileName = 'ExampleMonitorOutput_LVL1_MC.root'
267 
268  flags.lock()
269  flags.dump() # print all the configs
270 
271  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
272  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
273  cfg = MainServicesCfg(flags)
274  cfg.merge(PoolReadCfg(flags))
275 
276  EfexMonitorCfg = EfexMonitoringConfig(flags)
277  cfg.merge(EfexMonitorCfg)
278 
279  # options - print all details of algorithms, very short summary
280  cfg.printConfig(withDetails=False, summariseProps = True)
281 
282  nevents=10
283  cfg.run(nevents)
284 
EfexMonitorAlgorithm.EfexMonitoringHistConfig
def EfexMonitoringHistConfig(flags, eFexAlg)
Definition: EfexMonitorAlgorithm.py:24
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
str
Definition: BTagTrackIpAccessor.cxx:11
EfexMonitorAlgorithm.EfexMonitoringConfig
def EfexMonitoringConfig(inputFlags)
Definition: EfexMonitorAlgorithm.py:4
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69