BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
BDSPrimaryGeneratorFileHEPMC Class Reference

Loader to use any HepMC3 compatible file. More...

#include <BDSPrimaryGeneratorFileHEPMC.hh>

Inheritance diagram for BDSPrimaryGeneratorFileHEPMC:
Inheritance graph
Collaboration diagram for BDSPrimaryGeneratorFileHEPMC:
Collaboration graph

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.
 
- Public Member Functions inherited from BDSPrimaryGeneratorFile
 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.
 
- Protected Member Functions inherited from BDSPrimaryGeneratorFile
G4bool VertexInsideWorld (const G4ThreeVector &pos) const
 Utility function for derived classes to check a position is inside the world.
 

Protected Attributes

HepMC3::GenEvent * hepmcEvent
 
- Protected Attributes inherited from BDSPrimaryGeneratorFile
G4bool loopFile
 
BDSBunchEventGeneratorbunch
 
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 Public Member Functions inherited from BDSPrimaryGeneratorFile
static BDSPrimaryGeneratorFileConstructGenerator (const GMAD::Beam &beam, BDSBunch *bunchIn, G4bool recreate, G4int eventOffset, G4bool batchMode)
 

Detailed Description

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.

Author
Helena Lefebvre, Laurie Nevay

Definition at line 55 of file BDSPrimaryGeneratorFileHEPMC.hh.

Constructor & Destructor Documentation

◆ BDSPrimaryGeneratorFileHEPMC()

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().

Here is the call graph for this function:

◆ ~BDSPrimaryGeneratorFileHEPMC()

BDSPrimaryGeneratorFileHEPMC::~BDSPrimaryGeneratorFileHEPMC ( )
virtual

Definition at line 90 of file BDSPrimaryGeneratorFileHEPMC.cc.

Member Function Documentation

◆ CloseFile()

void BDSPrimaryGeneratorFileHEPMC::CloseFile ( )
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().

Here is the caller graph for this function:

◆ CountEventsInFile()

G4long BDSPrimaryGeneratorFileHEPMC::CountEventsInFile ( )
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GeneratePrimaryVertex()

void BDSPrimaryGeneratorFileHEPMC::GeneratePrimaryVertex ( G4Event *  anEvent)
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().

Here is the call graph for this function:

◆ GetHepMCGenEvent()

HepMC3::GenEvent * BDSPrimaryGeneratorFileHEPMC::GetHepMCGenEvent ( ) const
inline

Accessor.

Definition at line 73 of file BDSPrimaryGeneratorFileHEPMC.hh.

◆ HepMC2G4()

void BDSPrimaryGeneratorFileHEPMC::HepMC2G4 ( const HepMC3::GenEvent *  hepmcevt,
G4Event *  g4event 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenFile()

void BDSPrimaryGeneratorFileHEPMC::OpenFile ( G4bool  usualPrintOut = true)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadSingleEvent()

G4bool BDSPrimaryGeneratorFileHEPMC::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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RecreateAdvanceToEvent()

void BDSPrimaryGeneratorFileHEPMC::RecreateAdvanceToEvent ( G4int  eventOffset)
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().

Here is the call graph for this function:

◆ SkipEvents()

void BDSPrimaryGeneratorFileHEPMC::SkipEvents ( G4int  nEventsToSkip)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ fileName

G4String BDSPrimaryGeneratorFileHEPMC::fileName
private

Definition at line 115 of file BDSPrimaryGeneratorFileHEPMC.hh.

◆ fileType

BDSEventGeneratorFileType BDSPrimaryGeneratorFileHEPMC::fileType
private

Definition at line 118 of file BDSPrimaryGeneratorFileHEPMC.hh.

◆ hepmcEvent

HepMC3::GenEvent* BDSPrimaryGeneratorFileHEPMC::hepmcEvent
protected

Definition at line 111 of file BDSPrimaryGeneratorFileHEPMC.hh.

◆ reader

HepMC3::Reader* BDSPrimaryGeneratorFileHEPMC::reader
private

Definition at line 114 of file BDSPrimaryGeneratorFileHEPMC.hh.

◆ referenceBeamMomentumOffset

G4RotationMatrix BDSPrimaryGeneratorFileHEPMC::referenceBeamMomentumOffset
private

Definition at line 119 of file BDSPrimaryGeneratorFileHEPMC.hh.

◆ removeUnstableWithoutDecay

G4bool BDSPrimaryGeneratorFileHEPMC::removeUnstableWithoutDecay
private

Definition at line 116 of file BDSPrimaryGeneratorFileHEPMC.hh.

◆ warnAboutSkippedParticles

G4bool BDSPrimaryGeneratorFileHEPMC::warnAboutSkippedParticles
private

Definition at line 117 of file BDSPrimaryGeneratorFileHEPMC.hh.


The documentation for this class was generated from the following files: