Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:09

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 <cmath>      // for NAN
0018 #include <iostream>   // for operator<<, basic_ostream
0019 #include <iterator>   // for begin, end
0020 
0021 using namespace std;
0022 
0023 PHG4IonGun::PHG4IonGun(const string &name)
0024   : PHG4ParticleGeneratorBase(name)
0025   , ion(new PHG4Particlev3())
0026 {
0027 }
0028 
0029 void PHG4IonGun::SetCharge(const int c)
0030 {
0031   ioncharge = c * eplus;
0032 }
0033 
0034 void PHG4IonGun::SetMom(const double px, const double py, const double pz)
0035 {
0036   mom[0] = px;
0037   mom[1] = py;
0038   mom[2] = pz;
0039 }
0040 
0041 int PHG4IonGun::process_event(PHCompositeNode *topNode)
0042 {
0043   // get pdg code for ions
0044   UpdateParticle();
0045   PHG4InEvent *ineve = findNode::getClass<PHG4InEvent>(topNode, "PHG4INEVENT");
0046   ReuseExistingVertex(topNode);  // checks if we should reuse existing vertex
0047   int vtxindex = ineve->AddVtx(get_vtx_x(), get_vtx_y(), get_vtx_z(), get_t0());
0048   //   G4ParticleDefinition* ion = G4IonTable::GetIonTable()->GetIon(Z, A, excitEnergy);
0049   // G4PrimaryParticle* g4part = new G4PrimaryParticle(ion);
0050   //   cout << "name: " << ion->GetParticleName() << ", pdgcode: " << ion->GetPDGEncoding() << endl;
0051   PHG4Particle *particle = new PHG4Particlev3(ion);
0052   SetParticleId(particle, ineve);
0053   ineve->AddParticle(vtxindex, particle);
0054   return Fun4AllReturnCodes::EVENT_OK;
0055 }
0056 
0057 void PHG4IonGun::UpdateParticle()
0058 {
0059   ion->set_A(A);
0060   ion->set_Z(Z);
0061   ion->set_NumCharge(ioncharge);
0062   ion->set_ExcitEnergy(excitEnergy);
0063   ion->set_px(mom[0]);
0064   ion->set_py(mom[1]);
0065   ion->set_pz(mom[2]);
0066   G4ParticleDefinition *iondef = G4IonTable::GetIonTable()->GetIon(Z, A, excitEnergy);
0067   ion->set_name(iondef->GetParticleName());
0068   ion->set_pid(iondef->GetPDGEncoding());
0069   return;
0070 }
0071 
0072 void PHG4IonGun::Print(const string & /*what*/) const
0073 {
0074   cout << "PHG4IonGun, using ions of" << endl;
0075   cout << "A: " << A << ", Z: " << Z << ", charge: " << ioncharge
0076        << ", excitation Energy: " << excitEnergy << endl;
0077   cout << "px: " << mom[0] / GeV << " GeV, py: " << mom[1] / GeV << " GeV, pz: " << mom[2] / GeV << " GeV" << endl;
0078 }