ChannelMapAlg.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 
10 
11 namespace geo{
12 
13 
14  //----------------------------------------------------------------------------
15  unsigned int ChannelMapAlg::NearestWire(const TVector3& worldPos,
16  geo::PlaneID const& planeID) const
17  {
18  return NearestWireID(worldPos, planeID).Wire;
19  }
20 
21  //----------------------------------------------------------------------------
22  unsigned int ChannelMapAlg::NOpChannels(unsigned int NOpDets) const
23  {
24  // By default just return the number of optical detectos
25  return NOpDets;
26  }
27 
28  //----------------------------------------------------------------------------
29  unsigned int ChannelMapAlg::MaxOpChannel(unsigned int NOpDets) const
30  {
31  // By default just return the number of optical detectos
32  return NOpChannels(NOpDets);
33  }
34 
35  //----------------------------------------------------------------------------
36  unsigned int ChannelMapAlg::NOpHardwareChannels(unsigned int /*opDet*/) const
37  {
38  // By defualt, 1 channel per optical detector
39  return 1;
40  }
41 
42 
43 
44  //----------------------------------------------------------------------------
45  unsigned int ChannelMapAlg::OpChannel(unsigned int detNum, unsigned int /* channel */) const
46  {
47  return detNum;
48  }
49 
50  //----------------------------------------------------------------------------
51  unsigned int ChannelMapAlg::OpDetFromOpChannel(unsigned int opChannel) const
52  {
53  return opChannel;
54  }
55 
56  //----------------------------------------------------------------------------
57  unsigned int ChannelMapAlg::HardwareChannelFromOpChannel(unsigned int /* opChannel */) const
58  {
59  return 0;
60  }
61 
62  //----------------------------------------------------------------------------
63  bool ChannelMapAlg::IsValidOpChannel(unsigned int opChannel, unsigned int NOpDets) const
64  {
65  // Check channel number
66  if ( opChannel >= this->NOpChannels(NOpDets) ) return false;
67 
68  // Check opdet number
69  unsigned int opdet = this->OpDetFromOpChannel(opChannel);
70  if (opdet >= NOpDets) return false;
71 
72  // Check hardware channel number
73  unsigned int hChan = this->HardwareChannelFromOpChannel(opChannel);
74  if (hChan >= this->NOpHardwareChannels(opdet)) return false;
75 
76  return true;
77  }
78 
79  //----------------------------------------------------------------------------
80  size_t ChannelMapAlg::NearestAuxDet(const double* point,
81  std::vector<geo::AuxDetGeo> const& auxDets, double tolerance) const
82  {
83  double HalfCenterWidth = 0.;
84  double localPoint[3] = {0.};
85 
86 
87  for(size_t a = 0; a < auxDets.size(); ++a) {
88 
89  auxDets[a].WorldToLocal(point, localPoint);
90 
91  HalfCenterWidth = 0.5 * (auxDets[a].HalfWidth1() + auxDets[a].HalfWidth2());
92 
93  if( localPoint[2] >= - (auxDets[a].Length()/2 + tolerance) &&
94  localPoint[2] <= (auxDets[a].Length()/2 + tolerance) &&
95  localPoint[1] >= - auxDets[a].HalfHeight() - tolerance &&
96  localPoint[1] <= auxDets[a].HalfHeight() + tolerance &&
97  // if AuxDet a is a box, then HalfSmallWidth = HalfWidth
98  localPoint[0] >= - HalfCenterWidth + localPoint[2]*(HalfCenterWidth - auxDets[a].HalfWidth2())/(0.5 * auxDets[a].Length()) - tolerance &&
99  localPoint[0] <= HalfCenterWidth - localPoint[2]*(HalfCenterWidth - auxDets[a].HalfWidth2())/(0.5 * auxDets[a].Length()) + tolerance
100  ) return a;
101 
102  }// for loop over AudDet a
103 
104  // throw an exception because we couldn't find the sensitive volume
105  throw cet::exception("ChannelMap") << "Can't find AuxDet for position ("
106  << point[0] << ","
107  << point[1] << ","
108  << point[2] << ")\n";
109 
110  return UINT_MAX;
111 
112  }
113 
114  //----------------------------------------------------------------------------
115  size_t ChannelMapAlg::NearestSensitiveAuxDet(const double* point,
116  std::vector<geo::AuxDetGeo> const& auxDets, double tolerance) const
117  {
118  double HalfCenterWidth = 0.;
119  double localPoint[3] = {0.};
120 
121  size_t auxDetIdx = this->NearestAuxDet(point, auxDets, tolerance);
122 
123  geo::AuxDetGeo const& adg = auxDets[auxDetIdx];
124 
125  for(size_t a = 0; a < adg.NSensitiveVolume(); ++a) {
126 
127  geo::AuxDetSensitiveGeo const& adsg = adg.SensitiveVolume(a);
128  adsg.WorldToLocal(point, localPoint);
129 
130  HalfCenterWidth = 0.5 * (adsg.HalfWidth1() + adsg.HalfWidth2());
131 
132  if( localPoint[2] >= - (adsg.Length()/2 + tolerance) &&
133  localPoint[2] <= (adsg.Length()/2 + tolerance) &&
134  localPoint[1] >= - adsg.HalfHeight() - tolerance &&
135  localPoint[1] <= adsg.HalfHeight() + tolerance &&
136  // if AuxDet a is a box, then HalfSmallWidth = HalfWidth
137  localPoint[0] >= - HalfCenterWidth + localPoint[2]*(HalfCenterWidth - adsg.HalfWidth2())/(0.5 * adsg.Length()) - tolerance &&
138  localPoint[0] <= HalfCenterWidth - localPoint[2]*(HalfCenterWidth - adsg.HalfWidth2())/(0.5 * adsg.Length()) + tolerance
139  ) return a;
140  }// for loop over AuxDetSensitive a
141 
142  // throw an exception because we couldn't find the sensitive volume
143  throw cet::exception("Geometry") << "Can't find AuxDetSensitive for position ("
144  << point[0] << ","
145  << point[1] << ","
146  << point[2] << ")\n";
147 
148  return UINT_MAX;
149  }
150 
151  //----------------------------------------------------------------------------
152  size_t ChannelMapAlg::ChannelToAuxDet(std::vector<geo::AuxDetGeo> const& /* auxDets */,
153  std::string const& detName,
154  uint32_t const& /*channel*/) const
155  {
156  // loop over the map of AuxDet names to Geo object numbers to determine which auxdet
157  // we have. If no name in the map matches the provided string, throw an exception
158  for(auto itr : fADNameToGeo)
159  if( itr.first.compare(detName) == 0 ) return itr.second;
160 
161 
162  throw cet::exception("Geometry") << "No AuxDetGeo matching name: " << detName;
163 
164  return UINT_MAX;
165  }
166 
167  //----------------------------------------------------------------------------
168  // the first member of the pair is the index in the auxDets vector for the AuxDetGeo,
169  // the second member is the index in the vector of AuxDetSensitiveGeos for that AuxDetGeo
170  std::pair<size_t, size_t> ChannelMapAlg::ChannelToSensitiveAuxDet(std::vector<geo::AuxDetGeo> const& auxDets,
171  std::string const& detName,
172  uint32_t const& channel) const
173  {
174  size_t adGeoIdx = this->ChannelToAuxDet(auxDets, detName, channel);
175 
176  // look for the index of the sensitive volume for the given channel
177  if( fADChannelToSensitiveGeo.count(adGeoIdx) > 0 ){
178 
179  auto itr = fADChannelToSensitiveGeo.find(adGeoIdx);
180 
181  // get the vector of channels to AuxDetSensitiveGeo index
182  if( channel < itr->second.size() )
183  return std::make_pair(adGeoIdx, itr->second[channel]);
184 
185  throw cet::exception("Geometry") << "Given AuxDetSensitive channel, " << channel
186  << ", cannot be found in vector associated to AuxDetGeo index: "
187  << adGeoIdx << ". Vector has size " << itr->second.size();
188  }
189 
190  throw cet::exception("Geometry") << "Given AuxDetGeo with index " << adGeoIdx
191  << " does not correspond to any vector of sensitive volumes";
192 
193  return std::make_pair(adGeoIdx, UINT_MAX);
194  }
195 
197  {
198  return SignalTypeForChannelImpl(channel);
199  }
200 
202  {
203  return SignalTypeForROPIDImpl(ropid);
204  }
205 
207  {
209  }
210 }
float Length(const PFPStruct &pfp)
Definition: PFPUtils.cxx:3303
virtual std::pair< size_t, size_t > ChannelToSensitiveAuxDet(std::vector< geo::AuxDetGeo > const &auxDets, std::string const &detName, uint32_t const &channel) const
Returns the index of the sensitive detector containing the channel.
std::string string
Definition: nybbler.cc:12
AuxDetSensitiveGeo const & SensitiveVolume(size_t sv) const
Definition: AuxDetGeo.h:171
geo::SigType_t SignalTypeForROPID(readout::ROPID const &ropid) const
Return the signal type on the specified readout plane.
auto const tolerance
geo::SigType_t SignalTypeForChannel(raw::ChannelID_t const channel) const
Return the signal type of the specified channel.
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
virtual geo::SigType_t SignalTypeForChannelImpl(raw::ChannelID_t const channel) const =0
Return the signal type of the specified channel.
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:580
uint8_t channel
Definition: CRTFragment.hh:201
virtual unsigned int NOpChannels(unsigned int NOpDets) const
Returns the number of optical channels contained in some detectors.
virtual unsigned int OpDetFromOpChannel(unsigned int opChannel) const
Returns the optical detector the specified optical channel belongs.
unsigned int NearestWire(const TVector3 &worldPos, geo::PlaneID const &planeID) const
Returns the index of the wire nearest to the specified position.
enum geo::_plane_sigtype SigType_t
std::map< std::string, size_t > fADNameToGeo
map the names of the dets to the AuxDetGeo objects
const double a
Encapsulate the geometry of an auxiliary detector.
size_t NSensitiveVolume() const
Definition: AuxDetGeo.h:172
Class identifying a set of planes sharing readout channels.
std::map< size_t, std::vector< size_t > > fADChannelToSensitiveGeo
virtual raw::ChannelID_t FirstChannelInROP(readout::ROPID const &ropid) const =0
Returns the ID of the first channel in the specified readout plane.
virtual geo::SigType_t SignalTypeForROPIDImpl(readout::ROPID const &ropid) const
Return the signal type on the specified readout plane.
virtual unsigned int HardwareChannelFromOpChannel(unsigned int opChannel) const
Returns the hardware channel number of specified optical channel.
virtual unsigned int MaxOpChannel(unsigned int NOpDets) const
Returns the number of optical channels contained in some detectors.
virtual size_t ChannelToAuxDet(std::vector< geo::AuxDetGeo > const &auxDets, std::string const &detName, uint32_t const &channel) const
Returns the index of the detector containing the specified channel.
void WorldToLocal(const double *world, double *auxdet) const
Transform point from world frame to local auxiliary detector frame.
virtual unsigned int OpChannel(unsigned int detNum, unsigned int hwchannel=0) const
Returns the channel ID of the specified hardware channel.
virtual unsigned int NOpHardwareChannels(unsigned int opDet) const
Returns the number of channels in the specified optical detectors.
virtual geo::WireID NearestWireID(const TVector3 &worldPos, geo::PlaneID const &planeID) const
Returns the ID of the wire nearest to the specified position.
virtual bool IsValidOpChannel(unsigned int opChannel, unsigned int NOpDets) const
Returns whether the ID identifies a valid optical detector channel.
virtual size_t NearestSensitiveAuxDet(const double *point, std::vector< geo::AuxDetGeo > const &auxDets, double tolerance=0) const
Returns sensitive auxiliary detector closest to specified point.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
Interface to algorithm class for a specific detector channel mapping.
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:85
LArSoft geometry interface.
Definition: ChannelGeo.h:16
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
virtual size_t NearestAuxDet(const double *point, std::vector< geo::AuxDetGeo > const &auxDets, double tolerance=0) const
Returns the auxiliary detector closest to the specified point.