BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
Data Structures | Public Member Functions | Private Member Functions | Private Attributes
BDSBunchUserFile< T > Class Template Reference

A bunch distribution that reads a user specified column file. More...

#include <BDSBunchUserFile.hh>

Inheritance diagram for BDSBunchUserFile< T >:
Inheritance graph
Collaboration diagram for BDSBunchUserFile< T >:
Collaboration graph

Data Structures

struct  Doublet
 Struct for name and unit pair. More...
 

Public Member Functions

virtual void SetOptions (const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
 Pull out the relevant options and then pass through to BDSBunch::SetOptions().
 
virtual void CheckParameters ()
 
virtual void RecreateAdvanceToEvent (G4int eventOffset)
 
virtual BDSParticleCoordsFullGlobal GetNextParticleValid (G4int maxTries)
 
virtual G4bool DistributionIsFinished () const
 
virtual BDSParticleCoordsFull GetNextParticleLocal ()
 Get the next particle.
 
virtual G4bool ExpectChangingParticleType () const
 For this class we generally can expect a few extra particle types.
 
- Public Member Functions inherited from BDSBunchFileBased
 BDSBunchFileBased (const G4String &distributionName)
 
virtual void BeginOfRunAction (G4int numberOfEvents, G4bool batchMode)
 
void SetNEventsInFile (unsigned long long int nEventsInFileIn)
 
void SetNOriginalEvents (unsigned long long int nOriginalEventsIn)
 
void IncrementNEventsInFileSkipped ()
 
void IncrementNEventsInFileSkipped (unsigned long long int plus)
 
virtual void SetOptions (const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
 Pull out the relevant options and then pass through to BDSBunch::SetOptions().
 
BDSBunchFileBasedoperator= (const BDSBunchFileBased &)=delete
 Assignment and copy constructor not implemented nor used.
 
 BDSBunchFileBased (BDSBunchFileBased &)=delete
 Assignment and copy constructor not implemented nor used.
 
unsigned long long int NOriginalEvents () const
 Accessor.
 
unsigned long long int NEventsInFile () const
 Accessor.
 
unsigned long long int NEventsInFileSkipped () const
 Accessor.
 
G4int DistrFileLoopNTimes () const
 Accessor.
 
- Public Member Functions inherited from BDSBunch
 BDSBunch (const G4String &nameIn)
 
virtual void SetOptions (const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
 
virtual void CheckParameters ()
 
virtual void Initialise ()
 Any initialisation - to be used after SetOptions, then CheckParameters.
 
BDSParticleCoordsFullGlobal GetNextParticle ()
 
virtual G4bool ExpectChangingParticleType () const
 A hint of whether we expect to require and extended particle set (ie pions, kaons, muons).
 
virtual BDSParticleCoordsFullGlobal GetNextParticleValid (G4int maxTries=100)
 
virtual void BeginOfRunAction (G4int numberOfEvents, G4bool batchMode)
 
virtual const BDSParticleDefinitionParticleDefinition () const
 Access the beam particle definition.
 
virtual void SetGeneratePrimariesOnly (G4bool generatePrimariesOnlyIn)
 
virtual BDSParticleCoordsFull GetNextParticleLocal ()
 
G4bool UseCurvilinearTransform () const
 Access whether there's a finite S offset and therefore we're using a CL transform.
 
virtual void RecreateAdvanceToEvent (G4int eventOffset)
 
G4bool BeamParticleIsAnIon () const
 Access whether the beam particle is an ion or not.
 
virtual void UpdateIonDefinition ()
 
G4bool ParticleDefinitionHasBeenUpdated () const
 
G4String Name () const
 Distribution name.
 
G4int CurrentBunchIndex () const
 Get the current bunch index for writing to output.
 
void CalculateBunchIndex (G4int eventIndex)
 Calculate which bunch index we should be at given an event index.
 

Private Member Functions

void ParseFileFormat ()
 Parse the column tokens and units factors.
 
void OpenBunchFile ()
 Open the file and check it's open.
 
void SkipNLinesIgnoreIntoFile (G4bool usualPrintOut=true)
 
void SkipNLinesSkip (G4bool usualPrintOut=true)
 
void CloseBunchFile ()
 Close the file handler.
 
void skip (std::stringstream &stream, G4int nvalues)
 
template<typename Type >
void ReadValue (std::stringstream &stream, Type &value)
 
G4bool SkippableLine (const std::string &line) const
 Return true if a line is all whitespace or is commented out (starts with '#').
 
void CheckConflictingParameters (const std::set< G4String > &s) const
 Check conflicting columns aren't specified in file, e.g. P and Ek. Throw exception if wrong.
 
template<typename U >
void CheckAndParseUnits (const G4String &name, const G4String &rest, U unitParser)
 
G4long CountNLinesValidDataInFile ()
 
virtual void Initialise ()
 Open the file and skip lines.
 
void EndOfFileAction ()
 

Private Attributes

G4String distrFile
 Bunch file.
 
G4String distrFilePath
 Bunch file including absolute path.
 
G4String bunchFormat
 Format of the file.
 
G4long nlinesIgnore
 Number of lines that will be ignored at the start the file.
 
G4long nlinesSkip
 Number of lines that will be skipped after the nlinesIgnore.
 
G4long nLinesValidData
 
G4double particleMass
 Cache of nominal beam particle mass.
 
G4int lineCounter
 Line counter.
 
G4bool printedOutFirstTime
 Whether we've printed out opening the file the first time.
 
G4bool anEnergyCoordinateInUse
 Whether Et, Ek or P are in the columns.
 
G4bool changingParticleType
 Whether the particle type is a column.
 
G4bool endOfFileReached
 
InputBunchFile
 The file handler. Templated as could be std::ifstream or igzstream for example.
 
std::list< Doubletfields
 List of variables to parse on each line.
 
G4double ffact
 Cache of flip factor from global constants.
 
std::regex comment
 
G4bool matchDistrFileLength
 

Additional Inherited Members

- Static Public Member Functions inherited from BDSBunch
static G4double CalculateZp (G4double xp, G4double yp, G4double Zp0)
 Calculate zp safely based on other components.
 
static void SetEmittances (const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, G4double &emittGeometricX, G4double &emittGeometricY, G4double &emittNormalisedX, G4double &emittNormalisedY)
 
- Protected Member Functions inherited from BDSBunch
BDSParticleCoordsFullGlobal ApplyTransform (const BDSParticleCoordsFull &localIn) const
 
void ApplyTilt (BDSParticleCoordsFull &localIn) const
 Apply a rotation about unitZ for the local coordinates according to member variable tilt.
 
void ApplyBunchTiming (BDSParticleCoordsFullGlobal &localIn) const
 Add on the offset in T for the current bunch number (i*bunchPeriod).
 
BDSParticleCoordsFullGlobal ApplyCurvilinearTransform (const BDSParticleCoordsFull &localIn) const
 Calculate the global coordinates from curvilinear coordinates of a beam line.
 
- Protected Attributes inherited from BDSBunchFileBased
unsigned long long int nOriginalEvents
 nOriginalEvents from upstream file if skimmed - need to pass through.
 
unsigned long long int nEventsInFile
 The number of entries in the file loaded.
 
unsigned long long int nEventsInFileSkipped
 Number that are skipped as we go through the file due to filters.
 
G4bool distrFileLoop
 
G4int distrFileLoopNTimes
 
- Protected Attributes inherited from BDSBunch
G4String name
 Name of distribution.
 
G4bool useCurvilinear
 Whether to ignore z and use s and transform for curvilinear coordinates.
 
BDSParticleDefinitionparticleDefinition
 Particle definition for bunch - this class owns it.
 
G4bool particleDefinitionHasBeenUpdated
 
G4bool finiteTilt
 
G4bool generatePrimariesOnly
 
G4double X0
 Centre of distributions.
 
G4double Y0
 Centre of distributions.
 
G4double Z0
 Centre of distributions.
 
G4double S0
 Centre of distributions.
 
G4double T0
 Centre of distributions.
 
G4double Xp0
 Centre of distributions.
 
G4double Yp0
 Centre of distributions.
 
G4double Zp0
 Centre of distributions.
 
G4double E0
 Centre of distributions.
 
G4double P0
 central momentum
 
G4double tilt
 Centre of distributions.
 
G4double sigmaT
 Centre of distributions.
 
G4double sigmaP
 Centre of distributions.
 
G4double sigmaE
 Centre of distributions.
 
G4double sigmaEk
 Centre of distributions.
 
bool useBunchTiming
 Bunch offset in time parameters.
 
G4int currentBunchIndex
 Bunch offset in time parameters.
 
G4int eventsPerBunch
 Bunch offset in time parameters.
 
G4double bunchPeriod
 Bunch offset in time parameters.
 
G4bool finiteSigmaE
 Flags to ignore random number generator in case of no finite E or T.
 
G4bool finiteSigmaT
 Flags to ignore random number generator in case of no finite E or T.
 

Detailed Description

template<class T>
class BDSBunchUserFile< T >

A bunch distribution that reads a user specified column file.

Author
Lawrence Deacon

Definition at line 45 of file BDSBunchUserFile.hh.

Constructor & Destructor Documentation

◆ BDSBunchUserFile()

template<class T >
BDSBunchUserFile< T >::BDSBunchUserFile

Definition at line 48 of file BDSBunchUserFile.cc.

◆ ~BDSBunchUserFile()

template<class T >
BDSBunchUserFile< T >::~BDSBunchUserFile
virtual

Definition at line 74 of file BDSBunchUserFile.cc.

Member Function Documentation

◆ CheckAndParseUnits()

template<typename T >
template<typename U >
void BDSBunchUserFile< T >::CheckAndParseUnits ( const G4String &  name,
const G4String &  rest,
unitParser 
)
private

Definition at line 219 of file BDSBunchUserFile.cc.

◆ CheckConflictingParameters()

template<typename T >
void BDSBunchUserFile< T >::CheckConflictingParameters ( const std::set< G4String > &  s) const
private

Check conflicting columns aren't specified in file, e.g. P and Ek. Throw exception if wrong.

Definition at line 199 of file BDSBunchUserFile.cc.

References BDSBunchUserFile< T >::fields.

Referenced by BDSBunchUserFile< T >::ParseFileFormat().

Here is the caller graph for this function:

◆ CheckParameters()

template<class T >
void BDSBunchUserFile< T >::CheckParameters
virtual

Check the parameters for the given bunch distribution and exit if they're problematic or unphysical.

Reimplemented from BDSBunch.

Definition at line 66 of file BDSBunchUserFile.cc.

References BDSBunch::CheckParameters().

Here is the call graph for this function:

◆ CloseBunchFile()

template<class T >
void BDSBunchUserFile< T >::CloseBunchFile
private

Close the file handler.

Definition at line 95 of file BDSBunchUserFile.cc.

Referenced by BDSBunchUserFile< T >::CountNLinesValidDataInFile(), and BDSBunchUserFile< T >::EndOfFileAction().

Here is the caller graph for this function:

◆ CountNLinesValidDataInFile()

template<class T >
G4long BDSBunchUserFile< T >::CountNLinesValidDataInFile
private

Open the file, skip the nlinesIgnore, then count the number of valid lines in the file. A valid line is one that can be used for coordinates, so empty lines or commented lines are ignored from this count. This number should be the number of particle coordinate sets we can read from the file.

Definition at line 329 of file BDSBunchUserFile.cc.

References BDSBunchUserFile< T >::CloseBunchFile(), BDSBunchUserFile< T >::InputBunchFile, BDSBunchUserFile< T >::OpenBunchFile(), BDSBunchUserFile< T >::SkipNLinesIgnoreIntoFile(), and BDSBunchUserFile< T >::SkippableLine().

Referenced by BDSBunchUserFile< T >::Initialise().

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

◆ DistributionIsFinished()

template<class T >
virtual G4bool BDSBunchUserFile< T >::DistributionIsFinished ( ) const
inlinevirtual

Definition at line 69 of file BDSBunchUserFile.hh.

◆ EndOfFileAction()

template<class T >
void BDSBunchUserFile< T >::EndOfFileAction
private

Print out warning we're looping and reopen file from beginning. Includes skipping lines. Put in a function as used in multiple places.

Definition at line 412 of file BDSBunchUserFile.cc.

References BDSBunchUserFile< T >::CloseBunchFile(), BDSBunchUserFile< T >::OpenBunchFile(), BDSBunchUserFile< T >::SkipNLinesIgnoreIntoFile(), and BDSBunchUserFile< T >::SkipNLinesSkip().

Referenced by BDSBunchUserFile< T >::GetNextParticleLocal().

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

◆ ExpectChangingParticleType()

template<class T >
virtual G4bool BDSBunchUserFile< T >::ExpectChangingParticleType ( ) const
inlinevirtual

For this class we generally can expect a few extra particle types.

Reimplemented from BDSBunch.

Definition at line 75 of file BDSBunchUserFile.hh.

◆ GetNextParticleLocal()

template<class T >
BDSParticleCoordsFull BDSBunchUserFile< T >::GetNextParticleLocal
virtual

◆ GetNextParticleValid()

template<class T >
BDSParticleCoordsFullGlobal BDSBunchUserFile< T >::GetNextParticleValid ( G4int  maxTries)
virtual

Override base class method to find valid particle over rest mass. For a bunch file Just return one line each time. If it doesn't work as a particle, the event is aborted and the user has a 1:1 representation of particle coordinates to events in the output.

Reimplemented from BDSBunch.

Definition at line 478 of file BDSBunchUserFile.cc.

References BDSBunch::GetNextParticle().

Here is the call graph for this function:

◆ Initialise()

template<class T >
void BDSBunchUserFile< T >::Initialise
privatevirtual

◆ OpenBunchFile()

template<class T >
void BDSBunchUserFile< T >::OpenBunchFile
private

Open the file and check it's open.

Definition at line 80 of file BDSBunchUserFile.cc.

Referenced by BDSBunchUserFile< T >::CountNLinesValidDataInFile(), BDSBunchUserFile< T >::EndOfFileAction(), and BDSBunchUserFile< T >::Initialise().

Here is the caller graph for this function:

◆ ParseFileFormat()

template<class T >
void BDSBunchUserFile< T >::ParseFileFormat
private

◆ ReadValue()

template<class T >
template<typename Type >
void BDSBunchUserFile< T >::ReadValue ( std::stringstream &  stream,
Type &  value 
)
private

Read a word into a value. Templated so we can cleverly use different types to read into directly such as int or double.

Definition at line 647 of file BDSBunchUserFile.cc.

Referenced by BDSBunchUserFile< T >::GetNextParticleLocal(), and BDSBunchUserFile< T >::skip().

Here is the caller graph for this function:

◆ RecreateAdvanceToEvent()

template<class T >
void BDSBunchUserFile< T >::RecreateAdvanceToEvent ( G4int  eventOffset)
virtual

Advance to the correct event number in the file for recreation. The implementation is brute-force getting of the lines - this could be more efficient (certainly for a file that is looped over multiple times) but this is simple, clear and the time penalty is on the order of 1 minute for ~100k events.

Reimplemented from BDSBunch.

Definition at line 430 of file BDSBunchUserFile.cc.

References BDSBunchUserFile< T >::InputBunchFile, BDSGlobalConstants::Instance(), BDSBunchUserFile< T >::lineCounter, BDSBunchUserFile< T >::nlinesSkip, BDSBunch::RecreateAdvanceToEvent(), and BDSBunchUserFile< T >::SkippableLine().

Here is the call graph for this function:

◆ SetOptions()

template<class T >
void BDSBunchUserFile< T >::SetOptions ( const BDSParticleDefinition beamParticle,
const GMAD::Beam beam,
const BDSBunchType distrType,
G4Transform3D  beamlineTransformIn = G4Transform3D::Identity,
const G4double  beamlineS = 0 
)
virtual

◆ skip()

template<class T >
void BDSBunchUserFile< T >::skip ( std::stringstream &  stream,
G4int  nvalues 
)
private

Read a word out of the string stream, in effect advancing the internal string stream iterator.

Definition at line 250 of file BDSBunchUserFile.cc.

References BDSBunchUserFile< T >::ReadValue().

Here is the call graph for this function:

◆ SkipNLinesIgnoreIntoFile()

template<class T >
void BDSBunchUserFile< T >::SkipNLinesIgnoreIntoFile ( G4bool  usualPrintOut = true)
private

Skip nlinesIgnore into the file irrespective of what's on the lines. If the end of file is reached, an exception is thrown.

Definition at line 258 of file BDSBunchUserFile.cc.

References BDSBunchUserFile< T >::InputBunchFile, BDS::IsFinite(), BDSBunchUserFile< T >::lineCounter, and BDSBunchUserFile< T >::nlinesIgnore.

Referenced by BDSBunchUserFile< T >::CountNLinesValidDataInFile(), BDSBunchUserFile< T >::EndOfFileAction(), and BDSBunchUserFile< T >::Initialise().

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

◆ SkipNLinesSkip()

template<class T >
void BDSBunchUserFile< T >::SkipNLinesSkip ( G4bool  usualPrintOut = true)
private

Skip nlinesSkip further into the data where a line has to be 'valid' - i.e. it is not an empty or comment line.

Definition at line 281 of file BDSBunchUserFile.cc.

References BDSBunchUserFile< T >::InputBunchFile, BDS::IsFinite(), BDSBunchUserFile< T >::nlinesSkip, and BDSBunchUserFile< T >::SkippableLine().

Referenced by BDSBunchUserFile< T >::EndOfFileAction(), and BDSBunchUserFile< T >::Initialise().

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

◆ SkippableLine()

template<class T >
G4bool BDSBunchUserFile< T >::SkippableLine ( const std::string &  line) const
private

Return true if a line is all whitespace or is commented out (starts with '#').

Definition at line 323 of file BDSBunchUserFile.cc.

Referenced by BDSBunchUserFile< T >::CountNLinesValidDataInFile(), BDSBunchUserFile< T >::GetNextParticleLocal(), BDSBunchUserFile< T >::RecreateAdvanceToEvent(), and BDSBunchUserFile< T >::SkipNLinesSkip().

Here is the caller graph for this function:

Field Documentation

◆ anEnergyCoordinateInUse

template<class T >
G4bool BDSBunchUserFile< T >::anEnergyCoordinateInUse
private

Whether Et, Ek or P are in the columns.

Definition at line 87 of file BDSBunchUserFile.hh.

Referenced by BDSBunchUserFile< T >::GetNextParticleLocal(), and BDSBunchUserFile< T >::ParseFileFormat().

◆ bunchFormat

template<class T >
G4String BDSBunchUserFile< T >::bunchFormat
private

Format of the file.

Definition at line 80 of file BDSBunchUserFile.hh.

Referenced by BDSBunchUserFile< T >::ParseFileFormat(), and BDSBunchUserFile< T >::SetOptions().

◆ changingParticleType

template<class T >
G4bool BDSBunchUserFile< T >::changingParticleType
private

Whether the particle type is a column.

Definition at line 88 of file BDSBunchUserFile.hh.

Referenced by BDSBunchUserFile< T >::GetNextParticleLocal(), and BDSBunchUserFile< T >::ParseFileFormat().

◆ comment

template<class T >
std::regex BDSBunchUserFile< T >::comment
private

Definition at line 147 of file BDSBunchUserFile.hh.

◆ distrFile

template<class T >
G4String BDSBunchUserFile< T >::distrFile
private

Bunch file.

Definition at line 78 of file BDSBunchUserFile.hh.

Referenced by BDSBunchUserFile< T >::SetOptions().

◆ distrFilePath

template<class T >
G4String BDSBunchUserFile< T >::distrFilePath
private

Bunch file including absolute path.

Definition at line 79 of file BDSBunchUserFile.hh.

Referenced by BDSBunchUserFile< T >::Initialise(), and BDSBunchUserFile< T >::SetOptions().

◆ endOfFileReached

template<class T >
G4bool BDSBunchUserFile< T >::endOfFileReached
private

Definition at line 89 of file BDSBunchUserFile.hh.

◆ ffact

template<class T >
G4double BDSBunchUserFile< T >::ffact
private

Cache of flip factor from global constants.

Definition at line 146 of file BDSBunchUserFile.hh.

Referenced by BDSBunchUserFile< T >::GetNextParticleLocal().

◆ fields

template<class T >
std::list<Doublet> BDSBunchUserFile< T >::fields
private

◆ InputBunchFile

template<class T >
T BDSBunchUserFile< T >::InputBunchFile
private

◆ lineCounter

template<class T >
G4int BDSBunchUserFile< T >::lineCounter
private

◆ matchDistrFileLength

template<class T >
G4bool BDSBunchUserFile< T >::matchDistrFileLength
private

Definition at line 148 of file BDSBunchUserFile.hh.

◆ nlinesIgnore

template<class T >
G4long BDSBunchUserFile< T >::nlinesIgnore
private

Number of lines that will be ignored at the start the file.

Definition at line 81 of file BDSBunchUserFile.hh.

Referenced by BDSBunchUserFile< T >::SetOptions(), and BDSBunchUserFile< T >::SkipNLinesIgnoreIntoFile().

◆ nlinesSkip

template<class T >
G4long BDSBunchUserFile< T >::nlinesSkip
private

Number of lines that will be skipped after the nlinesIgnore.

Definition at line 82 of file BDSBunchUserFile.hh.

Referenced by BDSBunchUserFile< T >::Initialise(), BDSBunchUserFile< T >::RecreateAdvanceToEvent(), BDSBunchUserFile< T >::SetOptions(), and BDSBunchUserFile< T >::SkipNLinesSkip().

◆ nLinesValidData

template<class T >
G4long BDSBunchUserFile< T >::nLinesValidData
private

Definition at line 83 of file BDSBunchUserFile.hh.

◆ particleMass

template<class T >
G4double BDSBunchUserFile< T >::particleMass
private

Cache of nominal beam particle mass.

Definition at line 84 of file BDSBunchUserFile.hh.

Referenced by BDSBunchUserFile< T >::SetOptions().

◆ printedOutFirstTime

template<class T >
G4bool BDSBunchUserFile< T >::printedOutFirstTime
private

Whether we've printed out opening the file the first time.

Definition at line 86 of file BDSBunchUserFile.hh.


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