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
22using namespace std;
23
24ClassImp(TRestGeant4Hits);
25
26TRestGeant4Hits::TRestGeant4Hits() : TRestHits() {}
27
28TRestGeant4Hits::~TRestGeant4Hits() = default;
29
30void TRestGeant4Hits::RemoveG4Hits() {
31 RemoveHits();
32
33 fProcessID.clear();
34 fVolumeID.clear();
35 fKineticEnergy.clear();
36}
37
38Double_t TRestGeant4Hits::GetEnergyInVolume(Int_t volumeID) const {
39 Double_t energy = 0;
40
41 for (size_t n = 0; n < GetNumberOfHits(); n++) {
42 if (fVolumeID[n] == volumeID) {
43 energy += GetEnergy(n);
44 }
45 }
46
47 return energy;
48}
49
50TVector3 TRestGeant4Hits::GetMeanPositionInVolume(Int_t volumeID) const {
51 TVector3 pos;
52 Double_t energy = 0;
53 for (size_t n = 0; n < GetNumberOfHits(); n++)
54 if (fVolumeID[n] == volumeID) {
55 pos += GetPosition(n) * GetEnergy(n);
56 energy += GetEnergy(n);
57 }
58
59 if (energy == 0) {
60 Double_t nan = TMath::QuietNaN();
61 return {nan, nan, nan};
62 }
63
64 pos = (1. / energy) * pos;
65 return pos;
66}
67
68TVector3 TRestGeant4Hits::GetFirstPositionInVolume(Int_t volumeID) const {
69 for (size_t n = 0; n < GetNumberOfHits(); n++)
70 if (fVolumeID[n] == volumeID) return GetPosition(n);
71
72 Double_t nan = TMath::QuietNaN();
73 return {nan, nan, nan};
74}
75
76TVector3 TRestGeant4Hits::GetLastPositionInVolume(Int_t volumeID) const {
77 for (int n = GetNumberOfHits() - 1; n >= 0; n--) {
78 if (fVolumeID[n] == volumeID) {
79 return GetPosition(n);
80 }
81 }
82 Double_t nan = TMath::QuietNaN();
83 return {nan, nan, nan};
84}
85
86size_t TRestGeant4Hits::GetNumberOfHitsInVolume(Int_t volumeID) const {
87 size_t result = 0;
88 for (size_t n = 0; n < GetNumberOfHits(); n++) {
89 if (fVolumeID[n] == volumeID) {
90 result++;
91 }
92 }
93 return result;
94}
95
96TRestGeant4Metadata* TRestGeant4Hits::GetGeant4Metadata() const {
97 const TRestGeant4Event* event;
98 if (fTrack != nullptr) {
99 event = fTrack->GetEvent();
100 } else {
101 event = fEvent;
102 }
103 if (event == nullptr) {
104 return nullptr;
105 }
106 return const_cast<TRestGeant4Metadata*>(event->GetGeant4Metadata());
107}
108
109TString TRestGeant4Hits::GetProcessName(size_t n) const {
110 const auto metadata = GetGeant4Metadata();
111 return metadata == nullptr ? "" : metadata->GetGeant4PhysicsInfo().GetProcessName(GetProcessId(n));
112}
113
114TString TRestGeant4Hits::GetVolumeName(size_t n) const {
115 const auto metadata = GetGeant4Metadata();
116 return metadata == nullptr ? "" : metadata->GetGeant4GeometryInfo().GetVolumeFromID(GetVolumeId(n));
117}
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
TVector3 GetPosition(int n) const
It returns the position of hit number n.
Definition: TRestHits.cxx:515