Belle II Software  release-08-01-10
TSF_OldVsNew.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import basf2
13 import os
14 import glob
15 from ROOT import gROOT, Belle2
16 gROOT.ProcessLine("gErrorIgnoreLevel = 4000;") # ignore endless root errors for background files...
17 
18 """
19 Compare the CDCTriggerTSFModule output with the old TRGCDCModule,
20 to confirm that the behaviour of the new code is correct.
21 """
22 
23 # ------------ #
24 # user options #
25 # ------------ #
26 
27 # general options
28 seed = 1
29 evtnum = 100
30 clock = True
31 particlegun_params = {
32  'pdgCodes': [-13, 13],
33  'nTracks': 1,
34  'momentumGeneration': 'inversePt',
35  'momentumParams': [0.3, 10.],
36  'thetaGeneration': 'uniform',
37  'thetaParams': [35, 123],
38  'phiGeneration': 'uniform',
39  'phiParams': [0, 360],
40  'vertexGeneration': 'fixed',
41  'xVertexParams': [0.],
42  'yVertexParams': [0.],
43  'zVertexParams': [0.]}
44 usebkg = False
45 bkgdir = '/sw/belle2/bkg/'
46 
47 # ------------------------- #
48 # create path up to trigger #
49 # ------------------------- #
50 
51 # set random seed
52 basf2.set_random_seed(seed)
53 # suppress messages and warnings during processing:
54 basf2.set_log_level(basf2.LogLevel.ERROR)
55 
56 main = basf2.create_path()
57 
58 main.add_module('EventInfoSetter', evtNumList=evtnum)
59 main.add_module('Progress')
60 main.add_module('Gearbox')
61 main.add_module('Geometry', components=['CDC',
62  'MagneticFieldConstant4LimitedRCDC'])
63 particlegun = basf2.register_module('ParticleGun')
64 particlegun.param(particlegun_params)
65 main.add_module(particlegun)
66 main.add_module('FullSim')
67 if usebkg:
68  bkgmixer = basf2.register_module('BeamBkgMixer')
69  bkgfiles = glob.glob(os.path.join(bkgdir, '*[!(PXD)(ECL)]??.root'))
70  bkgmixer.param('backgroundFiles', bkgfiles)
71  bkgmixer.param('components', ['CDC'])
72  main.add_module(bkgmixer)
73 cdcdigitizer = basf2.register_module('CDCDigitizer')
74 if clock:
75  cdcdigitizer.param('TrigTimeJitter', 32.)
76 main.add_module(cdcdigitizer)
77 
78 # ----------- #
79 # CDC trigger #
80 # ----------- #
81 
82 trgcdc = basf2.register_module('TRGCDC')
83 simMode = 1 # 0: full trigger, 1: only TSF
84 if clock:
85  simMode += 2 # 2: full trigger (TSF with clock), 3: only TSF with clock
86 trgcdc_params = {
87  'ConfigFile': Belle2.FileSystem.findFile("data/trg/cdc/TRGCDCConfig_0_20101111.dat"),
88  'InnerTSLUTFile': Belle2.FileSystem.findFile("data/trg/cdc/innerLUT_v3.0.coe"),
89  'OuterTSLUTFile': Belle2.FileSystem.findFile("data/trg/cdc/outerLUT_v3.0.coe"),
90  'SimulationMode': 1, # only fast simulation
91  'FastSimulationMode': simMode,
92  'HoughFinderMappingFileMinus': Belle2.FileSystem.findFile("data/trg/cdc/HoughMappingMinus20160223.dat"),
93  'HoughFinderMappingFilePlus': Belle2.FileSystem.findFile("data/trg/cdc/HoughMappingPlus20160223.dat")}
94 trgcdc.param(trgcdc_params)
95 if clock:
96  trgcdc.param('inputCollection', 'CDCHits4Trg')
97 main.add_module(trgcdc)
98 
99 tsf = basf2.register_module('CDCTriggerTSF')
100 tsf_params = {
101  'InnerTSLUTFile': Belle2.FileSystem.findFile("data/trg/cdc/innerLUT_v3.0.coe"),
102  'OuterTSLUTFile': Belle2.FileSystem.findFile("data/trg/cdc/outerLUT_v3.0.coe"),
103  'TSHitCollectionName': 'TSHits', # to distinguish from old output
104  'ClockSimulation': clock}
105 tsf.param(tsf_params)
106 if clock:
107  tsf.param('CDCHitCollectionName', 'CDCHits4Trg')
108 main.add_module(tsf)
109 
110 
111 # ----------- #
112 # test module #
113 # ----------- #
114 
115 class TestModule(basf2.Module):
116  """
117  test module to compare the output of TRGCDC and CDCTriggerTSF
118  """
119 
120  def event(self):
121  """
122  give info for both output lists and warnings in the case of mismatches
123  """
124  oldHits = Belle2.PyStoreArray("CDCTriggerSegmentHits")
125  newHits = Belle2.PyStoreArray("TSHits")
126  if oldHits.getEntries() == newHits.getEntries():
127  basf2.B2INFO("%d hits" % oldHits.getEntries())
128  else:
129  basf2.B2WARNING("old version: %d, new version: %d" %
130  (oldHits.getEntries(), newHits.getEntries()))
131  for i in range(max(oldHits.getEntries(), newHits.getEntries())):
132  if i < oldHits.getEntries():
133  oldString = "ID %d priority %d LR %d fastest T %d priority T %d found T %d" % \
134  (oldHits[i].getSegmentID(), oldHits[i].getPriorityPosition(),
135  oldHits[i].getLeftRight(), oldHits[i].fastestTime(),
136  oldHits[i].priorityTime(), oldHits[i].foundTime())
137  else:
138  oldString = "no hit"
139  if i < newHits.getEntries():
140  newString = "ID %d priority %d LR %d fastest T %d priority T %d found T %d" % \
141  (newHits[i].getSegmentID(), newHits[i].getPriorityPosition(),
142  newHits[i].getLeftRight(), newHits[i].fastestTime(),
143  newHits[i].priorityTime(), newHits[i].foundTime())
144  else:
145  newString = "no hit"
146  if oldString == newString:
147  basf2.B2INFO(oldString)
148  else:
149  basf2.B2WARNING("old: " + oldString)
150  basf2.B2WARNING("new: " + newString)
151  # check relations
152  if clock:
153  oldCDCRels = oldHits[i].getRelationsTo("CDCHits4Trg")
154  newCDCRels = newHits[i].getRelationsTo("CDCHits4Trg")
155  else:
156  oldCDCRels = oldHits[i].getRelationsTo("CDCHits")
157  newCDCRels = newHits[i].getRelationsTo("CDCHits")
158  if len(oldCDCRels) == len(newCDCRels):
159  basf2.B2INFO("%d related CDCHits" % len(oldCDCRels))
160  else:
161  basf2.B2WARNING("old version: %d related CDCHits" % len(oldCDCRels))
162  basf2.B2WARNING("new version: %d related CDCHits" % len(newCDCRels))
163  for irel in range(max(len(oldCDCRels), len(newCDCRels))):
164  if irel < len(oldCDCRels):
165  oldString = "relation to hit %d, weight %.1f" % \
166  (oldCDCRels[irel].getArrayIndex(), oldCDCRels.weight(irel))
167  else:
168  oldString = "no relation"
169  if irel < len(newCDCRels):
170  newString = "relation to hit %d, weight %.1f" % \
171  (newCDCRels[irel].getArrayIndex(), newCDCRels.weight(irel))
172  else:
173  newString = "no relation"
174  if oldString == newString:
175  basf2.B2INFO(oldString)
176  else:
177  basf2.B2WARNING(oldString)
178  basf2.B2WARNING(newString)
179 
180 
181 main.add_module(TestModule(), logLevel=basf2.LogLevel.INFO)
182 
183 # Process events
184 basf2.process(main)
185 
186 # Print call statistics
187 print(basf2.statistics)
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:148
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72