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