9 #include "nutools/G4Base/ConvertMCTruthToG4.h" 10 #include "nutools/G4Base/PrimaryParticleInformation.h" 14 #include "Geant4/G4Event.hh" 15 #include "Geant4/G4IonTable.hh" 16 #include "Geant4/G4PrimaryVertex.hh" 17 #include "Geant4/G4ParticleDefinition.hh" 18 #include "Geant4/G4ParticleTable.hh" 20 #include <TParticle.h> 22 #include <CLHEP/Vector/LorentzVector.h> 48 std::ostringstream badtxt;
52 badtxt <<
"\n Unknown PDG code = " << pdg
53 <<
", seen " << (*i).second <<
" times.";
55 const int genieLo = 2000000001;
56 const int genieHi = 2000000202;
57 if ( pdg >= genieLo && pdg <= genieHi ) {
58 badtxt <<
" (GENIE specific)";
63 <<
"The following unknown PDG codes were present in the " 64 <<
"simb::MCTruth input.\n" 65 <<
"They were not processed by Geant4." 107 std::map< CLHEP::HepLorentzVector, G4PrimaryVertex* > vertexMap;
116 for (
int p = 0;
p != mct->NParticles(); ++
p ){
127 G4int pdgCode = particle.
PdgCode();
137 CLHEP::HepLorentzVector fourpos(x,y,z,t);
140 G4PrimaryVertex*
vertex = 0;
142 if ( result == vertexMap.end() ){
145 vertex =
new G4PrimaryVertex(x, y, z, t);
146 vertexMap[ fourpos ] = vertex;
149 event->AddPrimaryVertex( vertex );
153 vertex = (*result).second;
157 TLorentzVector momentum = particle.
Momentum();
168 G4ParticleDefinition* particleDefinition;
171 particleDefinition =
fParticleTable->FindParticle(
"opticalphoton");
176 if ( pdgCode > 1000000000) {
177 MF_LOG_DEBUG(
"ConvertPrimaryToGeant4") <<
": %%% Nuclear PDG code = " << pdgCode
178 <<
" (x,y,z,t)=(" << x
182 <<
" P=" << momentum.P()
183 <<
", E=" << momentum.E();
186 if (!particleDefinition) {
187 int Z = (pdgCode % 10000000) / 10000;
188 int A = (pdgCode % 10000) / 10;
189 particleDefinition =
fParticleTable->GetIonTable()->GetIon(Z, A, 0.);
195 if ( particleDefinition == 0 ){
196 MF_LOG_DEBUG(
"ConvertPrimaryToGeant4") <<
": %%% Code not found = " << pdgCode;
202 G4PrimaryParticle* g4particle =
new G4PrimaryParticle( particleDefinition,
208 G4double charge = particleDefinition->GetPDGCharge();
209 g4particle->SetCharge( charge );
210 g4particle->SetPolarization( polarization.x(),
215 vertex->SetPrimary( g4particle );
226 g4particle->SetUserInformation( primaryParticleInfo );
228 MF_LOG_DEBUG(
"ConvertPrimaryToGeant4") <<
": %%% primary PDG=" << pdgCode
229 <<
", (x,y,z,t)=(" << x
233 <<
" P=" << momentum.P()
234 <<
", E=" << momentum.E();
const TVector3 & Polarization() const
virtual void GeneratePrimaries(G4Event *)
void Reset()
Get ready to convert a new set of MCTruth objects.
static G4ParticleTable * fParticleTable
Geant4's table of particle definitions.
ConvertMCTruthToG4()
Standard constructor and destructor.
double T(const int i=0) const
basic interface to Geant4 for ART-based software
double Vx(const int i=0) const
virtual ~ConvertMCTruthToG4()
std::map< G4int, G4int > fUnknownPDG
map of unknown PDG codes to instances
const TLorentzVector & Momentum(const int i=0) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double Vz(const int i=0) const
void SetMCTruth(const simb::MCTruth *m, size_t idx=0, GeneratedParticleIndex_t indexInTruth=simb::NoGeneratedParticleIndex)
void Append(art::Ptr< simb::MCTruth > &mct)
Event generator information.
std::vector< const simb::MCTruth * > fConvertList
List of MCTruth objects to convert for this spill.
double Vy(const int i=0) const
Event finding and building.