BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSIMLink.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "BDSIMLink.hh"
19
20#include <csignal>
21#include <cstdlib> // standard headers
22#include <cstdio>
23
24#include "G4EventManager.hh" // Geant4 includes
25#include "G4GeometryManager.hh"
26#include "G4GeometryTolerance.hh"
27#include "G4Version.hh"
28#include "G4VModularPhysicsList.hh"
29
30#include "BDSAcceleratorModel.hh"
31#include "BDSAperturePointsLoader.hh"
32#include "BDSBeamPipeFactory.hh"
33#include "BDSBunch.hh"
34#include "BDSBunchFactory.hh"
35#include "BDSLinkBunch.hh"
36#include "BDSBunchSixTrackLink.hh"
37#include "BDSCavityFactory.hh"
38#include "BDSColours.hh"
39#include "BDSComponentFactoryUser.hh"
40#include "BDSDebug.hh"
41#include "BDSException.hh"
42#include "BDSExecOptions.hh"
43#include "BDSFieldFactory.hh"
44#include "BDSFieldLoader.hh"
45#include "BDSGeometryFactory.hh"
46#include "BDSGeometryFactorySQL.hh"
47#include "BDSGeometryWriter.hh"
48#include "BDSGlobalConstants.hh"
49#include "BDSLinkComponent.hh"
50#include "BDSLinkDetectorConstruction.hh"
51#include "BDSLinkEventAction.hh"
52#include "BDSLinkPrimaryGeneratorAction.hh"
53#include "BDSLinkRunAction.hh"
54#include "BDSLinkRunManager.hh"
55#include "BDSLinkStackingAction.hh"
56#include "BDSLinkTrackingAction.hh"
57#include "BDSMaterials.hh"
58#include "BDSOutput.hh"
59#include "BDSOutputFactory.hh"
60#include "BDSParallelWorldUtilities.hh"
61#include "BDSParser.hh"
62#include "BDSParticleExternal.hh"
63#include "BDSParticleDefinition.hh"
64#include "BDSPhysicsUtilities.hh"
65#include "BDSRandom.hh"
66#include "BDSSamplerRegistry.hh"
67#include "BDSSDManager.hh"
68#include "BDSTemporaryFiles.hh"
69#include "BDSUtilities.hh"
70#include "BDSVisManager.hh"
71
72#include <map>
73#include <set>
74
75
77 BDSParser* parserIn):
78 ignoreSIGINT(false),
79 usualPrintOut(true),
80 initialised(false),
81 initialisationResult(1),
82 argcCache(0),
83 argvCache(nullptr),
84 parser(parserIn),
85 bdsOutput(nullptr),
86 bdsBunch(bunchIn),
87 internalBdsBunch(false),
88 runManager(nullptr),
89 construction(nullptr),
90 runAction(nullptr),
91 currentElementIndex(0),
92 userPhysicsList(nullptr)
93{
94 if(!bdsBunch) {
95 bdsBunch = new BDSLinkBunch();
96 internalBdsBunch = true;
97 }
98}
99
100BDSIMLink::BDSIMLink(int argc, char** argv,
101 bool usualPrintOutIn,
102 BDSParser *parserIn):
103 ignoreSIGINT(false),
104 usualPrintOut(usualPrintOutIn),
105 initialised(false),
106 initialisationResult(1),
107 argcCache(argc),
108 argvCache(argv),
109 parser(parserIn),
110 bdsOutput(nullptr),
111 bdsBunch(nullptr),
112 runManager(nullptr),
113 construction(nullptr),
114 runAction(nullptr),
115 currentElementIndex(0),
116 userPhysicsList(nullptr)
117{
119}
120
122 char** argv,
123 bool usualPrintOutIn,
124 double minimumKineticEnergy,
125 bool protonsAndIonsOnly)
126{
127 argcCache = argc;
128 argvCache = new char*[argc + 1]; // +1 for null termination (optional)
129 for (int i = 0; i < argc; ++i) {
130 size_t len = std::strlen(argv[i]) + 1; // +1 for null terminator
131 argvCache[i] = new char[len];
132 std::strcpy(argvCache[i], argv[i]); // deep copy the string
133 }
134 argvCache[argc] = nullptr; // optional: null-terminate array like execv expects
135
136 usualPrintOut = usualPrintOutIn;
137 initialisationResult = Initialise(minimumKineticEnergy, protonsAndIonsOnly);
139}
140
141int BDSIMLink::Initialise(double minimumKineticEnergy,
142 bool protonsAndIonsOnly)
143{
144 minimumKineticEnergy *= CLHEP::GeV; // units
145 G4bool trackerDebug = false;
146
148 const BDSExecOptions* execOptions = new BDSExecOptions(argcCache,argvCache);
149 if (usualPrintOut)
150 {execOptions->Print();}
151 ignoreSIGINT = execOptions->IgnoreSIGINT(); // different sig catching for cmake
152 execOptions->PrintCopyright();
153#ifdef BDSDEBUG
154 G4cout << __METHOD_NAME__ << "DEBUG mode is on." << G4endl;
155#endif
156
158 if(!parser)
159 parser = BDSParser::Instance(execOptions->InputFileName());
161 parser->AmalgamateOptions(execOptions->Options());
162 parser->AmalgamateBeam(execOptions->Beam(), execOptions->Options().recreate);
165
168
170 delete execOptions;
171
176
178 BDSRandom::CreateRandomNumberGenerator(globalConstants->RandomEngine());
179 BDSRandom::SetSeed(); // set the seed from options
180
182 bdsOutput = BDSOutputFactory::CreateOutput(globalConstants->OutputFormat(),
183 globalConstants->OutputFileName());
184
187 {
188 G4cerr << "No Geant4 environmental variables found - please source geant4.sh environment" << G4endl;
189 G4cout << "A common fault is the wrong Geant4 environment as compared to the one BDSIM was compiled with." << G4endl;
190 return 1;
191 }
192
196
199
201 auto parallelWorldsRequiringPhysics = BDS::ConstructAndRegisterParallelWorlds(construction, true, false);
202
203 runManager->SetUserInitialization(construction);
204
205 // Set filters used in sensitive detectors that transfer particles back
206 BDSSDManager::Instance()->SetLinkMinimumEK(minimumKineticEnergy);
207 BDSSDManager::Instance()->SetLinkProtonsAndIonsOnly(protonsAndIonsOnly);
208
209#ifdef BDSDEBUG
210 G4cout << __METHOD_NAME__ << "> Constructing physics processes" << G4endl;
211#endif
212 G4String physicsListName = parser->GetOptions().physicsList;
213
214#if G4VERSION_NUMBER > 1049
215 // from 10.5 onwards they have a looping particle killer that warnings and kills particles
216 // deemed to be looping that are <100 MeV. This is unrelated to the primary energy so troublesome.
217 // set to the 'low' limits here ~10keV. This must be done before any physics is created as the
218 // parameters are copied into the transportation physics process for each particle and it's very
219 // hard to sift through and fix afterwards
220 G4PhysicsListHelper::GetPhysicsListHelper()->UseLowLooperThresholds();
221#endif
222 auto parallelWorldPhysics = BDS::ConstructParallelWorldPhysics(parallelWorldsRequiringPhysics);
223 G4int physicsVerbosity = BDSGlobalConstants::Instance()->PhysicsVerbosity();
224 G4VModularPhysicsList* physList;
225 if (userPhysicsList)
226 {
227 G4cout << "Using externally registered user defined physics list" << G4endl;
228 physList = userPhysicsList;
229 }
230 else
231 {physList = BDS::BuildPhysics(physicsListName, physicsVerbosity);}
232
233 BDS::RegisterSamplerPhysics(parallelWorldPhysics, physList);
234 // Construction of the physics lists defines the necessary particles and therefore
235 // we can calculate the beam rigidity for the particle the beam is designed w.r.t. This
236 // must happen before the geometry is constructed (which is called by
237 // runManager->Initialize()).
238 BDSParticleDefinition* designParticle = nullptr;
239 BDSParticleDefinition* beamParticle = nullptr;
240 G4bool beamDifferentFromDesignParticle = false;
242 globalConstants->FFact(),
243 designParticle,
244 beamParticle,
245 beamDifferentFromDesignParticle);
246 if (usualPrintOut)
247 {
248 G4cout << "Design particle properties: " << G4endl << *designParticle;
249 if (beamDifferentFromDesignParticle)
250 {G4cout << "Beam particle properties: " << G4endl << *beamParticle;}
251 }
252 // update rigidity where needed
253 construction->SetDesignParticle(designParticle);
254 //BDSFieldFactory::SetDesignParticle(designParticle);
255
256 //auto biasPhysics = BDS::BuildAndAttachBiasWrapper(parser->GetBiasing());
257 //if (biasPhysics)//could be nullptr and can't be passed to geant4 like this
258 // {physList->RegisterPhysics(biasPhysics);}
259 runManager->SetUserInitialization(physList);
260
262 GMAD::Beam b;
263 b.distrType = "sixtracklink";
264 if (!bdsBunch)
265 {
267 parser->GetBeam(),
268 globalConstants->BeamlineTransform(),
269 globalConstants->BeamlineS(),
270 globalConstants->GeneratePrimariesOnly());
271 }
272 else
273 {
274 bdsBunch->SetOptions(beamParticle, b, BDSBunchType::reference); // update particle definition only
275 }
278 delete beamParticle;
279
281 G4GeometryTolerance* theGeometryTolerance = G4GeometryTolerance::GetInstance();
282 if (usualPrintOut)
283 {
284 G4cout << __METHOD_NAME__ << "Geometry Tolerances: " << G4endl;
285 G4cout << __METHOD_NAME__ << std::setw(12) << "Surface: " << std::setw(7) << theGeometryTolerance->GetSurfaceTolerance() << " mm" << G4endl;
286 G4cout << __METHOD_NAME__ << std::setw(12) << "Angular: " << std::setw(7) << theGeometryTolerance->GetAngularTolerance() << " rad" << G4endl;
287 G4cout << __METHOD_NAME__ << std::setw(12) << "Radial: " << std::setw(7) << theGeometryTolerance->GetRadialTolerance() << " mm" << G4endl;
288 }
291 BDSLinkEventAction* eventAction = new BDSLinkEventAction(bdsOutput, runAction, trackerDebug);
292 runManager->SetUserAction(eventAction);
293 runManager->SetUserAction(runAction);
294 G4int verboseSteppingEventStart = globalConstants->VerboseSteppingEventStart();
295 G4int verboseSteppingEventStop = BDS::VerboseEventStop(verboseSteppingEventStart,
296 globalConstants->VerboseSteppingEventContinueFor());
297 runManager->SetUserAction(new BDSLinkTrackingAction(globalConstants->Batch(),
298 eventAction,
299 verboseSteppingEventStart,
300 verboseSteppingEventStop,
301 globalConstants->VerboseSteppingPrimaryOnly(),
302 globalConstants->VerboseSteppingLevel()));
303 runManager->SetUserAction(new BDSLinkStackingAction(globalConstants, std::set<G4int>(), protonsAndIonsOnly, minimumKineticEnergy));
304
305 /*
306 // Only add steppingaction if it is actually used, so do check here (for performance reasons)
307 G4int verboseSteppingEventStart = globalConstants->VerboseSteppingEventStart();
308 G4int verboseSteppingEventStop = BDS::VerboseEventStop(verboseSteppingEventStart,
309 globalConstants->VerboseSteppingEventContinueFor());
310 if (globalConstants->VerboseSteppingBDSIM())
311 {
312 runManager->SetUserAction(new BDSSteppingAction(true,
313 verboseSteppingEventStart,
314 verboseSteppingEventStop));
315 }
316 */
317
318 auto primaryGeneratorAction = new BDSLinkPrimaryGeneratorAction(bdsBunch, &currentElementIndex, construction, trackerDebug);
319 construction->SetPrimaryGeneratorAction(primaryGeneratorAction);
320 runManager->SetUserAction(primaryGeneratorAction);
321 //BDSFieldFactory::SetPrimaryGeneratorAction(primaryGeneratorAction);
322
324 runManager->Initialize();
325
327 construction->BuildPhysicsBias();
328
329 if (usualPrintOut && BDSGlobalConstants::Instance()->PhysicsVerbose())
330 {
333 }
334
338 runManager->SetVerboseLevel(std::min(globalConstants->VerboseRunLevel(), globalConstants->PhysicsVerbosity()));
339 G4EventManager::GetEventManager()->SetVerboseLevel(globalConstants->VerboseEventLevel());
340 G4EventManager::GetEventManager()->GetTrackingManager()->SetVerboseLevel(globalConstants->VerboseTrackingLevel());
341
343 G4bool bCloseGeometry = G4GeometryManager::GetInstance()->CloseGeometry();
344 if (!bCloseGeometry)
345 {
346 G4cerr << __METHOD_NAME__ << "error - geometry not closed." << G4endl;
347 return 1;
348 }
349
350 if (globalConstants->ExportGeometry())
351 {
352 BDSGeometryWriter geometrywriter;
353 geometrywriter.ExportGeometry(globalConstants->ExportType(),
354 globalConstants->ExportFileName());
355 }
356
357 const auto& nameInds = construction->NameToElementIndex();
358 nameToElementIndex.insert(nameInds.begin(), nameInds.end());
359
360 if (bdsOutput)
361 {
364 }
365
366 initialised = true;
367 return 0;
368}
369
370void BDSIMLink::BeamOn(int nGenerate)
371{
373 {return;} // a mode where we don't do anything
374
375 G4cout.precision(10);
377 struct sigaction act;
378 act.sa_handler = &BDS::HandleAborts;
379 sigemptyset(&act.sa_mask);
380 act.sa_flags = 0;
381 if (!ignoreSIGINT)
382 {sigaction(SIGINT, &act, nullptr);}
383 sigaction(SIGABRT, &act, nullptr);
384 sigaction(SIGTERM, &act, nullptr);
385 sigaction(SIGSEGV, &act, nullptr);
386
388 try
389 {
390 if (!BDSGlobalConstants::Instance()->Batch()) // Interactive mode
391 {
392 BDSVisManager visManager = BDSVisManager(BDSGlobalConstants::Instance()->VisMacroFileName(),
393 BDSGlobalConstants::Instance()->Geant4MacroFileName());
394 visManager.StartSession(argcCache, argvCache);
395 }
396 else
397 {// batch mode
398 if (nGenerate < 0)
399 {runManager->BeamOn(BDSGlobalConstants::Instance()->NGenerate());}
400 else
401 {runManager->BeamOn(nGenerate);}
402 }
403 }
404 catch (const BDSException& exception)
405 {
406 // don't do this for now in case it's dangerous and we try tracking with open geometry
407 //G4GeometryManager::GetInstance()->OpenGeometry();
408 G4cout << exception.what() << G4endl;
409 exit(1);
410 }
411}
412
414{
416 G4GeometryManager::GetInstance()->OpenGeometry();
417
418#ifdef BDSDEBUG
419 G4cout << __METHOD_NAME__ << "deleting..." << G4endl;
420#endif
421 if (bdsOutput)
422 {bdsOutput->CloseFile();}
423 delete bdsOutput;
424
425 try
426 {
427 // order important here because of singletons relying on each other
431 delete BDSAcceleratorModel::Instance();
433 delete BDSFieldFactory::Instance(); // this uses BDSGlobalConstants which uses BDSMaterials
435 delete BDSMaterials::Instance();
436
437 // instances not used in this file, but no other good location for deletion
438 if (initialisationResult < 2)
439 {
440 delete BDSColours::Instance();
442 //delete BDSSDManager::Instance();
445 }
446 }
447 catch (...)
448 {;} // ignore any exception as this is a destructor
449
450 delete runManager;
451 delete parser;
452
453 if (argvCache) {
454 for (int i = 0; i < argcCache; ++i) {
455 delete[] argvCache[i];
456 }
457 delete[] argvCache;
458 }
459
460 if (usualPrintOut)
461 {G4cout << __METHOD_NAME__ << "End of Run. Thank you for using BDSIM!" << G4endl;}
462}
463
464int BDSIMLink::GetLinkIndex(const std::string& elementName) const
465{
466 int result = -1;
467 auto search = nameToElementIndex.find(elementName);
468 if (search != nameToElementIndex.end())
469 {result = search->second;}
470 return result;
471}
472
473const BDSLinkComponent* BDSIMLink::GetLinkComponent(int linkID) const
474{
475 const BDSBeamline* bl = construction->LinkBeamline();
476 if (!bl)
477 {return nullptr;}
478 if (linkID > (int)bl->size())
479 {return nullptr;}
480 const auto rawAccComponent = bl->at(linkID)->GetAcceleratorComponent();
481 const auto linkComponent = dynamic_cast<const BDSLinkComponent*>(rawAccComponent);
482 return linkComponent;
483}
484
485double BDSIMLink::GetChordLengthOfLinkElement(int beamlineIndex) const
486{
487 const BDSLinkComponent* component = GetLinkComponent(beamlineIndex);
488 if (!component)
489 {return -1.0;} // play it safe
490 return component->ComponentChordLength();
491}
492
493double BDSIMLink::GetChordLengthOfLinkElement(const std::string& elementName)
494{
495 int linkID = GetLinkIndex(elementName);
496 int beamlineIndex = linkIDToBeamlineIndex[linkID];
497 return GetChordLengthOfLinkElement(beamlineIndex);
498}
499
500double BDSIMLink::GetArcLengthOfLinkElement(int beamlineIndex) const
501{
502 const BDSLinkComponent* component = GetLinkComponent(beamlineIndex);
503 if (!component)
504 {return -1.0;} // play it safe
505 return component->ComponentArcLength();
506}
507
508double BDSIMLink::GetArcLengthOfLinkElement(const std::string& elementName)
509{
510 int linkID = GetLinkIndex(elementName);
511 int beamlineIndex = linkIDToBeamlineIndex[linkID];
512 return GetArcLengthOfLinkElement(beamlineIndex);
513}
514
515BDSBunch* BDSIMLink::GetBunch() const
516{
517 return bdsBunch;
518}
519
520void BDSIMLink::SelectLinkElement(const std::string& elementName, G4bool debug)
521{
522 if (debug)
523 {G4cout << "Searching for " << elementName;}
524 currentElementIndex = GetLinkIndex(elementName);
525 if (debug)
526 {G4cout << ", Index " << currentElementIndex << G4endl;}
527
528 // Check if the element exists by querying the index: -1 means it doesn't exist
529 if (currentElementIndex == -1)
530 {throw std::runtime_error("Element not found " + elementName);}
531}
532
533void BDSIMLink::SelectLinkElement(int index, G4bool debug)
534{
535 if (debug)
536 {G4cout << "Searching for " << index << G4endl;}
537 currentElementIndex = index;
538}
539
540int BDSIMLink::AddLinkCollimatorJaw(const std::string& collimatorName,
541 const std::string& materialName,
542 double length,
543 double halfApertureLeft,
544 double halfApertureRight,
545 double rotation,
546 double xOffset,
547 double yOffset,
548 double jawTiltLeft,
549 double jawTiltRight,
550 bool buildLeftJaw,
551 bool buildRightJaw,
552 bool isACrystal,
553 double crystalAngle,
554 bool sampleIn)
555{
556 G4GeometryManager* gm = G4GeometryManager::GetInstance();
557 if (gm->IsGeometryClosed())
558 {gm->OpenGeometry();}
559
560 G4int linkID = construction->AddLinkCollimatorJaw(
561 collimatorName,
562 materialName,
563 length,
564 halfApertureLeft,
565 halfApertureRight,
566 rotation,
567 xOffset,
568 yOffset,
569 jawTiltLeft,
570 jawTiltRight,
571 buildLeftJaw,
572 buildRightJaw,
573 isACrystal,
574 crystalAngle,
575 sampleIn);
576 // update this class's nameToElementIndex map
577 nameToElementIndex = construction->NameToElementIndex();
578 linkIDToBeamlineIndex = construction->LinkIDToBeamlineIndex();
579
580 if (bdsOutput)
582
584 G4bool bCloseGeometry = gm->CloseGeometry();
585 if (!bCloseGeometry)
586 {throw BDSException(__METHOD_NAME__, "error - geometry not closed.");}
587 return (int)linkID;
588}
589
590int BDSIMLink::AddLinkCollimatorTipJaw(const std::string& collimatorName,
591 const std::string& materialName,
592 const std::string& tipMaterialName,
593 double tipThickness,
594 double length,
595 double halfApertureLeft,
596 double halfApertureRight,
597 double rotation,
598 double xOffset,
599 double yOffset,
600 double jawTiltLeft,
601 double jawTiltRight,
602 bool buildLeftJaw,
603 bool buildRightJaw)
604{
605 G4GeometryManager* gm = G4GeometryManager::GetInstance();
606 if (gm->IsGeometryClosed())
607 {gm->OpenGeometry();}
608
609 G4int linkID = construction->AddLinkCollimatorTipJaw(collimatorName,
610 materialName,
611 tipMaterialName,
612 tipThickness,
613 length,
614 halfApertureLeft,
615 halfApertureRight,
616 rotation,
617 xOffset,
618 yOffset,
619 jawTiltLeft,
620 jawTiltRight,
621 buildLeftJaw,
622 buildRightJaw);
623 // update this class's nameToElementIndex map
624 nameToElementIndex = construction->NameToElementIndex();
625 linkIDToBeamlineIndex = construction->LinkIDToBeamlineIndex();
626
627 if (bdsOutput)
629
631 G4bool bCloseGeometry = gm->CloseGeometry();
632 if (!bCloseGeometry)
633 {throw BDSException(__METHOD_NAME__, "error - geometry not closed.");}
634 return (int)linkID;
635}
636
637
639 G4GeometryManager* gm = G4GeometryManager::GetInstance();
640 if (gm->IsGeometryClosed())
641 {gm->OpenGeometry();}
642
643 G4int linkID = construction->AddLinkElement(el);
644 // update this class's nameToElementIndex map
645 nameToElementIndex = construction->NameToElementIndex();
646 linkIDToBeamlineIndex = construction->LinkIDToBeamlineIndex();
647
648 if (bdsOutput)
650
652 G4bool bCloseGeometry = gm->CloseGeometry();
653 if (!bCloseGeometry)
654 {throw BDSException(__METHOD_NAME__, "error - geometry not closed.");}
655 return (int)linkID;
656}
657
658
659BDSHitsCollectionSamplerLink* BDSIMLink::SamplerHits() const
660{
661 return runAction ? runAction->SamplerHits() : nullptr;
662}
663
664int BDSIMLink::GetCurrentMaximumSixTrackParticleID() const
665{
666 return runAction ? runAction->MaximumExternalParticleID() : 0;
667}
668
669void BDSIMLink::SetCurrentMaximumExternalParticleID(int currentMaximumExternalParticleID)
670{
671 if (runAction)
672 {runAction->SetMaximumExternalParticleID(currentMaximumExternalParticleID);}
673}
static BDSAperturePointsCache * Instance()
Access the singleton instance.
void ClearCachedFiles()
Delete all cached points from memory and clear the map of files loaded.
static BDSBeamPipeFactory * Instance()
Singleton accessor.
BDSAcceleratorComponent * GetAcceleratorComponent() const
Accessor.
A vector of BDSBeamlineElement instances - a beamline.
const BDSBeamlineElement * at(int iElement) const
Return a reference to the element at i.
BeamlineVector::size_type size() const
Get the number of elements.
static BDSBunch * CreateBunch(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const G4Transform3D &beamlineTransform=G4Transform3D::Identity, G4double beamlineS=0, G4bool generatePrimariesOnlyIn=false)
factory method
The base class for bunch distribution generators.
Definition BDSBunch.hh:46
virtual const BDSParticleDefinition * ParticleDefinition() const
Access the beam particle definition.
Definition BDSBunch.hh:95
virtual void SetOptions(const BDSParticleDefinition *beamParticle, const GMAD::Beam &beam, const BDSBunchType &distrType, G4Transform3D beamlineTransformIn=G4Transform3D::Identity, const G4double beamlineS=0)
Definition BDSBunch.cc:81
static BDSCavityFactory * Instance()
Singleton accessor.
static BDSColours * Instance()
singleton pattern
Definition BDSColours.cc:32
General exception with possible name of object and message.
const char * what() const noexcept override
Override message in std::exception.
Executable option processing for BDSIM.
const GMAD::Options & Options() const
Accessor for options generated by command line parsing.
void Print() const
Print out the commands and their set values.
G4bool IgnoreSIGINT() const
Accessor.
const GMAD::Beam & Beam() const
Accessor for beam options generate by command line parsing.
void PrintCopyright() const
Print out the copyright information (no exit).
G4String InputFileName() const
Acessor for convenience for the one thing that's needed before the parser options.
static BDSFieldFactory * Instance()
Public accessor method for singleton pattern.
static BDSFieldLoader * Instance()
Singleton accessor.
static BDSGeometryFactory * Instance()
Singleton accessor.
A class for writing fully constructed geometry from BDSIM out to other formats.
void ExportGeometry(const G4String &geometryType, const G4String &geometryFileName)
A class that holds global options and constants.
static BDSGlobalConstants * Instance()
Access method.
A bunch distribution that holds a bunch from a Link.
A BDSAcceleratorComponent wrapper for BDSLinkOpaqueBox.
G4double ComponentChordLength() const
Accessor.
G4double ComponentArcLength() const
Accessor.
Construction of the geometry in the case of a link model.
G4int AddLinkCollimatorTipJaw(const std::string &collimatorName, const std::string &materialName, const std::string &tipMaterialName, G4double tipThickness, G4double length, G4double halfApertureLeft, G4double halfApertureRight, G4double rotation, G4double xOffset, G4double yOffset, G4double jawTiltLeft=0.0, G4double jawTiltRight=0.0, G4bool buildLeftJaw=true, G4bool buildRightJaw=true)
Interface to append a tip collimator jaw to the linking.
G4int AddLinkCollimatorJaw(const std::string &collimatorName, const std::string &materialName, G4double length, G4double halfApertureLeft, G4double halfApertureRight, G4double rotation, G4double xOffset, G4double yOffset, G4double jawTiltLeft=0.0, G4double jawTiltRight=0.0, G4bool buildLeftJaw=true, G4bool buildRightJaw=true, G4bool isACrystal=false, G4double crystalAngle=0, G4bool sampleIn=false)
Interface to append a collimator of jaw style to the linking.
G4int AddLinkElement(GMAD::Element el)
Interface to append an element.
void SetDesignParticle(const BDSParticleDefinition *defIn)
Set the design particle definition.
Process information at the event level for Link to trackers.
Generates primary particle vertices using BDSBunch.
Simplified run action to hold link hits.
Wrapper from G4RunManager that provides our exception handler.
BDSIM's Geant4 stacking action.
Action to decide whether or not to store trajectory information.
static BDSMaterials * Instance()
Singleton pattern access.
void PrepareRequiredMaterials(G4bool verbose=false)
converts parser material list
static BDSOutput * CreateOutput(BDSOutputType format, const G4String &fileName, G4int fileNumberOffset=-1, G4int compressionLevel=-1)
factory method
virtual void NewFile()=0
Open a new file. This should call WriteHeader() in it.
virtual void InitialiseGeometryDependent()
Definition BDSOutput.cc:170
virtual void UpdateSamplers()
Interface to allow updating samplers with dynamic construction. Only for link - not for regular use.
Definition BDSOutput.hh:95
virtual void CloseFile()=0
Const entry to parser objects.
Definition BDSParser.hh:36
void AmalgamateBeam(const GMAD::Beam &beamIn, bool recreate)
Amalgamate the input beam definition with the ones stored in teh parser.
Definition BDSParser.cc:74
void CheckOptions()
Check options for consistency. This also checks the beam options.
Definition BDSParser.cc:93
static BDSParser * Instance()
Access method.
Definition BDSParser.cc:29
const GMAD::Beam & GetBeam() const
Return beam.
Definition BDSParser.hh:56
const GMAD::Options & GetOptions() const
Return options.
Definition BDSParser.hh:50
void AmalgamateOptions(const GMAD::Options &optionsIn)
Amalgamate the input options with the ones stored in the parser.
Definition BDSParser.cc:85
Wrapper for particle definition.
G4String Name() const
Accessor.
static BDSSamplerRegistry * Instance()
Accessor for registry.
static BDSTemporaryFiles * Instance()
Singleton accessor.
The BDS Visualisation Manager.
void StartSession(int argc, char **argv)
Start interactive mode.
std::string distrType
beam parameters
Definition beamBase.h:44
Beam class.
Definition beam.h:43
std::string physicsList
list of physics processes
bool verbose
General verbosity.
Definition optionsBase.h:64
bool recreate
Whether to recreate from a file or not.
Definition optionsBase.h:94
std::vector< G4ParallelWorldPhysics * > ConstructParallelWorldPhysics(const std::vector< G4VUserParallelWorld * > &worlds)
Construct the parallel physics process for each sampler world.
void PrintDefinedParticles()
void RegisterSamplerPhysics(const std::vector< G4ParallelWorldPhysics * > &processes, G4VModularPhysicsList *physicsList)
Register each parallel physics process to the main physics list.
std::vector< G4VUserParallelWorld * > ConstructAndRegisterParallelWorlds(G4VUserDetectorConstruction *massWorld, G4bool buildSamplerWorld, G4bool buildPlacementFieldsWorld)
void PrintPrimaryParticleProcesses(const G4String &primaryParticleName)
G4bool Geant4EnvironmentIsSet()
Check if the geant4 environmental variables necessary for a run are set.
void HandleAborts(int signal_number)
void ConstructDesignAndBeamParticle(const GMAD::Beam &beamDefinition, G4double ffact, BDSParticleDefinition *&designParticle, BDSParticleDefinition *&beamParticle, G4bool &beamDifferentFromDesignParticle)
G4int VerboseEventStop(G4int verboseEventStart, G4int verboseEventContinueFor)
G4VModularPhysicsList * BuildPhysics(const G4String &physicsList, G4int verbosity=1)
Element class.
Definition element.h:47