36 std::vector<T>& append(std::vector<T>& destColl, std::vector<T>&& srcColl) {
38 if (destColl.empty()) destColl = std::move(srcColl);
40 destColl.reserve(destColl.size() + srcColl.size());
41 std::move(srcColl.begin(), srcColl.end(), back_inserter(destColl));
56 std::string
const& logCategory
58 : icarus::ns::util::mfLoggingClass(logCategory)
69 std::vector<WindowChannelMap::WindowInfo_t> windows;
71 for (
auto const& [ cryoGates, cryo ]
77 createWindowsFromCryostat
78 (extractGateChannels(cryoGates), cryo, *
fGeom, windows.size())
83 return emplaceAndDumpMap(std::move(windows));
104 else if (cid != oid) {
105 throw cet::exception(
"WindowTopologyAlg")
106 <<
"Input gate includes gates from different cryostats!!\n";
111 gatesByCryostat.at(cid.
Cryostat).push_back(gate);
114 return createFromGates(gatesByCryostat);
124 return emplaceAndDumpMap(
125 createWindowsFromCryostat(extractGateChannels(windowChannels), cryo, *
fGeom)
135 return createFromCryostatGates(windowChannels,
fGeom->Cryostat(cryoID));
140 template <
typename... Args>
144 WindowChannelMap
const map { std::forward<Args>(
args)... };
145 mfLogTrace() <<
"Window map: << " << map;
155 std::size_t firstWindowIndex
156 ) -> std::vector<WindowChannelMap::WindowInfo_t>
166 std::vector<WindowChannelMap::WindowInfo_t> windows;
167 windows.reserve(windowChannels.size());
170 assert(cryo.
NTPC() > 0U);
176 using WindowInfoPtrs_t = std::vector<WindowChannelMap::WindowInfo_t*>;
178 WindowInfoPtrs_t cryoWindowInfo;
179 cryoWindowInfo.reserve(windowChannels.size());
181 std::size_t iWindow = firstWindowIndex;
182 for (
auto const& channels: windowChannels) {
186 wInfo.
index = iWindow++;
189 wInfo.
cryoid = channels.empty()
191 : geom.OpDetGeoFromOpChannel(channels.front()).ID().
asCryostatID()
197 geo::OpDetGeo const& opDet = geom.OpDetGeoFromOpChannel(channel);
203 windows.push_back(std::move(wInfo));
204 cryoWindowInfo.push_back(&windows.back());
211 auto const normalProjection = [&refTPC](
auto const*
info)
212 {
return refTPC.DistanceFromReferencePlane(
info->center); };
213 WindowInfoPtrs_t
const windowsByNormal
220 auto const beamCoordinate
221 = [&refPlane=refTPC.ReferencePlane()](
auto const*
info)
222 {
return refPlane.PointWidthDepthProjection(
info->center).X(); }
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)
237 for (
auto const& [ iPlane, planeWindows ]:
util::enumerate(windowsByPlane)) {
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)) {
248 if (WindowChannelMap::WindowInfo_t
const* closestOppositeWindow
249 = findClosestWindow(otherPlaneWindows, windowInfo)
251 windowInfo->opposite = closestOppositeWindow->index;
254 if (iPlaneWindow > 0U)
255 windowInfo->upstream = planeWindows[iPlaneWindow - 1U]->index;
257 if (iPlaneWindow < iLastPlaneWindow)
258 windowInfo->downstream = planeWindows[iPlaneWindow + 1U]->index;
274 windowChannels.reserve(gates.size());
277 auto const& gateChannels = gate.channels();
278 windowChannels.emplace_back(gateChannels.begin(), gateChannels.end());
281 return windowChannels;
288 std::vector<WindowChannelMap::WindowInfo_t*>
const& windowList,
293 if (!targetWindow || windowList.empty())
return nullptr;
296 double minDistance2 = std::numeric_limits<double>::max();
297 for (
auto const* window: windowList) {
298 if (!window)
continue;
300 double const d2 = (window->center - targetWindow->center).
mag2();
301 if (minDistance2 <= d2)
continue;
321 if (!hasTopology()) {
322 throw cet::exception(
"WindowTopologyVerification")
323 <<
"verify() called without any window topology set to be verified.\n";
326 std::size_t iWindow = 0U;
327 std::string errorMsg;
328 for (
auto const& gate: gates) {
331 std::string
const windowError = verifyGate(iWindow++, gate);
333 if (!windowError.empty()) errorMsg += windowError +
'\n';
351 if (!hasTopology()) {
352 throw cet::exception(
"WindowTopologyVerification")
353 <<
"verify() called without any window topology set to be verified.\n";
356 std::size_t iWindow = 0U;
357 std::string errorMsg;
358 for (
auto const& cryoGates: gates) {
359 for (
auto const& gate: cryoGates) {
362 std::string
const windowError = verifyGate(iWindow++, gate);
364 if (!windowError.empty()) errorMsg += windowError +
'\n';
382 auto const channelInWindow
385 {
return std::binary_search(
begin,
end, channel); }
389 if (channelInWindow(channel))
continue;
390 if (errors.empty()) {
Definition of util::zip().
icarus::trigger::WindowTopologyAlg::TriggerGates_t TriggerGates_t
Type of sets of trigger gates.
Assembles the topology of trigger windows.
auto sortBy(BIter begin, EIter end, Key key, Sorter sorter={})
Returns a vectors to pointers to coll elements, sorted by key.
Encapsulate the construction of a single cyostat.
std::vector< InputTriggerGate_t > TriggerGates_t
A list of trigger gates from input.
static WindowChannelColl_t extractGateChannels(TriggerGates_t const &gates)
Extracts the channel ID from a collection of gates.
Definition of util::enumerate().
A wrapper to trigger gate objects tracking the input of operations.
Helper class to compute the middle point in a point set.
bool isValid
Whether this ID points to a valid element.
Geometry information for a single TPC.
CryostatID_t Cryostat
Index of cryostat.
std::vector< TriggerGates_t > TriggerGatesPerCryostat_t
Type of lists of gates, one list per cryostat (outer index: cryostat no).
void GetCenter(double *xyz, double localz=0.0) const
Information about composition and topology of trigger sliding windows.
icarus::trigger::WindowTopologyAlg::TriggerGatesPerCryostat_t TriggerGatesPerCryostat_t
Type of sets of trigger gates, grouped by cryostat.
std::vector< WindowChannels_t > WindowChannelColl_t
All channels in many gates (one list per gate).
Geometry information for a single cryostat.
Information of a single window.
void add(Point const &p)
Accumulates a point.
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Access the description of detector geometry.
WindowTopologyAlg(geo::GeometryCore const &geom, std::string const &logCategory="WindowTopologyAlg")
Constructor.
WindowChannelMap emplaceAndDumpMap(Args &&...args) const
auto end(FixedBins< T, C > const &) noexcept
auto sortCollBy(Coll &coll, Key key, Sorter sorter={})
Returns a vectors to pointers to coll elements, sorted by key.
Utilities to extend the interface of geometry vectors.
unsigned int NTPC() const
Number of TPCs in this cryostat.
std::string verifyGate(std::size_t iWindow, InputTriggerGate_t const &gate) const
constexpr CryostatID const & asCryostatID() const
Conversion to CryostatID (for convenience of notation).
WindowChannelMap createFromGates(TriggerGatesPerCryostat_t const &gates) const
Returns the topology of the windows described by the gates.
Description of geometry of one entire detector.
geo::CryostatID cryoid
Which cryostat the channels are in.
auto mag2(Vector const &v)
Return norm of the specified vector.
auto begin(FixedBins< T, C > const &) noexcept
Encapsulate the geometry of an optical detector.
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
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.
std::string to_string(WindowPattern const &pattern)
std::string verify(TriggerGatesPerCryostat_t const &gates) const
Verifies that gates match the topology current set up.
std::vector< raw::Channel_t > channels
Optical detector channels covered by this window.
WindowIndex_t index
Index of the window this information is about.
decltype(auto) channels() const
Returns the list of channels of the enclosed gate.
geo::OpDetID const & ID() const
Returns the geometry ID of this optical 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.
WindowChannelMap createFromCryostatGates(TriggerGates_t const &windowChannels, geo::CryostatGeo const &cryo) const
Returns the topology of the windows described by the gates.
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
The data type to uniquely identify a optical detector.
geo::Point_t middlePoint(BeginIter begin, EndIter end)
Returns the middle of the specified points.
Provides sortBy() class of utilities.
Encapsulate the construction of a single detector plane.
The data type to uniquely identify a cryostat.