Belle II Software development
Fitter_OldVsNew.py
1#!/usr/bin/env python3
2
3
10
11import basf2
12import numpy as np
13import os
14import glob
15from ROOT import gROOT, Belle2
16gROOT.ProcessLine("gErrorIgnoreLevel = 4000;") # ignore endless root errors for background files...
17
18"""
19Compare the CDCTrigger2DFitterModule output with the old TRGCDCModule,
20to confirm that the behaviour of the new code is correct.
21"""
22
23# ------------ #
24# user options #
25# ------------ #
26
27# general options
28seed = 1
29evtnum = 1000
30clock = False
31particlegun_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.]}
44usebkg = False
45bkgdir = '/sw/belle2/bkg/'
46
47# ------------------------- #
48# create path up to trigger #
49# ------------------------- #
50
51# set random seed
52basf2.set_random_seed(seed)
53# suppress messages and warnings during processing:
54basf2.set_log_level(basf2.LogLevel.ERROR)
55
56main = basf2.create_path()
57
58main.add_module('EventInfoSetter', evtNumList=evtnum)
59main.add_module('Progress')
60main.add_module('Gearbox')
61main.add_module('Geometry', components=['CDC',
62 'MagneticFieldConstant4LimitedRCDC'])
63particlegun = basf2.register_module('ParticleGun')
64particlegun.param(particlegun_params)
65main.add_module(particlegun)
66main.add_module('FullSim')
67if 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)
73cdcdigitizer = basf2.register_module('CDCDigitizer')
74if clock:
75 cdcdigitizer.param('TrigTimeJitter', 32.)
76main.add_module(cdcdigitizer)
77
78# ----------- #
79# CDC trigger #
80# ----------- #
81
82xtsimple = False
83fitdrift = True
84
85trgcdc = basf2.register_module('TRGCDC')
86simMode = 0 # 0: full trigger, 1: only TSF
87if clock:
88 simMode += 2 # 2: full trigger (TSF with clock), 3: only TSF with clock
89trgcdc_params = {
90 'ConfigFile': Belle2.FileSystem.findFile("data/trg/cdc/TRGCDCConfig_0_20101111.dat"),
91 'InnerTSLUTFile': Belle2.FileSystem.findFile("data/trg/cdc/innerLUT_v3.0.coe"),
92 'OuterTSLUTFile': Belle2.FileSystem.findFile("data/trg/cdc/outerLUT_v3.0.coe"),
93 'SimulationMode': 1, # only fast simulation
94 'FastSimulationMode': simMode,
95 'HoughFinderMappingFileMinus': Belle2.FileSystem.findFile("data/trg/cdc/HoughMappingMinus20160223.dat"),
96 'HoughFinderMappingFilePlus': Belle2.FileSystem.findFile("data/trg/cdc/HoughMappingPlus20160223.dat"),
97 'DebugLevel': 0,
98 'Fitter3Ds2DFitDrift': fitdrift,
99 'Fitter3DsXtSimple': xtsimple,
100 '2DfinderCollection': 'TRGCDC2DFinderTracks'}
101trgcdc.param(trgcdc_params)
102if clock:
103 trgcdc.param('inputCollection', 'CDCHits4Trg')
104main.add_module(trgcdc, logLevel=basf2.LogLevel.INFO)
105
106# fitters
107main.add_module('CDCTriggerETF')
108main.add_module('CDCTrigger2DFitter', logLevel=basf2.LogLevel.INFO,
109 minHits=2, useDriftTime=fitdrift, xtSimple=xtsimple,
110 outputCollectionName='FitterTracks') # to distinguish from old output
111main.add_module('CDCTrigger3DFitter', logLevel=basf2.LogLevel.INFO,
112 xtSimple=xtsimple,
113 inputCollectionName='FitterTracks',
114 outputCollectionName='Fitter3DTracks') # to distinguish from old output
115
116
117# ----------- #
118# test module #
119# ----------- #
120
121class TestModule(basf2.Module):
122 """
123 test module to compare the output of TRGCDC and CDCTrigger2DFitter/CDCTrigger3DFitter
124 """
125
126 def event(self):
127 """
128 give info for both output lists and warnings in the case of mismatches
129 """
130 oldTracks = Belle2.PyStoreArray("Trg3DFitterTracks")
131 newTracks = Belle2.PyStoreArray("Fitter3DTracks")
132 if oldTracks.getEntries() == newTracks.getEntries():
133 basf2.B2INFO(f"{int(oldTracks.getEntries())} tracks")
134 else:
135 basf2.B2WARNING(f"old version: {int(oldTracks.getEntries())}, new version: {int(newTracks.getEntries())}")
136 for i in range(max(oldTracks.getEntries(), newTracks.getEntries())):
137 if i < oldTracks.getEntries():
138 ptfactor = 0.3 * 1.5 / 100 * 222.376063
139 oldString = f"phi {oldTracks[i].getPhi0() * 180. / np.pi:.3f} pt " + \
140 f"{oldTracks[i].getTransverseMomentum(1.5) / ptfactor:.3f} charge {oldTracks[i].getChargeSign():d} " + \
141 f"chi2 {oldTracks[i].getChi2D():.3f} z {oldTracks[i].getZ0():.3f} cot {oldTracks[i].getCotTheta():.3f} " + \
142 f"chi2 {oldTracks[i].getChi3D():.3f}"
143 else:
144 oldString = "no track"
145 if i < newTracks.getEntries():
146 newString = f"phi {newTracks[i].getPhi0() * 180. / np.pi:.3f} pt {newTracks[i].getTransverseMomentum(1.5):.3f} " + \
147 f"charge {newTracks[i].getChargeSign():d} chi2 {newTracks[i].getChi2D():.3f} z {newTracks[i].getZ0():.3f} " + \
148 f"cot {newTracks[i].getCotTheta():.3f} chi2 {newTracks[i].getChi3D():.3f}"
149 else:
150 newString = "no track"
151 if oldString == newString:
152 basf2.B2INFO(oldString)
153 else:
154 basf2.B2WARNING("old: " + oldString)
155 basf2.B2WARNING("new: " + newString)
156
157
158main.add_module(TestModule(), logLevel=basf2.LogLevel.INFO)
159
160# Process events
161basf2.process(main)
162
163# Print call statistics
164print(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