DuneApaChannelMapAlg.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file DuneApaChannelMapAlg.h
3 /// \brief Interface to algorithm class for a specific detector channel mapping
4 ///
5 /// \version $Id: $
6 /// \author David Adams
7 ///
8 /// David Adams
9 /// November 2016
10 ///
11 /// Derived from ChannelMapAPAAlg by Tyler Alion.
12 ///
13 /// Maps wires to channels for a DUNE-like APA structure. Each each APA has two
14 /// wrapped induction (u and v) ROPs (readout planes) shared by two TPCs and
15 /// separate collection (z) planes for each of the TPCs. I.e. the APA has four ROPs.
16 ///
17 /// The number of channels for the induction view is determined by the number of
18 /// wires which reach the starting side of each of the TPCs. These are called
19 /// anchored wires. For collection planes, the numbers or wires and anchored
20 /// wires are the same.
21 ///
22 /// Geometry is indexed by cryostat, TPC, plane and wire: (cry, tpc, pla, wir).
23 /// Readout is indexed by cryostat, APA, ROP and ROP plane: (cry, apa, rop, rpl).
24 /// All these indices are relative.
25 /// Channel numbers (cha) are absolute with ordering following that of the readout.
26 ///
27 /// Optical detector flag determines how optical channel mapping is done:
28 // OpDetFlag = 0 - Simple mapping with ChannelsPerOpDet fore each optical detector
29 // OpDetFlag = 1 - Dune 35t mapping
30 ////////////////////////////////////////////////////////////////////////
31 #ifndef geo_DuneApaChannelMapAlg_H
32 #define geo_DuneApaChannelMapAlg_H
33 
34 #include <vector>
35 #include <set>
36 #include "cetlib_except/exception.h"
37 #include "larcoreobj/SimpleTypesAndConstants/readout_types.h" // readout::ROPID, ...
38 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
41 #include "fhiclcpp/ParameterSet.h"
42 
43 namespace geo{
44 
46 
47 public:
48 
50 
51  void setSorter(const geo::GeoObjectSorter& sort);
52  void Initialize(GeometryData_t const& geodata) override;
53  void Uninitialize() override;
54 
55  /// Returns a list of TPC wires connected to the specified readout channel ID
56  /// @throws cet::exception (category: "Geometry") if non-existent channel
57  std::vector<WireID> ChannelToWire(raw::ChannelID_t channel) const override;
58 
59  unsigned int Nchannels() const override;
60 
61  /// @brief Returns the number of channels in the specified ROP
62  /// @return number of channels in the specified ROP, 0 if non-existent
63  /// @todo to be completed
64  unsigned int Nchannels(readout::ROPID const& ropid) const override;
65 
66  double WireCoordinate(double YPos,
67  double ZPos,
68  unsigned int PlaneNo,
69  unsigned int TPCNo,
70  unsigned int cstat) const override;
71 
72  double WireCoordinate(double YPos,
73  double ZPos,
74  geo::PlaneID const& planeID) const override;
75 
76  //@{
77  virtual WireID NearestWireID(const TVector3& worldPos,
78  unsigned int PlaneNo,
79  unsigned int TPCNo,
80  unsigned int cstat) const override
81  { return NearestWireID(worldPos, geo::PlaneID(cstat, TPCNo, PlaneNo)); }
82  virtual WireID
83  NearestWireID(const TVector3& worldPos, geo::PlaneID const& planeID) const override;
84  //@}
85  //@{
86  virtual raw::ChannelID_t PlaneWireToChannel(unsigned int plane,
87  unsigned int wire,
88  unsigned int tpc,
89  unsigned int cstat) const override
90  { return PlaneWireToChannel(geo::WireID(cstat, tpc, plane, wire)); }
91  virtual raw::ChannelID_t PlaneWireToChannel(geo::WireID const& wireID) const override;
92  //@}
93  SigType_t SignalTypeForChannelImpl( raw::ChannelID_t const channel) const override;
94  std::set<PlaneID> const& PlaneIDs() const override;
95 
96  //
97  // TPC set interface
98  //
99  /// @name TPC set mapping
100  /// @{
101  /**
102  * @brief Returns the total number of TPC sets in the specified cryostat
103  * @param cryoid cryostat ID
104  * @return number of TPC sets in the cryostat, or 0 if no cryostat found
105  */
106  virtual unsigned int NTPCsets(readout::CryostatID const& cryoid) const override;
107 
108  /// Returns the largest number of TPC sets any cryostat in the detector has
109  /// @todo to be completed
110  virtual unsigned int MaxTPCsets() const override;
111 
112  /// Returns whether we have the specified TPC set
113  /// @return whether the TPC set is valid and exists
114  /// @todo to be completed
115  virtual bool HasTPCset(readout::TPCsetID const& tpcsetid) const override;
116 
117  /**
118  * @brief Returns the ID of the TPC set the specified TPC belongs to
119  * @param tpcid ID of the TPC
120  * @return the ID of the corresponding TPC set
121  */
122  virtual readout::TPCsetID TPCtoTPCset(geo::TPCID const& tpcid) const override;
123 
124  /**
125  * @brief Returns a list of ID of TPCs belonging to the specified TPC set
126  * @param tpcsetid ID of the TPC set to convert into TPC IDs
127  * @return the list of TPCs, empty if TPC set is invalid
128  */
129  virtual std::vector<geo::TPCID> TPCsetToTPCs(readout::TPCsetID const& tpcsetid) const override;
130 
131  /// Returns the ID of the first TPC belonging to the specified TPC set
132  /// @todo to be completed
133  virtual geo::TPCID FirstTPCinTPCset(readout::TPCsetID const& tpcsetid) const override;
134 
135  /// @} TPC set mapping
136 
137  //
138  // Readout plane interface
139  //
140  /// @name Readout plane mapping
141  /// @{
142 
143  /**
144  * @brief Returns the total number of ROP in the specified TPC set
145  * @param tpcsetid TPC set ID
146  * @return number of readout planes in the TPC set, or 0 if no TPC set found
147  *
148  * Note that this methods explicitly check the existence of the TPC set.
149  */
150  virtual unsigned int NROPs(readout::TPCsetID const& tpcsetid) const override;
151 
152  /// Returns the largest number of ROPs a TPC set in the detector has
153  /// @todo to be completed
154  virtual unsigned int MaxROPs() const override;
155 
156  /// Returns whether we have the specified ROP
157  /// @return whether the readout plane is valid and exists
158  virtual bool HasROP(readout::ROPID const& ropid) const override;
159 
160  /**
161  * @brief Returns the ID of the ROP planeid belongs to, or invalid if none
162  * @param planeid ID of the wire plane
163  * @return the ID of the corresponding ROP, or invalid ID when planeid is
164  *
165  * Note that this check is performed on the validity of the wire plane
166  * ID, that does not necessarily imply that the wire plane specified by
167  * the ID actually exists. Check if the wire plane exists with HasPlane().
168  * The behaviour on non-existing wire planes is undefined.
169  */
170  virtual readout::ROPID WirePlaneToROP(geo::PlaneID const& planeid) const override;
171 
172  /**
173  * @brief Returns a list of ID of wire planes belonging to the specified ROP
174  * @param ropid ID of the readout plane to convert into wire planes
175  * @return the list of wire plane IDs, empty if readout plane ID is invalid
176  *
177  * Note that this check is performed on the validity of the readout plane
178  * ID, that does not necessarily imply that the readout plane specified by
179  * the ID actually exists. Check if the ROP exists with HasROP().
180  * The behaviour on non-existing readout planes is undefined.
181  */
182  virtual std::vector<geo::PlaneID> ROPtoWirePlanes(readout::ROPID const& ropid) const override;
183 
184  /**
185  * @brief Returns a list of ID of TPCs the specified ROP spans
186  * @param ropid ID of the readout plane
187  * @return the list of TPC IDs, empty if readout plane ID is invalid
188  *
189  * Note that this check is performed on the validity of the readout plane
190  * ID, that does not necessarily imply that the readout plane specified by
191  * the ID actually exists. Check if the ROP exists with HasROP().
192  * The behaviour on non-existing readout planes is undefined.
193  */
194  virtual std::vector<geo::TPCID> ROPtoTPCs(readout::ROPID const& ropid) const override;
195 
196  /// Returns the ID of the ROP the channel belongs to (invalid if none)
197  /// @throws cet::exception (category: "Geometry") if non-existent channel
198  virtual readout::ROPID ChannelToROP(raw::ChannelID_t channel) const override;
199 
200  /**
201  * @brief Returns the ID of the first channel in the specified readout plane
202  * @param ropid ID of the readout plane
203  * @return ID of first channel, or raw::InvalidChannelID if ID is invalid
204  *
205  * Note that this check is performed on the validity of the readout plane
206  * ID, that does not necessarily imply that the readout plane specified by
207  * the ID actually exists. Check if the ROP exists with HasROP().
208  * The behaviour for non-existing readout planes is undefined.
209  */
210  virtual raw::ChannelID_t FirstChannelInROP(readout::ROPID const& ropid) const override;
211 
212  /**
213  * @brief Returns the ID of the first plane belonging to the specified ROP
214  * @param ropid ID of the readout plane
215  * @return ID of first channel, or raw::InvalidChannelID if ID is invalid
216  *
217  * Note that this check is performed on the validity of the readout plane
218  * ID, that does not necessarily imply that the readout plane specified by
219  * the ID actually exists. Check if the ROP exists with HasROP().
220  * The behaviour for non-existing readout planes is undefined.
221  */
222  virtual geo::PlaneID FirstWirePlaneInROP(readout::ROPID const& ropid) const override;
223 
224  /// @} readout plane mapping
225 
226  /// Returns the object to sort geometry with
227  virtual geo::GeoObjectSorter const& Sorter() const override;
228 
229  unsigned int NOpChannels(unsigned int NOpDets) const override;
230  unsigned int NOpHardwareChannels(unsigned int opDet) const override;
231  unsigned int OpChannel(unsigned int detNum, unsigned int channel = 0) const override;
232  unsigned int OpDetFromOpChannel(unsigned int opChannel) const override;
233  unsigned int HardwareChannelFromOpChannel(unsigned int opChannel) const override;
234 
235 protected:
236 
237  template<class T>
238  using Vector = std::vector<T>;
239  template<class T>
241  template<class T>
243  template<class T>
245  unsigned int fOpDetFlag; /// Flag for OpDet channel map.
246  unsigned int fChannelsPerOpDet;
247  unsigned int fNcryostat; ///< number of cryostats in the detector
248  unsigned int fNchannels; ///< number of channels in the detector
249  unsigned int fChannelsPerAPA; ///< number of channels in each APA
250  raw::ChannelID_t fTopChannel; ///< book keeping highest channel #
251  unsigned int fNTpcMax; ///< Max # TPCs in any cryostat
252  unsigned int fNApaMax; ///< Max # TPCs in any cryostat
253  unsigned int fNRopMax; ///< Max # ROPs in any APA
254  std::vector<unsigned int> fNTpc; ///< number of TPCs in each cryostat
255  std::vector<unsigned int> fNApa; ///< number of APAs in each cryostat
256  std::set<View_t> fViews; ///< vector of the views present in the detector
257  std::set<PlaneID> fPlaneIDs; ///< vector of the PlaneIDs present in the detector
258  ThreeVector<unsigned int> fWiresPerPlane; ///< # wires/TPC plane for each (cry, tpc, pla)
259  TwoVector<unsigned int> fPlanesPerTpc; ///< # planes for each (cry, tpc)
260  TwoVector<unsigned int> fRopsPerApa; ///< # ROPs for each (cry, apa)
261  ThreeVector<unsigned int> fApaTpcs; ///< TPCs for each APA
262  ThreeVector<unsigned int> fPlanesPerRop; ///< # TPC planes for each (cry, apa, rop)
263  FourVector<unsigned int> fRopTpc; ///< # TPC planes for each (cry, apa, rop, rpl)
264  FourVector<unsigned int> fRopPlane; ///< # TPC plane index for each (cry, apa, rop, rpl)
265  TwoVector<unsigned int> fChannelsPerApa; ///< # channels for each APA
266  ThreeVector<unsigned int> fChannelsPerRop; ///< # channels for each Rop
267  ThreeVector<unsigned int> fAnchoredWires; ///< # anchored wires for each (cry, tpc, pla)
268  ThreeVector<unsigned int> fPlaneApa; ///< APA for each TPC plane (cry, tpc, pla)
269  ThreeVector<unsigned int> fPlaneRop; ///< ROP for each TPC plane (cry, tpc, pla)
270  ThreeVector<unsigned int> fPlaneRopIndex; ///< Index in ROP for each TPC plane (cry, tpc, pla)
271  ThreeVector<unsigned int> fAnchoredPlaneRop; ///< ROP holding the anchored wires for (cry, tpc, pla)
272  ThreeVector<unsigned int> fWiresPerRop; ///< # wires/ROP for each (cry, apa, rop)
275  const geo::GeoObjectSorter* fSorter; ///< sorts geo::XXXGeo objects
276 
277  /// all data we need for each APA
278  typedef struct {
281  /// +1 if the wire ID order follow z (larger z, or smaller intercept => larger wire ID); -1 otherwise
283  double fYmax;
284  double fYmin;
285  double fZmax;
286  double fZmin;
287  } PlaneData_t;
288 
289  ///< collects all data we need for each plane (indices: c t p)
291 
292  std::vector< double > fWirePitch;
293  std::vector< double > fOrientation;
294  std::vector< double > fSinOrientation; // to explore improving speed
295  std::vector< double > fCosOrientation; // to explore improving speed
296 
297  /// Returns whether the specified ID represents a valid cryostat.
298  bool HasCryostat(CryostatID const& cid) const
299  { return cid.Cryostat < fNcryostat; }
300 
301  }; // class DuneApaChannelMapAlg
302 
303  //----------------------------------------------------------------------------
304 
305 
306 }
307 #endif
308 
unsigned int Nchannels() const override
Returns the total number of channels present (not necessarily contiguous)
unsigned int fNApaMax
Max # TPCs in any cryostat.
unsigned int fNRopMax
Max # ROPs in any APA.
Interface for a class providing readout channel mapping to geometry.
Definition: ChannelMapAlg.h:48
bool HasCryostat(CryostatID const &cid) const
Returns whether the specified ID represents a valid cryostat.
virtual readout::ROPID WirePlaneToROP(geo::PlaneID const &planeid) const override
Returns the ID of the ROP planeid belongs to, or invalid if none.
std::set< PlaneID > fPlaneIDs
vector of the PlaneIDs present in the detector
unsigned int OpDetFromOpChannel(unsigned int opChannel) const override
Returns the optical detector the specified optical channel belongs.
Vector< ThreeVector< T >> FourVector
virtual geo::PlaneID FirstWirePlaneInROP(readout::ROPID const &ropid) const override
Returns the ID of the first plane belonging to the specified ROP.
Classes identifying readout-related concepts.
float fWireSortingInZ
+1 if the wire ID order follow z (larger z, or smaller intercept => larger wire ID); -1 otherwise ...
std::vector< double > fOrientation
SigType_t SignalTypeForChannelImpl(raw::ChannelID_t const channel) const override
Return the signal type of the specified channel.
ThreeVector< unsigned int > fApaTpcs
TPCs for each APA.
ThreeVector< unsigned int > fChannelsPerRop
channels for each Rop
std::vector< double > fCosOrientation
PlaneInfoMap_t< raw::ChannelID_t > fFirstChannelInThisRop
(cry, apa, rop)
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
double WireCoordinate(double YPos, double ZPos, unsigned int PlaneNo, unsigned int TPCNo, unsigned int cstat) const override
Returns the index of the wire nearest to the specified position.
Class identifying a set of TPC sharing readout channels.
Definition: readout_types.h:70
virtual WireID NearestWireID(const TVector3 &worldPos, unsigned int PlaneNo, unsigned int TPCNo, unsigned int cstat) const override
Returns the ID of the wire nearest to the specified position.
const geo::GeoObjectSorter * fSorter
sorts geo::XXXGeo objects
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
virtual unsigned int MaxROPs() const override
uint8_t channel
Definition: CRTFragment.hh:201
ThreeVector< unsigned int > fPlaneRop
ROP for each TPC plane (cry, tpc, pla)
DuneApaChannelMapAlg(const fhicl::ParameterSet &pset)
ThreeVector< unsigned int > fAnchoredWires
anchored wires for each (cry, tpc, pla)
virtual geo::GeoObjectSorter const & Sorter() const override
Returns the object to sort geometry with.
unsigned int NOpChannels(unsigned int NOpDets) const override
Returns the number of optical channels contained in some detectors.
virtual unsigned int MaxTPCsets() const override
std::vector< double > fWirePitch
void setSorter(const geo::GeoObjectSorter &sort)
PlaneInfoMap_t< PlaneData_t > fPlaneData
TwoVector< unsigned int > fPlanesPerTpc
planes for each (cry, tpc)
TPCInfoMap_t< std::vector< T >> PlaneInfoMap_t
Data type for per-plane information.
Interface to algorithm class for sorting geo::XXXGeo objects.
ThreeVector< unsigned int > fPlaneApa
APA for each TPC plane (cry, tpc, pla)
TwoVector< unsigned int > fChannelsPerApa
channels for each APA
virtual unsigned int NROPs(readout::TPCsetID const &tpcsetid) const override
Returns the total number of ROP in the specified TPC set.
virtual raw::ChannelID_t FirstChannelInROP(readout::ROPID const &ropid) const override
Returns the ID of the first channel in the specified readout plane.
unsigned int fChannelsPerOpDet
Flag for OpDet channel map.
void Initialize(GeometryData_t const &geodata) override
Geometry initialisation.
enum geo::_plane_sigtype SigType_t
FourVector< unsigned int > fRopPlane
TPC plane index for each (cry, apa, rop, rpl)
unsigned int OpChannel(unsigned int detNum, unsigned int channel=0) const override
Returns the channel ID of the specified hardware channel.
std::vector< WireID > ChannelToWire(raw::ChannelID_t channel) const override
Vector< TwoVector< T >> ThreeVector
std::vector< unsigned int > fNApa
number of APAs in each cryostat
virtual readout::ROPID ChannelToROP(raw::ChannelID_t channel) const override
ThreeVector< unsigned int > fPlanesPerRop
TPC planes for each (cry, apa, rop)
unsigned int fNcryostat
number of cryostats in the detector
std::vector< double > fSinOrientation
ThreeVector< unsigned int > fWiresPerRop
wires/ROP for each (cry, apa, rop)
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
Class identifying a set of planes sharing readout channels.
virtual std::vector< geo::PlaneID > ROPtoWirePlanes(readout::ROPID const &ropid) const override
Returns a list of ID of wire planes belonging to the specified ROP.
FourVector< unsigned int > fRopTpc
TPC planes for each (cry, apa, rop, rpl)
void Uninitialize() override
Deconfiguration: prepare for a following call of Initialize()
virtual readout::TPCsetID TPCtoTPCset(geo::TPCID const &tpcid) const override
Returns the ID of the TPC set the specified TPC belongs to.
virtual bool HasTPCset(readout::TPCsetID const &tpcsetid) const override
virtual std::vector< geo::TPCID > TPCsetToTPCs(readout::TPCsetID const &tpcsetid) const override
Returns a list of ID of TPCs belonging to the specified TPC set.
virtual raw::ChannelID_t PlaneWireToChannel(unsigned int plane, unsigned int wire, unsigned int tpc, unsigned int cstat) const override
Returns the channel ID a wire is connected to.
unsigned int fChannelsPerAPA
number of channels in each APA
ThreeVector< unsigned int > fPlaneRopIndex
Index in ROP for each TPC plane (cry, tpc, pla)
unsigned int fNchannels
number of channels in the detector
unsigned int HardwareChannelFromOpChannel(unsigned int opChannel) const override
Returns the hardware channel number of specified optical channel.
virtual unsigned int NTPCsets(readout::CryostatID const &cryoid) const override
Returns the total number of TPC sets in the specified cryostat.
unsigned int NOpHardwareChannels(unsigned int opDet) const override
Returns the number of channels in the specified optical detectors.
TwoVector< unsigned int > fRopsPerApa
ROPs for each (cry, apa)
std::set< PlaneID > const & PlaneIDs() const override
Returns a list of the plane IDs in the whole detector.
unsigned int fNTpcMax
Max # TPCs in any cryostat.
raw::ChannelID_t fTopChannel
book keeping highest channel #
std::set< View_t > fViews
vector of the views present in the detector
ThreeVector< unsigned int > fWiresPerPlane
wires/TPC plane for each (cry, tpc, pla)
Data in the geometry description.
Definition: GeometryData.h:31
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.
std::vector< unsigned int > fNTpc
number of TPCs in each cryostat
virtual bool HasROP(readout::ROPID const &ropid) const override
LArSoft geometry interface.
Definition: ChannelGeo.h:16
Vector< Vector< T >> TwoVector
virtual geo::TPCID FirstTPCinTPCset(readout::TPCsetID const &tpcsetid) const override
virtual std::vector< geo::TPCID > ROPtoTPCs(readout::ROPID const &ropid) const override
Returns a list of ID of TPCs the specified ROP spans.
The data type to uniquely identify a cryostat.
Definition: geo_types.h:190
ThreeVector< unsigned int > fAnchoredPlaneRop
ROP holding the anchored wires for (cry, tpc, pla)
PlaneInfoMap_t< raw::ChannelID_t > fFirstChannelInNextRop
(cry, apa, rop)