File indexing completed on 2025-12-17 09:22:02
0001 #include "PHG4IonGun.h"
0002
0003 #include "PHG4InEvent.h"
0004 #include "PHG4Particle.h" // for PHG4Particle
0005 #include "PHG4Particlev3.h"
0006
0007 #include <fun4all/Fun4AllReturnCodes.h>
0008
0009 #include <phool/getClass.h>
0010
0011 #include <Geant4/G4IonTable.hh>
0012 #include <Geant4/G4ParticleDefinition.hh> // for G4ParticleDefinition
0013 #include <Geant4/G4String.hh> // for G4String
0014 #include <Geant4/G4SystemOfUnits.hh>
0015
0016 #include <algorithm> // for fill
0017 #include <iostream> // for operator<<, basic_ostream
0018 #include <iterator> // for begin, end
0019
0020 PHG4IonGun::PHG4IonGun(const std::string &name)
0021 : PHG4ParticleGeneratorBase(name)
0022 , ion(new PHG4Particlev3())
0023 {
0024 }
0025
0026 void PHG4IonGun::SetCharge(const int c)
0027 {
0028 ioncharge = c * eplus;
0029 }
0030
0031 void PHG4IonGun::SetMom(const double px, const double py, const double pz)
0032 {
0033 mom[0] = px;
0034 mom[1] = py;
0035 mom[2] = pz;
0036 }
0037
0038 int PHG4IonGun::process_event(PHCompositeNode *topNode)
0039 {
0040
0041 UpdateParticle();
0042 PHG4InEvent *ineve = findNode::getClass<PHG4InEvent>(topNode, "PHG4INEVENT");
0043 ReuseExistingVertex(topNode);
0044 int vtxindex = ineve->AddVtx(get_vtx_x(), get_vtx_y(), get_vtx_z(), get_t0());
0045
0046
0047
0048 PHG4Particle *particle = new PHG4Particlev3(ion);
0049 SetParticleId(particle, ineve);
0050 ineve->AddParticle(vtxindex, particle);
0051 return Fun4AllReturnCodes::EVENT_OK;
0052 }
0053
0054 void PHG4IonGun::UpdateParticle()
0055 {
0056 ion->set_A(A);
0057 ion->set_Z(Z);
0058 ion->set_NumCharge(ioncharge);
0059 ion->set_ExcitEnergy(excitEnergy);
0060 ion->set_px(mom[0]);
0061 ion->set_py(mom[1]);
0062 ion->set_pz(mom[2]);
0063 G4ParticleDefinition *iondef = G4IonTable::GetIonTable()->GetIon(Z, A, excitEnergy);
0064 ion->set_name(iondef->GetParticleName());
0065 ion->set_pid(iondef->GetPDGEncoding());
0066 return;
0067 }
0068
0069 void PHG4IonGun::Print(const std::string & ) const
0070 {
0071 std::cout << "PHG4IonGun, using ions of" << std::endl;
0072 std::cout << "A: " << A << ", Z: " << Z << ", charge: " << ioncharge
0073 << ", excitation Energy: " << excitEnergy << std::endl;
0074 std::cout << "px: " << mom[0] / GeV << " GeV, py: " << mom[1] / GeV << " GeV, pz: " << mom[2] / GeV << " GeV" << std::endl;
0075 }