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