forked from awhitbeck/LDMX_TS
-
Notifications
You must be signed in to change notification settings - Fork 2
/
runSimAndDigi.py
119 lines (75 loc) · 3.48 KB
/
runSimAndDigi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/python
import sys
import os
# we need the ldmx configuration package to construct the object
from LDMX.Framework import ldmxcfg
# first, we define the process, which must have a name which identifies this processing pass ("pass name").
# it's pretty arbitrary but you will see it in the final collection names.
p=ldmxcfg.Process("sim")
from LDMX.SimCore import generators as gen
from LDMX.SimCore import simulator
from LDMX.Biasing import filters
from LDMX.SimCore import simcfg
from LDMX.TrigScint.trigScint import TrigScintDigiProducer
import LDMX.Ecal.EcalGeometry
nEv = 100
if len(sys.argv) < 1 :
print("The number of beam electrons has to be specified. Use (positional) argument 1 for it.")
exit(1)
else :
nPart=sys.argv[1] #number of beam electrons to use
if len(sys.argv) > 2 : # "run number"; mostly for guaranteeing uniqueness -- uses multiplicity as default
runNb=int(sys.argv[2])
else:
runNb=int(nPart)
if len(sys.argv) > 3 :
outputName=sys.argv[3] #specify the output name if default is not desired
else:
outputName="ldmx_upstreamElectron"
doPoisson = False #set to true to get poisson varied number of beam electrons instead of fixed
# ------------------- all set; setup in detail, and run with these settings ---------------
mySim = simulator.simulator("mySim")
mySim.runNumber = runNb
mySim.description = "Upstream 4 GeV "+nPart+"-electron beam"
mySim.beamSpotSmear = [20., 80., 0] #mm
# get the path to the installed detector description
from LDMX.Detectors.makePath import *
mySim.setDetector( 'ldmx-det-v12', True ) #the true should tell it to include scoring planes
mySim.scoringPlanes = makeScoringPlanesPath('ldmx-det-v12')
mpgGen = gen.multi( "mgpGen" ) # this is the line that actually creates the generator
mpgGen.vertex = [ -27.926, 0., -700 ] # mm
mpgGen.nParticles = int(nPart)
mpgGen.pdgID = 11
mpgGen.enablePoisson = doPoisson
import math
theta = math.radians(4.5)
mpgGen.momentum = [ 4000.*math.sin(theta) , 0, 4000.*math.cos(theta) ] # MeV
#mpgGen.momentum = [ 380., 0., 3981.909 ] #MeV
#set this as the simulator's generator
mySim.generators = [ mpgGen ]
#add simulation to the sequence of stuff the code does
p.sequence = [ mySim ]
# set the maximum number of events to process
p.maxEvents=nEv
tsDigisUp =TrigScintDigiProducer.up()
tsDigisTag =TrigScintDigiProducer.tagger()
tsDigisDown =TrigScintDigiProducer.down()
tsDigisUp.pe_per_mip = 100.
tsDigisTag.pe_per_mip = tsDigisUp.pe_per_mip
tsDigisDown.pe_per_mip = tsDigisUp.pe_per_mip
# add these to the sequence of processes the code should run
p.sequence=[ mySim, tsDigisUp, tsDigisTag, tsDigisDown ]
#drop scoring plane hits we won't be using anyway
p.keep = [ "drop MagnetScoringPlaneHits", "drop TrackerScoringPlaneHits", "drop HcalScoringPlaneHits"]
# Provide the list of output files to produce
# When using the simulator to produce events, only one output file is necessary
p.outputFiles=["%s_run%i_%se_%sevents.root" %( outputName, runNb, nPart, nEv) ]
#some logging stuff, helpful to follow what's going on
p.termLogLevel = 1 #include info messages
#print this many events to screen (independent on number of events, except round-off effects when not divisible. so can go up by a factor 2 or so)
logEvents=20
if p.maxEvents < logEvents :
logEvents = p.maxEvents
p.logFrequency = int( p.maxEvents/logEvents )
# Utility function to interpret and print out the configuration to the screen
print(p)