REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorLightAttenuationProcess.cxx
1//
2// Created by lobis on 25-Aug-23.
3//
4
5#include "TRestDetectorLightAttenuationProcess.h"
6
7using namespace std;
8
10
12 if (fVetoLightAttenuationLength <= 0.0) {
13 cerr << "TRestDetectorLightAttenuationProcess::InitProcess() - "
14 "parameter 'vetoLightAttenuationLength' is not set. "
15 "Please set it in the rml file."
16 << endl;
17 exit(1);
18 }
19
20 fReadout = GetMetadata<TRestDetectorReadout>();
21
22 if (fReadout == nullptr) {
23 cerr << "TRestDetectorLightAttenuationProcess::InitProcess() - "
24 "TRestDetectorReadout is not defined. "
25 "Please define it in the rml file."
26 << endl;
27 exit(1);
28 }
29
30 fInputEvent = nullptr;
31 fOutputEvent = new TRestDetectorHitsEvent();
32}
33
35 fInputEvent = dynamic_cast<TRestDetectorHitsEvent*>(inputEvent);
36 fOutputEvent->SetEventInfo(fInputEvent);
37
38 for (unsigned int hit = 0; hit < fInputEvent->GetNumberOfHits(); hit++) {
39 const TVector3& position = fInputEvent->GetPosition(hit);
40 const REST_HitType hitType = fInputEvent->GetType(hit);
41 const double energy = fInputEvent->GetEnergy(hit);
42 const double time = fInputEvent->GetTime(hit);
43
44 if (hitType != VETO) {
45 // this process only works for veto hits
46 fOutputEvent->AddHit(position, energy, time, hitType);
47 continue;
48 }
49
50 // attenuation
51
52 int count = 0;
53 double energyAttenuated = energy;
54 double timeDelayed = time;
55 for (int p = 0; p < fReadout->GetNumberOfReadoutPlanes(); p++) {
56 auto [daqId, moduleId, channelId] = fReadout->GetHitsDaqChannelAtReadoutPlane(position, p);
57 TRestDetectorReadoutPlane* plane = fReadout->GetReadoutPlane(p);
58
59 if (daqId >= 0) {
60 auto channel = fReadout->GetReadoutChannelWithDaqID(daqId);
61
62 const bool isVeto = (channel->GetChannelType() == "veto");
63
64 if (!isVeto) {
65 cout << "TRestDetectorLightAttenuationProcess::ProcessEvent() - "
66 "channel type is not 'veto'. "
67 << endl;
68 continue;
69 }
70
71 plane->GetType();
72 const double distance = plane->GetDistanceTo(position);
73 energyAttenuated = energy * TMath::Exp(-1.0 * distance / fVetoLightAttenuationLength);
74 timeDelayed = time + distance / fVetoEffectiveLightSpeed;
75 count++;
76 }
77 }
78
79 if (count == 0) {
80 cerr << "TRestDetectorLightAttenuationProcess::ProcessEvent() - "
81 "no readout plane found for veto hit "
82 << position.X() << " " << position.Y() << " " << position.Z() << " with energy: " << energy
83 << " keV" << endl;
84 exit(1);
85 // it's probably a hit on the boundary, the readout should be slightly bigger to account for this
86 // imprecision
87 } else if (count > 1) {
88 cerr << "TRestDetectorLightAttenuationProcess::ProcessEvent() - "
89 "more than one readout plane found for veto hit "
90 << endl;
91 exit(1);
92 }
93
94 fOutputEvent->AddHit(position, energyAttenuated, timeDelayed, hitType);
95 }
96
97 return fOutputEvent;
98}
99
102
103 RESTMetadata << "Veto effective light speed : " << fVetoEffectiveLightSpeed * units("m/s") << " m/s"
104 << RESTendl;
105 RESTMetadata << "Veto light attenuation length : " << fVetoLightAttenuationLength * units("cm") << " cm"
106 << RESTendl;
107
108 EndPrintProcess();
109}
void AddHit(Double_t x, Double_t y, Double_t z, Double_t en, Double_t t=0, REST_HitType type=XYZ)
Adds a new hit to this event.
A process to include detector energy resolution in a TRestDetectorHitsEvent.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
Double_t GetDistanceTo(const TVector3 &pos) const
Returns the perpendicular distance to the readout plane from a given position pos.
TRestDetectorReadoutPlane * GetReadoutPlane(int p)
Returns a pointer to the readout plane by index.
std::tuple< Int_t, Int_t, Int_t > GetHitsDaqChannelAtReadoutPlane(const TVector3 &position, Int_t planeId=0)
Returns a tuple with the DaqID, ModuleID, ChannelID.
TRestDetectorReadoutChannel * GetReadoutChannelWithDaqID(int daqId)
Returns a pointer to the readout channel by daq id.
void BeginPrintProcess()
[name, cut range]
A base class for any REST event.
Definition: TRestEvent.h:38
void SetEventInfo(TRestEvent *eve)
Definition: TRestEvent.cxx:137
endl_t RESTendl
Termination flag object for TRestStringOutput.