ATLAS Offline Software
jobOption.ParticleGun_corrhist.py
Go to the documentation of this file.
1 #! -*- python -*-
2 
3 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
4 
5 
7 
8 include("EvgenProdTools/StdEvgenSetup.py")
9 theApp.EvtMax = 100
10 
11 import ParticleGun as PG
12 
13 class PtEtaHistParticleSampler(PG.ParticleSampler):
14  "Particle sampler with correlated pT and eta from a 2D histogram."
15 
16  def __init__(self, pid, histfile, num=100):
17  self.pid = PG.mksampler(pid)
18  self.hist = PG.TH2(histfile, "h_pt_eta")
19  self.numparticles = num
20 
21  def shoot(self):
22  "Return a vector of sampled particles from the provided pT--eta histogram"
23  particles = []
24  for i in xrange(self.numparticles):
25  ptrand, etarand = self.hist.GetRandom()
26  ptrand *= 1000 # NB. This _particular_ histogram is in GeV, but Athena needs MeV!
27  # TODO: Provide 4-mom construction functions to avoid building this one-time sampler
28  pid = self.pid()
29  mom = PG.PtEtaMPhiSampler(pt=ptrand, eta=etarand, mass=PG.MASSES[abs(pid)])
30  p = PG.SampledParticle(pid, mom())
31  #print p.mom.Pt(), "\t", p.mom.Eta(), "\t", p.mom.Phi(), "\t", p.mom.M()
32  particles.append(p)
33  return particles
34 
35 topSeq += PG.ParticleGun()
36 topSeq.ParticleGun.randomSeed = 123456
37 topSeq.ParticleGun.sampler = PtEtaHistParticleSampler(11, "data_histos_el_1470pt.root")
38 
39 include("EvgenProdTools/postJO.CopyWeights.py")
40 include("EvgenProdTools/postJO.PoolOutput.py")
41 include("EvgenProdTools/postJO.DumpMC.py")
xrange
void xrange(TH1 *h, bool symmetric)
Definition: computils.cxx:515
jobOption.PtEtaHistParticleSampler.hist
hist
Definition: jobOption.ParticleGun_corrhist.py:18
jobOption.PtEtaHistParticleSampler.__init__
def __init__(self, pid, histfile, num=100)
Definition: jobOption.ParticleGun_corrhist.py:16
jobOption.PtEtaHistParticleSampler.numparticles
numparticles
Definition: jobOption.ParticleGun_corrhist.py:19
jobOption.PtEtaHistParticleSampler
Definition: jobOption.ParticleGun_corrhist.py:13
jobOption.PtEtaHistParticleSampler.shoot
def shoot(self)
Definition: jobOption.ParticleGun_corrhist.py:21
python.Include.include
include
Definition: Include.py:319
jobOption.mom
mom
Definition: jobOption.ParticleGun_constenergy_flateta.py:12
jobOption.PtEtaHistParticleSampler.pid
pid
Definition: jobOption.ParticleGun_corrhist.py:17