114 currentFileEventIndex = 0;
115 endOfFileReached =
false;
117 {G4cout << __METHOD_NAME__ <<
"Opening file: " << fileName << G4endl;}
120 case BDSEventGeneratorFileType::hepmc2:
121 {reader =
new HepMC3::ReaderAsciiHepMC2(fileName);
break;}
122 case BDSEventGeneratorFileType::hepmc3:
123 {reader =
new HepMC3::ReaderAscii(fileName);
break;}
124 case BDSEventGeneratorFileType::hpe:
125 {reader =
new HepMC3::ReaderHEPEVT(fileName);
break;}
126#ifdef USE_HEPMC3_ROOTIO
127 case BDSEventGeneratorFileType::root:
128 {reader =
new HepMC3::ReaderRoot(fileName);
break;}
129 case BDSEventGeneratorFileType::treeroot:
130 {reader =
new HepMC3::ReaderRootTree(fileName);
break;}
132 case BDSEventGeneratorFileType::root:
133 case BDSEventGeneratorFileType::treeroot:
135 throw BDSException(__METHOD_NAME__,
"HEPMC3 installation not compiled with ROOT support so can't load root file.");
139 case BDSEventGeneratorFileType::lhef:
140 {reader =
new HepMC3::ReaderLHEF(fileName);
break;}
221 if (nEventsToSkip > 0)
222 {G4cout << __METHOD_NAME__ <<
"skipping " << nEventsToSkip <<
" into file." << G4endl;}
226 G4long nAvailable = nEventsInFile * distrFileLoopNTimes;
227 if ((G4long)nEventsToSkip > nAvailable)
229 G4String msg =
"number of events to skip (" + std::to_string(nEventsToSkip) +
") is greater than the number of events (";
230 msg += std::to_string(nEventsInFile);
231 if (distrFileLoopNTimes > 1)
232 {msg +=
" x " + std::to_string(distrFileLoopNTimes) +
" loops of file";}
233 msg +=
") in this file.";
234 throw BDSException(
"BDSBunchUserFile::RecreateAdvanceToEvent>", msg);
236 G4long nToSkipSinglePass = nEventsToSkip % nEventsInFile;
237 for (G4int i = 0; i < nToSkipSinglePass; i++)
247 G4PrimaryVertex* g4vtx =
new G4PrimaryVertex(centralCoordsGlobal.global.x,
248 centralCoordsGlobal.global.y,
249 centralCoordsGlobal.global.z,
250 centralCoordsGlobal.global.T);
252 double overallWeight = 1.0;
253 if (!(hepmcevt->weights().empty()))
254 {overallWeight = hepmcevt->weight();}
255 std::vector<BDSPrimaryVertexInformation> vertexInfos;
256 G4int nParticlesSkipped = 0;
257 for (
const auto& particlePtr : hepmcevt->particles())
259 const HepMC3::GenParticle* particle = particlePtr.get();
260 if (!particle->children().empty())
263 int pdgcode = particle->pdg_id();
264 const HepMC3::FourVector& fv = particle->momentum();
265 G4LorentzVector p(fv.px(), fv.py(), fv.pz(), fv.e());
266 G4double px = p.x() * CLHEP::GeV;
267 G4double py = p.y() * CLHEP::GeV;
268 G4double pz = p.z() * CLHEP::GeV;
269 G4ThreeVector originalUnitMomentum(px,py,pz);
271 originalUnitMomentum = originalUnitMomentum.unit();
272 G4double rp = std::hypot(originalUnitMomentum.x(), originalUnitMomentum.y());
275 G4ThreeVector unitMomentum = originalUnitMomentum;
276 unitMomentum.transform(referenceBeamMomentumOffset);
279 G4PrimaryParticle* g4prim =
new G4PrimaryParticle(pdgcode, px, py, pz);
284 const G4ParticleDefinition* pd = g4prim->GetParticleDefinition();
285 G4bool deleteIt = !pd;
286 if (pd && removeUnstableWithoutDecay)
287 {deleteIt = !(pd->GetPDGStable()) && !pd->GetDecayTable();}
292 G4cout << __METHOD_NAME__ <<
"skipping particle with PDG ID: " << pdgcode << G4endl;
307 g4prim->GetTotalEnergy(),
310 if (!bunch->
AcceptParticle(local, rp, g4prim->GetKineticEnergy(), pdgcode))
327 G4double charge = g4prim->GetCharge();
328 G4double momentum = g4prim->GetTotalMomentum();
332 brho *= CLHEP::tesla*CLHEP::m;
335 g4prim->GetTotalMomentum(),
340 vertexInfos.emplace_back(vertexInfo);
343 g4prim->SetMomentumDirection(G4ThreeVector(fullCoords.global.xp,
344 fullCoords.global.yp,
345 fullCoords.global.zp));
346 g4vtx->SetPrimary(g4prim);
349 if (nParticlesSkipped > 0 && warnAboutSkippedParticles)
350 {G4cout << __METHOD_NAME__ << nParticlesSkipped <<
" particles skipped" << G4endl;}
353 if (g4vtx->GetNumberOfParticle() == 0)
357 if (warnAboutSkippedParticles)
358 {G4cout << __METHOD_NAME__ <<
"no particles found in event number: " << currentFileEventIndex <<
" in the file" << G4endl;}
363 g4event->AddPrimaryVertex(g4vtx);
364 vertexGeneratedSuccessfully =
true;
365 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.