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"
39#include "G4RotationMatrix.hh"
40#include "G4ThreeVector.hh"
41#include "G4Transform3D.hh"
42#include "G4UserLimits.hh"
43#include "G4Version.hh"
44#include "G4VisAttributes.hh"
46#include "CLHEP/Units/SystemOfUnits.h"
47#include "CLHEP/Vector/EulerAngles.h"
76 curvilinearDiameterShrunkForBends =
false;
89 G4double horizontalWidth =
options.horizontalWidth * CLHEP::m;
92 G4cerr << __METHOD_NAME__ <<
"Error: option \"horizontalWidth\" " << horizontalWidth
93 <<
" must be greater than 2x (\"aper1\" + \"beamPipeThickness\") ("
95 throw BDSException(__METHOD_NAME__,
"error in beam pipe defaults");
113 itsLaserwireWavelength = 0.532 * CLHEP::micrometer;
114 itsLaserwireDir = G4ThreeVector(1,0,0);
115 itsLaserwireTrackPhotons =
true;
116 itsLaserwireTrackElectrons =
true;
121 InitDefaultUserLimits();
142 if (StoreMinimalData())
144 G4cout <<
"\nGlobal option> storing minimal data\n" << G4endl;
149 std::map<std::string, bool*> otc = {
150 {
"storeApertureImpacts", &o.storeApertureImpacts},
151 {
"storeApertureImpactsHistograms", &o.storeApertureImpactsHistograms},
152 {
"storeCollimatorInfo", &o.storeCollimatorInfo},
153 {
"storeCollimatorHits", &o.storeCollimatorHits},
154 {
"storeCollimatorHitsLinks", &o.storeCollimatorHitsLinks},
155 {
"storeCollimatorHitsIons", &o.storeCollimatorHitsIons},
156 {
"storeCollimatorHitsAll", &o.storeCollimatorHitsAll},
157 {
"storePrimaryHistograms", &o.storePrimaryHistograms},
158 {
"storeTrajectoryTransportationSteps", &o.storeTrajectoryTransportationSteps},
159 {
"storeModel", &o.storeModel}
164 {*no.second =
false;}
168 std::map<std::set<std::string>,
bool*> otcMultiple = {
169 {{
"storeELoss",
"storeEloss"}, &o.storeEloss},
170 {{
"storeELoss",
"storeEloss"}, &o.storeEloss},
171 {{
"storeELossHistograms",
"storeElossHistograms"}, &o.storeElossHistograms},
172 {{
"storeTrajectory",
"storeTrajectories"}, &o.storeTrajectory},
173 {{
"storeParticleData",
"storeGeant4Data"}, &o.storeParticleData},
174 {{
"storePrimaries",
"writePrimaries"}, &o.storePrimaries},
176 for (
auto& no : otcMultiple)
178 bool hasBeenSet =
false;
179 for (
auto& op : no.first)
182 {*no.second =
false;}
185#if G4VERSION_NUMBER > 1079
187 {BDS::Warning(
"The option \"scintYieldFactor\" has no effect with Geant4 11.0 onwards");}
211 CLHEP::HepEulerAngles ang = CLHEP::HepEulerAngles(phi, theta, psi);
212 rm = G4RotationMatrix(ang);
218void BDSGlobalConstants::InitVisAttributes()
221 invisibleVisAttr =
new G4VisAttributes(G4Colour::Black());
222 invisibleVisAttr->SetVisibility(
false);
226 visibleDebugVisAttr =
new G4VisAttributes();
227 visibleDebugVisAttr->SetColour(0,0.6,0,0.1);
228 visibleDebugVisAttr->SetVisibility(
true);
232void BDSGlobalConstants::InitDefaultUserLimits()
236 for (G4int i = 0; i < (G4int)pteAsVector.size(); i++)
240 G4int pdgID = std::stoi(pteAsVector[i]);
241 particlesToExcludeFromCutsAsSet.insert(pdgID);
243 catch (std::logic_error& e)
245 G4String msg =
"Particle ID " + pteAsVector[i] +
" at index " + std::to_string(i);
246 msg +=
" in the option particlesToExcludeFromCutsAsSet cannot be converted to an integer";
251 defaultUserLimits =
new G4UserLimits(
"default_cuts");
252 const G4double maxTime = MaxTime();
255 G4cout << __METHOD_NAME__ <<
"Setting maximum tracking time to " << maxTime <<
" ns" << G4endl;
256 defaultUserLimits->SetUserMaxTime(maxTime);
258 defaultUserLimits->SetMaxAllowedStep(MaxStepLength());
259 defaultUserLimits->SetUserMaxTrackLength(MaxTrackLength());
260 G4double minEK = MinimumKineticEnergy();
261 defaultUserLimits->SetUserMinEkine(minEK);
263 {G4cout << __METHOD_NAME__ <<
"Default minimum kinetic energy for model: " << minEK/CLHEP::GeV <<
" GeV" << G4endl;}
264 G4double minR = MinimumRange();
265 defaultUserLimits->SetUserMinRange(minR);
267 {G4cout << __METHOD_NAME__ <<
"Default minimum range for user limits: " << minR/CLHEP::mm <<
" mm" << G4endl;}
272 defaultUserLimitsTunnel =
new G4UserLimits(*defaultUserLimits);
273 defaultUserLimitsTunnel->SetType(
"default_cuts_tunnel");
275 {defaultUserLimitsTunnel->SetUserMinEkine(MinimumKineticEnergyTunnel());}
276 if (TunnelIsInfiniteAbsorber())
277 {defaultUserLimitsTunnel->SetUserMinEkine(std::numeric_limits<double>::max());}
280G4int BDSGlobalConstants::PrintModuloEvents()
const
282 G4int nGenerate = NGenerate();
283 G4double fraction = PrintFractionEvents();
284 G4int printModulo = (G4int)ceil(nGenerate * fraction);
293G4int BDSGlobalConstants::PrintModuloTurns()
const
295 G4int nTurns = TurnsToTake();
296 G4double fraction = PrintFractionTurns();
297 G4int printModulo = (G4int)ceil(nTurns * fraction);
306BDSGlobalConstants::~BDSGlobalConstants()
310 delete defaultUserLimits;
311 delete defaultUserLimitsTunnel;
312 delete invisibleVisAttr;
313 delete visibleDebugVisAttr;
320 if (
options.storeTrajectoryELossSRange.empty())
322 std::istringstream is(
options.storeTrajectoryELossSRange);
326 std::size_t loc = tok.find(
':',0);
327 if (loc == std::string::npos)
328 {
throw BDSException(__METHOD_NAME__,
"Error: no ':' character found in option storeTrajectoryELossSRange \"" +
options.storeTrajectoryELossSRange +
"\" - invalid range.");}
333 rstart = std::stod(tok.substr(0, loc));
334 rend = std::stod(tok.substr(loc+1,tok.size()));
336 catch (
const std::invalid_argument& e)
338 G4cerr <<
"Invalid value \"" << tok <<
"\" in option storeTrajectoryELossSRange." << G4endl;
339 throw BDSException(__METHOD_NAME__,
"Error: can't convert string to number for option storeTrajectoryELossSRange.");
343 G4String message =
"Error in option storeTrajectoryElossSRange - end point "
344 + std::to_string(rend) +
" is less than beginning " + std::to_string(rstart) +
".";
347 elossSRange.emplace_back(rstart*CLHEP::m, rend*CLHEP::m);
357 {
return options.storeTrajectoryTransportationSteps;}
363 StoreTrajectoryKineticEnergy(),
364 StoreTrajectoryMomentumVector(),
365 StoreTrajectoryProcesses(),
366 StoreTrajectoryTime(),
367 StoreTrajectoryLocal(),
368 StoreTrajectoryLinks(),
369 StoreTrajectoryIon(),
370 StoreTrajectoryMaterial()};
372 if (StoreTrajectoryAllVariables())
374 result.storeKineticEnergy =
true;
375 result.storeMomentumVector =
true;
376 result.storeProcesses =
true;
377 result.storeTime =
true;
378 result.storeLocal =
true;
379 result.storeLinks =
true;
380 result.storeIon =
true;
381 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 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())