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 fOutputHitsEvent->AddHit(x, y, z, eDep, time, type);
176 }
177
178 Double_t energy = fOutputHitsEvent->GetEnergy();
179 TVector3 meanPosition = fOutputHitsEvent->GetMeanPosition();
180 Double_t sigmaX = fOutputHitsEvent->GetSigmaX();
181 Double_t sigmaY = fOutputHitsEvent->GetSigmaY();
182 Double_t sigmaXY2 = fOutputHitsEvent->GetSigmaXY2();
183 Double_t sigmaZ2 = fOutputHitsEvent->GetSigmaZ2();
184 Double_t skewXY = fOutputHitsEvent->GetSkewXY();
185 Double_t skewZ = fOutputHitsEvent->GetSkewZ();
186 Double_t energyX = fOutputHitsEvent->GetEnergyX();
187 Double_t energyY = fOutputHitsEvent->GetEnergyY();
188 Double_t maxEnergy = fOutputHitsEvent->GetMaximumHitEnergy();
189 Double_t minEnergy = fOutputHitsEvent->GetMinimumHitEnergy();
190 Double_t meanEnergy = fOutputHitsEvent->GetMeanHitEnergy();
191 Int_t nHits = fOutputHitsEvent->GetNumberOfHits();
192 Int_t nHitsX = fOutputHitsEvent->GetNumberOfHitsX();
193 Int_t nHitsY = fOutputHitsEvent->GetNumberOfHitsY();
194
195 SetObservableValue("nHits", nHits);
196
197 SetObservableValue("nHitsX", nHitsX);
198
199 SetObservableValue("nHitsY", nHitsY);
200
201 SetObservableValue("balanceXYnHits", (nHitsX - nHitsY) / double(nHitsX + nHitsY));
202
203 if ((nHits == nHitsX) || (nHits == nHitsY))
204 SetObservableValue("nHitsSizeXY", (double)nHits);
205 else
206 SetObservableValue("nHitsSizeXY", TMath::Sqrt(nHitsX * nHitsX + nHitsY * nHitsY));
207
208 // Checking hits inside fiducial cylinder
209 if (fCylinderFiducial) {
210 TVector3 meanPositionInCylinder =
211 fOutputHitsEvent->GetMeanPositionInCylinder(fFid_x0, fFid_x1, fFid_R);
212
213 Int_t isInsideCylinder = 0;
214 if (fOutputHitsEvent->anyHitInsideCylinder(fFid_x0, fFid_x1, fFid_R)) isInsideCylinder = 1;
215
216 Int_t nCylVol = fOutputHitsEvent->GetNumberOfHitsInsideCylinder(fFid_x0, fFid_x1, fFid_R);
217
218 Double_t enCylVol = fOutputHitsEvent->GetEnergyInCylinder(fFid_x0, fFid_x1, fFid_R);
219
220 SetObservableValue("isInsideCylindricalVolume", isInsideCylinder);
221
222 SetObservableValue("nInsideCylindricalVolume", nCylVol);
223
224 SetObservableValue("energyInsideCylindricalVolume", enCylVol);
225
226 // mean positions
227 SetObservableValue("xMeanInCylinder", meanPositionInCylinder.X());
228
229 SetObservableValue("yMeanInCylinder", meanPositionInCylinder.Y());
230
231 SetObservableValue("zMeanInCylinder", meanPositionInCylinder.Z());
232 }
233
234 // Checking hits inside fiducial prism
235 if (fPrismFiducial) {
236 TVector3 meanPositionInPrism =
237 fOutputHitsEvent->GetMeanPositionInPrism(fFid_x0, fFid_x1, fFid_sX, fFid_sY, fFid_theta);
238
239 Int_t isInsidePrism = 0;
240 if (fOutputHitsEvent->anyHitInsidePrism(fFid_x0, fFid_x1, fFid_sX, fFid_sY, fFid_theta))
241 isInsidePrism = 1;
242
243 Int_t nPrismVol =
244 fOutputHitsEvent->GetNumberOfHitsInsidePrism(fFid_x0, fFid_x1, fFid_sX, fFid_sY, fFid_theta);
245
246 Double_t enPrismVol =
247 fOutputHitsEvent->GetEnergyInPrism(fFid_x0, fFid_x1, fFid_sX, fFid_sY, fFid_theta);
248
249 SetObservableValue("isInsidePrismVolume", isInsidePrism);
250
251 SetObservableValue("nInsidePrismVolume", nPrismVol);
252
253 SetObservableValue("energyInsidePrismVolume", enPrismVol);
254
255 // Mean Positions
256
257 SetObservableValue("xMeanInPrism", meanPositionInPrism.X());
258
259 SetObservableValue("yMeanInPrism", meanPositionInPrism.Y());
260
261 SetObservableValue("zMeanInPrism", meanPositionInPrism.Z());
262 }
263
265
266 if (fCylinderFiducial) {
267 // Adding distances to cylinder wall
268 Double_t dToCylWall =
269 fOutputHitsEvent->GetClosestHitInsideDistanceToCylinderWall(fFid_x0, fFid_x1, fFid_R);
270 Double_t dToCylTop =
271 fOutputHitsEvent->GetClosestHitInsideDistanceToCylinderTop(fFid_x0, fFid_x1, fFid_R);
272 Double_t dToCylBottom =
273 fOutputHitsEvent->GetClosestHitInsideDistanceToCylinderBottom(fFid_x0, fFid_x1, fFid_R);
274
275 SetObservableValue("distanceToCylinderWall", dToCylWall);
276 SetObservableValue("distanceToCylinderTop", dToCylTop);
277 SetObservableValue("distanceToCylinderBottom", dToCylBottom);
278 }
279
280 if (fPrismFiducial) {
281 // Adding distances to prism wall
282 Double_t dToPrismWall = fOutputHitsEvent->GetClosestHitInsideDistanceToPrismWall(
283 fFid_x0, fFid_x1, fFid_sX, fFid_sY, fFid_theta);
284 Double_t dToPrismTop = fOutputHitsEvent->GetClosestHitInsideDistanceToPrismTop(
285 fFid_x0, fFid_x1, fFid_sX, fFid_sY, fFid_theta);
286 Double_t dToPrismBottom = fOutputHitsEvent->GetClosestHitInsideDistanceToPrismBottom(
287 fFid_x0, fFid_x1, fFid_sX, fFid_sY, fFid_theta);
288
289 SetObservableValue("distanceToPrismWall", dToPrismWall);
290
291 SetObservableValue("distanceToPrismTop", dToPrismTop);
292
293 SetObservableValue("distanceToPrismBottom", dToPrismBottom);
294 }
295
297
298 SetObservableValue("energy", energy);
299 SetObservableValue("energyX", energyX);
300 SetObservableValue("energyY", energyY);
301 SetObservableValue("balanceXYenergy", (energyX - energyY) / (energyX + energyY));
302
303 SetObservableValue("maxHitEnergy", maxEnergy);
304 SetObservableValue("minHitEnergy", minEnergy);
305 SetObservableValue("meanHitEnergy", meanEnergy);
306 SetObservableValue("meanHitEnergyBalance", meanEnergy / energy);
307
308 SetObservableValue("xMean", meanPosition.X());
309
310 SetObservableValue("yMean", meanPosition.Y());
311
312 SetObservableValue("zMean", meanPosition.Z());
313 SetObservableValue("xy2Sigma", sigmaXY2);
314 SetObservableValue("xSigma", sigmaX);
315 SetObservableValue("ySigma", sigmaY);
316 SetObservableValue("xySigmaBalance", (sigmaX - sigmaY) / (sigmaX + sigmaY));
317
318 SetObservableValue("z2Sigma", sigmaZ2);
319
320 SetObservableValue("xySkew", skewXY);
321 SetObservableValue("zSkew", skewZ);
322
324 fOutputHitsEvent->PrintEvent(1000);
325 GetChar();
326 }
327
328 if (fOutputHitsEvent->GetNumberOfHits() == 0) return nullptr;
329
330 return fOutputHitsEvent;
331}
332
334 // Function to be executed once at the end of the process
335 // (after all events have been processed)
336
337 // Start by calling the EndProcess function of the abstract class.
338 // Comment this if you don't want it.
339 // TRestEventProcess::EndProcess();
340}
341
343 fFid_x0 = Get3DVectorParameterWithUnits("fiducial_x0", TVector3(0, 0, 0));
344 fFid_x1 = Get3DVectorParameterWithUnits("fiducial_x1", TVector3(0, 0, 0));
345
346 fFid_R = GetDblParameterWithUnits("fiducial_R", 1);
347 fFid_sX = GetDblParameterWithUnits("fiducial_sX", 1);
348 fFid_sY = GetDblParameterWithUnits("fiducial_sY", 1);
349 // read angle in degrees
350 fFid_theta = StringToDouble(GetParameter("fiducial_theta", "0"));
351 // convert it into radians for internal usage
352 fFid_theta = std::fmod(fFid_theta, 360) * TMath::DegToRad();
353
354 if (GetParameter("cylinderFiducialization", "false") == "true") fCylinderFiducial = true;
355
356 if (GetParameter("prismFiducialization", "false") == "true") fPrismFiducial = true;
357}
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.
Double_t StringToDouble(std::string in)
Gets a double from a string.