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