Skip to content

Commit

Permalink
Merge pull request #54 from rest-for-physics/lobis-remove-process-har…
Browse files Browse the repository at this point in the history
…dcoding

Improve physics process store
  • Loading branch information
lobis authored Jul 6, 2022
2 parents 1ca45ad + 9b6ad04 commit 213a829
Show file tree
Hide file tree
Showing 13 changed files with 352 additions and 754 deletions.
234 changes: 8 additions & 226 deletions inc/TRestGeant4Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ class TRestGeant4Event : public TRestEvent {

void AddEnergyDepositToVolume(Int_t volID, Double_t eDep);

Bool_t PerProcessEnergyInitFlag = false;
std::map<std::string, Double_t> PerProcessEnergyInSensitive;

// TODO: review this method
void InitializePerProcessEnergyInSensitive();

protected:
#ifndef __CINT__

Expand Down Expand Up @@ -170,67 +164,6 @@ class TRestGeant4Event : public TRestEvent {
Int_t GetNumberOfTracksForParticle(const TString& parName) const;
Int_t GetEnergyDepositedByParticle(const TString& parName) const;

inline Double_t GetEnergyInSensitiveFromProcessPhoto() {
if (!PerProcessEnergyInitFlag) {
InitializePerProcessEnergyInSensitive();
}
return PerProcessEnergyInSensitive["photoelectric"];
}
inline Double_t GetEnergyInSensitiveFromProcessCompton() {
if (!PerProcessEnergyInitFlag) {
InitializePerProcessEnergyInSensitive();
}
return PerProcessEnergyInSensitive["compton"];
}
inline Double_t GetEnergyInSensitiveFromProcessEIoni() {
if (!PerProcessEnergyInitFlag) {
InitializePerProcessEnergyInSensitive();
}
return PerProcessEnergyInSensitive["electron_ionization"];
}
inline Double_t GetEnergyInSensitiveFromProcessIonIoni() {
if (!PerProcessEnergyInitFlag) {
InitializePerProcessEnergyInSensitive();
}
return PerProcessEnergyInSensitive["ion_ionization"];
}
inline Double_t GetEnergyInSensitiveFromProcessAlphaIoni() {
if (!PerProcessEnergyInitFlag) {
InitializePerProcessEnergyInSensitive();
}
return PerProcessEnergyInSensitive["alpha_ionization"];
}
inline Double_t GetEnergyInSensitiveFromProcessMsc() {
if (!PerProcessEnergyInitFlag) {
InitializePerProcessEnergyInSensitive();
}
return PerProcessEnergyInSensitive["msc"];
}
inline Double_t GetEnergyInSensitiveFromProcessHadronIoni() {
if (!PerProcessEnergyInitFlag) {
InitializePerProcessEnergyInSensitive();
}
return PerProcessEnergyInSensitive["hadronic_ionization"];
}
inline Double_t GetEnergyInSensitiveFromProcessProtonIoni() {
if (!PerProcessEnergyInitFlag) {
InitializePerProcessEnergyInSensitive();
}
return PerProcessEnergyInSensitive["proton_ionization"];
}
inline Double_t GetEnergyInSensitiveFromProcessHadronElastic() {
if (!PerProcessEnergyInitFlag) {
InitializePerProcessEnergyInSensitive();
}
return PerProcessEnergyInSensitive["hadronic_elastic"];
}
inline Double_t GetEnergyInSensitiveFromProcessNeutronElastic() {
if (!PerProcessEnergyInitFlag) {
InitializePerProcessEnergyInSensitive();
}
return PerProcessEnergyInSensitive["neutron_elastic"];
}

inline void SetPrimaryEventOrigin(const TVector3& pos) { fPrimaryEventOrigin = pos; }
inline void SetPrimaryEventDirection(const TVector3& dir) { fPrimaryEventDirection.push_back(dir); }
inline void SetPrimaryEventParticleName(const TString& pName) { fPrimaryParticleName.push_back(pName); }
Expand Down Expand Up @@ -264,167 +197,16 @@ class TRestGeant4Event : public TRestEvent {
void SetTrackSubEventID(Int_t n, Int_t id);
void AddTrack(TRestGeant4Track trk);

inline Bool_t isRadiactiveDecay() const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isRadiactiveDecay()) return true;
return false;
}

inline Bool_t isPhotoElectric() const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isPhotoElectric()) return true;
return false;
}
inline Bool_t isCompton() const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isCompton()) return true;
return false;
}
inline Bool_t isBremstralung() const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isBremstralung()) return true;
return false;
}

inline Bool_t ishadElastic() const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).ishadElastic()) return true;
return false;
}
inline Bool_t isneutronInelastic() const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isneutronInelastic()) return true;
return false;
}

inline Bool_t isnCapture() const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isnCapture()) return true;
return false;
}

inline Bool_t ishIoni() const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).ishIoni()) return true;
return false;
}

inline Bool_t isphotonNuclear() const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isphotonNuclear()) return true;
return false;
}

inline Bool_t isAlpha() const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).GetParticleName() == "alpha") return true;
return false;
}

inline Bool_t isNeutron() const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).GetParticleName() == "neutron") return true;
return false;
}

inline Bool_t isArgon() const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if ((GetTrack(n).GetParticleName()).Contains("Ar")) return true;
return false;
}

inline Bool_t isXenon() const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if ((GetTrack(n).GetParticleName()).Contains("Xe")) return true;
return false;
}

inline Bool_t isNeon() const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if ((GetTrack(n).GetParticleName()).Contains("Ne")) return true;
return false;
}
/// Processes and particles in a given volume

inline Bool_t isRadiactiveDecayInVolume(Int_t volID) const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isRadiactiveDecayInVolume(volID)) return true;
return false;
}

inline Bool_t isPhotoElectricInVolume(Int_t volID) const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isPhotoElectricInVolume(volID)) return true;
return false;
}
inline Bool_t isPhotonNuclearInVolume(Int_t volID) const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isPhotonNuclearInVolume(volID)) return true;
return false;
}
inline Bool_t isComptonInVolume(Int_t volID) const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isComptonInVolume(volID)) return true;
return false;
}
inline Bool_t isBremstralungInVolume(Int_t volID) const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isBremstralungInVolume(volID)) return true;
return false;
}
Bool_t ContainsProcessInVolume(Int_t processID, Int_t volumeID = -1) const;
inline Bool_t ContainsProcess(Int_t processID) const { return ContainsProcessInVolume(processID, -1); }

inline Bool_t isHadElasticInVolume(Int_t volID) const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isHadElasticInVolume(volID)) return true;
return false;
}
inline Bool_t isNeutronInelasticInVolume(Int_t volID) const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isNeutronInelasticInVolume(volID)) return true;
return false;
Bool_t ContainsProcessInVolume(const TString& processName, Int_t volumeID = -1) const;
inline Bool_t ContainsProcess(const TString& processName) const {
return ContainsProcessInVolume(processName, -1);
}

inline Bool_t isNCaptureInVolume(Int_t volID) const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isNCaptureInVolume(volID)) return true;
return false;
}

inline Bool_t ishIoniInVolume(Int_t volID) const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isHIoniInVolume(volID)) return true;
return false;
}

inline Bool_t isAlphaInVolume(Int_t volID) const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isAlphaInVolume(volID)) return true;
return false;
}

inline Bool_t isNeutronInVolume(Int_t volID) const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isNeutronInVolume(volID)) return true;
return false;
}

inline Bool_t isArgonInVolume(Int_t volID) const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isArgonInVolume(volID)) return true;
return false;
}

inline Bool_t isXenonInVolume(Int_t volID) const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isXenonInVolume(volID)) return true;
return false;
}

inline Bool_t isNeonInVolume(Int_t volID) const {
for (int n = 0; n < GetNumberOfTracks(); n++)
if (GetTrack(n).isNeonInVolume(volID)) return true;
return false;
}
Bool_t ContainsParticle(const TString& particleName) const;
Bool_t ContainsParticleInVolume(const TString& particleName, Int_t volumeID = -1) const;

void Initialize();

Expand All @@ -444,6 +226,6 @@ class TRestGeant4Event : public TRestEvent {
// Destructor
virtual ~TRestGeant4Event();

ClassDef(TRestGeant4Event, 6); // REST event superclass
ClassDef(TRestGeant4Event, 7); // REST event superclass
};
#endif
15 changes: 10 additions & 5 deletions inc/TRestGeant4GeometryInfo.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//
// Created by lobis on 3/5/2022.
//

#ifndef REST_TRESTGEANT4GEOMETRYINFO_H
#define REST_TRESTGEANT4GEOMETRYINFO_H
Expand All @@ -15,11 +12,14 @@
class G4VPhysicalVolume;

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

private:
bool fIsAssembly = false;

std::map<Int_t, TString> fVolumeNameMap = {};
std::map<TString, Int_t> fVolumeNameReverseMap = {};

public:
// Insertion order is important for GDML containers. These containers are filled from GDML only not Geant4
std::vector<TString> fGdmlNewPhysicalNames;
Expand All @@ -44,7 +44,7 @@ class TRestGeant4GeometryInfo {
TString GetAlternativeNameFromGeant4PhysicalName(const TString&) const;
TString GetGeant4PhysicalNameFromAlternativeName(const TString&) const;

Int_t GetIDFromVolumeName(const TString&) const;
// Int_t GetIDFromVolumeName(const TString&) const;

void PopulateFromGeant4World(const G4VPhysicalVolume*);

Expand Down Expand Up @@ -79,6 +79,11 @@ class TRestGeant4GeometryInfo {

inline bool IsAssembly() const { return fIsAssembly; }

void InsertVolumeName(Int_t id, const TString& volumeName);

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

void Print() const;
};

Expand Down
10 changes: 6 additions & 4 deletions inc/TRestGeant4Hits.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ class TRestGeant4Hits : public TRestHits {
Int_t GetVolumeId(int n) const { return fVolumeID[n]; }
Double_t GetKineticEnergy(int n) const { return fKineticEnergy[n]; }

Double_t GetEnergyInVolume(Int_t volID) const;
Double_t GetEnergyInVolume(Int_t volumeID) const;

TVector3 GetMeanPositionInVolume(Int_t volID) const;
TVector3 GetFirstPositionInVolume(Int_t volID) const;
TVector3 GetLastPositionInVolume(Int_t volID) const;
TVector3 GetMeanPositionInVolume(Int_t volumeID) const;
TVector3 GetFirstPositionInVolume(Int_t volumeID) const;
TVector3 GetLastPositionInVolume(Int_t volumeID) const;

size_t GetNumberOfHitsInVolume(Int_t volumeID) const;

// Constructor
TRestGeant4Hits();
Expand Down
21 changes: 15 additions & 6 deletions inc/TRestGeant4Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "TRestGeant4BiasingVolume.h"
#include "TRestGeant4GeometryInfo.h"
#include "TRestGeant4ParticleSource.h"
#include "TRestGeant4PhysicsInfo.h"
//------------------------------------------------------------------------------------------------------------------------
//
// * This section was added by Luis A. Obis (lobis@unizar.es) on 17/06/2019
Expand Down Expand Up @@ -87,8 +88,6 @@ enum class angular_dist_types {
extern std::map<std::string, angular_dist_types> angular_dist_types_map;
} // namespace g4_metadata_parameters

//------------------------------------------------------------------------------------------------------------------------

/// The main class to store the *Geant4* simulation conditions that will be used by *restG4*.
class TRestGeant4Metadata : public TRestMetadata {
private:
Expand All @@ -105,6 +104,9 @@ class TRestGeant4Metadata : public TRestMetadata {
/// Class used to store and retrieve geometry info
TRestGeant4GeometryInfo fGeant4GeometryInfo;

/// Class used to store and retrieve physics info such as process names or particle names
TRestGeant4PhysicsInfo fGeant4PhysicsInfo;

/// The version of Geant4 used to generate the data
TString fGeant4Version;

Expand Down Expand Up @@ -182,7 +184,7 @@ class TRestGeant4Metadata : public TRestMetadata {
/// volume.
Double_t fMaxTargetStepSize = 0; //!

/// \brief A time gap, in us, determinning if an energy hit should be considered (and
/// \brief A time gap, in us, determining if an energy hit should be considered (and
/// stored) as an independent event.
Double_t fSubEventTimeDelay;

Expand Down Expand Up @@ -221,8 +223,11 @@ class TRestGeant4Metadata : public TRestMetadata {
/// geant4 dataset.
inline Long_t GetSeed() const { return fSeed; }

/// \brief Returns a reference to the geometry info
inline TRestGeant4GeometryInfo* GetGeant4GeometryInfo() { return &fGeant4GeometryInfo; }
/// \brief Returns an immutable reference to the geometry info
inline const TRestGeant4GeometryInfo& GetGeant4GeometryInfo() const { return fGeant4GeometryInfo; }

/// \brief Returns an immutable reference to the physics info
inline const TRestGeant4PhysicsInfo& GetGeant4PhysicsInfo() const { return fGeant4PhysicsInfo; }

/// \brief Returns a std::string with the version of Geant4 used on the event data
/// simulation
Expand Down Expand Up @@ -420,6 +425,10 @@ class TRestGeant4Metadata : public TRestMetadata {

~TRestGeant4Metadata();

ClassDefOverride(TRestGeant4Metadata, 9);
ClassDefOverride(TRestGeant4Metadata, 10);

// Allow modification of otherwise inaccessible / immutable members that shouldn't be modified by the user
friend class SteppingAction;
friend class DetectorConstruction;
};
#endif // RestCore_TRestGeant4Metadata
Loading

0 comments on commit 213a829

Please sign in to comment.