Skip to content

Commit

Permalink
Merge pull request #116 from rest-for-physics/115-support-multiple-re…
Browse files Browse the repository at this point in the history
…adout-channel-types-on-processes

Smearing process allow channel type selection
  • Loading branch information
lobis authored May 8, 2024
2 parents 3ca09f8 + 243eac5 commit 41f054e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 14 deletions.
13 changes: 10 additions & 3 deletions inc/TRestDetectorHitsSmearingProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <TRestEventProcess.h>

#include "TRestDetectorHitsEvent.h"
#include "TRestDetectorReadout.h"

/// A process to include detector energy resolution in a TRestDetectorHitsEvent
class TRestDetectorHitsSmearingProcess : public TRestEventProcess {
Expand All @@ -43,6 +44,10 @@ class TRestDetectorHitsSmearingProcess : public TRestEventProcess {
void Initialize() override;
void InitProcess() override;

std::string fChannelType = "tpc";

TRestDetectorReadout* fReadout = nullptr; //!

protected:
/// Reference energy for the FWHM
Double_t fEnergyRef = 5.9; //<
Expand All @@ -64,8 +69,10 @@ class TRestDetectorHitsSmearingProcess : public TRestEventProcess {
void PrintMetadata() override {
BeginPrintProcess();

RESTMetadata << " reference energy (ERef): " << fEnergyRef << RESTendl;
RESTMetadata << " resolution at ERef : " << fResolutionAtERef << RESTendl;
RESTMetadata << "Channel type: " << fChannelType << RESTendl;

RESTMetadata << "Reference energy (ERef): " << fEnergyRef << RESTendl;
RESTMetadata << "Resolution at ERef : " << fResolutionAtERef << RESTendl;

EndPrintProcess();
}
Expand All @@ -85,6 +92,6 @@ class TRestDetectorHitsSmearingProcess : public TRestEventProcess {

~TRestDetectorHitsSmearingProcess();

ClassDefOverride(TRestDetectorHitsSmearingProcess, 3);
ClassDefOverride(TRestDetectorHitsSmearingProcess, 4);
};
#endif
66 changes: 55 additions & 11 deletions src/TRestDetectorHitsSmearingProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
///
/// <hr>
///

#include "TRestDetectorHitsSmearingProcess.h"

using namespace std;
Expand All @@ -79,10 +80,7 @@ TRestDetectorHitsSmearingProcess::TRestDetectorHitsSmearingProcess() { Initializ
///////////////////////////////////////////////
/// \brief Default destructor
///
TRestDetectorHitsSmearingProcess::~TRestDetectorHitsSmearingProcess() {
delete fOutputEvent;
// TRestDetectorHitsSmearingProcess destructor
}
TRestDetectorHitsSmearingProcess::~TRestDetectorHitsSmearingProcess() { delete fOutputEvent; }

///////////////////////////////////////////////
/// \brief Function to initialize input/output event members and define the section name
Expand All @@ -96,11 +94,25 @@ void TRestDetectorHitsSmearingProcess::Initialize() {
}

void TRestDetectorHitsSmearingProcess::InitProcess() {
if (fRandom != nullptr) {
delete fRandom;
}
delete fRandom;
fRandom = new TRandom3(fSeed);
fSeed = fRandom->TRandom::GetSeed();

fReadout = dynamic_cast<TRestDetectorReadout*>(fRunInfo->GetMetadataClass("TRestDetectorReadout"));

if (!fReadout && !fChannelType.empty()) {
throw runtime_error(
"TRestDetectorHitsSmearingProcess::InitProcess() : "
"TRestDetectorReadout not found and channel type is requested");
}

transform(fChannelType.begin(), fChannelType.end(), fChannelType.begin(), ::tolower);
const auto validChannelTypes = {"veto", "tpc"};
if (find(validChannelTypes.begin(), validChannelTypes.end(), fChannelType) == validChannelTypes.end()) {
throw runtime_error(
"TRestDetectorHitsSmearingProcess::InitProcess() : Channel type not valid: valid types are: "
"'tpc', 'veto'");
}
}

///////////////////////////////////////////////
Expand All @@ -114,10 +126,42 @@ TRestEvent* TRestDetectorHitsSmearingProcess::ProcessEvent(TRestEvent* inputEven
Double_t eRes = fResolutionAtERef * TMath::Sqrt(fEnergyRef / eDep) / 2.35 / 100.0;

Double_t gain = fRandom->Gaus(1.0, eRes);
for (unsigned int hit = 0; hit < fInputEvent->GetNumberOfHits(); hit++)
fOutputEvent->AddHit(fInputEvent->GetX(hit), fInputEvent->GetY(hit), fInputEvent->GetZ(hit),
fInputEvent->GetEnergy(hit) * gain, fInputEvent->GetTime(hit),
fInputEvent->GetType(hit));
for (int hit = 0; hit < static_cast<int>(fInputEvent->GetNumberOfHits()); hit++) {
const auto hitType = fInputEvent->GetType(hit);

// VETO hit types are processed according the "veto" channel type. All other hit types are processed
// according to the "tpc" type (XYZ, XZ, etc.)

if (fChannelType == "veto") {
if (hitType == REST_HitType::VETO) {
fOutputEvent->AddHit(fInputEvent->GetX(hit), fInputEvent->GetY(hit), fInputEvent->GetZ(hit),
fInputEvent->GetEnergy(hit) * gain, fInputEvent->GetTime(hit),
fInputEvent->GetType(hit));
} else {
// Do nothing
fOutputEvent->AddHit(fInputEvent->GetX(hit), fInputEvent->GetY(hit), fInputEvent->GetZ(hit),
fInputEvent->GetEnergy(hit), fInputEvent->GetTime(hit),
fInputEvent->GetType(hit));
}
} else if (fChannelType == "tpc") {
if (hitType == REST_HitType::VETO) {
// Do nothing
fOutputEvent->AddHit(fInputEvent->GetX(hit), fInputEvent->GetY(hit), fInputEvent->GetZ(hit),
fInputEvent->GetEnergy(hit), fInputEvent->GetTime(hit),
fInputEvent->GetType(hit));
} else {
fOutputEvent->AddHit(fInputEvent->GetX(hit), fInputEvent->GetY(hit), fInputEvent->GetZ(hit),
fInputEvent->GetEnergy(hit) * gain, fInputEvent->GetTime(hit),
fInputEvent->GetType(hit));
}
} else {
// this should never happen
throw runtime_error(
"TRestDetectorHitsSmearingProcess::ProcessEvent() : "
"Channel type not valid: valid types are: "
"'tpc', 'veto'");
}
}

return fOutputEvent;
}

0 comments on commit 41f054e

Please sign in to comment.