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) |
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... | |
![]() | |
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 BDSParticleDefinition * | ParticleDefinition () 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... | |
T | InputBunchFile |
The file handler. Templated as could be std::ifstream or igzstream for example. More... | |
std::list< Doublet > | fields |
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 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) |
![]() | |
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... | |
![]() | |
G4String | name |
Name of distribution. More... | |
G4bool | useCurvilinear |
Whether to ignore z and use s and transform for curvilinear coordinates. More... | |
BDSParticleDefinition * | particleDefinition |
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... | |
A bunch distribution that reads a user specified column file.
Definition at line 44 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 217 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 197 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 94 of file BDSBunchUserFile.cc.
Referenced by BDSBunchUserFile< T >::CountLinesInFile(), and BDSBunchUserFile< T >::EndOfFileAction().
|
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().
|
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().
|
inlinevirtual |
For this class we generally can expect a few extra particle types.
Reimplemented from BDSBunch.
Definition at line 72 of file BDSBunchUserFile.hh.
|
virtual |
Get the next particle.
Reimplemented from BDSBunch.
Definition at line 357 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(), 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 350 of file BDSBunchUserFile.cc.
References BDSBunch::GetNextParticle().
|
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().
|
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().
|
private |
Parse the column tokens and units factors.
Definition at line 101 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 520 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 334 of file BDSBunchUserFile.cc.
References BDSBunchUserFile< T >::EndOfFileAction(), BDSBunchUserFile< T >::InputBunchFile, and BDSBunchUserFile< T >::lineCounter.
|
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().
|
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().
|
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().
|
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().
|
private |
Format of the file.
Definition at line 77 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::ParseFileFormat(), and BDSBunchUserFile< T >::SetOptions().
|
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().
|
private |
Bunch file.
Definition at line 75 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::SetOptions().
|
private |
Bunch file including absolute path.
Definition at line 76 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::SetOptions().
|
private |
Cache of flip factor from global constants.
Definition at line 127 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::GetNextParticleLocal().
|
private |
List of variables to parse on each line.
Definition at line 109 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 96 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::CountLinesInFile(), BDSBunchUserFile< T >::GetNextParticleLocal(), BDSBunchUserFile< T >::RecreateAdvanceToEvent(), and BDSBunchUserFile< T >::SkipLines().
|
private |
Line counter.
Definition at line 81 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::GetNextParticleLocal(), BDSBunchUserFile< T >::RecreateAdvanceToEvent(), and BDSBunchUserFile< T >::SkipLines().
|
private |
Definition at line 128 of file BDSBunchUserFile.hh.
|
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().
|
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().
|
private |
Cache of nominal beam particle mass.
Definition at line 80 of file BDSBunchUserFile.hh.
Referenced by BDSBunchUserFile< T >::SetOptions().
|
private |
Whether we've printed out opening the file the first time.
Definition at line 82 of file BDSBunchUserFile.hh.