All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbndcode/sbndcode/CRT/CRTUtils/TPCGeoUtil.cc
Go to the documentation of this file.
1 #include "TPCGeoUtil.h"
2 
3 namespace sbnd {
4 namespace TPCGeoUtil {
5 int DetectedInTPC(std::vector<art::Ptr<recob::Hit>> hits){
6  // Return tpc of hit collection or -1 if in multiple
7  if(hits.size() == 0) return -1;
8  int tpc = hits[0]->WireID().TPC;
9  for(size_t i = 0; i < hits.size(); i++){
10  if((int)hits[i]->WireID().TPC != tpc) return -1;
11  }
12  return tpc;
13 }
14 // Work out the drift limits for a collection of hits
15 std::pair<double, double> XLimitsFromHits(const geo::GeometryCore *GeometryService, std::vector<art::Ptr<recob::Hit>> hits){
16  // If there are no hits then return 0
17  if(hits.size() == 0) return std::make_pair(0, 0);
18 
19  // If the track is stitched (in multiple TPCs) return 0
20  if(DetectedInTPC(hits) == -1) return std::make_pair(0, 0);
21 
22  // Work out the drift direction
23  geo::TPCID tpcID = hits[0]->WireID().asTPCID();
24  const geo::TPCGeo& tpcGeo = GeometryService->GetElement(tpcID);
25  return std::make_pair(tpcGeo.MinX(), tpcGeo.MaxX());
26 }
27 
28 int DriftDirectionFromHits(const geo::GeometryCore *GeometryService, std::vector<art::Ptr<recob::Hit>> hits){
29  // If there are no hits then return 0
30  if(hits.size() == 0) return 0;
31 
32  // If the track is stitched (in multiple TPCs) return 0
33  if(DetectedInTPC(hits) == -1) return 0;
34 
35  // Work out the drift direction
36  geo::TPCID tpcID = hits[0]->WireID().asTPCID();
37  const geo::TPCGeo& tpcGeo = GeometryService->GetElement(tpcID);
38  double driftDirection = tpcGeo.DetectDriftDirection();
39  if(std::abs(driftDirection) != 1) driftDirection = 0;
40  return driftDirection;
41 }
42 
43 // Is point inside given TPC
44 bool InsideTPC(geo::Point_t point, const geo::TPCGeo& tpc, double buffer){
45  if(point.X() < (tpc.MinX()-buffer) || point.X() > (tpc.MaxX()+buffer)
46  || point.Y() < (tpc.MinY()-buffer) || point.Y() > (tpc.MaxY()+buffer)
47  || point.Z() < (tpc.MinZ()-buffer) || point.Z() > (tpc.MaxZ()+buffer)) return false;
48  return true;
49 }
50 
51 } // namespace TPCGeoUtil
52 } // namespace sbnd
std::pair< double, double > XLimitsFromHits(const geo::GeometryCore *GeometryService, std::vector< art::Ptr< recob::Hit >> hits)
CryostatGeo const & GetElement(geo::CryostatID const &cryoid) const
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
int DetectedInTPC(std::vector< art::Ptr< recob::Hit >> hits)
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:91
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
T abs(T value)
bool InsideTPC(geo::Point_t point, const geo::TPCGeo &tpc, double buffer)
double MinZ() const
Returns the world z coordinate of the start of the box.
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
Description of geometry of one entire detector.
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
short int DetectDriftDirection() const
Returns the expected drift direction based on geometry.
Definition: TPCGeo.cxx:157
int DriftDirectionFromHits(const geo::GeometryCore *GeometryService, std::vector< art::Ptr< recob::Hit >> hits)
double MaxZ() const
Returns the world z coordinate of the end of the box.
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.