REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorHitsToSignalProcess.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
97
98#include "TRestDetectorHitsToSignalProcess.h"
99
100using namespace std;
101
103
108
122 Initialize();
123
124 if (LoadConfigFromFile(configFilename) == -1) {
126 }
127
128 if (fReadout == nullptr) fReadout = new TRestDetectorReadout(configFilename);
129}
130
135 delete fReadout;
136 delete fSignalEvent;
137}
138
143 SetName("hitsToSignalProcess-Default");
144 SetTitle("Default config");
145
146 cout << "Hits to signal metadata not found. Loading default values" << endl;
147
148 fSampling = 1;
149 fElectricField = 1000;
150 fGasPressure = 10;
151}
152
158 SetSectionName(this->ClassName());
159 SetLibraryVersion(LIBRARY_VERSION);
160
161 fReadout = nullptr;
162 fGas = nullptr;
163
164 fHitsEvent = nullptr;
166}
167
173 fGas = GetMetadata<TRestDetectorGas>();
174 if (fGas != nullptr) {
175#ifndef USE_Garfield
176 RESTError << "A TRestDetectorGas definition was found but REST was not linked to Garfield libraries."
177 << RESTendl;
178 RESTError
179 << "Please, remove the TRestDetectorGas definition, and add gas parameters inside the process "
180 "TRestDetectorHitsToSignalProcess"
181 << RESTendl;
182 if (!fGas->GetError()) fGas->SetError("REST was not compiled with Garfield.");
183 if (!this->GetError()) this->SetError("Attempt to use TRestDetectorGas without Garfield");
184#endif
185 if (fGasPressure <= 0) fGasPressure = fGas->GetPressure();
187
190
192 } else {
193 if (fDriftVelocity < 0) {
194 if (!this->GetError()) this->SetError("Drift velocity is negative.");
195 }
196 }
197
198 fReadout = GetMetadata<TRestDetectorReadout>();
199
200 if (fReadout == nullptr) {
201 if (!this->GetError()) this->SetError("The readout was not properly initialized.");
202 }
203}
204
209 fHitsEvent = (TRestDetectorHitsEvent*)inputEvent;
211
212 if (!fReadout) return nullptr;
213
215 cout << "Number of hits : " << fHitsEvent->GetNumberOfHits() << endl;
216 cout << "--------------------------" << endl;
217 }
218
219 for (unsigned int hit = 0; hit < fHitsEvent->GetNumberOfHits(); hit++) {
220 Double_t x = fHitsEvent->GetX(hit);
221 Double_t y = fHitsEvent->GetY(hit);
222 Double_t z = fHitsEvent->GetZ(hit);
223 Double_t t = fHitsEvent->GetTime(hit);
224
226 cout << "Hit : " << hit << " x : " << x << " y : " << y << " z : " << z << " t : " << t << endl;
227
228 Int_t moduleId = -1;
229 Int_t channelId = -1;
230
231 for (int p = 0; p < fReadout->GetNumberOfReadoutPlanes(); p++) {
232 Int_t daqId =
233 fReadout->GetHitsDaqChannelAtReadoutPlane(TVector3(x, y, z), moduleId, channelId, p);
234
236
237 if (daqId >= 0) {
238 Double_t energy = fHitsEvent->GetEnergy(hit);
239
240 Double_t time = plane->GetDistanceTo({x, y, z}) / fDriftVelocity + t;
241
243 cout << "Module : " << moduleId << " Channel : " << channelId << " daq ID : " << daqId
244 << endl;
245
247 cout << "Energy : " << energy << " time : " << time << endl;
248
250 printf(
251 " TRestDetectorHitsToSignalProcess: x %lf y %lf z %lf energy %lf t %lf "
252 "fDriftVelocity %lf fSampling %lf time %lf\n",
253 x, y, z, energy, t, fDriftVelocity, fSampling, time);
254
256 cout << "Drift velocity : " << fDriftVelocity << " mm/us" << endl;
257
258 time = ((Int_t)(time / fSampling)) * fSampling; // now time is in unit "us", but dispersed
259
260 fSignalEvent->AddChargeToSignal(daqId, time, energy);
261
262 } else {
264 RESTDebug << "TRestDetectorHitsToSignalProcess. Readout channel not find for position ("
265 << x << ", " << y << ", " << z << ")!" << RESTendl;
266 }
267 }
268 }
269
270 fSignalEvent->SortSignals();
271
273 cout << "TRestDetectorHitsToSignalProcess : Number of signals added : "
274 << fSignalEvent->GetNumberOfSignals() << endl;
275 cout << "TRestDetectorHitsToSignalProcess : Total signals integral : " << fSignalEvent->GetIntegral()
276 << endl;
277 }
278
279 if (fSignalEvent->GetNumberOfSignals() == 0) return nullptr;
280
281 return fSignalEvent;
282}
virtual void SetElectricField(double value)
Sets the electric field. Must be given in V/mm.
virtual Double_t GetElectricField() const
Returns the electric field in V/mm.
void SetPressure(Double_t pressure) override
Defines the pressure of the gas.
Double_t GetDriftVelocity(Double_t E)
It returns the drift velocity in cm/us for a given electric field in V/cm.
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.
A process to transform a x,y,z coordinate hits into daq identified physical time signals.
Double_t fSampling
The sampling rate in us.
void InitProcess() override
Process initialization. This process accesses the information inside TRestGeant4Metadata to identify ...
TRestDetectorHitsEvent * fHitsEvent
A pointer to the specific TRestDetectorHitsEvent output.
TRestDetectorGas * fGas
A pointer to the detector gas definition accessible to TRestRun.
Double_t fGasPressure
The gas pressure. If defined it will change the TRestDetectorGas pressure in atm.
TRestDetectorReadout * fReadout
A pointer to the detector readout definition accesible to TRestRun.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
Double_t fDriftVelocity
The drift velocity in mm/us. If it is negative, it will be calculated from TRestDetectorGas.
TRestDetectorSignalEvent * fSignalEvent
A pointer to the specific TRestDetectorHitsEvent input.
void LoadDefaultConfig()
Function to load the default config in absence of RML input.
Double_t fElectricField
The electric field in V/mm. Used to calculate the drift velocity if TRestDetectorGas is defined.
void Initialize() override
Function to initialize input/output event members and define the section name.
Double_t GetDistanceTo(const TVector3 &pos) const
Returns the perpendicular distance to the readout plane from a given position pos.
A metadata class to generate/store a readout description.
Int_t GetHitsDaqChannelAtReadoutPlane(const TVector3 &hitPosition, Int_t &moduleID, Int_t &channelID, Int_t planeId=0)
This method recovers the channel daq id corresponding to the (x,y,z) coordinates given by argument....
TRestDetectorReadoutPlane * GetReadoutPlaneWithID(int id)
Returns a pointer to the readout plane by ID.
Int_t GetNumberOfReadoutPlanes()
Returns the number of readout planes defined on the readout.
A base class for any REST event.
Definition: TRestEvent.h:38
void SetEventInfo(TRestEvent *eve)
Definition: TRestEvent.cxx:135
endl_t RESTendl
Termination flag object for TRestStringOutput.
Int_t LoadConfigFromFile(const std::string &configFilename, const std::string &sectionName="")
Give the file name, find out the corresponding section. Then call the main starter.
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
void SetError(std::string message="", bool print=true)
A metadata class may use this method to signal that something went wrong.
TRestStringOutput::REST_Verbose_Level GetVerboseLevel()
returns the verboselevel in type of REST_Verbose_Level enumerator
Bool_t GetError() const
It returns true if an error was identified by a derived metadata class.
void SetSectionName(std::string sName)
set the section name, clear the section content
@ REST_Debug
+show the defined debug messages