REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestGeant4GeometryInfo.h
1
2#ifndef REST_TRESTGEANT4GEOMETRYINFO_H
3#define REST_TRESTGEANT4GEOMETRYINFO_H
4
5#include <TRestStringOutput.h>
6#include <TRotation.h>
7#include <TString.h>
8#include <TVector3.h>
9
10#include <map>
11#include <set>
12#include <vector>
13
14class G4VPhysicalVolume;
15
17 ClassDef(TRestGeant4GeometryInfo, 5);
18
19 private:
20 bool fIsAssembly = false;
21 TString fPathSeparator = "_";
22
23 std::map<Int_t, TString> fVolumeNameMap = {};
24 std::map<TString, Int_t> fVolumeNameReverseMap = {};
25
26 void PopulateFromGeant4World(const G4VPhysicalVolume*);
27
28 inline void InitializeOnDetectorConstruction(const TString& gdmlFilename,
29 const G4VPhysicalVolume* world) {
30 PopulateFromGdml(gdmlFilename);
31 PopulateFromGeant4World(world);
32 }
33
34 public:
36 std::vector<TString> fGdmlNewPhysicalNames;
37
39 std::vector<TString> fGdmlLogicalNames;
40
42 std::map<TString, TString>
43 fNewPhysicalToGeant4PhysicalNameMap; // reverse map of old fGeant4PhysicalNameToNewPhysicalNameMap
44
47 std::map<TString, TString> fGeant4AssemblyImprintToGdmlNameMap;
48
52 std::map<TString, std::map<TString, TString>> fGdmlAssemblyToChildrenGeant4ToGdmlPhysicalNameMap;
53
57
59 std::map<TString, TString> fPhysicalToLogicalVolumeMap;
60
63 std::map<TString, std::vector<TString>> fLogicalToPhysicalMap;
64
66 std::map<TString, TString> fLogicalToMaterialMap;
67
69 std::map<TString, TVector3> fPhysicalToPositionInWorldMap;
70
72 std::map<TString, TRotation> fPhysicalToRotationInWorldMap;
73
74 public:
75 inline TRestGeant4GeometryInfo() = default;
76
77 void PopulateFromGdml(const TString&);
78
79 TString GetAlternativePathFromGeant4Path(const TString&) const;
80 TString GetAlternativeNameFromGeant4PhysicalName(const TString&) const;
81 std::set<TString> GetAlternativeNamesFromGeant4PhysicalName(const TString&) const;
82 TString GetGeant4PhysicalNameFromAlternativeName(const TString&) const;
83
84 std::vector<TString> GetAllLogicalVolumes() const;
85 std::vector<TString> GetAllPhysicalVolumes() const;
86 std::vector<TString> GetAllAlternativePhysicalVolumes() const;
87
88 std::vector<TString> GetAllLogicalVolumesMatchingExpression(const TString&) const;
89 std::vector<TString> GetAllPhysicalVolumesMatchingExpression(const TString&) const;
90
91 inline bool IsValidGdmlName(const TString& volume) const {
92 for (const auto& name : fGdmlNewPhysicalNames) {
93 if (name == volume) {
94 return true;
95 }
96 }
97 return false;
98 }
99
101 inline bool IsValidGeant4PhysicalVolume(const TString& volume) const {
102 return fPhysicalToLogicalVolumeMap.count(volume) > 0;
103 }
104
106 inline bool IsValidPhysicalVolume(const TString& volume) const {
107 return fNewPhysicalToGeant4PhysicalNameMap.count(volume) > 0;
108 }
109
111 inline bool IsValidLogicalVolume(const TString& volume) const {
112 return fLogicalToPhysicalMap.count(volume) > 0;
113 }
114
116 inline std::vector<TString> GetAllPhysicalVolumesFromLogical(const TString& logicalVolume) const {
117 if (IsValidLogicalVolume(logicalVolume)) {
118 return fLogicalToPhysicalMap.at(logicalVolume);
119 }
120 return {};
121 }
122
124 inline TVector3 GetPosition(const TString& volume) const {
125 return fPhysicalToPositionInWorldMap.at(volume);
126 }
127
129 inline TRotation GetRotation(const TString& volume) const {
130 return fPhysicalToRotationInWorldMap.at(volume);
131 }
132
133 inline bool IsAssembly() const { return fIsAssembly; }
134 inline TString GetPathSeparator() const { return fPathSeparator; }
135 void SetPathSeparator(const TString& separator) { fPathSeparator = separator; }
136 void InsertVolumeName(Int_t id, const TString& volumeName);
137
138 TString GetVolumeFromID(Int_t id) const;
139 Int_t GetIDFromVolume(const TString& volumeName) const;
140
141 void Print(bool multiLine = false) const;
142
143 friend class DetectorConstruction;
144};
145
146#endif // REST_TRESTGEANT4GEOMETRYINFO_H
TRotation GetRotation(const TString &volume) const
Gets the rotation in world coordinates of a given physical volume.
std::set< TString > GetAlternativeNamesFromGeant4PhysicalName(const TString &) const
Gets all the alternative physical volume names from the GDML file naming that correspond to a given G...
std::map< TString, TString > fPhysicalToLogicalVolumeMap
Map of GDML physical volume name to its logical volume name.
bool IsValidPhysicalVolume(const TString &volume) const
Checks if a (GDML) physical volume name exists in the geometry.
TString GetAlternativePathFromGeant4Path(const TString &) const
Converts a Geant4 volume path to a GDML volume path. The path is the concatenation of the names of th...
bool IsValidGeant4PhysicalVolume(const TString &volume) const
Checks if a (Geant4) physical volume name exists in the geometry.
TVector3 GetPosition(const TString &volume) const
Gets the position in world coordinates of a given physical volume.
std::map< TString, std::vector< TString > > fLogicalToPhysicalMap
std::map< TString, TString > fGeant4AssemblyImprintToGdmlNameMap
std::vector< TString > GetAllPhysicalVolumes() const
Gets all the (GDML) physical volume names.
TString GetAlternativeNameFromGeant4PhysicalName(const TString &) const
Gets the alternative physical volume name from the GDML file naming. Note that if a logical volume wi...
std::vector< TString > GetAllAlternativePhysicalVolumes() const
Gets all the alternative (GDML) physical volume names.
std::map< TString, TString > fGeant4AssemblyImprintToAssemblyLogicalNameMap
std::vector< TString > fGdmlLogicalNames
Logical volume names as in the GDML file.
bool IsValidLogicalVolume(const TString &volume) const
Checks if a logical volume name exists in the geometry.
std::map< TString, TRotation > fPhysicalToRotationInWorldMap
Map of GDML physical volume name to its rotation in world coordinates.
std::vector< TString > GetAllPhysicalVolumesMatchingExpression(const TString &) const
Gets all the (GDML) physical volume names matching a given regular expression.
std::vector< TString > GetAllLogicalVolumes() const
Gets all the logical volume names.
std::vector< TString > GetAllLogicalVolumesMatchingExpression(const TString &) const
Gets all the logical volume names matching a given regular expression.
std::map< TString, std::map< TString, TString > > fGdmlAssemblyToChildrenGeant4ToGdmlPhysicalNameMap
std::vector< TString > fGdmlNewPhysicalNames
Physical volume names as in the GDML file.
std::map< TString, TString > fNewPhysicalToGeant4PhysicalNameMap
Map from new physical volume names (unique) to Geant4 physical volume names (not always unique)
std::map< TString, TVector3 > fPhysicalToPositionInWorldMap
Map of GDML physical volume name to its position in world coordinates.
std::vector< TString > GetAllPhysicalVolumesFromLogical(const TString &logicalVolume) const
Gets all the (Geant4) physical volume names corresponding to a given logical volume name.
std::map< TString, TString > fLogicalToMaterialMap
Map of logical volume name to its material name.