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