Belle II Software  release-08-01-10
EclDataAnalysis.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 """This steering file shows how to use 'EclDataAnalysis'
13  module to dump ECL-related quantities in an ntuple.
14 
15 Input:
16  File with DST format
17 
18 Output:
19  Ntuple with ECL-related quantities
20 
21 Usage:
22  $ basf2 -i <path_to_input_file> -n <number_of_events>
23  EclDataAnalysis.py [-- --withBkg]
24 """
25 
26 import os
27 import glob
28 import argparse
29 import basf2 as b2
30 from simulation import add_simulation
31 from reconstruction import add_reconstruction
32 
33 
34 def argparser():
35 
36  parser = argparse.ArgumentParser()
37 
38  parser.add_argument('--withBkg',
39  action='store_true',
40  default=False,
41  help='Add beam background'
42  'Default is False i.e. no beam background.')
43  return parser
44 
45 
46 args = argparser().parse_args()
47 
48 # Create path. Register necessary modules to this path.
49 mainPath = b2.create_path()
50 
51 # Register and add 'EventInfoSetter' module and settings
52 eventInfoSetter = b2.register_module('EventInfoSetter')
53 eventInfoSetter.param({'evtNumList': [100],
54  'runList': [1],
55  'expList': [0]})
56 mainPath.add_module(eventInfoSetter)
57 
58 # Random number for generation
59 b2.set_random_seed(123456)
60 
61 # Register and add 'ParticleGun' generator module and settings
62 particleGun = b2.register_module('ParticleGun')
63 param_particleGun = {
64  'pdgCodes': [13], # 13: muon
65  'nTracks': 1,
66  'momentumGeneration': 'fixed',
67  'momentumParams': [0.5],
68  'thetaGeneration': 'uniform',
69  'thetaParams': [0., 30.],
70  'phiGeneration': 'uniform',
71  'phiParams': [0., 360.],
72  'vertexGeneration': 'uniform',
73  'xVertexParams': [0.0, 0.0],
74  'yVertexParams': [0.0, 0.0],
75  'zVertexParams': [0.0, 0.0],
76 }
77 particleGun.param(param_particleGun)
78 mainPath.add_module(particleGun)
79 
80 if args.withBkg:
81  # Add beam background overlay files
82  bgFiles = glob.glob(os.environ['BELLE2_BACKGROUND_DIR'] + '*.root')
83  # Add simulation
84  add_simulation(mainPath, bkgfiles=bgFiles)
85 else:
86  # Simulation
87  add_simulation(mainPath)
88 
89 # Reconstruction
90 add_reconstruction(mainPath)
91 
92 # Register and add 'ECLDataAnalysis' module and settings
93 eclDataAnalysis = b2.register_module('ECLDataAnalysis')
94 eclDataAnalysis.param('rootFileName',
95  'EclDataAnalysis_Test.root')
96 eclDataAnalysis.param('doTracking', 1)
97 eclDataAnalysis.param('doPureCsIStudy', 0)
98 mainPath.add_module(eclDataAnalysis)
99 
100 # Process the events and print call statistics
101 mainPath.add_module('Progress')
102 b2.process(mainPath)
103 print(b2.statistics)