ATLAS Offline Software
GfexMonitorAlgorithm.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 #
5  '''Function to configure LVL1 Gfex algorithm in the monitoring system.'''
6  import math
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  #inputFlags.dump() # print all the configs
12 
13  # use L1Calo's special MonitoringCfgHelper
14  from TrigT1CaloMonitoring.LVL1CaloMonitoringConfig import L1CaloMonitorCfgHelper
15  helper = L1CaloMonitorCfgHelper(flags,CompFactory.GfexMonitorAlgorithm,'GfexMonAlg')
16  GfexMonAlg = helper.alg
17 
18  # add any steering
19  groupName = 'GfexMonitor' # the monitoring group name is also used for the package name
20  GfexMonAlg.PackageName = groupName
21 
22  GfexMonAlg.gFexJetTobKeyList = ["L1_gFexLRJetRoI", "L1_gFexSRJetRoI"]
23  GfexMonAlg.gFexRhoTobKeyList = ["L1_gFexRhoRoI"]
24  GfexMonAlg.gFexGlobalTobKeyList = ["L1_gScalarEJwoj", "L1_gMETComponentsJwoj", "L1_gMHTComponentsJwoj", "L1_gMSTComponentsJwoj"]
25 
26  # Define various quantities
27  devPath = 'Developer/GfexOutput/'
28  expertPath = 'Expert/Outputs/'
29  globTobVarDict = {"gScalarEJwoj":["gFexMet", "gFexSumEt"], "gMETComponentsJwoj":["METx", "METy"], "gMHTComponentsJwoj":["MHTx", "MHTy"], "gMSTComponentsJwoj":["MSTx", "MSTy"]}
30 
31  # "gMETComponentsNoiseCut":["METx_NoiseCut", "METy_NoiseCut"], "gMETComponentsRms":["METx_Rms", "METy_Rms"], "gScalarENoiseCut":["gFexMet_NoiseCut", "gFexSumEt_NoiseCut"], "gScalarERms":["gFexMet_Rms", "gFexSumEt_Rms"]}- these are to be used in the future when rho and NC are fixed
32 
33  keyDirPathMap = {"gFexMet":"gXE/", "gFexSumEt":"gTE/", "METx":"gXE/", "METy":"gXE/", "MHTx":"gMHT/", "MHTy":"gMHT/", "MSTx":"gMST/", "MSTy":"gMST/"}
34 
35  #, "METx_NoiseCut":"gXE_NoiseCut/", "METy_NoiseCut":"gXE_NoiseCut/", "METx_Rms":"gXE_RMS/", "METy_Rms":"gXE_RMS/", "gFexMet_NoiseCut":"gXE_NoiseCut/", "gFexSumEt_NoiseCut":"gTE_NoiseCut/", "gFexMet_Rms":"gTE_RMS/", "gFexSumEt_Rms":"gTE_RMS/"} these are to be used in the future when rho and NC are fixed
36 
37  globTobRangeDict = {"gFexMet":[0, 4e5], "gFexSumEt":[0, 2e6], "METx":[-3e5, 3e5], "METy":[-3e5, 3e5], "MHTx":[-3e5, 3e5], "MHTy":[-3e5, 3e5], "MSTx":[-2e5, 2e5], "MSTy":[-2e5, 2e5]}
38 
39  #, "METx_NoiseCut":[-6e5, 6e5], "METy_NoiseCut":[-6e5, 6e5], "METx_Rms":[-6e5, 6e5], "METy_Rms":[-6e5, 6e5], "gFexMet_NoiseCut":[-1e4, 1e6], "gFexSumEt_NoiseCut":[0, 2.5e6], "gFexMet_Rms":[-1e5, 1e6], "gFexSumEt_Rms":[0, 2e6]} these are to be used in the future when rho and NC are fixed
40 
41 
42 
43  # Define gfex histograms
44  ptCutValuesgLJ = GfexMonAlg.ptCutValuesgLJ
45  ptCutValuesgJ = GfexMonAlg.ptCutValuesgJ
46  gFexJetTobKeyList = GfexMonAlg.gFexJetTobKeyList
47  gFexRhoTobKeyList = GfexMonAlg.gFexRhoTobKeyList
48  gFexGlobalTobKeyList = GfexMonAlg.gFexGlobalTobKeyList
49 
50  # Eta bins description
51  import numpy as np
52  eta_bins = [-4.9, -4.1,-3.5,-3.25,-3.2,-3.1,-2.9,-2.7,-2.5,2.5,2.7,2.9,3.1,3.3,3.25,3.5,4.1,4.9 ]
53  for eta in np.arange (-2.2,2.4,0.2):
54  eta_bins.append(eta)
55 
56  eta_bins = sorted(eta_bins)
57 
58  nbins_total = 32*40
59 
60 
61  helper.defineDQAlgorithm("Gfex_etaPhiMapFilled_gJ",
62  hanConfig={"libname":"libdqm_summaries.so","name":"Bins_Equal_Threshold","BinThreshold":"0"}, # counts empty bins
63  thresholdConfig={"NBins":[0,nbins_total]}, # 0 bins expected empty, warning above that, error if entirely empty (save for known empties)
64  )
65  #nned to put a condition on eta values
66  helper.defineDQAlgorithm("Gfex_etaPhiMapFilled_gLJ",
67  hanConfig={"libname":"libdqm_summaries.so","name":"Bins_Equal_Threshold","BinThreshold":"0"}, # counts empty bins
68  thresholdConfig={"NBins":[0,nbins_total]}, # 0 bins expected empty, warning above that, error if entirely empty (save for known empties)
69  )
70 
71  # Jet TOB list
72  for containerKey in gFexJetTobKeyList:
73  ptCutValues = ptCutValuesgLJ if "LRJet" in containerKey else ptCutValuesgJ
74  for ptCut in ptCutValues:
75 
76  ptCutString = "_CutPt{:.0f}".format(ptCut) if (ptCut != -1) else ""
77  containerKey = containerKey.split("+")[-1] # Needed to remove storeGate prefix if gFexJetTobKeyList is not set above
78 
79  # 1D histograms
80  tobTypeStr = "gFex SRJet" if "SRJet" in containerKey else "gFex LRJet"
81 
82  ptStrTitle = f" - tobEt [200 MeV Scale]>{ptCut}" if ptCut != -1 else ""
83  gPath = "gJ" if "SRJet" in containerKey else "gLJ"
84 
85  helper.defineHistogram(f"{containerKey}Eta{ptCutString};h_{containerKey}Eta{ptCutString}", title="{} #eta{}; #eta; counts".format(tobTypeStr, ptStrTitle), type='TH1F', fillGroup=groupName, path=f"{devPath}{gPath}/", xbins=eta_bins)
86  helper.defineHistogram(f"{containerKey}Phi{ptCutString};h_{containerKey}Phi{ptCutString}", title="{} #phi{}; #phi; counts".format(tobTypeStr, ptStrTitle), type='TH1F', fillGroup=groupName, path=f"{devPath}{gPath}", xbins=32,xmin=-math.pi,xmax=math.pi)
87  helper.defineHistogram(f"{containerKey}Pt{ptCutString};h_{containerKey}Pt{ptCutString}" , title="{} Pt{} ; Pt [MeV] ; counts".format(tobTypeStr, ptStrTitle), type='TH1F', fillGroup=groupName,path=f"{devPath}{gPath}",xbins=100,xmin=-1,xmax=4096)
88 
89  # 2D histograms
90  if gPath == "gJ":
91  helper.defineHistogram(f"{containerKey}Eta{ptCutString},{containerKey}Phi{ptCutString};h_etaphiMap{containerKey}{ptCutString}", title="{} {} #eta vs #phi ; #eta; #phi".format(tobTypeStr, ptStrTitle),
92  type='TH2F',fillGroup=groupName, path=f"{expertPath}{gPath}/",
93  hanConfig={
94  "algorithm": "Gfex_etaPhiMapFilled_gJ",
95  "description":f"Inspect for hot/cold spots - check <a href='./detail/h_{containerKey}{ptCutString}_posVsLBN'>detail timeseries</a>",
96  "display":"SetPalette(55),Draw=COL1Z"
97  },
98  opt=['kAlwaysCreate'],
99  xbins=eta_bins,ybins=32,ymin=-3.2,ymax=3.2)
100 
101 
102  helper.defineHistogram(f"{containerKey}LBN{ptCutString},{containerKey}binNumber{ptCutString};h_{containerKey}{ptCutString}_posVsLBN",title="{} {} LBN vs 40(y-1)+x; LBN; 40(y-1)+x".format(tobTypeStr, ptStrTitle),
103  path=f"{expertPath}{gPath}/detail",
104  fillGroup = groupName,
105  hanConfig={"description":f"x and y correspond to axis bin numbers on <a href='../h_etaphiMap{containerKey}{ptCutString}'/>eta-phi plot</a>. Use this plot to check if hotspot/coldspots affected whole or part of run: turn on Projection X1 to see 1D hist of individual locations"},
106  type='TH2I',
107  xbins=1,xmin=0,xmax=10,
108  ybins=40*32,ymin=0.5,ymax=40*32+0.5,
109  opt=['kAddBinsDynamically','kAlwaysCreate'],merge="merge")
110 
111  if (gPath == "gLJ"):
112  helper.defineHistogram(f"{containerKey}Eta{ptCutString},{containerKey}Phi{ptCutString};h_etaphiMap{containerKey}{ptCutString}", title="{} {} #eta vs #phi ; #eta; #phi".format(tobTypeStr, ptStrTitle),
113  type='TH2F',fillGroup=groupName, path=f"{expertPath}{gPath}/",
114  hanConfig={
115  "algorithm": "Gfex_etaPhiMapFilled_gLJ",
116  "description":f"Inspect for hot/cold spots - check <a href='./detail/h_{containerKey}{ptCutString}_posVsLBN'>detail timeseries</a>",
117  "display":"SetPalette(55),Draw=COL1Z"
118  },
119  opt=['kAlwaysCreate'],
120  xbins=eta_bins, ybins=32,ymin=-3.2,ymax=3.2)
121 
122  helper.defineHistogram(f"{containerKey}LBN{ptCutString},{containerKey}binNumber{ptCutString};h_{containerKey}{ptCutString}_posVsLBN",title="{} {} LBN vs 40(y-1)+x; LBN; 40(y-1)+x".format(tobTypeStr, ptStrTitle),
123  path=f"{expertPath}{gPath}/detail",
124  fillGroup = groupName,
125  hanConfig={"description":f"x and y correspond to axis bin numbers on <a href='../h_etaphiMap{containerKey}{ptCutString}'/>eta-phi plot</a>. Use this plot to check if hotspot/coldspots affected whole or part of run: turn on Projection X1 to see 1D hist of individual locations"},
126  type='TH2I',
127  xbins=1,xmin=0,xmax=10,
128  ybins=40*32,ymin=0.5,ymax=40*32+0.5,
129  opt=['kAddBinsDynamically','kAlwaysCreate'],merge="merge")
130 
131 
132  # Rho TOB list
133  for containerKey in gFexRhoTobKeyList:
134  helper.defineHistogram(f"{containerKey};h_{containerKey}", title=f"{containerKey}; gFexRho Et [MeV]; counts", fillGroup=groupName, type="TH1F", path=f"{devPath}gRHO", xbins=100,xmin=0,xmax=100000)
135 
136  # Global TOB list
137  for containerKey in gFexGlobalTobKeyList:
138  for key, dictVal in globTobVarDict.items():
139  if key in containerKey:
140  varOne, varTwo = dictVal
141  break
142 
143  xminOne, xmaxOne = globTobRangeDict.get(varOne, [0,1e6])
144  xminTwo, xmaxTwo = globTobRangeDict.get(varTwo, [0,1e6])
145 
146  helper.defineHistogram("{};h_{}".format(varOne, varOne), title="{}; {} [MeV]; counts".format(varOne, varOne), type="TH1F", fillGroup=groupName, path=devPath+keyDirPathMap.get(varOne, "gFexGlob/"), xbins=100,xmin=xminOne,xmax=xmaxOne)
147  helper.defineHistogram("{};h_{}".format(varTwo, varTwo), title="{}; {} [MeV]; counts".format(varTwo, varTwo), type="TH1F", fillGroup=groupName, path=devPath+keyDirPathMap.get(varTwo, "gFexGlob/"), xbins=100,xmin=xminTwo,xmax=xmaxTwo)
148 
149 
150  acc = helper.result()
151  result.merge(acc)
152  return result
153 
154 if __name__=='__main__':
155  # set input file and config options
156  from AthenaConfiguration.AllConfigFlags import initConfigFlags
157  import glob
158 
159  # Above MCs processed adding L1_eEMRoI
160  inputs = glob.glob('/afs/cern.ch/user/t/thompson/work/public/LVL1_monbatch/run_sim/l1calo.361106.PowhegPythia8EvtGen_AZNLOCTEQ6L1_Zee.ESD.eFex_2021-05-16T2101.root')
161  flags = initConfigFlags()
162  flags.Input.Files = inputs
163  flags.Output.HISTFileName = 'ExampleMonitorOutput.root'
164  flags.lock()
165  flags.dump() # print all the configs
166 
167  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
168  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
169  cfg = MainServicesCfg(flags)
170  cfg.merge(PoolReadCfg(flags))
171 
172  GfexMonitorCfg = GfexMonitoringConfig(flags)
173  cfg.merge(GfexMonitorCfg)
174  cfg.printConfig(withDetails=False, summariseProps = True)
175 
176  nevents=100
177  cfg.run(nevents)
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
vtune_athena.format
format
Definition: vtune_athena.py:14
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
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.
GfexMonitorAlgorithm.GfexMonitoringConfig
def GfexMonitoringConfig(flags)
Definition: GfexMonitorAlgorithm.py:4
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69