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