Belle II Software  release-08-01-10
EclPureCsIExample.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 """Pure CsI simulation for the ECL
13 
14 Input:
15  No file is reguired
16 
17 Output:
18  Mdst file named 'Ecl_Pure.mdst.root'
19 
20 Usage:
21  $ basf2 EclPureCsIExample.py [-- --withBkg]
22 """
23 
24 import os
25 import glob
26 import argparse
27 import basf2 as b2
28 from simulation import add_simulation
29 from reconstruction import add_reconstruction
30 
31 
32 def argparser():
33 
34  parser = argparse.ArgumentParser()
35 
36  parser.add_argument('--withBkg',
37  action='store_true',
38  default=False,
39  help='Add beam background'
40  'Default is False i.e. no beam background.')
41  return parser
42 
43 
44 args = argparser().parse_args()
45 
46 # Create path. Register necessary modules to this path.
47 mainPath = b2.create_path()
48 
49 # Register and add 'EventInfoSetter' module and settings
50 eventInfoSetter = b2.register_module('EventInfoSetter')
51 eventInfoSetter.param({'evtNumList': [1000],
52  'runList': [1],
53  'expList': [0]})
54 mainPath.add_module(eventInfoSetter)
55 
56 # Random number for generation
57 b2.set_random_seed(123456)
58 
59 # Register and add 'ParticleGun' generator module and settings
60 particleGun = b2.register_module('ParticleGun')
61 param_particleGun = {
62  'pdgCodes': [22], # 22: photon
63  'nTracks': 1,
64  'momentumGeneration': 'fixed',
65  'momentumParams': [.1],
66  'thetaGeneration': 'uniform',
67  'thetaParams': [13., 150.],
68  'phiGeneration': 'uniform',
69  'phiParams': [0., 360.],
70  'vertexGeneration': 'uniform',
71  'xVertexParams': [0., 0.],
72  'yVertexParams': [0., 0.],
73  'zVertexParams': [0., 0.],
74 }
75 particleGun.param(param_particleGun)
76 mainPath.add_module(particleGun)
77 
78 if args.withBkg:
79  # Add beam background overlay files
80  bgFiles = glob.glob(os.environ['BELLE2_BACKGROUND_DIR'] + '*.root')
81  # Add simulation
82  add_simulation(mainPath, bkgfiles=bgFiles)
83 else:
84  # Simulation
85  add_simulation(mainPath)
86 
87 # Reconstruction
88 add_reconstruction(mainPath)
89 
90 # Register and add 'ECLDigitizerPureCsI' module and settings
91 eclDigitizerPureCsI = b2.register_module('ECLDigitizerPureCsI')
92 eclDigitizerPureCsI.param('adcTickFactor', 8)
93 eclDigitizerPureCsI.param('sigmaTrigger', 0.)
94 eclDigitizerPureCsI.param('elecNoise', 1.3)
95 eclDigitizerPureCsI.param('photostatresolution', 0.4)
96 eclDigitizerPureCsI.param('sigmaTrigger', 0)
97 eclDigitizerPureCsI.param('LastRing', 12)
98 eclDigitizerPureCsI.param('NoCovMatrix', 1)
99 eclDigitizerPureCsI.param('Background', 0)
100 mainPath.add_module(eclDigitizerPureCsI)
101 
102 # Register and add 'ECLDigitCalibratorPureCsI' module
103 eclDigitCalibratorPureCsI = b2.register_module('ECLDigitCalibratorPureCsI')
104 # It is IMPORTANT to set 'simulatePure' to 1 for pure CsI simulation.
105 eclDigitCalibratorPureCsI.param('simulatePure', 1)
106 mainPath.add_module(eclDigitCalibratorPureCsI)
107 
108 # Register and add 'ECLCRFinderPureCsI' module
109 eclCRFinderPureCsI = b2.register_module('ECLCRFinderPureCsI')
110 mainPath.add_module(eclCRFinderPureCsI)
111 
112 # Register and add 'ECLLocalMaximumFinderPureCsI' module
113 eclLocalMaximumFinderPureCsI = b2.register_module('ECLLocalMaximumFinderPureCsI')
114 mainPath.add_module(eclLocalMaximumFinderPureCsI)
115 
116 # Register and add 'ECLSplitterN1PureCsI' module
117 eclSplitterN1PureCsI = b2.register_module('ECLSplitterN1PureCsI')
118 mainPath.add_module(eclSplitterN1PureCsI)
119 
120 # Register and add 'ECLSplitterN2PureCsI' module
121 eclSplitterN2PureCsI = b2.register_module('ECLSplitterN2PureCsI')
122 mainPath.add_module(eclSplitterN2PureCsI)
123 
124 # Register and add 'ECLShowerCorrectorPureCsI' module
125 eclShowerCorrectorPureCsI = b2.register_module('ECLShowerCorrectorPureCsI')
126 mainPath.add_module(eclShowerCorrectorPureCsI)
127 
128 # Register and add 'ECLShowerCalibratorPureCsI' module
129 eclShowerCalibratorPureCsI = b2.register_module('ECLShowerCalibratorPureCsI')
130 mainPath.add_module(eclShowerCalibratorPureCsI)
131 
132 # Register and add 'ECLShowerShapePureCsI' module
133 eclShowerShapePureCsI = b2.register_module('ECLShowerShapePureCsI')
134 mainPath.add_module(eclShowerShapePureCsI)
135 
136 # Register and add 'ECLCovarianceMatrixPureCsI' module
137 eclCovarianceMatrixPureCsI = b2.register_module('ECLCovarianceMatrixPureCsI')
138 mainPath.add_module(eclCovarianceMatrixPureCsI)
139 
140 # Register and add 'ECLFinalizerPureCsI' module
141 eclFinalizerPureCsI = b2.register_module('ECLFinalizerPureCsI')
142 mainPath.add_module(eclFinalizerPureCsI)
143 
144 # Register and add 'MCMatcherECLClustersPureCsI' module
145 mcMatcherECLClustersPureCsI = b2.register_module('MCMatcherECLClustersPureCsI')
146 mainPath.add_module(mcMatcherECLClustersPureCsI)
147 
148 # Register and add 'ECLDataAnalysis' module
149 eclDataAnalysis = b2.register_module('ECLDataAnalysis')
150 eclDataAnalysis.param('writeToRoot', 1)
151 eclDataAnalysis.param('rootFileName', 'Ecl_Pure_CsI_Example.root')
152 eclDataAnalysis.param('doSimulation', 0)
153 eclDataAnalysis.param('doTracking', 1)
154 eclDataAnalysis.param('doPureCsIStudy', 1)
155 mainPath.add_module(eclDataAnalysis)
156 
157 # Register and add 'RootOutput' module
158 outputFile = b2.register_module('RootOutput')
159 outputFile.param('outputFileName', 'Ecl_Pure.mdst.root')
160 mainPath.add_module(outputFile)
161 
162 # Process the events and print call statistics
163 mainPath.add_module('Progress')
164 b2.process(mainPath)
165 print(b2.statistics)