All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
icarus::trigger::WindowTopologyAlg Class Reference

Algorithm to create trigger window topology information. More...

#include <WindowTopologyAlg.h>

Inheritance diagram for icarus::trigger::WindowTopologyAlg:
icarus::ns::util::mfLoggingClass

Public Types

using InputTriggerGate_t = icarus::trigger::TrackedOpticalTriggerGate< sbn::OpDetWaveformMeta >
 Type of trigger gate extracted from the input event. More...
 
using TriggerGates_t = std::vector< InputTriggerGate_t >
 A list of trigger gates from input. More...
 
using TriggerGatesPerCryostat_t = std::vector< TriggerGates_t >
 Type of lists of gates, one list per cryostat (outer index: cryostat no). More...
 

Public Member Functions

 WindowTopologyAlg (geo::GeometryCore const &geom, std::string const &logCategory="WindowTopologyAlg")
 Constructor. More...
 
WindowChannelMap createFromGates (TriggerGatesPerCryostat_t const &gates) const
 Returns the topology of the windows described by the gates. More...
 
WindowChannelMap createFromGates (TriggerGates_t const &gates) const
 Returns the topology of the windows described by the gates. More...
 
WindowChannelMap createFromCryostatGates (TriggerGates_t const &windowChannels, geo::CryostatGeo const &cryo) const
 Returns the topology of the windows described by the gates. More...
 
WindowChannelMap createFromCryostatGates (TriggerGates_t const &windowChannels, geo::CryostatID cryoID) const
 Returns the topology of the windows described by the gates. More...
 
template<typename... Args>
auto emplaceAndDumpMap (Args &&...args) const -> WindowChannelMap
 

Private Types

using WindowChannels_t = std::vector< raw::Channel_t >
 All channels in a gate. More...
 
using WindowChannelColl_t = std::vector< WindowChannels_t >
 All channels in many gates (one list per gate). More...
 

Private Member Functions

template<typename... Args>
WindowChannelMap emplaceAndDumpMap (Args &&...args) const
 

Static Private Member Functions

static std::vector
< WindowChannelMap::WindowInfo_t
createWindowsFromCryostat (WindowChannelColl_t const &windowChannels, geo::CryostatGeo const &cryo, geo::GeometryCore const &geom, std::size_t firstWindowIndex=0U)
 Extracts topology information from a set of windows. More...
 
static WindowChannelColl_t extractGateChannels (TriggerGates_t const &gates)
 Extracts the channel ID from a collection of gates. More...
 
static
WindowChannelMap::WindowInfo_t
const * 
findClosestWindow (std::vector< WindowChannelMap::WindowInfo_t * > const &windowList, WindowChannelMap::WindowInfo_t const *targetWindow)
 Returns the window in windowList closest to the targetWindow. More...
 

Private Attributes

geo::GeometryCore const *const fGeom
 Geometry service provider. More...
 

Additional Inherited Members

- Protected Member Functions inherited from icarus::ns::util::mfLoggingClass
 mfLoggingClass (std::string const &logCategory)
 Constructor: initializes with the specified log category. More...
 
std::string logCategory () const
 Returns the logging category string for this object. More...
 
mfLoggingClass const & loggingClass () const
 Returns this object (as a logging class object). More...
 
mf::LogError mfLogError (std::string const &file={}, int const lineNumber=0) const
 Returns a mf::LogError() stream for logging. More...
 
mf::LogWarning mfLogWarning (std::string const &file={}, int const lineNumber=0) const
 Returns a mf::LogWarning() stream for logging. More...
 
mf::LogProblem mfLogProblem (std::string const &file={}, int const lineNumber=0) const
 Returns a mf::LogProblem() stream for logging. More...
 
mf::LogInfo mfLogInfo (std::string const &file={}, int const lineNumber=0) const
 Returns a mf::LogInfo() stream for logging. More...
 
mf::LogVerbatim mfLogVerbatim (std::string const &file={}, int const lineNumber=0) const
 Returns a mf::LogVerbatim() stream for logging. More...
 
mf::LogDebug mfLogDebug (std::string const &file={}, int const lineNumber=0) const
 Returns a mf::LogDebug() stream for logging. More...
 
mf::LogTrace mfLogTrace (std::string const &file={}, int const lineNumber=0) const
 Returns a mf::LogTrace() stream for logging. More...
 

Detailed Description

Algorithm to create trigger window topology information.

The algorithm defines the windows based on trigger gates and their channels, and establishes their topology cryostat by cryostat.

Definition at line 50 of file WindowTopologyAlg.h.

Member Typedef Documentation

Type of trigger gate extracted from the input event.

Definition at line 58 of file WindowTopologyAlg.h.

A list of trigger gates from input.

Definition at line 61 of file WindowTopologyAlg.h.

Type of lists of gates, one list per cryostat (outer index: cryostat no).

Definition at line 64 of file WindowTopologyAlg.h.

All channels in many gates (one list per gate).

Definition at line 148 of file WindowTopologyAlg.h.

All channels in a gate.

Definition at line 145 of file WindowTopologyAlg.h.

Constructor & Destructor Documentation

icarus::trigger::WindowTopologyAlg::WindowTopologyAlg ( geo::GeometryCore const &  geom,
std::string const &  logCategory = "WindowTopologyAlg" 
)

Constructor.

Parameters
geomgeometry service provider
logCategorycategory tag for messages from this algorithm

Definition at line 54 of file WindowTopologyAlg.cxx.

59  , fGeom(&geom)
60 {}
Helper for logging classes.
geo::GeometryCore const *const fGeom
Geometry service provider.
std::string logCategory() const
Returns the logging category string for this object.

Member Function Documentation

auto icarus::trigger::WindowTopologyAlg::createFromCryostatGates ( TriggerGates_t const &  windowChannels,
geo::CryostatGeo const &  cryo 
) const

Returns the topology of the windows described by the gates.

Parameters
gatesa set of gates within a single cryostat
cryothe cryostat the gates (and their channels) belong to
Returns
topology of the windows described by the gates

The input gates is a collection with all the gates from the specified cryostat cryo.

Each gate covers one or more channels: each window is made out of all the channels in a gate. The opening content of the gates is not considered.

Definition at line 121 of file WindowTopologyAlg.cxx.

123 {
124  return emplaceAndDumpMap(
125  createWindowsFromCryostat(extractGateChannels(windowChannels), cryo, *fGeom)
126  );
127 } // icarus::trigger::WindowTopologyAlg::createFromCryostatGates()
static WindowChannelColl_t extractGateChannels(TriggerGates_t const &gates)
Extracts the channel ID from a collection of gates.
WindowChannelMap emplaceAndDumpMap(Args &&...args) const
geo::GeometryCore const *const fGeom
Geometry service provider.
static std::vector< WindowChannelMap::WindowInfo_t > createWindowsFromCryostat(WindowChannelColl_t const &windowChannels, geo::CryostatGeo const &cryo, geo::GeometryCore const &geom, std::size_t firstWindowIndex=0U)
Extracts topology information from a set of windows.
auto icarus::trigger::WindowTopologyAlg::createFromCryostatGates ( TriggerGates_t const &  windowChannels,
geo::CryostatID  cryoID 
) const

Returns the topology of the windows described by the gates.

Parameters
gatesa set of gates within a single cryostat
cryoIDID of the cryostat the gates (and their channels) belong to
Returns
topology of the windows described by the gates
See Also
createFromCryostatGates(TriggerGates_t const&, geo::CryostatGeo const&)

The input gates is a collection with all the gates from the specified cryostat with ID cryoID.

See createFromCryostatGates(WindowChannelsPerCryostat_t const&, geo::CryostatGeo const&) for more information.

Definition at line 132 of file WindowTopologyAlg.cxx.

134 {
135  return createFromCryostatGates(windowChannels, fGeom->Cryostat(cryoID));
136 } // icarus::trigger::WindowTopologyAlg::createFromCryostatGates()
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
geo::GeometryCore const *const fGeom
Geometry service provider.
WindowChannelMap createFromCryostatGates(TriggerGates_t const &windowChannels, geo::CryostatGeo const &cryo) const
Returns the topology of the windows described by the gates.
auto icarus::trigger::WindowTopologyAlg::createFromGates ( TriggerGatesPerCryostat_t const &  gates) const

Returns the topology of the windows described by the gates.

Parameters
gatesa set of gates, grouped by cryostat
Returns
topology of the windows described by the gates

The input gates is a collection with as many entries as there are cryostats in the detector, the first entry collecting all gates from the first cryostat (C:0), the next all the gates from the second one (C:2), and so on.

Each gate covers one or more channels: each window is made out of all the channels in a gate. The opening content of the gates is not considered.

Definition at line 65 of file WindowTopologyAlg.cxx.

66 {
67 
68  // store the window topology information here:
69  std::vector<WindowChannelMap::WindowInfo_t> windows;
70 
71  for (auto const& [ cryoGates, cryo ]
72  : util::zip(gates, fGeom->IterateCryostats()))
73  {
74 
75  append(
76  windows,
78  (extractGateChannels(cryoGates), cryo, *fGeom, windows.size())
79  );
80 
81  } // for cryostats
82 
83  return emplaceAndDumpMap(std::move(windows));
84 
85 } // icarus::trigger::WindowTopologyAlg::createFromGates()
static WindowChannelColl_t extractGateChannels(TriggerGates_t const &gates)
Extracts the channel ID from a collection of gates.
WindowChannelMap emplaceAndDumpMap(Args &&...args) const
geo::GeometryCore const *const fGeom
Geometry service provider.
IteratorBox< cryostat_iterator,&GeometryCore::begin_cryostat,&GeometryCore::end_cryostat > IterateCryostats() const
Enables ranged-for loops on all cryostats of the detector.
static std::vector< WindowChannelMap::WindowInfo_t > createWindowsFromCryostat(WindowChannelColl_t const &windowChannels, geo::CryostatGeo const &cryo, geo::GeometryCore const &geom, std::size_t firstWindowIndex=0U)
Extracts topology information from a set of windows.
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
Definition: zip.h:295
auto icarus::trigger::WindowTopologyAlg::createFromGates ( TriggerGates_t const &  gates) const

Returns the topology of the windows described by the gates.

Parameters
gatesa set of gates
Returns
topology of the windows described by the gates

The input gates is a collection with all relevant gates in the detector.

Each gate covers one or more channels: each window is made out of all the channels in a gate. The opening content of the gates is not considered.

Gates are first split by the cryostat they belong to (cross-cryostat gates are forbidden), and then the window topology is extracted.

Definition at line 90 of file WindowTopologyAlg.cxx.

91 {
92 
93  // split gates by cryostat
94  TriggerGatesPerCryostat_t gatesByCryostat { fGeom->Ncryostats() };
95  for (InputTriggerGate_t const& gate: gates) {
96 
97  geo::CryostatID cid; // invalid
98  assert(!cid.isValid);
99 
100  for (raw::Channel_t const channel: gate.channels()) {
101  geo::OpDetGeo const& opDet = fGeom->OpDetGeoFromOpChannel(channel);
102  geo::OpDetID const oid = opDet.ID();
103  if (!cid) cid = oid;
104  else if (cid != oid) { // just in case
105  throw cet::exception("WindowTopologyAlg")
106  << "Input gate includes gates from different cryostats!!\n";
107  }
108  } // for channels in gate
109  if (!cid) continue; // gate with no channels does not contribute
110 
111  gatesByCryostat.at(cid.Cryostat).push_back(gate); // (copy)
112  } // for gates
113 
114  return createFromGates(gatesByCryostat);
115 
116 } // icarus::trigger::WindowTopologyAlg::createFromGates()
bool isValid
Whether this ID points to a valid element.
Definition: geo_types.h:211
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
icarus::trigger::TrackedOpticalTriggerGate< sbn::OpDetWaveformMeta > InputTriggerGate_t
Type of trigger gate extracted from the input event.
std::vector< TriggerGates_t > TriggerGatesPerCryostat_t
Type of lists of gates, one list per cryostat (outer index: cryostat no).
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
WindowChannelMap createFromGates(TriggerGatesPerCryostat_t const &gates) const
Returns the topology of the windows described by the gates.
geo::GeometryCore const *const fGeom
Geometry service provider.
geo::OpDetID const & ID() const
Returns the geometry ID of this optical detector.
Definition: OpDetGeo.h:72
The data type to uniquely identify a optical detector.
Definition: geo_types.h:297
OpDetGeo const & OpDetGeoFromOpChannel(unsigned int OpChannel) const
Returns the geo::OpDetGeo object for the given channel number.
The data type to uniquely identify a cryostat.
Definition: geo_types.h:190
auto icarus::trigger::WindowTopologyAlg::createWindowsFromCryostat ( WindowChannelColl_t const &  windowChannels,
geo::CryostatGeo const &  cryo,
geo::GeometryCore const &  geom,
std::size_t  firstWindowIndex = 0U 
)
staticprivate

Extracts topology information from a set of windows.

Parameters
windowChannelsthe windows, specified by composition in channel ID
cryothe cryostat the windows belong to
geomgeometry service provider
firstWindowIndex(default: 0) the index assigned to the first window
Returns
window topology information, one entry per window

Definition at line 151 of file WindowTopologyAlg.cxx.

157 {
158  /*
159  * 1. fill the window information with local information
160  * 2. sort the windows in drift plane (first cryostat TPC as reference)
161  * 3. split the windows per plane
162  * 4. for each window plane:
163  * 4.1. sort windows on beam direction (TPC width direction)
164  * 4.2. fill the neighbour information on each window
165  */
166  std::vector<WindowChannelMap::WindowInfo_t> windows;
167  windows.reserve(windowChannels.size());
168 
169  // use the first TPC of the cryostat as reference for directions
170  assert(cryo.NTPC() > 0U);
171  geo::TPCGeo const& refTPC = cryo.TPC(0U);
172 
173  //
174  // 1. fill the window information with local information
175  //
176  using WindowInfoPtrs_t = std::vector<WindowChannelMap::WindowInfo_t*>;
177 
178  WindowInfoPtrs_t cryoWindowInfo;
179  cryoWindowInfo.reserve(windowChannels.size());
180 
181  std::size_t iWindow = firstWindowIndex;
182  for (auto const& channels: windowChannels) {
183 
184  WindowChannelMap::WindowInfo_t wInfo;
185 
186  wInfo.index = iWindow++;
187  wInfo.channels = channels;
188  std::sort(wInfo.channels.begin(), wInfo.channels.end());
189  wInfo.cryoid = channels.empty()
190  ? geo::CryostatID{}
191  : geom.OpDetGeoFromOpChannel(channels.front()).ID().asCryostatID()
192  ;
193 
195  for (raw::Channel_t const channel: channels) {
196  // documentation of OpDetGeoFromOpChannel() does not say what on error...
197  geo::OpDetGeo const& opDet = geom.OpDetGeoFromOpChannel(channel);
198  middlePoint.add(opDet.GetCenter());
199  if (opDet.ID() != wInfo.cryoid) wInfo.cryoid = geo::CryostatID{};
200  } // for channel
201  wInfo.center = middlePoint.middlePoint();
202 
203  windows.push_back(std::move(wInfo));
204  cryoWindowInfo.push_back(&windows.back());
205 
206  } // for windows
207 
208  //
209  // 2. sort the windows in drift plane (first cryostat TPC as reference)
210  //
211  auto const normalProjection = [&refTPC](auto const* info)
212  { return refTPC.DistanceFromReferencePlane(info->center); };
213  WindowInfoPtrs_t const windowsByNormal
214  = util::sortCollBy(cryoWindowInfo, normalProjection);
215 
216  //
217  // 3. split the windows per plane
218  //
219  // split the list in two; there is a good deal of faith here
220  auto const beamCoordinate
221  = [&refPlane=refTPC.ReferencePlane()](auto const* info)
222  { return refPlane.PointWidthDepthProjection(info->center).X(); }
223  ;
224 
225  //
226  // 4. for each plane:
227  //
228  // 4.1. sort windows on beam direction (TPC width direction)
229  //
230  auto const iMiddleWindow
231  = std::next(windowsByNormal.cbegin(), windowsByNormal.size() / 2U);
232  std::array<WindowInfoPtrs_t, 2U> const windowsByPlane = {
233  util::sortBy(windowsByNormal.cbegin(), iMiddleWindow, beamCoordinate),
234  util::sortBy(iMiddleWindow, windowsByNormal.cend(), beamCoordinate)
235  };
236 
237  for (auto const& [ iPlane, planeWindows ]: util::enumerate(windowsByPlane)) {
238  //
239  // 4.2. fill the neighbour information on each window
240  //
241  auto const& otherPlaneWindows
242  = windowsByPlane.at(windowsByPlane.size() - 1U - iPlane);
243  std::size_t const iLastPlaneWindow = planeWindows.size() - 1U;
244  for (auto [ iPlaneWindow, windowInfo ]: util::enumerate(planeWindows)) {
245 
246  // assumes all topology information is InvalidWindowIndex by default
247 
248  if (WindowChannelMap::WindowInfo_t const* closestOppositeWindow
249  = findClosestWindow(otherPlaneWindows, windowInfo)
250  ) {
251  windowInfo->opposite = closestOppositeWindow->index;
252  }
253 
254  if (iPlaneWindow > 0U)
255  windowInfo->upstream = planeWindows[iPlaneWindow - 1U]->index;
256 
257  if (iPlaneWindow < iLastPlaneWindow)
258  windowInfo->downstream = planeWindows[iPlaneWindow + 1U]->index;
259 
260  } // for window in plane
261  } // for planes
262 
263  return windows;
264 
265 } // icarus::trigger::WindowTopologyAlg::createWindowsFromCryostat()
auto sortBy(BIter begin, EIter end, Key key, Sorter sorter={})
Returns a vectors to pointers to coll elements, sorted by key.
Definition: sortBy.h:104
Helper class to compute the middle point in a point set.
Geometry information for a single TPC.
Definition: TPCGeo.h:38
void GetCenter(double *xyz, double localz=0.0) const
Definition: OpDetGeo.cxx:40
void add(Point const &p)
Accumulates a point.
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
auto sortCollBy(Coll &coll, Key key, Sorter sorter={})
Returns a vectors to pointers to coll elements, sorted by key.
Definition: sortBy.h:169
constexpr CryostatID const & asCryostatID() const
Conversion to CryostatID (for convenience of notation).
Definition: geo_types.h:275
static WindowChannelMap::WindowInfo_t const * findClosestWindow(std::vector< WindowChannelMap::WindowInfo_t * > const &windowList, WindowChannelMap::WindowInfo_t const *targetWindow)
Returns the window in windowList closest to the targetWindow.
geo::OpDetID const & ID() const
Returns the geometry ID of this optical detector.
Definition: OpDetGeo.h:72
geo::Point_t middlePoint(BeginIter begin, EndIter end)
Returns the middle of the specified points.
The data type to uniquely identify a cryostat.
Definition: geo_types.h:190
template<typename... Args>
auto icarus::trigger::WindowTopologyAlg::emplaceAndDumpMap ( Args &&...  args) const -> WindowChannelMap

Definition at line 141 of file WindowTopologyAlg.cxx.

143 {
144  WindowChannelMap const map { std::forward<Args>(args)... };
145  mfLogTrace() << "Window map: << " << map;
146  return map;
147 } // icarus::trigger::WindowTopologyAlg::emplaceAndDumpMap()
mf::LogTrace mfLogTrace(std::string const &file={}, int const lineNumber=0) const
Returns a mf::LogTrace() stream for logging.
template<typename... Args>
WindowChannelMap icarus::trigger::WindowTopologyAlg::emplaceAndDumpMap ( Args &&...  args) const
private

Convenience function: creates and returns a WindowChannelMap from the arguments (args); in the meanwhile, it also dumps it into debug stream.

auto icarus::trigger::WindowTopologyAlg::extractGateChannels ( TriggerGates_t const &  gates)
staticprivate

Extracts the channel ID from a collection of gates.

Parameters
gatesa collection of gates
Returns
a collection of channel lists

The returned collection has one entry per input gate in gates: each entry is the list of channels that the corresponding gate covers.

Definition at line 270 of file WindowTopologyAlg.cxx.

271 {
272 
273  WindowChannelColl_t windowChannels;
274  windowChannels.reserve(gates.size());
275 
276  for (InputTriggerGate_t const& gate: gates) {
277  auto const& gateChannels = gate.channels();
278  windowChannels.emplace_back(gateChannels.begin(), gateChannels.end());
279  } // for gates
280 
281  return windowChannels;
282 
283 } // icarus::trigger::WindowTopologyAlg::extractGateChannels()
icarus::trigger::TrackedOpticalTriggerGate< sbn::OpDetWaveformMeta > InputTriggerGate_t
Type of trigger gate extracted from the input event.
std::vector< WindowChannels_t > WindowChannelColl_t
All channels in many gates (one list per gate).
auto icarus::trigger::WindowTopologyAlg::findClosestWindow ( std::vector< WindowChannelMap::WindowInfo_t * > const &  windowList,
WindowChannelMap::WindowInfo_t const *  targetWindow 
)
staticprivate

Returns the window in windowList closest to the targetWindow.

Parameters
windowListlist of (pointers to) the candidate windows
targetWindowthe reference window
Returns
a pointer to the closest among windowList, nullptr if none

A pointer to the window with the smallest distance from targetWindow is returned. The distance is computed between the centers of the windows as reported by the windows themselves.

The only case where no window (nullptr) is returned is when the window candidate list windowList is empty.

Definition at line 287 of file WindowTopologyAlg.cxx.

291 {
292 
293  if (!targetWindow || windowList.empty()) return nullptr;
294 
295  WindowChannelMap::WindowInfo_t const* closest = nullptr;
296  double minDistance2 = std::numeric_limits<double>::max();
297  for (auto const* window: windowList) {
298  if (!window) continue;
299 
300  double const d2 = (window->center - targetWindow->center).mag2();
301  if (minDistance2 <= d2) continue;
302  minDistance2 = d2;
303  closest = window;
304  } // for
305 
306  return closest;
307 } // icarus::trigger::WindowTopologyAlg::findClosestWindow()
auto mag2(Vector const &v)
Return norm of the specified vector.

Member Data Documentation

geo::GeometryCore const* const icarus::trigger::WindowTopologyAlg::fGeom
private

Geometry service provider.

Definition at line 151 of file WindowTopologyAlg.h.


The documentation for this class was generated from the following files: