REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorHitsSmearingProcess.cxx
1/*************************************************************************
2 * This file is part of the REST software framework. *
3 * *
4 * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5 * For more information see http://gifna.unizar.es/trex *
6 * *
7 * REST is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * REST is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have a copy of the GNU General Public License along with *
18 * REST in $REST_PATH/LICENSE. *
19 * If not, see http://www.gnu.org/licenses/. *
20 * For the list of contributors see $REST_PATH/CREDITS. *
21 *************************************************************************/
22
69
70#include "TRestDetectorHitsSmearingProcess.h"
71
72using namespace std;
73
75
80
85
90 SetSectionName(this->ClassName());
91 SetLibraryVersion(LIBRARY_VERSION);
92
93 fInputEvent = nullptr;
95}
96
98 delete fRandom;
99 fRandom = new TRandom3(fSeed);
100 fSeed = fRandom->TRandom::GetSeed();
101
102 fReadout = dynamic_cast<TRestDetectorReadout*>(fRunInfo->GetMetadataClass("TRestDetectorReadout"));
103
104 if (!fReadout && !fChannelType.empty()) {
105 throw runtime_error(
106 "TRestDetectorHitsSmearingProcess::InitProcess() : "
107 "TRestDetectorReadout not found and channel type is requested");
108 }
109
110 transform(fChannelType.begin(), fChannelType.end(), fChannelType.begin(), ::tolower);
111 const auto validChannelTypes = {"veto", "tpc"};
112 if (find(validChannelTypes.begin(), validChannelTypes.end(), fChannelType) == validChannelTypes.end()) {
113 throw runtime_error(
114 "TRestDetectorHitsSmearingProcess::InitProcess() : Channel type not valid: valid types are: "
115 "'tpc', 'veto'");
116 }
117}
118
123 fInputEvent = (TRestDetectorHitsEvent*)inputEvent;
125
126 Double_t eDep = 0.0;
127 for (int hit = 0; hit < static_cast<int>(fInputEvent->GetNumberOfHits()); hit++) {
128 const auto hitType = fInputEvent->GetType(hit);
129 if ((fChannelType == "veto" && hitType == REST_HitType::VETO) ||
130 (fChannelType == "tpc" && hitType != REST_HitType::VETO)) {
131 eDep += fInputEvent->GetEnergy(hit);
132 }
133 }
134
135 Double_t gain = 1.0;
136 if (eDep > 0) {
137 Double_t eRes = fResolutionAtERef * TMath::Sqrt(fEnergyRef / eDep) / 2.35 / 100.0;
138 gain = fRandom->Gaus(1.0, eRes);
139 }
140
141 for (int hit = 0; hit < static_cast<int>(fInputEvent->GetNumberOfHits()); hit++) {
142 const auto hitType = fInputEvent->GetType(hit);
143
144 // VETO hit types are processed according the "veto" channel type. All other hit types are processed
145 // according to the "tpc" type (XYZ, XZ, etc.)
146
147 if (fChannelType == "veto") {
148 if (hitType == REST_HitType::VETO) {
150 fInputEvent->GetEnergy(hit) * gain, fInputEvent->GetTime(hit),
151 fInputEvent->GetType(hit));
152 } else {
153 // Do nothing
155 fInputEvent->GetEnergy(hit), fInputEvent->GetTime(hit),
156 fInputEvent->GetType(hit));
157 }
158 } else if (fChannelType == "tpc") {
159 if (hitType == REST_HitType::VETO) {
160 // Do nothing
162 fInputEvent->GetEnergy(hit), fInputEvent->GetTime(hit),
163 fInputEvent->GetType(hit));
164 } else {
166 fInputEvent->GetEnergy(hit) * gain, fInputEvent->GetTime(hit),
167 fInputEvent->GetType(hit));
168 }
169 } else {
170 // this should never happen
171 throw runtime_error(
172 "TRestDetectorHitsSmearingProcess::ProcessEvent() : "
173 "Channel type not valid: valid types are: "
174 "'tpc', 'veto'");
175 }
176 }
177
178 return fOutputEvent;
179}
Double_t GetX(int n) const
Returns the X-coordinate of hit entry n in mm.
Double_t GetY(int n) const
Returns the Y-coordinate of hit entry n in mm.
Double_t GetZ(int n) const
Returns the Z-coordinate of hit entry n in mm.
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 Initialize() override
Function to initialize input/output event members and define the section name.
Double_t fEnergyRef
Reference energy for the FWHM.
Double_t fResolutionAtERef
FWHM at Energy of reference.
TRestDetectorHitsEvent * fOutputEvent
A pointer to the process output event.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
TRestDetectorHitsEvent * fInputEvent
A pointer to the process input event.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
TRandom3 * fRandom
A pointer to the random generator initializes with fSeed.
ULong_t fSeed
The seed to be used for the random generator.
A metadata class to generate/store a readout description.
TRestRun * fRunInfo
< Pointer to TRestRun object where to find metadata.
A base class for any REST event.
Definition: TRestEvent.h:38
void SetEventInfo(TRestEvent *eve)
Definition: TRestEvent.cxx:137
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
void SetSectionName(std::string sName)
set the section name, clear the section content