ATLAS Offline Software
exerciser.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from TrigHLTJetHypoUnitTests.TrigHLTJetHypoUnitTestsConf import (
4  JetHypoExerciserAlg,
5  SimpleHypoJetVectorGenerator,)
6 
7 from TriggerMenuMT.HLTMenuConfig.Menu import DictFromChainName
8 
9 from TrigHLTJetHypo.TrigJetHypoToolConfig import (
10  trigJetHypoToolHelperFromDict,
11  trigJetHypoToolHelperFromDict_,)
12 
13 from TrigHLTJetHypo.test_cases import test_strings
14 
15 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
16 
17 from TrigHLTJetHypo.ConditionsToolSetterTree import ConditionsToolSetterTree as ConditionsToolSetter
18 
20 
21  def __init__(self,
22  n_conds=6,
23  n_bkgd=4,
24  bkgd_etmax=50000., # MeV
25  run_with_partitions=False):
26 
27  self.n_conds = n_conds
28  self.n_bkgd = n_bkgd
29  self.bkgd_etmax = bkgd_etmax
30  self.run_with_partitions = run_with_partitions
31 
32 
33  def make_chain_dict(self):
34  """Chaindicts for Partion vs flownetwork strudies"""
35 
36  chainNameDecoder = DictFromChainName.DictFromChainName()
37  self.chain_name = 'HLT'
38  for i in range(self.n_conds):
39  self.chain_name += '_j80'
40 
41 
42  chain_dict = chainNameDecoder.getChainDict(self.chain_name)
43  assert len(chain_dict['chainParts']) == self.n_conds
44 
45  if (self.run_with_partitions):
46  for cp in chain_dict['chainParts']:
47  cp['hypoScenario'] = 'simple_partition'
48 
49  return chain_dict
50 
51 
53  generator = SimpleHypoJetVectorGenerator()
54 
55  generator.ets = [80000. + 1000.*i for i in range(self.n_sgnl)]
56  generator.etas = [0.5] * self.n_sgnl
57  generator.n_bkgd = self.n_bkgd
58  generator.bkgd_etmax = self.bkgd_etmax
59 
60  return generator
61 
62  def logfile_name(self, chain_name):
63  if (self.run_with_partitions):
64  lfn = self.chain_name + '_b' + str(self.n_bkgd) + '_part.log'
65  else:
66  lfn = self.chain_name + '_b' + str(self.n_bkgd) + '.log'
67 
68  return lfn
69 
71 
72  def __init__(self,
73  n_sgnl=4,
74  n_bkgd=4,
75  bkgd_etmax=50000., # MeV
76  ):
77  self.n_sgnl = n_sgnl
78  self.n_bkgd = n_bkgd
79  self.bkgd_etmax = bkgd_etmax
80  self.chain_name = 'HLT_j80_L1J20'
81 
82  def make_chain_dict(self):
83  """ChainDict to excercise modifications to CombinationsHelperTool"""
84 
85  chainNameDecoder = DictFromChainName.DictFromChainName()
86 
87  #make a chain dict to be perverted:
88  # its hypoScenario will be overwritten by the value
89  # 'combinationsTest'. This will result in a hardwired chain label
90  # being used.
91  chain_dict = chainNameDecoder.getChainDict(self.chain_name)
92  assert len(chain_dict['chainParts']) == 1
93 
94  chain_dict['chainParts'][0]['hypoScenario'] = 'combinationsTest'
95 
96  return chain_dict
97 
98  def make_helper_tool(self):
99  chain_dict = self._make_chain_dict()
100  print(chain_dict['chainParts'][0])
101  return trigJetHypoToolHelperFromDict(chain_dict)
102 
103 
105  generator = SimpleHypoJetVectorGenerator()
106 
107  generator.ets = [80000. + 1000.*i for i in range(self.n_sgnl)]
108  generator.etas = [0.5] * self.n_sgnl
109 
110  generator.n_bkgd = self.n_bkgd
111  generator.bkgd_etmax = self.bkgd_etmax
112 
113  return generator
114 
115  def logfile_name(self):
116  return self.chain_name + '_b' + str(self.n_bkgd) + '_combs.log'
117 
118 
120 
121  def __init__(self,
122  n_sgnl=4,
123  n_bkgd=4,
124  bkgd_etmax=50000., # MeV
125  ):
126  CombinationsTests.__init__(self, n_sgnl, n_bkgd, bkgd_etmax)
127 
128  def _make_chain_dict(self):
129  """ChainDict to excercise modifications to CombinationsHelperTool"""
130 
131  chain_dict = CombinationsTests.make_chain_dict(self)
132  chain_dict['chainParts'][0]['hypoScenario'] = 'partitionsTest'
133 
134  return chain_dict
135 
136  def make_helper_tool(self):
137  chain_dict = self._make_chain_dict()
138  print(chain_dict['chainParts'][0])
139  return trigJetHypoToolHelperFromDict(chain_dict)
140 
141 
142  def logfile_name(self, chain_name):
143  return chain_name + '_b' + str(self.n_bkgd) + '_parts.log'
144 
145 
147 
148  def __init__(self,
149  n_sgnl=4,
150  n_bkgd=4,
151  bkgd_etmax=20000., # MeV
152  ):
153  # useEtaEtNotEtaE = False
154  CombinationsTests.__init__(self, n_sgnl, n_bkgd, bkgd_etmax)
155  self.chain_name = 'HLT_DijetConditionTests'
156 
157  def make_helper_tool(self):
158  chain_label = """
159  z([]
160  simple([(10et, 0eta320)(20et)])
161  )"""
162 
163 
164  toolSetter = ConditionsToolSetter(self.chain_name)
165  return trigJetHypoToolHelperFromDict_(chain_label,
166  self.chain_name,
167  toolSetter=toolSetter)
168 
169 
170  def logfile_name(self, chain_name):
171  return chain_name + '_s' + str(self.n_sgnl) + '_b' + str(self.n_bkgd)+'.log'
172 
174  generator = SimpleHypoJetVectorGenerator()
175 
176  generator.ets = [80000. + 1000.*i for i in range(self.n_sgnl)]
177  generator.etas = [0.5] * self.n_sgnl
178 
179  # alternate eta signs to get high mass
180  factor = 1
181  for i in range(len(generator.etas)):
182  generator.etas[i] *= factor
183  factor *= -1
184 
185  generator.n_bkgd = self.n_bkgd
186  generator.bkgd_etmax = self.bkgd_etmax
187 
188  return generator
189 
191 
192  def __init__(self,
193  chain_label,
194  n_sgnl=4,
195  n_bkgd=4,
196  bkgd_etmax=20000., # MeV
197  label_ind=0
198  ):
199  CombinationsTests.__init__(self, n_sgnl, n_bkgd, bkgd_etmax)
200  self.chain_name = 'HLT_ConditionTests'
201  self.chain_label = chain_label
202  self.label_ind = label_ind
203 
204  def make_helper_tool(self):
205 
206  toolSetter = ConditionsToolSetter(self.chain_name)
207  return trigJetHypoToolHelperFromDict_(self.chain_label,
208  self.chain_name,
209  toolSetter=toolSetter)
210 
211 
212  def logfile_name(self, chain_name):
213  return '%s_s%d_b%d_l%d' % (chain_name,
214  self.n_sgnl,
215  self.n_bkgd,
216  self.label_ind)
217 
218 
220  generator = SimpleHypoJetVectorGenerator()
221 
222  generator.ets = [80000. + 1000.*i for i in range(self.n_sgnl)]
223  generator.etas = [0.5] * self.n_sgnl
224 
225 
226  # alternate eta signs to get high mass
227  factor = 1
228  for i in range(len(generator.etas)):
229  generator.etas[i] *= factor
230  factor *= -1
231 
232  generator.n_bkgd = self.n_bkgd
233  generator.bkgd_etmax = self.bkgd_etmax
234 
235  return generator
236 
237 
238 
240  n_signal,
241  n_background,
242  bkgdEmax,
243  label_ind=0):
244 
245  # test_conditions = FlowNetworkTests_1(n_sgnl=1, n_bkgd=0)
246  # test_conditions = SimpleFlowNetworkTests(n_sgnl=4, n_bkgd=0)
247  # test_conditions = FlowNetworkVsPartitionsTestsDijets(n_sgnl=4, n_bkgd=0)
248  # test_conditions = FlowNetworkVsCombinationsTests(n_sgnl=4, n_bkgd=0)
249  # test_conditions = SimpleConditionsTests(n_sgnl=4, n_bkgd=0)
250  test_conditions = ConditionsTests(label,
251  n_signal,
252  n_background,
253  bkgdEmax,
254  label_ind)
255 
256  print(test_conditions.__dict__)
257  # test_conditions = CombinationsTests()
258  chain_name = test_conditions.chain_name
259 
260  ht = test_conditions.make_helper_tool()
261 
262  print('ht = ', ht)
263 
264  jetHypoExerciserAlg=JetHypoExerciserAlg("JetHypoExerciser")
265  jetHypoExerciserAlg.JetHypoHelperTool = ht
266  jetHypoExerciserAlg.event_generator = test_conditions.make_event_generator()
267  jetHypoExerciserAlg.visit_debug = True
268 
269  lfn = test_conditions.logfile_name(chain_name)
270 
271  jetHypoExerciserAlg.logname = lfn
272 
273 
274  print(jetHypoExerciserAlg)
275 
276  result=ComponentAccumulator()
277  result.addEventAlgo(jetHypoExerciserAlg)
278  return result
279 
280 
281 
282 if __name__=="__main__":
283 
284  n_signal = 4
285  n_background = 0
286  bkgdEmax = 0.
287  label_ind = 2
288 
289  label = test_strings[label_ind]
290 
291  from AthenaConfiguration.AllConfigFlags import initConfigFlags
292  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
293  flags = initConfigFlags()
294  flags.Exec.MaxEvents=10
295  cfg=MainServicesCfg(flags)
296  cfg.merge(JetHypoExerciserCfg(label,
297  n_signal,
298  n_background,
299  bkgdEmax,
300  label_ind)
301  )
302 
303  cfg.run()
304 
305  #f=open("HelloWorld.pkl","wb")
306  #cfg.store(f)
307  #f.close()
308 
exerciser.PartitionvsFlowNetworkTests.chain_name
chain_name
Definition: exerciser.py:37
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
exerciser.CombinationsTests.make_helper_tool
def make_helper_tool(self)
Definition: exerciser.py:98
exerciser.CombinationsTests.make_event_generator
def make_event_generator(self)
Definition: exerciser.py:104
exerciser.PartitionvsFlowNetworkTests.make_event_generator
def make_event_generator(self)
Definition: exerciser.py:52
exerciser.PartitionsTests.__init__
def __init__(self, n_sgnl=4, n_bkgd=4, bkgd_etmax=50000.)
Definition: exerciser.py:121
exerciser.ConditionsTests.make_helper_tool
def make_helper_tool(self)
Definition: exerciser.py:204
exerciser.SimpleConditionsTests.make_helper_tool
def make_helper_tool(self)
Definition: exerciser.py:157
exerciser.PartitionvsFlowNetworkTests.make_chain_dict
def make_chain_dict(self)
Definition: exerciser.py:33
exerciser.CombinationsTests.bkgd_etmax
bkgd_etmax
Definition: exerciser.py:75
exerciser.CombinationsTests.logfile_name
def logfile_name(self)
Definition: exerciser.py:115
exerciser.SimpleConditionsTests.__init__
def __init__(self, n_sgnl=4, n_bkgd=4, bkgd_etmax=20000.)
Definition: exerciser.py:148
exerciser.PartitionsTests
Definition: exerciser.py:119
exerciser.JetHypoExerciserCfg
def JetHypoExerciserCfg(label, n_signal, n_background, bkgdEmax, label_ind=0)
Definition: exerciser.py:239
exerciser.ConditionsTests.__init__
def __init__(self, chain_label, n_sgnl=4, n_bkgd=4, bkgd_etmax=20000., label_ind=0)
Definition: exerciser.py:192
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:256
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
exerciser.ConditionsTests.make_event_generator
def make_event_generator(self)
Definition: exerciser.py:219
exerciser.PartitionsTests.logfile_name
def logfile_name(self, chain_name)
Definition: exerciser.py:142
exerciser.CombinationsTests.chain_name
chain_name
Definition: exerciser.py:76
exerciser.PartitionvsFlowNetworkTests.run_with_partitions
run_with_partitions
Definition: exerciser.py:26
exerciser.ConditionsTests.label_ind
label_ind
Definition: exerciser.py:196
exerciser.SimpleConditionsTests.make_event_generator
def make_event_generator(self)
Definition: exerciser.py:173
exerciser.PartitionvsFlowNetworkTests.n_conds
n_conds
Definition: exerciser.py:23
exerciser.PartitionvsFlowNetworkTests.n_bkgd
n_bkgd
Definition: exerciser.py:24
exerciser.PartitionvsFlowNetworkTests.__init__
def __init__(self, n_conds=6, n_bkgd=4, bkgd_etmax=50000., run_with_partitions=False)
Definition: exerciser.py:21
exerciser.PartitionsTests.make_helper_tool
def make_helper_tool(self)
Definition: exerciser.py:136
exerciser.SimpleConditionsTests
Definition: exerciser.py:146
exerciser.PartitionvsFlowNetworkTests.logfile_name
def logfile_name(self, chain_name)
Definition: exerciser.py:62
exerciser.CombinationsTests.n_bkgd
n_bkgd
Definition: exerciser.py:74
exerciser.CombinationsTests
Definition: exerciser.py:70
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
exerciser.PartitionvsFlowNetworkTests
Definition: exerciser.py:19
pickleTool.object
object
Definition: pickleTool.py:30
str
Definition: BTagTrackIpAccessor.cxx:11
exerciser.PartitionsTests._make_chain_dict
def _make_chain_dict(self)
Definition: exerciser.py:128
exerciser.CombinationsTests.__init__
def __init__(self, n_sgnl=4, n_bkgd=4, bkgd_etmax=50000.)
Definition: exerciser.py:72
exerciser.SimpleConditionsTests.logfile_name
def logfile_name(self, chain_name)
Definition: exerciser.py:170
exerciser.PartitionvsFlowNetworkTests.bkgd_etmax
bkgd_etmax
Definition: exerciser.py:25
exerciser.ConditionsTests
Definition: exerciser.py:190
exerciser.ConditionsTests.chain_label
chain_label
Definition: exerciser.py:195
exerciser.CombinationsTests.n_sgnl
n_sgnl
Definition: exerciser.py:73
exerciser.ConditionsTests.logfile_name
def logfile_name(self, chain_name)
Definition: exerciser.py:212
exerciser.CombinationsTests.make_chain_dict
def make_chain_dict(self)
Definition: exerciser.py:82