Belle II Software  release-05-01-25
beast_gun.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # -------------------------------------------------------------------------------------
5 # Example steering file for beast2 simulation
6 # Builds beast2 geometry and uses particle gun module to shoot particles
7 # Uncomment the lines related to the display module to show the detector geometry
8 # Simulation output hits are stored into "beast_test.root"
9 #
10 # Author: Luka Santelj
11 # Date: 15.2.2018
12 # -------------------------------------------------------------------------------------
13 
14 from basf2 import *
15 import sys
16 import os
17 from background import add_output
18 
19 # set parameters
20 main = create_path()
21 
22 # Event info setter
23 eventinfosetter = register_module('EventInfoSetter')
24 # set number of events
25 eventinfosetter.param('evtNumList', [200])
26 main.add_module(eventinfosetter)
27 
28 # Uncomment if you include your study/analysis module into the path
29 # Study modules (in your detector folder) are HistoModules, they produce histograms,
30 # and HistoManager module takes care to store them in the output root file
31 #
32 # histo = register_module('HistoManager')
33 # histo.param('histoFileName', 'histograms.root') # File to save histograms
34 # main.add_module(histo)
35 
36 # Gearbox - reads parameters from the xml files
37 gearbox = register_module('Gearbox')
38 gearbox.param('fileName', 'geometry/Beast2_phase2.xml')
39 main.add_module(gearbox)
40 
41 # Geant geometry
42 geometry = register_module('Geometry')
43 # select detectors to be built (IR structures+VXD+Beast2)
44 geometry.param('components', ["STR", "BeamPipe", "Cryostat",
45  "HeavyMetalShield", "PXD", "SVD", "MICROTPC", "PINDIODE",
46  "BEAMABORT", "HE3TUBE", "CLAWS", "FANGS", "PLUME", "QCSMONITOR",
47  "MagneticField3dQuadBeamline"])
48 main.add_module(geometry)
49 
50 # Overlap checker / if you make g4 geometry changes please check
51 # that there are no overlaps
52 # main.add_module("OverlapChecker")
53 # Save overlaps to file to be able to view them with b2display
54 # main.add_module("RootOutput", outputFileName="Overlaps.root")
55 
56 
57 # particle gun module, shoot particles into your detector
58 particlegun = register_module('ParticleGun')
59 particlegun.param('pdgCodes', [11]) # electron
60 particlegun.param('nTracks', 1)
61 particlegun.param('momentumGeneration', 'uniform')
62 particlegun.param('momentumParams', [1, 1.01]) # 1 GeV
63 particlegun.param('thetaGeneration', 'uniformCos')
64 particlegun.param('thetaParams', [0, 360]) # theta angle
65 particlegun.param('phiGeneration', 'uniform')
66 particlegun.param('phiParams', [0, 360]) # phi angle
67 particlegun.param('vertexGeneration', 'fixed')
68 particlegun.param('xVertexParams', [0])
69 particlegun.param('yVertexParams', [0])
70 particlegun.param('zVertexParams', [0])
71 particlegun.param('independentVertices', False)
72 main.add_module(particlegun)
73 
74 # Geant simulation
75 fullsim = register_module('FullSim')
76 fullsim.param('PhysicsList', 'FTFP_BERT_HP')
77 fullsim.param('UICommandsAtIdle', ['/process/inactivate nKiller'])
78 fullsim.param('StoreAllSecondaries', True)
79 fullsim.param('SecondariesEnergyCut', 0.000001) # [MeV] need for CDC EB neutron flux
80 main.add_module(fullsim)
81 
82 # Add additional modules, like digitization and study/analysis
83 # for example He3Digitizer
84 # dataobjects created in these modules are also put into the datastore
85 # and finally saved into the output root file (he3 digits in this case)
86 #
87 # he3digi = register_module('He3Digitizer')
88 # main.add_module(he3digi)
89 #
90 # if you add study/analysis module uncomment also HistoManager lines
91 #
92 # he3study = register_module('He3tubeStudy')
93 # main.add_module(he3study)
94 
95 # Show progress of processing
96 progress = register_module('Progress')
97 main.add_module(progress)
98 
99 # uncomment below to add the event display module
100 # display = register_module('Display')
101 # display.param('fullGeometry', True)
102 # main.add_module(display)
103 
104 # store output hits into root file (these is collection of hits, not histograms)
105 # by default all content of datastore is stored
106 output = register_module('RootOutput')
107 output.param('outputFileName', "beast_test.root")
108 # if you want to store only branches of interest (hits in your detector, etc.) use
109 # output.param('branchNames', ['PlumeSimHits'])
110 main.add_module(output)
111 
112 
113 # Process events
114 process(main)
115 
116 # Print call statistics
117 print(statistics)