19#include "BDSAcceleratorModel.hh"
20#include "BDSBeamline.hh"
21#include "BDSBeamlineElement.hh"
23#include "BDSHitEnergyDeposition.hh"
24#include "BDSEventInfo.hh"
25#include "BDSGlobalConstants.hh"
26#include "BDSOutputStructures.hh"
27#include "BDSOutputROOTEventAperture.hh"
28#include "BDSOutputROOTEventBeam.hh"
29#include "BDSOutputROOTEventCollimator.hh"
30#include "BDSOutputROOTEventCoords.hh"
31#include "BDSOutputROOTEventHeader.hh"
32#include "BDSOutputROOTEventHistograms.hh"
33#include "BDSOutputROOTEventInfo.hh"
34#include "BDSOutputROOTEventLoss.hh"
35#include "BDSOutputROOTEventLossWorld.hh"
36#include "BDSOutputROOTEventModel.hh"
37#include "BDSOutputROOTEventOptions.hh"
38#include "BDSOutputROOTEventRunInfo.hh"
39#include "BDSOutputROOTEventSampler.hh"
40#include "BDSOutputROOTEventSamplerC.hh"
41#include "BDSOutputROOTEventSamplerS.hh"
42#include "BDSOutputROOTEventTrajectory.hh"
43#include "BDSOutputROOTParticleData.hh"
44#include "BDSHitSampler.hh"
45#include "BDSSamplerRegistry.hh"
46#include "BDSTrajectoryPoint.hh"
49#include "G4Material.hh"
50#include "G4MaterialTable.hh"
52#include "CLHEP/Units/SystemOfUnits.h"
62 localSamplersInitialised(false),
63 localCollimatorsInitialised(false)
65 G4bool storeCollimatorInfo = globals->StoreCollimatorInfo();
66 G4bool storeTurn = globals->StoreELossTurn();
67 G4bool storeLinks = globals->StoreELossLinks();
68 G4bool storeLocal = globals->StoreELossLocal();
69 G4bool storeGlobal = globals->StoreELossGlobal();
70 G4bool storeTime = globals->StoreELossTime();
71 G4bool storeStepLength = globals->StoreELossStepLength();
72 G4bool storePreStepKineticEnergy = globals->StoreELossPreStepKineticEnergy();
73 G4bool storeModelID = globals->StoreELossModelID();
74 G4bool storeELPhysics = globals->StoreELossPhysicsProcesses();
76 storeModelID = storeModelID || storeLinks;
85 storeGlobal, storeTime, storeStepLength,
86 storePreStepKineticEnergy, storeELPhysics);
88 storeGlobal, storeTime, storeStepLength,
89 storePreStepKineticEnergy, storeELPhysics);
91 storeGlobal, storeTime, storeStepLength,
92 storePreStepKineticEnergy, storeELPhysics);
108#ifndef __ROOTDOUBLE__
116BDSOutputStructures::~BDSOutputStructures()
123 delete primaryGlobal;
140 for (
auto sampler : samplerCTrees)
142 for (
auto sampler : samplerSTrees)
150 G4int nbins, G4double xmin, G4double xmax)
152 G4int result =
evtHistos->Create1DHistogram(name, title, nbins, xmin, xmax);
154 runHistos->Create1DHistogram(name, title, nbins, xmin, xmax);
159 std::vector<double>& edges)
161 G4int result =
evtHistos->Create1DHistogram(name,title,edges);
162 runHistos->Create1DHistogram(name,title,edges);
167 G4int nBinsX, G4double xMin, G4double xMax,
168 G4int nBinsY, G4double yMin, G4double yMax,
169 G4int nBinsZ, G4double zMin, G4double zMax)
171 G4int result =
evtHistos->Create3DHistogram(name, title,
176 runHistos->Create3DHistogram(name, title,
184 const G4String& title,
185 const G4String& eScale,
186 const std::vector<double>& eBinsEdges,
187 G4int nBinsX, G4double xMin, G4double xMax,
188 G4int nBinsY, G4double yMin, G4double yMax,
189 G4int nBinsZ, G4double zMin, G4double zMax,
190 G4int nBinsE, G4double eMin, G4double eMax)
192 G4int result =
evtHistos->Create4DHistogram(name, title, eScale, eBinsEdges,
198 runHistos->Create4DHistogram(name, title, eScale, eBinsEdges,
211 const auto sNames = samplerRegistry->GetUniqueNamesPlane();
212#ifdef USE_SIXTRACKLINK
226 for (
const auto& samplerName : sNames)
228#ifndef __ROOTDOUBLE__
236 const auto planeIDs = samplerRegistry->GetSamplerIDsPlane();
238 for (
const auto& ID : planeIDs)
239 {samplerIDToIndexPlane[ID] = i; i++;}
242 const auto scNames = samplerRegistry->GetUniqueNamesCylinder();
243 samplerCTrees.reserve(scNames.size());
244 for (
const auto& samplerName : scNames)
247 samplerCNames.emplace_back(samplerName);
249 const auto cylinderIDs = samplerRegistry->GetSamplerIDsCylinder();
251 for (
const auto& ID : cylinderIDs)
252 {samplerIDToIndexCylinder[ID] = i; i++;}
255 const auto ssNames = samplerRegistry->GetUniqueNamesSphere();
256 samplerSTrees.reserve(ssNames.size());
257 for (
const auto& samplerName : ssNames)
260 samplerSNames.emplace_back(samplerName);
262 const auto sphereIDs = samplerRegistry->GetSamplerIDsSphere();
264 for (
const auto& ID : sphereIDs)
265 {samplerIDToIndexSphere[ID] = i; i++;}
271 materialToID.clear();
272 materialIDToNameUnique.clear();
274 const auto materialTable = G4Material::GetMaterialTable();
286 std::map<std::pair<G4String, G4double>, G4Material*> sortingMap;
287 std::map<G4String, int> nameCount;
288 std::map<G4Material*, G4String> matToUniqueName;
289 for (
const auto& mat : *materialTable)
291 G4String matName = mat->GetName();
292 sortingMap[std::make_pair(matName, mat->GetDensity())] = mat;
294 auto search = nameCount.find(matName);
295 if (search != nameCount.end())
298 matToUniqueName[mat] = matName + std::to_string(search->second);
302 nameCount[matName] = 0;
303 matToUniqueName[mat] = matName;
307 for (
const auto& kv : sortingMap)
309 materialToID[kv.second] = i;
310 materialIDToNameUnique[i] = matToUniqueName[kv.second];
323#ifndef __ROOTDOUBLE__
338 const G4String collimatorPrefix =
"COLL_";
359 G4double xDiff = info.xSizeOut - info.xSizeIn;
360 G4double yDiff = info.ySizeOut - info.ySizeIn;
405 for (
auto sampler : samplerCTrees)
407 for (
auto sampler : samplerSTrees)
410 {collimator->Flush();}
411 primaryGlobal->Flush();
const BDSBeamline * BeamlineMain() const
Accessor.
A class that holds a fully constructed BDSAcceleratorComponent as well as any information relevant to...
G4String GetPlacementName() const
Accessor.
G4String GetName() const
Accessor.
A vector of BDSBeamlineElement instances - a beamline.
const BDSBeamlineElement * at(int iElement) const
Return a reference to the element at i.
std::vector< G4int > GetIndicesOfCollimators() const
Return indices in order of ecol, rcol, jcol and crystalcol elements.
A class that holds global options and constants.
Data stored for energy deposition hits per event.
Class to store all beam options for a BDSIM run.
Data stored for each collimator in the model.
Data stored for each collimator per event.
Holder for a set of histograms to be stored.
virtual void Flush()
Flush the contents.
Information pertaining to an individual event.
Data stored for world hits per event.
Data stored for energy deposition hits per event.
Information stored per model representing accelerator.
void Flush()
Initialise all members.
Class to store all options for a BDSIM run.
Information pertaining to a run.
Information stored per cylindrical sampler per event.
Information stored per spherical sampler per event.
virtual void Flush()
Clean Sampler.
Structure to record a trajectory.
void Flush()
add comment to avoid warning (no need to make persistent, see issue #191)
Geant4 particle data for particles used in simulation.
virtual void Flush()
Clear maps.
void InitialiseCollimators()
Construct collimtors.
BDSOutputROOTEventModel * modelOutput
Model output.
G4int Create1DHistogram(G4String name, G4String title, G4int nbins, G4double xmin, G4double xmax)
Create histograms for both evtHistos and runHistos. Return index from evtHistos.
std::vector< G4String > collimatorNames
Names of collimators in output structures.
std::vector< BDSOutputROOTEventCollimator * > collimators
Collimator output structures.
std::vector< std::string > samplerNames
Sampler names to use.
BDSOutputROOTEventSampler< double > * primary
Primary sampler structure.
BDSOutputROOTEventRunInfo * runInfo
Run information.
void InitialiseMaterialMap()
Construct a map of material pointer to integer ID and name.
void ClearStructuresOptions()
Clear the local options structure.
BDSOutputROOTEventHistograms * runHistos
Run level histograms.
BDSOutputROOTEventLossWorld * eLossWorldExit
World exit hits.
void PrepareCollimatorInformation()
void ClearStructuresRunLevel()
Clear the local structures in this class in preparation for a new run.
BDSOutputStructures()=delete
Unused default constructors.
void InitialiseSamplers()
Construct samplers.
void ClearStructuresBeam()
Clear the local beam structure.
std::map< G4String, G4int > collimatorIndicesByName
Indices mapped to their name.
BDSOutputROOTEventLossWorld * eLossWorldContents
Externally supplied world contents hits.
G4int nCollimators
Number of collimators in beam line.
std::vector< BDSOutputROOTEventSampler< double > * > samplerTrees
Sampler structures.
std::vector< std::pair< G4double, G4double > > collimatorDifferences
void ClearStructuresModel()
Clear the local model structure.
void ClearStructuresHeader()
Clear the local header structure.
G4int Create4DHistogram(const G4String &name, const G4String &title, const G4String &eScale, const std::vector< double > &eBinsEdges, G4int nBinsX, G4double xMin, G4double xMax, G4int nBinsY, G4double yMin, G4double yMax, G4int nBinsZ, G4double zMin, G4double zMax, G4int nBinsE, G4double eMin, G4double eMax)
Create histograms for both evtHistos and runHistos. Return index from evtHistos.
BDSOutputROOTEventHeader * headerOutput
Information about the file.
BDSOutputROOTEventLossWorld * eLossWorld
World energy deposition.
BDSOutputROOTEventLoss * eLossVacuum
General energy deposition.
std::vector< G4int > collimatorIndices
Indices in beam line that are collimators.
BDSOutputROOTEventInfo * evtInfo
Event information.
BDSOutputROOTEventLoss * pLastHit
Primary loss point.
G4bool localSamplersInitialised
BDSOutputROOTEventHistograms * evtHistos
Event level histograms.
BDSOutputROOTEventLoss * eLossTunnel
Tunnel energy deposition.
G4int UpdateSamplerStructures()
Interface to allow setting up samplers later for dynamic geometry construction a la SixTrack....
G4int Create3DHistogram(G4String name, G4String title, G4int nBinsX, G4double xMin, G4double xMax, G4int nBinsY, G4double yMin, G4double yMax, G4int nBinsZ, G4double zMin, G4double zMax)
Create histograms for both evtHistos and runHistos. Return index from evtHistos.
void ClearStructuresEventLevel()
Clear the local structures in this class in preparation for a new event.
BDSOutputROOTEventLoss * pFirstHit
Primary hit point.
BDSOutputROOTEventTrajectory * traj
Trajectories.
BDSOutputROOTEventBeam * beamOutput
Beam output.
BDSOutputROOTEventLoss * eLoss
General energy deposition.
std::vector< BDSOutputROOTEventCollimatorInfo > collimatorInfo
void ClearStructuresParticleData()
Clear the local particle data structure.
G4bool localCollimatorsInitialised
Whether we've setup the member vector of collimators. Similarly to localSamplersInitialised.
BDSOutputROOTEventAperture * apertureImpacts
Impacts on the aperture.
BDSOutputROOTParticleData * particleDataOutput
Geant4 information / particle tables.
BDSOutputROOTEventOptions * optionsOutput
Options output.
static BDSSamplerRegistry * Instance()
Accessor for registry.