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