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