LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
AuxDetChannelMapAlg.cxx
Go to the documentation of this file.
1 
8 #include "cetlib_except/exception.h"
9 
13 
14 namespace geo {
15 
16  //----------------------------------------------------------------------------
18  std::vector<AuxDetGeo> const& auxDets,
19  double tolerance) const
20  {
21  for (size_t a = 0; a < auxDets.size(); ++a) {
22  auto const localPoint = auxDets[a].toLocalCoords(point);
23  double const HalfCenterWidth = 0.5 * (auxDets[a].HalfWidth1() + auxDets[a].HalfWidth2());
24 
25  if (localPoint.Z() >= (-auxDets[a].Length() / 2 - tolerance) &&
26  localPoint.Z() <= (auxDets[a].Length() / 2 + tolerance) &&
27  localPoint.Y() >= (-auxDets[a].HalfHeight() - tolerance) &&
28  localPoint.Y() <= (auxDets[a].HalfHeight() + tolerance) &&
29  // if AuxDet a is a box, then HalfSmallWidth = HalfWidth
30  localPoint.X() >= (-HalfCenterWidth +
31  localPoint.Z() * (HalfCenterWidth - auxDets[a].HalfWidth2()) /
32  (0.5 * auxDets[a].Length()) -
33  tolerance) &&
34  localPoint.X() <= (HalfCenterWidth -
35  localPoint.Z() * (HalfCenterWidth - auxDets[a].HalfWidth2()) /
36  (0.5 * auxDets[a].Length()) +
37  tolerance))
38  return a;
39 
40  } // for loop over AudDet a
41 
42  // throw an exception because we couldn't find the sensitive volume
43  throw cet::exception("AuxDetChannelMapAlg") << "Can't find AuxDet for position (" << point.X()
44  << "," << point.Y() << "," << point.Z() << ")\n";
45  }
46 
47  //----------------------------------------------------------------------------
49  std::vector<AuxDetGeo> const& auxDets,
50  size_t& ad,
51  double tolerance) const
52  {
53  ad = NearestAuxDet(point, auxDets, tolerance);
54 
55  AuxDetGeo const& adg = auxDets[ad];
56 
57  for (size_t a = 0; a < adg.NSensitiveVolume(); ++a) {
58  AuxDetSensitiveGeo const& adsg = adg.SensitiveVolume(a);
59  auto const localPoint = adsg.toLocalCoords(point);
60 
61  double const HalfCenterWidth = 0.5 * (adsg.HalfWidth1() + adsg.HalfWidth2());
62 
63  if (localPoint.Z() >= -(adsg.Length() / 2 + tolerance) &&
64  localPoint.Z() <= adsg.Length() / 2 + tolerance &&
65  localPoint.Y() >= -(adsg.HalfHeight() + tolerance) &&
66  localPoint.Y() <= adsg.HalfHeight() + tolerance &&
67  // if AuxDet a is a box, then HalfSmallWidth = HalfWidth
68  localPoint.X() >=
69  -HalfCenterWidth +
70  localPoint.Z() * (HalfCenterWidth - adsg.HalfWidth2()) / (0.5 * adsg.Length()) -
71  tolerance &&
72  localPoint.X() <=
73  HalfCenterWidth -
74  localPoint.Z() * (HalfCenterWidth - adsg.HalfWidth2()) / (0.5 * adsg.Length()) +
75  tolerance)
76  return a;
77  } // for loop over AuxDetSensitive a
78 
79  // throw an exception because we couldn't find the sensitive volume
80  throw cet::exception("Geometry") << "Can't find AuxDetSensitive for position (" << point.X()
81  << "," << point.Y() << "," << point.Z() << ")\n";
82  }
83 
84  //----------------------------------------------------------------------------
85  size_t AuxDetChannelMapAlg::ChannelToAuxDet(std::vector<AuxDetGeo> const& /* auxDets */,
86  std::string const& detName,
87  uint32_t /*channel*/) const
88  {
89  // loop over the map of AuxDet names to Geo object numbers to determine which auxdet
90  // we have. If no name in the map matches the provided string, throw an exception;
91  // the list of AuxDetGeo passed as argument is ignored!
92  // Note that fADGeoToName must have been updated by a derived class.
93  for (auto itr : fADGeoToName)
94  if (itr.second.compare(detName) == 0) return itr.first;
95 
96  throw cet::exception("Geometry") << "No AuxDetGeo matching name: " << detName;
97  }
98 
99  //----------------------------------------------------------------------------
100  // the first member of the pair is the index in the auxDets vector for the AuxDetGeo,
101  // the second member is the index in the vector of AuxDetSensitiveGeos for that AuxDetGeo
103  std::vector<AuxDetGeo> const& auxDets,
104  std::string const& detName,
105  uint32_t channel) const
106  {
107  size_t adGeoIdx = ChannelToAuxDet(auxDets, detName, channel);
108 
109  // look for the index of the sensitive volume for the given channel
110  if (fADGeoToChannelAndSV.count(adGeoIdx) > 0) {
111 
112  auto itr = fADGeoToChannelAndSV.find(adGeoIdx);
113 
114  // get the vector of channels to AuxDetSensitiveGeo index
115  if (channel < itr->second.size())
116  return std::make_pair(adGeoIdx, itr->second[channel].second);
117 
118  throw cet::exception("Geometry")
119  << "Given AuxDetSensitive channel, " << channel
120  << ", cannot be found in vector associated to AuxDetGeo index: " << adGeoIdx
121  << ". Vector has size " << itr->second.size();
122  }
123 
124  throw cet::exception("Geometry") << "Given AuxDetGeo with index " << adGeoIdx
125  << " does not correspond to any vector of sensitive volumes";
126  }
127 
128 }
float Length(const PFPStruct &pfp)
Definition: PFPUtils.cxx:3269
Encapsulate the geometry of the sensitive portion of an auxiliary detector.
std::map< size_t, std::vector< chanAndSV > > fADGeoToChannelAndSV
AuxDetSensitiveGeo const & SensitiveVolume(size_t sv) const
Definition: AuxDetGeo.h:143
virtual std::pair< size_t, size_t > ChannelToSensitiveAuxDet(std::vector< AuxDetGeo > const &auxDets, std::string const &detName, uint32_t channel) const
virtual size_t NearestAuxDet(Point_t const &point, std::vector< AuxDetGeo > const &auxDets, double tolerance=0) const
virtual size_t ChannelToAuxDet(std::vector< AuxDetGeo > const &auxDets, std::string const &detName, uint32_t channel) const
size_t NSensitiveVolume() const
Definition: AuxDetGeo.h:144
Encapsulate the geometry of an auxiliary detector.
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:180
virtual size_t NearestSensitiveAuxDet(Point_t const &point, std::vector< AuxDetGeo > const &auxDets, size_t &ad, double tolerance=0) const
std::map< size_t, std::string > fADGeoToName
map the AuxDetGeo index to the name
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
Namespace collecting geometry-related classes utilities.
LocalPoint_t toLocalCoords(geo::Point_t const &world) const
Transform point from world frame to local auxiliary detector frame.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33