REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorHitsAnalysisProcess.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
122
123#include "TRestDetectorHitsAnalysisProcess.h"
124
125using namespace std;
126
128
129TRestDetectorHitsAnalysisProcess::TRestDetectorHitsAnalysisProcess() { Initialize(); }
130
131TRestDetectorHitsAnalysisProcess::TRestDetectorHitsAnalysisProcess(const char* configFilename) {
132 Initialize();
133 if (LoadConfigFromFile(configFilename) == -1) {
134 LoadDefaultConfig();
135 }
136}
137
138TRestDetectorHitsAnalysisProcess::~TRestDetectorHitsAnalysisProcess() { delete fOutputHitsEvent; }
139
140void TRestDetectorHitsAnalysisProcess::LoadDefaultConfig() { SetTitle("Default config"); }
141
143 SetSectionName(this->ClassName());
144 SetLibraryVersion(LIBRARY_VERSION);
145
146 fInputHitsEvent = nullptr;
147 fOutputHitsEvent = new TRestDetectorHitsEvent();
148
149 fPrismFiducial = false;
150 fCylinderFiducial = false;
151}
152
153void TRestDetectorHitsAnalysisProcess::LoadConfig(const string& configFilename, const string& name) {
154 if (LoadConfigFromFile(configFilename, name) == -1) LoadDefaultConfig();
155}
156
157void TRestDetectorHitsAnalysisProcess::InitProcess() { TRestEventProcess::ReadObservables(); }
158
160 fInputHitsEvent = (TRestDetectorHitsEvent*)inputEvent;
161
162 TString obsName;
163
164 TRestHits* hits = fInputHitsEvent->GetHits();
165 for (unsigned int n = 0; n < hits->GetNumberOfHits(); n++) {
166 Double_t eDep = hits->GetEnergy(n);
167
168 Double_t x = hits->GetX(n);
169 Double_t y = hits->GetY(n);
170 Double_t z = hits->GetZ(n);
171
172 auto time = hits->GetTime(n);
173 auto type = hits->GetType(n);
174
175 // do not analyze veto hits
176 if (type == VETO) {
177 continue;
178 }
179 fOutputHitsEvent->AddHit({x, y, z}, eDep, time, type);
180 }
181
182 Double_t energy = fOutputHitsEvent->GetTotalEnergy();
183 TVector3 meanPosition = fOutputHitsEvent->GetMeanPosition();
184 Double_t sigmaX = fOutputHitsEvent->GetSigmaX();
185 Double_t sigmaY = fOutputHitsEvent->GetSigmaY();
186 Double_t sigmaXY2 = fOutputHitsEvent->GetSigmaXY2();
187 Double_t sigmaZ2 = fOutputHitsEvent->GetSigmaZ2();
188 Double_t skewXY = fOutputHitsEvent->GetSkewXY();
189 Double_t skewZ = fOutputHitsEvent->GetSkewZ();
190 Double_t energyX = fOutputHitsEvent->GetEnergyX();
191 Double_t energyY = fOutputHitsEvent->GetEnergyY();
192 Double_t maxEnergy = fOutputHitsEvent->GetMaximumHitEnergy();
193 Double_t minEnergy = fOutputHitsEvent->GetMinimumHitEnergy();
194 Double_t meanEnergy = fOutputHitsEvent->GetMeanHitEnergy();
195 Int_t nHits = fOutputHitsEvent->GetNumberOfHits();
196 Int_t nHitsX = fOutputHitsEvent->GetNumberOfHitsX();
197 Int_t nHitsY = fOutputHitsEvent->GetNumberOfHitsY();
198
199 SetObservableValue("nHits", nHits);
200
201 SetObservableValue("nHitsX", nHitsX);
202
203 SetObservableValue("nHitsY", nHitsY);
204
205 SetObservableValue("balanceXYnHits", (nHitsX - nHitsY) / double(nHitsX + nHitsY));
206
207 if ((nHits == nHitsX) || (nHits == nHitsY))
208 SetObservableValue("nHitsSizeXY", (double)nHits);
209 else
210 SetObservableValue("nHitsSizeXY", TMath::Sqrt(nHitsX * nHitsX + nHitsY * nHitsY));
211
212 // Checking hits inside fiducial cylinder
213 if (fCylinderFiducial) {
214 TVector3 meanPositionInCylinder =
215 fOutputHitsEvent->GetMeanPositionInCylinder(fFid_x0, fFid_x1, fFid_R);
216
217 Int_t isInsideCylinder = 0;
218 if (fOutputHitsEvent->anyHitInsideCylinder(fFid_x0, fFid_x1, fFid_R)) isInsideCylinder = 1;
219
220 Int_t nCylVol = fOutputHitsEvent->GetNumberOfHitsInsideCylinder(fFid_x0, fFid_x1, fFid_R);
221
222 Double_t enCylVol = fOutputHitsEvent->GetEnergyInCylinder(fFid_x0, fFid_x1, fFid_R);
223
224 SetObservableValue("isInsideCylindricalVolume", isInsideCylinder);
225
226 SetObservableValue("nInsideCylindricalVolume", nCylVol);
227
228 SetObservableValue("energyInsideCylindricalVolume", enCylVol);
229
230 // mean positions
231 SetObservableValue("xMeanInCylinder", meanPositionInCylinder.X());
232
233 SetObservableValue("yMeanInCylinder", meanPositionInCylinder.Y());
234
235 SetObservableValue("zMeanInCylinder", meanPositionInCylinder.Z());
236 }
237
238 // Checking hits inside fiducial prism
239 if (fPrismFiducial) {
240 TVector3 meanPositionInPrism =
241 fOutputHitsEvent->GetMeanPositionInPrism(fFid_x0, fFid_x1, fFid_sX, fFid_sY, fFid_theta);
242
243 Int_t isInsidePrism = 0;
244 if (fOutputHitsEvent->anyHitInsidePrism(fFid_x0, fFid_x1, fFid_sX, fFid_sY, fFid_theta))
245 isInsidePrism = 1;
246
247 Int_t nPrismVol =
248 fOutputHitsEvent->GetNumberOfHitsInsidePrism(fFid_x0, fFid_x1, fFid_sX, fFid_sY, fFid_theta);
249
250 Double_t enPrismVol =
251 fOutputHitsEvent->GetEnergyInPrism(fFid_x0, fFid_x1, fFid_sX, fFid_sY, fFid_theta);
252
253 SetObservableValue("isInsidePrismVolume", isInsidePrism);
254
255 SetObservableValue("nInsidePrismVolume", nPrismVol);
256
257 SetObservableValue("energyInsidePrismVolume", enPrismVol);
258
259 // Mean Positions
260
261 SetObservableValue("xMeanInPrism", meanPositionInPrism.X());
262
263 SetObservableValue("yMeanInPrism", meanPositionInPrism.Y());
264
265 SetObservableValue("zMeanInPrism", meanPositionInPrism.Z());
266 }
267
269
270 if (fCylinderFiducial) {
271 // Adding distances to cylinder wall
272 Double_t dToCylWall =
273 fOutputHitsEvent->GetClosestHitInsideDistanceToCylinderWall(fFid_x0, fFid_x1, fFid_R);
274 Double_t dToCylTop =
275 fOutputHitsEvent->GetClosestHitInsideDistanceToCylinderTop(fFid_x0, fFid_x1, fFid_R);
276 Double_t dToCylBottom =
277 fOutputHitsEvent->GetClosestHitInsideDistanceToCylinderBottom(fFid_x0, fFid_x1, fFid_R);
278
279 SetObservableValue("distanceToCylinderWall", dToCylWall);
280 SetObservableValue("distanceToCylinderTop", dToCylTop);
281 SetObservableValue("distanceToCylinderBottom", dToCylBottom);
282 }
283
284 if (fPrismFiducial) {
285 // Adding distances to prism wall
286 Double_t dToPrismWall = fOutputHitsEvent->GetClosestHitInsideDistanceToPrismWall(
287 fFid_x0, fFid_x1, fFid_sX, fFid_sY, fFid_theta);
288 Double_t dToPrismTop = fOutputHitsEvent->GetClosestHitInsideDistanceToPrismTop(
289 fFid_x0, fFid_x1, fFid_sX, fFid_sY, fFid_theta);
290 Double_t dToPrismBottom = fOutputHitsEvent->GetClosestHitInsideDistanceToPrismBottom(
291 fFid_x0, fFid_x1, fFid_sX, fFid_sY, fFid_theta);
292
293 SetObservableValue("distanceToPrismWall", dToPrismWall);
294
295 SetObservableValue("distanceToPrismTop", dToPrismTop);
296
297 SetObservableValue("distanceToPrismBottom", dToPrismBottom);
298 }
299
301
302 SetObservableValue("energy", energy);
303 SetObservableValue("energyX", energyX);
304 SetObservableValue("energyY", energyY);
305 SetObservableValue("balanceXYenergy", (energyX - energyY) / (energyX + energyY));
306
307 SetObservableValue("maxHitEnergy", maxEnergy);
308 SetObservableValue("minHitEnergy", minEnergy);
309 SetObservableValue("meanHitEnergy", meanEnergy);
310 SetObservableValue("meanHitEnergyBalance", meanEnergy / energy);
311
312 SetObservableValue("xMean", meanPosition.X());
313
314 SetObservableValue("yMean", meanPosition.Y());
315
316 SetObservableValue("zMean", meanPosition.Z());
317 SetObservableValue("xy2Sigma", sigmaXY2);
318 SetObservableValue("xSigma", sigmaX);
319 SetObservableValue("ySigma", sigmaY);
320 SetObservableValue("xySigmaBalance", (sigmaX - sigmaY) / (sigmaX + sigmaY));
321
322 SetObservableValue("z2Sigma", sigmaZ2);
323
324 SetObservableValue("xySkew", skewXY);
325 SetObservableValue("zSkew", skewZ);
326
328 fOutputHitsEvent->PrintEvent(1000);
329 GetChar();
330 }
331
332 if (fOutputHitsEvent->GetNumberOfHits() == 0) {
333 return nullptr;
334 }
335
336 for (unsigned int n = 0; n < hits->GetNumberOfHits(); n++) {
337 Double_t eDep = hits->GetEnergy(n);
338
339 Double_t x = hits->GetX(n);
340 Double_t y = hits->GetY(n);
341 Double_t z = hits->GetZ(n);
342
343 auto time = hits->GetTime(n);
344 auto type = hits->GetType(n);
345
346 // add back missing hits from veto
347 if (type != VETO) {
348 continue;
349 }
350 fOutputHitsEvent->AddHit({x, y, z}, eDep, time, type);
351 }
352
353 return fOutputHitsEvent;
354}
355
357 // Function to be executed once at the end of the process
358 // (after all events have been processed)
359
360 // Start by calling the EndProcess function of the abstract class.
361 // Comment this if you don't want it.
362 // TRestEventProcess::EndProcess();
363}
364
366 fFid_x0 = Get3DVectorParameterWithUnits("fiducial_x0", TVector3(0, 0, 0));
367 fFid_x1 = Get3DVectorParameterWithUnits("fiducial_x1", TVector3(0, 0, 0));
368
369 fFid_R = GetDblParameterWithUnits("fiducial_R", 1);
370 fFid_sX = GetDblParameterWithUnits("fiducial_sX", 1);
371 fFid_sY = GetDblParameterWithUnits("fiducial_sY", 1);
372 // read angle in degrees
373 fFid_theta = GetDblParameterWithUnits("fiducial_theta", 0.0);
374
375 if (GetParameter("cylinderFiducialization", "false") == "true") {
376 fCylinderFiducial = true;
377 }
378
379 if (GetParameter("prismFiducialization", "false") == "true") {
380 fPrismFiducial = true;
381 }
382}
An analysis REST process to extract valuable information from Hits type of data.
void Initialize() override
Making default settings.
void EndProcess() override
To be executed at the end of the run (outside event loop)
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
virtual void PrintEvent() const
TVector3 GetMeanPositionInCylinder(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the mean position of the hits found inside the cylinder volume given by argument.
Double_t GetClosestHitInsideDistanceToCylinderTop(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the distance to the cylinder top face from the closest hit contained inside the c...
Double_t GetClosestHitInsideDistanceToPrismBottom(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the distance to the prism bottom face from the closest hit contained inside the p...
Int_t GetNumberOfHitsInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the total number hits found inside the cylinder volume given by argument.
Bool_t anyHitInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius)
This method returns true if at least 1 hit is found inside the cylinder volume given by argument.
Double_t GetEnergyInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the total integrated energy of all hits found inside the prism volume given by ar...
Double_t GetClosestHitInsideDistanceToCylinderWall(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the distance to the cylinder wall from the closest hit contained inside the cylin...
Int_t GetNumberOfHitsInsidePrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the total number of hits found inside the prism volume given by argument.
Double_t GetClosestHitInsideDistanceToCylinderBottom(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the distance to the cylinder bottom face from the closest hit contained inside th...
TVector3 GetMeanPositionInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the mean position of all hits found inside the prism volume given by argument.
Double_t GetEnergyInCylinder(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the total integrated energy of all hits found inside the cylinder volume given by...
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.
Double_t GetClosestHitInsideDistanceToPrismTop(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the distance to the prism top face from the closest hit contained inside the pris...
Bool_t anyHitInsidePrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns true if at least 1 hit is found inside the prism volume given by argument.
Double_t GetClosestHitInsideDistanceToPrismWall(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the distance to the prism wall from the closest hit contained inside the prism vo...
void SetObservableValue(const std::string &name, const T &value)
Set observable value for AnalysisTree.
A base class for any REST event.
Definition: TRestEvent.h:38
It saves a 3-coordinate position and an energy for each punctual deposition.
Definition: TRestHits.h:39
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.
TRestStringOutput::REST_Verbose_Level GetVerboseLevel()
returns the verboselevel in type of REST_Verbose_Level enumerator
void SetSectionName(std::string sName)
set the section name, clear the section content
std::string GetParameter(std::string parName, TiXmlElement *e, TString defaultValue=PARAMETER_NOT_FOUND_STR)
Returns the value for the parameter named parName in the given section.
Int_t GetChar(std::string hint="Press a KEY to continue ...")
Helps to pause the program, printing a message before pausing.