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