Skip to content

Commit

Permalink
Merge pull request #113 from rest-for-physics/lobis-working-on-veto-r…
Browse files Browse the repository at this point in the history
…eadout

Working on veto readout
  • Loading branch information
lobis authored Sep 10, 2023
2 parents 9dc628f + 160477c commit fb0145d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 35 deletions.
2 changes: 1 addition & 1 deletion inc/TRestGeant4Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class TRestGeant4Event : public TRestEvent {

void InitializeReferences(TRestRun* run) override;

const TRestGeant4Metadata* GetGeant4Metadata(const char* name = "TRestGeant4Metadata") const;
const TRestGeant4Metadata* GetGeant4Metadata() const;

/// maxTracks : number of tracks to print, 0 = all
void PrintActiveVolumes() const;
Expand Down
2 changes: 1 addition & 1 deletion inc/TRestGeant4PhysicsLists.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/// inherited from TRestMetadata
/// How to use: replace TRestGeant4PhysicsLists by your class name,
/// fill the required functions following instructions and add all
/// needed additional members and funcionality
/// needed additional members and functionality
///
/// Apr 2017: First concept. Javier Galan
///
Expand Down
8 changes: 6 additions & 2 deletions src/TRestGeant4Event.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1208,8 +1208,12 @@ Bool_t TRestGeant4Event::ContainsParticleInVolume(const TString& particleName, I
return false;
}

const TRestGeant4Metadata* TRestGeant4Event::GetGeant4Metadata(const char* name) const {
return dynamic_cast<TRestGeant4Metadata*>(fRun->GetMetadataClass(name));
const TRestGeant4Metadata* TRestGeant4Event::GetGeant4Metadata() const {
if (fRun == nullptr) {
RESTError << "TRestGeant4Event::GetGeant4Metadata: fRun is nullptr" << RESTendl;
return nullptr;
}
return dynamic_cast<TRestGeant4Metadata*>(fRun->GetMetadataClass("TRestGeant4Metadata"));
}

void TRestGeant4Event::InitializeReferences(TRestRun* run) {
Expand Down
11 changes: 5 additions & 6 deletions src/TRestGeant4Hits.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "TRestGeant4Hits.h"

#include "TRestGeant4Event.h"
#include "TRestGeant4Track.h"

using namespace std;

Expand All @@ -39,7 +38,7 @@ void TRestGeant4Hits::RemoveG4Hits() {
Double_t TRestGeant4Hits::GetEnergyInVolume(Int_t volumeID) const {
Double_t energy = 0;

for (size_t n = 0; n < fNHits; n++) {
for (size_t n = 0; n < GetNumberOfHits(); n++) {
if (fVolumeID[n] == volumeID) {
energy += GetEnergy(n);
}
Expand All @@ -51,7 +50,7 @@ Double_t TRestGeant4Hits::GetEnergyInVolume(Int_t volumeID) const {
TVector3 TRestGeant4Hits::GetMeanPositionInVolume(Int_t volumeID) const {
TVector3 pos;
Double_t energy = 0;
for (size_t n = 0; n < fNHits; n++)
for (size_t n = 0; n < GetNumberOfHits(); n++)
if (fVolumeID[n] == volumeID) {
pos += GetPosition(n) * GetEnergy(n);
energy += GetEnergy(n);
Expand All @@ -67,15 +66,15 @@ TVector3 TRestGeant4Hits::GetMeanPositionInVolume(Int_t volumeID) const {
}

TVector3 TRestGeant4Hits::GetFirstPositionInVolume(Int_t volumeID) const {
for (size_t n = 0; n < fNHits; n++)
for (size_t n = 0; n < GetNumberOfHits(); n++)
if (fVolumeID[n] == volumeID) return GetPosition(n);

Double_t nan = TMath::QuietNaN();
return {nan, nan, nan};
}

TVector3 TRestGeant4Hits::GetLastPositionInVolume(Int_t volumeID) const {
for (int n = fNHits - 1; n >= 0; n--) {
for (int n = GetNumberOfHits() - 1; n >= 0; n--) {
if (fVolumeID[n] == volumeID) {
return GetPosition(n);
}
Expand All @@ -86,7 +85,7 @@ TVector3 TRestGeant4Hits::GetLastPositionInVolume(Int_t volumeID) const {

size_t TRestGeant4Hits::GetNumberOfHitsInVolume(Int_t volumeID) const {
size_t result = 0;
for (size_t n = 0; n < fNHits; n++) {
for (size_t n = 0; n < GetNumberOfHits(); n++) {
if (fVolumeID[n] == volumeID) {
result++;
}
Expand Down
52 changes: 27 additions & 25 deletions src/TRestGeant4VetoAnalysisProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void TRestGeant4VetoAnalysisProcess::InitProcess() {
exit(1);
}

cout << "Expression: " << fVetoVolumesExpression << endl;
RESTDebug << "Expression: " << fVetoVolumesExpression << RESTendl;
const auto& geometryInfo = fGeant4Metadata->GetGeant4GeometryInfo();

auto vetoVolumes = geometryInfo.GetAllPhysicalVolumesMatchingExpression(fVetoVolumesExpression);
Expand All @@ -236,7 +236,7 @@ void TRestGeant4VetoAnalysisProcess::InitProcess() {
}
}

PrintMetadata();
// PrintMetadata();
}

///////////////////////////////////////////////
Expand Down Expand Up @@ -327,8 +327,9 @@ TRestEvent* TRestGeant4VetoAnalysisProcess::ProcessEvent(TRestEvent* inputEvent)

vector<float> nCapturesInCaptureVolumesTimes;
vector<vector<float>> nCapturesInCaptureVolumesChildGammaEnergies;
// for each child gamma, how much energy was deposited in all vetoes
vector<float> nCapturesInCaptureVolumesChildGammasEnergyInVetos;
vector<int> nCapturesInCaptureVolumesNumberOfVetoesHitByCapture;
vector<vector<float>> nCapturesInCaptureVolumesEnergyInVetoesForCapture;

set<int> nCapturesInCaptureVolumesNeutronTrackIds;

Expand Down Expand Up @@ -374,14 +375,14 @@ TRestEvent* TRestGeant4VetoAnalysisProcess::ProcessEvent(TRestEvent* inputEvent)
}
nCapturesInCaptureVolumesChildGammaEnergies.push_back(childrenEnergy);

int numberOfVetoesHitByCapture = 0;
vector<float> energyInVetoesForCapture;
for (const auto& veto : fVetoVolumes) {
const double energyInVeto = track.GetEnergyInVolume(veto.name, true);
if (energyInVeto > 100) { // soft limit of 100 keV
numberOfVetoesHitByCapture++;
if (energyInVeto > 0) { // soft limit of 100 keV
energyInVetoesForCapture.push_back(energyInVeto);
}
}
nCapturesInCaptureVolumesNumberOfVetoesHitByCapture.push_back(numberOfVetoesHitByCapture);
nCapturesInCaptureVolumesEnergyInVetoesForCapture.push_back(energyInVetoesForCapture);
}
if (volumeName.find("scintillatorVolume") != string::npos) {
nCapturesInVetoVolumes++;
Expand Down Expand Up @@ -480,25 +481,26 @@ TRestEvent* TRestGeant4VetoAnalysisProcess::ProcessEvent(TRestEvent* inputEvent)
SetObservableValue("nCapturesInCaptureVolumesChildGammasEnergyInVetosTotal",
nCapturesInCaptureVolumesChildGammasEnergyInVetosTotal);

SetObservableValue("nCapturesInCaptureVolumesNumberOfVetoesHitByCapture",
nCapturesInCaptureVolumesNumberOfVetoesHitByCapture);

int nCapturesInCaptureVolumesNumberOfVetoesHitByCaptureTotal = 0;
float nCapturesInCaptureVolumesNumberOfVetoesHitByCaptureAverage = 0;
for (const auto& n : nCapturesInCaptureVolumesNumberOfVetoesHitByCapture) {
nCapturesInCaptureVolumesNumberOfVetoesHitByCaptureTotal += n;
nCapturesInCaptureVolumesNumberOfVetoesHitByCaptureAverage +=
float(n) / nCapturesInCaptureVolumesNumberOfVetoesHitByCapture.size();
SetObservableValue("nCapturesInCaptureVolumesEnergyInVetoesForCapture",
nCapturesInCaptureVolumesEnergyInVetoesForCapture);

const vector<float> energyInVetoesThresholds = {0, 100, 250, 500, 1000, 1500};
for (const auto& threshold : energyInVetoesThresholds) {
vector<vector<int>> nCapturesInCaptureVolumesEnergyInVetoesForCaptureThreshold;
for (const auto& captureForNeutronEnergies : nCapturesInCaptureVolumesEnergyInVetoesForCapture) {
int nCapturesInCaptureVolumesVetoesAboveThresholdForCapture = 0;
for (const auto& energy : captureForNeutronEnergies) {
if (energy > threshold) {
nCapturesInCaptureVolumesVetoesAboveThresholdForCapture++;
}
}
nCapturesInCaptureVolumesEnergyInVetoesForCaptureThreshold.push_back(
{nCapturesInCaptureVolumesVetoesAboveThresholdForCapture});
}
SetObservableValue(
"nCapturesInCaptureVolumesVetoesAboveThresholdForCapture" + to_string(int(threshold)) + "keV",
nCapturesInCaptureVolumesEnergyInVetoesForCaptureThreshold);
}
SetObservableValue("nCapturesInCaptureVolumesNumberOfVetoesHitByCaptureTotal",
nCapturesInCaptureVolumesNumberOfVetoesHitByCaptureTotal);

SetObservableValue("nCapturesInCaptureVolumesNumberOfVetoesHitByCaptureAverage",
nCapturesInCaptureVolumesNumberOfVetoesHitByCaptureAverage);

SetObservableValue("nCapturesInCaptureVolumesNumberOfVetoesHitByCaptureMostFrequent",
findMostFrequent(nCapturesInCaptureVolumesNumberOfVetoesHitByCapture));

return fOutputEvent;
}

Expand Down

0 comments on commit fb0145d

Please sign in to comment.