94 auto const& mclistHandles = *
fMCLists;
96 size_t mclSize = mclistHandles.size();
97 mf::LogDebug(
"generatePrimaries") <<
"MCTruth Handles Size: " << mclSize;
101 std::map<CLHEP::HepLorentzVector, G4PrimaryVertex*> vertexMap;
102 for (
size_t mcl = 0; mcl < mclSize; ++mcl) {
103 mf::LogDebug(
"generatePrimaries")
104 <<
"MCTruth Handle Number: " << (mcl + 1) <<
" of " << mclSize;
105 art::Handle<std::vector<simb::MCTruth>> mclistHandle = mclistHandles[mcl];
108 for (
size_t i = 0; i < mclistHandle->size(); ++i) {
109 art::Ptr<simb::MCTruth> mclist(mclistHandle, i);
111 mf::LogDebug(
"generatePrimaries")
112 <<
"art::Ptr number " << (i + 1) <<
" of " << mclistHandle->size() <<
", Ptr: " << mclist;
113 int nPart = mclist->NParticles();
114 MF_LOG_INFO(
"generatePrimaries") <<
"Generating " << nPart <<
" particles";
117 for (
int m = 0;
m != nPart; ++
m) {
118 simb::MCParticle
const& particle = mclist->GetParticle(
m);
119 G4int
const pdgCode = particle.PdgCode();
121 if (particle.StatusCode() != 1) {
122 MF_LOG_DEBUG(
"generatePrimaries")
123 <<
"Status code != 1, skipping particle number with MCTruth index = "
124 <<
"(" << mcl <<
"," << i <<
")"
125 <<
" and particle index = " <<
m;
130 if (((
m + 1) % nPart) < 2)
132 mf::LogDebug(
"generatePrimaries") <<
"Particle Number: " << (
m + 1) <<
" of " << nPart;
133 mf::LogDebug(
"generatePrimaries") <<
"TrackID: " << particle.TrackId();
134 mf::LogDebug(
"generatePrimaries") <<
"index: " << index;
137 G4double
x = particle.Vx() * CLHEP::cm;
138 G4double
y = particle.Vy() * CLHEP::cm;
139 G4double
z = particle.Vz() * CLHEP::cm;
140 G4double t = particle.T() * CLHEP::ns;
143 CLHEP::HepLorentzVector fourpos(x, y, z, t);
146 G4PrimaryVertex*
vertex =
nullptr;
147 auto result = vertexMap.find(fourpos);
148 if (result == vertexMap.end()) {
150 vertex =
new G4PrimaryVertex(x, y, z, t);
151 vertexMap[fourpos] =
vertex;
154 anEvent->AddPrimaryVertex(vertex);
158 vertex = result->second;
162 TLorentzVector
const& momentum = particle.Momentum();
163 TVector3
const& polarization = particle.Polarization();
171 G4ParticleDefinition* particleDefinition =
nullptr;
173 if (pdgCode == 0) { particleDefinition =
fParticleTable->FindParticle(
"opticalphoton"); }
178 if (pdgCode >= 2
'000'000
'000) { // If the particle is generator-specific
179 mf::LogDebug("ConvertPrimaryToGeant4")
180 << ": %%% Will skip particle with generator-specific PDG code = " << pdgCode;
181 fUnknownPDG[pdgCode] += 1;
184 if (pdgCode > 1'000
'000'000) {
185 mf::LogDebug(
"ConvertPrimaryToGeant4")
186 <<
": %%% Nuclear PDG code = " << pdgCode <<
" (x,y,z,t)=(" << x <<
"," << y <<
"," << z
188 <<
" P=" << momentum.P() <<
", E=" << momentum.E();
192 if (!particleDefinition) {
193 int const Z = (pdgCode % 10
'000'000) / 10
'000; // atomic number
194 int const A = (pdgCode % 10'000) / 10;
201 if (particleDefinition ==
nullptr) {
202 mf::LogDebug(
"ConvertPrimaryToGeant4") <<
": %%% Code not found = " << pdgCode;
210 auto* g4particle =
new G4PrimaryParticle(particleDefinition,
216 g4particle->SetCharge(particleDefinition->GetPDGCharge());
217 g4particle->SetPolarization(polarization.x(), polarization.y(), polarization.z());
220 vertex->SetPrimary(g4particle);
227 auto* primaryParticleInfo =
new g4b::PrimaryParticleInformation;
228 primaryParticleInfo->SetMCTruth(mclist.get(), index,
m);
232 g4particle->SetUserInformation(primaryParticleInfo);
util::quantities::gigaelectronvolt GeV
process_name opflash particleana ie ie ie z
static G4ParticleTable * fParticleTable
Geant4's table of particle definitions.
process_name opflash particleana ie x
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
std::vector< art::Handle< std::vector< simb::MCTruth > > > const * fMCLists
MCTruthCollection input lists.
process_name opflash particleana ie ie y
std::map< G4int, G4int > fProcessedPDG
PDG codes processed.
std::map< G4int, G4int > fNon1StatusPDG
PDG codes skipped because not status 1.
std::map< G4int, G4int > fUnknownPDG
map of unknown PDG codes to instances