ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4ParticleGenerator.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4ParticleGenerator.cc
2 
3 #include "PHG4InEvent.h"
4 #include "PHG4Particle.h" // for PHG4Particle
5 #include "PHG4Particlev2.h"
6 
7 #include <phool/getClass.h>
8 
9 #include <gsl/gsl_rng.h> // for gsl_rng_uniform_pos
10 
11 #include <cmath>
12 #include <iostream> // for operator<<, endl, basic_ostream, basic_o...
13 #include <vector> // for vector, vector<>::iterator
14 
15 class PHCompositeNode;
16 
19 {
20  return;
21 }
22 
23 void PHG4ParticleGenerator::set_z_range(const double min, const double max)
24 {
25  m_ZMin = min;
26  m_ZMax = max;
27  return;
28 }
29 
30 void PHG4ParticleGenerator::set_eta_range(const double min, const double max)
31 {
32  m_EtaMin = min;
33  m_EtaMax = max;
34  return;
35 }
36 
37 void PHG4ParticleGenerator::set_phi_range(const double min, const double max)
38 {
39  m_PhiMin = min;
40  m_PhiMax = max;
41  return;
42 }
43 
44 void PHG4ParticleGenerator::set_mom_range(const double min, const double max)
45 {
46  m_MomMin = min;
47  m_MomMax = max;
48  return;
49 }
50 
52 {
53  PHG4InEvent *ineve = findNode::getClass<PHG4InEvent>(topNode, "PHG4INEVENT");
54 
55  if (!ReuseExistingVertex(topNode))
56  {
57  set_vtx_z((m_ZMax - m_ZMin) * gsl_rng_uniform_pos(RandomGenerator()) + m_ZMin);
58  }
59  int vtxindex = ineve->AddVtx(get_vtx_x(), get_vtx_y(), get_vtx_z(), get_t0());
60 
61  std::vector<PHG4Particle *>::iterator iter;
62  for (iter = particlelist_begin(); iter != particlelist_end(); ++iter)
63  {
64  PHG4Particle *particle = new PHG4Particlev2(*iter);
65  SetParticleId(particle, ineve);
66  double mom = (m_MomMax - m_MomMin) * gsl_rng_uniform_pos(RandomGenerator()) + m_MomMin;
67  double eta = (m_EtaMax - m_EtaMin) * gsl_rng_uniform_pos(RandomGenerator()) + m_EtaMin;
68  double phi = (m_PhiMax - m_PhiMin) * gsl_rng_uniform_pos(RandomGenerator()) + m_PhiMin;
69  double pt = mom / cosh(eta);
70 
71  particle->set_e(mom);
72  particle->set_px(pt * cos(phi));
73  particle->set_py(pt * sin(phi));
74  particle->set_pz(pt * sinh(eta));
75  // update internal particle list with changed momenta
76  // needed for correct printout of particle kinematics
77  // in PHG4ParticleGenerator::Print()
78  (*iter)->set_e(particle->get_e());
79  (*iter)->set_px(particle->get_px());
80  (*iter)->set_py(particle->get_py());
81  (*iter)->set_pz(particle->get_pz());
82  ineve->AddParticle(vtxindex, particle);
83  }
84  if (Verbosity() > 0)
85  {
86  ineve->identify();
87  }
88  return 0;
89 }
90 
91 void PHG4ParticleGenerator::Print(const std::string &what) const
92 {
93  std::cout << "PHG4ParticleGenerator settings:" << std::endl;
94  std::cout << "ZMin, ZMax: " << m_ZMin << "/" << m_ZMax << std::endl;
95  std::cout << "EtaMin, EtaMax: " << m_EtaMin << "/" << m_EtaMax << std::endl;
96  std::cout << "PhiMin, PhiMax: " << m_PhiMin << "/" << m_PhiMax << std::endl;
97  std::cout << "MomMin, MomMax: " << m_MomMin << "/" << m_MomMax << std::endl;
98  PrintParticles(what);
99  return;
100 }