19#include "BDSBeamPipeInfo.hh"
21#include "BDSException.hh"
22#include "BDSGlobalConstants.hh"
23#include "BDSFieldInfo.hh"
24#include "BDSIntegratorSetType.hh"
25#include "BDSOutputType.hh"
26#include "BDSPTCOneTurnMap.hh"
27#include "BDSParser.hh"
28#include "BDSSamplerCustom.hh"
29#include "BDSSamplerPlane.hh"
30#include "BDSSamplerRegistry.hh"
31#include "BDSTrajectoryFilter.hh"
32#include "BDSTrajectoryOptions.hh"
33#include "BDSTunnelInfo.hh"
34#include "BDSUtilities.hh"
35#include "BDSWarning.hh"
37#include "parser/options.h"
41#include "G4RotationMatrix.hh"
42#include "G4ThreeVector.hh"
43#include "G4Transform3D.hh"
44#include "G4UserLimits.hh"
45#include "G4Version.hh"
46#include "G4VisAttributes.hh"
48#include "CLHEP/Units/SystemOfUnits.h"
49#include "CLHEP/Vector/EulerAngles.h"
83 curvilinearDiameterShrunkForBends =
false;
96 G4double horizontalWidth =
options.horizontalWidth * CLHEP::m;
99 G4cerr << __METHOD_NAME__ <<
"Error: option \"horizontalWidth\" " << horizontalWidth
100 <<
" must be greater than 2x (\"aper1\" + \"beamPipeThickness\") ("
102 throw BDSException(__METHOD_NAME__,
"error in beam pipe defaults");
120 itsLaserwireWavelength = 0.532 * CLHEP::micrometer;
121 itsLaserwireDir = G4ThreeVector(1,0,0);
122 itsLaserwireTrackPhotons =
true;
123 itsLaserwireTrackElectrons =
true;
128 InitDefaultUserLimits();
135 {
throw BDSException(__METHOD_NAME__,
"\"lengthSafetyLarge\" must be > \"lengthSafety\"");}
153 if (StoreMinimalData())
155 G4cout <<
"\nGlobal option> storing minimal data\n" << G4endl;
160 std::map<std::string, bool*> otc = {
161 {
"storeApertureImpacts", &o.storeApertureImpacts},
162 {
"storeApertureImpactsHistograms", &o.storeApertureImpactsHistograms},
163 {
"storeCollimatorInfo", &o.storeCollimatorInfo},
164 {
"storeCollimatorHits", &o.storeCollimatorHits},
165 {
"storeCollimatorHitsLinks", &o.storeCollimatorHitsLinks},
166 {
"storeCollimatorHitsIons", &o.storeCollimatorHitsIons},
167 {
"storeCollimatorHitsAll", &o.storeCollimatorHitsAll},
168 {
"storePrimaryHistograms", &o.storePrimaryHistograms},
169 {
"storeTrajectoryTransportationSteps", &o.storeTrajectoryTransportationSteps},
170 {
"storeModel", &o.storeModel}
175 {*no.second =
false;}
179 std::map<std::set<std::string>,
bool*> otcMultiple = {
180 {{
"storeELoss",
"storeEloss"}, &o.storeEloss},
181 {{
"storeELoss",
"storeEloss"}, &o.storeEloss},
182 {{
"storeELossHistograms",
"storeElossHistograms"}, &o.storeElossHistograms},
183 {{
"storeTrajectory",
"storeTrajectories"}, &o.storeTrajectory},
184 {{
"storeParticleData",
"storeGeant4Data"}, &o.storeParticleData},
185 {{
"storePrimaries",
"writePrimaries"}, &o.storePrimaries},
187 for (
auto& no : otcMultiple)
189 bool hasBeenSet =
false;
190 for (
auto& op : no.first)
193 {*no.second =
false;}
199 {
throw BDSException(__METHOD_NAME__,
"the option \"fieldModulator\" cannot be used currently - in development");}
203 if (
options.uprootCompatible == 1)
205 options.samplersSplitLevel = 1;
209#if G4VERSION_NUMBER > 1079
211 {BDS::Warning(
"The option \"scintYieldFactor\" has no effect with Geant4 11.0 onwards");}
235 CLHEP::HepEulerAngles ang = CLHEP::HepEulerAngles(phi, theta, psi);
236 rm = G4RotationMatrix(ang);
242void BDSGlobalConstants::InitVisAttributes()
245 invisibleVisAttr =
new G4VisAttributes(G4Colour::Black());
246 invisibleVisAttr->SetVisibility(
false);
250 visibleDebugVisAttr =
new G4VisAttributes();
251 visibleDebugVisAttr->SetColour(0,0.6,0,0.1);
252 visibleDebugVisAttr->SetVisibility(
true);
256void BDSGlobalConstants::InitDefaultUserLimits()
260 for (G4int i = 0; i < (G4int)pteAsVector.size(); i++)
264 G4int pdgID = std::stoi(pteAsVector[i]);
265 particlesToExcludeFromCutsAsSet.insert(pdgID);
267 catch (std::logic_error& e)
269 G4String msg =
"Particle ID " + pteAsVector[i] +
" at index " + std::to_string(i);
270 msg +=
" in the option particlesToExcludeFromCutsAsSet cannot be converted to an integer";
275 defaultUserLimits =
new G4UserLimits(
"default_cuts");
276 const G4double maxTime = MaxTime();
279 G4cout << __METHOD_NAME__ <<
"Setting maximum tracking time to " << maxTime <<
" ns" << G4endl;
280 defaultUserLimits->SetUserMaxTime(maxTime);
282 defaultUserLimits->SetMaxAllowedStep(MaxStepLength());
283 defaultUserLimits->SetUserMaxTrackLength(MaxTrackLength());
284 G4double minEK = MinimumKineticEnergy();
285 defaultUserLimits->SetUserMinEkine(minEK);
287 {G4cout << __METHOD_NAME__ <<
"Default minimum kinetic energy for model: " << minEK/CLHEP::GeV <<
" GeV" << G4endl;}
288 G4double minR = MinimumRange();
289 defaultUserLimits->SetUserMinRange(minR);
291 {G4cout << __METHOD_NAME__ <<
"Default minimum range for user limits: " << minR/CLHEP::mm <<
" mm" << G4endl;}
296 defaultUserLimitsTunnel =
new G4UserLimits(*defaultUserLimits);
297 defaultUserLimitsTunnel->SetType(
"default_cuts_tunnel");
299 {defaultUserLimitsTunnel->SetUserMinEkine(MinimumKineticEnergyTunnel());}
300 if (TunnelIsInfiniteAbsorber())
301 {defaultUserLimitsTunnel->SetUserMinEkine(std::numeric_limits<double>::max());}
304G4int BDSGlobalConstants::PrintModuloEvents()
const
306 G4int nGenerate = NGenerate();
307 G4double fraction = PrintFractionEvents();
308 G4int printModulo = (G4int)ceil(nGenerate * fraction);
317G4int BDSGlobalConstants::PrintModuloTurns()
const
319 G4int nTurns = TurnsToTake();
320 G4double fraction = PrintFractionTurns();
321 G4int printModulo = (G4int)ceil(nTurns * fraction);
330BDSGlobalConstants::~BDSGlobalConstants()
334 delete defaultUserLimits;
335 delete defaultUserLimitsTunnel;
336 delete invisibleVisAttr;
337 delete visibleDebugVisAttr;
344 if (
options.storeTrajectoryELossSRange.empty())
346 std::istringstream is(
options.storeTrajectoryELossSRange);
350 std::size_t loc = tok.find(
':',0);
351 if (loc == std::string::npos)
352 {
throw BDSException(__METHOD_NAME__,
"Error: no ':' character found in option storeTrajectoryELossSRange \"" +
options.storeTrajectoryELossSRange +
"\" - invalid range.");}
357 rstart = std::stod(tok.substr(0, loc));
358 rend = std::stod(tok.substr(loc+1,tok.size()));
360 catch (
const std::invalid_argument& e)
362 G4cerr <<
"Invalid value \"" << tok <<
"\" in option storeTrajectoryELossSRange." << G4endl;
363 throw BDSException(__METHOD_NAME__,
"Error: can't convert string to number for option storeTrajectoryELossSRange.");
367 G4String message =
"Error in option storeTrajectoryElossSRange - end point "
368 + std::to_string(rend) +
" is less than beginning " + std::to_string(rstart) +
".";
371 elossSRange.emplace_back(rstart*CLHEP::m, rend*CLHEP::m);
381 {
return options.storeTrajectoryTransportationSteps;}
387 StoreTrajectoryKineticEnergy(),
388 StoreTrajectoryMomentumVector(),
389 StoreTrajectoryProcesses(),
390 StoreTrajectoryTime(),
391 StoreTrajectoryLocal(),
392 StoreTrajectoryLinks(),
393 StoreTrajectoryIon(),
394 StoreTrajectoryMaterial()};
396 if (StoreTrajectoryAllVariables())
398 result.storeKineticEnergy =
true;
399 result.storeMomentumVector =
true;
400 result.storeProcesses =
true;
401 result.storeTime =
true;
402 result.storeLocal =
true;
403 result.storeLinks =
true;
404 result.storeIon =
true;
405 result.storeMaterial =
true;
Holder class for all information required to describe a beam pipe model.
G4double aper1
Public member for direct access.
G4double beamPipeThickness
Public member for direct access.
General exception with possible name of object and message.
static G4UserLimits * defaultUL
Cache of default user limits.
A class that holds global options and constants.
GMAD::Options options
Options instance that this is largely based on and extends.
void ProcessTrajectoryELossSRange()
Process the option string and fill the below vector.
G4double curvilinearDiameter
Curvilinear diameter for CL volumes - defaults to samplerDiameter.
BDSTunnelInfo * tunnelInfo
Tunnel model.
std::bitset< BDS::NTrajectoryFilters > trajectoryFiltersSet
Which filters were used in the options.
static BDSGlobalConstants * Instance()
Access method.
BDSOutputType outputType
Output type enum for output format to be used.
BDSIntegratorSetType integratorSet
Integrator type enum for integrator set to be used.
std::vector< std::pair< G4double, G4double > > elossSRange
Pairs of S ranges to link trajectories to.
BDS::TrajectoryOptions StoreTrajectoryOptions() const
options that require some implementation.
BDSBeamPipeInfo * defaultBeamPipeModel
Default beam pipe model information.
void InitialiseBeamlineTransform()
Prepare the G4Transform3D instance from the options for the initial beam line transform.
BDSGlobalConstants()=delete
Unused default constructors.
BDSMagnetGeometryType magnetGeometryType
Magnet geometry.
G4double samplerDiameter
Cache of sampler diameter in this class so it can be updated.
G4Transform3D beamlineTransform
Transform for start of beam line.
G4int numberToGenerate
Number of particles to generate can be set from outside (by e.g. BDSBunchPtc)
G4bool StoreTrajectoryTransportationSteps() const
options that require some implementation.
void ResetTurnNumber()
Setter.
static BDSGlobalConstants * instance
Singleton instance.
static BDSParser * Instance()
Access method.
static bool IsInitialised()
Returns if parser is initialised.
static G4double chordLength
The chord length for all is fixed and can be static.
Holder struct of all information required to create a section of tunnel.
std::string magnetGeometryType
default magnet geometry parameters
double beamlineZ
Initial beam line transform w.r.t. the world coordinate frame.
int nGenerate
The number of primary events to simulate.
double beamlineAngle
Initial beam line transform w.r.t. the world coordinate frame.
double tunnelSoilThickness
tunnel geometry parameters
std::string outputFormat
Parameter for output format.
bool beamlineAxisAngle
Initial beam line transform w.r.t. the world coordinate frame.
double tunnelFloorOffset
tunnel geometry parameters
std::string tunnelMaterial
tunnel geometry parameters
int nSegmentsPerCircle
Number of facets per 2pi in visualisation.
std::string soilMaterial
tunnel geometry parameters
double aper1
default beampipe parameters
double aper2
default beampipe parameters
double beamlinePhi
Initial beam line transform w.r.t. the world coordinate frame.
std::string vacMaterial
vacuum material
bool buildTunnelFloor
tunnel geometry parameters
double beamlineAxisY
Initial beam line transform w.r.t. the world coordinate frame.
double tunnelAper1
tunnel geometry parameters
std::string beampipeMaterial
default beampipe parameters
double beampipeThickness
default beampipe parameters
double beamlineX
Initial beam line transform w.r.t. the world coordinate frame.
std::string apertureType
default beampipe parameters
double tunnelAper2
tunnel geometry parameters
double beamlineY
Initial beam line transform w.r.t. the world coordinate frame.
double beamlineAxisX
Initial beam line transform w.r.t. the world coordinate frame.
double tunnelThickness
tunnel geometry parameters
double aper4
default beampipe parameters
double aper3
default beampipe parameters
std::string tunnelType
tunnel geometry parameters
double beamlineAxisZ
Initial beam line transform w.r.t. the world coordinate frame.
double beamlinePsi
Initial beam line transform w.r.t. the world coordinate frame.
bool trajNoTransportation
kept only for backwards compatibility.
bool tunnelVisible
tunnel geometry parameters
double beamlineTheta
Initial beam line transform w.r.t. the world coordinate frame.
bool HasBeenSet(const std::string &name) const
Whether a parameter has been set using the set_value method or not.
BDSMagnetGeometryType DetermineMagnetGeometryType(G4String geometryType)
function to determine the enum type of the magnet geometry (case-insensitive)
BDSIntegratorSetType DetermineIntegratorSetType(G4String integratorSet)
Function that gives corresponding enum value for string (case-insensitive)
BDSOutputType DetermineOutputType(G4String outputType)
Determine the output format to be used from the input string.
std::vector< G4String > SplitOnWhiteSpace(const G4String &input)
Split a string on whitespace and return a vector of these 'words'.
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())