Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4IonGun.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4IonGun.cc
1 #include "PHG4IonGun.h"
2 
3 #include "PHG4InEvent.h"
4 #include "PHG4Particle.h" // for PHG4Particle
5 #include "PHG4Particlev3.h"
6 
8 
9 #include <phool/getClass.h>
10 
11 #include <Geant4/G4IonTable.hh>
12 #include <Geant4/G4ParticleDefinition.hh> // for G4ParticleDefinition
13 #include <Geant4/G4String.hh> // for G4String
14 #include <Geant4/G4SystemOfUnits.hh>
15 
16 #include <algorithm> // for fill
17 #include <cmath> // for NAN
18 #include <iostream> // for operator<<, basic_ostream
19 #include <iterator> // for begin, end
20 
21 using namespace std;
22 
25  , ion(new PHG4Particlev3())
26 {
27 }
28 
29 void PHG4IonGun::SetCharge(const int c)
30 {
31  ioncharge = c * eplus;
32 }
33 
34 void PHG4IonGun::SetMom(const double px, const double py, const double pz)
35 {
36  mom[0] = px;
37  mom[1] = py;
38  mom[2] = pz;
39 }
40 
42 {
43  // get pdg code for ions
45  PHG4InEvent *ineve = findNode::getClass<PHG4InEvent>(topNode, "PHG4INEVENT");
46  ReuseExistingVertex(topNode); // checks if we should reuse existing vertex
47  int vtxindex = ineve->AddVtx(get_vtx_x(), get_vtx_y(), get_vtx_z(), get_t0());
48  // G4ParticleDefinition* ion = G4IonTable::GetIonTable()->GetIon(Z, A, excitEnergy);
49  //G4PrimaryParticle* g4part = new G4PrimaryParticle(ion);
50  // cout << "name: " << ion->GetParticleName() << ", pdgcode: " << ion->GetPDGEncoding() << endl;
52  SetParticleId(particle, ineve);
53  ineve->AddParticle(vtxindex, particle);
55 }
56 
58 {
59  ion->set_A(A);
60  ion->set_Z(Z);
63  ion->set_px(mom[0]);
64  ion->set_py(mom[1]);
65  ion->set_pz(mom[2]);
66  G4ParticleDefinition *iondef = G4IonTable::GetIonTable()->GetIon(Z, A, excitEnergy);
67  ion->set_name(iondef->GetParticleName());
68  ion->set_pid(iondef->GetPDGEncoding());
69  return;
70 }
71 
72 void PHG4IonGun::Print(const string &/*what*/) const
73 {
74  cout << "PHG4IonGun, using ions of" << endl;
75  cout << "A: " << A << ", Z: " << Z << ", charge: " << ioncharge
76  << ", excitation Energy: " << excitEnergy << endl;
77  cout << "px: " << mom[0] / GeV << " GeV, py: " << mom[1] / GeV << " GeV, pz: " << mom[2] / GeV << " GeV" << endl;
78 }