BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
|
Loader to use any HepMC3 compatible file. More...
#include <BDSPrimaryGeneratorFileHEPMC.hh>
Public Member Functions | |
BDSPrimaryGeneratorFileHEPMC ()=delete | |
Do not require default constructor. | |
BDSPrimaryGeneratorFileHEPMC (const G4String &distrType, const G4String &fileNameIn, BDSBunchEventGenerator *bunchIn, G4bool loopFileIn, G4bool removeUnstableWithoutDecayIn=true, G4bool warnAboutSkippedParticlesIn=true) | |
HepMC3::GenEvent * | GetHepMCGenEvent () const |
Accessor. | |
virtual void | GeneratePrimaryVertex (G4Event *anEvent) |
virtual void | RecreateAdvanceToEvent (G4int eventOffset) |
Advance to the correct event number in the file for recreation. | |
![]() | |
BDSPrimaryGeneratorFile (G4bool loopFileIn, BDSBunchEventGenerator *bunchIn) | |
G4bool | GeneratePrimaryVertexSafe (G4Event *event) |
Return false if not able to generate a primary vertex. | |
virtual void | RecreateAdvanceToEvent (G4int eventOffset)=0 |
Advance into the file as required. | |
G4long | NEventsInFile () const |
G4long | NEventsLeftInFile () const |
G4bool | OKToLoopFile () const |
G4long | NEventsReadThatPassedFilters () const |
Accessor. | |
G4long | NEventsSkipped () const |
Return the offset into the file if any. | |
G4bool | DistributionIsFinished () const |
Report whether the distribution is finished generating. | |
void | ThrowExceptionIfRecreateOffsetTooHigh (G4long eventOffset) const |
Protected Member Functions | |
void | OpenFile (G4bool usualPrintOut=true) |
Construct the member "reader" and open the file for reading. | |
void | CloseFile () |
G4long | CountEventsInFile () |
G4bool | ReadSingleEvent () |
void | SkipEvents (G4int nEventsToSkip) |
void | HepMC2G4 (const HepMC3::GenEvent *hepmcevt, G4Event *g4event) |
Conversion from HepMC::GenEvent to G4Event. | |
![]() | |
G4bool | VertexInsideWorld (const G4ThreeVector &pos) const |
Utility function for derived classes to check a position is inside the world. | |
Protected Attributes | |
HepMC3::GenEvent * | hepmcEvent |
![]() | |
G4bool | loopFile |
BDSBunchEventGenerator * | bunch |
G4bool | endOfFileReached |
G4bool | vertexGeneratedSuccessfully |
G4long | currentFileEventIndex |
G4long | nEventsInFile |
G4long | nEventsReadThatPassedFilters |
G4long | nEventsSkipped |
G4VSolid * | worldSolid |
Private Attributes | |
HepMC3::Reader * | reader |
G4String | fileName |
G4bool | removeUnstableWithoutDecay |
G4bool | warnAboutSkippedParticles |
BDSEventGeneratorFileType | fileType |
G4RotationMatrix | referenceBeamMomentumOffset |
Additional Inherited Members | |
![]() | |
static BDSPrimaryGeneratorFile * | ConstructGenerator (const GMAD::Beam &beam, BDSBunch *bunchIn, G4bool recreate, G4int eventOffset, G4bool batchMode) |
Loader to use any HepMC3 compatible file.
Interface to use HepMC3 library to load a variety of files.
This is largely based on Geant4's example examples/extended/eventgenerator/HepMC/HepMCEx01, however it has been rewritten to use HepMC3 library rather than HepMC2. Additionally, the interface has been written based on HepMC3 example "convert_example" to use multiple reader classes.
Definition at line 55 of file BDSPrimaryGeneratorFileHEPMC.hh.
BDSPrimaryGeneratorFileHEPMC::BDSPrimaryGeneratorFileHEPMC | ( | const G4String & | distrType, |
const G4String & | fileNameIn, | ||
BDSBunchEventGenerator * | bunchIn, | ||
G4bool | loopFileIn, | ||
G4bool | removeUnstableWithoutDecayIn = true , |
||
G4bool | warnAboutSkippedParticlesIn = true |
||
) |
Constructor takes full distrType string including semicolon and eventgeneratorfile prefix. The filename is assumed to be correctly prefixed if a relative path already. The bunch definition is used for the reference coordinates and offset of the beam point.
Definition at line 65 of file BDSPrimaryGeneratorFileHEPMC.cc.
References CountEventsInFile(), BDS::DetermineEventGeneratorFileType(), BDSBunchEventGenerator::eventGeneratorNEventsSkip, OpenFile(), BDSBunchEventGenerator::ReferenceBeamMomentumOffset(), SkipEvents(), and BDS::SplitOnColon().
|
virtual |
Definition at line 90 of file BDSPrimaryGeneratorFileHEPMC.cc.
|
protected |
Close and delete reader. Have to delete as HepMC3 readers have no iteration or ability to loop back to the beginning.
Definition at line 147 of file BDSPrimaryGeneratorFileHEPMC.cc.
Referenced by CountEventsInFile(), and ReadSingleEvent().
|
protected |
Open the file, read all the events and count them. Do not apply any filters. Therefore, this returns the maximum number of raw events.
Definition at line 157 of file BDSPrimaryGeneratorFileHEPMC.cc.
References CloseFile(), and OpenFile().
Referenced by BDSPrimaryGeneratorFileHEPMC().
|
virtual |
This will attempt once to generate an event by reading a single event and then converting it to a Geant4 one. The second step includes applying various filters for accepted particles and it is possible the event can be read ok but no particles pass the filters. This function can therefore be used repeatedly if needs be to generate a suitable event.
Definition at line 96 of file BDSPrimaryGeneratorFileHEPMC.cc.
References HepMC2G4(), and ReadSingleEvent().
|
inline |
Accessor.
Definition at line 73 of file BDSPrimaryGeneratorFileHEPMC.hh.
|
protected |
Conversion from HepMC::GenEvent to G4Event.
Definition at line 242 of file BDSPrimaryGeneratorFileHEPMC.cc.
References BDSBunchEventGenerator::AcceptParticle(), BDSBunch::ApplyTransform(), BDS::cOverGeV, BDSBunch::GetNextParticleLocal(), BDS::IsFinite(), BDSParticleCoordsFull::s, and BDSPrimaryGeneratorFile::VertexInsideWorld().
Referenced by GeneratePrimaryVertex().
|
protected |
Construct the member "reader" and open the file for reading.
Definition at line 113 of file BDSPrimaryGeneratorFileHEPMC.cc.
References BDSTypeSafeEnum< def, inner >::underlying().
Referenced by BDSPrimaryGeneratorFileHEPMC(), CountEventsInFile(), and ReadSingleEvent().
|
protected |
Clear the hepmcEvent object, reallocate and read a single event and fill that member. Returns true if event read successfully, else false.
Definition at line 180 of file BDSPrimaryGeneratorFileHEPMC.cc.
References CloseFile(), BDSPrimaryGeneratorFile::OKToLoopFile(), and OpenFile().
Referenced by GeneratePrimaryVertex(), and SkipEvents().
|
virtual |
Advance to the correct event number in the file for recreation.
Implements BDSPrimaryGeneratorFile.
Definition at line 106 of file BDSPrimaryGeneratorFileHEPMC.cc.
References SkipEvents(), and BDSPrimaryGeneratorFile::ThrowExceptionIfRecreateOffsetTooHigh().
|
protected |
Read events but do nothing with them. Will throw an exception if the number is greater than the number of events in the file.
Definition at line 220 of file BDSPrimaryGeneratorFileHEPMC.cc.
References BDSBunchFileBased::DistrFileLoopNTimes(), and ReadSingleEvent().
Referenced by BDSPrimaryGeneratorFileHEPMC(), and RecreateAdvanceToEvent().
|
private |
Definition at line 115 of file BDSPrimaryGeneratorFileHEPMC.hh.
|
private |
Definition at line 118 of file BDSPrimaryGeneratorFileHEPMC.hh.
|
protected |
Definition at line 111 of file BDSPrimaryGeneratorFileHEPMC.hh.
|
private |
Definition at line 114 of file BDSPrimaryGeneratorFileHEPMC.hh.
|
private |
Definition at line 119 of file BDSPrimaryGeneratorFileHEPMC.hh.
|
private |
Definition at line 116 of file BDSPrimaryGeneratorFileHEPMC.hh.
|
private |
Definition at line 117 of file BDSPrimaryGeneratorFileHEPMC.hh.