BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSDetectorConstruction.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 BDSDETECTORCONSTRUCTION_H
19#define BDSDETECTORCONSTRUCTION_H
20
21#include "BDSExtent.hh"
22#include "BDSExtentGlobal.hh"
23
24#include "globals.hh" // geant4 types / globals
25#include "G4Transform3D.hh"
26#include "G4Version.hh"
27#include "G4VUserDetectorConstruction.hh"
28
29#include <list>
30#include <map>
31#include <set>
32#include <string>
33#include <vector>
34
35class G4LogicalVolume;
36class G4Region;
37class G4VPhysicalVolume;
38
39namespace GMAD {
40 class BLMPlacement;
41 struct Element;
42 template<typename T> class FastList;
43 class Placement;
44 class Query;
45 class SamplerPlacement;
46 class ScorerMesh;
47}
48
50class BDSBeamline;
52class BDSBeamlineSet;
54class BDSFieldObjects;
57class BDSSamplerInfo;
58
59#if G4VERSION_NUMBER > 1009
61#endif
62
74class BDSDetectorConstruction: public G4VUserDetectorConstruction
75{
76public:
77 explicit BDSDetectorConstruction(BDSComponentFactoryUser* userComponentFactoryIn = nullptr);
79
83
86 virtual G4VPhysicalVolume* Construct();
87
89 virtual void ConstructSDandField();
90
94 void BuildPhysicsBias();
95
97 inline void SetDesignParticle(const BDSParticleDefinition* defIn) {designParticle = defIn;}
98
101
103 const std::vector<BDSFieldQueryInfo*>& FieldQueries() const {return fieldQueries;}
104
113 static void PlaceBeamlineInWorld(BDSBeamline* beamline,
114 G4VPhysicalVolume* containerPV,
115 G4bool checkOverlaps = false,
116 G4bool setRegions = false,
117 G4bool registerInfo = false,
118 G4bool useCLPlacementTransform = false,
119 G4bool useIncrementalCopyNumbers = false,
120 G4bool registerPlacementNamesForOutput = false);
121
126 static G4Transform3D CreatePlacementTransform(const GMAD::Placement& placement,
127 const BDSBeamline* beamLine,
128 G4double* S = nullptr,
129 BDSExtent* placementExtent = nullptr,
130 const G4String& objectTypeForErrorMsg = "placement");
131
132 // Create a scorermesh placement transform. Turns the scorermesh into a
134 static G4Transform3D CreatePlacementTransform(const GMAD::ScorerMesh& scorerMesh,
135 const BDSBeamline* beamLine,
136 G4double* S = nullptr);
137
140 static G4Transform3D CreatePlacementTransform(const GMAD::SamplerPlacement& samplerPlacement,
141 const BDSBeamline* beamLine,
142 G4double* S = nullptr);
143
145 static G4Transform3D CreatePlacementTransform(const GMAD::BLMPlacement& blmPlacement,
146 const BDSBeamline* beamLine,
147 G4double* S = nullptr,
148 BDSExtent* blmExtent = nullptr);
149
151 static G4Transform3D CreatePlacementTransform(const GMAD::Query& queryPlacement,
152 const BDSBeamline* beamLine,
153 G4double* S = nullptr);
154
156 static G4ThreeVector SideToLocalOffset(const GMAD::Placement& placement,
157 const BDSBeamline* beamLine,
158 const BDSExtent& placementExtent);
159
162 static BDSSamplerInfo* BuildSamplerInfo(const GMAD::Element* element);
163
166 G4bool BuildSamplerWorld() const {return nSamplers > 0;}
167
168 G4bool BuildPlacementFieldsWorld() const {return buildPlacementFieldsWorld;}
169
171 static std::vector<BDSFieldQueryInfo*> PrepareFieldQueries(const BDSBeamline* mainBeamline);
172
173private:
177
181
184
186 void InitialiseRegions();
187
189 void InitialiseApertures();
190
192 void BuildBeamlines();
193
198 const G4String& name,
199 const BDSBeamlineIntegral& startingIntegral,
200 BDSBeamlineIntegral*& integral,
201 const G4Transform3D& initialTransform = G4Transform3D(),
202 G4bool beamlineIsCircular = false,
203 G4bool isPlacementBeamline = false);
204
206 void BuildTunnel();
207
210 G4VPhysicalVolume* BuildWorld();
211
213 void ComponentPlacement(G4VPhysicalVolume* worldPV);
214
217 G4bool UnsuitableFirstElement(std::list<GMAD::Element>::const_iterator element);
218
221
225
228
232
233#if G4VERSION_NUMBER > 1009
235 BDSBOptrMultiParticleChangeCrossSection* BuildCrossSectionBias(const std::list<std::string>& biasList,
236 const std::list<std::string>& defaultBias,
237 const G4String& elementName);
238
241
243 void VerboseSensitivity() const;
245 void PrintSensitiveDetectorsOfLV(const G4LogicalVolume* lv, G4int currentDepth) const;
246
248 std::vector<BDSBOptrMultiParticleChangeCrossSection*> biasObjects;
249 std::map<G4String, BDSBOptrMultiParticleChangeCrossSection*> biasSetObjects;
250#endif
251
252#ifdef BDSDEBUG
253 bool debug = true;
254#else
255 bool debug = false;
256#endif
257
259 G4bool verbose;
262
265
267 std::vector<BDSFieldObjects*> fields;
268
269 G4bool circular;
275
276 BDSComponentFactoryUser* userComponentFactory;
277
278 G4int nSamplers;
279 G4bool buildPlacementFieldsWorld;
280
282 std::set<G4LogicalVolume*> worldContentsLogicalVolumes;
283 std::set<G4LogicalVolume*> worldVacuumLogicalVolumes;
284 G4LogicalVolume* worldLogicalVolume;
285
286 std::vector<BDSFieldQueryInfo*> fieldQueries;
287
288 // for developer checks only
289#ifdef BDSCHECKUSERLIMITS
290 void PrintUserLimitsSummary(const G4VPhysicalVolume* world) const;
291 void PrintUserLimitsPV(const G4VPhysicalVolume* aPV, G4double globalMinEK) const;
292#endif
293};
294
295#endif
296
A holder class for all representations of the accelerator model created in BDSIM.
A class that holds the current integrated quantities along a beam line.
Simple struct to return a beamline plus associated beam lines.
A vector of BDSBeamlineElement instances - a beamline.
Factory for user specified accelerator components.
Class that constructs a Geant4 model of an accelerator.
G4bool circular
Whether or not we're building a circular machine.
void SetDesignParticle(const BDSParticleDefinition *defIn)
Set the (initial) design particle definition.
BDSDetectorConstruction & operator=(const BDSDetectorConstruction &)=delete
assignment and copy constructor not implemented nor used
BDSBOptrMultiParticleChangeCrossSection * BuildCrossSectionBias(const std::list< std::string > &biasList, const std::list< std::string > &defaultBias, const G4String &elementName)
Function that creates physics biasing cross section.
void InitialiseRegions()
Create and set parameters for various G4Regions.
std::vector< BDSBOptrMultiParticleChangeCrossSection * > biasObjects
List of bias objects - for memory management.
BDSExtent CalculateExtentOfScorerMesh(const GMAD::ScorerMesh &sm) const
Calculate local extent of scorer mesh in 3D.
BDSAcceleratorModel * acceleratorModel
Accelerator model pointer.
static G4ThreeVector SideToLocalOffset(const GMAD::Placement &placement, const BDSBeamline *beamLine, const BDSExtent &placementExtent)
Attach component with extent2 to component with extent1 with placement.
G4bool verbose
Variable copied from global constants.
static std::vector< BDSFieldQueryInfo * > PrepareFieldQueries(const BDSBeamline *mainBeamline)
Prepare field queries from parser information.
void VerboseSensitivity() const
Print out the sensitivity of every single volume so far constructed in the world.
void InitialiseApertures()
Create all aperture definitions from parser and store in BDSAcceleratorModel.
void CountPlacementFields()
Count number of fields required for placements.
G4bool canSampleAngledFaces
Whether the integrator set permits sampling elements with angled faces.
BDSExtent worldExtent
Record of the world extent.
std::set< G4LogicalVolume * > worldContentsLogicalVolumes
Cache of possibly loaded logical volumes from a world geometry file - used for biasing.
static BDSSamplerInfo * BuildSamplerInfo(const GMAD::Element *element)
BDSExtent CalculateExtentOfSamplerPlacement(const GMAD::SamplerPlacement &sp) const
Calculate local extent of custom user sampler.
void ConstructScoringMeshes()
Construct scoring meshes.
BDSBeamlineSet BuildBeamline(const GMAD::FastList< GMAD::Element > &beamLine, const G4String &name, const BDSBeamlineIntegral &startingIntegral, BDSBeamlineIntegral *&integral, const G4Transform3D &initialTransform=G4Transform3D(), G4bool beamlineIsCircular=false, G4bool isPlacementBeamline=false)
BDSExtentGlobal CalculateExtentOfScorerMeshes(const BDSBeamline *bl) const
G4bool checkOverlaps
Variable copied from global constants.
G4int nSamplers
Count of number of samplers to be built.
void ComponentPlacement(G4VPhysicalVolume *worldPV)
Place beam line, tunnel beam line, end pieces and placements in world.
const std::vector< BDSFieldQueryInfo * > & FieldQueries() const
Access vector of query objects.
void BuildBeamlines()
Build the main beam line and then any other required beam lines.
const BDSParticleDefinition * designParticle
Particle definition all components are built w.r.t. Includes rigidity etc.
void BuildTunnel()
Build the tunnel around the already constructed flat beam line.
BDSExtent WorldExtent() const
Public access to the world extent.
virtual void ConstructSDandField()
Construct sensitive detectors and fields.
std::vector< BDSFieldObjects * > fields
All fields.
void PrintSensitiveDetectorsOfLV(const G4LogicalVolume *lv, G4int currentDepth) const
Recursive function to print out each sensitive detector name.
static void PlaceBeamlineInWorld(BDSBeamline *beamline, G4VPhysicalVolume *containerPV, G4bool checkOverlaps=false, G4bool setRegions=false, G4bool registerInfo=false, G4bool useCLPlacementTransform=false, G4bool useIncrementalCopyNumbers=false, G4bool registerPlacementNamesForOutput=false)
virtual G4VPhysicalVolume * Construct()
static G4Transform3D CreatePlacementTransform(const GMAD::Placement &placement, const BDSBeamline *beamLine, G4double *S=nullptr, BDSExtent *placementExtent=nullptr, const G4String &objectTypeForErrorMsg="placement")
G4bool UnsuitableFirstElement(std::list< GMAD::Element >::const_iterator element)
BDSExtentGlobal CalculateExtentOfSamplerPlacements(const BDSBeamline *beamLine) const
Holder for +- extents in 3 dimensions with a rotation and translation.
Holder for +- extents in 3 dimensions.
Definition BDSExtent.hh:38
A holder for all the Geant4 field related objects.
Holder class for all information required for a field query.
Wrapper for particle definition.
All info required to build a sampler but not place it.
blm for parser.
List with Efficient Lookup.
Definition fastlist.h:41
Placement class for parser.
Definition placement.h:40
Query structure class for parser.
Definition query.h:36
Sampler placement class for parser.
ScorerMesh class for parser.
Definition scorermesh.h:39
Parser namespace for GMAD language. Combination of Geant4 and MAD.
Element class.
Definition element.h:47