LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
GeoObjectSorterStandard.cxx
Go to the documentation of this file.
1 
15 
16 #include <utility>
17 
18 namespace {
19 
20  // Tolerance when comparing distances in geometry:
21  constexpr double DistanceTol = 0.001; // cm
22 
23 } // local namespace
24 
25 namespace geo {
26 
27  //----------------------------------------------------------------------------
28  // Define sort order for cryostats in standard configuration
29  static bool sortAuxDetStandard(const AuxDetGeo& ad1, const AuxDetGeo& ad2)
30  {
31  // sort based off of GDML name, assuming ordering is encoded
32  std::string const& ad1name = ad1.TotalVolume()->GetName();
33  std::string const& ad2name = ad2.TotalVolume()->GetName();
34 
35  // assume volume name is "volAuxDet##"
36  int ad1Num = atoi(ad1name.substr(9, ad1name.size()).c_str());
37  int ad2Num = atoi(ad2name.substr(9, ad2name.size()).c_str());
38 
39  return ad1Num < ad2Num;
40  }
41 
42  //----------------------------------------------------------------------------
43  // Define sort order for cryostats in standard configuration
45  const AuxDetSensitiveGeo& ad2)
46  {
47  // sort based off of GDML name, assuming ordering is encoded
48  std::string ad1name = (ad1.TotalVolume())->GetName();
49  std::string ad2name = (ad2.TotalVolume())->GetName();
50 
51  // assume volume name is "volAuxDetSensitive##"
52  int ad1Num = atoi(ad1name.substr(9, ad1name.size()).c_str());
53  int ad2Num = atoi(ad2name.substr(9, ad2name.size()).c_str());
54 
55  return ad1Num < ad2Num;
56  }
57 
58  //----------------------------------------------------------------------------
59  // Define sort order for cryostats in standard configuration
60  static bool sortCryoStandard(const CryostatGeo& c1, const CryostatGeo& c2)
61  {
62  CryostatGeo::LocalPoint_t const local{0., 0., 0.};
63  auto const xyz1 = c1.toWorldCoords(local);
64  auto const xyz2 = c2.toWorldCoords(local);
65  return xyz1.X() < xyz2.X();
66  }
67 
68  //----------------------------------------------------------------------------
69  // Define sort order for tpcs in standard configuration.
70  static bool sortTPCStandard(const TPCGeo& t1, const TPCGeo& t2)
71  {
72  TPCGeo::LocalPoint_t const local{0., 0., 0.};
73  auto const xyz1 = t1.toWorldCoords(local);
74  auto const xyz2 = t2.toWorldCoords(local);
75 
76  // sort TPCs according to x
77  return xyz1.X() < xyz2.X();
78  }
79 
80  //----------------------------------------------------------------------------
81  // Define sort order for planes in standard configuration
82  static bool sortPlaneStandard(const PlaneGeo& p1, const PlaneGeo& p2)
83  {
84  PlaneGeo::LocalPoint_t const local{0., 0., 0.};
85  auto const xyz1 = p1.toWorldCoords(local);
86  auto const xyz2 = p2.toWorldCoords(local);
87 
88  // drift direction is negative, plane number increases in drift direction
89  if (std::abs(xyz1.X() - xyz2.X()) > DistanceTol) return xyz1.X() > xyz2.X();
90 
91  //if same drift, sort by z
92  if (std::abs(xyz1.Z() - xyz2.Z()) > DistanceTol) return xyz1.Z() < xyz2.Z();
93 
94  //if same z, sort by y
95  return xyz1.Y() < xyz2.Y();
96  }
97 
98  //----------------------------------------------------------------------------
99  static bool sortWireStandard(WireGeo const& w1, WireGeo const& w2)
100  {
101  auto const [xyz1, xyz2] = std::make_pair(w1.GetCenter(), w2.GetCenter());
102 
103  //sort by z first
104  if (std::abs(xyz1.Z() - xyz2.Z()) > DistanceTol) return xyz1.Z() < xyz2.Z();
105 
106  //if same z sort by y
107  if (std::abs(xyz1.Y() - xyz2.Y()) > DistanceTol) return xyz1.Y() < xyz2.Y();
108 
109  //if same y sort by x
110  return xyz1.X() < xyz2.X();
111  }
112 
113  //----------------------------------------------------------------------------
115 
116  //----------------------------------------------------------------------------
117  void GeoObjectSorterStandard::SortAuxDets(std::vector<geo::AuxDetGeo>& adgeo) const
118  {
119  std::sort(adgeo.begin(), adgeo.end(), sortAuxDetStandard);
120  }
121 
122  //----------------------------------------------------------------------------
124  std::vector<geo::AuxDetSensitiveGeo>& adsgeo) const
125  {
126  std::sort(adsgeo.begin(), adsgeo.end(), sortAuxDetSensitiveStandard);
127  }
128 
129  //----------------------------------------------------------------------------
130  void GeoObjectSorterStandard::SortCryostats(std::vector<geo::CryostatGeo>& cgeo) const
131  {
132  std::sort(cgeo.begin(), cgeo.end(), sortCryoStandard);
133  }
134 
135  //----------------------------------------------------------------------------
136  void GeoObjectSorterStandard::SortTPCs(std::vector<geo::TPCGeo>& tgeo) const
137  {
138  std::sort(tgeo.begin(), tgeo.end(), sortTPCStandard);
139  }
140 
141  //----------------------------------------------------------------------------
142  void GeoObjectSorterStandard::SortPlanes(std::vector<geo::PlaneGeo>& pgeo,
143  geo::DriftDirection_t const driftDir) const
144  {
145  // sort the planes to increase in drift direction
146  // The drift direction has to be set before this method is called. It is set when
147  // the CryostatGeo objects are sorted by the CryostatGeo::SortSubVolumes method
148  if (driftDir == geo::kPosX)
149  std::sort(pgeo.rbegin(), pgeo.rend(), sortPlaneStandard);
150  else if (driftDir == geo::kNegX)
151  std::sort(pgeo.begin(), pgeo.end(), sortPlaneStandard);
152  else if (driftDir == geo::kUnknownDrift)
153  throw cet::exception("TPCGeo") << "Drift direction is unknown, can't sort the planes\n";
154  }
155 
156  //----------------------------------------------------------------------------
157  void GeoObjectSorterStandard::SortWires(std::vector<geo::WireGeo>& wgeo) const
158  {
159  std::sort(wgeo.begin(), wgeo.end(), sortWireStandard);
160  }
161 
162 }
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
Definition: WireGeo.h:114
static bool sortAuxDetStandard(const AuxDetGeo &ad1, const AuxDetGeo &ad2)
Point_t const & GetCenter() const
Returns the world coordinate of the center of the wire [cm].
Definition: WireGeo.h:221
Drift direction is unknown.
Definition: geo_types.h:163
TTree * t1
Definition: plottest35.C:26
Encapsulate the construction of a single cyostat.
Encapsulate the geometry of the sensitive portion of an auxiliary detector.
geo::Point3DBase_t< TPCGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML TPC frame.
Definition: TPCGeo.h:64
static bool sortWireStandard(WireGeo const &w1, WireGeo const &w2)
Geometry information for a single TPC.
Definition: TPCGeo.h:36
constexpr auto abs(T v)
Returns the absolute value of the argument.
void SortWires(std::vector< geo::WireGeo > &wgeo) const override
Drift towards negative X values.
Definition: geo_types.h:167
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local TPC frame to world frame.
Definition: TPCGeo.h:482
Interface to algorithm class for standard sorting of geo::XXXGeo objects.
void SortTPCs(std::vector< geo::TPCGeo > &tgeo) const override
TCanvas * c1
Definition: plotHisto.C:7
void SortPlanes(std::vector< geo::PlaneGeo > &pgeo, geo::DriftDirection_t driftDir) const override
TCanvas * c2
Definition: plot_hist.C:75
enum geo::driftdir DriftDirection_t
Drift direction: positive or negative.
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local plane frame to world frame.
Definition: PlaneGeo.h:1225
geo::Point3DBase_t< CryostatGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML cryostat frame.
Definition: CryostatGeo.h:79
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:78
const TGeoVolume * TotalVolume() const
static bool sortAuxDetSensitiveStandard(const AuxDetSensitiveGeo &ad1, const AuxDetSensitiveGeo &ad2)
static bool sortPlaneStandard(const PlaneGeo &p1, const PlaneGeo &p2)
static bool sortCryoStandard(const CryostatGeo &c1, const CryostatGeo &c2)
TTree * t2
Definition: plottest35.C:36
void SortAuxDetSensitive(std::vector< geo::AuxDetSensitiveGeo > &adsgeo) const override
Encapsulate the geometry of an auxiliary detector.
Encapsulate the geometry of a wire.
GeoObjectSorterStandard(fhicl::ParameterSet const &p)
Drift towards positive X values.
Definition: geo_types.h:166
Encapsulate the construction of a single detector plane.
const TGeoVolume * TotalVolume() const
Returns the distance of point from the center of the detector.
Definition: AuxDetGeo.h:91
void SortCryostats(std::vector< geo::CryostatGeo > &cgeo) const override
static bool sortTPCStandard(const TPCGeo &t1, const TPCGeo &t2)
void SortAuxDets(std::vector< geo::AuxDetGeo > &adgeo) const override
Namespace collecting geometry-related classes utilities.
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local cryostat frame to world frame.
Definition: CryostatGeo.h:347
geo::Point3DBase_t< PlaneGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML wire plane frame.
Definition: PlaneGeo.h:106
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Encapsulate the construction of a single detector plane.