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 offset " << ToTimeString(fTimeOffset)
129 <<
" - Time length of " << ToTimeString(fTimeLength) <<
" and spatial length of "
130 << ToLengthString(fLength) << endl;
133 if (maxHits > 0 && maxHits < nHits) {
134 nHits = min(maxHits, nHits);
135 cout <<
"Printing only the first " << nHits <<
" hits of the track" << endl;
139 for (
unsigned int i = 0; i < nHits; i++) {
140 TString processName = GetProcessName(fHits.GetHitProcess(i));
141 if (processName.IsNull()) {
143 TString(std::to_string(fHits.GetHitProcess(i)));
146 TString volumeName =
"";
147 if (metadata !=
nullptr) {
150 if (volumeName.IsNull()) {
152 volumeName = TString(std::to_string(fHits.GetHitVolume(i)));
154 cout <<
" - Hit " << i <<
" - Energy: " << ToEnergyString(fHits.GetEnergy(i))
155 <<
" - Process: " << processName <<
" - Volume: " << volumeName
156 <<
" - Position: " << VectorToString(TVector3(fHits.GetX(i), fHits.GetY(i), fHits.GetZ(i)))
157 <<
" mm - Time: " << ToTimeString(fHits.GetTime(i))
158 <<
" - KE: " << ToEnergyString(fHits.GetKineticEnergy(i)) << endl;
162void TRestGeant4Track::PrintTrackFilterVolumes(
const std::set<std::string>& volumeNames)
const {
164 if (metadata ==
nullptr) {
171 if (volumeName.IsNull()) {
173 volumeName = TString(std::to_string(fHits.GetHitVolume(i)));
175 if (volumeNames.find(volumeName.Data()) != volumeNames.end()) {
186 <<
" * TrackID: " << fTrackID <<
" - Particle: " << fParticleName <<
" - ParentID: " << fParentID
188 << (GetParentTrack() !=
nullptr
189 ? TString::Format(
" - Parent particle: %s", GetParentTrack()->GetParticleName().Data()).Data()
191 <<
" - Created by '" << fCreatorProcess <<
"' in volume '" << GetInitialVolume()
192 <<
"' with initial KE of " << ToEnergyString(fInitialKineticEnergy) <<
" - Initial position "
193 << VectorToString(fInitialPosition) <<
" mm at time " << ToTimeString(fGlobalTimestamp)
194 <<
" - Time length of " << ToTimeString(fTimeLength) <<
" and spatial length of "
195 << ToLengthString(fLength) << endl;
198 for (
unsigned int i = 0; i < nHits; i++) {
199 TString processName = GetProcessName(fHits.GetHitProcess(i));
200 if (processName.IsNull()) {
202 TString(std::to_string(fHits.GetHitProcess(i)));
206 if (volumeName.IsNull()) {
208 volumeName = TString(std::to_string(fHits.GetHitVolume(i)));
210 if (volumeNames.find(volumeName.Data()) == volumeNames.end()) {
213 cout <<
" - Hit " << i <<
" - Energy: " << ToEnergyString(fHits.GetEnergy(i))
214 <<
" - Process: " << processName <<
" - Volume: " << volumeName
215 <<
" - Position: " << VectorToString(TVector3(fHits.GetX(i), fHits.GetY(i), fHits.GetZ(i)))
216 <<
" mm - Time: " << ToTimeString(fHits.GetTime(i))
217 <<
" - KE: " << ToEnergyString(fHits.GetKineticEnergy(i)) << endl;
221Bool_t TRestGeant4Track::ContainsProcessInVolume(Int_t processID, Int_t volumeID)
const {
223 if (fHits.GetHitProcess(i) != processID)
continue;
224 if (volumeID == -1 || fHits.GetVolumeId(i) == volumeID)
return true;
229Bool_t TRestGeant4Track::ContainsProcessInVolume(
const TString& processName, Int_t volumeID)
const {
231 if (metadata ==
nullptr) {
236 if (fHits.GetHitProcess(i) != processID)
continue;
237 if (volumeID == -1 || fHits.GetVolumeId(i) == volumeID)
return true;
243 if (GetEvent() ==
nullptr) {
246 return GetEvent()->GetGeant4Metadata();
250 if (fEvent ==
nullptr) {
253 return fEvent->GetTrackByID(GetParentID());
256vector<const TRestGeant4Track*> TRestGeant4Track::GetSecondaryTracks()
const {
257 vector<const TRestGeant4Track*> secondaryTracks = {};
258 for (
const auto trackID : fSecondaryTrackIDs) {
260 if (track !=
nullptr) {
261 secondaryTracks.push_back(track);
264 return secondaryTracks;
267TString TRestGeant4Track::GetInitialVolume()
const {
268 const auto metadata = GetGeant4Metadata();
269 if (metadata ==
nullptr) {
272 const auto& hits = GetHits();
276TString TRestGeant4Track::GetFinalVolume()
const {
277 const auto metadata = GetGeant4Metadata();
278 if (metadata ==
nullptr) {
281 const auto& hits = GetHits();
283 hits.GetVolumeId(hits.GetNumberOfHits() - 1));
286Double_t TRestGeant4Track::GetEnergyInVolume(
const TString& volumeName,
bool children)
const {
287 const auto metadata = GetGeant4Metadata();
288 if (metadata ==
nullptr) {
295 return GetEnergyInVolume(volumeId);
299 vector<const TRestGeant4Track*> tracks = {
this};
300 while (!tracks.empty()) {
303 if (track ==
nullptr) {
306 energy += track->GetEnergyInVolume(volumeId);
307 for (
const TRestGeant4Track* secondaryTrack : track->GetSecondaryTracks()) {
308 tracks.push_back(secondaryTrack);
314TString TRestGeant4Track::GetLastProcessName()
const {
315 const auto metadata = GetGeant4Metadata();
316 if (metadata ==
nullptr) {
320 const auto& hits = GetHits();
322 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...