All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbncode/sbncode/GeometryTools/TPCGeoAlg.cc
Go to the documentation of this file.
1 
2 #include "TPCGeoAlg.h"
3 
4 namespace sbn{
5 
6 // Constructor - get values from the geometry service
8 
9  fMinX = 99999;
10  fMinY = 99999;
11  fMinZ = 99999;
12  fMaxX = -99999;
13  fMaxY = -99999;
14  fMaxZ = -99999;
15  fCpaWidth = 0;
16 
17  fGeometryService = lar::providerFrom<geo::Geometry>();
18 
19  for(size_t cryo_i = 0; cryo_i < fGeometryService->Ncryostats(); cryo_i++){
20  const geo::CryostatGeo& cryostat = fGeometryService->Cryostat(cryo_i);
21 
22  for (size_t tpc_i = 0; tpc_i < cryostat.NTPC(); tpc_i++)
23  {
24  const geo::TPCGeo& tpcg = cryostat.TPC(tpc_i);
25  if (tpcg.MinX() < fMinX) fMinX = tpcg.MinX();
26  if (tpcg.MaxX() > fMaxX) fMaxX = tpcg.MaxX();
27  if (tpcg.MinY() < fMinY) fMinY = tpcg.MinY();
28  if (tpcg.MaxY() > fMaxY) fMaxY = tpcg.MaxY();
29  if (tpcg.MinZ() < fMinZ) fMinZ = tpcg.MinZ();
30  if (tpcg.MaxZ() > fMaxZ) fMaxZ = tpcg.MaxZ();
31  fCpaWidth = std::min(std::abs(tpcg.MinX()), std::abs(tpcg.MaxX()));
32  }
33  }
34 }
35 
36 
38 
39 }
40 
41 // ----------------------------------------------------------------------------------
42 // Getters
43 double TPCGeoAlg::MinX() const{
44  return fMinX;
45 }
46 
47 double TPCGeoAlg::MinY() const{
48  return fMinY;
49 }
50 
51 double TPCGeoAlg::MinZ() const{
52  return fMinZ;
53 }
54 
55 double TPCGeoAlg::MaxX() const{
56  return fMaxX;
57 }
58 
59 double TPCGeoAlg::MaxY() const{
60  return fMaxY;
61 }
62 
63 double TPCGeoAlg::MaxZ() const{
64  return fMaxZ;
65 }
66 
67 double TPCGeoAlg::CpaWidth() const{
68  return fCpaWidth;
69 }
70 
71 // ----------------------------------------------------------------------------------
72 // Functions for applying fiducial volume cuts to total volume
73 bool TPCGeoAlg::InFiducial(geo::Point_t point, double fiducial){
74  return InFiducial(point, fiducial, fiducial);
75 }
76 
77 bool TPCGeoAlg::InFiducial(geo::Point_t point, double fiducial, double fiducialTop){
78  return InFiducial(point, fiducial, fiducial, fiducial, fiducial, fiducialTop, fiducial);
79 }
80 
81 bool TPCGeoAlg::InFiducial(geo::Point_t point, double minXCut, double minYCut, double minZCut,
82  double maxXCut, double maxYCut, double maxZCut){
83 
84  double xmin = fMinX + minXCut;
85  double xmax = fMaxX - maxXCut;
86  double ymin = fMinY + minYCut;
87  double ymax = fMaxY - maxYCut;
88  double zmin = fMinZ + minZCut;
89  double zmax = fMaxZ - maxZCut;
90 
91  double x = point.X();
92  double y = point.Y();
93  double z = point.Z();
94  if(x>xmin && x<xmax && y>ymin && y<ymax && z>zmin && z<zmax) return true;
95 
96  return false;
97 }
98 
99 // ----------------------------------------------------------------------------------
100 // Determine which TPC a collection of hits is detected in (-1 if multiple)
101 int TPCGeoAlg::DetectedInTPC(std::vector<art::Ptr<recob::Hit>> hits){
102  // Return tpc of hit collection or -1 if in multiple
103  if(hits.size() == 0) return -1;
104  int tpc = hits[0]->WireID().TPC;
105  for(size_t i = 0; i < hits.size(); i++){
106  if((int)hits[i]->WireID().TPC != tpc) return -1;
107  }
108  return tpc;
109 }
110 
111 // Determine the drift direction for a collection of hits (-1, 0 or 1 assuming drift in X)
112 int TPCGeoAlg::DriftDirectionFromHits(std::vector<art::Ptr<recob::Hit>> hits){
113  // If there are no hits then return 0
114  if(hits.size() == 0) return 0;
115 
116  // If the track is stitched (in multiple TPCs) return 0
117  if(DetectedInTPC(hits) == -1) return 0;
118 
119  // Work out the drift direction
120  geo::TPCID tpcID = hits[0]->WireID().asTPCID();
121  const geo::TPCGeo& tpcGeo = fGeometryService->GetElement(tpcID);
122  double driftDirection = tpcGeo.DetectDriftDirection();
123  if(std::abs(driftDirection) != 1) driftDirection = 0;
124  return driftDirection;
125 }
126 
127 // Work out the drift limits for a collection of hits
128 std::pair<double, double> TPCGeoAlg::XLimitsFromHits(std::vector<art::Ptr<recob::Hit>> hits){
129  // If there are no hits then return 0
130  if(hits.size() == 0) return std::make_pair(0, 0);
131 
132  // If the track is stitched (in multiple TPCs) return 0
133  if(DetectedInTPC(hits) == -1) return std::make_pair(0, 0);
134 
135  // Work out the drift direction
136  geo::TPCID tpcID = hits[0]->WireID().asTPCID();
137  const geo::TPCGeo& tpcGeo = fGeometryService->GetElement(tpcID);
138  return std::make_pair(tpcGeo.MinX(), tpcGeo.MaxX());
139 }
140 
141 // Is point inside given TPC
142 bool TPCGeoAlg::InsideTPC(geo::Point_t point, const geo::TPCGeo& tpc, double buffer){
143  if(point.X() < (tpc.MinX()-buffer) || point.X() > (tpc.MaxX()+buffer)
144  || point.Y() < (tpc.MinY()-buffer) || point.Y() > (tpc.MaxY()+buffer)
145  || point.Z() < (tpc.MinZ()-buffer) || point.Z() > (tpc.MaxZ()+buffer)) return false;
146  return true;
147 }
148 
149 // Minimum distance to a TPC wall
151 
152  std::vector<double> dists;
153 
154  dists.push_back(std::abs(point.X() - fMinX));
155  dists.push_back(std::abs(point.X() - fMaxX));
156  dists.push_back(std::abs(point.Y() - fMinY));
157  dists.push_back(std::abs(point.Y() - fMaxY));
158  dists.push_back(std::abs(point.Z() - fMinZ));
159  dists.push_back(std::abs(point.Z() - fMaxZ));
160 
161  std::sort(dists.begin(), dists.end());
162 
163  return dists[0];
164 
165 }
166 
167 // ----------------------------------------------------------------------------------
168 // Determine if a true particle is ever inside the TPC volume
169 bool TPCGeoAlg::InVolume(const simb::MCParticle& particle){
170  for(size_t i = 0; i < particle.NumberTrajectoryPoints(); i++){
171  double x = particle.Vx(i);
172  double y = particle.Vy(i);
173  double z = particle.Vz(i);
174  if(x > fMinX && y > fMinY && z > fMinZ && x < fMaxX && y < fMaxY && z < fMaxZ){
175  return true;
176  }
177  }
178  return false;
179 }
180 
181 // ----------------------------------------------------------------------------------
182 // Determine if a true particle is contained inside the TPC volume
183 bool TPCGeoAlg::IsContained(const simb::MCParticle& particle){
184  for(size_t i = 0; i < particle.NumberTrajectoryPoints(); i++){
185  double x = particle.Vx(i);
186  double y = particle.Vy(i);
187  double z = particle.Vz(i);
188  if(x < fMinX || y < fMinY || z < fMinZ || x > fMaxX || y > fMaxY || z > fMaxZ){
189  return false;
190  }
191  }
192  return true;
193 }
194 
195 // ----------------------------------------------------------------------------------
196 // Determine if a true particle enters the TPC volume
197 bool TPCGeoAlg::EntersVolume(const simb::MCParticle& particle){
198  bool enters = false;
199  bool startOutside = false;
200  bool endOutside = false;
201  for(size_t i = 0; i < particle.NumberTrajectoryPoints(); i++){
202  double x = particle.Vx(i);
203  double y = particle.Vy(i);
204  double z = particle.Vz(i);
205  if(x > fMinX && y > fMinY && z > fMinZ && x < fMaxX && y < fMaxY && z < fMaxZ){
206  enters = true;
207  }
208  else if(i == 0) startOutside = true;
209  else if(i == particle.NumberTrajectoryPoints()-1) endOutside = true;
210  }
211  if(enters && (startOutside || endOutside)) return true;
212  return false;
213 }
214 
215 // ----------------------------------------------------------------------------------
216 // Determine if a true particle crosses the TPC volume
217 bool TPCGeoAlg::CrossesVolume(const simb::MCParticle& particle){
218  bool enters = false;
219  bool startOutside = false;
220  bool endOutside = false;
221  for(size_t i = 0; i < particle.NumberTrajectoryPoints(); i++){
222  double x = particle.Vx(i);
223  double y = particle.Vy(i);
224  double z = particle.Vz(i);
225  if(x > fMinX && y > fMinY && z > fMinZ && x < fMaxX && y < fMaxY && z < fMaxZ){
226  enters = true;
227  }
228  else if(i == 0) startOutside = true;
229  else if(i == particle.NumberTrajectoryPoints()-1) endOutside = true;
230  }
231  if(startOutside && enters && endOutside) return true;
232  return false;
233 }
234 
235 // ----------------------------------------------------------------------------------
236 // Determine if a true particle crosses either APA
237 bool TPCGeoAlg::CrossesApa(const simb::MCParticle& particle){
238  for(size_t i = 0; i < particle.NumberTrajectoryPoints()-1; i++){
239  double x = particle.Vx(i);
240  double y = particle.Vy(i);
241  double z = particle.Vz(i);
242  double x1 = particle.Vx(i+1);
243  double y1 = particle.Vy(i+1);
244  double z1 = particle.Vz(i+1);
245  if(y >= fMinY && z >= fMinZ && y <= fMaxY && z <= fMaxZ
246  && y1 >= fMinY && z1 >= fMinZ && y1 <= fMaxY && z1 <= fMaxZ){
247  if(x <= fMinX && x1 >= fMinX) return true;
248  if(x >= fMinX && x1 <= fMinX) return true;
249  if(x <= fMaxX && x1 >= fMaxX) return true;
250  if(x >= fMaxX && x1 <= fMaxX) return true;
251  }
252  }
253  return false;
254 }
255 
256 std::pair<TVector3, TVector3> TPCGeoAlg::CrossingPoints(const simb::MCParticle& particle){
257  bool first = true;
258  TVector3 start (-99999, -99999, -99999);
259  TVector3 end (-99999, -99999, -99999);
260  for(size_t i = 0; i < particle.NumberTrajectoryPoints(); i++){
261  double x = particle.Vx(i);
262  double y = particle.Vy(i);
263  double z = particle.Vz(i);
264  if(x > fMinX && y > fMinY && z > fMinZ && x < fMaxX && y < fMaxY && z < fMaxZ){
265  if(first){
266  first = false;
267  start.SetXYZ(x, y, z);
268  }
269  end.SetXYZ(x, y, z);
270  }
271  }
272  return std::make_pair(start, end);
273 }
274 
275 double TPCGeoAlg::TpcLength(const simb::MCParticle& particle){
276  bool first = true;
277  double length = 0;
278  TVector3 point, disp;
279  for(size_t i = 0; i < particle.NumberTrajectoryPoints(); i++){
280  double x = particle.Vx(i);
281  double y = particle.Vy(i);
282  double z = particle.Vz(i);
283  if(x > fMinX && y > fMinY && z > fMinZ && x < fMaxX && y < fMaxY && z < fMaxZ){
284  point.SetXYZ(x, y, z);
285  if(!first){
286  disp -= point;
287  length += disp.Mag();
288  }
289  first = false;
290  disp = point;
291  }
292  }
293  return length;
294 }
295 
296 
297 }
298 
299 
process_name opflash particleana ie ie ie z
CryostatGeo const & GetElement(geo::CryostatID const &cryoid) const
bool InsideTPC(geo::Point_t point, const geo::TPCGeo &tpc, double buffer=0.)
process_name opflash particleana ie x
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:88
Geometry information for a single TPC.
Definition: TPCGeo.h:38
std::pair< TVector3, TVector3 > CrossingPoints(const simb::MCParticle &particle)
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:91
bool EntersVolume(const simb::MCParticle &particle)
int DriftDirectionFromHits(std::vector< art::Ptr< recob::Hit >> hits)
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
double TpcLength(const simb::MCParticle &particle)
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
T abs(T value)
bool IsContained(const simb::MCParticle &particle)
double MinDistToWall(geo::Point_t point) const
bool CrossesVolume(const simb::MCParticle &particle)
process_name opflash particleana ie ie y
int DetectedInTPC(std::vector< art::Ptr< recob::Hit >> hits)
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
double MinZ() const
Returns the world z coordinate of the start of the box.
unsigned int NTPC() const
Number of TPCs in this cryostat.
Definition: CryostatGeo.h:181
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
bool InFiducial(geo::Point_t point, double fiducial)
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
double MaxY() const
Returns the world y coordinate of the end of the box.
constexpr TPCID const & asTPCID() const
Conversion to TPCID (for convenience of notation).
Definition: geo_types.h:446
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc&#39;th TPC in the cryostat.
Definition: CryostatGeo.cxx:93
short int DetectDriftDirection() const
Returns the expected drift direction based on geometry.
Definition: TPCGeo.cxx:157
double MaxZ() const
Returns the world z coordinate of the end of the box.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
double MinY() const
Returns the world y coordinate of the start of the box.
std::pair< double, double > XLimitsFromHits(std::vector< art::Ptr< recob::Hit >> hits)
bool InVolume(const simb::MCParticle &particle)
geo::GeometryCore const * fGeometryService
bool CrossesApa(const simb::MCParticle &particle)