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