All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SlidingWindowDefinitionAlg.cxx
Go to the documentation of this file.
1 /**
2  * @file icaruscode/PMT/Trigger/Algorithms/SlidingWindowDefinitionAlg.cxx
3  * @brief Algorithm composing PMT sliding windows from geometry information.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date January 26, 2021
6  * @file icaruscode/PMT/Trigger/Algorithms/SlidingWindowDefinitionAlg.h
7  *
8  */
9 
10 
11 // library header
13 
14 // ICARUS libraries
16 
17 // LArSoft libraries
22 
23 // framework libraries
24 #include "messagefacility/MessageLogger/MessageLogger.h"
25 #include "cetlib_except/exception.h"
26 
27 // C/C++ standard libraries
28 #include <ostream>
29 #include <optional>
30 #include <cassert>
31 
32 
33 // -----------------------------------------------------------------------------
34 // --- icarus::trigger::SlidingWindowDefinitionAlg implementation
35 // -----------------------------------------------------------------------------
37  (unsigned int windowSize, unsigned int windowStride) const
38  -> WindowDefs_t
39 {
40  /*
41  * 1. compute the vertical PMT towers in each separate optical detector plane
42  * 2. fill the windows by counting channels (i.e. op. det.)
43  */
45 
46  //
47  // 1. compute the vertical PMT towers in each separate optical detector plane
48  //
51  for (geo::CryostatGeo const& cryo: fGeom.IterateCryostats())
52  slicerAlg.appendCryoSlices(slices, cryo);
53 
54  //
55  // 2. fill the windows by counting channels (i.e. optical detectors)
56  //
57  WindowDefs_t windows;
58 
59  for (PMTverticalSlicingAlg::PMTtowerOnPlane_t const& planeSlices: slices) {
60 
61  auto itSlice = planeSlices.begin();
62  auto const send = planeSlices.end();
63  while (itSlice != send) {
64 
65  mf::LogTrace(fLogCategory) << "Assembling window #" << windows.size();
66 
67  WindowDefs_t::value_type window;
68  window.reserve(windowSize);
69 
70  std::optional<decltype(itSlice)> nextStart;
71  unsigned int nChannels = 0U;
72  while (nChannels < windowSize) {
73  if (itSlice == send) break;
74 
75  // aside: check if this is the right place to start the next window
76  if (nChannels == windowStride) {
77  mf::LogTrace(fLogCategory)
78  << " (next window will start from this slice)";
79  nextStart = itSlice;
80  }
81  else if ((nChannels > windowStride) && !nextStart) {
82  throw cet::exception("SlidingWindowDefinitionAlg")
83  << "Unable to start a new window " << windowStride
84  << " channels after window #" << windows.size()
85  << " (next slice starts " << nChannels << " channels after)\n";
86  }
87 
88  mf::LogTrace(fLogCategory)
89  << " adding " << itSlice->size() << " channels to existing "
90  << nChannels;
91  for (geo::OpDetGeo const* opDet: *itSlice) {
92  geo::OpDetID const& id = opDet->ID();
93  raw::Channel_t const channel
94  = fGeom.OpDetFromCryo(id.OpDet, id.Cryostat);
95  mf::LogTrace(fLogCategory)
96  << " * " << id << " (channel " << channel << ")";
97  window.push_back(channel);
98  } // for channels in slice
99  nChannels += (itSlice++)->size();
100  } // while
101  if (nChannels == windowStride) nextStart = itSlice;
102  assert(nextStart);
103 
104  if (nChannels < windowSize) {
105  if (!windows.empty()) {
106  // if the last window can't be completed, it's still fine for us
107  mf::LogTrace(fLogCategory)
108  << " ... couldn't complete the last " << windowSize
109  << "-channel window: only " << nChannels << " channels collected";
110  break;
111  }
112  } // if missing windows
113  if (nChannels != windowSize) {
114  throw cet::exception("SlidingWindowDefinitionAlg")
115  << "Definition of one window yielded " << nChannels
116  << " elements (window should be of size " << windowSize
117  << " and with stride " << windowStride << ").\n";
118  }
119 
120  windows.push_back(std::move(window));
121 
122  itSlice = nextStart.value();
123  } // for all slices
124  } // for all windows
125  mf::LogTrace(fLogCategory)
126  << "SlidingWindowTrigger defined " << windows.size() << " windows.";
127 
128  return windows;
129 } // icarus::trigger::SlidingWindowDefinitionAlg::makeWindows()
130 
131 
132 // -----------------------------------------------------------------------------
133 
Encapsulate the construction of a single cyostat.
Definition of util::enumerate().
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
icarus::trigger::TriggerWindowDefs_t WindowDefs_t
Definition of all windows.
fDetProps &fDetProps fDetProps &fDetProps fLogCategory
Access the description of detector geometry.
void appendCryoSlices(Slices_t &slices, geo::CryostatGeo const &cryo) const
Computes slices from all PMT in cryo and appends them to slices.
Algorithm composing PMT sliding windows from geometry information.
Algorihtm to group PMTs into piling towers.
std::vector< TCSlice > slices
Definition: DataStructs.cxx:13
Encapsulate the geometry of an optical detector.
The data type to uniquely identify a optical detector.
Definition: geo_types.h:297
WindowDefs_t makeWindows(unsigned int windowSize, unsigned int windowStride) const
Performs the calculation and returns the sliding window composition.
std::vector< PMTtowerOnPlane_t > Slices_t
Type of PMT towers, per plane.
std::vector< PMTtower_t > PMTtowerOnPlane_t
Type of list of PMT towers on a single optical detector plane.
Algorithm clustering PMT according to their position.