Belle II Software  release-08-01-10
ETF_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 CDCTrigger2DFitterModule 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 = 1000
30 clock = False
31 particlegun_params = {
32  'pdgCodes': [-13, 13],
33  'nTracks': 2,
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 = 0 # 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  'DebugLevel': 0}
95 trgcdc.param(trgcdc_params)
96 if clock:
97  trgcdc.param('inputCollection', 'CDCHits4Trg')
98 main.add_module(trgcdc)
99 
100 # ETF
101 main.add_module('CDCTriggerETF')
102 
103 
104 # ----------- #
105 # test module #
106 # ----------- #
107 
108 class TestModule(basf2.Module):
109  """
110  test module to compare the output of TRGCDC and CDCTriggerETF
111  """
112 
113  def event(self):
114  """
115  give info for both modules and warnings in the case of mismatches
116  """
117  oldT0 = Belle2.PyStoreObj("CDCTriggerEventTime").obj().getTiming()
118  if Belle2.PyStoreObj("BinnedEventT0").hasBinnedEventT0(Belle2.Const.CDC):
119  newT0 = Belle2.PyStoreObj("BinnedEventT0").obj().getBinnedEventT0(Belle2.Const.CDC)
120  else:
121  newT0 = 9999
122  if oldT0 == newT0:
123  basf2.B2INFO("T0 %d" % oldT0)
124  else:
125  basf2.B2WARNING("old T0 %d, new T0 %d" % (oldT0, newT0))
126 
127 
128 main.add_module(TestModule(), logLevel=basf2.LogLevel.INFO)
129 
130 # Process events
131 basf2.process(main)
132 
133 # Print call statistics
134 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 StoreObjPtr.
Definition: PyStoreObj.h:67