18#include "BDSAcceleratorModel.hh"
19#include "BDSBeamline.hh"
20#include "BDSBeamlineElement.hh"
22#include "BDSHitEnergyDeposition.hh"
23#include "BDSEventInfo.hh"
24#include "BDSGlobalConstants.hh"
25#include "BDSOutputStructures.hh"
26#include "BDSOutputROOTEventAperture.hh"
27#include "BDSOutputROOTEventBeam.hh"
28#include "BDSOutputROOTEventCollimator.hh"
29#include "BDSOutputROOTEventCoords.hh"
30#include "BDSOutputROOTEventHeader.hh"
31#include "BDSOutputROOTEventHistograms.hh"
32#include "BDSOutputROOTEventInfo.hh"
33#include "BDSOutputROOTEventLoss.hh"
34#include "BDSOutputROOTEventLossWorld.hh"
35#include "BDSOutputROOTEventModel.hh"
36#include "BDSOutputROOTEventOptions.hh"
37#include "BDSOutputROOTEventRunInfo.hh"
38#include "BDSOutputROOTEventSampler.hh"
39#include "BDSOutputROOTEventSamplerC.hh"
40#include "BDSOutputROOTEventSamplerS.hh"
41#include "BDSOutputROOTEventTrajectory.hh"
42#include "BDSOutputROOTParticleData.hh"
43#include "BDSHitSampler.hh"
44#include "BDSSamplerRegistry.hh"
45#include "BDSTrajectoryPoint.hh"
48#include "G4Material.hh"
49#include "G4MaterialTable.hh"
51#include "CLHEP/Units/SystemOfUnits.h"
62 localSamplersInitialised(false),
63 localCollimatorsInitialised(false)
65 G4bool storeCollimatorInfo = globals->StoreCollimatorInfo();
66 G4bool storeCavityInfo = globals->StoreCavityInfo();
67 G4bool storeTurn = globals->StoreELossTurn();
68 G4bool storeLinks = globals->StoreELossLinks();
69 G4bool storeLocal = globals->StoreELossLocal();
70 G4bool storeGlobal = globals->StoreELossGlobal();
71 G4bool storeTime = globals->StoreELossTime();
72 G4bool storeStepLength = globals->StoreELossStepLength();
73 G4bool storePreStepKineticEnergy = globals->StoreELossPreStepKineticEnergy();
74 G4bool storeModelID = globals->StoreELossModelID();
75 G4bool storeELPhysics = globals->StoreELossPhysicsProcesses();
77 storeModelID = storeModelID || storeLinks;
86 storeGlobal, storeTime, storeStepLength,
87 storePreStepKineticEnergy, storeELPhysics);
89 storeGlobal, storeTime, storeStepLength,
90 storePreStepKineticEnergy, storeELPhysics);
92 storeGlobal, storeTime, storeStepLength,
93 storePreStepKineticEnergy, storeELPhysics);
109#ifndef __ROOTDOUBLE__
117BDSOutputStructures::~BDSOutputStructures()
124 delete primaryGlobal;
141 for (
auto sampler : samplerCTrees)
143 for (
auto sampler : samplerSTrees)
151 G4int nbins, G4double xmin, G4double xmax)
153 G4int result =
evtHistos->Create1DHistogram(name, title, nbins, xmin, xmax);
155 runHistos->Create1DHistogram(name, title, nbins, xmin, xmax);
160 std::vector<double>& edges)
162 G4int result =
evtHistos->Create1DHistogram(name,title,edges);
163 runHistos->Create1DHistogram(name,title,edges);
168 G4int nBinsX, G4double xMin, G4double xMax,
169 G4int nBinsY, G4double yMin, G4double yMax,
170 G4int nBinsZ, G4double zMin, G4double zMax)
172 G4int result =
evtHistos->Create3DHistogram(name, title,
177 runHistos->Create3DHistogram(name, title,
185 const G4String& title,
186 const G4String& eScale,
187 const std::vector<double>& eBinsEdges,
188 G4int nBinsX, G4double xMin, G4double xMax,
189 G4int nBinsY, G4double yMin, G4double yMax,
190 G4int nBinsZ, G4double zMin, G4double zMax,
191 G4int nBinsE, G4double eMin, G4double eMax)
193 G4int result =
evtHistos->Create4DHistogram(name, title, eScale, eBinsEdges,
199 runHistos->Create4DHistogram(name, title, eScale, eBinsEdges,
212 const auto sNames = samplerRegistry->GetUniqueNamesPlane();
213#ifdef USE_SIXTRACKLINK
227 for (
const auto& samplerName : sNames)
229#ifndef __ROOTDOUBLE__
237 const auto planeIDs = samplerRegistry->GetSamplerIDsPlane();
239 for (
const auto& ID : planeIDs)
240 {samplerIDToIndexPlane[ID] = i; i++;}
243 const auto scNames = samplerRegistry->GetUniqueNamesCylinder();
244 samplerCTrees.reserve(scNames.size());
245 for (
const auto& samplerName : scNames)
248 samplerCNames.emplace_back(samplerName);
250 const auto cylinderIDs = samplerRegistry->GetSamplerIDsCylinder();
252 for (
const auto& ID : cylinderIDs)
253 {samplerIDToIndexCylinder[ID] = i; i++;}
256 const auto ssNames = samplerRegistry->GetUniqueNamesSphere();
257 samplerSTrees.reserve(ssNames.size());
258 for (
const auto& samplerName : ssNames)
261 samplerSNames.emplace_back(samplerName);
263 const auto sphereIDs = samplerRegistry->GetSamplerIDsSphere();
265 for (
const auto& ID : sphereIDs)
266 {samplerIDToIndexSphere[ID] = i; i++;}
272 materialToID.clear();
273 materialIDToNameUnique.clear();
275 const auto materialTable = G4Material::GetMaterialTable();
292 std::map<std::pair<G4String, G4double>, G4Material*> sortingMap;
293 std::map<G4String, int> nameCount;
294 std::map<G4Material*, G4String> matToUniqueName;
296 for (
const auto& mat : *materialTable)
298 G4String matName = mat->GetName();
299 G4String matNameUnique = matName;
301 auto search = nameCount.find(matName);
302 if (search != nameCount.end())
305 matNameUnique = matName + std::to_string(search->second);
306 matToUniqueName[mat] = matNameUnique;
310 nameCount[matName] = 0;
311 matToUniqueName[mat] = matName;
313 sortingMap[std::make_pair(matNameUnique, mat->GetDensity())] = mat;
317 for (
const auto& kv : sortingMap)
319 materialToID[kv.second] = i;
320 materialIDToNameUnique[i] = matToUniqueName[kv.second];
329 for (
auto const& samplerName : samplerRegistry->GetUniqueNames())
334#ifndef __ROOTDOUBLE__
344 const auto planeNames = samplerRegistry->GetUniqueNamesPlane();
345 const auto planeIDs = samplerRegistry->GetSamplerIDsPlane();
346 for (
size_t i = 0; i < planeIDs.size(); ++i)
350 {samplerIDToIndexPlane[planeIDs.at(i)] = (G4int)std::distance(
samplerNames.begin(), nameIterator);}
358 const G4String collimatorPrefix =
"COLL_";
380 G4double xDiff = info.xSizeOut - info.xSizeIn;
381 G4double yDiff = info.ySizeOut - info.ySizeIn;
388 const G4String cavityPrefix =
"CAV_";
456 for (
auto sampler : samplerCTrees)
458 for (
auto sampler : samplerSTrees)
461 {collimator->Flush();}
462 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 > GetIndicesOfElementsOfType(const G4String &type) const
Return vector of indices for this beam line where element of type name 'type' is found.
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 cavity in the model.
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.
Information stored per sampler per event.
virtual void Flush()
Clean Sampler.
Structure to record a trajectory.
virtual 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 collimators.
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.
G4int nCavities
Number of cavities in beam line.
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.
std::vector< G4String > cavityNames
Names of cavities in output structures.
BDSOutputROOTEventHistograms * runHistos
Run level histograms.
BDSOutputROOTEventLossWorld * eLossWorldExit
World exit hits.
std::vector< G4int > cavityIndices
Indices in beam line that are cavities.
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::vector< BDSOutputROOTEventCavityInfo > cavityInfo
Cavity parameters.
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 PrepareCavityInformation()
Extract number of collimators and their names from beam line.
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.
std::map< G4String, G4int > cavityIndicesByName
Indices mapped to their name.
static BDSSamplerRegistry * Instance()
Accessor for registry.