REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
Loading...
Searching...
No Matches
TRestHits.h
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
23#ifndef TRestSoft_TRestHits
24#define TRestSoft_TRestHits
25
26#include <TCanvas.h>
27#include <TF1.h>
28#include <TGraphErrors.h>
29#include <TH1.h>
30#include <TMath.h>
31#include <TMatrixD.h>
32#include <TVector3.h>
33
34#include <iostream>
35
36enum REST_HitType { unknown = -1, X = 2, Y = 3, Z = 5, XY = 6, XZ = 10, YZ = 15, XYZ = 30, VETO = 100 };
37
39class TRestHits {
40 protected:
41 // TODO: This is no longer used, it should be removed
42 size_t fNHits = 0;
43 // TODO: This is no longer used, it should be removed
44 Double_t fTotalEnergy = 0;
45
47 std::vector<Float_t> fX; // [fNHits]
48
50 std::vector<Float_t> fY; // [fNHits]
51
53 std::vector<Float_t> fZ; // [fNHits]
54
56 std::vector<Float_t> fTime; // [fNHits]
57
59 std::vector<Float_t> fEnergy; // [fNHits]
60
62 std::vector<REST_HitType> fType;
63
64 public:
65 void Translate(Int_t n, Double_t x, Double_t y, Double_t z);
66 void RotateIn3D(Int_t n, Double_t alpha, Double_t beta, Double_t gamma, const TVector3& center);
67 void Rotate(Int_t n, Double_t alpha, const TVector3& vAxis, const TVector3& vMean);
68
69 void AddHit(const TVector3& position, Double_t energy, Double_t time = 0, REST_HitType type = XYZ);
70 void AddHit(TRestHits& hits, Int_t n);
71
72 Int_t GetMostEnergeticHitInRange(Int_t n, Int_t m) const;
73
74 Double_t GetMaximumHitDistance() const;
75 Double_t GetMaximumHitDistance2() const;
76
77 virtual void RemoveHits();
78 virtual void MergeHits(int n, int m);
79 virtual void SwapHits(Int_t i, Int_t j);
80 virtual void RemoveHit(int n);
81
82 virtual Bool_t areXY() const;
83 virtual Bool_t areXZ() const;
84 virtual Bool_t areYZ() const;
85 virtual Bool_t areXYZ() const;
86
87 Bool_t isNaN(Int_t n) const;
88
89 Double_t GetDistanceToNode(Int_t n) const;
90
91 Bool_t isSortedByEnergy() const;
92
93 inline size_t GetNumberOfHits() const { return fEnergy.size(); }
94
95 inline const std::vector<Float_t>& GetX() const { return fX; }
96 inline const std::vector<Float_t>& GetY() const { return fY; }
97 inline const std::vector<Float_t>& GetZ() const { return fZ; }
98 inline const std::vector<Float_t>& GetTime() const { return fTime; }
99 inline const std::vector<Float_t>& GetEnergyVector() const { return fEnergy; }
100
101 inline Double_t GetX(int n) const { return fX[n]; } // return value in mm
102 inline Double_t GetY(int n) const { return fY[n]; } // return value in mm
103 inline Double_t GetZ(int n) const { return fZ[n]; } // return value in mm
104 inline Double_t GetTime(int n) const { return fTime[n]; } // return value in us
105 inline Double_t GetEnergy(int n) const { return fEnergy[n]; } // return value in keV
106
107 inline REST_HitType GetType(int n) const { return fType[n]; }
108
109 TVector3 GetPosition(int n) const;
110 TVector3 GetVector(int i, int j) const;
111
112 Int_t GetNumberOfHitsX() const;
113 Int_t GetNumberOfHitsY() const;
114
115 Double_t GetMeanPositionX() const;
116 Double_t GetMeanPositionY() const;
117 Double_t GetMeanPositionZ() const;
118 TVector3 GetMeanPosition() const;
119
120 Double_t GetSigmaXY2() const;
121 Double_t GetSigmaX() const;
122 Double_t GetSigmaY() const;
123 Double_t GetSigmaZ2() const;
124 Double_t GetSkewXY() const;
125 Double_t GetSkewZ() const;
126
127 Double_t GetGaussSigmaX(Double_t error = 150.0, Int_t nHitsMin = 100000);
128 Double_t GetGaussSigmaY(Double_t error = 150.0, Int_t nHitsMin = 100000);
129 Double_t GetGaussSigmaZ(Double_t error = 150.0, Int_t nHitsMin = 100000);
130
131 Double_t GetEnergyX() const;
132 Double_t GetEnergyY() const;
133
134 Bool_t isHitNInsidePrism(Int_t n, const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY,
135 Double_t theta) const;
136 Int_t GetNumberOfHitsInsidePrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY,
137 Double_t theta) const;
138 Double_t GetEnergyInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY,
139 Double_t theta) const;
140 Double_t GetMeanPositionXInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY,
141 Double_t theta) const;
142 Double_t GetMeanPositionYInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY,
143 Double_t theta) const;
144 Double_t GetMeanPositionZInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY,
145 Double_t theta) const;
146 TVector3 GetMeanPositionInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY,
147 Double_t theta) const;
148
149 Bool_t isHitNInsideCylinder(Int_t n, const TVector3& x0, const TVector3& x1, Double_t radius) const;
150
151 Int_t GetNumberOfHitsInsideCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const;
152 Int_t GetNumberOfHitsInsideCylinder(Int_t i, Int_t j, Double_t radius) const;
153
154 Double_t GetEnergyInCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const;
155 Double_t GetEnergyInCylinder(Int_t i, Int_t j, Double_t radius) const;
156 Double_t GetMeanPositionXInCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const;
157 Double_t GetMeanPositionYInCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const;
158 Double_t GetMeanPositionZInCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const;
159 TVector3 GetMeanPositionInCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const;
160
161 Bool_t isHitNInsideSphere(Int_t n, const TVector3& pos0, Double_t radius) const;
162 Bool_t isHitNInsideSphere(Int_t n, Double_t x0, Double_t y0, Double_t z0, Double_t radius) const;
163
164 Double_t GetEnergyInSphere(const TVector3& pos0, Double_t radius) const;
165 Double_t GetEnergyInSphere(Double_t x, Double_t y, Double_t z, Double_t radius) const;
166
167 Double_t GetMaximumHitEnergy() const;
168 Double_t GetMinimumHitEnergy() const;
169 Double_t GetMeanHitEnergy() const;
170
171 Double_t GetTotalEnergy() const;
172 Double_t GetDistance2(int n, int m) const;
173 inline Double_t GetDistance(int N, int M) const { return TMath::Sqrt(GetDistance2(N, M)); }
174 Double_t GetTotalDistance() const;
175
176 Double_t GetHitsPathLength(Int_t n = 0, Int_t m = 0) const;
177
178 Double_t GetHitsTwist(Int_t n, Int_t m) const;
179 Double_t GetHitsTwistWeighted(Int_t n, Int_t m) const;
180
181 Int_t GetClosestHit(const TVector3& position) const;
182
183 TVector2 GetProjection(Int_t n, Int_t m, const TVector3& position) const;
184
185 Double_t GetTransversalProjection(const TVector3& p0, const TVector3& direction,
186 const TVector3& position) const;
187
188 void WriteHitsToTextFile(TString filename);
189
190 static void GetBoundaries(std::vector<double>& val, double& max, double& min, int& nBins,
191 double offset = 10);
192
193 virtual void PrintHits(Int_t nHits = -1) const;
194
196 public:
197 using iterator_category = std::random_access_iterator_tag;
199 using difference_type = int;
200 using pointer = void;
201 using reference = void;
202
203 private:
204 int maxIndex = 0;
205 int index = 0;
206 TRestHits* fHits = nullptr;
207 bool isAccessor = false;
208 float _x;
209 float _y;
210 float _z;
211 float _t;
212 float _e;
213 REST_HitType _type;
214
215 public:
216 float& x() { return isAccessor ? _x : fHits->fX[index]; }
217 float& y() { return isAccessor ? _y : fHits->fY[index]; }
218 float& z() { return isAccessor ? _z : fHits->fZ[index]; }
219 float& t() { return isAccessor ? _t : fHits->fTime[index]; }
220 float& e() { return isAccessor ? _e : fHits->fEnergy[index]; }
221 REST_HitType& type() { return isAccessor ? _type : fHits->fType[index]; }
222
223 float x() const { return isAccessor ? _x : fHits->fX[index]; }
224 float y() const { return isAccessor ? _y : fHits->fY[index]; }
225 float z() const { return isAccessor ? _z : fHits->fZ[index]; }
226 float t() const { return isAccessor ? _t : fHits->fTime[index]; }
227 float e() const { return isAccessor ? _e : fHits->fEnergy[index]; }
228 REST_HitType type() const { return isAccessor ? _type : fHits->fType[index]; }
229
230 // accessor: hit data is copied to self. The class acts like "TRestHit"
231 void toaccessor();
232
233 TRestHits_Iterator operator*() const;
234 TRestHits_Iterator& operator++();
235 TRestHits_Iterator& operator+=(const int& n);
236 TRestHits_Iterator operator+(const int& n);
237 TRestHits_Iterator& operator--();
238 TRestHits_Iterator& operator-=(const int& n);
239 TRestHits_Iterator operator-(const int& n);
240 TRestHits_Iterator& operator=(const TRestHits_Iterator& iter);
241
242 friend int operator-(const TRestHits_Iterator& i1, const TRestHits_Iterator& i2) {
243 return i1.index - i2.index;
244 }
245 friend bool operator==(const TRestHits_Iterator& i1, const TRestHits_Iterator& i2) {
246 return i1.fHits == i2.fHits && i1.index == i2.index;
247 }
248 friend bool operator!=(const TRestHits_Iterator& i1, const TRestHits_Iterator& i2) {
249 return i1.fHits != i2.fHits || i1.index != i2.index;
250 }
251 friend bool operator>(const TRestHits_Iterator& i1, const TRestHits_Iterator& i2) {
252 // default comparison logic
253 return i1.index > i2.index;
254 }
255 friend bool operator>=(const TRestHits_Iterator& i1, const TRestHits_Iterator& i2) {
256 // default comparison logic
257 return i1.index >= i2.index;
258 }
259 friend bool operator<(const TRestHits_Iterator& i1, const TRestHits_Iterator& i2) {
260 return i1.index < i2.index;
261 }
262 friend bool operator<=(const TRestHits_Iterator& i1, const TRestHits_Iterator& i2) {
263 return i1.index <= i2.index;
264 }
266 if (i1.fHits == i2.fHits) {
267 i1.fHits->SwapHits(i1.index, i2.index);
268 }
269 }
270
271 TRestHits_Iterator(TRestHits* h, int _index);
272 };
273 inline TRestHits_Iterator begin() { return {this, 0}; }
274 inline TRestHits_Iterator end() { return {this, static_cast<int>(GetNumberOfHits())}; }
275 typedef TRestHits_Iterator iterator;
276
279
280 ClassDef(TRestHits, 6);
281};
282
283#endif
It saves a 3-coordinate position and an energy for each punctual deposition.
Definition TRestHits.h:39
TVector3 GetVector(int i, int j) const
It returns the vector that goes from hit j to hit i.
virtual Bool_t areXYZ() const
It will return true only if all the hits inside are of type XYZ.
Double_t GetEnergyX() const
It calculates the total energy of hits with a valid X coordinate.
Double_t GetDistanceToNode(Int_t n) const
It determines the distance required to travel from the first hit to the hit n adding all the distance...
virtual Bool_t areYZ() const
It will return true only if all the hits inside are of type YZ.
void Rotate(Int_t n, Double_t alpha, const TVector3 &vAxis, const TVector3 &vMean)
It rotates hit n by an angle akpha along the vAxis with center at vMean.
virtual Bool_t areXY() const
It will return true only if all the hits inside are of type XY.
Double_t GetMaximumHitEnergy() const
It returns the maximum hit energy.
Int_t GetNumberOfHitsInsidePrism(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines the total number of hits contained inside a prisma delimited between x0 and y0 vertex,...
Double_t GetMeanPositionZ() const
It calculates the mean Z position weighting with the energy of the hits with a valid Z coordinate.
Double_t GetMeanPositionX() const
It calculates the mean X position weighting with the energy of the hits with a valid X coordinate.
Double_t GetSkewXY() const
It returns the 2-dimensional skewness on the XY-plane which is a measure of the hits distribution asy...
Double_t GetHitsTwistWeighted(Int_t n, Int_t m) const
Same as GetHitsTwist but weighting with the energy.
TVector3 GetMeanPosition() const
It calculates the mean position weighting with the energy of the hits. Each coordinate is calculated ...
Double_t GetMeanPositionY() const
It calculates the mean Y position weighting with the energy of the hits with a valid Y coordinate.
virtual void RemoveHits()
It removes all hits inside the class.
Double_t GetMeanHitEnergy() const
It returns the mean hits energy.
Double_t GetTotalDistance() const
It determines the distance required to travel from the first to the last hit adding all the distances...
TVector3 GetMeanPositionInCylinder(const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines the mean position using the hits contained inside a cylinder with a given radius and de...
Double_t GetGaussSigmaX(Double_t error=150.0, Int_t nHitsMin=100000)
It computes the gaussian sigma in the X-coordinate. It adds a hit to the right and a hit to the left,...
Double_t GetMeanPositionYInPrism(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines the mean Y position of hits contained inside a prisma delimited between x0 and x1 verte...
virtual void MergeHits(int n, int m)
It merges hits n and m being the resulting hit placed at the weighted center and being its final ener...
static void GetBoundaries(std::vector< double > &val, double &max, double &min, int &nBins, double offset=10)
TODO This method is not using any TRestHits member. This probably means that it should be placed some...
Bool_t isSortedByEnergy() const
It returns true if the hits are ordered in increasing energies.
Double_t GetSigmaX() const
It calculates the hits standard deviation in the X-coordinate.
Double_t GetTransversalProjection(const TVector3 &p0, const TVector3 &direction, const TVector3 &position) const
It returns the transversal projection of position to the line defined by position and direction.
Double_t GetEnergyInCylinder(const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines the total energy contained inside a cylinder with a given radius and delimited between ...
virtual void RemoveHit(int n)
It removes the hit at position n from the list.
std::vector< REST_HitType > fType
The type of hit X,Y,XY,XYZ, ...
Definition TRestHits.h:62
std::vector< Float_t > fZ
Position on Z axis for each punctual deposition (units mm)
Definition TRestHits.h:53
Double_t GetEnergyY() const
It calculates the total energy of hits with a valid Y coordinate.
Bool_t isHitNInsidePrism(Int_t n, const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines if hit n is contained inside a prisma delimited between x0 and y0 vertex,...
Double_t GetMeanPositionZInPrism(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines the mean Z position of hits contained inside a prisma delimited between x0 and x1 verte...
Double_t GetMeanPositionXInCylinder(const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines the mean position X using the hits contained inside a cylinder with a given radius and ...
Double_t GetHitsTwist(Int_t n, Int_t m) const
A parameter measuring how straight is a given sequence of hits. If the value is close to zero,...
Double_t GetMeanPositionXInPrism(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines the mean X position of hits contained inside a prisma delimited between x0 and x1 verte...
std::vector< Float_t > fY
Position on Y axis for each punctual deposition (units mm)
Definition TRestHits.h:50
std::vector< Float_t > fX
Position on X axis for each punctual deposition (units mm)
Definition TRestHits.h:47
Double_t GetEnergyInSphere(const TVector3 &pos0, Double_t radius) const
It determines the total energy contained in a sphere with position pos0 for a given spherical radius.
Double_t GetGaussSigmaZ(Double_t error=150.0, Int_t nHitsMin=100000)
It computes the gaussian sigma in the Z-coordinate. It adds a hit to the right and a hit to the left,...
Int_t GetMostEnergeticHitInRange(Int_t n, Int_t m) const
It returns the most energetic hit found between hits n and m.
Double_t GetEnergyInPrism(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines the total hit energy contained inside a prisma delimited between x0 and y0 vertex,...
void WriteHitsToTextFile(TString filename)
It writes the hits to a plain text file.
~TRestHits()
Default destructor.
std::vector< Float_t > fEnergy
Energy deposited at each 3-coordinate position (units keV)
Definition TRestHits.h:59
void AddHit(const TVector3 &position, Double_t energy, Double_t time=0, REST_HitType type=XYZ)
Adds a new hit to the list of hits using a TVector3.
TVector2 GetProjection(Int_t n, Int_t m, const TVector3 &position) const
It returns the longitudinal and transversal projections of position to the axis defined by the hits n...
Double_t GetGaussSigmaY(Double_t error=150.0, Int_t nHitsMin=100000)
It computes the gaussian sigma in the Y-coordinate. It adds a hit to the right and a hit to the left,...
std::vector< Float_t > fTime
Absolute time information for each punctual deposition (units us, 0 is time of decay)
Definition TRestHits.h:56
TRestHits()
Default constructor.
virtual Bool_t areXZ() const
It will return true only if all the hits inside are of type XZ.
Int_t GetClosestHit(const TVector3 &position) const
It returns the closest hit to a given position.
size_t fNHits
Number of punctual energy depositions, it is the length for all the arrays.
Definition TRestHits.h:42
void RotateIn3D(Int_t n, Double_t alpha, Double_t beta, Double_t gamma, const TVector3 &center)
It rotates hit n following rotations in Z, Y and X by angles gamma, beta and alpha....
Double_t fTotalEnergy
Event total energy.
Definition TRestHits.h:44
Int_t GetNumberOfHitsInsideCylinder(const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines the total number of hits contained inside a cylinder with a given radius and delimited ...
Double_t GetSigmaZ2() const
It returns the hits distribution variance on the Z-axis.
Bool_t isHitNInsideCylinder(Int_t n, const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines if hit n is contained inside a cylinder with a given radius and delimited between x0 an...
Double_t GetSkewZ() const
It returns the hits distribution skewness, or asymmetry on the Z-axis.
TVector3 GetMeanPositionInPrism(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines the mean position of hits contained inside a prisma delimited between x0 and x1 vertex,...
Double_t GetSigmaY() const
It calculates the hits standard deviation in the Y-coordinate.
virtual void SwapHits(Int_t i, Int_t j)
It exchanges hits n and m affecting to the ordering of the hits inside the list of hits.
Bool_t isNaN(Int_t n) const
It will return true only if all the 3-coordinates of hit number n are not a number,...
Double_t GetMaximumHitDistance() const
It returns the maximum distance between 2-hits.
Double_t GetDistance2(int n, int m) const
It returns the euclidian distance between hits n and m.
TVector3 GetPosition(int n) const
It returns the position of hit number n.
virtual void PrintHits(Int_t nHits=-1) const
It prints on screen the first nHits from the list.
Double_t GetMaximumHitDistance2() const
It returns the maximum squared distance between 2-hits.
Double_t GetSigmaXY2() const
It calculates the 2-dimensional hits variance.
Double_t GetMinimumHitEnergy() const
It returns the minimum hit energy.
Int_t GetNumberOfHitsY() const
It returns the number of hits with a valid Y coordinate.
void Translate(Int_t n, Double_t x, Double_t y, Double_t z)
It moves hit n by a given amount (x,y,z).
Bool_t isHitNInsideSphere(Int_t n, const TVector3 &pos0, Double_t radius) const
It determines if the hit n is contained in a sphere with position pos0 for a given sphereical radius.
Int_t GetNumberOfHitsX() const
It returns the number of hits with a valid X coordinate.
Double_t GetHitsPathLength(Int_t n=0, Int_t m=0) const
It determines the distance required to travel from hit n to hit m adding all the distances of the hit...
Double_t GetMeanPositionYInCylinder(const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines the mean position Y using the hits contained inside a cylinder with a given radius and ...
Double_t GetMeanPositionZInCylinder(const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines the mean position Z using the hits contained inside a cylinder with a given radius and ...