ATLAS Offline Software
ParticleGun_FastCalo_Config_Erange.py
Go to the documentation of this file.
1 #! -*- python -*-
2 evgenConfig.description = "Single particle gun for FastCaloSim event generation"
3 evgenConfig.keywords = ["singleParticle",]
4 evgenConfig.generators = ["ParticleGun"]
5 evgenConfig.contact = ["david.sosa@cern.ch"]
6 
7 import ParticleGun as PG
8 import ROOT
9 
10 class MyParticleSampler(PG.ParticleSampler):
11  def __init__(self,energy,eta,pid,shift_z=0):
12  self.pid = pid
13  self.shift_z = shift_z
14  pdg_table = ROOT.TDatabasePDG.Instance() #Gives values in GeV
15  mass = pdg_table.GetParticle(self.pid()).Mass()*1000.
16  self.mom1 = PG.EEtaMPhiSampler(energy=energy,eta=eta,mass=mass)
17 
18  def shoot(self):
19  pid = self.pid()
20 
21  shift_z = self.shift_z
22 
23  mom = self.mom1.shoot()
24  pos_temp = mom.Vect().Unit()
25 
26  # Define geometry
27  barrelR1 = 1148.0
28  barrelR2 = 120.0
29  barrelR3 = 41.0
30  endcapZ1 = 3550.0
31  endcapZ2 = 4587.0
32 
33  # Would it hit the barrel, or the endcap?
34  tanTheta = pos_temp.Perp() / abs( pos_temp.Z() );
35  if tanTheta > barrelR1 / endcapZ1:
36  pos_temp *= barrelR1 / pos_temp.Perp()
37  elif tanTheta > barrelR2 / endcapZ1:
38  pos_temp *= endcapZ1 / abs( pos_temp.Z() )
39  elif tanTheta > barrelR2 / endcapZ2:
40  pos_temp *= barrelR2 / pos_temp.Perp()
41  elif tanTheta > barrelR3 / endcapZ2:
42  pos_temp *= endcapZ2 / abs( pos_temp.Z() )
43  else:
44  pos_temp *= barrelR3 / pos_temp.Perp()
45 
46  # Shift position of vector in the Z direction
47  pos_temp_2 = ROOT.TVector3()
48  pos_temp_2.SetXYZ(pos_temp.X(), pos_temp.Y(), pos_temp.Z()+shift_z)
49  pos_temp_2 *= 1. / pos_temp_2.Mag(); # reduce magnitude of vector
50 
51  # recalculate; Would it hit the barrel, or the endcap?
52  tanTheta_2 = pos_temp_2.Perp() / abs( pos_temp_2.Z() );
53  if tanTheta_2 > barrelR1 / endcapZ1:
54  pos_temp_2 *= barrelR1 / pos_temp_2.Perp()
55  elif tanTheta_2 > barrelR2 / endcapZ1:
56  pos_temp_2 *= endcapZ1 / abs( pos_temp_2.Z() )
57  elif tanTheta_2 > barrelR2 / endcapZ2:
58  pos_temp_2 *= barrelR2 / pos_temp_2.Perp()
59  elif tanTheta_2 > barrelR3 / endcapZ2:
60  pos_temp_2 *= endcapZ2 / abs( pos_temp_2.Z() )
61  else:
62  pos_temp_2 *= barrelR3 / pos_temp_2.Perp()
63 
64  pos = ROOT.TLorentzVector(pos_temp_2.X(),pos_temp_2.Y(),pos_temp_2.Z(), pos_temp_2.Mag())
65 
66  #print "pid ",pid
67 
68  return [ PG.SampledParticle( pid , mom , pos ) ]
69 
70 E_li = []
71 myLowE = float(jofile.split('_E')[1].split('_')[0])
72 myHighE = float(jofile.split('_E')[1].split('_')[1])
73 E_li.extend([myLowE,myHighE])
74 
75 myZV = float(jofile.split('_')[-1].split('.py')[0].replace("m","-"))
76 myPDGID = int(float(jofile.split('_pid')[1].split('_')[0].replace('m','-')))
77 
78 eta_li = []
79 
80 if "disj" in jofile:
81  myLowEta1 = 0.01*float(jofile.split('eta_')[1].split('_')[0].replace('m','-'))
82  myLowEta2 = 0.01*float(jofile.split('eta_')[1].split('_')[1].replace('m','-'))
83  myHighEta1 = 0.01*float(jofile.split('eta_')[1].split('_')[2].replace('m','-'))
84  myHighEta2 = 0.01*float(jofile.split('eta_')[1].split('_')[3].replace('m','-'))
85  eta_li.extend([myLowEta1,myLowEta2,myHighEta1,myHighEta2])
86 
87 else:
88  myLowEta = 0.01*float(jofile.split('eta')[1].split('_')[0].replace('m','-'))
89  myHighEta = 0.01*float(jofile.split('eta')[1].split('_')[1].replace('m','-'))
90  eta_li.extend([myLowEta,myHighEta])
91 
92 
93 print "================ SETTTINGS ================="
94 print ("energy = ", E_li)
95 print ("eta = ", eta_li)
96 print ("pid = ", myPDGID)
97 print ("shift_z = ", myZV)
98 print "============================================"
99 
100 genSeq += PG.ParticleGun()
101 print "E_li = ", E_li, ", eta_li = ", eta_li, ", pid = ", myPDGID, ", myZV = ", myZV
102 genSeq.ParticleGun.sampler = MyParticleSampler(energy=E_li,eta=eta_li,pid=myPDGID,shift_z=myZV)
103 
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
ParticleGun_FastCalo_Config_Erange.MyParticleSampler
Definition: ParticleGun_FastCalo_Config_Erange.py:10
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ParticleGun_FastCalo_Config_Erange.MyParticleSampler.shift_z
shift_z
Definition: ParticleGun_FastCalo_Config_Erange.py:13
ParticleGun_FastCalo_Config_Erange.MyParticleSampler.pid
pid
Definition: ParticleGun_FastCalo_Config_Erange.py:12
ParticleGun_FastCalo_Config_Erange.MyParticleSampler.shoot
def shoot(self)
Definition: ParticleGun_FastCalo_Config_Erange.py:18
ParticleGun_FastCalo_Config_Erange.MyParticleSampler.mom1
mom1
Definition: ParticleGun_FastCalo_Config_Erange.py:16
readCCLHist.float
float
Definition: readCCLHist.py:83
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
ParticleGun_FastCalo_Config_Erange.MyParticleSampler.__init__
def __init__(self, energy, eta, pid, shift_z=0)
Definition: ParticleGun_FastCalo_Config_Erange.py:11