18#include "TRestGeant4Track.h"
20#include "TRestGeant4Event.h"
21#include "TRestGeant4Metadata.h"
27TRestGeant4Track::TRestGeant4Track() =
default;
29TRestGeant4Track::~TRestGeant4Track() =
default;
31Int_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;
44TString TRestGeant4Track::GetProcessName(Int_t processID)
const {
46 if (metadata !=
nullptr) {
48 if (processName != TString{}) {
53 cout <<
"WARNING : The process " << processID <<
" was not found" << endl;
58EColor 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 <<
"' in volume '" << GetInitialVolume()
122 <<
"' with initial KE of " << ToEnergyString(fInitialKineticEnergy) <<
" - Initial position "
123 << VectorToString(fInitialPosition) <<
" mm at time " << ToTimeString(fGlobalTimestamp)
124 <<
" - Time length of " << ToTimeString(fTimeLength) <<
" and spatial length of "
125 << ToLengthString(fLength) << endl;
127 cout <<
" Initial position " << VectorToString(fInitialPosition) <<
" mm at time "
128 << ToTimeString(fGlobalTimestamp) <<
" - Time length of " << ToTimeString(fTimeLength)
129 <<
" and spatial length of " << ToLengthString(fLength) << endl;
132 if (maxHits > 0 && maxHits < nHits) {
133 nHits = min(maxHits, nHits);
134 cout <<
"Printing only the first " << nHits <<
" hits of the track" << endl;
138 for (
unsigned int i = 0; i < nHits; i++) {
139 TString processName = GetProcessName(fHits.GetHitProcess(i));
140 if (processName.IsNull()) {
142 TString(std::to_string(fHits.GetHitProcess(i)));
145 TString volumeName =
"";
146 if (metadata !=
nullptr) {
149 if (volumeName.IsNull()) {
151 volumeName = TString(std::to_string(fHits.GetHitVolume(i)));
153 cout <<
" - Hit " << i <<
" - Energy: " << ToEnergyString(fHits.GetEnergy(i))
154 <<
" - Process: " << processName <<
" - Volume: " << volumeName
155 <<
" - Position: " << VectorToString(TVector3(fHits.GetX(i), fHits.GetY(i), fHits.GetZ(i)))
156 <<
" mm - Time: " << ToTimeString(fHits.GetTime(i))
157 <<
" - KE: " << ToEnergyString(fHits.GetKineticEnergy(i)) << endl;
161void TRestGeant4Track::PrintTrackFilterVolumes(
const std::set<std::string>& volumeNames)
const {
163 if (metadata ==
nullptr) {
170 if (volumeName.IsNull()) {
172 volumeName = TString(std::to_string(fHits.GetHitVolume(i)));
174 if (volumeNames.find(volumeName.Data()) != volumeNames.end()) {
185 <<
" * TrackID: " << fTrackID <<
" - Particle: " << fParticleName <<
" - ParentID: " << fParentID
187 << (GetParentTrack() !=
nullptr
188 ? TString::Format(
" - Parent particle: %s", GetParentTrack()->GetParticleName().Data()).Data()
190 <<
" - Created by '" << fCreatorProcess <<
"' in volume '" << GetInitialVolume()
191 <<
"' with initial KE of " << ToEnergyString(fInitialKineticEnergy) <<
" - Initial position "
192 << VectorToString(fInitialPosition) <<
" mm at time " << ToTimeString(fGlobalTimestamp)
193 <<
" - Time length of " << ToTimeString(fTimeLength) <<
" and spatial length of "
194 << ToLengthString(fLength) << endl;
197 for (
unsigned int i = 0; i < nHits; i++) {
198 TString processName = GetProcessName(fHits.GetHitProcess(i));
199 if (processName.IsNull()) {
201 TString(std::to_string(fHits.GetHitProcess(i)));
205 if (volumeName.IsNull()) {
207 volumeName = TString(std::to_string(fHits.GetHitVolume(i)));
209 if (volumeNames.find(volumeName.Data()) == volumeNames.end()) {
212 cout <<
" - Hit " << i <<
" - Energy: " << ToEnergyString(fHits.GetEnergy(i))
213 <<
" - Process: " << processName <<
" - Volume: " << volumeName
214 <<
" - Position: " << VectorToString(TVector3(fHits.GetX(i), fHits.GetY(i), fHits.GetZ(i)))
215 <<
" mm - Time: " << ToTimeString(fHits.GetTime(i))
216 <<
" - KE: " << ToEnergyString(fHits.GetKineticEnergy(i)) << endl;
220Bool_t TRestGeant4Track::ContainsProcessInVolume(Int_t processID, Int_t volumeID)
const {
222 if (fHits.GetHitProcess(i) != processID)
continue;
223 if (volumeID == -1 || fHits.GetVolumeId(i) == volumeID)
return true;
228Bool_t TRestGeant4Track::ContainsProcessInVolume(
const TString& processName, Int_t volumeID)
const {
230 if (metadata ==
nullptr) {
235 if (fHits.GetHitProcess(i) != processID)
continue;
236 if (volumeID == -1 || fHits.GetVolumeId(i) == volumeID)
return true;
242 if (GetEvent() ==
nullptr) {
245 return GetEvent()->GetGeant4Metadata();
249 if (fEvent ==
nullptr) {
252 return fEvent->GetTrackByID(GetParentID());
255vector<const TRestGeant4Track*> TRestGeant4Track::GetSecondaryTracks()
const {
256 vector<const TRestGeant4Track*> secondaryTracks = {};
257 for (
const auto trackID : fSecondaryTrackIDs) {
259 if (track !=
nullptr) {
260 secondaryTracks.push_back(track);
263 return secondaryTracks;
266TString TRestGeant4Track::GetInitialVolume()
const {
267 const auto metadata = GetGeant4Metadata();
268 if (metadata ==
nullptr) {
271 const auto& hits = GetHits();
275TString TRestGeant4Track::GetFinalVolume()
const {
276 const auto metadata = GetGeant4Metadata();
277 if (metadata ==
nullptr) {
280 const auto& hits = GetHits();
282 hits.GetVolumeId(hits.GetNumberOfHits() - 1));
285Double_t TRestGeant4Track::GetEnergyInVolume(
const TString& volumeName,
bool children)
const {
286 const auto metadata = GetGeant4Metadata();
287 if (metadata ==
nullptr) {
294 return GetEnergyInVolume(volumeId);
298 vector<const TRestGeant4Track*> tracks = {
this};
299 while (!tracks.empty()) {
302 if (track ==
nullptr) {
305 energy += track->GetEnergyInVolume(volumeId);
306 for (
const TRestGeant4Track* secondaryTrack : track->GetSecondaryTracks()) {
307 tracks.push_back(secondaryTrack);
313TString TRestGeant4Track::GetLastProcessName()
const {
314 const auto metadata = GetGeant4Metadata();
315 if (metadata ==
nullptr) {
319 const auto& hits = GetHits();
321 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...