19#include "BDSBunchEventGenerator.hh"
21#include "BDSException.hh"
22#include "BDSParticleCoordsFull.hh"
23#include "BDSPhysicsUtilities.hh"
24#include "BDSUtilities.hh"
25#include "BDSWarning.hh"
27#include "parser/beam.h"
29#include "G4ParticleDefinition.hh"
30#include "G4ParticleTable.hh"
32#include "CLHEP/Units/SystemOfUnits.h"
41BDSBunchEventGenerator::BDSBunchEventGenerator():
43 eventGeneratorNEventsSkip(0),
44 eventGeneratorMinX(0),
45 eventGeneratorMaxX(0),
46 eventGeneratorMinY(0),
47 eventGeneratorMaxY(0),
48 eventGeneratorMinZ(0),
49 eventGeneratorMaxZ(0),
50 eventGeneratorMinXp(0),
51 eventGeneratorMaxXp(0),
52 eventGeneratorMinYp(0),
53 eventGeneratorMaxYp(0),
54 eventGeneratorMinZp(0),
55 eventGeneratorMaxZp(0),
56 eventGeneratorMinRp(0),
57 eventGeneratorMaxRp(0),
58 eventGeneratorMinT(0),
59 eventGeneratorMaxT(0),
60 eventGeneratorMinEK(0),
61 eventGeneratorMaxEK(0),
64 testOnParticleType(true),
65 acceptedParticlesString(
"")
68BDSBunchEventGenerator::~BDSBunchEventGenerator()
74 G4Transform3D beamlineTransformIn,
75 const G4double beamlineSIn)
106 {
throw BDSException(__METHOD_NAME__,
"eventGeneratorNEventsSkip < 0");}
108 {
throw BDSException(__METHOD_NAME__,
"eventGeneratorMinX >= eventGeneratorMaxX");}
110 {
throw BDSException(__METHOD_NAME__,
"eventGeneratorMinY >= eventGeneratorMaxY");}
112 {
throw BDSException(__METHOD_NAME__,
"eventGeneratorMinZ >= eventGeneratorMaxZ");}
114 {
throw BDSException(__METHOD_NAME__,
"eventGeneratorMinXp >= eventGeneratorMaxXp");}
116 {
throw BDSException(__METHOD_NAME__,
"eventGeneratorMinYp >= eventGeneratorMaxYp");}
118 {
throw BDSException(__METHOD_NAME__,
"eventGeneratorMinZp >= eventGeneratorMaxZp");}
120 {
throw BDSException(__METHOD_NAME__,
"eventGeneratorMinT >= eventGeneratorMaxT");}
122 {
throw BDSException(__METHOD_NAME__,
"eventGeneratorMinEK >= eventGeneratorMaxEK");}
129 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
130 std::string particleIDStr;
132 while (ss >> particleIDStr)
138 int particleID = std::stoi(particleIDStr);
143 G4ParticleTable::G4PTblEncodingDictionary* encoding = G4ParticleTable::fEncodingDictionary;
144 auto search = encoding->find(particleID);
145 if (search != encoding->end())
148 {
throw BDSException(__METHOD_NAME__,
"PDG ID \"" + particleIDStr +
"\" not found in particle table");}
150 catch (
const std::logic_error&)
152 G4ParticleDefinition* particleDef = particleTable->FindParticle(particleIDStr);
156 throw BDSException(__METHOD_NAME__,
"Particle \"" + particleIDStr +
"\" not found.");
169 G4double kineticEnergy,
185 G4bool allowedParticle =
true;
189 return x && y && z && xp && yp && zp && rp && t && ek && allowedParticle;
195 {
return G4RotationMatrix();}
198 G4RotationMatrix result;
199 result.rotateX(std::asin(-
Yp0));
200 result.rotateY(std::asin(
Xp0));
G4RotationMatrix ReferenceBeamMomentumOffset() const
Get a rotation matrix according to Xp0 and Yp0.
G4double Rp0
Cache of limit.
G4double eventGeneratorMinRp
Cache of limit.
G4int eventGeneratorNEventsSkip
Cache of limit.
G4double eventGeneratorMaxZ
Cache of limit.
std::set< G4int > acceptedParticles
Vector (sorted) of permitted particles.
G4double eventGeneratorMaxXp
Cache of limit.
G4double eventGeneratorMinXp
Cache of limit.
virtual void CheckParameters()
G4String acceptedParticlesString
Cache of string for parsing on first query.
G4double eventGeneratorMaxEK
Cache of limit.
void ParseAcceptedParticleIDs()
G4double eventGeneratorMinY
Cache of limit.
G4double eventGeneratorMaxRp
Cache of limit.
G4double eventGeneratorMaxT
Cache of limit.
G4double eventGeneratorMinT
Cache of limit.
G4double eventGeneratorMaxYp
Cache of limit.
G4double eventGeneratorMinZp
Cache of limit.
G4double eventGeneratorMaxX
Cache of limit.
G4bool firstTime
Flag to prepare acceptedParticles on first call.
G4double eventGeneratorMinZ
Cache of limit.
G4double eventGeneratorMaxY
Cache of limit.
G4bool testOnParticleType
Flag whether to bother applying search.
G4double eventGeneratorMinEK
Cache of limit.
G4double eventGeneratorMinYp
Cache of limit.
G4double eventGeneratorMinX
Cache of limit.
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, G4double beamlineS=0)
Pull out the relevant options and then pass through to BDSBunch::SetOptions().
G4double eventGeneratorMaxZp
Cache of limit.
G4bool AcceptParticle(const BDSParticleCoordsFull &coords, G4double rpOriginal, G4double kineticEnergy, G4int pdgID)
An intermediate layer for any bunch classes that are file based.
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().
G4double Yp0
Centre of distributions.
G4double T0
Centre of distributions.
G4double X0
Centre of distributions.
G4double Xp0
Centre of distributions.
G4double Y0
Centre of distributions.
virtual void CheckParameters()
General exception with possible name of object and message.
A set of particle coordinates including energy and weight.
Wrapper for particle definition.
Improve type-safety of native enum data type in C++.
double eventGeneratorMaxYp
Event generator file filter.
double eventGeneratorMaxXp
Event generator file filter.
double eventGeneratorMaxEK
Event generator file filter.
double eventGeneratorMaxZp
Event generator file filter.
double eventGeneratorMinYp
Event generator file filter.
double eventGeneratorMinEK
Event generator file filter.
double eventGeneratorMaxZ
Event generator file filter.
double eventGeneratorMinY
Event generator file filter.
int eventGeneratorNEventsSkip
Event generator file filter.
double eventGeneratorMaxRp
Event generator file filter.
double eventGeneratorMinZ
Event generator file filter.
double eventGeneratorMinXp
Event generator file filter.
double eventGeneratorMinZp
Event generator file filter.
std::string eventGeneratorParticles
Event generator file filter.
double eventGeneratorMaxY
Event generator file filter.
double eventGeneratorMinT
Event generator file filter.
double eventGeneratorMaxT
Event generator file filter.
double eventGeneratorMaxX
Event generator file filter.
double eventGeneratorMinRp
Event generator file filter.
double eventGeneratorMinX
Event generator file filter.
void PrintDefinedParticles()
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())