Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7642390
add necessary maps to retrieve assemblies and nested volumes informat…
AlvaroEzq Nov 18, 2025
91755b0
add TRestGeant4GeometryInfo::GetAlternativePathFromGeant4Path
AlvaroEzq Nov 18, 2025
17518e9
fix trailing whitespace
AlvaroEzq Nov 18, 2025
710fb1e
add and fix debugging messages
AlvaroEzq Nov 18, 2025
62a4516
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 18, 2025
6046e4a
add function myXml::GetChildByAttributeValue
AlvaroEzq Nov 24, 2025
70cd131
fix imprint parsing of nested assemblies
AlvaroEzq Nov 24, 2025
4f4ca90
add RML configuration parameter to set the TRestGeant4GeometryInfo::f…
AlvaroEzq Nov 24, 2025
182df27
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 24, 2025
71a4a96
fix std::function typo and indentation
AlvaroEzq Nov 24, 2025
3618222
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 24, 2025
e868d5b
add forgotten filling of fGeant4AssemblyImprintToAssemblyLogicalNameMap
AlvaroEzq Nov 24, 2025
d6f78a6
fix filling of fGeant4AssemblyImprintToAssemblyLogicalNameMap
AlvaroEzq Nov 28, 2025
5379b36
replace fGeant4PhysicalNameToNewPhysicalNameMap by its reverse fNewPh…
AlvaroEzq Nov 29, 2025
ccc508c
fix typo in name
AlvaroEzq Nov 29, 2025
e7406c6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 29, 2025
29a0a01
ensure the final sensitive volumes are valid gdml physical names
AlvaroEzq Dec 1, 2025
2b25009
add documentation and clarify PV validity methods
AlvaroEzq Dec 1, 2025
ef7a11a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions inc/TRestGeant4GeometryInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifndef REST_TRESTGEANT4GEOMETRYINFO_H
#define REST_TRESTGEANT4GEOMETRYINFO_H

#include <TRestStringOutput.h>
#include <TString.h>
#include <TVector3.h>

Expand All @@ -12,10 +13,11 @@
class G4VPhysicalVolume;

class TRestGeant4GeometryInfo {
ClassDef(TRestGeant4GeometryInfo, 3);
ClassDef(TRestGeant4GeometryInfo, 4);

private:
bool fIsAssembly = false;
TString fPathSeparator = "_";

std::map<Int_t, TString> fVolumeNameMap = {};
std::map<TString, Int_t> fVolumeNameReverseMap = {};
Expand All @@ -29,27 +31,50 @@ class TRestGeant4GeometryInfo {
}

public:
// Insertion order is important for GDML containers. These containers are filled from GDML only not Geant4
/// Physical volume names as in the GDML file
std::vector<TString> fGdmlNewPhysicalNames;

/// Logical volume names as in the GDML file
std::vector<TString> fGdmlLogicalNames;

/// Map from new physical volume names (unique) to Geant4 physical volume names (not always unique)
std::map<TString, TString>
fGeant4PhysicalNameToNewPhysicalNameMap; /*
* only makes sense when using assembly
*/
fNewPhysicalToGeant4PhysicalNameMap; // reverse map of old fGeant4PhysicalNameToNewPhysicalNameMap

/// Map of Geant4 prefix for the assembly imprint to the GDML physical volume name of that assembly
/// imprint. For example: {"av_1_impr_1" -> "micromegasRight" , "av_1_impr_2" -> "micromegasleft"}
std::map<TString, TString> fGeant4AssemblyImprintToGdmlNameMap;

/// Map of each assembly name to a map of Geant4 naming of the assembly daughters to their GDML physical
/// volume names. For example: {"micromegas_assembly" -> { "mMBaseLV_pv_0" -> "mMBase",
/// "mMBaseClosingBracketLV_pv_1" -> "mMBaseClosingBracket1"}}
std::map<TString, std::map<TString, TString>> fGdmlAssemblyToChildrenGeant4ToGdmlPhysicalNameMap;

/// Map of GDML physical volume name of an assembly to its assembly name.
/// For example: {"micromegasRight" -> "micromegas_assembly"}
std::map<TString, TString> fGeant4AssemblyImprintToAssemblyLogicalNameMap;

/// Map of GDML physical volume name to its logical volume name
std::map<TString, TString> fPhysicalToLogicalVolumeMap;
std::map<TString, std::vector<TString> > fLogicalToPhysicalMap;
// many physical volumes can point to one single logical

/// Map of logical volume name to their Geant4 physical volume names.
/// Note that many physical volumes can share the same logical volume.
std::map<TString, std::vector<TString>> fLogicalToPhysicalMap;

/// Map of logical volume name to its material name
std::map<TString, TString> fLogicalToMaterialMap;

/// Map of GDML physical volume name to its position in world coordinates
std::map<TString, TVector3> fPhysicalToPositionInWorldMap;

public:
inline TRestGeant4GeometryInfo() = default;

void PopulateFromGdml(const TString&);

TString GetAlternativePathFromGeant4Path(const TString&) const;
TString GetAlternativeNameFromGeant4PhysicalName(const TString&) const;
std::set<TString> GetAlternativeNamesFromGeant4PhysicalName(const TString&) const;
TString GetGeant4PhysicalNameFromAlternativeName(const TString&) const;

std::vector<TString> GetAllLogicalVolumes() const;
Expand All @@ -68,31 +93,43 @@ class TRestGeant4GeometryInfo {
return false;
}

inline bool IsValidPhysicalVolume(const TString& volume) const {
/// \brief Checks if a (Geant4) physical volume name exists in the geometry.
inline bool IsValidGeant4PhysicalVolume(const TString& volume) const {
return fPhysicalToLogicalVolumeMap.count(volume) > 0;
}

/// \brief Checks if a (GDML) physical volume name exists in the geometry.
inline bool IsValidPhysicalVolume(const TString& volume) const {
return fNewPhysicalToGeant4PhysicalNameMap.count(volume) > 0;
}

/// \brief Checks if a logical volume name exists in the geometry.
inline bool IsValidLogicalVolume(const TString& volume) const {
return fLogicalToPhysicalMap.count(volume) > 0;
}

/// \brief Gets all the (Geant4) physical volume names corresponding to a given logical volume name.
inline std::vector<TString> GetAllPhysicalVolumesFromLogical(const TString& logicalVolume) const {
if (IsValidLogicalVolume(logicalVolume)) {
return fLogicalToPhysicalMap.at(logicalVolume);
}
return {};
}

/// \brief Gets the position in world coordinates of a given physical volume.
inline TVector3 GetPosition(const TString& volume) const {
return fPhysicalToPositionInWorldMap.at(volume);
}

inline bool IsAssembly() const { return fIsAssembly; }

inline TString GetPathSeparator() const { return fPathSeparator; }
void SetPathSeparator(const TString& separator) { fPathSeparator = separator; }
void InsertVolumeName(Int_t id, const TString& volumeName);

TString GetVolumeFromID(Int_t id) const;
Int_t GetIDFromVolume(const TString& volumeName) const;

void Print() const;
void Print(bool multiLine = false) const;

friend class DetectorConstruction;
};
Expand Down
Loading