remage
Simulation framework for HPGe-based experiments
 
Loading...
Searching...
No Matches
RMGHardware.hh
1// Copyright (C) 2022 Luigi Pertoldi <https://orcid.org/0000-0002-0467-2571>
2//
3// This program is free software: you can redistribute it and/or modify it under
4// the terms of the GNU Lesser General Public License as published by the Free
5// Software Foundation, either version 3 of the License, or (at your option) any
6// later version.
7//
8// This program is distributed in the hope that it will be useful, but WITHOUT
9// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11// details.
12//
13// You should have received a copy of the GNU Lesser General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16#ifndef _RMG_HARDWARE_HH_
17#define _RMG_HARDWARE_HH_
18
19#include <map>
20#include <memory>
21#include <set>
22#include <string>
23#include <unordered_map>
24#include <vector>
25
26#include "G4GenericMessenger.hh"
27#include "G4Region.hh"
28#include "G4VUserDetectorConstruction.hh"
29
30#include "RMGDetectorMetadata.hh"
31#include "RMGHardwareMessenger.hh"
32#include "RMGLog.hh"
33#include "RMGNavigationTools.hh"
34#include "RMGVOutputScheme.hh"
35
37class G4LogicalVolume;
40
41 public:
42
45 ~RMGHardware() = default;
46
47 RMGHardware(RMGHardware const&) = delete;
48 RMGHardware& operator=(RMGHardware const&) = delete;
49 RMGHardware(RMGHardware&&) = delete;
50 RMGHardware& operator=(RMGHardware&&) = delete;
51
68 G4VPhysicalVolume* Construct() override;
69
75 void ConstructSDandField() override;
76
94 RMGDetectorType type,
95 const std::string& pv_name,
96 int uid,
97 int copy_nr = 0,
98 bool allow_uid_reuse = false,
99 const std::string& ntuple_name = ""
100 );
101
117 void StageDetector(
118 RMGDetectorType type,
119 const std::string& pv_name,
120 int uid,
121 const std::string& copy_nr = "0",
122 bool allow_uid_reuse = false,
123 const std::string& ntuple_name = ""
124 );
125
127 const auto& GetDetectorMetadataMap() { return fDetectorMetadata; }
128
133 const auto& GetDetectorMetadata(const std::pair<std::string, int>& det) {
134 return fDetectorMetadata.at(det);
135 }
136
137
138 const auto& GetActiveDetectorList() { return fActiveDetectors; }
139 [[nodiscard]] const auto& GetAllActiveOutputSchemes() { return fActiveOutputSchemes; }
140
145 void IncludeGDMLFile(std::string filename) { fGDMLFiles.emplace_back(filename); }
146
148 [[nodiscard]] const G4VPhysicalVolume* GetDefinedWorldVolume() const { return fWorld; }
149
152
161 void SetMaxStepLimit(double max_step, std::string name);
162
172 void SetEminLimitForParticle(double ekin_min, std::string name, std::string particle_name);
173
175 static bool IsEminLimitParticleSelected(
176 const G4LogicalVolume* logical,
177 const std::string& particle_name
178 );
179
180 void PrintListOfLogicalVolumes() { RMGNavigationTools::PrintListOfLogicalVolumes(); }
181 void PrintListOfPhysicalVolumes() { RMGNavigationTools::PrintListOfPhysicalVolumes(); }
182
183 protected:
184
186 virtual G4VPhysicalVolume* DefineGeometry() { return nullptr; }
187
188 private:
189
191 std::vector<std::string> fGDMLFiles;
192 bool fGDMLDisableOverlapCheck = false;
193 int fGDMLOverlapCheckNumPoints = 3000;
194 bool fGDMLDisableXmlCheck = false;
196 std::map<std::string, double> fPhysVolStepLimits;
197
198 struct RMGSelectiveEminLimit {
199 double ekin_min;
200 std::set<std::string> particles;
201 };
202 std::map<std::string, RMGSelectiveEminLimit> fPhysVolEminLimits;
203 static std::unordered_map<const G4LogicalVolume*, std::set<std::string>> fLogicalVolEminParticles;
204
205 // one element for each sensitive detector physical volume
206 std::map<std::pair<std::string, int>, RMGDetectorMetadata> fDetectorMetadata;
207
208 std::set<RMGDetectorType> fActiveDetectors;
209 static G4ThreadLocal std::vector<std::shared_ptr<RMGVOutputScheme>> fActiveOutputSchemes;
210 static G4ThreadLocal bool fActiveDetectorsInitialized;
211
212 std::set<RMGDetectorType> fRegisterDetectorsFromGDML;
213 void RegisterDetectorsFromGDML(std::string s);
214
215 std::unique_ptr<G4GenericMessenger> fMessenger;
216 std::unique_ptr<RMGHardwareMessenger> fHwMessenger;
217 void DefineCommands();
218
220 G4VPhysicalVolume* fWorld = nullptr;
221
225 G4Region* fSensitiveRegion = new G4Region("SensitiveRegion");
226
227 struct RMGStagedDetector {
228 RMGDetectorType type;
229 std::string name;
230 int uid;
231 std::string copy_nr;
232 bool allow_uid_reuse;
233 std::string ntuple_name;
234 };
235
236 // Holds detector info before initialization
237 std::map<std::pair<std::string, std::string>, RMGStagedDetector> fStagedDetectors;
238};
239
240#endif
241
242// vim: tabstop=2 shiftwidth=2 expandtab
virtual G4VPhysicalVolume * DefineGeometry()
Method to define geometry directly, the user must reimplement the base class method.
Definition RMGHardware.hh:186
void SetMaxStepLimit(double max_step, std::string name)
Set the maximum step size.
Definition RMGHardware.cc:543
static bool IsEminLimitParticleSelected(const G4LogicalVolume *logical, const std::string &particle_name)
Check if selective EkinMin should be applied for the current track context.
Definition RMGHardware.cc:582
void StageDetector(RMGDetectorType type, const std::string &pv_name, int uid, const std::string &copy_nr="0", bool allow_uid_reuse=false, const std::string &ntuple_name="")
Stage a detector for later registration.
Definition RMGHardware.cc:444
const auto & GetDetectorMetadataMap()
Extract a map of the detector metadata, one element for each sensitive detector physical volume and c...
Definition RMGHardware.hh:127
RMGHardware()
Constructor based on calling the macro commands (with DefineCommands ).
Definition RMGHardware.cc:60
void RegisterDetector(RMGDetectorType type, const std::string &pv_name, int uid, int copy_nr=0, bool allow_uid_reuse=false, const std::string &ntuple_name="")
Register a physical volume as sensitive detector.
Definition RMGHardware.cc:481
G4VPhysicalVolume * Construct() override
Construct the detector.
Definition RMGHardware.cc:62
G4VPhysicalVolume * GetDefinedWorldVolume()
Get the instance of the world volume, after Construct had been called once.
Definition RMGHardware.hh:151
void IncludeGDMLFile(std::string filename)
Add a GDML file to the geometry.
Definition RMGHardware.hh:145
const auto & GetDetectorMetadata(const std::pair< std::string, int > &det)
Extract the detector metadata for a given detector.
Definition RMGHardware.hh:133
const G4VPhysicalVolume * GetDefinedWorldVolume() const
Get the instance of the world volume, after Construct had been called once.
Definition RMGHardware.hh:148
void ConstructSDandField() override
Setup thread-local geometry data.
Definition RMGHardware.cc:316
void SetEminLimitForParticle(double ekin_min, std::string name, std::string particle_name)
Set a minimum kinetic energy cut for one selected particle in a volume.
Definition RMGHardware.cc:550