18#include "BDSBeamPipeInfo.hh"
20#include "BDSException.hh"
21#include "BDSGlobalConstants.hh"
22#include "BDSFieldInfo.hh"
23#include "BDSIntegratorSetType.hh"
24#include "BDSOutputType.hh"
25#include "BDSPTCOneTurnMap.hh"
26#include "BDSParser.hh"
27#include "BDSSamplerCustom.hh"
28#include "BDSSamplerPlane.hh"
29#include "BDSSamplerRegistry.hh"
30#include "BDSTrajectoryFilter.hh"
31#include "BDSTrajectoryOptions.hh"
32#include "BDSTunnelInfo.hh"
33#include "BDSUtilities.hh"
34#include "BDSWarning.hh"
36#include "parser/options.h"
40#include "G4RotationMatrix.hh"
41#include "G4ThreeVector.hh"
42#include "G4Transform3D.hh"
43#include "G4UserLimits.hh"
44#include "G4Version.hh"
45#include "G4VisAttributes.hh"
47#include "CLHEP/Units/SystemOfUnits.h"
48#include "CLHEP/Vector/EulerAngles.h"
82 curvilinearDiameterShrunkForBends =
false;
95 G4double horizontalWidth =
options.horizontalWidth * CLHEP::m;
98 G4cerr << __METHOD_NAME__ <<
"Error: option \"horizontalWidth\" " << horizontalWidth
99 <<
" must be greater than 2x (\"aper1\" + \"beamPipeThickness\") ("
101 throw BDSException(__METHOD_NAME__,
"error in beam pipe defaults");
119 itsLaserwireWavelength = 0.532 * CLHEP::micrometer;
120 itsLaserwireDir = G4ThreeVector(1,0,0);
121 itsLaserwireTrackPhotons =
true;
122 itsLaserwireTrackElectrons =
true;
127 InitDefaultUserLimits();
134 {
throw BDSException(__METHOD_NAME__,
"\"lengthSafetyLarge\" must be > \"lengthSafety\"");}
152 if (StoreMinimalData())
154 G4cout <<
"\nGlobal option> storing minimal data\n" << G4endl;
159 std::map<std::string, bool*> otc = {
160 {
"storeApertureImpacts", &o.storeApertureImpacts},
161 {
"storeApertureImpactsHistograms", &o.storeApertureImpactsHistograms},
162 {
"storeCollimatorInfo", &o.storeCollimatorInfo},
163 {
"storeCollimatorHits", &o.storeCollimatorHits},
164 {
"storeCollimatorHitsLinks", &o.storeCollimatorHitsLinks},
165 {
"storeCollimatorHitsIons", &o.storeCollimatorHitsIons},
166 {
"storeCollimatorHitsAll", &o.storeCollimatorHitsAll},
167 {
"storePrimaryHistograms", &o.storePrimaryHistograms},
168 {
"storeTrajectoryTransportationSteps", &o.storeTrajectoryTransportationSteps},
169 {
"storeModel", &o.storeModel}
174 {*no.second =
false;}
178 std::map<std::set<std::string>,
bool*> otcMultiple = {
179 {{
"storeELoss",
"storeEloss"}, &o.storeEloss},
180 {{
"storeELoss",
"storeEloss"}, &o.storeEloss},
181 {{
"storeELossHistograms",
"storeElossHistograms"}, &o.storeElossHistograms},
182 {{
"storeTrajectory",
"storeTrajectories"}, &o.storeTrajectory},
183 {{
"storeParticleData",
"storeGeant4Data"}, &o.storeParticleData},
184 {{
"storePrimaries",
"writePrimaries"}, &o.storePrimaries},
186 for (
auto& no : otcMultiple)
188 bool hasBeenSet =
false;
189 for (
auto& op : no.first)
192 {*no.second =
false;}
198 {
throw BDSException(__METHOD_NAME__,
"the option \"fieldModulator\" cannot be used currently - in development");}
202 if (
options.uprootCompatible == 1)
204 options.samplersSplitLevel = 1;
208#if G4VERSION_NUMBER > 1079
210 {BDS::Warning(
"The option \"scintYieldFactor\" has no effect with Geant4 11.0 onwards");}
234 CLHEP::HepEulerAngles ang = CLHEP::HepEulerAngles(phi, theta, psi);
235 rm = G4RotationMatrix(ang);
241void BDSGlobalConstants::InitVisAttributes()
244 invisibleVisAttr =
new G4VisAttributes(G4Colour::Black());
245 invisibleVisAttr->SetVisibility(
false);
249 visibleDebugVisAttr =
new G4VisAttributes();
250 visibleDebugVisAttr->SetColour(0,0.6,0,0.1);
251 visibleDebugVisAttr->SetVisibility(
true);
255void BDSGlobalConstants::InitDefaultUserLimits()
259 for (G4int i = 0; i < (G4int)pteAsVector.size(); i++)
263 G4int pdgID = std::stoi(pteAsVector[i]);
264 particlesToExcludeFromCutsAsSet.insert(pdgID);
266 catch (std::logic_error& e)
268 G4String msg =
"Particle ID " + pteAsVector[i] +
" at index " + std::to_string(i);
269 msg +=
" in the option particlesToExcludeFromCutsAsSet cannot be converted to an integer";
274 defaultUserLimits =
new G4UserLimits(
"default_cuts");
275 const G4double maxTime = MaxTime();
278 G4cout << __METHOD_NAME__ <<
"Setting maximum tracking time to " << maxTime <<
" ns" << G4endl;
279 defaultUserLimits->SetUserMaxTime(maxTime);
281 defaultUserLimits->SetMaxAllowedStep(MaxStepLength());
282 defaultUserLimits->SetUserMaxTrackLength(MaxTrackLength());
283 G4double minEK = MinimumKineticEnergy();
284 defaultUserLimits->SetUserMinEkine(minEK);
286 {G4cout << __METHOD_NAME__ <<
"Default minimum kinetic energy for model: " << minEK/CLHEP::GeV <<
" GeV" << G4endl;}
287 G4double minR = MinimumRange();
288 defaultUserLimits->SetUserMinRange(minR);
290 {G4cout << __METHOD_NAME__ <<
"Default minimum range for user limits: " << minR/CLHEP::mm <<
" mm" << G4endl;}
295 defaultUserLimitsTunnel =
new G4UserLimits(*defaultUserLimits);
296 defaultUserLimitsTunnel->SetType(
"default_cuts_tunnel");
298 {defaultUserLimitsTunnel->SetUserMinEkine(MinimumKineticEnergyTunnel());}
299 if (TunnelIsInfiniteAbsorber())
300 {defaultUserLimitsTunnel->SetUserMinEkine(std::numeric_limits<double>::max());}
303G4int BDSGlobalConstants::PrintModuloEvents()
const
305 G4int nGenerate = NGenerate();
306 G4double fraction = PrintFractionEvents();
307 G4int printModulo = (G4int)ceil(nGenerate * fraction);
316G4int BDSGlobalConstants::PrintModuloTurns()
const
318 G4int nTurns = TurnsToTake();
319 G4double fraction = PrintFractionTurns();
320 G4int printModulo = (G4int)ceil(nTurns * fraction);
329BDSGlobalConstants::~BDSGlobalConstants()
333 delete defaultUserLimits;
334 delete defaultUserLimitsTunnel;
335 delete invisibleVisAttr;
336 delete visibleDebugVisAttr;
343 if (
options.storeTrajectoryELossSRange.empty())
345 std::istringstream is(
options.storeTrajectoryELossSRange);
349 std::size_t loc = tok.find(
':',0);
350 if (loc == std::string::npos)
351 {
throw BDSException(__METHOD_NAME__,
"Error: no ':' character found in option storeTrajectoryELossSRange \"" +
options.storeTrajectoryELossSRange +
"\" - invalid range.");}
356 rstart = std::stod(tok.substr(0, loc));
357 rend = std::stod(tok.substr(loc+1,tok.size()));
359 catch (
const std::invalid_argument& e)
361 G4cerr <<
"Invalid value \"" << tok <<
"\" in option storeTrajectoryELossSRange." << G4endl;
362 throw BDSException(__METHOD_NAME__,
"Error: can't convert string to number for option storeTrajectoryELossSRange.");
366 G4String message =
"Error in option storeTrajectoryElossSRange - end point "
367 + std::to_string(rend) +
" is less than beginning " + std::to_string(rstart) +
".";
370 elossSRange.emplace_back(rstart*CLHEP::m, rend*CLHEP::m);
380 {
return options.storeTrajectoryTransportationSteps;}
386 StoreTrajectoryKineticEnergy(),
387 StoreTrajectoryMomentumVector(),
388 StoreTrajectoryProcesses(),
389 StoreTrajectoryTime(),
390 StoreTrajectoryLocal(),
391 StoreTrajectoryLinks(),
392 StoreTrajectoryIon(),
393 StoreTrajectoryMaterial()};
395 if (StoreTrajectoryAllVariables())
397 result.storeKineticEnergy =
true;
398 result.storeMomentumVector =
true;
399 result.storeProcesses =
true;
400 result.storeTime =
true;
401 result.storeLocal =
true;
402 result.storeLinks =
true;
403 result.storeIon =
true;
404 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())