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