Belle II Software  release-08-01-10
ECLPureCsIStudy.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 """Dump digit information for pure CsI vs CsI(Tl)
13  using 'ParticleGun' to generate single particles
14  enabling pure CsI digitization
15  dump useful in a flat ntuple + enriched mdst
16 
17 Usage:
18  $ basf2 ECLPureCsIStudy.py -- --momentum <number>
19  --fileNamePrefix <name> --elecNoise <number>
20  --photoStatResolution <number>
21  [--beamBkgPath <path_to_files> --pdgCode <integer>]
22 """
23 
24 import glob
25 import argparse
26 import basf2 as b2
27 from simulation import add_simulation
28 from reconstruction import add_reconstruction
29 from mdst import add_mdst_output
30 from beamparameters import add_beamparameters
31 
32 
33 def argparser():
34 
35  parser = argparse.ArgumentParser()
36 
37  parser.add_argument('--momentum',
38  type=float,
39  required=True,
40  help='Fixed momentum of particle equivalent in GeV')
41 
42  parser.add_argument('--fileNamePrefix',
43  required=True,
44  help='Output file name')
45 
46  parser.add_argument('--elecNoise',
47  type=float,
48  required=True,
49  help='Electronics noise energy equivalent in MeV')
50 
51  parser.add_argument('--photoStatResolution',
52  type=float,
53  required=True,
54  help='Sigma for 1 MeV energy deposit')
55 
56  parser.add_argument('--beamBkgPath',
57  help='If you want to add beam background, pass this'
58  'option with path to beam background files.')
59 
60  parser.add_argument('--pdgCode',
61  type=int,
62  help='PDG code of particle'
63  ' For more information:'
64  'http://pdg.lbl.gov/2019/reviews/rpp2018-rev-monte-carlo-numbering.pdf')
65  return parser
66 
67 
68 args = argparser().parse_args()
69 
70 # Create path. Register necessary modules to this path.
71 mainPath = b2.create_path()
72 
73 # Register and add 'EventInfoSetter' module
74 eventInfoSetter = b2.register_module('EventInfoSetter')
75 mainPath.add_module(eventInfoSetter)
76 
77 if args.pdgCode:
78  # single particle generator settings
79  particleGun = b2.register_module('ParticleGun')
80  param_particleGun = {
81  'pdgCodes': [args.pdgCode],
82  'nTracks': 1,
83  'momentumGeneration': 'fixed',
84  'momentumParams': [args.momentum],
85  'thetaGeneration': 'uniform',
86  'thetaParams': [13.0, 30.0],
87  'phiGeneration': 'uniform',
88  'phiParams': [0., 360.],
89  'vertexGeneration': 'uniform',
90  'xVertexParams': [0.0, 0.0],
91  'yVertexParams': [0.0, 0.0],
92  'zVertexParams': [0.0, 0.0],
93  }
94  particleGun.param(param_particleGun)
95  mainPath.add_module(particleGun)
96 else:
97  # Beam parameters
98  beamparameters = add_beamparameters(mainPath, 'Y4S')
99  evtGenInput = b2.register_module('EvtGenInput')
100  mainPath.add_module(evtGenInput)
101 
102 if args.beamBkgPath:
103  # Add beam background
104  bgFiles = glob.glob(args.beamBkgPath + '/*.root')
105  # Simulation
106  add_simulation(mainPath, bkgfiles=bgFiles)
107 else:
108  add_simulation(mainPath)
109 
110 # Reconstruction
111 add_reconstruction(mainPath, components='ECL')
112 
113 # Register and add 'ECLDigitizerPureCsI' module
114 eclDigitizerPureCsI = b2.register_module('ECLDigitizerPureCsI')
115 eclDigitizerPureCsI.param('adcTickFactor', 8)
116 eclDigitizerPureCsI.param('sigmaTrigger', 0.)
117 eclDigitizerPureCsI.param('elecNoise',
118  args.elecNoise)
119 eclDigitizerPureCsI.param('photostatresolution',
120  args.photoStatResolution)
121 eclDigitizerPureCsI.param('sigmaTrigger', 0)
122 eclDigitizerPureCsI.param('LastRing', 12)
123 eclDigitizerPureCsI.param('NoCovMatrix', 1)
124 if args.withBkg:
125  eclDigitizerPureCsI.param('Background', 1)
126 mainPath.add_module(eclDigitizerPureCsI)
127 
128 # Register and add 'ECLDigitCalibratorPureCsI' module
129 eclDigitCalibratorPureCsI = b2.register_module('ECLDigitCalibratorPureCsI')
130 mainPath.add_module(eclDigitCalibratorPureCsI)
131 
132 # Register and add 'ECLReconstructorPureCsI' module
133 eclReconstructorPureCsI = b2.register_module('ECLReconstructorPureCsI')
134 mainPath.add_module(eclReconstructorPureCsI)
135 
136 # Register and add 'ECLDigiStudy' module
137 eclDigiStudy = b2.register_module('ECLDigiStudy')
138 eclDigiStudy.param('outputFileName',
139  args.fileNamePrefix + '_digi')
140 mainPath.add_module(eclDigiStudy)
141 
142 # display = b2.register_module('Display')
143 # mainPath.add_module(display)
144 
145 # Add output mdst file with ECL information
146 add_mdst_output(
147  mainPath,
148  mc=True,
149  filename=args.fileNamePrefix + '.mdst.root',
150  additionalBranches=[
151  'ECLHits',
152  'ECLClustersPureCsI',
153  'ECLDsps',
154  'ECLDspsPureCsI',
155  'ECLDigits',
156  'ECLCalDigits',
157  'ECLDigitsPureCsI',
158  'ECLCalDigitsPureCsI',
159  'ECLDigitsPureCsIToECLDspsPureCsI',
160  'ECLDigitsPureCsIToECLHits'])
161 
162 # Show progress of processing
163 mainPath.add_module('ProgressBar')
164 
165 # Process the events and print call statistics
166 mainPath.add_module('Progress')
167 b2.process(mainPath)
168 print(b2.statistics)