Belle II Software development
ARICHStandAlone.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12from optparse import OptionParser
13import os
14
15# --------------------------------------------------------------------
16# Example script for ARICH stand alone simulation and reconstruction
17# (only ARICH is simulated, very fast)
18# Instead of tracks from CDC, the track information is taken from MC hits
19# on aerogel plane (ARICHAeroHit).
20# Smearing of track position and direction is applied to mimic tracking
21# resolution.
22# --------------------------------------------------------------------
23
24parser = OptionParser()
25parser.add_option('-n', '--nevents', dest='nevents', default=1000, help='Number of events to process')
26parser.add_option('-f', '--file', dest='filename', default='ARICHEvents.root')
27parser.add_option('-r', '--hepr', action="store_true", dest='hepr', default=False, help='Visualisation with heprep')
28parser.add_option('-o', '--overlap', action="store_true", dest='overlap', default=False, help='Run overlap checker')
29parser.add_option('-b', '--rootbatch', action="store_true", dest='rootbatch',
30 default=False, help='Run analysis root script in batch mode')
31parser.add_option('-m', '--rootoff', action="store_true", dest='rootoff', default=False, help='Do not run root script in the end')
32
33(options, args) = parser.parse_args()
34
35home = os.environ['BELLE2_LOCAL_DIR']
36
37# set specific database tag
38# b2.conditions.override_globaltags(["tagname"])
39# use local database
40# b2.conditions.testing_payloads = ["localdb/database.txt"]
41
42# Suppress messages and warnings during processing:
43b2.set_log_level(b2.LogLevel.ERROR)
44
45# Create path
46main = b2.create_path()
47
48# Set number of events to generate
49eventinfosetter = b2.register_module('EventInfoSetter')
50if not (options.hepr):
51 if not (options.overlap):
52 eventinfosetter.param({'evtNumList': [int(options.nevents)], 'runList': [1]})
53if (options.hepr):
54 eventinfosetter.param({'evtNumList': [1], 'runList': [1]})
55if (options.overlap):
56 eventinfosetter.param({'evtNumList': [1], 'runList': [1]})
57main.add_module(eventinfosetter)
58
59# Histogram manager immediately after master module
60histo = b2.register_module('HistoManager')
61histo.param('histoFileName', 'DQMhistograms.root') # File to save histograms
62main.add_module(histo)
63
64# Gearbox: access to database (xml files)
65main.add_module('Gearbox')
66
67# Geometry
68# only ARICH and magnetic field
69geometry = b2.register_module('Geometry')
70geometry.param('components', [
71 'MagneticField',
72 'ARICH'])
73main.add_module(geometry)
74
75# Particle gun
76particlegun = b2.register_module('ParticleGun')
77particlegun.param('pdgCodes', [211, -211, 321, -321])
78particlegun.param('nTracks', 1)
79# particlegun.param('varyNTracks', True)
80particlegun.param('momentumGeneration', 'uniform')
81particlegun.param('momentumParams', [0.5, 4])
82# particlegun.param('momentumParams', [0.4, 0.8])
83particlegun.param('thetaGeneration', 'uniformCos')
84particlegun.param('thetaParams', [17, 35])
85particlegun.param('phiGeneration', 'uniform')
86particlegun.param('phiParams', [0, 360])
87particlegun.param('vertexGeneration', 'fixed')
88particlegun.param('xVertexParams', [0])
89particlegun.param('yVertexParams', [0])
90particlegun.param('zVertexParams', [0])
91particlegun.param('independentVertices', False)
92main.add_module(particlegun)
93
94# Simulation
95simulation = b2.register_module('FullSim')
96# Visualisation with HepRep
97if (options.hepr):
98 print('Visualisation with HepRep')
99 simulation.param('EnableVisualization', True)
100 simulation.param('UICommandsAtIdle', [
101 '/vis/open HepRepFile',
102 '/vis/scene/create',
103 '/vis/scene/add/volume',
104 '/vis/sceneHandler/attach',
105 '/vis/viewer/flush',
106 '/vis/scene/add/trajectories smooth',
107 '/vis/scene/add/hits'
108 ])
109
110main.add_module(simulation)
111
112# Check for volume intersection/overlaps
113if (options.overlap):
114 print('Check for volume intersection/overlaps')
115 overlapchecker = b2.register_module('OverlapChecker')
116 main.add_module(overlapchecker)
117
118# ARICH digitization
119arichDigi = b2.register_module('ARICHDigitizer')
120main.add_module(arichDigi)
121
122# convert ARICHDigits to ARICHHits
123arichHits = b2.register_module('ARICHFillHits')
124main.add_module(arichHits)
125
126# ARICH reconstruction
127# calculate PID likelihoods for all tracks
128arichreco = b2.register_module('ARICHReconstructor')
129# use MC hits (ARICHAeroHits) instead of reconstructed tracks
130arichreco.param('inputTrackType', 1)
131# store Cherenkov angle information
132arichreco.param('storePhotons', 1)
133main.add_module(arichreco)
134
135# ARICH Ntuple
136# create flat ntuple for performance analysis
137arichNtuple = b2.register_module('ARICHNtuple')
138arichNtuple.param('outputFile', options.filename)
139main.add_module(arichNtuple)
140
141# ARICH DQM
142# create DQM occupancy plots
143arichdqm = b2.register_module('ARICHDQM')
144main.add_module(arichdqm)
145
146# Uncomment to store DataStore content to root file
147# output = register_module('RootOutput')
148# output.param('outputFileName', 'DataStore.root')
149# main.add_module(output)
150
151# Uncomment to show event display
152# display = register_module('Display')
153# display.param('showARICHHits', True)
154# display.param('fullGeometry', True)
155# main.add_module(display)
156
157# Show progress of processing
158main.add_module('Progress')
159
160# Process events
161b2.process(main)
162
163# Print call statistics
164print(b2.statistics)
165
166# Make basic performance plots
167if (options.rootbatch):
168 com = 'root -l -b -q ' + options.filename + ' ' + home + '/arich/utility/scripts/plotEfficiency.C'
169else:
170 com = 'root -l ' + options.filename + ' ' + home + '/arich/utility/scripts/plotEfficiency.C'
171
172if not (options.hepr or options.overlap or options.rootoff):
173 os.system(com)
174
175# Retrieve of the histograms from TCanvas produced by plotEfficiency.C
176com = 'root -l -b -q ' + 'ARICHPerformance.root' + ' ' + home + '/arich/utility/scripts/plotEfficiencyConvertTCanvasToHist.C'
177if not (options.hepr or options.overlap or options.rootoff):
178 os.system(com)