All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ChannelMapAlg.h
Go to the documentation of this file.
1 #ifndef GEO_CHANNELMAPALG_H
2 #define GEO_CHANNELMAPALG_H
3 // vim: sw=2 expandtab :
4 ////////////////////////////////////////////////////////////////////////
5 /// \file larcorealg/Geometry/ChannelMapAlg.h
6 /// \brief Interface to algorithm class for a specific detector channel mapping
7 /// \ingroup Geometry
8 ///
9 /// \author brebel@fnal.gov
10 ////////////////////////////////////////////////////////////////////////
11 
12 // LArSoft libraries
17 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
18 
19 // ROOT libraries
20 #include "TVector3.h"
21 
22 // C/C++ standard libraries
23 #include <cstddef>
24 #include <vector>
25 #include <map>
26 #include <set>
27 #include <string>
28 #include <utility>
29 
30 namespace geo{
31 
32  /**
33  * @brief Interface for a class providing readout channel mapping to geometry
34  * @ingroup Geometry
35  *
36  * @note A number of methods react specifically when provided with invalid IDs
37  * as arguments. An invalid ID is an ID with the `isValid` flag unset, or, in
38  * case of channel IDs, an ID with value `raw::InvalidChannelID`.
39  * An ID that does not present this feature is by definition "valid"; this
40  * does not imply that the represented entity (channel, geometry entity or
41  * readout group) actually exists. *The behaviour of the methods to valid,
42  * non-existent IDs should be considered undefined*, and it is recommended
43  * that the existence of the entity is checked beforehand.
44  * Unless the documentation explicitly defines a behaviour, an undefined
45  * behaviour should be assumed; nevertheless, the documentation of some of the
46  * methods still reminds of this.
47  */
49 
50  public:
51 
52  /// Virtual destructor
53  virtual ~ChannelMapAlg() = default;
54 
55 
56  //--------------------------------------------------------------------------
57  /// @{
58  /// @name Geometry and mapping initialization and management
59 
60  /// Geometry initialisation
61  virtual void Initialize(GeometryData_t const& geodata) = 0;
62 
63  /// Deconfiguration: prepare for a following call of Initialize()
64  virtual void Uninitialize() = 0;
65 
66 
67  /// @}
68 
69 
70  //--------------------------------------------------------------------------
71  /// @{
72  /// @name TPC channel mapping
73 
74  /// Returns the total number of channels present (not necessarily contiguous)
75  virtual unsigned int Nchannels() const = 0;
76 
77  /// @brief Returns the number of channels in the specified ROP
78  /// @return number of channels in the specified ROP, 0 if non-existent
79  virtual unsigned int Nchannels(readout::ROPID const& ropid) const = 0;
80 
81  /// @brief Returns whether the specified channel is valid
82  /// This default implementation assumes all channels up to Nchannels() valid.
83  virtual bool HasChannel(raw::ChannelID_t channel) const
84  { return raw::isValidChannelID(channel)? channel < Nchannels(): false; }
85 
86  /// Returns a list of TPC wires connected to the specified readout channel ID
87  /// @throws cet::exception (category: "Geometry") if non-existent channel
88  virtual std::vector<WireID> ChannelToWire
89  (raw::ChannelID_t channel) const = 0;
90 
91  /**
92  * @brief Return the signal type of the specified channel
93  * @param channel ID of the channel
94  * @return signal type of the channel, or geo::kMysteryType if not known
95  *
96  * On any type of error (e.g., invalid or unknown channel ID),
97  * geo::kMysteryType is returned.
98  */
100 
101  protected:
102 
103  /**
104  * @brief Return the signal type of the specified channel
105  * @param channel ID of the channel
106  * @return signal type of the channel, or geo::kMysteryType if not known
107  *
108  * On any type of error (e.g., invalid or unknown channel ID),
109  * geo::kMysteryType is returned.
110  */
111  virtual geo::SigType_t SignalTypeForChannelImpl(raw::ChannelID_t const channel) const = 0;
112 
113  public:
114 
115  /**
116  * @brief Return the signal type on the specified readout plane
117  * @param ropid ID of the readout plane
118  * @return signal type on the plane, or geo::kMysteryType if not known
119  *
120  * If the readout plane ID is marked invalid, geo::kMysteryType is returned.
121  * If the readout plane is not marked invalid, but it does not match an
122  * existing readout plane, the result is undefined.
123  *
124  * The default implementation uses readout plane to channel mapping.
125  * Other implementation may decide to do the opposite.
126  */
128 
129  protected:
130 
131  /**
132  * @brief Return the signal type on the specified readout plane
133  * @param ropid ID of the readout plane
134  * @return signal type on the plane, or geo::kMysteryType if not known
135  *
136  * If the readout plane ID is marked invalid, geo::kMysteryType is returned.
137  * If the readout plane is not marked invalid, but it does not match an
138  * existing readout plane, the result is undefined.
139  *
140  * The default implementation uses readout plane to channel mapping.
141  * Other implementation may decide to do the opposite.
142  */
143  virtual geo::SigType_t SignalTypeForROPIDImpl(readout::ROPID const& ropid) const;
144 
145  public:
146 
147  /// Returns a list of the plane IDs in the whole detector
148  virtual std::set<geo::PlaneID> const& PlaneIDs() const = 0;
149 
150  /**
151  * @brief Returns the channel ID a wire is connected to
152  * @param wireID ID of the wire
153  * @return the ID of the channel
154  * @see PlaneWireToChannel(geo::WireID const&)
155  *
156  * Behaviour on an invalid or not present wires is undefined.
157  *
158  * @deprecated Use the version with `geo::WireID`
159  */
160  virtual raw::ChannelID_t PlaneWireToChannel(geo::WireID const& wireID) const
161  {
162  return PlaneWireToChannel
163  (wireID.Plane, wireID.Wire, wireID.TPC, wireID.Cryostat);
164  }
165 
166  /**
167  * @brief Returns the channel ID a wire is connected to
168  * @param plane number of plane
169  * @param wire number of wire
170  * @param tpc number of TPC
171  * @param cstat number of cryostat
172  * @return the ID of the channel
173  * @see PlaneWireToChannel(geo::WireID const&)
174  *
175  * @deprecated Use the version with `geo::WireID`
176  */
177  virtual raw::ChannelID_t PlaneWireToChannel(unsigned int plane,
178  unsigned int wire,
179  unsigned int tpc,
180  unsigned int cstat) const = 0;
181 
182  /// @}
183 
184 
185  //--------------------------------------------------------------------------
186  /// @{
187  /// @name Optical detector channel mapping
188 
189  /**
190  * @brief Returns the number of optical channels contained in some detectors
191  * @param NOpDets number of optical detectors
192  * @return optical channels contained in NOpDets detectors
193  *
194  * This function returns how many channels can be expected to be present
195  * in a detector with NOpDets optical detectors. This is an upper limit, as
196  * not all channels have necessarily to be present.
197  *
198  * For example: if a detector has four channels per optical detector, the
199  * returned value will be four times the argument NOpDets. If there is a
200  * single channel on each optical detector, the return value will be the
201  * value NOpDets (this is in fact the fallback implementation). If each
202  * optical detector can have anywhere between 2 and 12 channels, the
203  * returned value is 12 times NOpDets, and it will be an overestimation of
204  * the number of channels.
205  */
206  virtual unsigned int NOpChannels(unsigned int NOpDets) const;
207 
208  /**
209  * @brief Returns the number of optical channels contained in some detectors
210  * @param NOpDets number of optical detectors
211  * @return optical channels contained in NOpDets detectors
212  *
213  * This function returns the first optical channel ID larger than the last
214  * channel ID in a detector with NOpDets optical detectors (with the same
215  * logic as `NOpChannels()`).
216  * For example, in a detector with 32 channels with contiguous
217  * IDs starting at 0, this function would return 32. If the channels started
218  * with ID 1, this function would instead return 33 and if there were a 16
219  * channel gap, so that valid channels are from 0 to 15 and from 32 to 47,
220  * this function would return 48.
221  */
222  virtual unsigned int MaxOpChannel(unsigned int NOpDets) const;
223 
224  /**
225  * @brief Returns the number of channels in the specified optical detectors
226  * @param opDet ID of the chosen optical detector
227  * @return optical channels contained in optical detector with ID opDet
228  *
229  * This function returns how many channels are actually present in the
230  * optical detector with the specified ID.
231  *
232  * For example: if a detector has four channels per optical detector, the
233  * returned value will be four, regardless opDet, and . If there is a
234  * single channel on each optical detector, the return value will be 1,
235  * again ignoring opDet (this is in fact the fallback implementation). If
236  * each optical detector can have anywhere between 2 and 12 channels, the
237  * returned value will be 2, 12, etc., that is the exact number of channels
238  * in opDet.
239  *
240  * Although implementations are encouraged to return 0 on invalid optical
241  * detectors, the actual return value in that case is undefined.
242  */
243  virtual unsigned int NOpHardwareChannels(unsigned int opDet) const;
244 
245  /**
246  * @brief Returns whether the ID identifies a valid optical detector channel
247  * @param opChannel channel number
248  * @param NOpDets number of optical detectors in the detector
249  * @return whether opChannel would be a valid channel
250  *
251  * The specification of the number of optical channels reflects the logic
252  * described in `NOpChannel()`.
253  */
254  virtual bool IsValidOpChannel
255  (unsigned int opChannel, unsigned int NOpDets) const;
256 
257  /**
258  * @brief Returns the channel ID of the specified hardware channel
259  * @param detNum optical detector ID
260  * @param hwchannel hardware channel within the specified optical detector
261  * @return ID of the channel identified by detector and hardware channel IDs
262  *
263  * If the input IDs identify a non-existing channel, the result is
264  * undefined.
265  */
266  virtual unsigned int OpChannel
267  (unsigned int detNum, unsigned int hwchannel = 0) const;
268 
269  /**
270  * @brief Returns the optical detector the specified optical channel belongs
271  * @param opChannel the optical detector channel being queried
272  * @return the optical detector the specified optical channel belongs to
273  *
274  * If the specified optical channel is invalid, behaviour is undefined.
275  */
276  virtual unsigned int OpDetFromOpChannel(unsigned int opChannel) const;
277 
278  /**
279  * @brief Returns the hardware channel number of specified optical channel
280  * @param opChannel the optical detector channel being queried
281  * @return the optical detector the specified optical channel belongs to
282  *
283  * If the specified optical channel is invalid, behaviour is undefined.
284  */
285  virtual unsigned int HardwareChannelFromOpChannel
286  (unsigned int opChannel) const;
287 
288  /// @}
289 
290 
291  //--------------------------------------------------------------------------
292  /// @{
293  /// @name Mapping of position to wires
294 
295  /**
296  * @brief Returns the index of the wire nearest to the specified position
297  * @param YPos y coordinate on the wire plane
298  * @param ZPos z coordinate on the wire plane
299  * @param planeID ID of the plane
300  * @return an index interpolation between the two nearest wires
301  * @see NearestWireID()
302  *
303  * Respect to NearestWireID(), this method returns a real number,
304  * representing a continuous coordinate in the wire axis, with the round
305  * values corresponding to the actual wires.
306  *
307  * The plane is required to be valid and exist in the detector. Otherwise,
308  * the behaviour is undefined.
309  */
310  virtual double WireCoordinate(double YPos,
311  double ZPos,
312  geo::PlaneID const& planeID) const
313  {
314  return WireCoordinate
315  (YPos, ZPos, planeID.Plane, planeID.TPC, planeID.Cryostat);
316  }
317 
318  /**
319  * @brief Returns the index of the wire nearest to the specified position
320  * @param YPos y coordinate on the wire plane
321  * @param ZPos z coordinate on the wire plane
322  * @param PlaneNo number of plane
323  * @param TPCNo number of TPC
324  * @param cstat number of cryostat
325  * @return an index interpolation between the two nearest wires
326  * @see WireCoordinate(double, double, geo::PlaneID const&)
327  *
328  * @deprecated Use the version with `geo::PlaneID` instead
329  */
330  virtual double WireCoordinate(double YPos,
331  double ZPos,
332  unsigned int PlaneNo,
333  unsigned int TPCNo,
334  unsigned int cstat) const = 0;
335 
336 
337  /**
338  * @brief Returns the ID of the wire nearest to the specified position
339  * @param worldPos position to be tested
340  * @param planeID plane containing the wire
341  * @return the ID of the wire closest to worldPos in the specified plane
342  * @throw InvalidWireIDError the ID found is not present in the detector
343  * @see WireCoordinate(double, double, geo::PlaneID const&)
344  *
345  * The plane is required to be valid and exist in the detector. Otherwise,
346  * the behaviour is undefined.
347  * An exception is thrown if the wire that would be the closest is actually
348  * not present; but no check is performed whether the specified position is
349  * outside the wire plane: wires are extrapolated to be infinitely long.
350  * In other words, the result can be trusted only as long as the position
351  * is within the specified wire plane.
352  */
353  virtual geo::WireID NearestWireID
354  (const TVector3& worldPos, geo::PlaneID const& planeID) const
355  {
356  return
357  NearestWireID(worldPos, planeID.Plane, planeID.TPC, planeID.Cryostat);
358  }
359 
360  /**
361  * @brief Returns the ID of the wire nearest to the specified position
362  * @param worldPos position to be tested
363  * @param PlaneNo number of plane containing the wire
364  * @param TPCNo number of TPC containing the wire
365  * @param cstat number of cryostat containing the wire
366  * @return the ID of the wire closest to worldPos in the specified plane
367  * @see NearestWireID(const TVector3&, geo::PlaneID const&)
368  *
369  * @deprecated Use the version with `geo::PlaneID` instead
370  */
371  virtual geo::WireID NearestWireID(const TVector3& worldPos,
372  unsigned int PlaneNo,
373  unsigned int TPCNo,
374  unsigned int cstat) const = 0;
375 
376  /**
377  * @brief Returns the index of the wire nearest to the specified position
378  * @param worldPos position to be tested
379  * @param planeID plane containing the wire
380  * @return the ID of the wire closest to worldPos in the specified plane
381  * @see NearestWireID(const TVector3&, geo::PlaneID const&)
382  *
383  * @deprecated Use `NearestWireID(const TVector3&, geo::PlaneID const&)`
384  * instead.
385  */
386  unsigned int NearestWire(const TVector3& worldPos,
387  geo::PlaneID const& planeID) const;
388 
389  /**
390  * @brief Returns the index of the wire nearest to the specified position
391  * @param worldPos position to be tested
392  * @param PlaneNo number of plane containing the wire
393  * @param TPCNo number of TPC containing the wire
394  * @param cstat number of cryostat containing the wire
395  * @return the ID of the wire closest to worldPos in the specified plane
396  * @see NearestWireID(const TVector3&, geo::PlaneID const&)
397  *
398  * @deprecated Use `NearestWireID(const TVector3&, geo::PlaneID const&)`
399  * instead.
400  */
401  unsigned int NearestWire(const TVector3& worldPos,
402  unsigned int PlaneNo,
403  unsigned int TPCNo,
404  unsigned int cstat) const
405  { return NearestWire(worldPos, geo::PlaneID(cstat, TPCNo, PlaneNo)); }
406 
407  /// @}
408 
409 
410  //--------------------------------------------------------------------------
411  /// @{
412  /// @name Auxiliary detectors
413 
414  /**
415  * @brief Returns the auxiliary detector closest to the specified point
416  * @param point coordinates of the position to be investigated (x, y, z)
417  * @param auxDets list of the sought auxiliary detectors
418  * @param tolerance tolerance for comparison. Default 0.
419  * @return index of auxiliary detector within auxDets
420  */
421  virtual size_t NearestAuxDet
422  (const double* point, std::vector<geo::AuxDetGeo> const& auxDets, double tolerance = 0) const;
423 
424  /**
425  * @brief Returns sensitive auxiliary detector closest to specified point
426  * @param point coordinates of the position to be investigated (x, y, z)
427  * @param auxDets list of the auxiliary detectors
428  * @param tolerance tolerance for comparison. Default 0.
429  * @return index of sought sensitive auxiliary detector within auxDets
430  */
431  virtual size_t NearestSensitiveAuxDet
432  (const double* point, std::vector<geo::AuxDetGeo> const& auxDets, double tolerance = 0) const;
433 
434  /**
435  * @brief Returns the index of the detector containing the specified channel
436  * @param auxDets list of the auxiliary detectors
437  * @param detName name of the auxiliary detector being investigated
438  * @param channel number of the channel within that auxiliary detector
439  * @return index of the sought auxiliary detector within auxDets
440  *
441  * @bug This function is somehow broken in that it ignores the `auxDets`
442  * in the arguments and instead relies on a cache that is never filled
443  * by this class (derived classes can fill it though).
444  */
445  virtual size_t ChannelToAuxDet(std::vector<geo::AuxDetGeo> const& auxDets,
446  std::string const& detName,
447  uint32_t const& channel
448  ) const;
449 
450  /**
451  * @brief Returns the index of the sensitive detector containing the channel
452  * @param auxDets list of the sensitive auxiliary detectors
453  * @param detName name of the auxiliary detector being investigated
454  * @param channel number of the channel within that auxiliary detector
455  * @return index of the sought sensitive auxiliary detector within auxDets
456  */
457  virtual std::pair<size_t, size_t> ChannelToSensitiveAuxDet(
458  std::vector<geo::AuxDetGeo> const& auxDets,
459  std::string const& detName,
460  uint32_t const& channel
461  ) const;
462 
463  /// @}
464 
465 
466  //--------------------------------------------------------------------------
467  /// @name TPC set mapping
468  /// @{
469  /**
470  * @brief Returns the total number of TPC sets in the specified cryostat
471  * @param cryoid cryostat ID
472  * @return number of TPC sets in the cryostat, or 0 if no cryostat found
473  */
474  virtual unsigned int NTPCsets(readout::CryostatID const& cryoid) const = 0;
475 
476  /// Returns the largest number of TPC sets any cryostat in the detector has
477  virtual unsigned int MaxTPCsets() const = 0;
478 
479  /// Returns whether we have the specified TPC set
480  /// @return whether the TPC set is valid and exists
481  virtual bool HasTPCset(readout::TPCsetID const& tpcsetid) const = 0;
482 
483  /// Returns the ID of the TPC set tpcid belongs to
484  virtual readout::TPCsetID TPCtoTPCset(geo::TPCID const& tpcid) const = 0;
485 
486  /**
487  * @brief Returns a list of ID of TPCs belonging to the specified TPC set
488  * @param tpcsetid ID of the TPC set to convert into TPC IDs
489  * @return the list of TPCs, empty if TPC set is invalid
490  *
491  * Note that the check is performed on the validity of the TPC set ID, that
492  * does not necessarily imply that the TPC set specified by the ID actually
493  * exists. Check the existence of the TPC set first (HasTPCset()).
494  * Behaviour on valid, non-existent TPC set IDs is undefined.
495  */
496  virtual std::vector<geo::TPCID> TPCsetToTPCs
497  (readout::TPCsetID const& tpcsetid) const = 0;
498 
499  /// Returns the ID of the first TPC belonging to the specified TPC set
501  (readout::TPCsetID const& tpcsetid) const = 0;
502 
503  /// @} TPC set mapping
504 
505 
506  //--------------------------------------------------------------------------
507  /// @name Readout plane mapping
508  /// @{
509  /**
510  * @brief Returns the total number of ROP in the specified TPC set
511  * @param tpcsetid TPC set ID
512  * @return number of readout planes in the TPC set, or 0 if no TPC set found
513  *
514  * Note that this methods explicitly check the existence of the TPC set.
515  */
516  virtual unsigned int NROPs(readout::TPCsetID const& tpcsetid) const = 0;
517 
518  /// Returns the largest number of ROPs a TPC set in the detector has
519  virtual unsigned int MaxROPs() const = 0;
520 
521  /// Returns whether we have the specified ROP
522  /// @return whether the readout plane is valid and exists
523  virtual bool HasROP(readout::ROPID const& ropid) const = 0;
524 
525  /// Returns the ID of the ROP planeid belongs to
527  (geo::PlaneID const& planeid) const = 0;
528 
529  /// Returns a list of ID of planes belonging to the specified ROP
530  virtual std::vector<geo::PlaneID> ROPtoWirePlanes
531  (readout::ROPID const& ropid) const = 0;
532 
533  /// Returns the ID of the first plane belonging to the specified ROP
535  (readout::ROPID const& ropid) const = 0;
536 
537  /**
538  * @brief Returns a list of ID of TPCs the specified ROP spans
539  * @param ropid ID of the readout plane
540  * @return the list of TPC IDs, empty if readout plane ID is invalid
541  *
542  * Note that this check is performed on the validity of the readout plane
543  * ID, that does not necessarily imply that the readout plane specified by
544  * the ID actually exists. Check if the ROP exists with HasROP().
545  * The behaviour on non-existing readout planes is undefined.
546  */
547  virtual std::vector<geo::TPCID> ROPtoTPCs
548  (readout::ROPID const& ropid) const = 0;
549 
550  /**
551  * @brief Returns the ID of the ROP the channel belongs to
552  * @return the ID of the ROP the channel belongs to (invalid if channel is)
553  * @see HasChannel()
554  *
555  * The channel must exist, or be the invalid channel value.
556  * With a channel that is not present in the mapping and that is not the
557  * invalid channel (`raw::InvalidChannelID`), the result is undefined.
558  */
559  virtual readout::ROPID ChannelToROP(raw::ChannelID_t channel) const = 0;
560 
561  /**
562  * @brief Returns the ID of the first channel in the specified readout plane
563  * @param ropid ID of the readout plane
564  * @return ID of first channel, or raw::InvalidChannelID if ID is invalid
565  *
566  * Note that this check is performed on the validity of the readout plane
567  * ID, that does not necessarily imply that the readout plane specified by
568  * the ID actually exists. Check if the ROP exists with HasROP().
569  * The behaviour for non-existing readout planes is undefined.
570  */
572  (readout::ROPID const& ropid) const = 0;
573 
574  /// @}
575 
576 
577  //--------------------------------------------------------------------------
578  /// Returns the object to sort geometry with
579  virtual geo::GeoObjectSorter const& Sorter() const = 0;
580 
581  //--------------------------------------------------------------------------
582  /// @{
583  /// @name Testing (not in the interface)
584 
585  /// Retrieve the private fFirstChannelInNextPlane vector for testing.
586  const std::vector<std::vector<std::vector<raw::ChannelID_t>>> FirstChannelInNextPlane() const
587  { return fFirstChannelInThisPlane; }
588 
589  /// Retrieve the private fFirstChannelInThisPlane vector for testing.
590  const std::vector<std::vector<std::vector<raw::ChannelID_t>>> FirstChannelInThisPlane() const
591  { return fFirstChannelInNextPlane; }
592 
593  /// @}
594 
595  //--------------------------------------------------------------------------
596 
597  protected:
598 
599  /// Data type for per-TPC information
600  template <typename T>
601  using TPCInfoMap_t = std::vector<std::vector<T>>;
602 
603  /// Data type for per-plane information
604  template <typename T>
606 
607  // These 3D vectors are used in initializing the Channel map.
608  // Only a 1D vector is really needed so far, but these are more general.
611 
612  std::map<std::string, size_t> fADNameToGeo; ///< map the names of the dets to the AuxDetGeo objects
613  std::map<size_t, std::vector<size_t> > fADChannelToSensitiveGeo; ///< map the AuxDetGeo index to a vector of
614  ///< indices corresponding to the AuxDetSensitiveGeo index
615 
616  /**
617  * @name Internal structure data access
618  *
619  * These functions allow access to the XxxInfoMap_t types based on geometry
620  * element IDs.
621  * They are strictly internal.
622  */
623  /// @{
624 
625  /// Returns the specified element of the TPC map
626  template <typename T>
627  T const& AccessElement
628  (TPCInfoMap_t<T> const& map, geo::TPCID const& id) const
629  { return map[id.Cryostat][id.TPC]; }
630 
631  /// Returns the number of elements in the specified cryostat of the TPC map
632  template <typename T>
633  size_t AccessElementSize
634  (TPCInfoMap_t<T> const& map, geo::CryostatID const& id) const
635  { return map[id.Cryostat].size(); }
636 
637  //@{
638  /// Returns whether the ID specifies a valid entry
639  template <typename T>
640  bool isValidElement
641  (TPCInfoMap_t<T> const& map, geo::CryostatID const& id) const
642  { return id.Cryostat < map.size(); }
643  template <typename T>
644  bool isValidElement(TPCInfoMap_t<T> const& map, geo::TPCID const& id) const
645  {
646  return isValidElement(map, id.asCryostatID())
647  && (id.TPC < map[id.Cryostat].size());
648  }
649  //@}
650 
651 
652  /// Returns the specified element of the plane map
653  template <typename T>
654  T const& AccessElement
655  (PlaneInfoMap_t<T> const& map, geo::PlaneID const& id) const
656  { return map[id.Cryostat][id.TPC][id.Plane]; }
657 
658  /// Returns the number of elements in the specified TPC of the plane map
659  template <typename T>
660  size_t AccessElementSize
661  (PlaneInfoMap_t<T> const& map, geo::TPCID const& id) const
662  { return map[id.Cryostat][id.TPC].size(); }
663 
664  //@{
665  /// Returns whether the ID specifies a valid entry
666  template <typename T>
667  bool isValidElement
668  (PlaneInfoMap_t<T> const& map, geo::CryostatID const& id) const
669  { return id.Cryostat < map.size(); }
670  template <typename T>
671  bool isValidElement(PlaneInfoMap_t<T> const& map, geo::TPCID const& id) const
672  {
673  return isValidElement(map, id.asCryostatID())
674  && (id.TPC < map[id.Cryostat].size());
675  }
676  template <typename T>
677  bool isValidElement
678  (PlaneInfoMap_t<T> const& map, geo::PlaneID const& id) const
679  {
680  return isValidElement(map, id.asTPCID())
681  && (id.Plane < AccessSize(map, id.asTPCID()));
682  }
683  //@}
684 
685  /// Returns a pointer to the specified element, or nullptr if invalid
686  template <typename T>
687  T const* GetElementPtr
688  (PlaneInfoMap_t<T> const& map, geo::PlaneID const& id) const
689  {
690  if (id.Cryostat >= map.size()) return nullptr;
691  auto const& cryo_map = map[id.Cryostat];
692  if (id.TPC >= cryo_map.size()) return nullptr;
693  auto const& TPC_map = cryo_map[id.TPC];
694  if (id.Plane >= TPC_map.size()) return nullptr;
695  auto const& plane_map = TPC_map[id.Plane];
696  return &plane_map;
697  } // GetElementPtr()
698 
699  ///@} Internal structure data access
700 
701  };
702 }
703 #endif // GEO_CHANNELMAPALG_H
Interface for a class providing readout channel mapping to geometry.
Definition: ChannelMapAlg.h:48
BEGIN_PROLOG true icarus_rawdigitfilter FilterTools FilterPlane1 Plane
virtual double WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeID) const
Returns the index of the wire nearest to the specified position.
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.
bool isValidElement(TPCInfoMap_t< T > const &map, geo::TPCID const &id) const
Classes identifying readout-related concepts.
virtual geo::GeoObjectSorter const & Sorter() const =0
Returns the object to sort geometry with.
bool isValidElement(PlaneInfoMap_t< T > const &map, geo::TPCID const &id) const
const std::vector< std::vector< std::vector< raw::ChannelID_t > > > FirstChannelInThisPlane() const
Retrieve the private fFirstChannelInThisPlane vector for testing.
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.
Simple data structure holding the data of the geometry.
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
Class identifying a set of TPC sharing readout channels.
Definition: readout_types.h:70
virtual readout::TPCsetID TPCtoTPCset(geo::TPCID const &tpcid) const =0
Returns the ID of the TPC set tpcid belongs to.
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:580
T const & AccessElement(TPCInfoMap_t< T > const &map, geo::TPCID const &id) const
Returns the specified element of the TPC map.
virtual unsigned int MaxTPCsets() const =0
Returns the largest number of TPC sets any cryostat in the detector has.
PlaneInfoMap_t< raw::ChannelID_t > fFirstChannelInThisPlane
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.
virtual bool HasROP(readout::ROPID const &ropid) const =0
virtual void Uninitialize()=0
Deconfiguration: prepare for a following call of Initialize()
BEGIN_PROLOG TPC
std::vector< std::vector< T >> TPCInfoMap_t
Data type for per-TPC information.
virtual bool HasTPCset(readout::TPCsetID const &tpcsetid) const =0
TPCInfoMap_t< std::vector< T >> PlaneInfoMap_t
Data type for per-plane information.
Interface to algorithm class for sorting geo::XXXGeo objects.
unsigned int NearestWire(const TVector3 &worldPos, geo::PlaneID const &planeID) const
Returns the index of the wire nearest to the specified position.
virtual unsigned int NTPCsets(readout::CryostatID const &cryoid) const =0
Returns the total number of TPC sets in the specified cryostat.
virtual raw::ChannelID_t FirstChannelInROP(readout::ROPID const &ropid) const =0
Returns the ID of the first channel in the specified readout plane.
virtual std::vector< geo::TPCID > TPCsetToTPCs(readout::TPCsetID const &tpcsetid) const =0
Returns a list of ID of TPCs belonging to the specified TPC set.
enum geo::_plane_sigtype SigType_t
std::map< std::string, size_t > fADNameToGeo
map the names of the dets to the AuxDetGeo objects
virtual unsigned int MaxROPs() const =0
Returns the largest number of ROPs a TPC set in the detector has.
virtual unsigned int Nchannels() const =0
Returns the total number of channels present (not necessarily contiguous)
virtual raw::ChannelID_t PlaneWireToChannel(geo::WireID const &wireID) const
Returns the channel ID a wire is connected to.
constexpr bool isValidChannelID(raw::ChannelID_t channel)
Definition: RawTypes.h:37
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
Definition of data types for geometry description.
Class identifying a set of planes sharing readout channels.
std::map< size_t, std::vector< size_t > > fADChannelToSensitiveGeo
unsigned int NearestWire(const TVector3 &worldPos, unsigned int PlaneNo, unsigned int TPCNo, unsigned int cstat) const
Returns the index of the wire nearest to the specified position.
T const * GetElementPtr(PlaneInfoMap_t< T > const &map, geo::PlaneID const &id) const
Returns a pointer to the specified element, or nullptr if invalid.
size_t AccessElementSize(TPCInfoMap_t< T > const &map, geo::CryostatID const &id) const
Returns the number of elements in the specified cryostat of the TPC map.
virtual geo::SigType_t SignalTypeForChannelImpl(raw::ChannelID_t const channel) const =0
Return the signal type of the specified channel.
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 geo::PlaneID FirstWirePlaneInROP(readout::ROPID const &ropid) const =0
Returns the ID of the first plane belonging to the specified ROP.
virtual readout::ROPID WirePlaneToROP(geo::PlaneID const &planeid) const =0
Returns the ID of the ROP planeid belongs to.
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.
virtual bool HasChannel(raw::ChannelID_t channel) const
Returns whether the specified channel is valid This default implementation assumes all channels up to...
Definition: ChannelMapAlg.h:83
virtual std::vector< geo::PlaneID > ROPtoWirePlanes(readout::ROPID const &ropid) const =0
Returns a list of ID of planes belonging to the specified ROP.
virtual unsigned int OpChannel(unsigned int detNum, unsigned int hwchannel=0) const
Returns the channel ID of the specified hardware channel.
bool isValidElement(TPCInfoMap_t< T > const &map, geo::CryostatID const &id) const
Returns whether the ID specifies a valid entry.
virtual unsigned int NOpHardwareChannels(unsigned int opDet) const
Returns the number of channels in the specified optical detectors.
virtual std::set< geo::PlaneID > const & PlaneIDs() const =0
Returns a list of the plane IDs in the whole detector.
virtual geo::WireID NearestWireID(const TVector3 &worldPos, geo::PlaneID const &planeID) const
Returns the ID of the wire nearest to the specified position.
virtual ~ChannelMapAlg()=default
Virtual destructor.
virtual bool IsValidOpChannel(unsigned int opChannel, unsigned int NOpDets) const
Returns whether the ID identifies a valid optical detector channel.
virtual geo::TPCID FirstTPCinTPCset(readout::TPCsetID const &tpcsetid) const =0
Returns the ID of the first TPC belonging to the specified TPC set.
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.
Data in the geometry description.
Definition: GeometryData.h:31
PlaneInfoMap_t< raw::ChannelID_t > fFirstChannelInNextPlane
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
virtual std::vector< WireID > ChannelToWire(raw::ChannelID_t channel) const =0
virtual unsigned int NROPs(readout::TPCsetID const &tpcsetid) const =0
Returns the total number of ROP in the specified TPC set.
const std::vector< std::vector< std::vector< raw::ChannelID_t > > > FirstChannelInNextPlane() const
Retrieve the private fFirstChannelInNextPlane vector for testing.
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.
virtual void Initialize(GeometryData_t const &geodata)=0
Geometry initialisation.
The data type to uniquely identify a cryostat.
Definition: geo_types.h:190
virtual readout::ROPID ChannelToROP(raw::ChannelID_t channel) const =0
Returns the ID of the ROP the channel belongs to.
virtual std::vector< geo::TPCID > ROPtoTPCs(readout::ROPID const &ropid) const =0
Returns a list of ID of TPCs the specified ROP spans.