5 #include "PythiaJetGun.hh"
6 #include "generator/pythia6.h"
7 #include "geners/GenericIO.hh"
8 #include "geners/IOException.hh"
12 using namespace geom3;
15 namespace PythiaJetGun
17 bool Particle::operator==(
const Particle& r)
const
19 return code_ == r.code_ &&
20 p4_.momentum() == r.p4_.momentum() &&
24 double Particle::charge()
const
26 return pychge(code_)/3.0;
29 double Particle::gyrationRadius(
const double B)
const
31 const double qB = charge()*B;
36 const double c = 299792458.0;
37 return 1.e9/c*p4_.pt()/qB;
41 bool Particle::write(std::ostream& of)
const
43 write_item(of, p4_,
false);
48 void Particle::restore(
const gs::ClassId&
id, std::istream& in,
51 static const ClassId myClassId(ClassId::makeId<Particle>());
52 myClassId.ensureSameId(
id);
55 restore_item(in, &ptr->p4_,
false);
56 read_pod(in, &ptr->code_);
58 if (in.fail())
throw IOReadFailure(
"In Particle::restore: "
59 "input stream failure");
67 void pythiacmd(
const char* cmd)
72 double gaussRandom(
const double mean,
const double sigma)
77 }
while (r <= 0.0 || r > 1.0);
78 return mean + sigma*sqrt(-2.0*log(r))*cos(2.0*M_PI*pyrandom());
81 void shoot1(
const int code,
const double pt,
const double eta,
82 const double phi, Particle* partonptr,
83 std::vector<Particle>* output)
86 assert(code >= 1 && code <= 500);
91 rk::P4 parton(Vector3(pt*cos(phi), pt*sin(phi),
92 pt*sinh(eta)), pymass(zcode));
96 py1ent(0, zcode, parton.e(), parton.theta(), phi);
102 const int nparticles = pyjets_.n;
106 output->reserve(nparticles);
107 for (
int i=0; i<nparticles; ++i)
109 Vector3 p(pyjets_.p[0][i],pyjets_.p[1][i],pyjets_.p[2][i]);
110 output->push_back(Particle(pyjets_.k[1][i],
111 rk::P4(p, pyjets_.p[4][i])));
113 *partonptr = Particle(zcode, parton);
118 shoot1(code, pt, eta, phi, partonptr, output);
122 void shoot2(
const int code,
const double pt,
const double eta,
123 const double phi, Particle* partonptr,
124 std::vector<Particle>* output,
bool runPyexec)
127 assert(code >= 1 && code <= 500);
129 if (pyrandom() < 0.5)
132 rk::P4 parton(Vector3(pt*cos(phi), pt*sin(phi),
133 pt*sinh(eta)), pymass(zcode));
134 const UnitVector3 pdir(parton.momentum().direction());
139 py2ent(-1, zcode, -zcode, 2.0*parton.e());
140 pyshow(1, 2, 2.0*parton.e());
148 const UnitVector3 axis(
149 UnitVector3::zAxis().cross(pdir).direction());
150 const double angle = UnitVector3::zAxis().angle(pdir);
151 Rotation3 rot(axis, angle);
154 rot *= Rotation3(pdir, pyrandom()*2.0*M_PI);
157 const int nparticles = pyjets_.n;
159 for (
int i=0; i<nparticles; ++i)
160 if (pyjets_.p[2][i] > 0.0)
166 output->reserve(count);
167 for (
int i=0; i<nparticles; ++i)
168 if (pyjets_.p[2][i] > 0.0)
170 Vector3 p(pyjets_.p[0][i],pyjets_.p[1][i],pyjets_.p[2][i]);
171 output->push_back(Particle(pyjets_.k[1][i],
172 rk::P4(rot.rotate(p), pyjets_.p[4][i])));
174 *partonptr = Particle(zcode, parton);
179 shoot2(code, pt, eta, phi, partonptr, output);