Belle II Software  release-05-01-25
ETF_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': 2,
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 trgcdc = basf2.register_module('TRGCDC')
77 simMode = 0 # 0: full trigger, 1: only TSF
78 if clock:
79  simMode += 2 # 2: full trigger (TSF with clock), 3: only TSF with clock
80 trgcdc_params = {
81  'ConfigFile': Belle2.FileSystem.findFile("data/trg/cdc/TRGCDCConfig_0_20101111.dat"),
82  'InnerTSLUTFile': Belle2.FileSystem.findFile("data/trg/cdc/innerLUT_v3.0.coe"),
83  'OuterTSLUTFile': Belle2.FileSystem.findFile("data/trg/cdc/outerLUT_v3.0.coe"),
84  'SimulationMode': 1, # only fast simulation
85  'FastSimulationMode': simMode,
86  'HoughFinderMappingFileMinus': Belle2.FileSystem.findFile("data/trg/cdc/HoughMappingMinus20160223.dat"),
87  'HoughFinderMappingFilePlus': Belle2.FileSystem.findFile("data/trg/cdc/HoughMappingPlus20160223.dat"),
88  'DebugLevel': 0}
89 trgcdc.param(trgcdc_params)
90 if clock:
91  trgcdc.param('inputCollection', 'CDCHits4Trg')
92 main.add_module(trgcdc)
93 
94 # ETF
95 main.add_module('CDCTriggerETF')
96 
97 
98 # ----------- #
99 # test module #
100 # ----------- #
101 
102 class TestModule(basf2.Module):
103  """
104  test module to compare the output of TRGCDC and CDCTriggerETF
105  """
106 
107  def event(self):
108  """
109  give info for both modules and warnings in the case of mismatches
110  """
111  oldT0 = Belle2.PyStoreObj("CDCTriggerEventTime").obj().getTiming()
112  if Belle2.PyStoreObj("BinnedEventT0").hasBinnedEventT0(Belle2.Const.CDC):
113  newT0 = Belle2.PyStoreObj("BinnedEventT0").obj().getBinnedEventT0(Belle2.Const.CDC)
114  else:
115  newT0 = 9999
116  if oldT0 == newT0:
117  basf2.B2INFO("T0 %d" % oldT0)
118  else:
119  basf2.B2WARNING("old T0 %d, new T0 %d" % (oldT0, newT0))
120 
121 
122 main.add_module(TestModule(), logLevel=basf2.LogLevel.INFO)
123 
124 # Process events
125 basf2.process(main)
126 
127 # Print call statistics
128 print(basf2.statistics)
ETF_OldVsNew.TestModule.event
def event(self)
Definition: ETF_OldVsNew.py:107
Belle2::PyStoreObj
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:69
basf2.process
def process(path, max_event=0)
Definition: __init__.py:25
ETF_OldVsNew.TestModule
Definition: ETF_OldVsNew.py:102
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