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