BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
|
A bunch distribution that reads a user specified column file. More...
#include <BDSBunchUserFile.hh>
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. | |
![]() | |
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(). | |
BDSBunchFileBased & | operator= (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. | |
![]() | |
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 BDSParticleDefinition * | ParticleDefinition () 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 |
T | InputBunchFile |
The file handler. Templated as could be std::ifstream or igzstream for example. | |
std::list< Doublet > | fields |
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 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) |
![]() | |
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. | |
![]() | |
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 |
![]() | |
G4String | name |
Name of distribution. | |
G4bool | useCurvilinear |
Whether to ignore z and use s and transform for curvilinear coordinates. | |
BDSParticleDefinition * | particleDefinition |
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. | |
A bunch distribution that reads a user specified column file.
Definition at line 45 of file BDSBunchUserFile.hh.
BDSBunchUserFile< T >::BDSBunchUserFile |
Definition at line 48 of file BDSBunchUserFile.cc.
|
virtual |
Definition at line 74 of file BDSBunchUserFile.cc.
|
private |
Definition at line 219 of file BDSBunchUserFile.cc.
|
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().
|
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().
|
private |
Close the file handler.
Definition at line 95 of file BDSBunchUserFile.cc.
Referenced by BDSBunchUserFile< T >::CountNLinesValidDataInFile(), and BDSBunchUserFile< T >::EndOfFileAction().
|
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().
|
inlinevirtual |
Definition at line 69 of file BDSBunchUserFile.hh.
|
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().
|
inlinevirtual |
For this class we generally can expect a few extra particle types.
Reimplemented from BDSBunch.
Definition at line 75 of file BDSBunchUserFile.hh.
|
virtual |
Get the next particle.
Reimplemented from BDSBunch.
Definition at line 485 of file BDSBunchUserFile.cc.
References BDSIonDefinition::A(), BDSBunchUserFile< T >::anEnergyCoordinateInUse, BDSBunch::CalculateZp(), BDSBunchUserFile< T >::changingParticleType, BDSBunch::E0, BDSBunchUserFile< T >::EndOfFileAction(), BDSIonDefinition::ExcitationEnergy(), BDSBunchUserFile< T >::ffact, BDSBunchUserFile< T >::fields, BDSBunchUserFile< T >::InputBunchFile, BDSBunchUserFile< T >::lineCounter, BDSBunch::particleDefinition, BDSBunch::particleDefinitionHasBeenUpdated, BDSBunchUserFile< T >::ReadValue(), BDSParticleDefinition::SetEnergies(), BDSBunchUserFile< T >::SkippableLine(), BDSParticleDefinition::TotalEnergy(), BDSBunch::X0, BDSBunch::Xp0, BDSBunch::Y0, BDSBunch::Yp0, BDSIonDefinition::Z(), and BDSBunch::Z0.
|
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().
|
privatevirtual |
Open the file and skip lines.
Reimplemented from BDSBunch.
Definition at line 347 of file BDSBunchUserFile.cc.
References BDSBunchUserFile< T >::CountNLinesValidDataInFile(), BDSBunchUserFile< T >::distrFilePath, BDSGlobalConstants::Instance(), BDSBunchFileBased::nEventsInFile, BDSBunchUserFile< T >::nlinesSkip, BDSBunchUserFile< T >::OpenBunchFile(), BDSBunchUserFile< T >::SkipNLinesIgnoreIntoFile(), and BDSBunchUserFile< T >::SkipNLinesSkip().
|
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().
|
private |
Parse the column tokens and units factors.
Definition at line 103 of file BDSBunchUserFile.cc.
References BDSBunchUserFile< T >::anEnergyCoordinateInUse, BDSBunchUserFile< T >::bunchFormat, BDSBunchUserFile< T >::changingParticleType, BDSBunchUserFile< T >::CheckConflictingParameters(), BDSBunchUserFile< T >::fields, BDS::ParseAngleUnit(), BDS::ParseEnergyUnit(), BDS::ParseLengthUnit(), BDS::ParseTimeUnit(), BDSBunchUserFile< T >::Doublet::unit, and BDSBunch::useCurvilinear.
Referenced by BDSBunchUserFile< T >::SetOptions().
|
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().
|
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().
|
virtual |
Pull out the relevant options and then pass through to BDSBunch::SetOptions().
Reimplemented from BDSBunchFileBased.
Definition at line 305 of file BDSBunchUserFile.cc.
References BDSBunchUserFile< T >::bunchFormat, BDSBunchUserFile< T >::distrFile, GMAD::BeamBase::distrFile, GMAD::BeamBase::distrFileFormat, GMAD::BeamBase::distrFileMatchLength, BDSBunchUserFile< T >::distrFilePath, BDS::GetFullPath(), BDSParticleDefinition::Mass(), BDSBunchUserFile< T >::nlinesIgnore, GMAD::BeamBase::nlinesIgnore, BDSBunchUserFile< T >::nlinesSkip, GMAD::BeamBase::nlinesSkip, BDSBunchUserFile< T >::ParseFileFormat(), BDSBunchUserFile< T >::particleMass, and BDSBunchFileBased::SetOptions().
|
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().
|
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().
|
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().
|
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().
|
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().
|
private |
Format of the file.
Definition at line 80 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::ParseFileFormat(), and BDSBunchUserFile< T >::SetOptions().
|
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().
|
private |
Definition at line 147 of file BDSBunchUserFile.hh.
|
private |
Bunch file.
Definition at line 78 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::SetOptions().
|
private |
Bunch file including absolute path.
Definition at line 79 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::Initialise(), and BDSBunchUserFile< T >::SetOptions().
|
private |
Definition at line 89 of file BDSBunchUserFile.hh.
|
private |
Cache of flip factor from global constants.
Definition at line 146 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::GetNextParticleLocal().
|
private |
List of variables to parse on each line.
Definition at line 122 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::CheckConflictingParameters(), BDSBunchUserFile< T >::GetNextParticleLocal(), and BDSBunchUserFile< T >::ParseFileFormat().
|
private |
The file handler. Templated as could be std::ifstream or igzstream for example.
Definition at line 109 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::CountNLinesValidDataInFile(), BDSBunchUserFile< T >::GetNextParticleLocal(), BDSBunchUserFile< T >::RecreateAdvanceToEvent(), BDSBunchUserFile< T >::SkipNLinesIgnoreIntoFile(), and BDSBunchUserFile< T >::SkipNLinesSkip().
|
private |
Line counter.
Definition at line 85 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::GetNextParticleLocal(), BDSBunchUserFile< T >::RecreateAdvanceToEvent(), and BDSBunchUserFile< T >::SkipNLinesIgnoreIntoFile().
|
private |
Definition at line 148 of file BDSBunchUserFile.hh.
|
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().
|
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().
|
private |
Definition at line 83 of file BDSBunchUserFile.hh.
|
private |
Cache of nominal beam particle mass.
Definition at line 84 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::SetOptions().
|
private |
Whether we've printed out opening the file the first time.
Definition at line 86 of file BDSBunchUserFile.hh.