REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestMesh.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 RestCore_TRestMesh
24#define RestCore_TRestMesh
25
26#include <TObject.h>
27#include <TVector3.h>
28
29#include <iostream>
30
31#include "TRestHits.h"
32
33constexpr int NODE_NOT_SET = -1;
34constexpr int GROUP_NOT_FOUND = -1;
35constexpr int NODE_NOT_FOUND = -1;
36
38class TRestMesh : public TObject {
39 protected:
41 TVector3 fNetOrigin = TVector3(0, 0, 0);
42
44 Double_t fNetSizeX = 0;
46 Double_t fNetSizeY = 0;
48 Double_t fNetSizeZ = 0;
49
51 Int_t fNodesX = 0;
53 Int_t fNodesY = 0;
55 Int_t fNodesZ = 0;
56
58 Int_t fNumberOfNodes = 0;
60 Int_t fNumberOfGroups = 0;
61
63 std::vector<Int_t> fNodeGroupID;
65 std::vector<Int_t> fNodeX;
67 std::vector<Int_t> fNodeY;
69 std::vector<Int_t> fNodeZ;
70
72 std::vector<Double_t> fEnergy;
73
75 Bool_t fIsCylindrical = false;
77 Bool_t fIsSpherical = false;
78
79 public:
80 Double_t GetX(Int_t nX);
81 Double_t GetY(Int_t nY);
82 Double_t GetZ(Int_t nZ);
83
85 inline Int_t GetNumberOfNodes() const { return fNumberOfNodes; }
87 inline Int_t GetNumberOfGroups() const { return fNumberOfGroups; }
88
89 TVector3 GetPosition(Int_t nX, Int_t nY, Int_t nZ);
90
91 Int_t GetNodeX(Double_t x, Bool_t relative = false);
92 Int_t GetNodeY(Double_t y, Bool_t relative = false);
93 Int_t GetNodeZ(Double_t z, Bool_t relative = false);
94
95 Int_t GetNodeX(TVector3 v, Bool_t relative = false);
96 Int_t GetNodeY(TVector3 v, Bool_t relative = false);
97 Int_t GetNodeZ(TVector3 v, Bool_t relative = false);
98
100 Bool_t IsCylindrical() { return fIsCylindrical; }
102 Bool_t IsSpherical() { return fIsSpherical; }
103
105 TVector3 GetNodeByIndex(Int_t index) {
106 TVector3 node(fNodeX[index], fNodeY[index], fNodeZ[index]);
107 return node;
108 }
109
111 Double_t GetEnergyAtNode(Int_t nx, Int_t ny, Int_t nz) { return fEnergy[GetNodeIndex(nx, ny, nz)]; }
112
113 void SetNodesFromHits(TRestHits* hits);
115 void Regrouping();
116
117 Int_t GetNodeIndex(Int_t nx, Int_t ny, Int_t nz);
118
119 Int_t GetGroupId(Double_t x, Double_t y, Double_t z);
120 Int_t GetGroupId(Int_t index);
121
122 Double_t GetGroupEnergy(Int_t index);
123 TVector3 GetGroupPosition(Int_t index);
124
125 Int_t FindNeighbourGroup(Int_t nx, Int_t ny, Int_t nz);
126 Int_t FindForeignNeighbour(Int_t nx, Int_t ny, Int_t nz);
127
128 void SetOrigin(Double_t oX, Double_t oY, Double_t oZ);
129 void SetOrigin(TVector3 pos);
130
131 void SetSize(Double_t sX, Double_t sY, Double_t sZ);
132
133 void SetNodes(Int_t nX, Int_t nY, Int_t nZ);
134
136 void SetCylindrical(Bool_t v) { fIsCylindrical = v; }
137
139 void SetSpherical(Bool_t v) {
140 if (v && (fNetSizeX != fNetSizeY || fNetSizeY != fNetSizeZ))
141 std::cout << "Warning!! The net size should be the same in X, Y and Z for spherical net!"
142 << std::endl;
143
144 fIsSpherical = v;
145 }
146
148 inline Int_t GetNodesX() const { return fNodesX; }
150 inline Int_t GetNodesY() const { return fNodesY; }
152 inline Int_t GetNodesZ() const { return fNodesZ; }
153
155 inline Double_t GetNetSizeX() const { return fNetSizeX; }
157 inline Double_t GetNetSizeY() const { return fNetSizeY; }
159 inline Double_t GetNetSizeZ() const { return fNetSizeZ; }
160
162 inline TVector3 GetOrigin() const { return fNetOrigin; }
164 inline TVector3 GetNetSize() const { return {fNetSizeX, fNetSizeY, fNetSizeZ}; }
165 TVector3 GetNetCenter();
166 TVector3 GetVertex(Int_t id) const;
167
169 inline TVector3 GetBottomVertex() const { return GetVertex(0); }
171 inline TVector3 GetTopVertex() const { return GetVertex(1); }
172
173 void AddNode(Double_t x, Double_t y, Double_t z, Double_t en = 0);
174 void AddSphericalNode(Double_t x, Double_t y, Double_t z, Double_t en = 0);
175
176 void RemoveNodes();
177
178 Bool_t IsInside(TVector3 pos);
179 Bool_t IsInsideBoundingBox(TVector3 pos);
180
181 std::vector<TVector3> GetTrackBoundaries(TVector3 pos, TVector3 dir, Bool_t particle = true);
182 std::vector<TVector3> GetTrackBoundariesCylinder(TVector3 pos, TVector3 dir, Bool_t particle = true);
183
184 void Print();
185
186 // Constructor
187 TRestMesh();
188
189 TRestMesh(Double_t size, Int_t nodes);
190 TRestMesh(TVector3 size, TVector3 position, Int_t nx, Int_t ny, Int_t nz);
191 // Destructor
192 ~TRestMesh();
193
194 ClassDef(TRestMesh, 2);
195};
196#endif
It saves a 3-coordinate position and an energy for each punctual deposition.
Definition: TRestHits.h:39
A basic class inheriting from TObject to help creating a node grid definition.
Definition: TRestMesh.h:38
void SetSize(Double_t sX, Double_t sY, Double_t sZ)
Sets the origin of the bounding-box and initializes the nodes vector to zero.
Definition: TRestMesh.cxx:527
TVector3 GetVertex(Int_t id) const
It returns the position of both boundary vertex, bottom vertex identified with id = 0 and top vertex ...
Definition: TRestMesh.cxx:684
std::vector< TVector3 > GetTrackBoundaries(TVector3 pos, TVector3 dir, Bool_t particle=true)
Finds the intersection of the straight line (track defined by the input arguments given,...
Definition: TRestMesh.cxx:710
void SetSpherical(Bool_t v)
Sets the coordinate system to spherical.
Definition: TRestMesh.h:139
void RemoveNodes()
It initializes all node vectors to zero.
Definition: TRestMesh.cxx:621
Bool_t IsInside(TVector3 pos)
It returns true if the position is found inside the grid (box,sphere or cylinder).
Definition: TRestMesh.cxx:633
Int_t FindNeighbourGroup(Int_t nx, Int_t ny, Int_t nz)
Returns the group id of the first node identified in the neighbour cell from cell=(nx,...
Definition: TRestMesh.cxx:466
Int_t GetNodeY(Double_t y, Bool_t relative=false)
Gets the node index corresponding to the y-coordinate.
Definition: TRestMesh.cxx:214
TRestMesh()
Default constructor.
Definition: TRestMesh.cxx:72
std::vector< Int_t > fNodeY
A std::vector storing the Y-dimension cell id.
Definition: TRestMesh.h:67
TVector3 GetNetSize() const
Returns a std::vector with the size/dimensions of the bounding box.
Definition: TRestMesh.h:164
Int_t GetNodeZ(Double_t z, Bool_t relative=false)
Gets the node index corresponding to the z-coordinate.
Definition: TRestMesh.cxx:268
void SetNodesFromSphericalHits(TRestHits *hits)
It initializes the nodes using the hit coordinates found inside a TRestHits structure....
Definition: TRestMesh.cxx:335
Double_t fNetSizeZ
The size of the grid in Z dimension.
Definition: TRestMesh.h:48
Double_t GetY(Int_t nY)
Gets the cartesian position of nodeY.
Definition: TRestMesh.cxx:121
void SetOrigin(Double_t oX, Double_t oY, Double_t oZ)
Sets the origin of the bounding-box and initializes the nodes vector to zero.
Definition: TRestMesh.cxx:507
void Regrouping()
Needs TO BE documented.
Definition: TRestMesh.cxx:350
void AddSphericalNode(Double_t x, Double_t y, Double_t z, Double_t en=0)
If adds corresponding node to xyz-coordinates if not previously defined.
Definition: TRestMesh.cxx:588
Int_t fNodesX
Number of nodes in X-dimension (R in spherical coordinates)
Definition: TRestMesh.h:51
Int_t GetNodeIndex(Int_t nx, Int_t ny, Int_t nz)
Returns the vector position for a given node index. If the node is not found, -1 will be returned.
Definition: TRestMesh.cxx:393
Int_t GetNodesZ() const
Returns the number of nodes defined in the Z-dimension.
Definition: TRestMesh.h:152
std::vector< Int_t > fNodeZ
A std::vector storing the Z-dimension cell id.
Definition: TRestMesh.h:69
Int_t GetNodesX() const
Returns the number of nodes defined in the X-dimension.
Definition: TRestMesh.h:148
std::vector< Int_t > fNodeX
A std::vector storing the X-dimension cell id.
Definition: TRestMesh.h:65
Int_t fNumberOfGroups
Total number of groups found.
Definition: TRestMesh.h:60
std::vector< TVector3 > GetTrackBoundariesCylinder(TVector3 pos, TVector3 dir, Bool_t particle=true)
Needs TO BE documented.
Definition: TRestMesh.cxx:794
void AddNode(Double_t x, Double_t y, Double_t z, Double_t en=0)
If adds corresponding node to xyz-coordinates if not previously defined.
Definition: TRestMesh.cxx:551
Int_t fNumberOfNodes
Total number of nodes filled.
Definition: TRestMesh.h:58
TVector3 GetGroupPosition(Int_t index)
It returns the average position for all nodes weighted with their corresponding energy.
Definition: TRestMesh.cxx:448
Int_t GetNumberOfNodes() const
Returns the total number of nodes added.
Definition: TRestMesh.h:85
Double_t fNetSizeX
The size of the grid in X dimension.
Definition: TRestMesh.h:44
TVector3 GetBottomVertex() const
It returns the bottom boundary vertex.
Definition: TRestMesh.h:169
void SetCylindrical(Bool_t v)
Sets the coordinate system to cylindrical.
Definition: TRestMesh.h:136
TVector3 GetTopVertex() const
It returns the top boundary vertex.
Definition: TRestMesh.h:171
Int_t FindForeignNeighbour(Int_t nx, Int_t ny, Int_t nz)
It identifies a foreign neighbour. I.e. if the group id of the neighbour cell is different to the cel...
Definition: TRestMesh.cxx:485
Bool_t IsSpherical()
Returns true if the coordinate system is set to spherical.
Definition: TRestMesh.h:102
Bool_t fIsCylindrical
A flag to indentify if we use cylindrical coordinates.
Definition: TRestMesh.h:75
Int_t fNodesZ
Number of nodes in Z-dimension (Phi in spherical coordinates)
Definition: TRestMesh.h:55
Int_t GetNodesY() const
Returns the number of nodes defined in the Y-dimension.
Definition: TRestMesh.h:150
Double_t GetNetSizeZ() const
Returns the net size on Z-dimension.
Definition: TRestMesh.h:159
Bool_t IsInsideBoundingBox(TVector3 pos)
It returns true if the position is found inside the bounding box.
Definition: TRestMesh.cxx:665
Int_t fNodesY
Number of nodes in Y-dimension (Theta in spherical coordinates)
Definition: TRestMesh.h:53
TVector3 GetOrigin() const
Returns the origin of the grid (bottom-left corner)
Definition: TRestMesh.h:162
Double_t GetNetSizeX() const
Returns the net size on X-dimension.
Definition: TRestMesh.h:155
void SetNodesFromHits(TRestHits *hits)
It initializes the nodes using the hit coordinates found inside a TRestHits structure.
Definition: TRestMesh.cxx:318
TVector3 GetNetCenter()
It returns the position of the mesh center.
Definition: TRestMesh.cxx:676
void Print()
Prints the nodes information.
Definition: TRestMesh.cxx:875
Double_t GetGroupEnergy(Int_t index)
It returns the total energy of all nodes corresponding to the group id given by argument.
Definition: TRestMesh.cxx:435
Int_t GetNodeX(Double_t x, Bool_t relative=false)
Gets the node index corresponding to the x-coordinate.
Definition: TRestMesh.cxx:160
Double_t GetZ(Int_t nZ)
Gets the cartesian position of nodeZ.
Definition: TRestMesh.cxx:126
TVector3 GetNodeByIndex(Int_t index)
Returns a node by its position in the std::vector.
Definition: TRestMesh.h:105
TVector3 fNetOrigin
The bottom-left corner of the bounding-box grid.
Definition: TRestMesh.h:41
Int_t GetGroupId(Double_t x, Double_t y, Double_t z)
Returns the group id corresponding to the x,y,z coordinate. If the coordinate falls at a non-initiali...
Definition: TRestMesh.cxx:404
Bool_t IsCylindrical()
Returns true if the coordinate system is set to cylindrical.
Definition: TRestMesh.h:100
std::vector< Int_t > fNodeGroupID
A std::vector storing the group ID of the corresponding nodes activated.
Definition: TRestMesh.h:63
Double_t GetEnergyAtNode(Int_t nx, Int_t ny, Int_t nz)
Returns the energy at a particular node.
Definition: TRestMesh.h:111
Int_t GetNumberOfGroups() const
Returns the total number of groups identified.
Definition: TRestMesh.h:87
Double_t fNetSizeY
The size of the grid in Y dimension.
Definition: TRestMesh.h:46
void SetNodes(Int_t nX, Int_t nY, Int_t nZ)
Sets the number of nodes and initializes the nodes vector to zero.
Definition: TRestMesh.cxx:539
Bool_t fIsSpherical
A flag to indentify if we use spherical coordinates.
Definition: TRestMesh.h:77
Double_t GetX(Int_t nX)
Gets the cartesian position of nodeX.
Definition: TRestMesh.cxx:116
std::vector< Double_t > fEnergy
A std::vector storing the total energy inside the cell id.
Definition: TRestMesh.h:72
Double_t GetNetSizeY() const
Returns the net size on Y-dimension.
Definition: TRestMesh.h:157
TVector3 GetPosition(Int_t nX, Int_t nY, Int_t nZ)
Gets the position of the corresponding node.
Definition: TRestMesh.cxx:131
~TRestMesh()
Default destructor.
Definition: TRestMesh.cxx:109