ATLAS Offline Software
cmpExerciser.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  JetHypoExerciserCompareAlg,
5  SimpleHypoJetVectorGenerator,
6  RandomSignalHypoJetVectorGenerator,
7  AlwaysSameHelperTool,
8 )
9 
10 from TriggerMenuMT.HLTMenuConfig.Menu import DictFromChainName
11 
12 from TrigHLTJetHypo.TrigJetHypoToolConfig import (
13  trigJetHypoToolHelperFromDict,
14  trigJetHypoToolHelperFromDict_,)
15 
16 from TrigHLTJetHypo.test_cases import test_strings
17 
18 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
19 
20 from TrigHLTJetHypo.ConditionsToolSetterTree import ConditionsToolSetterTree
21 
22 from TrigHLTJetHypo.ConditionsToolSetterFastReduction import \
23  ConditionsToolSetterFastReduction
24 
25 import os
26 
27 
29  n_bkgd=0,
30  bkgd_etmax=50000., # MeV
31  useEtNotE=True):
32 
33  generator = SimpleHypoJetVectorGenerator()
34 
35  generator.ets = [80000. + 1000.*i + 500. for i in range(n_signal)]
36  generator.etas = [0.5* pow(-1, i) for i in range(n_signal)]
37 
38  generator.n_bkgd = n_bkgd
39  generator.bkgd_etmax = bkgd_etmax
40 
41  # generator.bkgd_etamax = 1.0
42 
43  generator.useEtaEtNotEtaE = useEtNotE
44 
45  return generator
46 
47 
49 
50  def __init__(self):
51  pass
52 
53  def make_chain_dict(self):
54  """ChainDict to excercise modifications to CombinationsHelperTool"""
55 
56  chainNameDecoder = DictFromChainName.DictFromChainName()
57 
58  #make a chain dict to be perverted:
59  # its hypoScenario will be overwritten by the value
60  # 'combinationsTest'. This will result in a hardwired chain label
61  # being used.
62  chain_dict = chainNameDecoder.getChainDict(self.chain_name)
63  assert len(chain_dict['chainParts']) == 1
64 
65  chain_dict['chainParts'][0]['hypoScenario'] = 'combinationsTest'
66 
67  return chain_dict
68 
69  def make_helper_tool(self):
70  chain_dict = self._make_chain_dict()
71  print(chain_dict['chainParts'][0])
72  return trigJetHypoToolHelperFromDict(chain_dict)
73 
74  def logfile_name(self):
75  return self.chain_name + '_b' + str(self.n_bkgd) + '_combs.log'
76 
77 
79 
80  def __init__(self,
81  label,
82  fn_frag,
83  mult_string):
84 
85  CombinationsTests.__init__(self)
86  self.chain_name = 'HLT_' + fn_frag
87  self.chain_label = label
88  self.logname = self.chain_name + mult_string + '.log'
89 
90  def make_helper_tools(self):
91 
92  setter1 = ConditionsToolSetterTree('dummyChainName')
93  helper1 = trigJetHypoToolHelperFromDict_(self.chain_label,
94  self.chain_name,
95  setter1)
96 
97  # setter1 = ConditionsToolSetterTree('treeConditionsTreeSetter')
98  # helper1 = trigJetHypoToolHelperFromDict_(self.chain_label,
99  # self.chain_name,
100  # setter1)
101 
102  # setter0 = ConditionsToolSetterFastReduction('frConditionsTreeSetter')
103  # helper0 = trigJetHypoToolHelperFromDict_(self.chain_label,
104  # self.chain_name,
105  # setter0)
106 
107  helper0 = AlwaysSameHelperTool()
108  helper0.passflag = False
109 
110  setter0 = ConditionsToolSetterFastReduction('dummyChainName')
111  helper0 = trigJetHypoToolHelperFromDict_(self.chain_label,
112  self.chain_name,
113  setter0)
114 
115  # helper0 = AlwaysSameHelperTool()
116  # helper0.passflag = False
117 
118  # helper1 = AlwaysSameHelperTool()
119  # helper1.passflag = True
120 
121  return (helper0, helper1)
122 
123 
125  fn_frag,
126  mult_string,
127  event_generator):
128 
129 
130  test_conditions = FastReductionLabeledCompTests(label,
131  fn_frag,
132  mult_string)
133 
134  print(test_conditions.__dict__)
135 
136  ht0, ht1 = test_conditions.make_helper_tools()
137 
138  # print('ht0 = ', ht0)
139  # print('ht1 = ', ht1)
140 
141  jetHypoExerciserAlg=JetHypoExerciserCompareAlg("JetHypoCompareExerciser")
142  jetHypoExerciserAlg.JetHypoHelperTool0 = ht0 # run ufn first
143  # jetHypoExerciserAlg.JetHypoHelperTool1 = ht0
144  jetHypoExerciserAlg.JetHypoHelperTool1 = ht1 # then tree
145 
146  jetHypoExerciserAlg.event_generator = event_generator
147 
148  jetHypoExerciserAlg.visit_debug = True # more evebt debug if True
149 
150  jetHypoExerciserAlg.logname = test_conditions.logname
151 
152 
153  print(jetHypoExerciserAlg)
154 
155  result=ComponentAccumulator()
156  result.addEventAlgo(jetHypoExerciserAlg)
157  return result
158 
159 
160 if __name__ == "__main__":
161  doSimpleGen = True
162  useEtNotE = True
163  if doSimpleGen:
164  n_signal = 6
165  n_background = 10
166  bkgdEmax = 50000.
167  useEtNotE = True
168  event_generator = make_simple_event_generator(
169  n_signal,
170  n_background,
171  bkgdEmax,
172  useEtNotE)
173  mult_string = '_s' + str(n_signal).zfill(2) + '_b' + \
174  str(n_background).zfill(2)
175  else:
176  n_sig_lo = 10
177  n_sig_hi = 15
178  e_sig_lo = 80
179  e_sig_hi = 90
180  eta_sig_hi = 5
181  n_bkgd = 2
182  bkgd_etmax = 50000. # MeV
183  useEtaEtNotEtaE = False
184  event_generator = RandomSignalHypoJetVectorGenerator()
185  event_generator.n_sig_lo = n_sig_lo
186  event_generator.n_sig_hi = n_sig_hi
187  event_generator.e_sig_lo = e_sig_lo * 1000.
188  event_generator.e_sig_hi = e_sig_hi * 1000.
189  event_generator.eta_sig_hi = eta_sig_hi
190  event_generator.n_bkgd = n_bkgd
191  event_generator.bkgd_etmax = bkgd_etmax
192  event_generator.useEtaEtNotEtaE = useEtaEtNotEtaE
193 
194  s_params = [str(p).zfill(2) for p in (
195  n_sig_lo,
196  n_sig_hi,
197  e_sig_lo,
198  e_sig_hi,
199  eta_sig_hi,
200  n_bkgd)]
201 
202  mult_string = '_s%s_%s_%s_%s_%s_b%s' % tuple(s_params)
203 
204  # label_ind = 22 # simplegen, s=5,6
205  # label_ind = 25 # debug label
206  # label_ind = 26 # and
207  # label_ind = 21 # quadjet
208  label_ind = 12 # multithreshold
209  label = test_strings[label_ind]
210  lfn = 'test_case.txt'
211  if(not os.path.exists(lfn)):
212  with open(lfn, 'w') as ofile:
213  ofile.write(label+'\n')
214 
215 
216 
217  fn_frag = {
218  0: 'simple1condComp',
219  1: 'simple2condComp',
220  12: 'NoRootNeeded',
221  21: 'QFBComp',
222  22: 'QFBCompLow',
223  23: 'dijet',
224  24: 'dijeteasy',
225  25: 'debug',
226  26: 'and',
227  }[label_ind]
228 
229  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
230  from AthenaConfiguration.AllConfigFlags import initConfigFlags
231  flags = initConfigFlags()
232  flags.Exec.MaxEvents=10
233  cfg=MainServicesCfg(flags)
234  cfg.merge(JetHypoExerciserCompareCfg(label,
235  fn_frag,
236  mult_string,
237  event_generator)
238  )
239 
240  cfg.run()
241 
242  #f=open("HelloWorld.pkl","wb")
243  #cfg.store(f)
244  #f.close()
cmpExerciser.CombinationsTests
Definition: cmpExerciser.py:48
cmpExerciser.FastReductionLabeledCompTests.logname
logname
Definition: cmpExerciser.py:85
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
cmpExerciser.make_simple_event_generator
def make_simple_event_generator(n_nsignal=4, n_bkgd=0, bkgd_etmax=50000., useEtNotE=True)
Definition: cmpExerciser.py:28
cmpExerciser.FastReductionLabeledCompTests.__init__
def __init__(self, label, fn_frag, mult_string)
Definition: cmpExerciser.py:80
cmpExerciser.CombinationsTests.logfile_name
def logfile_name(self)
Definition: cmpExerciser.py:74
cmpExerciser.CombinationsTests.__init__
def __init__(self)
Definition: cmpExerciser.py:50
cmpExerciser.FastReductionLabeledCompTests.chain_name
chain_name
Definition: cmpExerciser.py:83
cmpExerciser.CombinationsTests.make_chain_dict
def make_chain_dict(self)
Definition: cmpExerciser.py:53
cmpExerciser.FastReductionLabeledCompTests.make_helper_tools
def make_helper_tools(self)
Definition: cmpExerciser.py:90
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
cmpExerciser.CombinationsTests.make_helper_tool
def make_helper_tool(self)
Definition: cmpExerciser.py:69
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
cmpExerciser.FastReductionLabeledCompTests
Definition: cmpExerciser.py:78
Trk::open
@ open
Definition: BinningType.h:40
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
cmpExerciser.FastReductionLabeledCompTests.chain_label
chain_label
Definition: cmpExerciser.py:84
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
cmpExerciser.JetHypoExerciserCompareCfg
def JetHypoExerciserCompareCfg(label, fn_frag, mult_string, event_generator)
Definition: cmpExerciser.py:124
pickleTool.object
object
Definition: pickleTool.py:30
str
Definition: BTagTrackIpAccessor.cxx:11
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15