Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:19:22

0001 #include "PHG4ParticleGenerator.h"
0002 
0003 #include "PHG4InEvent.h"
0004 #include "PHG4Particle.h"  // for PHG4Particle
0005 #include "PHG4Particlev2.h"
0006 
0007 #include <phool/getClass.h>
0008 
0009 #include <gsl/gsl_rng.h>  // for gsl_rng_uniform_pos
0010 
0011 #include <cmath>
0012 #include <iostream>  // for operator<<, endl, basic_ostream, basic_o...
0013 #include <vector>    // for vector, vector<>::iterator
0014 
0015 class PHCompositeNode;
0016 
0017 PHG4ParticleGenerator::PHG4ParticleGenerator(const std::string &name)
0018   : PHG4ParticleGeneratorBase(name)
0019 {
0020   return;
0021 }
0022 
0023 void PHG4ParticleGenerator::set_z_range(const double min, const double max)
0024 {
0025   m_ZMin = min;
0026   m_ZMax = max;
0027   return;
0028 }
0029 
0030 void PHG4ParticleGenerator::set_eta_range(const double min, const double max)
0031 {
0032   m_EtaMin = min;
0033   m_EtaMax = max;
0034   return;
0035 }
0036 
0037 void PHG4ParticleGenerator::set_phi_range(const double min, const double max)
0038 {
0039   m_PhiMin = min;
0040   m_PhiMax = max;
0041   return;
0042 }
0043 
0044 void PHG4ParticleGenerator::set_mom_range(const double min, const double max)
0045 {
0046   m_MomMin = min;
0047   m_MomMax = max;
0048   return;
0049 }
0050 
0051 int PHG4ParticleGenerator::process_event(PHCompositeNode *topNode)
0052 {
0053   PHG4InEvent *ineve = findNode::getClass<PHG4InEvent>(topNode, "PHG4INEVENT");
0054 
0055   if (!ReuseExistingVertex(topNode))
0056   {
0057     set_vtx_z(((m_ZMax - m_ZMin) * gsl_rng_uniform_pos(RandomGenerator())) + m_ZMin);
0058   }
0059   int vtxindex = ineve->AddVtx(get_vtx_x(), get_vtx_y(), get_vtx_z(), get_t0());
0060 
0061   std::vector<PHG4Particle *>::iterator iter;
0062   for (iter = particlelist_begin(); iter != particlelist_end(); ++iter)
0063   {
0064     PHG4Particle *particle = new PHG4Particlev2(*iter);
0065     SetParticleId(particle, ineve);
0066     double mom = ((m_MomMax - m_MomMin) * gsl_rng_uniform_pos(RandomGenerator())) + m_MomMin;
0067     double eta = ((m_EtaMax - m_EtaMin) * gsl_rng_uniform_pos(RandomGenerator())) + m_EtaMin;
0068     double phi = ((m_PhiMax - m_PhiMin) * gsl_rng_uniform_pos(RandomGenerator())) + m_PhiMin;
0069     double pt = mom / cosh(eta);
0070 
0071     particle->set_e(mom);
0072     particle->set_px(pt * cos(phi));
0073     particle->set_py(pt * sin(phi));
0074     particle->set_pz(pt * sinh(eta));
0075     // update internal particle list with changed momenta
0076     // needed for correct printout of particle kinematics
0077     // in PHG4ParticleGenerator::Print()
0078     (*iter)->set_e(particle->get_e());
0079     (*iter)->set_px(particle->get_px());
0080     (*iter)->set_py(particle->get_py());
0081     (*iter)->set_pz(particle->get_pz());
0082     ineve->AddParticle(vtxindex, particle);
0083   }
0084   if (Verbosity() > 0)
0085   {
0086     ineve->identify();
0087   }
0088   return 0;
0089 }
0090 
0091 void PHG4ParticleGenerator::Print(const std::string &what) const
0092 {
0093   std::cout << "PHG4ParticleGenerator settings:" << std::endl;
0094   std::cout << "ZMin, ZMax: " << m_ZMin << "/" << m_ZMax << std::endl;
0095   std::cout << "EtaMin, EtaMax: " << m_EtaMin << "/" << m_EtaMax << std::endl;
0096   std::cout << "PhiMin, PhiMax: " << m_PhiMin << "/" << m_PhiMax << std::endl;
0097   std::cout << "MomMin, MomMax: " << m_MomMin << "/" << m_MomMax << std::endl;
0098   PrintParticles(what);
0099   return;
0100 }