BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSSDManager.hh
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#ifndef BDSSDMANAGER_H
19#define BDSSDMANAGER_H
20
21#include "BDSSDSamplerLink.hh"
22#include "BDSSDType.hh"
23
24#include "G4String.hh"
25#include "G4Types.hh"
26#include "G4Version.hh"
27
28#include <map>
29#include <set>
30#include <vector>
31
33class BDSSDCollimator;
36class BDSLinkRegistry;
39class BDSSDSampler;
42class BDSSDTerminator;
43class BDSSDThinThing;
44class BDSSDVolumeExit;
45
46class G4VSDFilter;
47
48#if G4VERSION_NUMBER < 1030
49// In this case we use only the energy counter SD and return it
50// as a base class pointer. Include header so casting works.
51#include "BDSSDEnergyDeposition.hh"
52#include "BDSSDEnergyDepositionGlobal.hh"
53#endif
54
67{
68public:
69 static BDSSDManager* Instance();
70
71 BDSSDManager(const BDSSDManager&) = delete;
72 BDSSDManager& operator=(const BDSSDManager&) = delete;
74
81 G4VSensitiveDetector* SensitiveDetector(const BDSSDType sdType,
82 G4bool applyOptions = false) const;
83
85 inline BDSSDSampler* SamplerPlane() const {return samplerPlane;}
86
89
92
94 inline BDSSDSamplerLink* SamplerLink() const {return samplerLink;}
95
98 inline BDSSDTerminator* Terminator() const {return terminator;}
99
102
105
108
111
114
117
119 inline BDSSDVolumeExit* WorldExit() const {return worldExit;}
120
123
124#if G4VERSION_NUMBER > 1029
126 inline G4VSensitiveDetector* WorldComplete() const {return worldCompleteSD;}
127 inline G4VSensitiveDetector* ApertureComplete() const {return apertureCompleteSD;}
128#else
131 inline G4VSensitiveDetector* WorldComplete() const {return energyDepositionWorld;}
132 inline G4VSensitiveDetector* ApertureComplete() const {return energyDeposition;}
133#endif
134
136 inline BDSSDCollimator* Collimator() const {return collimatorSD;}
137
139 inline BDSMultiSensitiveDetectorOrdered* CollimatorComplete() const {return collimatorCompleteSD;}
140
143 inline BDSSDThinThing* ThinThing() const {return thinThingSD;}
144
146 inline BDSMultiSensitiveDetectorOrdered* WireComplete() const {return wireCompleteSD;}
147
150 void RegisterPrimitiveScorerName(const G4String& nameIn, G4double unit = 1.0);
151
153 void RegisterPrimitiveScorerNames(const std::vector<G4String>& namesIn,
154 const std::vector<G4double>* units = nullptr);
155
157 inline const std::vector<G4String>& PrimitiveScorerNamesComplete() const {return primitiveScorerNamesComplete;}
158
160 inline const std::vector<G4String>& PrimitiveScorerNames() const {return primitiveScorerNames;}
161
163 inline const std::map<G4String, G4double>& PrimitiveScorerUnits() const {return primitiveScorerNameToUnit;}
164
166 void SetLinkRegistry(BDSLinkRegistry* registry);
167 inline void SetLinkMinimumEK(G4double minimumEKIn) {samplerLink->SetMinimumEK(minimumEKIn);}
168 inline void SetLinkProtonsAndIonsOnly(G4bool protonsAndIonsOnlyIn) {samplerLink->SetProtonsAndIonsOnly(protonsAndIonsOnlyIn);}
169
173 void ConstructSamplerSDsForParticleSets(const std::map<int, std::set<int>>& samplerFilterIDtoPDGSetIn);
174
176 inline const std::vector<G4String>& ExtraSamplerWithFilterNamesComplete() const {return extraSamplerWithFilterNamesComplete;}
177
179 inline const std::vector<G4String>& ExtraSamplerCylinderWithFilterNamesComplete() const {return extraSamplerCylinderWithFilterNamesComplete;}
180
182 inline const std::vector<G4String>& ExtraSamplerSphereWithFilterNamesComplete() const {return extraSamplerSphereWithFilterNamesComplete;}
183
185 BDSSDSampler* SamplerPlaneWithFilter(G4int ID) const;
186
189
192
193private:
195 BDSSDManager();
196
197 static BDSSDManager* instance;
198
213#if G4VERSION_NUMBER > 1029
214 G4VSensitiveDetector* worldCompleteSD;
215 G4VSensitiveDetector* apertureCompleteSD;
216#endif
218 BDSSDCollimator* collimatorSD;
219 BDSMultiSensitiveDetectorOrdered* collimatorCompleteSD;
220 BDSSDThinThing* thinThingSD;
221 BDSMultiSensitiveDetectorOrdered* wireCompleteSD;
222
224 std::map<G4String, G4VSDFilter*> filters;
225
227 std::vector<G4String> primitiveScorerNamesComplete;
228
230 std::vector<G4String> primitiveScorerNames;
231
233 std::map<G4String, G4double> primitiveScorerNameToUnit;
234
235 std::map<G4int, BDSSDSampler*> extraSamplersWithFilters;
236 std::map<G4int, BDSSDSamplerCylinder*> extraSamplerCylindersWithFilters;
237 std::map<G4int, BDSSDSamplerSphere*> extraSamplerSpheresWithFilters;
238 std::map<G4int, BDSSDFilterPDGIDSet*> extraSamplerFilters;
239 std::vector<G4String> extraSamplerWithFilterNamesComplete;
240 std::vector<G4String> extraSamplerCylinderWithFilterNamesComplete;
241 std::vector<G4String> extraSamplerSphereWithFilterNamesComplete;
242
259};
260
261#endif
Registry / map of components for tracker linkage.
Modified G4MultiSensitiveDetector that retains order and passes hits in sequence.
Generates BDSHitsEnergyDepositions from step information - uses curvilinear coords.
The sensitive detector class that provides sensitivity to collimators instances.
Generates BDSHitsEnergyDepositionGlobal from step information.
Generates BDSHitsEnergyDepositions from step information - uses curvilinear coords.
Filter for a set of PDG IDs (ints).
A singleton class that holds all required sensitive detector class instances.
BDSSDEnergyDeposition * EnergyDeposition() const
SD for general energy deposition.
G4double collimatorHitsMinimumKE
Cache of global constant option.
const std::map< G4String, G4double > & PrimitiveScorerUnits() const
Access the map of units for primitive scorers.
BDSSDManager()
Private default constructor for singleton.
BDSSDSamplerSphere * samplerSphere
SD instance.
G4bool storeCollimatorHitsAll
Cache of global constant option.
std::map< G4String, G4VSDFilter * > filters
Map of all filters used. This class owns a single instance of each.
BDSSDVolumeExit * WorldExit() const
SD for world exit hits.
BDSSDTerminator * terminator
SD instance.
BDSSDSamplerCylinder * SamplerCylinderWithFilter(G4int ID) const
Access the relevant SD for a given particle filter set ID. It will return nullptr if the ID is invali...
G4bool generateCollimatorHits
Cache of global constant option.
BDSSDVolumeExit * worldExit
SD instance.
G4bool generateELossVacuumHits
Cache of global constant option.
BDSSDEnergyDepositionGlobal * energyDepositionWorldContents
SD instance.
void RegisterPrimitiveScorerName(const G4String &nameIn, G4double unit=1.0)
BDSSDApertureImpacts * apertureImpacts
SD instance.
void ConstructSamplerSDsForParticleSets(const std::map< int, std::set< int > > &samplerFilterIDtoPDGSetIn)
BDSMultiSensitiveDetectorOrdered * CollimatorComplete() const
SD for collimator impacts + energy deposition at the same time in order.
BDSSDEnergyDeposition * EnergyDepositionTunnel() const
SD for tunnel energy counter.
BDSSDTerminator * Terminator() const
const std::vector< G4String > & ExtraSamplerCylinderWithFilterNamesComplete() const
Access a vector of names of extra samplers so we can identify the hits collections.
const std::vector< G4String > & ExtraSamplerSphereWithFilterNamesComplete() const
Access a vector of names of extra samplers so we can identify the hits collections.
G4bool generateELossWorldContents
Cache of global constant option.
G4bool generateELossTunnelHits
Cache of global constant option.
const std::vector< G4String > & PrimitiveScorerNames() const
Access a vector of the just primitive scorer part of the names.
BDSSDEnergyDeposition * EnergyDepositionFull() const
SD for general energy deposition but always include extra half of information.
BDSSDSamplerLink * samplerLink
SD instance.
G4bool storeELossWorld
Cache of global constant option.
BDSSDSamplerSphere * SamplerSphereWithFilter(G4int ID) const
Access the relevant SD for a given particle filter set ID. It will return nullptr if the ID is invali...
BDSSDEnergyDeposition * energyDeposition
SD instance.
void RegisterPrimitiveScorerNames(const std::vector< G4String > &namesIn, const std::vector< G4double > *units=nullptr)
Loop over a vector and apply above single name function.
G4VSensitiveDetector * worldCompleteSD
SD instance.
G4bool storeApertureImpactsIons
Cache of global constant option.
G4VSensitiveDetector * apertureCompleteSD
SD instance.
BDSSDSamplerLink * SamplerLink() const
SD for link samplers.
BDSSDCollimator * Collimator() const
SD for collimator impact locations.
BDSSDThinThing * ThinThing() const
G4bool storeApertureImpactsAll
Cache of global constant option.
BDSSDApertureImpacts * ApertureImpacts() const
SD for aperture impact hits.
BDSSDEnergyDeposition * energyDepositionTunnel
SD instance.
BDSSDSampler * samplerPlane
SD instance.
G4bool generateELossHits
Cache of global constant option.
G4VSensitiveDetector * SensitiveDetector(const BDSSDType sdType, G4bool applyOptions=false) const
BDSSDSamplerCylinder * samplerCylinder
SD instance.
BDSSDSamplerCylinder * SamplerCylinder() const
SD for samplers (cylinder type).
const std::vector< G4String > & PrimitiveScorerNamesComplete() const
Access a vector the full primitive scorer names as registered.
BDSSDManager(const BDSSDManager &)=delete
Singleton accessor.
std::map< G4String, G4double > primitiveScorerNameToUnit
Map of primitive scorer names to units.
BDSSDSampler * SamplerPlane() const
SD for samplers (plane type). See also SamplerPlaneWithFilter below.
BDSSDSamplerSphere * SamplerSphere() const
SD for samplers (sphere type).
BDSSDSampler * SamplerPlaneWithFilter(G4int ID) const
Access the relevant SD for a given particle filter set ID. It will return nullptr if the ID is invali...
G4bool generateApertureImpacts
Cache of global constant option.
BDSMultiSensitiveDetectorOrdered * WireComplete() const
SD for wire scanner wires that is a composite of thin things + energy deposition full.
G4bool storeCollimatorHitsIons
Cache of global constant option.
G4VSensitiveDetector * WorldComplete() const
SD for multiple SDs for world - energy loss and exit.
BDSSDEnergyDepositionGlobal * EnergyDepositionWorldContents() const
SD for energy deposition in things that were already placed in the externally provided world.
BDSSDEnergyDeposition * energyDepositionFull
SD instance.
G4double apertureImpactsMinimumKE
Cache of global constant option.
BDSSDEnergyDepositionGlobal * EnergyDepositionWorld() const
SD for energy deposition in the world volume.
std::vector< G4String > primitiveScorerNamesComplete
Vector of complete (including mesh name) primitive scorer names.
G4bool storeELossExtras
Cache of global constant option.
std::vector< G4String > primitiveScorerNames
Just the primitive scorer part of the name.
void SetLinkRegistry(BDSLinkRegistry *registry)
If samplerLink member exists, set the registry to look up links for that SD.
BDSSDEnergyDeposition * EnergyDepositionVacuum() const
SD for energy deposition in vacuum volumes.
BDSSDEnergyDepositionGlobal * energyDepositionWorld
SD instance.
BDSSDEnergyDeposition * energyDepositionVacuum
SD instance.
const std::vector< G4String > & ExtraSamplerWithFilterNamesComplete() const
Access a vector of names of extra samplers so we can identify the hits collections.
The sensitive detector class that provides sensitivity to BDSSamplerCylinder instances.
The sensitive detector class that provides sensitivity to BDSSamplerSphere instances.
The sensitive detector class that provides sensitivity to BDSSampler instances.
Sensitivity that measures primary particle turns for terminator.
The sensitive detector class that provides sensitivity to record thin thing hits.
Generates BDSHitEnergyDepositionGlobals if a particle is leaving a volume.
Improve type-safety of native enum data type in C++.