BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
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)
 
virtual void CheckParameters ()
 
virtual void RecreateAdvanceToEvent (G4int eventOffset)
 
virtual BDSParticleCoordsFullGlobal GetNextParticleValid (G4int maxTries)
 
virtual BDSParticleCoordsFull GetNextParticleLocal ()
 Get the next particle. More...
 
virtual G4bool ExpectChangingParticleType () const
 For this class we generally can expect a few extra particle types. More...
 
- 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. More...
 
BDSParticleCoordsFullGlobal GetNextParticle ()
 
virtual G4bool ExpectChangingParticleType () const
 A hint of whether we expect to require and extended particle set (ie pions, kaons, muons). More...
 
virtual BDSParticleCoordsFullGlobal GetNextParticleValid (G4int maxTries=100)
 
virtual void BeginOfRunAction (G4int numberOfEvents)
 
virtual const BDSParticleDefinitionParticleDefinition () const
 Access the beam particle definition. More...
 
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. More...
 
virtual void RecreateAdvanceToEvent (G4int)
 
G4bool BeamParticleIsAnIon () const
 Access whether the beam particle is an ion or not. More...
 
virtual void UpdateIonDefinition ()
 
G4bool ParticleDefinitionHasBeenUpdated () const
 
G4String Name () const
 

Private Member Functions

void ParseFileFormat ()
 Parse the column tokens and units factors. More...
 
void OpenBunchFile ()
 Open the file and check it's open. More...
 
void SkipLines ()
 Read lines according to nlinesIgnore. More...
 
void CloseBunchFile ()
 Close the file handler. More...
 
void skip (std::stringstream &stream, G4int nvalues)
 
template<typename Type >
void ReadValue (std::stringstream &stream, Type &value)
 
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. More...
 
template<typename U >
void CheckAndParseUnits (const G4String &name, const G4String &rest, U unitParser)
 
G4int CountLinesInFile ()
 Open the file, skip lines, then count number of lines, then close file again. More...
 
virtual void Initialise ()
 Open the file and skip lines. More...
 
void EndOfFileAction ()
 

Private Attributes

G4String distrFile
 Bunch file. More...
 
G4String distrFilePath
 Bunch file including absolute path. More...
 
G4String bunchFormat
 Format of the file. More...
 
G4int nlinesIgnore
 Number of lines that will be ignored at the start the file. More...
 
G4int nlinesSkip
 Number of lines that will be skipped after the nlinesIgnore. More...
 
G4double particleMass
 Cache of nominal beam particle mass. More...
 
G4int lineCounter
 Line counter. More...
 
G4bool printedOutFirstTime
 Whether we've printed out opening the file the first time. More...
 
G4bool anEnergyCoordinateInUse
 Whether Et, Ek or P are in the columns. More...
 
G4bool changingParticleType
 Whether the particle type is a column. More...
 
InputBunchFile
 The file handler. Templated as could be std::ifstream or igzstream for example. More...
 
std::list< Doubletfields
 List of variables to parse on each line. More...
 
G4double ffact
 Cache of flip factor from global constants. More...
 
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. More...
 
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. More...
 
BDSParticleCoordsFullGlobal ApplyCurvilinearTransform (const BDSParticleCoordsFull &localIn) const
 Calculate the global coordinates from curvilinear coordinates of a beam line. More...
 
- Protected Attributes inherited from BDSBunch
G4String name
 Name of distribution. More...
 
G4bool useCurvilinear
 Whether to ignore z and use s and transform for curvilinear coordinates. More...
 
BDSParticleDefinitionparticleDefinition
 Particle definition for bunch - this class owns it. More...
 
G4bool particleDefinitionHasBeenUpdated
 
G4bool finiteTilt
 
G4bool generatePrimariesOnly
 
G4double X0
 Centre of distributions. More...
 
G4double Y0
 Centre of distributions. More...
 
G4double Z0
 Centre of distributions. More...
 
G4double S0
 Centre of distributions. More...
 
G4double T0
 Centre of distributions. More...
 
G4double Xp0
 Centre of distributions. More...
 
G4double Yp0
 Centre of distributions. More...
 
G4double Zp0
 Centre of distributions. More...
 
G4double E0
 Centre of distributions. More...
 
G4double P0
 central momentum More...
 
G4double tilt
 Centre of distributions. More...
 
G4double sigmaT
 Centre of distributions. More...
 
G4double sigmaP
 Centre of distributions. More...
 
G4double sigmaE
 Centre of distributions. More...
 
G4double sigmaEk
 Centre of distributions. More...
 
G4bool finiteSigmaE
 Flags to ignore random number generator in case of no finite E or T. More...
 
G4bool finiteSigmaT
 Flags to ignore random number generator in case of no finite E or T. More...
 

Detailed Description

template<class T>
class BDSBunchUserFile< T >

A bunch distribution that reads a user specified column file.

Author
Lawrence Deacon

Definition at line 44 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 217 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 197 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 94 of file BDSBunchUserFile.cc.

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

Here is the caller graph for this function:

◆ CountLinesInFile()

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

Open the file, skip lines, then count number of lines, then close file again.

Definition at line 290 of file BDSBunchUserFile.cc.

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

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

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

◆ 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 323 of file BDSBunchUserFile.cc.

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

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

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 72 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 350 of file BDSBunchUserFile.cc.

References BDSBunch::GetNextParticle().

Here is the call graph for this function:

◆ Initialise()

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

Open the file and skip lines.

Reimplemented from BDSBunch.

Definition at line 309 of file BDSBunchUserFile.cc.

References BDSBunchUserFile< T >::CountLinesInFile(), BDSGlobalConstants::Instance(), BDSBunchUserFile< T >::OpenBunchFile(), BDSGlobalConstants::SetNumberToGenerate(), and BDSBunchUserFile< T >::SkipLines().

Here is the call graph for this function:

◆ 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 >::CountLinesInFile(), 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 520 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 334 of file BDSBunchUserFile.cc.

References BDSBunchUserFile< T >::EndOfFileAction(), BDSBunchUserFile< T >::InputBunchFile, and BDSBunchUserFile< T >::lineCounter.

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

Extract and set the relevant options from the beam definition. The distribution type is explicitly required as this function may be used inside a nested bunch distribution. This argument is for the most part ignored, but there's no way to have a default for it. Also, some classes can cover multiple input distributions so need to know which one they're meant to be.

Reimplemented from BDSBunch.

Definition at line 272 of file BDSBunchUserFile.cc.

References BDSBunchUserFile< T >::bunchFormat, BDSBunchUserFile< T >::distrFile, GMAD::BeamBase::distrFile, GMAD::BeamBase::distrFileFormat, BDSBunchUserFile< T >::distrFilePath, BDS::GetFullPath(), BDSParticleDefinition::Mass(), GMAD::BeamBase::matchDistrFileLength, BDSBunchUserFile< T >::nlinesIgnore, GMAD::BeamBase::nlinesIgnore, BDSBunchUserFile< T >::nlinesSkip, GMAD::BeamBase::nlinesSkip, BDSBunchUserFile< T >::ParseFileFormat(), BDSBunchUserFile< T >::particleMass, and BDSBunch::SetOptions().

Here is the call graph for this function:

◆ 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 248 of file BDSBunchUserFile.cc.

References BDSBunchUserFile< T >::ReadValue().

Here is the call graph for this function:

◆ SkipLines()

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

Read lines according to nlinesIgnore.

Definition at line 256 of file BDSBunchUserFile.cc.

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

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

Here is the call graph for this function:
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 83 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 77 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 84 of file BDSBunchUserFile.hh.

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

◆ distrFile

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

Bunch file.

Definition at line 75 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 76 of file BDSBunchUserFile.hh.

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

◆ ffact

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

Cache of flip factor from global constants.

Definition at line 127 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

The file handler. Templated as could be std::ifstream or igzstream for example.

Definition at line 96 of file BDSBunchUserFile.hh.

Referenced by BDSBunchUserFile< T >::CountLinesInFile(), BDSBunchUserFile< T >::GetNextParticleLocal(), BDSBunchUserFile< T >::RecreateAdvanceToEvent(), and BDSBunchUserFile< T >::SkipLines().

◆ lineCounter

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

◆ matchDistrFileLength

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

Definition at line 128 of file BDSBunchUserFile.hh.

◆ nlinesIgnore

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

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

Definition at line 78 of file BDSBunchUserFile.hh.

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

◆ nlinesSkip

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

Number of lines that will be skipped after the nlinesIgnore.

Definition at line 79 of file BDSBunchUserFile.hh.

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

◆ particleMass

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

Cache of nominal beam particle mass.

Definition at line 80 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 82 of file BDSBunchUserFile.hh.


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