ATLAS Offline Software
ParticleGun_SamplingFraction.py
Go to the documentation of this file.
1 #! -*- python -*-
2 evgenConfig.description = "Single particle gun for Sampling Fraction event generation"
3 evgenConfig.keywords = ["singleParticle",]
4 evgenConfig.generators = ["ParticleGun"]
5 evgenConfig.contact = ["michael.duehrssen@cern.ch"]
6 
7 import ParticleGun as PG
8 import ROOT, math, random
9 
10 class 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 
54 FIRST_DIR = (os.environ['JOBOPTSEARCHPATH']).split(":")[0]
55 jofiles = [f for f in os.listdir(FIRST_DIR) if (f.startswith('mc') and f.endswith('.py'))]
56 
57 print "================ SETTTINGS ================="
58 print ("jofiles = ", jofiles)
59 
60 
61 args = jofiles[0].split('.py')[0]
62 print ("args = ", args)
63 
64 myMomentum = float(args.split('_Mom')[1].split('_')[0])
65 print ("Momentum = ", myMomentum,"MeV")
66 
67 myPDGID = int(float(args.split('_pid')[1].split('_')[0].replace('m','-')))
68 print ("pid = ", myPDGID)
69 
70 myLowEta = 0.01*float(args.split('eta_')[1].split('_')[0].replace('m','-'))
71 print ("etalow = ", myLowEta)
72 
73 myHighEta = 0.01*float(args.split('eta_')[1].split('_')[1].replace('m','-'))
74 print ("etahigh = ", myHighEta)
75 
76 if "_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
78 else:
79  myRadius = 1500.
80 print ("radius = ", myRadius,"mm")
81 
82 if "_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
84 else:
85  myZ = 3740.5
86 print ("Z = ", myZ,"mm")
87 
88 if "bec" in args:
89  bec=1
90 else:
91  bec=0
92 print ("bec = ", bec)
93 print "============================================"
94 
95 genSeq += PG.ParticleGun()
96 genSeq.ParticleGun.sampler = MyParticleSampler(momentum=myMomentum,eta1=myLowEta,eta2=myHighEta,pid=myPDGID,bec=bec,radius=myRadius,z=myZ)
97 
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ParticleGun_SamplingFraction.MyParticleSampler.bec
bec
Definition: ParticleGun_SamplingFraction.py:22
ParticleGun_SamplingFraction.MyParticleSampler.radius
radius
Definition: ParticleGun_SamplingFraction.py:23
ParticleGun_SamplingFraction.MyParticleSampler.pid
pid
Definition: ParticleGun_SamplingFraction.py:16
ParticleGun_SamplingFraction.MyParticleSampler.momentum
momentum
Definition: ParticleGun_SamplingFraction.py:17
ParticleGun_SamplingFraction.MyParticleSampler.mass
mass
Definition: ParticleGun_SamplingFraction.py:21
ParticleGun_SamplingFraction.MyParticleSampler.__init__
def __init__(self, pid=11, momentum=50000., eta1=0., eta2=1.4, bec=0, radius=1500., z=3740.5)
Definition: ParticleGun_SamplingFraction.py:15
ParticleGun_SamplingFraction.MyParticleSampler.shoot
def shoot(self)
Definition: ParticleGun_SamplingFraction.py:26
ParticleGun_SamplingFraction.MyParticleSampler.eta2
eta2
Definition: ParticleGun_SamplingFraction.py:19
ParticleGun_SamplingFraction.MyParticleSampler
Definition: ParticleGun_SamplingFraction.py:10
ParticleGun_SamplingFraction.MyParticleSampler.z
z
Definition: ParticleGun_SamplingFraction.py:24
ParticleGun_SamplingFraction.MyParticleSampler.eta1
eta1
Definition: ParticleGun_SamplingFraction.py:18
readCCLHist.float
float
Definition: readCCLHist.py:83
Trk::split
@ split
Definition: LayerMaterialProperties.h:38