GeoObjectSorterCRM.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file GeoObjectSorterCRM.cxx
3 /// \brief Interface to algorithm class for sorting dual-phase CRM geo::XXXGeo objects
4 ///
5 /// \version $Id: $
6 /// \author brebel@fnal.gov vgalymov@ipnl.in2p3.fr
7 ////////////////////////////////////////////////////////////////////////
8 
17 
18 #include <array>
19 #include <string>
20 #include <cmath> // std::abs()
21 
22 namespace geo{
23 
24  //----------------------------------------------------------------------------
25  // Define sort order for cryostats in dual-phase configuration
26  static bool sortAuxDetCRM(const AuxDetGeo& ad1, const AuxDetGeo& ad2)
27  {
28 
29  // sort based off of GDML name, assuming ordering is encoded
30  std::string ad1name = (ad1.TotalVolume())->GetName();
31  std::string 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 dual-phase configuration
43  static bool sortAuxDetSensitiveCRM(const AuxDetSensitiveGeo& ad1, const AuxDetSensitiveGeo& ad2)
44  {
45 
46  // sort based off of GDML name, assuming ordering is encoded
47  std::string ad1name = (ad1.TotalVolume())->GetName();
48  std::string ad2name = (ad2.TotalVolume())->GetName();
49 
50  // assume volume name is "volAuxDetSensitive##"
51  int ad1Num = atoi( ad1name.substr( 9, ad1name.size()).c_str() );
52  int ad2Num = atoi( ad2name.substr( 9, ad2name.size()).c_str() );
53 
54  return ad1Num < ad2Num;
55 
56  }
57 
58  //----------------------------------------------------------------------------
59  // Define sort order for cryostats in dual-phase configuration
60  static bool sortCryoCRM(const CryostatGeo& c1, const CryostatGeo& c2)
61  {
62  double xyz1[3] = {0.}, xyz2[3] = {0.};
63  double local[3] = {0.};
64  c1.LocalToWorld(local, xyz1);
65  c2.LocalToWorld(local, xyz2);
66 
67  return xyz1[0] < xyz2[0];
68  }
69 
70 
71  //----------------------------------------------------------------------------
72  // Define sort order for tpcs in dual-phase configuration
73  static bool sortTPCCRM(const TPCGeo& t1, const TPCGeo& t2)
74  {
75  double xyz1[3] = {0.};
76  double xyz2[3] = {0.};
77  double local[3] = {0.};
78  t1.LocalToWorld(local, xyz1);
79  t2.LocalToWorld(local, xyz2);
80 
81  // First sort all TPCs into same-z groups
82  if(xyz1[2]<xyz2[2]) return true;
83 
84  // Within a same-z group, sort TPCs into same-y groups
85  if(xyz1[2] == xyz2[2] && xyz1[1] < xyz2[1]) return true;
86 
87  return false;
88  }
89 
90 
91  //----------------------------------------------------------------------------
92  // Define sort order for planes in dual-phase configuration
93  static bool sortPlaneCRM(const PlaneGeo& p1, const PlaneGeo& p2)
94  {
95  double xyz1[3] = {0.};
96  double xyz2[3] = {0.};
97  double local[3] = {0.};
98  p1.LocalToWorld(local, xyz1);
99  p2.LocalToWorld(local, xyz2);
100 
101  // drift direction is negative, plane number increases in drift direction
102  return xyz1[0] > xyz2[0];
103  }
104 
105 
106  //----------------------------------------------------------------------------
107  bool sortWireCRM(WireGeo const& w1, WireGeo const& w2){
108 
109  std::array<double, 3> xyz1, xyz2;
110  w1.GetCenter(xyz1.data()); w2.GetCenter(xyz2.data());
111 
112  // for dual-phase we have to planes with wires perpendicular to each other
113  // sort wires in the increasing coordinate order
114 
115  if (std::abs(xyz1[0] - xyz2[0]) < 1.0E-4 && std::abs(xyz1[1] - xyz2[1]) < 1.0E-4 )
116  return xyz1[2] < xyz2[2];
117  else if (std::abs(xyz1[0] - xyz2[0]) < 1.0E-4 && std::abs(xyz1[2] - xyz2[2]) < 1.0E-4 )
118  return xyz1[1] < xyz2[1];
119  else if (std::abs(xyz1[1] - xyz2[1]) < 1.0E-4 && std::abs(xyz1[2] - xyz2[2]) < 1.0E-4 )
120  return xyz1[0] < xyz2[0];
121  else { // don't know what to do
122  throw cet::exception("GeoObjectSorterCRM")
123  << "Uknown sorting situation for the wires in a plane\n";
124  }
125  } // sortWireCRM()
126 
127  //----------------------------------------------------------------------------
129  {
130  }
131 
132  //----------------------------------------------------------------------------
133  void GeoObjectSorterCRM::SortAuxDets(std::vector<geo::AuxDetGeo> & adgeo) const
134  {
135  std::sort(adgeo.begin(), adgeo.end(), sortAuxDetCRM);
136  }
137 
138  //----------------------------------------------------------------------------
139  void GeoObjectSorterCRM::SortAuxDetSensitive(std::vector<geo::AuxDetSensitiveGeo> & adsgeo) const
140  {
141  std::sort(adsgeo.begin(), adsgeo.end(), sortAuxDetSensitiveCRM);
142  }
143 
144  //----------------------------------------------------------------------------
145  void GeoObjectSorterCRM::SortCryostats(std::vector<geo::CryostatGeo> & cgeo) const
146  {
147  std::sort(cgeo.begin(), cgeo.end(), sortCryoCRM);
148  }
149 
150  //----------------------------------------------------------------------------
151  void GeoObjectSorterCRM::SortTPCs(std::vector<geo::TPCGeo> & tgeo) const
152  {
153  std::sort(tgeo.begin(), tgeo.end(), sortTPCCRM);
154  }
155 
156  //----------------------------------------------------------------------------
157  void GeoObjectSorterCRM::SortPlanes(std::vector<geo::PlaneGeo> & pgeo,
158  geo::DriftDirection_t const driftDir) const
159  {
160  // sort the planes to increase in drift direction
161  // The drift direction has to be set before this method is called. It is set when
162  // the CryostatGeo objects are sorted by the CryostatGeo::SortSubVolumes method
163  if (driftDir == geo::kPosX) std::sort(pgeo.rbegin(), pgeo.rend(), sortPlaneCRM);
164  else if(driftDir == geo::kNegX) std::sort(pgeo.begin(), pgeo.end(), sortPlaneCRM);
165  else if(driftDir == geo::kUnknownDrift)
166  throw cet::exception("TPCGeo") << "Drift direction is unknown, can't sort the planes\n";
167  }
168 
169  //----------------------------------------------------------------------------
170  void GeoObjectSorterCRM::SortWires(std::vector<geo::WireGeo> & wgeo) const
171  {
172  std::sort(wgeo.begin(), wgeo.end(), sortWireCRM);
173  }
174 
175  //----------------------------------------------------------------------------
176  void GeoObjectSorterCRM::SortOpDets (std::vector<geo::OpDetGeo> & opdet) const {
177  std::sort(opdet.begin(), opdet.end(), sortorderOpDet);
178  }
179 
180 }
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
void SortCryostats(std::vector< geo::CryostatGeo > &cgeo) const
Geometry information for a single TPC.
Definition: TPCGeo.h:38
void SortPlanes(std::vector< geo::PlaneGeo > &pgeo, geo::DriftDirection_t driftDir) const
static bool sortAuxDetCRM(const AuxDetGeo &ad1, const AuxDetGeo &ad2)
Drift towards negative X values.
Definition: geo_types.h:162
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
bool sortWireCRM(WireGeo const &w1, WireGeo const &w2)
void SortAuxDetSensitive(std::vector< geo::AuxDetSensitiveGeo > &adsgeo) const
static bool sortCryoCRM(const CryostatGeo &c1, const CryostatGeo &c2)
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 SortAuxDets(std::vector< geo::AuxDetGeo > &adgeo) const
void SortOpDets(std::vector< geo::OpDetGeo > &opdet) 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
static bool sortTPCCRM(const TPCGeo &t1, const TPCGeo &t2)
bool sortorderOpDet(const OpDetGeo &t1, const OpDetGeo &t2)
Definition: OpDetSorter.h:10
Encapsulate the geometry of an auxiliary detector.
static bool sortPlaneCRM(const PlaneGeo &p1, const PlaneGeo &p2)
Interface to algorithm class for sorting dual-phase CRM of geo::XXXGeo objects.
void SortTPCs(std::vector< geo::TPCGeo > &tgeo) const
Encapsulate the geometry of a wire.
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 sortAuxDetSensitiveCRM(const AuxDetSensitiveGeo &ad1, const AuxDetSensitiveGeo &ad2)
const TGeoVolume * TotalVolume() const
Definition: AuxDetGeo.h:106
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 LocalToWorld(const double *tpc, double *world) const
Transform point from local TPC frame to world frame.
Definition: TPCGeo.h:563
GeoObjectSorterCRM(fhicl::ParameterSet const &p)
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.
void SortWires(std::vector< geo::WireGeo > &wgeo) const