GeoObjectSorterCRU.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file GeoObjectSorterCRU.cxx
3 /// \brief Interface to algorithm class for sorting VD CRUs of geo::XXXGeo objects
4 /// The sorting makes the assumptions on the drift direction along X axis
5 ///
6 /// \version $Id: $
7 /// \author vgalymov@ipnl.in2p3.fr
8 ////////////////////////////////////////////////////////////////////////
9 
18 
19 #include <array>
20 #include <string>
21 #include <cmath> // std::abs()
22 
23 using std::cout;
24 using std::endl;
25 
26 // comparison functions for sorting various geo objects
27 namespace geo {
28 
29  namespace CRU {
30  //----------------------------------------------------------------------------
31  // Define sort order for auxdet in VD configuration
32  static bool sortAuxDet(const AuxDetGeo& ad1, const AuxDetGeo& ad2)
33  {
34 
35  // sort based off of GDML name, assuming ordering is encoded
36  std::string ad1name = (ad1.TotalVolume())->GetName();
37  std::string ad2name = (ad2.TotalVolume())->GetName();
38 
39  // assume volume name is "volAuxDet##"
40  int ad1Num = atoi( ad1name.substr( 9, ad1name.size()).c_str() );
41  int ad2Num = atoi( ad2name.substr( 9, ad2name.size()).c_str() );
42 
43  return ad1Num < ad2Num;
44 
45  }
46 
47  //----------------------------------------------------------------------------
48  // Define sort order for auxsensitve det in VD configuration
49  static bool sortAuxDetSensitive(const AuxDetSensitiveGeo& ad1, const AuxDetSensitiveGeo& ad2)
50  {
51 
52  // sort based off of GDML name, assuming ordering is encoded
53  std::string ad1name = (ad1.TotalVolume())->GetName();
54  std::string ad2name = (ad2.TotalVolume())->GetName();
55 
56  // assume volume name is "volAuxDetSensitive##"
57  int ad1Num = atoi( ad1name.substr( 9, ad1name.size()).c_str() );
58  int ad2Num = atoi( ad2name.substr( 9, ad2name.size()).c_str() );
59 
60  return ad1Num < ad2Num;
61 
62  }
63 
64  //----------------------------------------------------------------------------
65  // Define sort order for cryostats in VD configuration
66  static bool sortCryo(const CryostatGeo& c1, const CryostatGeo& c2)
67  {
68  double xyz1[3] = {0.}, xyz2[3] = {0.};
69  double local[3] = {0.};
70  c1.LocalToWorld(local, xyz1);
71  c2.LocalToWorld(local, xyz2);
72 
73  return xyz1[0] < xyz2[0];
74  }
75 
76 
77  //----------------------------------------------------------------------------
78  // Define sort order for tpcs (CRUs) in VD configuration
79  static bool sortTPC(const TPCGeo& t1, const TPCGeo& t2)
80  {
81  double xyz1[3] = {0.};
82  double xyz2[3] = {0.};
83  double local[3] = {0.};
84  t1.LocalToWorld(local, xyz1);
85  t2.LocalToWorld(local, xyz2);
86 
87  // First sort all TPCs into same-z groups
88  if(xyz1[2]<xyz2[2]) return true;
89 
90  // Within a same-z group, sort TPCs into same-y groups
91  if(xyz1[2] == xyz2[2] && xyz1[1] < xyz2[1]) return true;
92 
93  return false;
94  }
95 
96 
97  //----------------------------------------------------------------------------
98  // Define sort order for planes in VD configuration
99  static bool sortPlane(const PlaneGeo& p1, const PlaneGeo& p2)
100  {
101  double xyz1[3] = {0.};
102  double xyz2[3] = {0.};
103  double local[3] = {0.};
104  p1.LocalToWorld(local, xyz1);
105  p2.LocalToWorld(local, xyz2);
106 
107  // drift direction is negative, plane number increases in drift direction
108  return xyz1[0] > xyz2[0];
109  }
110 
111 
112  //----------------------------------------------------------------------------
113  bool sortWire(WireGeo const& w1, WireGeo const& w2){
114  // wire sorting algorithm
115  // z_low -> z_high
116  // for same-z group
117  // the sorting either from bottom (y) left (z) corner up for strip angles > pi/2
118  // and horizontal wires
119  // or from top corner to bottom otherwise
120  // we assume all wires in the plane are parallel
121 
122  // w1 geo info
123  auto center1 = w1.GetCenter<geo::Point_t>();
124  auto start1 = w1.GetStart<geo::Point_t>();
125  auto end1 = w1.GetEnd<geo::Point_t>();
126  auto Delta = end1-start1;
127  //double dx1 = Delta.X();
128  double dy1 = Delta.Y();
129  double dz1 = Delta.Z();
130 
131  // w2 geo info
132  auto center2 = w2.GetCenter<geo::Point_t>();
133 
134  auto CheckTol = [](double val, double tol = 1.E-4){
135  return (std::abs( val ) < tol);
136  };
137 
138  if( CheckTol(dz1) ){ // wires perpendicular to z axis
139  return (center1.Z() < center2.Z());
140  }
141 
142  if( CheckTol(dy1) ){ // wires perpendicular to y axis
143  return (center1.Y() < center2.Y());
144  }
145 
146  // wires at angle with same z center
147  if( CheckTol( center2.Z() - center1.Z() ) ){
148  if( dz1 < 0 ){ dy1 = -dy1; } // always compare here upstream - downstream ends
149  if( dy1 < 0 ){ return (center1.Y() < center2.Y()); }
150  if( dy1 > 0 ){ return (center1.Y() > center2.Y()); }
151  }
152 
153  // otherwise sorted in z
154  return ( center1.Z() < center2.Z() );
155  }
156 
157  } // namespace geo::CRU
158 
159  //----------------------------------------------------------------------------
161  {}
162 
163  //----------------------------------------------------------------------------
164  void GeoObjectSorterCRU::SortAuxDets(std::vector<geo::AuxDetGeo> & adgeo) const
165  {
166  std::sort(adgeo.begin(), adgeo.end(), CRU::sortAuxDet);
167  }
168 
169  //----------------------------------------------------------------------------
170  void GeoObjectSorterCRU::SortAuxDetSensitive(std::vector<geo::AuxDetSensitiveGeo> & adsgeo) const
171  {
172  std::sort(adsgeo.begin(), adsgeo.end(), CRU::sortAuxDetSensitive);
173  }
174 
175  //----------------------------------------------------------------------------
176  void GeoObjectSorterCRU::SortCryostats(std::vector<geo::CryostatGeo> & cgeo) const
177  {
178  std::sort(cgeo.begin(), cgeo.end(), CRU::sortCryo);
179  }
180 
181  //----------------------------------------------------------------------------
182  void GeoObjectSorterCRU::SortTPCs(std::vector<geo::TPCGeo> & tgeo) const
183  {
184  std::sort(tgeo.begin(), tgeo.end(), CRU::sortTPC);
185  }
186 
187  //----------------------------------------------------------------------------
188  void GeoObjectSorterCRU::SortPlanes(std::vector<geo::PlaneGeo> & pgeo,
189  geo::DriftDirection_t const driftDir) const
190  {
191  // sort the planes to increase in drift direction
192  // The drift direction has to be set before this method is called. It is set when
193  // the CryostatGeo objects are sorted by the CryostatGeo::SortSubVolumes method
194  if (driftDir == geo::kPosX) std::sort(pgeo.rbegin(), pgeo.rend(), CRU::sortPlane);
195  else if(driftDir == geo::kNegX) std::sort(pgeo.begin(), pgeo.end(), CRU::sortPlane);
196  else if(driftDir == geo::kUnknownDrift)
197  throw cet::exception("TPCGeo") << "Drift direction is unknown, can't sort the planes\n";
198  }
199 
200  //----------------------------------------------------------------------------
201  void GeoObjectSorterCRU::SortWires(std::vector<geo::WireGeo> & wgeo) const
202  {
203  std::sort(wgeo.begin(), wgeo.end(), CRU::sortWire);
204  }
205 
206  //----------------------------------------------------------------------------
207  void GeoObjectSorterCRU::SortOpDets (std::vector<geo::OpDetGeo> & opdet) const {
208  std::sort(opdet.begin(), opdet.end(), sortorderOpDet);
209  }
210 
211 }
void GetStart(double *xyz) const
Definition: WireGeo.h:157
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
Definition: WireGeo.h:65
Drift direction is unknown.
Definition: geo_types.h:158
Encapsulate the construction of a single cyostat.
std::string string
Definition: nybbler.cc:12
auto const tol
Definition: SurfXYZTest.cc:16
Geometry information for a single TPC.
Definition: TPCGeo.h:38
void SortWires(std::vector< geo::WireGeo > &wgeo) const
static bool sortTPC(const TPCGeo &t1, const TPCGeo &t2)
Drift towards negative X values.
Definition: geo_types.h:162
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
void SortOpDets(std::vector< geo::OpDetGeo > &opdet) const
T abs(T value)
Encapsulate the geometry of the sensitive portion of an auxiliary detector.
enum geo::driftdir DriftDirection_t
Drift direction: positive or negative.
void SortPlanes(std::vector< geo::PlaneGeo > &pgeo, geo::DriftDirection_t driftDir) const
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
bool sortorderOpDet(const OpDetGeo &t1, const OpDetGeo &t2)
Definition: OpDetSorter.h:10
Encapsulate the geometry of an auxiliary detector.
static bool sortPlane(const PlaneGeo &p1, const PlaneGeo &p2)
static bool sortCryo(const CryostatGeo &c1, const CryostatGeo &c2)
void SortCryostats(std::vector< geo::CryostatGeo > &cgeo) const
Interface to algorithm class for sorting VD CRUs of geo::XXXGeo objects.
void SortAuxDets(std::vector< geo::AuxDetGeo > &adgeo) const
Encapsulate the geometry of a wire.
static bool sortAuxDet(const AuxDetGeo &ad1, const AuxDetGeo &ad2)
GeoObjectSorterCRU(fhicl::ParameterSet const &p)
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
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.
static bool sortAuxDetSensitive(const AuxDetSensitiveGeo &ad1, const AuxDetSensitiveGeo &ad2)
const TGeoVolume * TotalVolume() const
Definition: AuxDetGeo.h:106
void GetEnd(double *xyz) const
Definition: WireGeo.h:163
void SortTPCs(std::vector< geo::TPCGeo > &tgeo) const
void GetCenter(double *xyz, double localz=0.0) const
Fills the world coordinate of a point on the wire.
Definition: WireGeo.cxx:73
LArSoft geometry interface.
Definition: ChannelGeo.h:16
void SortAuxDetSensitive(std::vector< geo::AuxDetSensitiveGeo > &adsgeo) const
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
QTextStream & endl(QTextStream &s)
Encapsulate the construction of a single detector plane.
bool sortWire(WireGeo const &w1, WireGeo const &w2)