REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestGeant4Hits.cxx
1
17
18#include "TRestGeant4Hits.h"
19
20#include "TRestGeant4Event.h"
21#include "TRestGeant4Track.h"
22
23using namespace std;
24
25ClassImp(TRestGeant4Hits);
26
27TRestGeant4Hits::TRestGeant4Hits() : TRestHits() {}
28
29TRestGeant4Hits::~TRestGeant4Hits() = default;
30
31void TRestGeant4Hits::RemoveG4Hits() {
32 RemoveHits();
33
34 fProcessID.clear();
35 fVolumeID.clear();
36 fKineticEnergy.clear();
37}
38
39Double_t TRestGeant4Hits::GetEnergyInVolume(Int_t volumeID) const {
40 Double_t energy = 0;
41
42 for (size_t n = 0; n < fNHits; n++) {
43 if (fVolumeID[n] == volumeID) {
44 energy += GetEnergy(n);
45 }
46 }
47
48 return energy;
49}
50
51TVector3 TRestGeant4Hits::GetMeanPositionInVolume(Int_t volumeID) const {
52 TVector3 pos;
53 Double_t energy = 0;
54 for (size_t n = 0; n < fNHits; n++)
55 if (fVolumeID[n] == volumeID) {
56 pos += GetPosition(n) * GetEnergy(n);
57 energy += GetEnergy(n);
58 }
59
60 if (energy == 0) {
61 Double_t nan = TMath::QuietNaN();
62 return {nan, nan, nan};
63 }
64
65 pos = (1. / energy) * pos;
66 return pos;
67}
68
69TVector3 TRestGeant4Hits::GetFirstPositionInVolume(Int_t volumeID) const {
70 for (size_t n = 0; n < fNHits; n++)
71 if (fVolumeID[n] == volumeID) return GetPosition(n);
72
73 Double_t nan = TMath::QuietNaN();
74 return {nan, nan, nan};
75}
76
77TVector3 TRestGeant4Hits::GetLastPositionInVolume(Int_t volumeID) const {
78 for (int n = fNHits - 1; n >= 0; n--) {
79 if (fVolumeID[n] == volumeID) {
80 return GetPosition(n);
81 }
82 }
83 Double_t nan = TMath::QuietNaN();
84 return {nan, nan, nan};
85}
86
87size_t TRestGeant4Hits::GetNumberOfHitsInVolume(Int_t volumeID) const {
88 size_t result = 0;
89 for (size_t n = 0; n < fNHits; n++) {
90 if (fVolumeID[n] == volumeID) {
91 result++;
92 }
93 }
94 return result;
95}
96
97TRestGeant4Metadata* TRestGeant4Hits::GetGeant4Metadata() const {
98 const TRestGeant4Event* event;
99 if (fTrack != nullptr) {
100 event = fTrack->GetEvent();
101 } else {
102 event = fEvent;
103 }
104 if (event == nullptr) {
105 return nullptr;
106 }
107 return const_cast<TRestGeant4Metadata*>(event->GetGeant4Metadata());
108}
109
110TString TRestGeant4Hits::GetProcessName(size_t n) const {
111 const auto metadata = GetGeant4Metadata();
112 return metadata == nullptr ? "" : metadata->GetGeant4PhysicsInfo().GetProcessName(GetProcessId(n));
113}
114
115TString TRestGeant4Hits::GetVolumeName(size_t n) const {
116 const auto metadata = GetGeant4Metadata();
117 return metadata == nullptr ? "" : metadata->GetGeant4GeometryInfo().GetVolumeFromID(GetVolumeId(n));
118}
An event class to store geant4 generated event information.
The main class to store the Geant4 simulation conditions that will be used by restG4.
It saves a 3-coordinate position and an energy for each punctual deposition.
Definition: TRestHits.h:39
virtual void RemoveHits()
It removes all hits inside the class.
Definition: TRestHits.cxx:371
size_t fNHits
Number of punctual energy depositions, it is the length for all the arrays.
Definition: TRestHits.h:42
TVector3 GetPosition(int n) const
It returns the position of hit number n.
Definition: TRestHits.cxx:515