115 currentFileEventIndex = 0;
116 endOfFileReached =
false;
118 {G4cout << __METHOD_NAME__ <<
"Opening file: " << fileName << G4endl;}
121 case BDSEventGeneratorFileType::hepmc2:
122 {reader =
new HepMC3::ReaderAsciiHepMC2(fileName);
break;}
123 case BDSEventGeneratorFileType::hepmc3:
124 {reader =
new HepMC3::ReaderAscii(fileName);
break;}
125 case BDSEventGeneratorFileType::hpe:
126 {reader =
new HepMC3::ReaderHEPEVT(fileName);
break;}
127#ifdef USE_HEPMC3_ROOTIO
128 case BDSEventGeneratorFileType::root:
129 {reader =
new HepMC3::ReaderRoot(fileName);
break;}
130 case BDSEventGeneratorFileType::treeroot:
131 {reader =
new HepMC3::ReaderRootTree(fileName);
break;}
133 case BDSEventGeneratorFileType::root:
134 case BDSEventGeneratorFileType::treeroot:
136 throw BDSException(__METHOD_NAME__,
"HEPMC3 installation not compiled with ROOT support so can't load root file.");
140 case BDSEventGeneratorFileType::lhef:
141 {reader =
new HepMC3::ReaderLHEF(fileName);
break;}
222 if (nEventsToSkip > 0)
223 {G4cout << __METHOD_NAME__ <<
"skipping " << nEventsToSkip <<
" into file." << G4endl;}
227 G4long nAvailable = nEventsInFile * distrFileLoopNTimes;
228 if ((G4long)nEventsToSkip > nAvailable)
230 G4String msg =
"number of events to skip (" + std::to_string(nEventsToSkip) +
") is greater than the number of events (";
231 msg += std::to_string(nEventsInFile);
232 if (distrFileLoopNTimes > 1)
233 {msg +=
" x " + std::to_string(distrFileLoopNTimes) +
" loops of file";}
234 msg +=
") in this file.";
235 throw BDSException(
"BDSBunchUserFile::RecreateAdvanceToEvent>", msg);
237 G4long nToSkipSinglePass = nEventsToSkip % nEventsInFile;
238 for (G4int i = 0; i < nToSkipSinglePass; i++)
248 G4PrimaryVertex* g4vtx =
new G4PrimaryVertex(centralCoordsGlobal.global.x,
249 centralCoordsGlobal.global.y,
250 centralCoordsGlobal.global.z,
251 centralCoordsGlobal.global.T);
253 double overallWeight = 1.0;
254 if (!(hepmcevt->weights().empty()))
255 {overallWeight = hepmcevt->weight();}
256 std::vector<BDSPrimaryVertexInformation> vertexInfos;
257 G4int nParticlesSkipped = 0;
258 for (
const auto& particlePtr : hepmcevt->particles())
260 const HepMC3::GenParticle* particle = particlePtr.get();
261 if (!particle->children().empty())
264 int pdgcode = particle->pdg_id();
265 const HepMC3::FourVector& fv = particle->momentum();
266 G4LorentzVector p(fv.px(), fv.py(), fv.pz(), fv.e());
267 G4double px = p.x() * CLHEP::GeV;
268 G4double py = p.y() * CLHEP::GeV;
269 G4double pz = p.z() * CLHEP::GeV;
270 G4ThreeVector originalUnitMomentum(px,py,pz);
272 originalUnitMomentum = originalUnitMomentum.unit();
273 G4double rp = std::hypot(originalUnitMomentum.x(), originalUnitMomentum.y());
276 G4ThreeVector unitMomentum = originalUnitMomentum;
277 unitMomentum.transform(referenceBeamMomentumOffset);
280 G4PrimaryParticle* g4prim =
new G4PrimaryParticle(pdgcode, px, py, pz);
285 const G4ParticleDefinition* pd = g4prim->GetParticleDefinition();
286 G4bool deleteIt = !pd;
287 if (pd && removeUnstableWithoutDecay)
288 {deleteIt = !(pd->GetPDGStable()) && !pd->GetDecayTable();}
293 G4cout << __METHOD_NAME__ <<
"skipping particle with PDG ID: " << pdgcode << G4endl;
308 g4prim->GetTotalEnergy(),
311 if (!bunch->
AcceptParticle(local, rp, g4prim->GetKineticEnergy(), pdgcode))
328 G4double charge = g4prim->GetCharge();
329 G4double momentum = g4prim->GetTotalMomentum();
333 brho *= CLHEP::tesla*CLHEP::m;
336 g4prim->GetTotalMomentum(),
341 vertexInfos.emplace_back(vertexInfo);
344 g4prim->SetMomentumDirection(G4ThreeVector(fullCoords.global.xp,
345 fullCoords.global.yp,
346 fullCoords.global.zp));
347 g4vtx->SetPrimary(g4prim);
350 if (nParticlesSkipped > 0 && warnAboutSkippedParticles)
351 {G4cout << __METHOD_NAME__ << nParticlesSkipped <<
" particles skipped" << G4endl;}
354 if (g4vtx->GetNumberOfParticle() == 0)
358 if (warnAboutSkippedParticles)
359 {G4cout << __METHOD_NAME__ <<
"no particles found in event number: " << currentFileEventIndex <<
" in the file" << G4endl;}
364 g4event->AddPrimaryVertex(g4vtx);
365 vertexGeneratedSuccessfully =
true;
366 nEventsReadThatPassedFilters++;
A set of particle coordinates in both local and global.
A set of particle coordinates including energy and weight.
G4double s
TODO - remove this. Unused. S (global) is calculated from S0 + z.