Belle II Software  release-08-01-10
ARICHStandAlone.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2 as b2
12 from optparse import OptionParser
13 import 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 
24 parser = OptionParser()
25 parser.add_option('-n', '--nevents', dest='nevents', default=1000, help='Number of events to process')
26 parser.add_option('-f', '--file', dest='filename', default='ARICHEvents.root')
27 parser.add_option('-r', '--hepr', action="store_true", dest='hepr', default=False, help='Visualisation with heprep')
28 parser.add_option('-o', '--overlap', action="store_true", dest='overlap', default=False, help='Run overlap checker')
29 parser.add_option('-b', '--rootbatch', action="store_true", dest='rootbatch',
30  default=False, help='Run analysis root script in batch mode')
31 parser.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 
35 home = 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:
43 b2.set_log_level(b2.LogLevel.ERROR)
44 
45 # Create path
46 main = b2.create_path()
47 
48 # Set number of events to generate
49 eventinfosetter = b2.register_module('EventInfoSetter')
50 if not (options.hepr):
51  if not (options.overlap):
52  eventinfosetter.param({'evtNumList': [int(options.nevents)], 'runList': [1]})
53 if (options.hepr):
54  eventinfosetter.param({'evtNumList': [1], 'runList': [1]})
55 if (options.overlap):
56  eventinfosetter.param({'evtNumList': [1], 'runList': [1]})
57 main.add_module(eventinfosetter)
58 
59 # Histogram manager immediately after master module
60 histo = b2.register_module('HistoManager')
61 histo.param('histoFileName', 'DQMhistograms.root') # File to save histograms
62 main.add_module(histo)
63 
64 # Gearbox: access to database (xml files)
65 main.add_module('Gearbox')
66 
67 # Geometry
68 # only ARICH and magnetic field
69 geometry = b2.register_module('Geometry')
70 geometry.param('components', [
71  'MagneticField',
72  'ARICH'])
73 main.add_module(geometry)
74 
75 # Particle gun
76 particlegun = b2.register_module('ParticleGun')
77 particlegun.param('pdgCodes', [211, -211, 321, -321])
78 particlegun.param('nTracks', 1)
79 # particlegun.param('varyNTracks', True)
80 particlegun.param('momentumGeneration', 'uniform')
81 particlegun.param('momentumParams', [0.5, 4])
82 # particlegun.param('momentumParams', [0.4, 0.8])
83 particlegun.param('thetaGeneration', 'uniformCos')
84 particlegun.param('thetaParams', [17, 35])
85 particlegun.param('phiGeneration', 'uniform')
86 particlegun.param('phiParams', [0, 360])
87 particlegun.param('vertexGeneration', 'fixed')
88 particlegun.param('xVertexParams', [0])
89 particlegun.param('yVertexParams', [0])
90 particlegun.param('zVertexParams', [0])
91 particlegun.param('independentVertices', False)
92 main.add_module(particlegun)
93 
94 # Simulation
95 simulation = b2.register_module('FullSim')
96 # Visualisation with HepRep
97 if (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 
110 main.add_module(simulation)
111 
112 # Check for volume intersection/overlaps
113 if (options.overlap):
114  print('Check for volume intersection/overlaps')
115  overlapchecker = b2.register_module('OverlapChecker')
116  main.add_module(overlapchecker)
117 
118 # ARICH digitization
119 arichDigi = b2.register_module('ARICHDigitizer')
120 main.add_module(arichDigi)
121 
122 # convert ARICHDigits to ARICHHits
123 arichHits = b2.register_module('ARICHFillHits')
124 main.add_module(arichHits)
125 
126 # ARICH reconstruction
127 # calculate PID likelihoods for all tracks
128 arichreco = b2.register_module('ARICHReconstructor')
129 # use MC hits (ARICHAeroHits) instead of reconstructed tracks
130 arichreco.param('inputTrackType', 1)
131 # store Cherenkov angle information
132 arichreco.param('storePhotons', 1)
133 main.add_module(arichreco)
134 
135 # ARICH Ntuple
136 # create flat ntuple for performance analysis
137 arichNtuple = b2.register_module('ARICHNtuple')
138 arichNtuple.param('outputFile', options.filename)
139 main.add_module(arichNtuple)
140 
141 # ARICH DQM
142 # create DQM occupancy plots
143 arichdqm = b2.register_module('ARICHDQM')
144 main.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
158 main.add_module('Progress')
159 
160 # Process events
161 b2.process(main)
162 
163 # Print call statistics
164 print(b2.statistics)
165 
166 # Make basic performance plots
167 if (options.rootbatch):
168  com = 'root -l -b -q ' + options.filename + ' ' + home + '/arich/utility/scripts/plotEfficiency.C'
169 else:
170  com = 'root -l ' + options.filename + ' ' + home + '/arich/utility/scripts/plotEfficiency.C'
171 
172 if 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
176 com = 'root -l -b -q ' + 'ARICHPerformance.root' + ' ' + home + '/arich/utility/scripts/plotEfficiencyConvertTCanvasToHist.C'
177 if not (options.hepr or options.overlap or options.rootoff):
178  os.system(com)