ATLAS Offline Software
Loading...
Searching...
No Matches
ParticleGun_SamplingFraction.py
Go to the documentation of this file.
1#! -*- python -*-
2evgenConfig.description = "Single particle gun for Sampling Fraction event generation"
3evgenConfig.keywords = ["singleParticle",]
4evgenConfig.generators = ["ParticleGun"]
5evgenConfig.contact = ["michael.duehrssen@cern.ch"]
6
7import ParticleGun as PG
8import ROOT, math, random
9
10class MyParticleSampler(PG.ParticleSampler):
11 """
12 Projective showers starting at entrance of calorimeter, flat in eta, constant energy
13 """
14
15 def __init__(self,pid=11,momentum=50000.,eta1=0.,eta2=1.4,bec=0,radius=1500.,z=3740.5):
16 self.pid = pid
17 self.momentum = momentum
18 self.eta1 = eta1
19 self.eta2 = eta2
20 pdg_table = ROOT.TDatabasePDG.Instance() #Gives values in GeV
21 self.mass = pdg_table.GetParticle(self.pid()).Mass()*1000.
22 self.bec=bec
23 self.radius=radius
24 self.z=z
25
26 def shoot(self):
27 rtn=[]
28 eta = random.uniform(self.eta1, self.eta2)
29 phi = random.uniform(0, math.tau) # tau = 2 * pi
30 v4 = ROOT.TLorentzVector()
31 pt = self.momentum / math.cosh(eta)
32 v4.SetPtEtaPhiM(pt, eta, phi, self.mass)
33 if self.bec==0:
34 radius= self.radius
35 x=radius*math.cos(phi)
36 y=radius*math.sin(phi)
37 z=radius*math.sinh(eta)
38 else:
39 z=self.z
40 radius=z/math.sinh(eta)
41 x=radius*math.cos(phi)
42 y=radius*math.sin(phi)
43 t=math.sqrt(x*x+y*y+z*z)
44 vp = ROOT.TLorentzVector(x,y,z,t)
45 p = PG.SampledParticle(pid=self.pid(),mom=v4,pos=vp)
46 #print "E,eta,phi,mass ",e,eta,phi,self.mass," position ",x,y,z," pid=",p.pid
47 rtn.append(p)
48 return rtn
49
50
52
53
54FIRST_DIR = (os.environ['JOBOPTSEARCHPATH']).split(":")[0]
55jofiles = [f for f in os.listdir(FIRST_DIR) if (f.startswith('mc') and f.endswith('.py'))]
56
57print "================ SETTTINGS ================="
58print ("jofiles = ", jofiles)
59
60
61args = jofiles[0].split('.py')[0]
62print ("args = ", args)
63
64myMomentum = float(args.split('_Mom')[1].split('_')[0])
65print ("Momentum = ", myMomentum,"MeV")
66
67myPDGID = int(float(args.split('_pid')[1].split('_')[0].replace('m','-')))
68print ("pid = ", myPDGID)
69
70myLowEta = 0.01*float(args.split('eta_')[1].split('_')[0].replace('m','-'))
71print ("etalow = ", myLowEta)
72
73myHighEta = 0.01*float(args.split('eta_')[1].split('_')[1].replace('m','-'))
74print ("etahigh = ", myHighEta)
75
76if "_Radius" in args:
77 myRadius = 0.001*float(args.split('_Radius')[1].split('_')[0]) #Argument needs to by in mum, since a "." in the filename is not allowed
78else:
79 myRadius = 1500.
80print ("radius = ", myRadius,"mm")
81
82if "_Z" in args:
83 myZ = 0.001*float(args.split('_Z')[1].split('_')[0]) #Argument needs to by in mum, since a "." in the filename is not allowed
84else:
85 myZ = 3740.5
86print ("Z = ", myZ,"mm")
87
88if "bec" in args:
89 bec=1
90else:
91 bec=0
92print ("bec = ", bec)
93print "============================================"
94
95genSeq += PG.ParticleGun()
96genSeq.ParticleGun.sampler = MyParticleSampler(momentum=myMomentum,eta1=myLowEta,eta2=myHighEta,pid=myPDGID,bec=bec,radius=myRadius,z=myZ)
97
__init__(self, pid=11, momentum=50000., eta1=0., eta2=1.4, bec=0, radius=1500., z=3740.5)
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177