LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ChannelMapAlg.h
Go to the documentation of this file.
1 #ifndef GEO_CHANNELMAPALG_H
2 #define GEO_CHANNELMAPALG_H
3 // vim: sw=2 expandtab :
11 
12 // LArSoft libraries
15 #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 <map>
25 #include <set>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 namespace geo {
31 
48  class ChannelMapAlg {
49  public:
50  virtual ~ChannelMapAlg() = default;
51 
52  //--------------------------------------------------------------------------
55 
57  virtual void Initialize(GeometryData_t const& geodata) = 0;
58 
60  virtual void Uninitialize() = 0;
61 
63 
64  //--------------------------------------------------------------------------
67 
69  virtual unsigned int Nchannels() const = 0;
70 
73  virtual unsigned int Nchannels(readout::ROPID const& ropid) const = 0;
74 
77  virtual bool HasChannel(raw::ChannelID_t channel) const
78  {
79  return raw::isValidChannelID(channel) ? channel < Nchannels() : false;
80  }
81 
84  virtual std::vector<WireID> ChannelToWire(raw::ChannelID_t channel) const = 0;
85 
94  SigType_t SignalTypeForChannel(raw::ChannelID_t const channel) const;
95 
96  protected:
105  virtual SigType_t SignalTypeForChannelImpl(raw::ChannelID_t const channel) const = 0;
106 
107  public:
120  SigType_t SignalTypeForROPID(readout::ROPID const& ropid) const;
121 
122  protected:
135  virtual SigType_t SignalTypeForROPIDImpl(readout::ROPID const& ropid) const;
136 
137  public:
139  virtual std::set<PlaneID> const& PlaneIDs() const = 0;
140 
149  virtual raw::ChannelID_t PlaneWireToChannel(WireID const& wireID) const = 0;
150 
152 
153  //--------------------------------------------------------------------------
156 
174  virtual unsigned int NOpChannels(unsigned int NOpDets) const;
175 
190  virtual unsigned int MaxOpChannel(unsigned int NOpDets) const;
191 
211  virtual unsigned int NOpHardwareChannels(unsigned int opDet) const;
212 
222  virtual bool IsValidOpChannel(unsigned int opChannel, unsigned int NOpDets) const;
223 
233  virtual unsigned int OpChannel(unsigned int detNum, unsigned int hwchannel = 0) const;
234 
242  virtual unsigned int OpDetFromOpChannel(unsigned int opChannel) const;
243 
251  virtual unsigned int HardwareChannelFromOpChannel(unsigned int opChannel) const;
252 
254 
255  //--------------------------------------------------------------------------
258 
274  virtual double WireCoordinate(double YPos, double ZPos, PlaneID const& planeID) const = 0;
275 
292  virtual WireID NearestWireID(Point_t const& worldPos, PlaneID const& planeID) const = 0;
293 
295 
296  //--------------------------------------------------------------------------
299 
307  virtual size_t NearestAuxDet(Point_t const& point,
308  std::vector<AuxDetGeo> const& auxDets,
309  double tolerance = 0) const;
310 
318  virtual size_t NearestSensitiveAuxDet(Point_t const& point,
319  std::vector<AuxDetGeo> const& auxDets,
320  double tolerance = 0) const;
321 
333  virtual size_t ChannelToAuxDet(std::vector<AuxDetGeo> const& auxDets,
334  std::string const& detName,
335  uint32_t const& channel) const;
336 
344  virtual std::pair<size_t, size_t> ChannelToSensitiveAuxDet(
345  std::vector<AuxDetGeo> const& auxDets,
346  std::string const& detName,
347  uint32_t const& channel) const;
348 
350 
351  //--------------------------------------------------------------------------
354 
359  virtual unsigned int NTPCsets(readout::CryostatID const& cryoid) const = 0;
360 
362  virtual unsigned int MaxTPCsets() const = 0;
363 
366  virtual bool HasTPCset(readout::TPCsetID const& tpcsetid) const = 0;
367 
369  virtual readout::TPCsetID TPCtoTPCset(TPCID const& tpcid) const = 0;
370 
381  virtual std::vector<TPCID> TPCsetToTPCs(readout::TPCsetID const& tpcsetid) const = 0;
382 
384  virtual TPCID FirstTPCinTPCset(readout::TPCsetID const& tpcsetid) const = 0;
385 
387 
388  //--------------------------------------------------------------------------
391 
398  virtual unsigned int NROPs(readout::TPCsetID const& tpcsetid) const = 0;
399 
401  virtual unsigned int MaxROPs() const = 0;
402 
405  virtual bool HasROP(readout::ROPID const& ropid) const = 0;
406 
408  virtual readout::ROPID WirePlaneToROP(PlaneID const& planeid) const = 0;
409 
411  virtual std::vector<PlaneID> ROPtoWirePlanes(readout::ROPID const& ropid) const = 0;
412 
414  virtual PlaneID FirstWirePlaneInROP(readout::ROPID const& ropid) const = 0;
415 
426  virtual std::vector<TPCID> ROPtoTPCs(readout::ROPID const& ropid) const = 0;
427 
437  virtual readout::ROPID ChannelToROP(raw::ChannelID_t channel) const = 0;
438 
449  virtual raw::ChannelID_t FirstChannelInROP(readout::ROPID const& ropid) const = 0;
450 
452 
453  //--------------------------------------------------------------------------
455  virtual GeoObjectSorter const& Sorter() const = 0;
456 
457  //--------------------------------------------------------------------------
460 
462  std::vector<std::vector<std::vector<raw::ChannelID_t>>> const& FirstChannelInNextPlane() const
463  {
465  }
466 
468  std::vector<std::vector<std::vector<raw::ChannelID_t>>> const& FirstChannelInThisPlane() const
469  {
471  }
472 
474 
475  //--------------------------------------------------------------------------
476 
477  protected:
479  template <typename T>
480  using TPCInfoMap_t = std::vector<std::vector<T>>;
481 
483  template <typename T>
485 
486  // These 3D vectors are used in initializing the Channel map.
487  // Only a 1D vector is really needed so far, but these are more general.
490 
491  std::map<std::string, size_t>
493  std::map<size_t, std::vector<size_t>>
495 
504 
507  template <typename T>
508  T const& AccessElement(TPCInfoMap_t<T> const& map, TPCID const& id) const
509  {
510  return map[id.Cryostat][id.TPC];
511  }
512 
514  template <typename T>
515  size_t AccessElementSize(TPCInfoMap_t<T> const& map, CryostatID const& id) const
516  {
517  return map[id.Cryostat].size();
518  }
519 
521  template <typename T>
523  bool isValidElement(TPCInfoMap_t<T> const& map, CryostatID const& id) const
524  {
525  return id.Cryostat < map.size();
526  }
527  template <typename T>
528  bool isValidElement(TPCInfoMap_t<T> const& map, TPCID const& id) const
529  {
530  return isValidElement(map, id.asCryostatID()) && (id.TPC < map[id.Cryostat].size());
531  }
533 
535  template <typename T>
536  T const& AccessElement(PlaneInfoMap_t<T> const& map, PlaneID const& id) const
537  {
538  return map[id.Cryostat][id.TPC][id.Plane];
539  }
540 
542  template <typename T>
543  size_t AccessElementSize(PlaneInfoMap_t<T> const& map, TPCID const& id) const
544  {
545  return map[id.Cryostat][id.TPC].size();
546  }
547 
549  template <typename T>
551  bool isValidElement(PlaneInfoMap_t<T> const& map, CryostatID const& id) const
552  {
553  return id.Cryostat < map.size();
554  }
555  template <typename T>
556  bool isValidElement(PlaneInfoMap_t<T> const& map, TPCID const& id) const
557  {
558  return isValidElement(map, id.asCryostatID()) && (id.TPC < map[id.Cryostat].size());
559  }
560  template <typename T>
561  bool isValidElement(PlaneInfoMap_t<T> const& map, PlaneID const& id) const
562  {
563  return isValidElement(map, id.asTPCID()) && (id.Plane < AccessSize(map, id.asTPCID()));
564  }
566 
568  template <typename T>
569  T const* GetElementPtr(PlaneInfoMap_t<T> const& map, PlaneID const& id) const
570  {
571  if (id.Cryostat >= map.size()) return nullptr;
572  auto const& cryo_map = map[id.Cryostat];
573  if (id.TPC >= cryo_map.size()) return nullptr;
574  auto const& TPC_map = cryo_map[id.TPC];
575  if (id.Plane >= TPC_map.size()) return nullptr;
576  auto const& plane_map = TPC_map[id.Plane];
577  return &plane_map;
578  } // GetElementPtr()
579 
581  };
582 }
583 #endif // GEO_CHANNELMAPALG_H
Interface for a class providing readout channel mapping to geometry.
Definition: ChannelMapAlg.h:48
size_t AccessElementSize(TPCInfoMap_t< T > const &map, CryostatID const &id) const
Returns the number of elements in the specified cryostat of the TPC map.
virtual SigType_t SignalTypeForChannelImpl(raw::ChannelID_t const channel) const =0
Return the signal type of the specified channel.
virtual std::vector< TPCID > TPCsetToTPCs(readout::TPCsetID const &tpcsetid) const =0
Returns a list of ID of TPCs belonging to the specified TPC set.
virtual double WireCoordinate(double YPos, double ZPos, PlaneID const &planeID) const =0
Returns the index of the wire nearest to the specified position.
virtual std::vector< TPCID > ROPtoTPCs(readout::ROPID const &ropid) const =0
Returns a list of ID of TPCs the specified ROP spans.
Classes identifying readout-related concepts.
virtual unsigned int Nchannels() const =0
Returns the total number of channels present (not necessarily contiguous)
virtual std::set< PlaneID > const & PlaneIDs() const =0
Returns a list of the plane IDs in the whole detector.
virtual readout::TPCsetID TPCtoTPCset(TPCID const &tpcid) const =0
Returns the ID of the TPC set tpcid belongs to.
T const & AccessElement(TPCInfoMap_t< T > const &map, TPCID const &id) const
Returns the specified element of the TPC map.
SigType_t SignalTypeForROPID(readout::ROPID const &ropid) const
Return the signal type on the specified readout plane.
virtual bool HasROP(readout::ROPID const &ropid) const =0
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:463
Class identifying a set of TPC sharing readout channels.
Definition: readout_types.h:72
std::vector< std::vector< std::vector< raw::ChannelID_t > > > const & FirstChannelInThisPlane() const
Retrieve the private fFirstChannelInThisPlane vector for testing.
bool isValidElement(TPCInfoMap_t< T > const &map, CryostatID const &id) const
Returns whether the ID specifies a valid entry.
PlaneInfoMap_t< raw::ChannelID_t > fFirstChannelInThisPlane
bool isValidElement(PlaneInfoMap_t< T > const &map, PlaneID const &id) const
Returns whether the ID specifies a valid entry.
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 void Uninitialize()=0
Deconfiguration: prepare for a following call of Initialize()
std::vector< std::vector< T >> TPCInfoMap_t
Data type for per-TPC information.
TPCInfoMap_t< std::vector< T >> PlaneInfoMap_t
Data type for per-plane information.
size_t AccessElementSize(PlaneInfoMap_t< T > const &map, TPCID const &id) const
Returns the number of elements in the specified TPC of the plane map.
virtual unsigned int NROPs(readout::TPCsetID const &tpcsetid) const =0
Returns the total number of ROP in the specified TPC set.
Interface to algorithm class for sorting geo::XXXGeo objects.
virtual unsigned int MaxROPs() const =0
Returns the largest number of ROPs a TPC set in the detector has.
virtual std::vector< PlaneID > ROPtoWirePlanes(readout::ROPID const &ropid) const =0
Returns a list of ID of planes belonging to the specified ROP.
T const & AccessElement(PlaneInfoMap_t< T > const &map, PlaneID const &id) const
Returns the specified element of the plane map.
virtual GeoObjectSorter const & Sorter() const =0
Returns the object to sort geometry with.
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
virtual bool HasTPCset(readout::TPCsetID const &tpcsetid) const =0
bool isValidElement(PlaneInfoMap_t< T > const &map, CryostatID const &id) const
Returns whether the ID specifies a valid entry.
bool isValidElement(PlaneInfoMap_t< T > const &map, TPCID const &id) const
Returns whether the ID specifies a valid entry.
constexpr bool isValidChannelID(raw::ChannelID_t channel)
Definition: RawTypes.h:35
std::vector< std::vector< std::vector< raw::ChannelID_t > > > const & FirstChannelInNextPlane() const
Retrieve the private fFirstChannelInNextPlane vector for testing.
virtual unsigned int NTPCsets(readout::CryostatID const &cryoid) const =0
Returns the total number of TPC sets in the specified cryostat.
The data type to uniquely identify a TPC.
Definition: geo_types.h:381
Definition of data types for geometry description.
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 PlaneID FirstWirePlaneInROP(readout::ROPID const &ropid) const =0
Returns the ID of the first plane belonging to the specified ROP.
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.
std::map< size_t, std::vector< size_t > > fADChannelToSensitiveGeo
virtual readout::ROPID ChannelToROP(raw::ChannelID_t channel) const =0
Returns the ID of the ROP the channel belongs to.
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 MaxTPCsets() const =0
Returns the largest number of TPC sets any cryostat in the detector has.
virtual readout::ROPID WirePlaneToROP(PlaneID const &planeid) const =0
Returns the ID of the ROP planeid belongs to.
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 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:77
virtual unsigned int OpChannel(unsigned int detNum, unsigned int hwchannel=0) const
Returns the channel ID of the specified hardware channel.
virtual raw::ChannelID_t PlaneWireToChannel(WireID const &wireID) const =0
Returns the channel ID a wire is connected to.
virtual unsigned int NOpHardwareChannels(unsigned int opDet) const
Returns the number of channels in the specified optical detectors.
virtual std::vector< WireID > ChannelToWire(raw::ChannelID_t channel) const =0
virtual ~ChannelMapAlg()=default
virtual bool IsValidOpChannel(unsigned int opChannel, unsigned int NOpDets) const
Returns whether the ID identifies a valid optical detector channel.
Data in the geometry description.
Definition: GeometryData.h:30
PlaneInfoMap_t< raw::ChannelID_t > fFirstChannelInNextPlane
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
recob::tracking::Plane Plane
Definition: TrackState.h:17
Namespace collecting geometry-related classes utilities.
virtual TPCID FirstTPCinTPCset(readout::TPCsetID const &tpcsetid) const =0
Returns the ID of the first TPC belonging to the specified TPC set.
T const * GetElementPtr(PlaneInfoMap_t< T > const &map, PlaneID const &id) const
Returns a pointer to the specified element, or nullptr if invalid.
virtual WireID NearestWireID(Point_t const &worldPos, PlaneID const &planeID) const =0
Returns the ID of the wire nearest to the specified position.
bool isValidElement(TPCInfoMap_t< T > const &map, TPCID const &id) const
Returns the specified element of the TPC map.
virtual void Initialize(GeometryData_t const &geodata)=0
Geometry initialisation.
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.
The data type to uniquely identify a cryostat.
Definition: geo_types.h:192