18 #include "TRestGeant4Track.h"
20 #include "TRestGeant4Event.h"
21 #include "TRestGeant4Metadata.h"
27 TRestGeant4Track::TRestGeant4Track() =
default;
29 TRestGeant4Track::~TRestGeant4Track() =
default;
31 Int_t TRestGeant4Track::GetProcessID(
const TString& processName)
const {
33 if (metadata !=
nullptr) {
35 if (processID != Int_t{}) {
40 cout <<
"WARNING : The process " << processName <<
" was not found" << endl;
44 TString TRestGeant4Track::GetProcessName(Int_t processID)
const {
46 if (metadata !=
nullptr) {
48 if (processName != TString{}) {
53 cout <<
"WARNING : The process " << processID <<
" was not found" << endl;
58 EColor TRestGeant4Track::GetParticleColor()
const {
61 if (GetParticleName() ==
"e-")
63 else if (GetParticleName() ==
"e+")
65 else if (GetParticleName() ==
"alpha")
67 else if (GetParticleName() ==
"mu-")
69 else if (GetParticleName() ==
"gamma")
72 cout <<
"TRestGeant4Track::GetParticleColor. Particle NOT found! Returning "
85 size_t numberOfHits = 0;
86 for (
unsigned int n = 0; n < fHits.GetNumberOfHits(); n++) {
87 if (volID != -1 && fHits.GetVolumeId(n) != volID) {
101 size_t numberOfHits = 0;
102 for (
unsigned int n = 0; n < fHits.GetNumberOfHits(); n++) {
103 if (volID != -1 && fHits.GetVolumeId(n) != volID) {
106 if (fHits.GetEnergy(n) <= 0) {
116 <<
" * TrackID: " << fTrackID <<
" - Particle: " << fParticleName <<
" - ParentID: " << fParentID
118 << (GetParentTrack() !=
nullptr
119 ? TString::Format(
" - Parent particle: %s", GetParentTrack()->GetParticleName().Data()).Data()
121 <<
" - Created by '" << fCreatorProcess
124 << ToEnergyString(fInitialKineticEnergy) <<
"" << endl;
126 cout <<
" Initial position " << VectorToString(fInitialPosition) <<
" mm at time "
127 << ToTimeString(fGlobalTimestamp) <<
" - Time length of " << ToTimeString(fTimeLength)
128 <<
" and spatial length of " << ToLengthString(fLength) << endl;
130 size_t nHits = GetNumberOfHits();
131 if (maxHits > 0 && maxHits < nHits) {
132 nHits = min(maxHits, nHits);
133 cout <<
"Printing only the first " << nHits <<
" hits of the track" << endl;
137 for (
unsigned int i = 0; i < nHits; i++) {
138 TString processName = GetProcessName(fHits.GetHitProcess(i));
139 if (processName.IsNull()) {
141 TString(std::to_string(fHits.GetHitProcess(i)));
144 TString volumeName =
"";
145 if (metadata !=
nullptr) {
148 if (volumeName.IsNull()) {
150 volumeName = TString(std::to_string(fHits.GetHitVolume(i)));
152 cout <<
" - Hit " << i <<
" - Energy: " << ToEnergyString(fHits.GetEnergy(i))
153 <<
" - Process: " << processName <<
" - Volume: " << volumeName
154 <<
" - Position: " << VectorToString(TVector3(fHits.GetX(i), fHits.GetY(i), fHits.GetZ(i)))
155 <<
" mm - Time: " << ToTimeString(fHits.GetTime(i))
156 <<
" - KE: " << ToEnergyString(fHits.GetKineticEnergy(i)) << endl;
160 Bool_t TRestGeant4Track::ContainsProcessInVolume(Int_t processID, Int_t volumeID)
const {
161 for (
unsigned int i = 0; i < GetNumberOfHits(); i++) {
162 if (fHits.GetHitProcess(i) != processID)
continue;
163 if (volumeID == -1 || fHits.GetVolumeId(i) == volumeID)
return true;
168 Bool_t TRestGeant4Track::ContainsProcessInVolume(
const TString& processName, Int_t volumeID)
const {
170 if (metadata ==
nullptr) {
174 for (
unsigned int i = 0; i < GetNumberOfHits(); i++) {
175 if (fHits.GetHitProcess(i) != processID)
continue;
176 if (volumeID == -1 || fHits.GetVolumeId(i) == volumeID)
return true;
182 if (GetEvent() ==
nullptr) {
185 return GetEvent()->GetGeant4Metadata();
189 if (fEvent ==
nullptr) {
192 return fEvent->GetTrackByID(GetParentID());
195 vector<const TRestGeant4Track*> TRestGeant4Track::GetSecondaryTracks()
const {
196 vector<const TRestGeant4Track*> secondaryTracks = {};
197 for (
const auto trackID : fSecondaryTrackIDs) {
199 if (track !=
nullptr) {
200 secondaryTracks.push_back(track);
203 return secondaryTracks;
206 TString TRestGeant4Track::GetInitialVolume()
const {
207 const auto metadata = GetGeant4Metadata();
208 if (metadata ==
nullptr) {
211 const auto& hits = GetHits();
212 return GetGeant4Metadata()->GetGeant4GeometryInfo().GetVolumeFromID(hits.GetVolumeId(0));
215 TString TRestGeant4Track::GetFinalVolume()
const {
216 const auto metadata = GetGeant4Metadata();
217 if (metadata ==
nullptr) {
220 const auto& hits = GetHits();
221 return GetGeant4Metadata()->GetGeant4GeometryInfo().GetVolumeFromID(
222 hits.GetVolumeId(hits.GetNumberOfHits() - 1));
225 Double_t TRestGeant4Track::GetEnergyInVolume(
const TString& volumeName,
bool children)
const {
226 const auto metadata = GetGeant4Metadata();
227 if (metadata ==
nullptr) {
234 return GetEnergyInVolume(volumeId);
238 vector<const TRestGeant4Track*> tracks = {
this};
239 while (!tracks.empty()) {
242 if (track ==
nullptr) {
245 energy += track->GetEnergyInVolume(volumeId);
246 for (
const TRestGeant4Track* secondaryTrack : track->GetSecondaryTracks()) {
247 tracks.push_back(secondaryTrack);
253 TString TRestGeant4Track::GetLastProcessName()
const {
254 const auto metadata = GetGeant4Metadata();
255 if (metadata ==
nullptr) {
259 const auto& hits = GetHits();
260 return GetGeant4Metadata()->GetGeant4PhysicsInfo().GetProcessName(
261 hits.GetProcess(hits.GetNumberOfHits() - 1));
void PrintTrack(size_t maxHits=0) const
Prints the track information. N number of hits to print, 0 = all.
size_t GetNumberOfHits(Int_t volID=-1) const
Function that returns the number of hit depositions found inside the TRestGeant4Track....
size_t GetNumberOfPhysicalHits(Int_t volID=-1) const
Function that returns the number of hit depositions found inside the TRestGeant4Track with energy > 0...