EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eASTPrimaryGeneratorAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file eASTPrimaryGeneratorAction.cc
1 // ********************************************************************
2 //
3 // eASTPrimaryGeneratorAction.cc
4 // primary generator action class
5 //
6 // History
7 // September 8th, 2021 : first implementation
8 // December 29th, 2021 : Adding messenger - M. Asai (JLab)
9 //
10 // ********************************************************************
11 
14 
15 #include "G4Event.hh"
16 #include "G4ParticleGun.hh"
17 #include "G4GeneralParticleSource.hh"
18 #include "G4ParticleTable.hh"
19 #include "G4ParticleDefinition.hh"
20 #include "G4SystemOfUnits.hh"
21 #include "Randomize.hh"
22 
23 #ifdef eAST_USE_HepMC3
24 #include "eASTHepMC3Interface.hh"
25 #endif // eAST_USE_HepMC3
26 
28  G4bool useParticleGun, G4bool useParticleSource,
29  G4bool useHepMC3Interface)
30 : G4VUserPrimaryGeneratorAction()
31 {
32  if(useParticleGun)
33  {
34  fParticleGun = new G4ParticleGun(1);
35 
36  auto particleTable = G4ParticleTable::GetParticleTable();
37  auto fPion = particleTable->FindParticle("pi+");
38  fParticleGun->SetParticleDefinition(fPion);
39 
40  // default particle kinematics
41  fParticleGun->SetParticlePosition(G4ThreeVector(0.,0.,0.));
42  fParticleGun->SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.));
43  fParticleGun->SetParticleEnergy(1.*GeV);
44  }
45 
46  if(useParticleSource)
47  { fParticleSource = new G4GeneralParticleSource(); }
48 
49 #ifdef eAST_USE_HepMC3
50  if(useHepMC3Interface)
51  { fHepMC3Interface = eASTHepMC3Interface::GetInstance(); }
52 #endif // eAST_USE_HepMC3
53 
55 }
56 
58 {
59  if(fParticleGun!=nullptr) delete fParticleGun;
60  if(fParticleSource!=nullptr) delete fParticleSource;
61 
62 #ifdef eAST_USE_HepMC3
63  if(fHepMC3Interface!=nullptr && eASTHepMC3Interface::GetInstance()!=nullptr)
64  { delete fHepMC3Interface; }
65 #endif // eAST_USE_HepMC3
66 
67  delete messenger;
68 }
69 
71 {
72  if(fParticleGun) fParticleGun->GeneratePrimaryVertex(event);
73  if(fParticleSource) fParticleSource->GeneratePrimaryVertex(event);
74 #ifdef eAST_USE_HepMC3
75  if(fHepMC3Interface) fHepMC3Interface->GeneratePrimaryVertex(event);
76 #endif // eAST_USE_HepMC3
77 
78  G4int evId = event->GetEventID();
79  G4double tVtx = deltaT * (G4double)evId + T0;
80  auto* pv = event->GetPrimaryVertex();
81  while(pv!=nullptr)
82  {
83  pv->SetT0(pv->GetT0() + tVtx);
84  pv = pv->GetNext();
85  }
86 
87 }
88