ATLAS Offline Software
Loading...
Searching...
No Matches
TrigEgammaEmulationToolConfigMT.py
Go to the documentation of this file.
2# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3#
4
5from AthenaConfiguration.ComponentFactory import CompFactory
6from TrigEgammaMonitoring.TrigEgammaMonitCategory import single_electron_triggers, single_photon_triggers
7
8#
9# emulator config class
10#
12
13 #
14 # Constructor
15 #
16 def __init__(self, flags, name, triggerList = [],
17 OutputLevel = 0,
18 ElectronTriggerList = single_electron_triggers,
19 PhotonTriggerList = single_photon_triggers):
20
21 self.flags = flags
22 self.name = name
23 self.__chains = []
24 self.TriggerList = triggerList
25 self.OutputLevel = OutputLevel
26 self.ElectronTriggerList = ElectronTriggerList
27 self.PhotonTriggerList = PhotonTriggerList
28
29 # force cofnig file path
35
37
38
39 def core(self):
40 self.update()
41 return self.__emulator
42
43
44 def update(self):
45 for trigger in self.TriggerList:
46 if trigger not in self.__configured_triggers:
47 hypo = self.setupChain(trigger)
48 self.__emulator.HypoTools += [hypo]
49 self.__configured_triggers += trigger
50
51 #
52 # Configure emulator tool
53 #
54 def configure(self):
55
56 from TrigEgammaHypo.TrigEgammaFastCaloHypoTool import createTrigEgammaFastCaloSelectors
57 from TrigEgammaHypo.TrigEgammaPrecisionPhotonHypoTool import createTrigEgammaPrecisionPhotonSelectors
58 from TrigEgammaHypo.TrigEgammaPrecisionElectronHypoTool import TrigEgammaPrecisionElectronCBSelectorCfg
59 from TrigEgammaHypo.TrigEgammaPrecisionElectronHypoTool import TrigEgammaPrecisionElectronLHSelectorCfg
60 from TrigEgammaHypo.TrigEgammaPrecisionElectronHypoTool import TrigEgammaPrecisionElectronDNNSelectorCfg
61
62
63 # create the emulator tool
64 self.__emulator = CompFactory.Trig.TrigEgammaEmulationToolMT( self.name,
65 ElectronTriggerList = self.ElectronTriggerList,
66 PhotonTriggerList = self.PhotonTriggerList )
67
68 # NOTE: will be adapt next
69 self.__emulator.RingerTools = createTrigEgammaFastCaloSelectors(ConfigFilePath = self.FastCaloConfigFilePath)
70 self.__emulator.ElectronLHSelectorTools = TrigEgammaPrecisionElectronLHSelectorCfg(ConfigFilePath = self.ElectronLHConfigFilePath).getPublicTools()
71 self.__emulator.ElectronCBSelectorTools = TrigEgammaPrecisionElectronCBSelectorCfg(ConfigFilePath = self.ElectronCBConfigFilePath).getPublicTools()
72 self.__emulator.ElectronDNNSelectorTools = TrigEgammaPrecisionElectronDNNSelectorCfg(ConfigFilePath = self.ElectronDNNConfigFilePath).getPublicTools()
73 self.__emulator.PhotonCBSelectorTools = createTrigEgammaPrecisionPhotonSelectors(ConfigFilePath = self.PhotonCBConfigFilePath)
74 for tool in self.__emulator.ElectronDNNSelectorTools:
75 tool.skipAmbiguityCut =True
76 for tool in self.__emulator.ElectronLHSelectorTools:
77 tool.skipDeltaPoverP = True
78
79 #
80 # Setup chain by name (only single chains)
81 #
82 def setupChain( self, trigger ):
83
84 import cppyy
85 cppyy.load_library('libElectronPhotonSelectorToolsDict')
86
87 from TriggerMenuMT.HLT.Config.Utility.DictFromChainName import dictFromChainName
88 d = dictFromChainName(self.flags, trigger)
89
90 signature = d['signatures'][0]
91
92 from TrigEgammaHypo.TrigEgammaFastCaloHypoTool import TrigEgammaFastCaloHypoToolFromDict
93 from TrigEgammaHypo.TrigEgammaFastElectronHypoTool import TrigEgammaFastElectronHypoToolFromDict
94 from TrigEgammaHypo.TrigEgammaFastPhotonHypoTool import TrigEgammaFastPhotonHypoToolFromDict
95 from TrigEgammaHypo.TrigEgammaPrecisionCaloHypoTool import TrigEgammaPrecisionCaloHypoToolFromDict
96 from TrigEgammaHypo.TrigEgammaPrecisionElectronHypoTool import TrigEgammaPrecisionElectronHypoToolFromDict
97 from TrigEgammaHypo.TrigEgammaPrecisionPhotonHypoTool import TrigEgammaPrecisionPhotonHypoToolFromDict
98 from TrigEgammaHypo.TrigEgammaPrecisionTrackingHypoTool import TrigEgammaPrecisionTrackingHypoToolFromDict
99
100 # Configure L1Calo
101 L1CaloTool = self.setupL1Calo(trigger + "_Step0" , d)
102 sequence = list()
103 # Configure HLT
104 FastCaloTool = TrigEgammaFastCaloHypoToolFromDict(d, tool = CompFactory.Trig.TrigEgammaEmulationFastCaloHypoTool(trigger+'_Step1') )
105 PrecisionCaloTool = TrigEgammaPrecisionCaloHypoToolFromDict(d, tool = CompFactory.Trig.TrigEgammaEmulationPrecisionCaloHypoTool(trigger+'_Step3'))
106 if signature == 'Electron':
107 isEtCut = bool(d['chainParts'][0]['addInfo'])
108 isIdperf = bool(d['chainParts'][0]['idperfInfo'])
109 FastTool = TrigEgammaFastElectronHypoToolFromDict(d, tool = CompFactory.Trig.TrigEgammaEmulationFastElectronHypoTool(trigger+'_Step2'))
110 if isEtCut:
111 sequence = [FastCaloTool, FastTool, PrecisionCaloTool]
112 elif isIdperf:
113 PrecisionTrackingTool = TrigEgammaPrecisionTrackingHypoToolFromDict(d, tool = CompFactory.Trig.TrigEgammaEmulationPrecisionTrackingHypoTool(trigger+'_Step4'))
114 sequence = [FastCaloTool, FastTool, PrecisionCaloTool, PrecisionTrackingTool]
115 else:
116 PrecisionTrackingTool = TrigEgammaPrecisionTrackingHypoToolFromDict(d, tool = CompFactory.Trig.TrigEgammaEmulationPrecisionTrackingHypoTool(trigger+'_Step4'))
117 PrecisionTool = TrigEgammaPrecisionElectronHypoToolFromDict(d, tool = CompFactory.Trig.TrigEgammaEmulationPrecisionElectronHypoTool(trigger+'_Step5'))
118 sequence = [FastCaloTool, FastTool, PrecisionCaloTool, PrecisionTrackingTool, PrecisionTool]
119 elif signature == 'Photon':
120 isEtCut = bool(d['chainParts'][0]['addInfo'])
121 FastTool = TrigEgammaFastPhotonHypoToolFromDict(d, tool = CompFactory.Trig.TrigEgammaEmulationFastPhotonHypoTool(trigger+'_Step2'))
122 if isEtCut:
123 sequence = [FastCaloTool, FastTool, PrecisionCaloTool]
124 else:
125 PrecisionTool = TrigEgammaPrecisionPhotonHypoToolFromDict(d, tool = CompFactory.Trig.TrigEgammaEmulationPrecisionPhotonHypoTool(trigger+'_Step5'))
126 sequence = [FastCaloTool, FastTool, PrecisionCaloTool, PrecisionTool]
127
128 chain = CompFactory.Trig.TrigEgammaEmulationChain(
129 name = trigger,
130 L1Seed = L1CaloTool,
131 # Steps = [FastCaloTool, FastTool, PrecisionCaloTool, PrecisionTrackingTool, PrecisionTool],
132 Steps = sequence,
133 Chain = trigger,
134 Signature = signature.lower(),
135 OutputLevel = self.OutputLevel
136 )
137
138 return chain
139
140
141
142 #
143 # Configure legacy L1
144 #
145 def setupL1Calo( self, name , info):
146
147 from AthenaConfiguration.ComponentFactory import CompFactory
148 import re
149
150 #chainName = info['chainName']
151 L1Item = info['chainParts'][0]['L1threshold']
152 L1thr = float( re.findall(r'\d+', L1Item)[0] )
153 wp = 0 # default
154
155 # [Default, Tight , Medium, Loose ]
156 HadCoreCutMin = [ 1.0 , 1.0 , 1.0 , 1.0 ]
157 HadCoreCutOff = [-0.2 , -0,2 , -0.2 , -0.2 ]
158 HadCoreSlope = [ 1/23. , 1/23., 1/23., 1/23.]
159 EmIsolCutMin = [ 2.0 , 1.0 , 1.0 , 1.5 ]
160 EmIsolCutOff = [-1.8 , -2.6 , -2.0 , -1.8 ]
161 EmIsolSlope = [ 1/8. , 1/8. , 1/8. , 1/8. ]
162
163 # Configure L1
164 L1CaloTool = CompFactory.Trig.TrigEgammaEmulationL1CaloHypoTool(
165 name = name,
166 L1Item = L1Item,
167 L1Thr = L1thr,
168 HadCoreCutMin = HadCoreCutMin[wp],
169 HadCoreCutOff = HadCoreCutOff[wp],
170 HadCoreSlope = HadCoreSlope[wp],
171 EmIsolCutMin = EmIsolCutMin[wp],
172 EmIsolCutOff = EmIsolCutOff[wp],
173 EmIsolSlope = EmIsolSlope[wp],
174 IsolCutMax = 50,
175 OutputLevel = self.OutputLevel)
176
177 return L1CaloTool
178
179
180
181
182
183
184
185
187
188 from AthenaConfiguration.ComponentFactory import CompFactory
189 triggerList = [
190 "HLT_e17_lhvloose_L1EM15VHI",
191 "HLT_e5_etcut_L1EM3",
192 "HLT_e26_lhtight_L1EM22VHI",
193 "HLT_g20_loose_L1EM15"
194 ]
195
196 '''Function to configures some algorithms in the monitoring system.'''
197 # The following class will make a sequence, configure algorithms, and link
198 from AthenaMonitoring import AthMonitorCfgHelper
199 helper = AthMonitorCfgHelper(inputFlags,'TrigEgammaEmulationToolTestCfg')
200
201 test = helper.addAlgorithm( CompFactory.TrigEgammaEmulationToolTest("EmulationTest") )
202 acc = helper.resobj
203 EgammaMatchTool = CompFactory.TrigEgammaMatchingToolMT()
204 EgammaMatchTool.DeltaR=0.4
205 acc.addPublicTool(EgammaMatchTool)
206
207 emulator = TrigEgammaEmulationToolConfig(inputFlags, "EmulatorTool")
208 emulator.configure()
209
210 emulator.TriggerList += triggerList
211 acc.addPublicTool(emulator.core())
212 test.MatchTool = EgammaMatchTool
213 test.EmulatorTool = emulator.core()
214 test.ElectronTriggerList = [
215 #"HLT_e5_etcut_L1EM3",
216 "HLT_e17_lhvloose_L1EM15VHI",
217 #"HLT_e26_lhtight_L1EM22VHI",
218 ]
219 test.PhotonTriggerList = []
220
221 # include some monitoring histograms
222 basepath = '/HLT/EgammaMon'
223 for trigger in triggerList:
224 cutLabels = ['L1Calo','L2Calo','L2','EFCalo','HLT']
225 monGroup = helper.addGroup( test, trigger, basepath+'/EgammaEmulationTest/'+trigger )
226 monGroup.defineHistogram("decisions", type='TH1I', path='', title="Event Selection; Cut ; Count",
227 xbins=len(cutLabels), xmin=0, xmax=len(cutLabels), xlabels=cutLabels)
228 monGroup.defineHistogram("emulations", type='TH1I', path='', title="Event Selection; Cut ; Count",
229 xbins=len(cutLabels), xmin=0, xmax=len(cutLabels), xlabels=cutLabels)
230
231 return helper.result()
232
233
234
235if __name__=='__main__':
236
237 # Set the Athena configuration flags
238 from AthenaConfiguration.AllConfigFlags import initConfigFlags
239
240 path = '/afs/cern.ch/work/j/jodafons/public/valid_sampleA/AOD_fixCalo.pool.root'
241 flags = initConfigFlags()
242 flags.Input.Files = [path]
243 flags.Input.isMC = True
244 flags.Output.HISTFileName = 'TrigEgammaMonitorOutput.root'
245 flags.lock()
246
247 # Initialize configuration object, add accumulator, merge, and run.
248 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
249 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
250 cfg = MainServicesCfg(flags)
251 cfg.merge(PoolReadCfg(flags))
253 cfg.merge(testAcc)
254
255 # If you want to turn on more detailed messages ...
256 cfg.printConfig(withDetails=False) # set True for exhaustive info
257 cfg.run(-1) #use cfg.run(20) to only run on first 20 events
__init__(self, flags, name, triggerList=[], OutputLevel=0, ElectronTriggerList=single_electron_triggers, PhotonTriggerList=single_photon_triggers)