LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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
13 #include "larcorealg/Geometry/Exceptions.h" // geo::InvalidWireIDError
17 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
18 
19 // Framework libraries
20 #include "cetlib_except/exception.h"
21 
22 // ROOT libraries
23 #include "TVector3.h"
24 
25 // C/C++ standard libraries
26 #include <vector>
27 #include <map>
28 #include <set>
29 #include <memory> // std::unique_ptr<>
30 
31 
32 namespace geo{
33 
34  // forward-declaration from geometry
35  struct GeometryData_t;
36  class AuxDetGeo;
37 
38 
56 
57  public:
58 
60  virtual ~ChannelMapAlg() = default;
61 
62 
63  //--------------------------------------------------------------------------
66 
68  virtual void Initialize(GeometryData_t const& geodata) = 0;
69 
71  virtual void Uninitialize() = 0;
72 
73 
75 
76 
77  //--------------------------------------------------------------------------
80 
82  virtual unsigned int Nchannels() const = 0;
83 
86  virtual unsigned int Nchannels(readout::ROPID const& ropid) const = 0;
87 
90  virtual bool HasChannel(raw::ChannelID_t channel) const
91  { return raw::isValidChannelID(channel)? channel < Nchannels(): false; }
92 
95  virtual std::vector<WireID> ChannelToWire
96  (raw::ChannelID_t channel) const = 0;
97 
107 
108  protected:
109 
118  virtual geo::SigType_t SignalTypeForChannelImpl(raw::ChannelID_t const channel) const = 0;
119 
120  public:
121 
135 
136  protected:
137 
150  virtual geo::SigType_t SignalTypeForROPIDImpl(readout::ROPID const& ropid) const;
151 
152  public:
153 
155  virtual std::set<geo::PlaneID> const& PlaneIDs() const = 0;
156 
167  virtual raw::ChannelID_t PlaneWireToChannel(geo::WireID const& wireID) const
168  {
169  return PlaneWireToChannel
170  (wireID.Plane, wireID.Wire, wireID.TPC, wireID.Cryostat);
171  }
172 
184  virtual raw::ChannelID_t PlaneWireToChannel(unsigned int plane,
185  unsigned int wire,
186  unsigned int tpc,
187  unsigned int cstat) const = 0;
188 
190 
191 
192  //--------------------------------------------------------------------------
195 
213  virtual unsigned int NOpChannels(unsigned int NOpDets) const;
214 
229  virtual unsigned int MaxOpChannel(unsigned int NOpDets) const;
230 
250  virtual unsigned int NOpHardwareChannels(unsigned int opDet) const;
251 
261  virtual bool IsValidOpChannel
262  (unsigned int opChannel, unsigned int NOpDets) const;
263 
273  virtual unsigned int OpChannel
274  (unsigned int detNum, unsigned int hwchannel = 0) const;
275 
283  virtual unsigned int OpDetFromOpChannel(unsigned int opChannel) const;
284 
292  virtual unsigned int HardwareChannelFromOpChannel
293  (unsigned int opChannel) const;
294 
296 
297 
298  //--------------------------------------------------------------------------
301 
317  virtual double WireCoordinate(double YPos,
318  double ZPos,
319  geo::PlaneID const& planeID) const
320  {
321  return WireCoordinate
322  (YPos, ZPos, planeID.Plane, planeID.TPC, planeID.Cryostat);
323  }
324 
337  virtual double WireCoordinate(double YPos,
338  double ZPos,
339  unsigned int PlaneNo,
340  unsigned int TPCNo,
341  unsigned int cstat) const = 0;
342 
343 
360  virtual geo::WireID NearestWireID
361  (const TVector3& worldPos, geo::PlaneID const& planeID) const
362  {
363  return
364  NearestWireID(worldPos, planeID.Plane, planeID.TPC, planeID.Cryostat);
365  }
366 
378  virtual geo::WireID NearestWireID(const TVector3& worldPos,
379  unsigned int PlaneNo,
380  unsigned int TPCNo,
381  unsigned int cstat) const = 0;
382 
393  unsigned int NearestWire(const TVector3& worldPos,
394  geo::PlaneID const& planeID) const;
395 
408  unsigned int NearestWire(const TVector3& worldPos,
409  unsigned int PlaneNo,
410  unsigned int TPCNo,
411  unsigned int cstat) const
412  { return NearestWire(worldPos, geo::PlaneID(cstat, TPCNo, PlaneNo)); }
413 
415 
416 
417  //--------------------------------------------------------------------------
420 
427  virtual size_t NearestAuxDet
428  (const double* point, std::vector<geo::AuxDetGeo*> const& auxDets) const;
429 
436  virtual size_t NearestSensitiveAuxDet
437  (const double* point, std::vector<geo::AuxDetGeo*> const& auxDets) const;
438 
450  virtual size_t ChannelToAuxDet(std::vector<geo::AuxDetGeo*> const& auxDets,
451  std::string const& detName,
452  uint32_t const& channel
453  ) const;
454 
462  virtual std::pair<size_t, size_t> ChannelToSensitiveAuxDet(
463  std::vector<geo::AuxDetGeo*> const& auxDets,
464  std::string const& detName,
465  uint32_t const& channel
466  ) const;
467 
469 
470 
471  //--------------------------------------------------------------------------
474 
479  virtual unsigned int NTPCsets(readout::CryostatID const& cryoid) const = 0;
480 
482  virtual unsigned int MaxTPCsets() const = 0;
483 
486  virtual bool HasTPCset(readout::TPCsetID const& tpcsetid) const = 0;
487 
489  virtual readout::TPCsetID TPCtoTPCset(geo::TPCID const& tpcid) const = 0;
490 
501  virtual std::vector<geo::TPCID> TPCsetToTPCs
502  (readout::TPCsetID const& tpcsetid) const = 0;
503 
506  (readout::TPCsetID const& tpcsetid) const = 0;
507 
509 
510 
511  //--------------------------------------------------------------------------
514 
521  virtual unsigned int NROPs(readout::TPCsetID const& tpcsetid) const = 0;
522 
524  virtual unsigned int MaxROPs() const = 0;
525 
528  virtual bool HasROP(readout::ROPID const& ropid) const = 0;
529 
532  (geo::PlaneID const& planeid) const = 0;
533 
535  virtual std::vector<geo::PlaneID> ROPtoWirePlanes
536  (readout::ROPID const& ropid) const = 0;
537 
540  (readout::ROPID const& ropid) const = 0;
541 
552  virtual std::vector<geo::TPCID> ROPtoTPCs
553  (readout::ROPID const& ropid) const = 0;
554 
564  virtual readout::ROPID ChannelToROP(raw::ChannelID_t channel) const = 0;
565 
577  (readout::ROPID const& ropid) const = 0;
578 
580 
581 
582  //--------------------------------------------------------------------------
584  virtual geo::GeoObjectSorter const& Sorter() const = 0;
585 
586  //--------------------------------------------------------------------------
589 
591  const std::vector<std::vector<std::vector<raw::ChannelID_t>>> FirstChannelInNextPlane() const
592  { return fFirstChannelInThisPlane; }
593 
595  const std::vector<std::vector<std::vector<raw::ChannelID_t>>> FirstChannelInThisPlane() const
596  { return fFirstChannelInNextPlane; }
597 
599 
600  //--------------------------------------------------------------------------
601 
602  protected:
603 
605  template <typename T>
606  using TPCInfoMap_t = std::vector<std::vector<T>>;
607 
609  template <typename T>
611 
612  // These 3D vectors are used in initializing the Channel map.
613  // Only a 1D vector is really needed so far, but these are more general.
616 
617  std::map<std::string, size_t> fADNameToGeo;
618  std::map<size_t, std::vector<size_t> > fADChannelToSensitiveGeo;
619 
628 
631  template <typename T>
632  T const& AccessElement
633  (TPCInfoMap_t<T> const& map, geo::TPCID const& id) const
634  { return map[id.Cryostat][id.TPC]; }
635 
637  template <typename T>
638  size_t AccessElementSize
639  (TPCInfoMap_t<T> const& map, geo::CryostatID const& id) const
640  { return map[id.Cryostat].size(); }
641 
643  template <typename T>
645  bool isValidElement
646  (TPCInfoMap_t<T> const& map, geo::CryostatID const& id) const
647  { return id.Cryostat < map.size(); }
648  template <typename T>
649  bool isValidElement(TPCInfoMap_t<T> const& map, geo::TPCID const& id) const
650  {
651  return isValidElement(map, id.asCryostatID())
652  && (id.TPC < map[id.Cryostat].size());
653  }
655 
656 
658  template <typename T>
659  T const& AccessElement
660  (PlaneInfoMap_t<T> const& map, geo::PlaneID const& id) const
661  { return map[id.Cryostat][id.TPC][id.Plane]; }
662 
664  template <typename T>
665  size_t AccessElementSize
666  (PlaneInfoMap_t<T> const& map, geo::TPCID const& id) const
667  { return map[id.Cryostat][id.TPC].size(); }
668 
670  template <typename T>
672  bool isValidElement
673  (PlaneInfoMap_t<T> const& map, geo::CryostatID const& id) const
674  { return id.Cryostat < map.size(); }
675  template <typename T>
676  bool isValidElement(PlaneInfoMap_t<T> const& map, geo::TPCID const& id) const
677  {
678  return isValidElement(map, id.asCryostatID())
679  && (id.TPC < map[id.Cryostat].size());
680  }
681  template <typename T>
682  bool isValidElement
683  (PlaneInfoMap_t<T> const& map, geo::PlaneID const& id) const
684  {
685  return isValidElement(map, id.asTPCID())
686  && (id.Plane < AccessSize(map, id.asTPCID()));
687  }
689 
691  template <typename T>
692  T const* GetElementPtr
693  (PlaneInfoMap_t<T> const& map, geo::PlaneID const& id) const
694  {
695  if (id.Cryostat >= map.size()) return nullptr;
696  auto const& cryo_map = map[id.Cryostat];
697  if (id.TPC >= cryo_map.size()) return nullptr;
698  auto const& TPC_map = cryo_map[id.TPC];
699  if (id.Plane >= TPC_map.size()) return nullptr;
700  auto const& plane_map = TPC_map[id.Plane];
701  return &plane_map;
702  } // GetElementPtr()
703 
705 
706  };
707 }
708 #endif // GEO_CHANNELMAPALG_H
709 
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.
Interface for a class providing readout channel mapping to geometry.
Definition: ChannelMapAlg.h:55
virtual std::set< geo::PlaneID > const & PlaneIDs() const =0
Returns a list of the plane IDs in the whole detector.
virtual double WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeID) const
Returns the index of the wire nearest to the specified position.
bool isValidElement(TPCInfoMap_t< T > const &map, geo::TPCID const &id) const
Returns the specified element of the TPC map.
Classes identifying readout-related concepts.
virtual unsigned int Nchannels() const =0
Returns the total number of channels present (not necessarily contiguous)
bool isValidElement(PlaneInfoMap_t< T > const &map, geo::TPCID const &id) const
Returns whether the ID specifies a valid entry.
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.
virtual bool HasROP(readout::ROPID const &ropid) const =0
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:250
Class identifying a set of TPC sharing readout channels.
Definition: readout_types.h:41
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:130
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:313
virtual size_t NearestAuxDet(const double *point, std::vector< geo::AuxDetGeo * > const &auxDets) const
Returns the auxiliary detector closest to the specified point.
T const & AccessElement(TPCInfoMap_t< T > const &map, geo::TPCID const &id) const
Returns the specified element of the TPC map.
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 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.
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 geo::GeoObjectSorter const & Sorter() const =0
Returns the object to sort geometry with.
Collection of exceptions for Geometry system.
unsigned int NearestWire(const TVector3 &worldPos, geo::PlaneID const &planeID) const
Returns the index of the wire nearest to the specified position.
virtual std::vector< geo::TPCID > ROPtoTPCs(readout::ROPID const &ropid) const =0
Returns a list of ID of TPCs the specified ROP spans.
virtual size_t NearestSensitiveAuxDet(const double *point, std::vector< geo::AuxDetGeo * > const &auxDets) const
Returns sensitive auxiliary detector closest to specified point.
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
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 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:36
virtual unsigned int NTPCsets(readout::CryostatID const &cryoid) const =0
Returns the total number of TPC sets in the specified cryostat.
virtual geo::TPCID FirstTPCinTPCset(readout::TPCsetID const &tpcsetid) const =0
Returns the ID of the first TPC belonging to the specified TPC set.
The data type to uniquely identify a TPC.
Definition: geo_types.h:195
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:258
Definition of data types for geometry description.
Class identifying a set of planes sharing readout channels.
virtual readout::ROPID WirePlaneToROP(geo::PlaneID const &planeid) const =0
Returns the ID of the ROP planeid belongs to.
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.
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.
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 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 unsigned int MaxOpChannel(unsigned int NOpDets) const
Returns the number of optical channels contained in some detectors.
virtual readout::TPCsetID TPCtoTPCset(geo::TPCID const &tpcid) const =0
Returns the ID of the TPC set tpcid belongs to.
virtual geo::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< geo::AuxDetGeo * > const &auxDets, std::string const &detName, uint32_t const &channel) const
Returns the index of the detector containing the specified channel.
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.
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:90
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 geo::WireID NearestWireID(const TVector3 &worldPos, geo::PlaneID const &planeID) const
Returns the ID of the wire nearest to the specified position.
virtual std::vector< WireID > ChannelToWire(raw::ChannelID_t channel) const =0
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.
Data in the geometry description.
PlaneInfoMap_t< raw::ChannelID_t > fFirstChannelInNextPlane
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:27
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:203
recob::tracking::Plane Plane
Definition: TrackState.h:17
Namespace collecting geometry-related classes utilities.
const std::vector< std::vector< std::vector< raw::ChannelID_t > > > FirstChannelInNextPlane() const
Retrieve the private fFirstChannelInNextPlane vector for testing.
virtual void Initialize(GeometryData_t const &geodata)=0
Geometry initialisation.
The data type to uniquely identify a cryostat.
Definition: geo_types.h:120