All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ROPandTPCsetBuildingAlg.h
Go to the documentation of this file.
1 /**
2  * @file icarusalg/Geometry/details/ROPandTPCsetBuildingAlg.h
3  * @brief Algorithm discovering TPC sets and readout planes for ICARUS.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date October 10, 2019
6  * @see `icarusalg/Geometry/details/ROPandTPCsetBuildingAlg.cxx`
7  */
8 
9 #ifndef ICARUSALG_GEOMETRY_DETAILS_ROPANDTPCSETBUILDINGALG_H
10 #define ICARUSALG_GEOMETRY_DETAILS_ROPANDTPCSETBUILDINGALG_H
11 
12 
13 // ICARUS libraries
15 
16 // LArSoft libraries
23 #include "larcoreobj/SimpleTypesAndConstants/readout_types.h" // readout::TPCsetID, ...
25 
26 // C/C++ standard library
27 #include <string>
28 #include <vector>
29 #include <tuple>
30 #include <utility> // std::move()
31 
32 
33 // -----------------------------------------------------------------------------
34 namespace icarus::details {
35 
36  //
37  // forward declarations
38  //
39  class ROPandTPCsetBuildingAlg;
40 
41  //
42  // data type definitions
43  //
44 
45  /// Type of collection of TPCs (pointers to `geo::TPCGeo`).
46  using TPCColl_t = std::vector<geo::TPCGeo const*>;
47 
48  /// Type of collection of planes (pointers to `geo::PlaneGeo`).
49  using PlaneColl_t = std::vector<geo::PlaneGeo const*>;
50 
51 
52 } // namespace icarus::details
53 
54 
55 // -----------------------------------------------------------------------------
56 /**
57  * @brief Extracts TPC sets and readout planes from a list of cryostats.
58  *
59  * This algorithm parses the wire plane and TPC content of the cryostats and
60  * groups planes which share the same drift coordinate.
61  * Afterwards, it arranges them into LArSoft readout planes, defining at the
62  * same time the TPC sets that contain them.
63  *
64  *
65  * Assignment of readout plane IDs
66  * --------------------------------
67  *
68  * Readout planes closer to the cathode have lower ID.
69  *
70  *
71  * Algorithm workflow
72  * ===================
73  *
74  * An example:
75  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
76  * icarus::details::ROPandTPCsetBuildingAlg builder("BuildingAlg");
77  * auto results = builder.run(Cryostats);
78  *
79  * // planes in each ROP
80  * readout::ROPDataContainer<icarus::details::PlaneColl_t> ROPplanes
81  * = std::move(results.ROPplanes());
82  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83  * will run the algorithm on `Cryostats` and extract one of the results, the
84  * map of wire planes in each readout plane.
85  * It will use the default configuration of the algorithm, except for the
86  * message category being customized into `"BuildingAlg"`.
87  *
88  *
89  * Configuration
90  * ==============
91  *
92  * See the
93  * @ref ICARUS_ROPandTPCsetBuildingAlg_Config "constructor documentation".
94  *
95  *
96  *
97  */
99 
100  public:
101 
102  // import definitions
105 
106 
107  /// Full group of results of the algorithm.
108  using ResultsBase_t = std::tuple<
109  std::vector<unsigned int>, // TPCsetCount
115  >;
116  struct Results_t: public ResultsBase_t {
117 
118  Results_t(ResultsBase_t&& data): ResultsBase_t(std::move(data)) {}
119 
120  /// Output: number of TPC sets in each cryostat.
121  std::vector<unsigned int> TPCsetCount() &&
122  { return std::move(std::get<0U>(*this)); }
123 
124  /// Output: TPC's in each TPC set.
126  { return std::move(std::get<1U>(*this)); }
127 
128  /// Output: number of readout planes in each TPC set.
130  { return std::move(std::get<2U>(*this)); }
131 
132  /// Output: planes in each of the readout plane.
134  { return std::move(std::get<3U>(*this)); }
135 
136  /// Output: number of readout planes in each TPC set.
138  { return std::move(std::get<4U>(*this)); }
139 
140  /// Output: planes in each of the readout plane.
142  { return std::move(std::get<5U>(*this)); }
143 
144  }; // struct Results_t
145 
146 
147  /// Construction: use default configuration.
148  ROPandTPCsetBuildingAlg() = default;
149 
150  /**
151  * @brief Construction: specify the algorithm configuration.
152  * @param logCategory message facility category to write messages into
153  * @param usePlaneIDforROPID whether to use `ROPnumberFromPlanes()` algorithm
154  *
155  *
156  * Configuration
157  * ==============
158  *
159  * @anchor ICARUS_ROPandTPCsetBuildingAlg_Config
160  *
161  * * *logCategory* (default: `"ROPandTPCsetBuildingAlg"`): name of the stream
162  * destination used for output messages via message facility
163  *
164  */
165  ROPandTPCsetBuildingAlg(std::string const& logCategory)
166  : fLogCategory(logCategory)
167  {}
168 
169 
170  /**
171  * @brief Runs the algorithm as configured from start to end.
172  * @return the results of the algorithm
173  *
174  * Results are in the form of a `tuple` that can be used to construct
175  * variables with structured binding declarations, or saved to extract
176  * the results one by one (see `Results_t` for the interface).
177  *
178  */
180 
181 
182  private:
183 
184  // --- BEGIN -- Configuration ------------------------------------------------
185 
186  /// Category to write messages into.
187  std::string fLogCategory = "ROPandTPCsetBuildingAlg";
188 
189  // --- END -- Configuration --------------------------------------------------
190 
191 
193 
194  // --- BEGIN -- Output -------------------------------------------------------
195  /// @name Output
196  /// @{
197 
198  /// Output: number of TPC sets in each cryostat.
199  std::vector<unsigned int> fTPCsetCount;
200 
201  /// Output: TPC's in each TPC set.
203 
204  /// Output: number of readout planes in each TPC set.
206 
207  /// Output: planes in each of the readout plane.
209 
210  /// Output: the TPC set each TPC belongs to.
212 
213  /// Output: the ROP each wire plane belongs to.
215 
216  /// @}
217  // --- END -- Output ---------------------------------------------------------
218 
219  /// Highest number of TPC sets in any cryostat.
220  unsigned int fMaxTPCsets = 0U;
221 
222  /// Highest number of ROPs in any TPC set.
223  unsigned int fMaxROPs = 0U;
224 
225 
226  /// Destroys all the result data members.
227  void clear();
228 
229  /**
230  * @brief Extracts composition of all readout planes.
231  * @tparam Pred type of the predicate `pred` with one `geo::PlaneGeo` argument
232  * @param standalonePlane predicate to determine if a plane is stand-alone
233  * @return readout plane composition
234  *
235  * This function returns a list: for each cryostat (first index),
236  * a list of TPC sets (second index: TPC set within the cryostat)
237  * each listing its TPC (third index: runs through all TPCs).
238  *
239  * If `standalonePlane` is specified, it is a functor that returns whether its
240  * argument, a `geo::PlaneGeo` object, should not be grouped at all (i.e.,
241  * `standalonePlane(plane)` returns `false` if the `plane` can be grouped to
242  * others).
243  * Each plane for which `standalonePlane` evaluates `true` has their own
244  * "group" of one plane.
245  */
246  template <typename Pred>
247  std::vector<std::vector<PlaneColl_t>> groupPlanesAndTPCs
248  (Pred standalonePlane);
249 
250  /**
251  * @brief Extracts composition of all readout planes.
252  * @return readout plane composition
253  *
254  * This function returns a list: for each cryostat (first index),
255  * a list of TPC sets (second index: TPC set within the cryostat)
256  * each listing its TPC (third index: runs through all TPCs).
257  */
258  std::vector<std::vector<PlaneColl_t>> groupPlanesAndTPCs();
259 
260 
261  /**
262  * @brief Extracts all the TPC sets covered by any of the plane groups.
263  * @param groupedPlanes wire planes, grouped by cryostat.
264  * @return TPC sets as sets of TPC IDs
265  *
266  * The return value is a container that for each cryostat (first index),
267  * hosts a list of TPC sets (second index: TPC set within the cryostat),
268  * each listing its TPC (third index: runs through all TPCs).
269  * The order of the TPC sets within a cryostat is undefined.
270  * This function also fills `fMaxTPCsets`.
271  *
272  * The input parameter `groupedPlanes` follows the same structure as the
273  * argument `AllTPCsOnROPs` of `groupPlanesIntoROPs()`.
274  */
275  std::vector<std::vector<std::vector<geo::TPCID>>> extractTPCsetsFromROPs
276  (std::vector<std::vector<PlaneColl_t>> const& planes);
277 
278 
279  /**
280  * @brief Extracts the final set of TPC sets
281  * @param AllTPCsOnROPs groups of TPC IDs planes in a readout planes belong to
282  *
283  * The function collects sets of TPCs from all the ROP's.
284  * It fills `fTPCsetCount` and `fTPCsetTPCs`.
285  * It requires `fMaxTPCsets` to have been already set.
286  * The input argument `AllTPCsOnROPs` is a vector with index the number of
287  * cryostat. For each cryostat, a list of readout planes is presented
288  * (unsorted and unlabelled), in each of which the list of TPCs the planes in
289  * the readout planes belong to is stored.
290  */
291  void fillTPCsInSet
292  (std::vector<std::vector<std::vector<geo::TPCID>>> const& AllTPCsOnROPs);
293 
294 
295  /**
296  * @brief Assigns each of the readout planes to a TPC set.
297  * @param AllTPCsOnROPs groups of TPC IDs planes in a readout planes belong to
298  * @param AllPlanesInROPs planes grouped by ROP
299  * @return a map of readout planes in each TPC set, each with plane content
300  *
301  * This function fills `MaxROPs`. In addition, it returns the list by TPC set
302  * of the groups of sensitive planes into each readout plane in the set.
303  * It requires `fTPCsetTPCs` to have been computed already.
304  *
305  * The input argument `AllTPCsOnROPs` is a vector with index the number of
306  * cryostat. For each cryostat, a list of readout planes is presented
307  * (unsorted and unlabelled), in each of which the list of TPCs the planes in
308  * the readout planes belong to is stored.
309  *
310  */
312  std::vector<std::vector<std::vector<geo::TPCID>>> const& AllTPCsOnROPs, std::vector<std::vector<PlaneColl_t>>&& AllPlanesInROPs
313  );
314 
315  /**
316  * @brief Builds final readout plane information.
317  * @param PlanesInProtoROPs plane-to-ROP assignments in each TPC set
318  *
319  * This function fills `fROPcount` and `fROPplanes`.
320  *
321  * It requires `fMaxROPs`, `fTPCsetTPCs` and `fTPCsetCount` to have been
322  * computed already.
323  */
324  void fillPlanesInROP(
325  readout::TPCsetDataContainer<std::vector<PlaneColl_t>> const& PlanesInProtoROPs
326  );
327 
328  /**
329  * @brief Creates the map from each TPC to its TPC set.
330  *
331  * This function fills `fTPCtoTPCset`.
332  *
333  * It requires `fCryostats` and `fTPCsetTPCs` to have been computed already.
334  */
335  void fillTPCtoTPCsetMap();
336 
337 
338  /**
339  * @brief Creates the map from each wire plane to its readout plane.
340  *
341  * This function fills `fPlaneToROP`.
342  *
343  * It requires `fCryostats` and `fROPplanes` to have been computed
344  * already.
345  */
346  void fillPlaneToROPmap();
347 
348  /// Returns the `planes` sorted by decreasing normal coordinate.
349  std::vector<PlaneColl_t> sortByNormalCoordinate
350  (std::vector<PlaneColl_t> const& planes) const;
351 
352  /// Throws an exception if planes do not share the same normal direction.
353  void checkNormalDirection(std::vector<PlaneColl_t> const& planes) const;
354 
355 
356  /**
357  * @brief Returns the planes grouped by their drift coordinate.
358  * @tparam PlaneColl a `geo::PlaneGeo` collection (forward-iterable)
359  * @param planes collection of the wire planes to be grouped
360  * @param tolerance maximum distance in drift for planes in a single group
361  * @return a collection of groups of (pointers to) planes
362  *
363  * The `planes` in the input collection are split into groups which share the
364  * same drift coordinate. The `tolerance` parameter defines how different that
365  * coordinate can be for planes to be grouped together.
366  * The result is expressed as a collection of collections of planes: each
367  * element of the outer collection is a group of constant pointers to
368  * `geo::PlaneGeo` objects representing all the planes with the same drift
369  * coordinate.
370  * The sorting algorithm is guaranteed to be stable, i.e. if any two planes
371  * _A_ and _B_ have the same drift coordinate and in the `planes` collection
372  * _A_ is before _B_, in the resulting group _A_ will also be before _B_.
373  *
374  * In the current ICARUS geometry description the drift direction is on _x_
375  * axis, and _x_ is the drift coordinate.
376  */
377  template <typename PlaneColl>
378  static std::vector<std::vector<geo::PlaneGeo const*>> groupPlanesByDriftCoord
379  (PlaneColl const& planes, double tolerance = 0.1);
380 
381 
382  /// Returns a collection with a TPC ID for each plane in the list of `planes`.
383  static std::vector<geo::TPCID> extractTPCIDs
384  (std::vector<geo::PlaneGeo const*> const& planes);
385 
386 
387  /// Returns whether all the TPCs covered by a ROP are in a given TPC set.
388  static bool isROPinTPCset(
389  std::vector<geo::TPCID> const& ROPTPCIDs,
390  std::vector<geo::TPCID> const& TPCsetTPCIDs
391  );
392 
393 
394  /**
395  * @brief Returns ROP number matching the plane number shared by all `planes`.
396  * @return a ROP number, or `readout::ROPID::getInvalidID()` on failure
397  *
398  * The algorithms verifies that all elements in `planes` have an `ID()` with
399  * the same plane number (`geo::PlaneID::Plane`), and returns it.
400  * If the plane list is empty or if not all planes in the list have the same
401  * plane number, `readout::ROPID::getInvalidID()` is returned.
402  */
404 
405 
406 }; // class icarus::details::ROPandTPCsetBuildingAlg
407 
408 
409 // ----------------------------------------------------------------------------
410 
411 #endif // ICARUSALG_GEOMETRY_DETAILS_ROPANDTPCSETBUILDINGALG_H
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
readout::TPCsetDataContainer< TPCColl_t > fTPCsetTPCs
Output: TPC&#39;s in each TPC set.
std::vector< unsigned int > TPCsetCount()&&
Output: number of TPC sets in each cryostat.
readout::TPCsetDataContainer< unsigned int > ROPcount()&&
Output: number of readout planes in each TPC set.
void fillTPCsInSet(std::vector< std::vector< std::vector< geo::TPCID >>> const &AllTPCsOnROPs)
Extracts the final set of TPC sets.
Encapsulate the construction of a single cyostat.
Classes identifying readout-related concepts.
unsigned int ROPID_t
Type for the ID number.
unsigned int fMaxTPCsets
Highest number of TPC sets in any cryostat.
readout::TPCsetDataContainer< unsigned int > fROPcount
Output: number of readout planes in each TPC set.
auto const tolerance
Simple data structure holding the data of the geometry.
readout::ROPDataContainer< PlaneColl_t > ROPplanes()&&
Output: planes in each of the readout plane.
static std::vector< std::vector< geo::PlaneGeo const * > > groupPlanesByDriftCoord(PlaneColl const &planes, double tolerance=0.1)
Returns the planes grouped by their drift coordinate.
std::vector< geo::CryostatGeo > CryostatList_t
Type of list of cryostats.
Definition: GeometryData.h:34
geo::GeometryData_t::CryostatList_t const * fCryostats
std::vector< std::vector< PlaneColl_t > > groupPlanesAndTPCs()
Extracts composition of all readout planes.
void fillTPCtoTPCsetMap()
Creates the map from each TPC to its TPC set.
geo::PlaneDataContainer< readout::ROPID > PlaneToROP()&&
Output: planes in each of the readout plane.
A few simple data type definitions.
std::vector< unsigned int > fTPCsetCount
Output: number of TPC sets in each cryostat.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
Containers to hold one datum per TPC or plane.
ROPandTPCsetBuildingAlg(std::string const &logCategory)
Construction: specify the algorithm configuration.
readout::TPCsetDataContainer< TPCColl_t > TPCsetTPCs()&&
Output: TPC&#39;s in each TPC set.
static readout::ROPID::ROPID_t ROPnumberFromPlanes(PlaneColl_t const &planes)
Returns ROP number matching the plane number shared by all planes.
static std::vector< geo::TPCID > extractTPCIDs(std::vector< geo::PlaneGeo const * > const &planes)
Returns a collection with a TPC ID for each plane in the list of planes.
std::vector< PlaneColl_t > sortByNormalCoordinate(std::vector< PlaneColl_t > const &planes) const
Returns the planes sorted by decreasing normal coordinate.
void fillPlanesInROP(readout::TPCsetDataContainer< std::vector< PlaneColl_t >> const &PlanesInProtoROPs)
Builds final readout plane information.
std::vector< std::vector< std::vector< geo::TPCID > > > extractTPCsetsFromROPs(std::vector< std::vector< PlaneColl_t >> const &planes)
Extracts all the TPC sets covered by any of the plane groups.
Structure to hold enough information to computed the expected results.
readout::TPCsetDataContainer< std::vector< PlaneColl_t > > groupPlanesIntoROPs(std::vector< std::vector< std::vector< geo::TPCID >>> const &AllTPCsOnROPs, std::vector< std::vector< PlaneColl_t >> &&AllPlanesInROPs)
Assigns each of the readout planes to a TPC set.
std::tuple< std::vector< unsigned int >, readout::TPCsetDataContainer< TPCColl_t >, readout::TPCsetDataContainer< unsigned int >, readout::ROPDataContainer< PlaneColl_t >, geo::TPCDataContainer< readout::TPCsetID >, geo::PlaneDataContainer< readout::ROPID > > ResultsBase_t
Full group of results of the algorithm.
geo::TPCDataContainer< readout::TPCsetID > TPCtoTPCset()&&
Output: number of readout planes in each TPC set.
std::vector< geo::PlaneGeo const * > PlaneColl_t
Type of collection of planes (pointers to geo::PlaneGeo).
Definition of data types for geometry description.
unsigned int fMaxROPs
Highest number of ROPs in any TPC set.
BEGIN_PROLOG Z planes
Extracts TPC sets and readout planes from a list of cryostats.
geo::PlaneDataContainer< readout::ROPID > fPlaneToROP
Output: the ROP each wire plane belongs to.
readout::ROPDataContainer< PlaneColl_t > fROPplanes
Output: planes in each of the readout plane.
geo::TPCDataContainer< readout::TPCsetID > fTPCtoTPCset
Output: the TPC set each TPC belongs to.
Encapsulate the construction of a single detector plane.
void fillPlaneToROPmap()
Creates the map from each wire plane to its readout plane.
ROPandTPCsetBuildingAlg()=default
Construction: use default configuration.
static bool isROPinTPCset(std::vector< geo::TPCID > const &ROPTPCIDs, std::vector< geo::TPCID > const &TPCsetTPCIDs)
Returns whether all the TPCs covered by a ROP are in a given TPC set.
std::string fLogCategory
Category to write messages into.
void clear()
Destroys all the result data members.
Results_t run(geo::GeometryData_t::CryostatList_t const &Cryostats)
Runs the algorithm as configured from start to end.
std::vector< geo::TPCGeo const * > TPCColl_t
Type of collection of TPCs (pointers to geo::TPCGeo).
Containers to hold one datum per TPC set or readout plane.
void checkNormalDirection(std::vector< PlaneColl_t > const &planes) const
Throws an exception if planes do not share the same normal direction.
Encapsulate the construction of a single detector plane.