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"
63 localSamplersInitialised(false),
64 localCollimatorsInitialised(false)
66 G4bool storeCollimatorInfo = globals->StoreCollimatorInfo();
67 G4bool storeCavityInfo = globals->StoreCavityInfo();
68 G4bool storeTurn = globals->StoreELossTurn();
69 G4bool storeLinks = globals->StoreELossLinks();
70 G4bool storeLocal = globals->StoreELossLocal();
71 G4bool storeGlobal = globals->StoreELossGlobal();
72 G4bool storeTime = globals->StoreELossTime();
73 G4bool storeStepLength = globals->StoreELossStepLength();
74 G4bool storePreStepKineticEnergy = globals->StoreELossPreStepKineticEnergy();
75 G4bool storeModelID = globals->StoreELossModelID();
76 G4bool storeELPhysics = globals->StoreELossPhysicsProcesses();
78 storeModelID = storeModelID || storeLinks;
87 storeGlobal, storeTime, storeStepLength,
88 storePreStepKineticEnergy, storeELPhysics);
90 storeGlobal, storeTime, storeStepLength,
91 storePreStepKineticEnergy, storeELPhysics);
93 storeGlobal, storeTime, storeStepLength,
94 storePreStepKineticEnergy, storeELPhysics);
110#ifndef __ROOTDOUBLE__
118BDSOutputStructures::~BDSOutputStructures()
125 delete primaryGlobal;
142 for (
auto sampler : samplerCTrees)
144 for (
auto sampler : samplerSTrees)
152 G4int nbins, G4double xmin, G4double xmax)
154 G4int result =
evtHistos->Create1DHistogram(name, title, nbins, xmin, xmax);
156 runHistos->Create1DHistogram(name, title, nbins, xmin, xmax);
161 std::vector<double>& edges)
163 G4int result =
evtHistos->Create1DHistogram(name,title,edges);
164 runHistos->Create1DHistogram(name,title,edges);
169 G4int nBinsX, G4double xMin, G4double xMax,
170 G4int nBinsY, G4double yMin, G4double yMax,
171 G4int nBinsZ, G4double zMin, G4double zMax)
173 G4int result =
evtHistos->Create3DHistogram(name, title,
178 runHistos->Create3DHistogram(name, title,
186 const G4String& title,
187 const G4String& eScale,
188 const std::vector<double>& eBinsEdges,
189 G4int nBinsX, G4double xMin, G4double xMax,
190 G4int nBinsY, G4double yMin, G4double yMax,
191 G4int nBinsZ, G4double zMin, G4double zMax,
192 G4int nBinsE, G4double eMin, G4double eMax)
194 G4int result =
evtHistos->Create4DHistogram(name, title, eScale, eBinsEdges,
200 runHistos->Create4DHistogram(name, title, eScale, eBinsEdges,
213 const auto sNames = samplerRegistry->GetUniqueNamesPlane();
214#ifdef USE_SIXTRACKLINK
228 for (
const auto& samplerName : sNames)
230#ifndef __ROOTDOUBLE__
238 const auto planeIDs = samplerRegistry->GetSamplerIDsPlane();
240 for (
const auto& ID : planeIDs)
241 {samplerIDToIndexPlane[ID] = i; i++;}
244 const auto scNames = samplerRegistry->GetUniqueNamesCylinder();
245 samplerCTrees.reserve(scNames.size());
246 for (
const auto& samplerName : scNames)
249 samplerCNames.emplace_back(samplerName);
251 const auto cylinderIDs = samplerRegistry->GetSamplerIDsCylinder();
253 for (
const auto& ID : cylinderIDs)
254 {samplerIDToIndexCylinder[ID] = i; i++;}
257 const auto ssNames = samplerRegistry->GetUniqueNamesSphere();
258 samplerSTrees.reserve(ssNames.size());
259 for (
const auto& samplerName : ssNames)
262 samplerSNames.emplace_back(samplerName);
264 const auto sphereIDs = samplerRegistry->GetSamplerIDsSphere();
266 for (
const auto& ID : sphereIDs)
267 {samplerIDToIndexSphere[ID] = i; i++;}
273 materialToID.clear();
274 materialIDToNameUnique.clear();
276 const auto materialTable = G4Material::GetMaterialTable();
293 std::map<std::pair<G4String, G4double>, G4Material*> sortingMap;
294 std::map<G4String, int> nameCount;
295 std::map<G4Material*, G4String> matToUniqueName;
297 for (
const auto& mat : *materialTable)
299 G4String matName = mat->GetName();
300 G4String matNameUnique = matName;
302 auto search = nameCount.find(matName);
303 if (search != nameCount.end())
306 matNameUnique = matName + std::to_string(search->second);
307 matToUniqueName[mat] = matNameUnique;
311 nameCount[matName] = 0;
312 matToUniqueName[mat] = matName;
314 sortingMap[std::make_pair(matNameUnique, mat->GetDensity())] = mat;
318 for (
const auto& kv : sortingMap)
320 materialToID[kv.second] = i;
321 materialIDToNameUnique[i] = matToUniqueName[kv.second];
334#ifndef __ROOTDOUBLE__
349 const G4String collimatorPrefix =
"COLL_";
371 G4double xDiff = info.xSizeOut - info.xSizeIn;
372 G4double yDiff = info.ySizeOut - info.ySizeIn;
379 const G4String cavityPrefix =
"CAV_";
447 for (
auto sampler : samplerCTrees)
449 for (
auto sampler : samplerSTrees)
452 {collimator->Flush();}
453 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.
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.