18#include "BDSAcceleratorModel.hh"
19#include "BDSBeamline.hh"
20#include "BDSBeamlineElement.hh"
21#include "BDSBLMRegistry.hh"
23#include "BDSEventInfo.hh"
24#include "BDSException.hh"
25#include "BDSGlobalConstants.hh"
26#include "BDSHistBinMapper.hh"
27#include "BDSHitApertureImpact.hh"
28#include "BDSHitCollimator.hh"
29#include "BDSHitEnergyDeposition.hh"
30#include "BDSHitEnergyDepositionGlobal.hh"
31#include "BDSHitSampler.hh"
32#include "BDSHitSamplerCylinder.hh"
33#include "BDSHitSamplerSphere.hh"
34#include "BDSHitSamplerLink.hh"
35#include "BDSOutput.hh"
36#include "BDSOutputROOTEventAperture.hh"
37#include "BDSOutputROOTEventBeam.hh"
38#include "BDSOutputROOTEventCollimator.hh"
39#include "BDSOutputROOTEventCavityInfo.hh"
40#include "BDSOutputROOTEventCollimatorInfo.hh"
41#include "BDSOutputROOTEventCoords.hh"
42#include "BDSOutputROOTEventLossWorld.hh"
43#include "BDSOutputROOTEventHeader.hh"
44#include "BDSOutputROOTEventHistograms.hh"
45#include "BDSOutputROOTEventInfo.hh"
46#include "BDSOutputROOTEventLoss.hh"
47#include "BDSOutputROOTEventModel.hh"
48#include "BDSOutputROOTEventOptions.hh"
49#include "BDSOutputROOTEventRunInfo.hh"
50#include "BDSOutputROOTEventSampler.hh"
51#include "BDSOutputROOTEventSamplerC.hh"
52#include "BDSOutputROOTEventSamplerS.hh"
53#include "BDSOutputROOTEventTrajectory.hh"
54#include "BDSOutputROOTParticleData.hh"
55#include "BDSParticleDefinition.hh"
56#include "BDSPrimaryVertexInformation.hh"
57#include "BDSPrimaryVertexInformationV.hh"
58#include "BDSScorerHistogramDef.hh"
59#include "BDSSDManager.hh"
60#include "BDSStackingAction.hh"
61#include "BDSTrajectoriesToStore.hh"
62#include "BDSTrajectoryPoint.hh"
63#include "BDSTrajectoryPointHit.hh"
64#include "BDSUtilities.hh"
67#include "G4ParticleDefinition.hh"
68#include "G4PrimaryParticle.hh"
69#include "G4PrimaryVertex.hh"
70#include "G4THitsMap.hh"
71#include "G4Version.hh"
76#include "parser/beamBase.h"
77#include "parser/optionsBase.h"
87#include "CLHEP/Units/SystemOfUnits.h"
90 "Event",
"Histos",
"Info",
"Primary",
"PrimaryGlobal",
91 "Eloss",
"ElossVacuum",
"ElossTunnel",
"ElossWorld",
"ElossWorldExit",
93 "PrimaryFirstHit",
"PrimaryLastHit",
"Trajectory",
"ApertureImpacts"
97 const G4String& fileExtensionIn,
98 G4int fileNumberOffset):
100 baseFileName(baseFileNameIn),
101 fileExtension(fileExtensionIn),
102 outputFileNumber(fileNumberOffset),
107 energyDepositedVacuum(0),
108 energyDepositedWorld(0),
109 energyDepositedWorldContents(0),
110 energyDepositedTunnel(0),
111 energyImpactingAperture(0),
112 energyImpactingApertureKinetic(0),
114 energyWorldExitKinetic(0),
115 nCollimatorsInteracted(0)
159 if (g->StoreSamplerAll())
238 &materialIDToNameUnique,
246 const G4int turnsTaken)
248 const G4VUserPrimaryVertexInformation* vertexInfo = vertex->GetUserInformation();
251 primary->Fill(vertexInfoBDS->primaryVertex.local,
252 vertexInfoBDS->momentum,
253 vertexInfoBDS->charge,
254 vertexInfoBDS->pdgID,
256 vertexInfoBDS->primaryVertex.beamlineIndex,
257 vertexInfoBDS->nElectrons,
259 vertexInfoBDS->rigidity);
260 primaryGlobal->
Fill(vertexInfoBDS->primaryVertex.global);
264 primary->Fill(vertexInfoBDSV, turnsTaken);
265 primaryGlobal->
Fill(vertexInfoBDSV);
267 auto nextLinkedVertex = vertex->GetNext();
268 if (nextLinkedVertex)
275 G4bool isIon = particle->
IsAnIon();
292 &isIon, &ionA, &ionZ);
293 primaryGlobal->
Fill(coords.global);
299 const G4PrimaryVertex* vertex,
300 const std::vector<BDSHitsCollectionSampler*>& samplerHitsPlane,
301 const std::vector<BDSHitsCollectionSamplerCylinder*>& samplerHitsCylinder,
302 const std::vector<BDSHitsCollectionSamplerSphere*>& samplerHitsSphere,
308 const BDSHitsCollectionEnergyDepositionGlobal* energyLossWorld,
309 const BDSHitsCollectionEnergyDepositionGlobal* energyLossWorldContents,
310 const BDSHitsCollectionEnergyDepositionGlobal* worldExitHits,
311 const std::vector<const BDSTrajectoryPointHit*>& primaryHits,
312 const std::vector<const BDSTrajectoryPointHit*>& primaryLosses,
314 const BDSHitsCollectionCollimator* collimatorHits,
315 const BDSHitsCollectionApertureImpacts* apertureImpactHits,
317 const G4int turnsTaken)
335 FillSamplerCylinderHitsVector(samplerHitsCylinder);
336 FillSamplerSphereHitsVector(samplerHitsSphere);
343 if (energyLossVacuum)
345 if (energyLossTunnel)
351 if (energyLossWorldContents)
352 {
FillEnergyLoss(energyLossWorldContents, BDSOutput::LossType::worldcontents);}
382 unsigned long long int nOriginalEventsIn,
383 unsigned long long int nEventsRequestedIn,
384 unsigned long long int nEventsInOriginalDistrFileIn,
385 unsigned long long int nEventsDistrFileSkippedIn,
386 unsigned int distrFileLoopNTimesIn)
388 FillRunInfoAndUpdateHeader(info, nOriginalEventsIn, nEventsRequestedIn, nEventsInOriginalDistrFileIn, nEventsDistrFileSkippedIn, distrFileLoopNTimesIn);
401 out <<
"Protected names for output " << G4endl;
403 {out <<
"\"" << key <<
"\"" << G4endl;}
421 if (!globalConstants->OutputFileNameSet() || !globalConstants->Batch())
423 G4String original = newFileName;
424 G4int nTimeAppended = 1;
427 newFileName = original +
"-" + std::to_string(nTimeAppended);
435 G4cout << __METHOD_NAME__ <<
"Setting up new file: " << newFileName << G4endl;
448 if (!flatBeamline->
empty())
469 const G4double smax = sMaxHistograms / CLHEP::m;
471 G4cout << __METHOD_NAME__ <<
"histogram parameters calculated to be: " << G4endl;
472 G4cout <<
"s minimum: " << smin <<
" m" << G4endl;
473 G4cout <<
"s maximum: " << smax <<
" m" << G4endl;
474 G4cout <<
"# of bins: " <<
nbins << G4endl;
485 std::vector<G4double> binedges;
495 "Primary Hits per Element",
498 "Primary Loss per Element",
504 "Energy Loss per Element" ,
510 "Energy Loss in Vacuum",
513 "Energy Loss in Vacuum per Element" ,
520 "Primary aperture impacts",
535 "Energy Loss in Tunnel",
538 "Energy Loss in Tunnel per Element",
544 std::vector<G4String> collHistNames = {
"CollPhitsPE",
547 "CollPInteractedPE"};
548 std::vector<G4String> collHistDesciptions = {
"Primary Hits per Coll",
549 "Primary Loss per Coll",
550 "Energy Loss per Collimator",
551 "Primary Interacted per Collimator"};
552 for (G4int i = 0; i < (G4int)collHistNames.size(); i++)
555 collHistDesciptions[i],
565 {
throw BDSException(__METHOD_NAME__,
"0 width in general 3D scoring histogram in x dimension - check options, xmin and xmax");}
567 {
throw BDSException(__METHOD_NAME__,
"0 width in general 3D scoring histogram in y dimension - check options, ymin and ymax");}
569 {
throw BDSException(__METHOD_NAME__,
"0 width in general 3D scoring histogram in z dimension - check options, zmin and zmax");}
570 if (g->NBinsX() <= 0)
571 {
throw BDSException(__METHOD_NAME__,
"invalid number of bins in x dimension of 3D scoring histogram - check option, nbinsx");}
572 if (g->NBinsY() <= 0)
573 {
throw BDSException(__METHOD_NAME__,
"invalid number of bins in y dimension of 3D scoring histogram - check option, nbinsx");}
574 if (g->NBinsZ() <= 0)
575 {
throw BDSException(__METHOD_NAME__,
"invalid number of bins in z dimension of 3D scoring histogram - check option, nbinsx");}
578 g->NBinsX(), g->XMin()/CLHEP::m, g->XMax()/CLHEP::m,
579 g->NBinsY(), g->YMin()/CLHEP::m, g->YMax()/CLHEP::m,
580 g->NBinsZ(), g->ZMin()/CLHEP::m, g->ZMax()/CLHEP::m);
586 if (!scorerHistogramDefs.empty())
588 for (
const auto& nameDef : scorerHistogramDefs)
590 const auto def = nameDef.second;
596 if (def.geometryType ==
"box")
599 def.nBinsX, def.xLow/CLHEP::m, def.xHigh/CLHEP::m,
600 def.nBinsY, def.yLow/CLHEP::m, def.yHigh/CLHEP::m,
601 def.nBinsZ, def.zLow/CLHEP::m, def.zHigh/CLHEP::m);
603 else if (def.geometryType ==
"cylindrical")
606 def.nBinsZ, def.zLow/CLHEP::m, def.zHigh/CLHEP::m,
607 def.nBinsPhi, 0, CLHEP::twopi,
608 def.nBinsR, def.rInner / CLHEP::m, def.rOuter / CLHEP::m);
612 histIndexToUnits3D[histID] = def.primitiveScorerUnitValue;
617 if (def.geometryType ==
"box")
619 histID =
Create4DHistogram(def.outputName+
"-"+def.eScale,def.outputName,def.eScale,def.eBinsEdges,
620 def.nBinsX, def.xLow/CLHEP::m, def.xHigh/CLHEP::m,
621 def.nBinsY, def.yLow/CLHEP::m, def.yHigh/CLHEP::m,
622 def.nBinsZ, def.zLow/CLHEP::m, def.zHigh/CLHEP::m,
623 def.nBinsE, def.eLow/CLHEP::GeV, def.eHigh/CLHEP::GeV);
625 else if (def.geometryType ==
"cylindrical")
627 histID =
Create4DHistogram(def.outputName+
"-"+def.eScale, def.outputName, def.eScale, def.eBinsEdges,
628 def.nBinsZ, def.zLow/CLHEP::m, def.zHigh/CLHEP::m,
629 def.nBinsPhi, 0, CLHEP::twopi,
630 def.nBinsR, def.rInner / CLHEP::m, def.rOuter / CLHEP::m,
631 def.nBinsE, def.eLow/CLHEP::GeV, def.eHigh/CLHEP::GeV);
635 histIndexToUnits4D[histID] = def.primitiveScorerUnitValue;
653 std::set<G4String> blmHistoNames;
654 std::map<G4String, G4String> psFullNameToPS;
655 for (
const auto& scorerNameComplete : psnamesc)
659 for (
const auto& scorerName : psnames)
663 blmHistoNames.insert(scorerName);
664 psFullNameToPS[scorerNameComplete] = scorerName;
672 for (
const auto &hn : blmHistoNames)
674 G4String blmHistName =
"BLM_" + hn;
678 for (
const auto& kv : psFullNameToPS)
700 G4double ek = BDSStackingAction::energyKilled / CLHEP::GeV;
715 for (
const auto& hc : hits)
719 if (!(hc->entries() > 0))
721 for (
int i = 0; i < (int) hc->entries(); i++)
724 G4int samplerID = hit->samplerID;
725 G4int samplerVectorIndex = samplerIDToIndexPlane[samplerID];
735 {sampler->FillIon();}
739void BDSOutput::FillSamplerCylinderHitsVector(
const std::vector<BDSHitsCollectionSamplerCylinder*>& hits)
741 for (
const auto& hc : hits)
745 if (!(hc->entries() > 0))
747 for (
int i = 0; i < (int) hc->entries(); i++)
750 G4int samplerID = hit->samplerID;
751 G4int samplerVectorIndex = samplerIDToIndexCylinder[samplerID];
760 for (
auto& sampler : samplerCTrees)
761 {sampler->FillIon();}
765void BDSOutput::FillSamplerSphereHitsVector(
const std::vector<BDSHitsCollectionSamplerSphere*>& hits)
767 for (
const auto& hc : hits)
771 if (!(hc->entries() > 0))
773 for (
int i = 0; i < (int) hc->entries(); i++)
776 G4int samplerID = hit->samplerID;
777 G4int samplerVectorIndex = samplerIDToIndexSphere[samplerID];
786 for (
auto& sampler : samplerSTrees)
787 {sampler->FillIon();}
794 if (!(hits->entries() > 0))
796 for (
int i = 0; i < (int)hits->entries(); i++)
799 G4int samplerID = hit->samplerID;
800 G4int samplerVectorIndex = samplerIDToIndexPlane[samplerID];
810 {sampler->FillIon();}
816 G4int nHits = (G4int)hits->entries();
819 for (G4int i = 0; i < nHits; i++)
822 auto samplerIndex = samplerIDToIndexPlane.find(hit->samplerID);
823 if (samplerIndex == samplerIDToIndexPlane.end())
824 {
throw BDSException(__METHOD_NAME__,
"Sampler ID not found: " + std::to_string(hit->samplerID));}
831 {sampler->FillIon();}
840 case BDSOutput::LossType::world:
841 case BDSOutput::LossType::worldexit:
842 case BDSOutput::LossType::worldcontents:
848 G4int nHits = (G4int)hits->entries();
853 case BDSOutput::LossType::world:
855 for (G4int i=0; i < nHits; i++)
864 case BDSOutput::LossType::worldexit:
866 for (G4int i = 0; i < nHits; i++)
876 case BDSOutput::LossType::worldcontents:
878 for (G4int i = 0; i < nHits; i++)
895 G4int nHits = (G4int)hits->entries();
900 case BDSOutput::LossType::energy:
904 for (G4int i = 0; i < nHits; i++)
907 G4double sHit = hit->GetSHit() / CLHEP::m;
908 G4double eW = hit->GetEnergyWeighted() / CLHEP::GeV;
914 runHistos->Fill1DHistogram(indELoss, sHit, eW);
915 evtHistos->Fill1DHistogram(indELoss, sHit, eW);
916 runHistos->Fill1DHistogram(indELossPE, sHit, eW);
917 evtHistos->Fill1DHistogram(indELossPE, sHit, eW);
922 case BDSOutput::LossType::vacuum:
926 for (G4int i = 0; i < nHits; i++)
929 G4double sHit = hit->GetSHit() / CLHEP::m;
930 G4double eW = hit->GetEnergyWeighted() / CLHEP::GeV;
936 evtHistos->Fill1DHistogram(indELossVacuum, sHit, eW);
937 runHistos->Fill1DHistogram(indELossVacuumPE, sHit, eW);
942 case BDSOutput::LossType::tunnel:
946 for (G4int i = 0; i < nHits; i++)
949 G4double sHit = hit->GetSHit() / CLHEP::m;
950 G4double eW = hit->GetEnergyWeighted() / CLHEP::GeV;
956 runHistos->Fill1DHistogram(indELossTunnel, sHit, eW);
957 evtHistos->Fill1DHistogram(indELossTunnel, sHit, eW);
958 runHistos->Fill1DHistogram(indELossTunnelPE, sHit, eW);
959 evtHistos->Fill1DHistogram(indELossTunnelPE, sHit, eW);
970 for (G4int i = 0; i < nHits; i++)
973 G4double sHit = hit->GetSHit() / CLHEP::m;
974 G4double eW = hit->GetEnergyWeighted() / CLHEP::GeV;
975 G4double x = hit->
Getx() / CLHEP::m;
976 G4double y = hit->
Gety() / CLHEP::m;
977 evtHistos->Fill3DHistogram(indScoringMap, x, y, sHit, eW);
978 runHistos->Fill3DHistogram(indScoringMap, x, y, sHit, eW);
984 (lossType == BDSOutput::LossType::energy) &&
991 for (
auto phit : primaryHits)
996 const G4double preStepSPosition = phit->point->GetPreS() / CLHEP::m;
1012 for (
auto ploss : primaryLosses)
1017 const G4double postStepSPosition = ploss->point->GetPostS() / CLHEP::m;
1038 const std::vector<const BDSTrajectoryPointHit*>& primaryLossPoints)
1040 G4int nHits = (G4int)hits->entries();
1041 for (G4int i = 0; i < nHits; i++)
1053 if (!primaryLossPoints.empty())
1055 for (
auto primaryLossPoint : primaryLossPoints)
1057 if (primaryLossPoint->point->GetBeamLine() &&
nCollimators > 0)
1059 G4int lossPointBLInd = primaryLossPoint->point->GetBeamLineIndex();
1084 for (G4int i = 0; i < (G4int)
collimators.size(); i++)
1091 if (collimator->primaryInteracted)
1101 G4int nPrimaryImpacts = 0;
1102 G4int nHits = (G4int)hits->entries();
1104 for (G4int i = 0; i < nHits; i++)
1107 G4double eW = (hit->totalEnergy / CLHEP::GeV) * hit->weight;
1110 if (hit->parentID == 0)
1112 nPrimaryImpacts += 1;
1115 {
evtHistos->Fill1DHistogram(histIndex, hit->S / CLHEP::m);}
1127 for (
const auto& nameHitsMap : scorerHitsMap)
1130 if (nameHitsMap.second->GetSize() == 0)
1132 if (nameHitsMap.second->size() == 0)
1135 {G4cout << nameHitsMap.first <<
" empty" << G4endl;
continue;}
1147 {
return FillScorerHitsIndividualBLM(histogramDefName, hitMap);}
1158 for (
const auto& hit : *hitMap->GetMap())
1160 for (
const auto& hit : *hitMap)
1164 mapper.IJKLFromGlobal(hit.first, x,y,z,e);
1165 G4int rootGlobalIndex = (hist->GetBin(x + 1, y + 1, z + 1));
1179 for (
const auto& hit : *hitMap->GetMap())
1181 for (
const auto& hit : *hitMap)
1185 mapper.IJKLFromGlobal(hit.first, x,y,z,e);
1186 evtHistos->Set4DHistogramBinContent(histIndex, x, y, z, e - 1, *hit.second / unit);
1192void BDSOutput::FillScorerHitsIndividualBLM(
const G4String& histogramDefName,
1197 for (
const auto& hit : *hitMap->GetMap())
1199 for (const auto& hit : *hitMap)
1203 G4cout <<
"Filling hist " << histIndex <<
", bin: " << hit.first+1 <<
" value: " << *hit.second << G4endl;
1206 evtHistos->Fill1DHistogram(histIndex,hit.first, *hit.second / unit);
1207 runHistos->Fill1DHistogram(histIndex,hit.first, *hit.second / unit);
1212 unsigned long long int nOriginalEventsIn,
1213 unsigned long long int nEventsRequestedIn,
1214 unsigned long long int nEventsInOriginalDistrFileIn,
1215 unsigned long long int nEventsDistrFileSkippedIn,
1216 unsigned int distrFileLoopNTimesIn)
1230 const G4String& destinationName,
1231 const std::vector<G4int>& indices)
1239 for (
const auto index : indices)
1241 destinationEvt->SetBinContent(binIndex, sourceEvt->GetBinContent(index + 1));
1242 destinationEvt->SetBinError(binIndex, sourceEvt->GetBinError(index + 1));
1243 destinationRun->SetBinContent(binIndex, sourceRun->GetBinContent(index + 1));
1244 destinationRun->SetBinError(binIndex, sourceRun->GetBinError(index + 1));
const std::map< G4String, BDSScorerHistogramDef > & ScorerHistogramDefinitionsMap() const
Access all scorer histogram definitions.
const std::map< G4String, G4Transform3D > & ScorerMeshPlacementsMap() const
Access all scorer histogram definitions.
BDSBeamline * TunnelBeamline() const
Access the beam line containing all the tunnel segments.
const BDSBeamline * BeamlineMain() const
Accessor.
static BDSBLMRegistry * Instance()
Accessor for registry.
G4double GetSPositionEnd() const
Accessor.
A vector of BDSBeamlineElement instances - a beamline.
std::vector< G4double > GetEdgeSPositions() const
const BDSBeamlineElement * GetLastItem() const
Return a reference to the last element.
G4bool empty() const
Iterator mechanics.
Interface to store event information use G4 hooks.
const BDSOutputROOTEventInfo * GetInfo() const
Accessor.
General exception with possible name of object and message.
A class that holds global options and constants.
static BDSGlobalConstants * Instance()
Access method.
BDS::TrajectoryOptions StoreTrajectoryOptions() const
options that require some implementation.
G4bool UseImportanceSampling() const
Is importance sampling being used.
Mapping from axis indices to 1D index.
Snapshot of information for particle passing through a collimator.
Snapshot of information for particle passing through a collimator.
G4int collimatorIndex
Index of collimator the hit is in.
Information recorded for a step leaving a volume.
Information recorded for a single piece of energy deposition.
G4double Getx() const
Accessor for extra piece of information.
G4double Gety() const
Accessor for extra piece of information.
The information recorded from a particle impacting a sampler.
The information recorded from a particle impacting a link sampler.
The information recorded from a particle impacting a sampler.
The information recorded from a particle impacting a sampler.
Class to store all beam options for a BDSIM run.
void Fill(const BDSOutputROOTEventCoords *other)
Fill from another instance.
void AccumulateHistogram3D(G4int histoId, TH3D *otherHistogram)
Add the values from one supplied 3D histogram to another. Uses TH3-Add().
BDSBH4DBase * Get4DHistogram(int iHisto) const
Accessors.
TH1D * Get1DHistogram(int iHisto) const
Accessors.
void Set3DHistogramBinContent(G4int histoId, G4int globalBinID, G4double value)
TH3D * Get3DHistogram(int iHisto) const
Accessors.
double energyKilled
Total energy of killed particles that weren't in a sensitive volume.
double energyWorldExitKinetic
Total kinetic energy leaving the world.
double energyWorldExit
Total energy leaving the world.
double energyDepositedWorldContents
Total energy deposited in the world contents for this event.
double energyImpactingApertureKinetic
Total kinetic energy impacting the aperture.
double energyDepositedWorld
Total energy deposited in the world for this event.
double energyDepositedTunnel
Total energy deposited in the tunnel for this event.
double energyDepositedVacuum
Total energy deposited in vacuum volumes.
int nCollimatorsInteracted
Number of collimators primary interacted with.
double energyTotal
Sum of above 5 variables that totals all energy.
double energyDeposited
Total energy deposited in machine (not world or tunnel).
double energyImpactingAperture
Total energy impacting the aperture.
void Fill(const BDSOutputROOTEventLoss *other)
Fill from another instance.
virtual void Fill(const std::vector< G4int > &collimatorIndicesIn={}, const std::map< G4String, G4int > &collimatorIndicesByNameIn={}, const std::vector< BDSOutputROOTEventCollimatorInfo > &collimatorInfoIn={}, const std::vector< G4String > &collimatorBranchNamesIn={}, const std::vector< G4int > &cavityIndicesIn={}, const std::map< G4String, G4int > &cavityIndicesByNameIn={}, const std::vector< BDSOutputROOTEventCavityInfo > &cavityInfoIn={}, const std::vector< G4String > &cavityBranchNamesIn={}, const std::map< G4String, G4Transform3D > *scorerMeshPlacements=nullptr, const std::map< short int, G4String > *materialIDToNameUnique=nullptr, G4bool storeTrajectory=false)
Fill root output.
Class to store all options for a BDSIM run.
Information pertaining to a run.
Information stored per sampler per event.
void Fill(G4bool fillIons)
Fill maps of particle information from Geant4.
virtual void Flush()
Clear maps.
Holder for output information.
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.
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.
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.
BDSOutputROOTEventHistograms * evtHistos
Event level histograms.
BDSOutputROOTEventLoss * eLossTunnel
Tunnel energy deposition.
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.
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.
virtual void WriteModel()=0
Write a representation of the samplers and beamline.
void FillEnergyLoss(const BDSHitsCollectionEnergyDeposition *loss, const LossType type)
Fill a collection of energy hits into the appropriate output structure.
G4double energyDepositedVacuum
Integral when filling hit.
virtual void WriteParticleData()=0
Write the geant4 information.
G4bool createCollimatorOutputStructures
virtual void WriteBeam()=0
Write the beam.
virtual void NewFile()=0
Open a new file. This should call WriteHeader() in it.
G4bool storeCollimatorHitsIons
Storage option.
G4bool storeSamplerCharge
Storage option.
G4bool storeSamplerRigidity
Storage option.
virtual void WriteFileEventLevel()=0
BDSOutput()=delete
No default constructor.
G4bool storePerEventHistos
Options for dynamic bits of output.
G4bool storeCollimatorHitsLinks
Storage option.
G4bool storeELossHistograms
Storage option.
G4bool storePrimaryHistograms
Storage option.
G4double energyDepositedTunnel
Integral when filling hit.
G4bool storeSamplerKineticEnergy
Storage option.
void CloseAndOpenNewFile()
Close a file and open a new one.
void FillEventInfo(const BDSEventInfo *info)
Fill event summary information.
virtual void WriteOptions()=0
Write the options.
G4bool storeCavityInfo
Storage option.
std::map< G4String, G4int > blmCollectionNameToHistogramID
std::map< G4int, G4double > histIndexToUnits1D
G4bool storePrimaries
Options for dynamic bits of output.
G4bool storeSamplerPolarCoords
Storage option.
void FillScorerHitsIndividual(const G4String &hsitogramDefName, const G4THitsMap< G4double > *hitMap)
Fill an individual scorer hits map into a particular output histogram.
const G4String baseFileName
Base file name.
void FillSamplerHitsVector(const std::vector< BDSHitsCollectionSampler * > &hits)
Fill sampler hits from a vector<sampler hits collection>.
G4bool storeTrajectory
Options for dynamic bits of output.
void FillSamplerHitsLink(const BDSHitsCollectionSamplerLink *hits)
Fill sampler link hits into output structures.
G4int nbins
Number of bins for each histogram required.
G4bool useScoringMap
Whether the single 3D histogram will be built.
void CopyFromHistToHist1D(const G4String &sourceName, const G4String &destinationName, const std::vector< G4int > &indices)
G4String GetNextFileName()
Get the next file name based on the base file name and the accrued number of files.
virtual void InitialiseGeometryDependent()
void FillPrimary(const G4PrimaryVertex *vertex, const G4int turnsTaken)
G4double energyDepositedWorldContents
Integral when filling hit.
const G4String fileExtension
File extension to add to each file.
G4bool storeSamplerIon
Storage option.
G4bool storeModel
Storage option.
void FillRun(const BDSEventInfo *info, unsigned long long int nOriginalEventsIn, unsigned long long int nEventsRequestedIn, unsigned long long int nEventsInOriginalDistrFileIn, unsigned long long int nEventsDistrFileSkippedIn, unsigned int distrFileLoopNTimesIn)
Copy run information to output structure.
G4double energyWorldExitKinetic
Integral when filling hit.
std::map< G4String, G4int > histIndices1D
Map of histogram name (short) to index of histogram in output.
void FillTrajectories(const BDSTrajectoriesToStore *trajectories)
Copy a set of trajectories to the output structure.
G4bool storeELoss
Options for dynamic bits of output.
void FillParticleData(G4bool writeIons)
Fill the local structure particle data with information. Also calls WriteParticleData().
G4bool storeParticleData
Storage option.
G4bool storeApertureImpactsHistograms
Options for dynamic bits of output.
G4double energyImpactingApertureKinetic
Integral when filling hit.
G4double energyImpactingAperture
Integral when filling hit.
void FillEventPrimaryOnly(const BDSParticleCoordsFullGlobal &coords, const BDSParticleDefinition *particle)
G4bool storeELossWorldContents
Options for dynamic bits of output.
G4bool storeCollimatorInfo
Storage option.
virtual void WriteFileRunLevel()=0
void FillBeam(const GMAD::BeamBase *beam)
virtual void WriteHeaderEndOfFile()=0
Overwrite and update header in the output.
void FillHeader()
Fill the local structure header with information - updates time stamp.
void FillPrimaryLoss(const std::vector< const BDSTrajectoryPointHit * > &primaryLosses)
Fill a collection volume exit hits into the appropriate output structure.
static void PrintProtectedNames(std::ostream &out)
Feedback for protected names.
std::map< G4String, G4int > histIndices4D
Map of histogram name (short) to index of histogram in output.
void FillPrimaryHit(const std::vector< const BDSTrajectoryPointHit * > &primaryHits)
Fill the hit where the primary particle impact.
void FillRunInfoAndUpdateHeader(const BDSEventInfo *info, unsigned long long int nOriginalEventsIn, unsigned long long int nEventsRequestedIn, unsigned long long int nEventsInOriginalDistrFileIn, unsigned long long int nEventsDistrFileSkippedIn, unsigned int distrFileLoopNTimesIn)
G4int outputFileNumber
Number of output file.
void FillApertureImpacts(const BDSHitsCollectionApertureImpacts *hits)
Fill aperture impact hits.
void FillSamplerHits(const BDSHitsCollectionSampler *hits)
Fill sampler hits into output structures.
G4bool storeELossWorld
Options for dynamic bits of output.
void FillEvent(const BDSEventInfo *info, const G4PrimaryVertex *vertex, const std::vector< BDSHitsCollectionSampler * > &samplerHitsPlane, const std::vector< BDSHitsCollectionSamplerCylinder * > &samplerHitsCylinder, const std::vector< BDSHitsCollectionSamplerSphere * > &samplerHitsSphere, const BDSHitsCollectionSamplerLink *samplerHitsLink, const BDSHitsCollectionEnergyDeposition *energyLoss, const BDSHitsCollectionEnergyDeposition *energyLossFull, const BDSHitsCollectionEnergyDeposition *energyLossVacuum, const BDSHitsCollectionEnergyDeposition *energyLossTunnel, const BDSHitsCollectionEnergyDepositionGlobal *energyLossWorld, const BDSHitsCollectionEnergyDepositionGlobal *energyLossWorldContents, const BDSHitsCollectionEnergyDepositionGlobal *worldExitHits, const std::vector< const BDSTrajectoryPointHit * > &primaryHits, const std::vector< const BDSTrajectoryPointHit * > &primaryLosses, const BDSTrajectoriesToStore *trajectories, const BDSHitsCollectionCollimator *collimatorHits, const BDSHitsCollectionApertureImpacts *apertureImpactHits, const std::map< G4String, G4THitsMap< G4double > * > &scorerHitsMap, const G4int turnsTaken)
Copy event information from Geant4 simulation structures to output structures.
void CreateHistograms()
Create histograms.
G4int storeTrajectoryStepPoints
Storage option.
G4bool storeTrajectoryStepPointLast
Storage option.
G4bool storeELossVacuum
Options for dynamic bits of output.
std::map< G4String, BDSHistBinMapper > scorerCoordinateMaps
Map of histogram name (short) to index of histogram in output.
G4bool storeSamplerMass
Storage option.
G4double energyWorldExit
Integral when filling hit.
G4int nCollimatorsInteracted
Integral when filling hit.
void FillOptions(const GMAD::OptionsBase *options)
G4bool storeELossVacuumHistograms
Storage option.
LossType
Enum for different types of energy loss that can be written out.
void CalculateHistogramParameters()
Calculate the number of bins and required maximum s.
G4bool storeELossTunnel
Options for dynamic bits of output.
G4double energyDeposited
Integral when filling hit.
static const std::set< G4String > protectedNames
Invalid names for samplers - kept here as this is where the output structures are created.
G4int numberEventPerFile
Number of events stored per file.
G4double energyDepositedWorld
Integral when filling hit.
G4bool storeCollimatorHits
Storage option.
void FillScorerHits(const std::map< G4String, G4THitsMap< G4double > * > &scorerHitsMap)
Fill a map of scorer hits into the output.
static G4bool InvalidSamplerName(const G4String &samplerName)
Test whether a sampler name is invalid or not.
void FillCollimatorHits(const BDSHitsCollectionCollimator *hits, const std::vector< const BDSTrajectoryPointHit * > &primaryLossPoints)
Fill collimator hits.
BDS::TrajectoryOptions storeTrajectoryOptions
Storage option.
std::map< G4String, G4int > histIndices3D
Map of histogram name (short) to index of histogram in output.
G4bool storeApertureImpacts
Options for dynamic bits of output.
virtual void CloseFile()=0
G4bool storeELossTunnelHistograms
Storage option.
virtual void WriteHeader()=0
Write the header.
A set of particle coordinates in both local and global.
Wrapper for particle definition.
G4double Mass() const
Accessor.
G4bool NElectrons() const
Accessor.
G4double Momentum() const
Accessor.
G4double Charge() const
Accessor.
G4double BRho() const
Accessor.
BDSIonDefinition * IonDefinition() const
Accessor.
G4bool IsAnIon() const
Accessor.
const std::map< G4String, G4double > & PrimitiveScorerUnits() const
Access the map of units for primitive scorers.
const std::vector< G4String > & PrimitiveScorerNames() const
Access a vector of the just primitive scorer part of the names.
const std::vector< G4String > & PrimitiveScorerNamesComplete() const
Access a vector the full primitive scorer names as registered.
Double map of trajectories to bitset of which filters matched whether to store them.
Options for a beam distribution.
Basic options class independent of Geant4.
G4bool StrContains(const G4String &str, const G4String &test)
Utility function to simplify lots of syntax changes for pedantic g4 changes.
V MapGetWithDefault(const std::map< K, V > &m, const K &key, const V &defaultValue)
G4bool FileExists(const G4String &filename)
Checks if filename exists.
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())