Skip to content

Commit 763216a

Browse files
authored
Merge pull request #64 from rest-for-physics/lobis-hits-getters
Update TRestGeant4Hits getters to return directly process or volume names
2 parents 15ce030 + 20df018 commit 763216a

File tree

6 files changed

+50
-21
lines changed

6 files changed

+50
-21
lines changed

inc/TRestGeant4Event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class TRestGeant4Event : public TRestEvent {
210210
return lowestID;
211211
}
212212

213-
const std::set<std::string> GetUniqueParticles() const;
213+
std::set<std::string> GetUniqueParticles() const;
214214

215215
Bool_t ContainsProcessInVolume(Int_t processID, Int_t volumeID = -1) const;
216216
inline Bool_t ContainsProcess(Int_t processID) const { return ContainsProcessInVolume(processID, -1); }

inc/TRestGeant4Hits.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@ class TRestGeant4Hits : public TRestHits {
4949

5050
inline TVector3 GetMomentumDirection(size_t n) const { return fMomentumDirection[n]; }
5151

52-
inline Int_t GetProcess(size_t n) const { return fProcessID[n]; }
52+
inline Int_t GetProcessId(size_t n) const { return fProcessID[n]; }
53+
inline Int_t GetProcess(size_t n) const { return GetProcessId(n); }
54+
inline Int_t GetHitProcess(size_t n) const { return GetProcessId(n); }
55+
TString GetProcessName(size_t n) const;
56+
57+
inline Int_t GetVolumeId(size_t n) const { return fVolumeID[n]; }
58+
inline Int_t GetHitVolume(size_t n) const { return GetVolumeId(n); }
59+
TString GetVolumeName(size_t n) const;
5360

5461
void RemoveG4Hits();
5562

56-
inline Int_t GetHitProcess(size_t n) const { return fProcessID[n]; }
57-
inline Int_t GetHitVolume(size_t n) const { return fVolumeID[n]; }
58-
inline Int_t GetVolumeId(size_t n) const { return fVolumeID[n]; }
5963
inline Double_t GetKineticEnergy(size_t n) const { return fKineticEnergy[n]; }
6064

6165
Double_t GetEnergyInVolume(Int_t volumeID) const;

inc/TRestGeant4Metadata.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,14 @@ class TRestGeant4Metadata : public TRestMetadata {
337337
return fRemoveUnwantedTracksVolumesToKeep.count(volumeName) > 0;
338338
}
339339

340+
inline std::vector<std::string> GetRemoveUnwantedTracksVolumesToKeep() const {
341+
std::vector<std::string> result;
342+
for (const auto& volume : fRemoveUnwantedTracksVolumesToKeep) {
343+
result.emplace_back(volume);
344+
}
345+
return result;
346+
}
347+
340348
/// Returns a std::string with the name of the active volume with index n
341349
inline TString GetActiveVolumeName(Int_t n) const { return fActiveVolumes[n]; }
342350

@@ -364,7 +372,7 @@ class TRestGeant4Metadata : public TRestMetadata {
364372

365373
~TRestGeant4Metadata();
366374

367-
ClassDefOverride(TRestGeant4Metadata, 11);
375+
ClassDefOverride(TRestGeant4Metadata, 12);
368376

369377
// Allow modification of otherwise inaccessible / immutable members that shouldn't be modified by the user
370378
friend class SteppingAction;

inc/TRestGeant4Track.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class TRestGeant4Track {
133133
// Destructor
134134
virtual ~TRestGeant4Track();
135135

136+
friend class TRestGeant4Event; // allows TRestGeant4Event to access private members
137+
136138
ClassDef(TRestGeant4Track, 5); // REST event superclass
137139

138140
// restG4

src/TRestGeant4Event.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ void TRestGeant4Event::PrintEvent(int maxTracks, int maxHits) const {
11201120
cout << "- Total deposited energy: " << ToEnergyString(fTotalDepositedEnergy) << endl;
11211121
cout << "- Sensitive detectors total energy: " << ToEnergyString(fSensitiveVolumeEnergy) << endl;
11221122

1123-
cout << "- Primary source position: " << VectorToString(fPrimaryPosition) << "{} mm" << endl;
1123+
cout << "- Primary source position: " << VectorToString(fPrimaryPosition) << " mm" << endl;
11241124

11251125
for (int i = 0; i < GetNumberOfPrimaries(); i++) {
11261126
const char* sourceNumberString =
@@ -1202,10 +1202,12 @@ void TRestGeant4Event::InitializeReferences(TRestRun* run) {
12021202
*/
12031203
for (auto& track : fTracks) {
12041204
track.SetEvent(this);
1205+
track.fHits.SetTrack(&track);
1206+
track.fHits.SetEvent(this);
12051207
}
12061208
}
12071209

1208-
const set<string> TRestGeant4Event::GetUniqueParticles() const {
1210+
set<string> TRestGeant4Event::GetUniqueParticles() const {
12091211
set<string> result;
12101212
for (const auto& track : fTracks) {
12111213
result.insert(track.GetParticleName().Data());

src/TRestGeant4Hits.cxx

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ClassImp(TRestGeant4Hits);
2626

2727
TRestGeant4Hits::TRestGeant4Hits() : TRestHits() {}
2828

29-
TRestGeant4Hits::~TRestGeant4Hits() {}
29+
TRestGeant4Hits::~TRestGeant4Hits() = default;
3030

3131
void TRestGeant4Hits::RemoveG4Hits() {
3232
RemoveHits();
@@ -37,30 +37,32 @@ void TRestGeant4Hits::RemoveG4Hits() {
3737
}
3838

3939
Double_t TRestGeant4Hits::GetEnergyInVolume(Int_t volumeID) const {
40-
Double_t en = 0;
40+
Double_t energy = 0;
4141

4242
for (int n = 0; n < fNHits; n++) {
43-
if (fVolumeID[n] == volumeID) en += GetEnergy(n);
43+
if (fVolumeID[n] == volumeID) {
44+
energy += GetEnergy(n);
45+
}
4446
}
4547

46-
return en;
48+
return energy;
4749
}
4850

4951
TVector3 TRestGeant4Hits::GetMeanPositionInVolume(Int_t volumeID) const {
5052
TVector3 pos;
51-
Double_t en = 0;
53+
Double_t energy = 0;
5254
for (int n = 0; n < fNHits; n++)
5355
if (fVolumeID[n] == volumeID) {
5456
pos += GetPosition(n) * GetEnergy(n);
55-
en += GetEnergy(n);
57+
energy += GetEnergy(n);
5658
}
5759

58-
if (en == 0) {
60+
if (energy == 0) {
5961
Double_t nan = TMath::QuietNaN();
6062
return {nan, nan, nan};
6163
}
6264

63-
pos = (1. / en) * pos;
65+
pos = (1. / energy) * pos;
6466
return pos;
6567
}
6668

@@ -73,9 +75,11 @@ TVector3 TRestGeant4Hits::GetFirstPositionInVolume(Int_t volumeID) const {
7375
}
7476

7577
TVector3 TRestGeant4Hits::GetLastPositionInVolume(Int_t volumeID) const {
76-
for (int n = fNHits - 1; n >= 0; n--)
77-
if (fVolumeID[n] == volumeID) return GetPosition(n);
78-
78+
for (int n = fNHits - 1; n >= 0; n--) {
79+
if (fVolumeID[n] == volumeID) {
80+
return GetPosition(n);
81+
}
82+
}
7983
Double_t nan = TMath::QuietNaN();
8084
return {nan, nan, nan};
8185
}
@@ -91,15 +95,24 @@ size_t TRestGeant4Hits::GetNumberOfHitsInVolume(Int_t volumeID) const {
9195
}
9296

9397
TRestGeant4Metadata* TRestGeant4Hits::GetGeant4Metadata() const {
94-
const TRestGeant4Event* event = nullptr;
98+
const TRestGeant4Event* event;
9599
if (fTrack != nullptr) {
96100
event = fTrack->GetEvent();
97101
} else {
98102
event = fEvent;
99103
}
100104
if (event == nullptr) {
101-
cout << "null event" << endl;
102105
return nullptr;
103106
}
104107
return const_cast<TRestGeant4Metadata*>(event->GetGeant4Metadata());
105108
}
109+
110+
TString TRestGeant4Hits::GetProcessName(size_t n) const {
111+
const auto metadata = GetGeant4Metadata();
112+
return metadata == nullptr ? "" : metadata->GetGeant4PhysicsInfo().GetProcessName(GetProcessId(n));
113+
}
114+
115+
TString TRestGeant4Hits::GetVolumeName(size_t n) const {
116+
const auto metadata = GetGeant4Metadata();
117+
return metadata == nullptr ? "" : metadata->GetGeant4GeometryInfo().GetVolumeFromID(GetVolumeId(n));
118+
}

0 commit comments

Comments
 (0)