28 #include "messagefacility/MessageLogger/MessageLogger.h"
29 #include "fhiclcpp/ParameterSet.h"
30 #include "cetlib_except/exception.h"
46 fhicl::ParameterSet getOptionalParameterSet
47 (fhicl::OptionalDelegatedParameter
const& param)
49 fhicl::ParameterSet pset;
50 param.get_if_present(pset);
58 template <
typename Coll,
typename Op>
59 auto transformCollection(Coll
const& coll, Op op) {
62 = std::decay_t<decltype(op(std::declval<typename Coll::value_type>()))>;
64 std::vector<Result_t> transformed;
67 (coll.begin(), coll.end(), std::back_inserter(transformed), op);
79 : fWirelessChannelCounts
80 (extractWirelessChannelParams(config.WirelessChannels()))
81 , fSorter(getOptionalParameterSet(config.Sorter))
91 mf::LogInfo(
"ICARUSChannelMapAlg")
92 <<
"Initializing ICARUSChannelMapAlg channel mapping algorithm.";
98 MF_LOG_TRACE(
"ICARUSChannelMapAlg")
99 <<
"ICARUSChannelMapAlg::Initialize() completed.";
107 fReadoutMapInfo.clear();
109 fChannelToWireMap.clear();
123 assert(!fPlaneInfo.empty());
128 std::vector<geo::WireID> AllSegments;
134 = fChannelToWireMap.find(channel);
136 throw cet::exception(
"Geometry")
137 <<
"icarus::ICARUSChannelMapAlg::ChannelToWire(" << channel
138 <<
"): invalid channel requested (must be lower than "
139 << Nchannels() <<
")\n";
150 AllSegments.reserve(planes.size());
154 ChannelRange_t const& channelRange = fPlaneInfo[pid].channelRange();
156 if (!channelRange.
contains(channel))
continue;
157 AllSegments.emplace_back
158 (pid, static_cast<geo::WireID::WireID_t>(channel - channelRange.
begin()));
170 return fChannelToWireMap.nChannels();
180 = fChannelToWireMap.find(ropid);
193 cet::exception
e(
"ICARUSChannelMapAlg");
194 e <<
"ICARUSChannelMapAlg does not support `WireCoordinate()` call."
195 "\nPlease update calling software to use geo::PlaneGeo::WireCoordinate()`:"
212 cet::exception
e(
"ICARUSChannelMapAlg");
213 e <<
"ICARUSChannelMapAlg does not support `NearestWireID()` call."
214 "\nPlease update calling software to use geo::PlaneGeo::NearestWireID()`:"
227 return fPlaneInfo[wireID].firstChannel() + wireID.
Wire;
238 cet::exception
e(
"ICARUSChannelMapAlg");
239 e <<
"ICARUSChannelMapAlg does not support `PlaneIDs()` call."
240 "\nPlease update calling software to use geo::GeometryCore::IteratePlanes()`"
254 return HasCryostat(cryoid)? TPCsetCount(cryoid): 0U;
261 assert(fReadoutMapInfo);
262 return fReadoutMapInfo.MaxTPCsets();
273 HasCryostat(tpcsetid)? (tpcsetid.
TPCset < TPCsetCount(tpcsetid)):
false;
289 std::vector<geo::TPCID>
TPCs;
290 if (!tpcsetid)
return TPCs;
292 auto const& TPClist = TPCsetTPCs(tpcsetid);
293 TPCs.reserve(TPClist.size());
294 std::transform(TPClist.begin(), TPClist.end(), std::back_inserter(TPCs),
305 if (!tpcsetid)
return {};
307 auto const& TPClist = TPCsetTPCs(tpcsetid);
308 return TPClist.empty()?
geo::TPCID{}: TPClist.front()->ID();
317 return HasTPCset(tpcsetid)? ROPcount(tpcsetid): 0U;
323 assert(fReadoutMapInfo);
324 return fReadoutMapInfo.MaxROPs();
329 return HasTPCset(ropid)? (ropid.
ROP < ROPcount(ropid)):
false;
357 std::vector<geo::PlaneID> Planes;
358 if (!ropid)
return Planes;
360 auto const& PlaneList = ROPplanes(ropid);
361 Planes.reserve(PlaneList.size());
362 std::transform(PlaneList.begin(), PlaneList.end(), std::back_inserter(Planes),
373 std::vector<geo::TPCID>
TPCs;
374 if (!ropid)
return TPCs;
387 auto const& PlaneList = ROPplanes(ropid);
388 TPCs.reserve(PlaneList.size());
389 std::transform(PlaneList.begin(), PlaneList.end(), std::back_inserter(TPCs),
402 = fChannelToWireMap.find(channel);
413 = fChannelToWireMap.find(ropid);
422 if (!ropid)
return {};
424 return planes.empty()?
geo::PlaneID{}: planes.front()->ID();
432 assert(fReadoutMapInfo);
433 return cryoid.
Cryostat < fReadoutMapInfo.NCryostats();
445 assert(fReadoutMapInfo);
446 assert(!Cryostats.empty());
451 assert(fPlaneInfo.empty());
452 std::array<unsigned int, 3U> maxSizes
453 = geo::details::extractMaxGeometryElements<3U>(Cryostats);
455 fPlaneInfo.resize(maxSizes[0U], maxSizes[1U], maxSizes[2U]);
476 auto const& TPCsetChannelCounts
477 = fWirelessChannelCounts.at(sid.TPCset & 1);
483 mf::LogTrace log(
"ICARUSChannelMapAlg");
486 auto const planeType = findPlaneType(rid);
487 log <<
"ROP: " << rid
488 <<
" (plane type: " << PlaneTypeName(planeType) <<
")";
490 auto const& WirelessChannelCounts
491 = TPCsetChannelCounts.at(planeType);
494 log <<
" (" << planes.size() <<
" planes):";
495 assert(!planes.empty());
503 nextChannel += WirelessChannelCounts.first + (*iPlane)->Nwires();
504 fPlaneInfo[(*iPlane)->ID()] = {
506 { firstROPchannel + WirelessChannelCounts.first, nextChannel },
509 log <<
" [" << (*iPlane)->ID() <<
"] "
510 << fPlaneInfo[(*iPlane)->ID()].firstChannel()
511 <<
" -- " << fPlaneInfo[(*iPlane)->ID()].lastChannel() <<
";";
515 while (++iPlane != pend) {
541 auto const nWires = plane.
Nwires();
543 = (nextChannel - 1) - lastMatchedWireID.
Wire;
544 nextChannel = firstChannel + nWires;
546 fPlaneInfo[plane.
ID()] = { { firstChannel, nextChannel }, rid };
547 log <<
" [" << plane.
ID() <<
"] "
548 << fPlaneInfo[plane.
ID()].firstChannel() <<
" -- "
549 << fPlaneInfo[plane.
ID()].lastChannel() <<
";";
556 nextChannel += WirelessChannelCounts.second;
557 unsigned int const nChannels = nextChannel - firstROPchannel;
558 fChannelToWireMap.addROP(rid, firstROPchannel, nChannels);
560 <<
" => " << nChannels <<
" channels starting at " << firstROPchannel;
568 fChannelToWireMap.setEndChannel(nextChannel);
569 mf::LogTrace(
"ICARUSChannelMapAlg")
570 <<
"Counted " << fChannelToWireMap.nChannels() <<
" channels.";
582 auto results = builder.
run(Cryostats);
585 std::move(results).TPCsetCount(), std::move(results).TPCsetTPCs(),
586 std::move(results).ROPcount(), std::move(results).ROPplanes(),
587 std::move(results).TPCtoTPCset(), std::move(results).PlaneToROP()
606 kSecondInductionType,
611 if (planes.empty())
return kUnknownType;
612 if (
auto const planeNo = planes.front()->ID().Plane; planeNo < PlaneTypes.size())
613 return PlaneTypes[planeNo];
614 else return kUnknownType;
629 = fChannelToWireMap.find(channel);
632 switch (findPlaneType(channelInfo->
ropid)) {
633 case kFirstInductionType:
634 case kSecondInductionType:
636 case kCollectionType:
688 using namespace std::string_literals;
690 case kFirstInductionType:
return "first induction"s;
691 case kSecondInductionType:
return "second induction"s;
692 case kCollectionType:
return "collection induction"s;
693 case kUnknownType:
return "unknown"s;
geo::TPCID const & ID() const
Returns the identifier of this TPC.
virtual std::set< geo::PlaneID > const & PlaneIDs() const override
Returns a list of the plane IDs in the whole detector.
PlaneType_t findPlaneType(readout::ROPID const &ropid) const
Returns the "type" of readout plane.
readout::ROPID ropid
ID of the ROP we cover.
virtual std::vector< geo::TPCID > ROPtoTPCs(readout::ROPID const &ropid) const override
Returns a list of ID of TPCs the specified ROP spans.
fhicl::Atom< unsigned int > CollectionEvenPostChannels
ICARUSChannelMapAlg(Config const &config)
Constructor: taked a configuration object.
virtual geo::SigType_t SignalTypeForChannelImpl(raw::ChannelID_t const channel) const override
Returns the type of signal on the specified channel.
Channel mapping algorithms for ICARUS detector.
Encapsulate the construction of a single cyostat.
virtual void Initialize(geo::GeometryData_t const &geodata) override
Prepares the algorithm extracting information from the geometry.
fhicl::Atom< unsigned int > SecondInductionOddPreChannels
fhicl::Atom< unsigned int > FirstInductionPreChannels
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.
void buildReadoutPlanes(geo::GeometryData_t::CryostatList_t const &Cryostats)
Fills information about the TPC set and readout plane structure.
geo::TPCDataContainer< readout::TPCsetID > const & TPCtoTPCset() const
The TPC set including each TPC.
std::size_t PlaneType_t
Type for plane type identifier.
virtual geo::PlaneID FirstWirePlaneInROP(readout::ROPID const &ropid) const override
Returns the ID of the first plane belonging to the specified ROP.
Definition of util::enumerate().
unsigned int ROPID_t
Type for the ID number.
std::array< std::array< std::pair< unsigned int, unsigned int >, 3U >, 2U > WirelessChannelCounts_t
virtual double WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeID) const override
Returns the index of the wire nearest to the specified position.
virtual readout::ROPID WirePlaneToROP(geo::PlaneID const &planeid) const override
Returns the ID of the ROP planeid belongs to, or invalid if none.
unsigned short TPCsetID_t
Type for the ID number.
BEGIN_PROLOG opflashtpc1 TPCs
The data type to uniquely identify a Plane.
virtual std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t channel) const override
Returns a collection of ID of wires connected to the channel.
Class identifying a set of TPC sharing readout channels.
std::vector< geo::CryostatGeo > CryostatList_t
Type of list of cryostats.
virtual unsigned int NTPCsets(readout::CryostatID const &cryoid) const override
Returns the total number of TPC sets in the specified cryostat.
CryostatID_t Cryostat
Index of cryostat.
virtual raw::ChannelID_t FirstChannelInROP(readout::ROPID const &ropid) const override
Returns the ID of the first channel in the specified readout plane.
constexpr raw::ChannelID_t begin() const
Returns the ID of the first channel in the range.
WireID_t Wire
Index of the wire within its plane.
CryostatList_t cryostats
The detector cryostats.
virtual bool HasTPCset(readout::TPCsetID const &tpcsetid) const override
Geometry information for a single cryostat.
virtual unsigned int MaxTPCsets() const override
Returns the largest number of TPC sets any cryostat in the detector has.
virtual bool HasROP(readout::ROPID const &ropid) const override
virtual geo::WireID NearestWireID(const TVector3 &worldPos, geo::PlaneID const &planeID) const override
Returns the ID of the wire nearest to the specified position.
static WirelessChannelCounts_t extractWirelessChannelParams(Config::WirelessChannelStruct const ¶ms)
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
fhicl::Atom< unsigned int > CollectionOddPreChannels
fhicl::Atom< unsigned int > CollectionEvenPreChannels
virtual unsigned int MaxROPs() const override
Returns the largest number of ROPs a TPC set in the detector has.
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
fhicl::Atom< unsigned int > CollectionOddPostChannels
then echo ***************************************echo array
ROPID_t ROP
Index of the readout plane within its TPC set.
geo::WireID NearestWireID(geo::Point_t const &pos) const
Returns the ID of wire closest to the specified position.
Signal from induction planes.
bool HasCryostat(readout::CryostatID const &cryoid) const
Returns whether the specified cryostat is known to the mapping.
Definitions of geometry vector data types.
enum geo::_plane_sigtype SigType_t
virtual unsigned int NROPs(readout::TPCsetID const &tpcsetid) const override
Returns the total number of readout planes in the specified TPC set.
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
constexpr bool isValidChannelID(raw::ChannelID_t channel)
Algorithm discovering TPC sets and readout planes for ICARUS.
Test of util::counter and support utilities.
The data type to uniquely identify a TPC.
Class identifying a set of planes sharing readout channels.
virtual raw::ChannelID_t PlaneWireToChannel(geo::WireID const &wireID) const override
Returns the channel ID a wire is connected to.
virtual geo::TPCID FirstTPCinTPCset(readout::TPCsetID const &tpcsetid) const override
Returns the ID of the first TPC belonging to the specified TPC set.
TPCsetID_t TPCset
Index of the TPC set within its cryostat.
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.
fhicl::Atom< unsigned int > SecondInductionEvenPreChannels
Extracts TPC sets and readout planes from a list of cryostats.
A simple range of channels.
raw::ChannelID_t firstChannel
First channel in ROP.
Functions to help debugging by instrumenting code.
Encapsulate the construction of a single detector plane.
constexpr bool contains(raw::ChannelID_t channel) const
Returns whether this range includes the specified channel.
std::string to_string(WindowPattern const &pattern)
then echo File list $list not found else cat $list while read file do echo $file sed s
geo::PlaneID const & ID() const
Returns the identifier of this plane.
unsigned int Nwires() const
Number of wires in this plane.
Functions pulling in STL customization if available.
fhicl::Atom< unsigned int > SecondInductionOddPostChannels
void fillChannelToWireMap(geo::GeometryData_t::CryostatList_t const &Cryostats)
Fills the information about readout channel mapping.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Results_t run(geo::GeometryData_t::CryostatList_t const &Cryostats)
Runs the algorithm as configured from start to end.
void GetCenter(double *xyz, double localz=0.0) const
Fills the world coordinate of a point on the wire.
Data in the geometry description.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
void printBacktrace(Stream &&out, BacktracePrintOptions options)
Prints the full backtrace into a stream.
Containers to hold one datum per TPC set or readout plane.
const WireGeo & LastWire() const
Return the last wire in the plane.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
icarus::details::PlaneColl_t PlaneColl_t
virtual readout::ROPID ChannelToROP(raw::ChannelID_t channel) const override
Returns the ID of the ROP the channel belongs to (invalid if none).
fhicl::Atom< unsigned int > SecondInductionEvenPostChannels
virtual unsigned int Nchannels() const override
Returns the number of readout channels (ID's go 0 to Nchannels()).
static std::string PlaneTypeName(PlaneType_t planeType)
Returns the name of the specified plane type.
Encapsulate the construction of a single detector plane.
The data type to uniquely identify a cryostat.
virtual void Uninitialize() override
Frees the resources of this algorithm.
Signal from collection planes.
fhicl::Atom< unsigned int > FirstInductionPostChannels