ColdBoxChannelMapAlg.cxx
Go to the documentation of this file.
1 /*!
2  * \file ColdBoxChannelMapAlg.h
3  * \brief Channel mapping algorithms for VD ColdBox CRP.
4  * \details Adapted from ICARUSChannelMapAlg by G. Petrillo
5  * \date October 25, 2021
6  * \warning Only one CRP is currently supported with 48 deg ind1
7  *
8  * vgalymov@ipnl.in2p3.fr
9  */
10 
11 
12 // LArSoft libraries
20 #include "larcorealg/CoreUtils/DebugUtils.h" // lar::debug::printBacktrace()
21 #include "larcorealg/CoreUtils/StdUtils.h" // util::size()
23 
24 // framework libraries
26 #include "fhiclcpp/ParameterSet.h"
27 #include "cetlib_except/exception.h" // cet::exception
28 
29 // C/C++ libraries
30 #include <vector>
31 #include <array>
32 #include <set>
33 #include <algorithm> // std::transform(), std::find()
34 #include <utility> // std::move()
35 #include <iterator> // std::back_inserter()
36 #include <functional> // std::mem_fn()
37 #include <tuple>
38 
39 #include "ColdBoxChannelMapAlg.h"
40 
42 /*
43 namespace {
44 
45  // ---------------------------------------------------------------------------
46  fhicl::ParameterSet getOptionalParameterSet
47  (fhicl::OptionalDelegatedParameter const& param)
48  {
49  fhicl::ParameterSet pset; // empty by default
50  param.get_if_present(pset);
51  return pset;
52  }
53 }
54 
55 // -----------------------------------------------------------------------------
56 geo::ColdBoxChannelMapAlg::ColdBoxChannelMapAlg(Config const& config):
57  fSorter(geo::GeoObjectSorterCRU(getOptionalParameterSet(config.Sorter)))
58 {}
59 */
60 // -----------------------------------------------------------------------------
62  fSorter(geo::GeoObjectSorterCRU(p))
63 {}
64 
65 
66 // -----------------------------------------------------------------------------
68 {
69  mf::LogInfo("ColdBoxChannelMapAlg")
70  << "Initializing ColdBoxChannelMapAlg channel mapping algorithm.";
71 
74 
75  MF_LOG_TRACE("ColdBoxChannelMapAlg")
76  << "ColdBoxChannelMapAlg::Initialize() completed.";
77 } // geo::ColdBoxChannelMapAlg::Initialize()
78 
79 
80 // -----------------------------------------------------------------------------
82 
85  fPlaneInfo.clear();
86 
87 } // geo::ColdBoxChannelMapAlg::Uninitialize()
88 
89 
90 //------------------------------------------------------------------------------
91 std::vector<geo::WireID> geo::ColdBoxChannelMapAlg::ChannelToWire
93 {
94  //
95  // input check
96  //
97  assert(!fPlaneInfo.empty());
98 
99  //
100  // output
101  //
102  std::vector<geo::WireID> AllSegments;
103 
104  //
105  // find the ROP with that channel
106  //
107  ChannelToWireMap::ChannelsInROPStruct const* channelInfo
108  = fChannelToWireMap.find(channel);
109  if (!channelInfo) {
110  throw cet::exception("Geometry")
111  << "geo::ColdBoxChannelMapAlg::ChannelToWire(" << channel
112  << "): invalid channel requested (must be lower than "
113  << Nchannels() << ")\n";
114  }
115 
116  //
117  // find the wire planes in that ROP
118  //
119  PlaneColl_t const& planes = ROPplanes(channelInfo->ropid);
120 
121  //
122  // associate one wire for each of those wire planes to the channel
123  //
124  AllSegments.reserve(planes.size()); // this is sometimes (often?) too much
125  for (auto const pid: planes) {
126 
127  //geo::PlaneID const& pid = plane->ID();
128  ChannelRange_t const& channelRange = fPlaneInfo[pid].channelRange();
129 
130  if (!channelRange.contains(channel)) continue;
131  AllSegments.emplace_back
132  (pid, static_cast<geo::WireID::WireID_t>(channel - channelRange.begin()));
133 
134  } // for planes in ROP
135 
136  return AllSegments;
137 
138 } // geo::ColdBoxChannelMapAlg::ChannelToWire()
139 
140 
141 //------------------------------------------------------------------------------
143 
144  return fChannelToWireMap.nChannels();
145 } // geo::ColdBoxChannelMapAlg::Nchannels()
146 
147 
148 //------------------------------------------------------------------------------
150  (readout::ROPID const& ropid) const
151 {
152  ChannelToWireMap::ChannelsInROPStruct const* ROPinfo
153  = fChannelToWireMap.find(ropid);
154  return ROPinfo? ROPinfo->nChannels: 0U;
155 } // geo::ColdBoxChannelMapAlg::Nchannels(ROPID)
156 
157 
158 //------------------------------------------------------------------------------
160  (double YPos, double ZPos, geo::PlaneID const& planeID) const
161 {
162  /*
163  * this should NOT be called... it shouldn't be here at all!
164  */
165 
166  cet::exception e("ColdBoxChannelMapAlg");
167  e << "ColdBoxChannelMapAlg does not support `WireCoordinate()` call."
168  "\nPlease update calling software to use geo::PlaneGeo::WireCoordinate()`:"
169  "\n";
170 
171  //lar::debug::printBacktrace(e, 4U);
172 
173  throw e;
174 } // geo::ColdBoxChannelMapAlg::WireCoordinate()
175 
176 
177 //------------------------------------------------------------------------------
179  (const TVector3& worldPos, geo::PlaneID const& planeID) const
180 {
181  /*
182  * this should NOT be called... it shouldn't be here at all!
183  */
184 
185  cet::exception e("ColdBoxChannelMapAlg");
186  e << "ColdBoxChannelMapAlg does not support `NearestWireID()` call."
187  "\nPlease update calling software to use geo::PlaneGeo::NearestWireID()`:"
188  "\n";
189 
190  //lar::debug::printBacktrace(e, 3U);
191 
192  throw e;
193 } // geo::ColdBoxChannelMapAlg::NearestWireID()
194 
195 
196 //------------------------------------------------------------------------------
198  (geo::WireID const& wireID) const
199 {
200  return fPlaneInfo[wireID].firstChannel() + wireID.Wire;
201 } // geo::ColdBoxChannelMapAlg::PlaneWireToChannel()
202 
203 
204 //------------------------------------------------------------------------------
205 std::set<geo::PlaneID> const& geo::ColdBoxChannelMapAlg::PlaneIDs() const {
206 
207  /*
208  * this should NOT be called... it shouldn't be here at all!
209  */
210 
211  cet::exception e("ColdBoxChannelMapAlg");
212  e << "ColdBoxChannelMapAlg does not support `PlaneIDs()` call."
213  "\nPlease update calling software to use geo::GeometryCore::IteratePlanes()`"
214  "\n";
215 
216  //lar::debug::printBacktrace(e, 3U);
217 
218  throw e;
219 
220 } // geo::ColdBoxChannelMapAlg::PlaneIDs()
221 
222 
223 //------------------------------------------------------------------------------
225  (readout::CryostatID const& cryoid) const
226 {
227  return HasCryostat(cryoid)? TPCsetCount(cryoid): 0U;
228 } // geo::ColdBoxChannelMapAlg::NTPCsets()
229 
230 
231 //------------------------------------------------------------------------------
232 /// Returns the largest number of TPC sets any cryostat in the detector has
234  assert(fReadoutMapInfo);
235  return fReadoutMapInfo.MaxTPCsets();
236 } // geo::ColdBoxChannelMapAlg::MaxTPCsets()
237 
238 
239 //------------------------------------------------------------------------------
240 /// Returns whether we have the specified TPC set
241 /// @return whether the TPC set is valid and exists
243  (readout::TPCsetID const& tpcsetid) const
244 {
245  return
246  HasCryostat(tpcsetid)? (tpcsetid.TPCset < TPCsetCount(tpcsetid)): false;
247 } // geo::ColdBoxChannelMapAlg::HasTPCset()
248 
249 
250 //------------------------------------------------------------------------------
252  (geo::TPCID const& tpcid) const
253 {
254  return tpcid? TPCtoTPCset()[tpcid]: readout::TPCsetID{};
255 } // geo::ColdBoxChannelMapAlg::TPCtoTPCset()
256 
257 
258 //------------------------------------------------------------------------------
259 std::vector<geo::TPCID> geo::ColdBoxChannelMapAlg::TPCsetToTPCs
260  (readout::TPCsetID const& tpcsetid) const
261 {
262  std::vector<geo::TPCID> TPCs;
263  if (!tpcsetid) return TPCs;
264 
265  return TPCsetTPCs(tpcsetid);
266 } // geo::ColdBoxChannelMapAlg::TPCsetToTPCs()
267 
268 
269 //------------------------------------------------------------------------------
271  (readout::TPCsetID const& tpcsetid) const
272 {
273  if (!tpcsetid) return {};
274 
275  auto const& TPClist = TPCsetTPCs(tpcsetid);
276  return TPClist.empty()? geo::TPCID{}: TPClist.front();
277 
278 } // geo::ColdBoxChannelMapAlg::FirstTPCinTPCset()
279 
280 
281 //------------------------------------------------------------------------------
283  (readout::TPCsetID const& tpcsetid) const
284 {
285  return HasTPCset(tpcsetid)? ROPcount(tpcsetid): 0U;
286 } // geo::ColdBoxChannelMapAlg::NROPs()
287 
288 
289 //------------------------------------------------------------------------------
291  assert(fReadoutMapInfo);
292  return fReadoutMapInfo.MaxROPs();
293 } // geo::ColdBoxChannelMapAlg::MaxROPs()
294 
295 //------------------------------------------------------------------------------
297  return HasTPCset(ropid)? (ropid.ROP < ROPcount(ropid)): false;
298 } // geo::ColdBoxChannelMapAlg::HasROP()
299 
300 
301 //------------------------------------------------------------------------------
302  /**
303  * @brief Returns the ID of the ROP planeid belongs to, or invalid if none
304  * @param planeid ID of the plane
305  * @return the ID of the corresponding ROP, or invalid ID when planeid is
306  *
307  * In this mapping, readout planes and wire planes are mapped one-to-one.
308  * The returned value mirrors the plane ID in the readout space.
309  * If the plane ID is not valid, an invalid readout plane ID is returned.
310  * Note that this check is performed on the validity of the plane ID, that
311  * does not necessarily imply that the plane specified by the ID actually
312  * exists.
313  */
315  (geo::PlaneID const& planeid) const
316 {
317  return planeid? PlaneToROP(planeid): readout::ROPID{};
318  //return planeid?fReadoutMapInfo.fPlaneToROP[planeid]:readout::ROPID{};
319 } // geo::ColdBoxChannelMapAlg::WirePlaneToROP()
320 
321 
322 //------------------------------------------------------------------------------
323 std::vector<geo::PlaneID> geo::ColdBoxChannelMapAlg::ROPtoWirePlanes
324  (readout::ROPID const& ropid) const
325 {
326  std::vector<geo::PlaneID> Planes;
327  if (!ropid) return Planes;
328  return ROPplanes(ropid);
329 } // geo::ColdBoxChannelMapAlg::ROPtoWirePlanes()
330 
331 
332 //------------------------------------------------------------------------------
333 std::vector<geo::TPCID> geo::ColdBoxChannelMapAlg::ROPtoTPCs
334  (readout::ROPID const& ropid) const
335 {
336  std::vector<geo::TPCID> TPCs;
337  if (!ropid) return TPCs;
338 
339  auto const& PlaneList = ROPplanes(ropid);
340  TPCs.reserve(PlaneList.size());
341  for( auto const pid : PlaneList ){
342  TPCs.push_back( pid );
343  }
344 
345  return TPCs;
346 } // geo::ColdBoxChannelMapAlg::ROPtoTPCs()
347 
348 
349 //------------------------------------------------------------------------------
351  (raw::ChannelID_t channel) const
352 {
353  if (!raw::isValidChannelID(channel)) return {};
354 
355  ChannelToWireMap::ChannelsInROPStruct const* info
356  = fChannelToWireMap.find(channel);
357  return info? info->ropid: readout::ROPID{};
358 } // geo::ColdBoxChannelMapAlg::ChannelToROP()
359 
360 
361 //------------------------------------------------------------------------------
363  (readout::ROPID const& ropid) const
364 {
365  if (!ropid) return raw::InvalidChannelID;
366 
367  ChannelToWireMap::ChannelsInROPStruct const* info
368  = fChannelToWireMap.find(ropid);
369  return info? info->firstChannel: raw::InvalidChannelID;
370 } // geo::ColdBoxChannelMapAlg::FirstChannelInROP()
371 
372 
373 //------------------------------------------------------------------------------
375  (readout::ROPID const& ropid) const
376 {
377  if (!ropid) return {};
378  PlaneColl_t const& planes = ROPplanes(ropid);
379  return planes.empty()? geo::PlaneID{}: planes.front();
380 } // geo::ColdBoxChannelMapAlg::FirstWirePlaneInROP()
381 
382 
383 //------------------------------------------------------------------------------
385  (readout::CryostatID const& cryoid) const
386 {
387  assert(fReadoutMapInfo);
388  return cryoid.Cryostat < fReadoutMapInfo.NCryostats();
389 } // geo::ColdBoxChannelMapAlg::HasCryostat()
390 
391 
392 //------------------------------------------------------------------------------
395 {
396 
397  //
398  // input check
399  //
400  assert(fReadoutMapInfo);
401  assert(!Cryostats.empty());
402 
403  //mf::LogInfo("ColdBoxChannelMapAlg")<<"fillChannelToWireMap\n";
404  //
405  // output setup
406  //
407  assert(fPlaneInfo.empty());
408  std::array<unsigned int, 3U> maxSizes
409  = geo::details::extractMaxGeometryElements<3U>(Cryostats);
410 
411  fPlaneInfo.resize(maxSizes[0U], maxSizes[1U], maxSizes[2U]);
412 
413  raw::ChannelID_t nextChannel = 0; // next available channel
414  for (geo::CryostatGeo const& cryo: Cryostats) {
415 
416  readout::CryostatID const cid { cryo.ID() };
417 
418  auto const nTPCsets
419  = static_cast<readout::TPCsetID::TPCsetID_t>(TPCsetCount(cid));
420 
422 
423  readout::TPCsetID const sid { cid, s };
424  auto const nROPs = static_cast<readout::ROPID::ROPID_t>(ROPcount(sid));
425 
426  for (readout::ROPID::ROPID_t r: util::counter(nROPs)) {
427 
428  mf::LogTrace log("ColdBoxChannelMapAlg");
429 
430  readout::ROPID const rid { sid, r };
431  auto const planeType = findPlaneType(rid);
432  log << "ROP: " << rid
433  << " (plane type: " << PlaneTypeName(planeType) << ")";
434 
435  PlaneColl_t const& plane_ids = ROPplanes(rid);
436  assert(!plane_ids.empty());
437  log << " (" << plane_ids.size() << " planes):";
438 
439  std::vector<geo::PlaneGeo const*> planes;
440  planes.reserve( plane_ids.size() );
441  for( auto const pid : plane_ids ){
442  planes.push_back( cryo.TPC( pid ).PlanePtr( pid ) );
443  }
444 
445  raw::ChannelID_t const firstROPchannel = nextChannel;
446 
447  auto iPlane = util::begin(planes);
448  auto const pend = util::end(planes);
449 
450  // assign available channels to all wires of the first plane
451  nextChannel += (*iPlane)->Nwires();
452  fPlaneInfo[(*iPlane)->ID()] = {
453  ChannelRange_t{ firstROPchannel, nextChannel }, rid };
454  log << " [" << (*iPlane)->ID() << "] "
455  << fPlaneInfo[(*iPlane)->ID()].firstChannel()
456  << " -- " << fPlaneInfo[(*iPlane)->ID()].lastChannel() << ";";
457 
458  geo::Point_t lastWirePos = (*iPlane)->LastWire().GetCenter<geo::Point_t>();
459 
460  while (++iPlane != pend) {
461 
462  geo::PlaneGeo const& plane = **iPlane;
463 
464  // find out which wire matches the last wire from the previous plane;
465  // if there is no such wire, an exception will be thrown,
466  // which is ok to us since we believe it should not happen.
467  geo::WireID const lastMatchedWireID
468  = plane.NearestWireID(lastWirePos);
469 
470  /*
471  mf::LogTrace("ColdBoxChannelMapAlg")
472  << (*std::prev(iPlane))->ID() << " W:" << ((*std::prev(iPlane))->Nwires() - 1)
473  << " ending at " << (*std::prev(iPlane))->LastWire().GetEnd<geo::Point_t>()
474  << " matched " << lastMatchedWireID
475  << " which starts at " << plane.Wire(lastMatchedWireID).GetStart<geo::Point_t>()
476  ;
477  */
478 
479  // For ROP = 0 (1st induction)
480  // the first channel in this plane (`iPlane`) is the one associated
481  // to the first wire in the plane, which has local wire number `0`;
482  // the last channel from the previous plane (`nextChannel - 1`)
483  // is associated to the matched wire (`lastMatchedWireID`),
484  // which has some wire number (`lastMatchedWireID.Wire`).
485  //
486  auto const nWires = plane.Nwires();
487  raw::ChannelID_t const firstChannel =
488  (r == 0)?((nextChannel - 1) - lastMatchedWireID.Wire):nextChannel;
489 
490  nextChannel = firstChannel + nWires;
491 
492  fPlaneInfo[plane.ID()] = { { firstChannel, nextChannel }, rid };
493  log << " [" << plane.ID() << "] "
494  << fPlaneInfo[plane.ID()].firstChannel() << " -- "
495  << fPlaneInfo[plane.ID()].lastChannel() << ";";
496 
497  // update for the next iteration
498  lastWirePos = plane.LastWire().GetCenter<geo::Point_t>();
499 
500  } // while
501 
502  unsigned int const nChannels = nextChannel - firstROPchannel;
503  fChannelToWireMap.addROP(rid, firstROPchannel, nChannels);
504  log
505  << " => " << nChannels << " channels starting at " << firstROPchannel;
506 
507  } // for readout plane
508 
509  } // for TPC set
510 
511  } // for cryostat
512 
513  fChannelToWireMap.setEndChannel(nextChannel);
514  mf::LogInfo("ColdBoxChannelMapAlg")
515  << "Counted " << fChannelToWireMap.nChannels() << " channels.";
516 
517 } // geo::ColdBoxChannelMapAlg::fillChannelToWireMap()
518 
519 
520 // -----------------------------------------------------------------------------
523 {
524  auto const [ NCryostats, MaxTPCs, MaxPlanes ]
525  = geo::details::extractMaxGeometryElements<3U>(Cryostats);
526 
527  //mf::LogInfo("ColdBoxChannelMapAlg")
528  //<< "Build readout planes for "<<NCryostats<<" "<<MaxTPCs<<" "<<MaxPlanes<<"\n";
529 
530 
531  if( Cryostats.size() > 1 ){
532  throw cet::exception("Geometry")
533  << "geo::ColdBoxChannelMapAlg::buildReadoutPlanes " << Cryostats.size()
534  << ": more than one cryostat is currently not supported\n";
535  }
536 
537  if( Cryostats[0].NTPC() != 4 ){
538  throw cet::exception("Geometry")
539  << "geo::ColdBoxChannelMapAlg::buildReadoutPlanes " << Cryostats[0].NTPC()
540  << ": more than four TPCs is currently not supported\n";
541  }
542 
543  // currently do it by hand for CB --> to be generalized for FD
544  auto cryo = Cryostats[0];
545  //unsigned int MaxTPCs = cryo.NTPC();
546  //unsigned int MaxPlanes = 3;
547  unsigned int MaxROPs = 3;
548  unsigned int MaxTPCsets = MaxTPCs/2;
549  std::vector<unsigned int> TPCsetCount = {2};
550  std::vector<std::vector<const geo::TPCGeo*>> AllTPCsInTPCsets( MaxTPCsets ); // TPCs belonging to a set
551  // the standard CRU sorter is assumed (fixing this another "todo")
552  AllTPCsInTPCsets[0] = {cryo.TPCPtr(0), cryo.TPCPtr(2)};
553  AllTPCsInTPCsets[1] = {cryo.TPCPtr(1), cryo.TPCPtr(3)};
554  readout::TPCsetDataContainer<TPCColl_t> TPCsetTPCs(NCryostats, MaxTPCsets);
555 
556  for( auto&& [s, TPClist ]: util::enumerate(AllTPCsInTPCsets) ){
557  readout::TPCsetID const tpcsetid
558  { cryo.ID(), static_cast<readout::TPCsetID::TPCsetID_t>(s) };
559  //mf::LogInfo("ColdBoxChannelMapAlg")<< tpcsetid <<" "<<TPCPtrs.size()<<"\n";
560  std::vector<geo::TPCID> TPCs;
561  TPCs.reserve(TPClist.size());
562  std::transform(TPClist.begin(), TPClist.end(), std::back_inserter(TPCs),
563  std::mem_fn(&geo::TPCGeo::ID));
564 
565  TPCsetTPCs[tpcsetid] = std::move(TPCs);
566  }
567 
568  // number of readout planes in each TPC set
570  ROPcount.resize( TPCsetTPCs.dimSize<0U>(), TPCsetTPCs.dimSize<1U>(), 0U );
571 
572  // geo::PlaneGeo objects in each readout plane
574  ROPplanes.resize(TPCsetTPCs.dimSize<0U>(), TPCsetTPCs.dimSize<1U>(), MaxROPs);
575 
576  for (auto [ c, nTPCsets ]: util::enumerate(TPCsetCount)) {
577  readout::CryostatID const cryoid
578  { static_cast<readout::CryostatID::CryostatID_t>(c) };
579  for (readout::TPCsetID::TPCsetID_t s = 0; s < nTPCsets; ++s) {
580  readout::TPCsetID const tpcsetid { cryoid, s };
581  unsigned int nROP = MaxROPs;
582  ROPcount[tpcsetid] = nROP;
583 
584  auto TPCs = AllTPCsInTPCsets[s];
585  for( unsigned r = 0; r<nROP;++r ){ // assuming the number of rops == number of planes per TPC
586  // get PlaneColl_t for each set for each plane
587  PlaneColl_t planes;
588 
589  for ( const geo::TPCGeo* TPC: TPCs){
590  planes.push_back( TPC->Plane(r).ID() );
591  }
592  readout::ROPID const ropid { tpcsetid, r };
594  log << "Readout plane " << ropid << " assigned with " << planes.size()
595  << " planes:";
596  for (auto const plane: planes)
597  log << " (" << plane << ")";
598 
599  if(!ROPplanes[ropid].empty()) {
600  //
601  // If this happens, it may be that the geometry is not compatible
602  // with the algorithm, or just a bug.
603  // Enabling the debug stream will show which planes are assigned
604  // each time, including the two conflicting assignments.
605  //
607  << "Logic error: ROPID " << ropid
608  << " has already been assigned!\n";
609  }
610 
611  ROPplanes[ ropid ] = std::move( planes );
612  } // ROPs/ planes
613  } // tpcs in tpcset
614  }//cryo, TPCSets
615 
616  //
617  // the TPC set each TPC belongs to
619  TPCtoTPCset.resize( NCryostats, MaxTPCs, {});
620  for (auto c
621  : util::counter<geo::CryostatID::CryostatID_t>(TPCsetTPCs.dimSize<0>())){
622 
623  geo::CryostatID const cid { c };
624  for (auto s: util::counter<readout::TPCsetID::TPCsetID_t>(TPCsetTPCs.dimSize<1>()))
625  {
626  readout::TPCsetID const sid { cid, s };
627  for (auto const TPCid: TPCsetTPCs[sid]) {
628  TPCtoTPCset[TPCid] = sid;
629  MF_LOG_TRACE(fLogCategory) << TPCid << " => " << sid;
630  } // for TPCs in TPC set
631  } // for TPC sets in cryostat
632  } // for cryostats
633 
634  // ROP each wire belongs to
636  PlaneToROP.resize( NCryostats, MaxTPCs, MaxPlanes, {} );
637  for (auto c
638  : util::counter<geo::CryostatID::CryostatID_t>(ROPplanes.dimSize<0>())
639  )
640  {
641  geo::CryostatID const cid { c };
642  for (auto s: util::counter<readout::TPCsetID::TPCsetID_t>(ROPplanes.dimSize<1>()))
643  {
644  readout::TPCsetID const sid { cid, s };
645  for (auto r: util::counter<readout::ROPID::ROPID_t>(ROPplanes.dimSize<2>()))
646  {
647  readout::ROPID const rid { sid, r };
648  for (auto const plane: ROPplanes[rid]) {
649  //assert(plane && plane->ID());
650  PlaneToROP[plane] = rid;
651  MF_LOG_TRACE(fLogCategory) << plane << " => " << rid;
652  } // for planes in readout plane
653  } // for readout planes in TPC set
654  } // for TPC sets in cryostat
655  } // for cryostats
656 
657  // copy to ReadoutMapInfo struct
659  std::move(TPCsetCount), std::move(TPCsetTPCs),
660  std::move(ROPcount), std::move(ROPplanes),
661  std::move(TPCtoTPCset), std::move(PlaneToROP)
662  );
663 } // geo::ColdBoxChannelMapAlg::buildReadoutPlanes()
664 
665 
666 // -----------------------------------------------------------------------------
668 {
669  /*
670  * This implementation is very fragile, relying on the fact that the first
671  * induction plane numbers are `kFirstInductionType`, the second induction
672  * plane numbers are `kSecondInductionType` and the collection plane numbers
673  * are `kCollectionType`. This assumption is not checked anywhere.
674  *
675  */
676  constexpr std::array PlaneTypes = { // let's C++ figure out type and size
677  kFirstInductionType, // P:0
678  kSecondInductionType, // P:1
679  kCollectionType // P:2
680  };
681 
682  PlaneColl_t const& planes = ROPplanes(rid);
683  //std::cout<<"findPlaneType: "<<rid<<" "<<planes.size()<<" @ "<<planes.front()
684  //<<" "<<planes.front()->ID().Plane<<"\n";
685  //for (geo::PlaneGeo const* plane: planes)
686  //std::cout <<" (" << plane->ID() << ")";
687  //std::cout<<"\n";
688 
689  if (planes.empty()) return kUnknownType;
690  if (auto const planeNo = planes.front().Plane; planeNo < PlaneTypes.size())
691  return PlaneTypes[planeNo];
692  else return kUnknownType;
693 
694 } // geo::ColdBoxChannelMapAlg::findPlaneType()
695 
696 
697 // ----------------------------------------------------------------------------
699  (raw::ChannelID_t const channel) const
700 {
701  ChannelToWireMap::ChannelsInROPStruct const* channelInfo
702  = fChannelToWireMap.find(channel);
703  if (!channelInfo) return geo::kMysteryType;
704 
705  switch (findPlaneType(channelInfo->ropid)) {
706  case kFirstInductionType:
708  return geo::kInduction;
709  case kCollectionType:
710  return geo::kCollection;
711  default:
712  return geo::kMysteryType;
713  } // switch
714 
715  return geo::kMysteryType;
716 } // geo::ColdBoxChannelMapAlg::SignalTypeForChannelImpl()
717 
718 
719 // ----------------------------------------------------------------------------
721 
722  using namespace std::string_literals;
723  switch (planeType) {
724  case kFirstInductionType: return "first induction"s;
725  case kSecondInductionType: return "second induction"s;
726  case kCollectionType: return "collection induction"s;
727  case kUnknownType: return "unknown"s;
728  default:
729  return "unsupported ("s + std::to_string(planeType) + ")"s;
730  } // switch
731 
732 } // geo::ColdBoxChannelMapAlg::PlaneTypeName()
733 
734 
735 // ----------------------------------------------------------------------------
736 
geo::TPCID const & ID() const
Returns the identifier of this TPC.
Definition: TPCGeo.h:333
virtual geo::TPCID FirstTPCinTPCset(readout::TPCsetID const &tpcsetid) const override
Returns the ID of the first TPC belonging to the specified TPC set.
readout::TPCsetDataContainer< TPCColl_t > const & TPCsetTPCs() const
All geo::TPCGeo objects in each TPC set.
virtual unsigned int NROPs(readout::TPCsetID const &tpcsetid) const override
Returns the total number of readout planes in the specified TPC set.
virtual raw::ChannelID_t FirstChannelInROP(readout::ROPID const &ropid) const override
Returns the ID of the first channel in the specified readout plane.
void addROP(readout::ROPID const &rid, raw::ChannelID_t firstROPchannel, unsigned int nChannels)
void clear()
Frees the memory and leaves the object unusable until next set().
unsigned int nChannels() const
Returns the number of mapped channels.
virtual void Uninitialize() override
Frees the resources of this algorithm.
Who knows?
Definition: geo_types.h:147
Encapsulate the construction of a single cyostat.
Definition of util::enumerate().
readout::ROPID ropid
ID of the ROP we cover.
std::string string
Definition: nybbler.cc:12
void clear()
Resets the data of the map to like just constructed.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
PlaneType_t findPlaneType(readout::ROPID const &ropid) const
Returns the "type" of readout plane.
virtual std::vector< geo::TPCID > ROPtoTPCs(readout::ROPID const &ropid) const override
Returns a list of ID of TPCs the specified ROP spans.
unsigned int ROPID_t
Type for the ID number.
virtual raw::ChannelID_t PlaneWireToChannel(geo::WireID const &wireID) const override
Returns the channel ID a wire is connected to.
unsigned short TPCsetID_t
Type for the ID number.
Definition: readout_types.h:71
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
Geometry information for a single TPC.
Definition: TPCGeo.h:38
Class identifying a set of TPC sharing readout channels.
Definition: readout_types.h:70
std::vector< unsigned int > const & TPCsetCount() const
Returns the number of TPC sets in each cryostat.
std::vector< geo::CryostatGeo > CryostatList_t
Type of list of cryostats.
Definition: GeometryData.h:34
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
Algorithm discovering the number of elements in the geometry.
virtual std::set< geo::PlaneID > const & PlaneIDs() const override
Returns a list of the plane IDs in the whole detector.
virtual readout::ROPID WirePlaneToROP(geo::PlaneID const &planeid) const override
Returns the ID of the ROP planeid belongs to, or invalid if none.
void resize(unsigned int nCryo, unsigned int nTPCsets)
Prepares the container with default-constructed data.
static constexpr PlaneType_t kUnknownType
Identifier for unknown plane type.
virtual bool HasTPCset(readout::TPCsetID const &tpcsetid) const override
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:580
geo::PlaneDataContainer< PlaneInfo_t > fPlaneInfo
Range of channels covered by each of the wire planes.
CryostatList_t cryostats
The detector cryostats.
Definition: GeometryData.h:38
static std::string PlaneTypeName(PlaneType_t planeType)
Returns the name of the specified plane type.
uint8_t channel
Definition: CRTFragment.hh:201
Container with one element per geometry wire plane.
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
virtual geo::PlaneID FirstWirePlaneInROP(readout::ROPID const &ropid) const override
Returns the ID of the first plane belonging to the specified ROP.
Functions to help debugging by instrumenting code.
void resize(unsigned int nCryo, unsigned int nTPCs)
Prepares the container with default-constructed data.
ColdBoxChannelMapAlg(fhicl::ParameterSet const &p)
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
virtual std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t channel) const override
Returns a collection of ID of wires connected to the channel.
constexpr bool contains(raw::ChannelID_t channel) const
Returns whether this range includes the specified channel.
void resize(unsigned int nCryo, unsigned int nTPCsets, unsigned int nROPs)
Prepares the container with default-constructed data.
virtual unsigned int MaxROPs() const override
Returns the largest number of ROPs a TPC set in the detector has.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
geo::dune::vd::ChannelToWireMap fChannelToWireMap
Mapping of channels and ROP&#39;s.
virtual readout::ROPID ChannelToROP(raw::ChannelID_t channel) const override
Returns the ID of the ROP the channel belongs to (invalid if none).
bool HasCryostat(readout::CryostatID const &cryoid) const
Returns whether the specified cryostat is known to the mapping.
virtual unsigned int Nchannels() const override
Returns the number of readout channels (ID&#39;s go 0 to Nchannels()).
void buildReadoutPlanes(geo::GeometryData_t::CryostatList_t const &Cryostats)
Fills information about the TPC set and readout plane structure.
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:32
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
const double e
ROPID_t ROP
Index of the readout plane within its TPC set.
Channel mapping algorithms for VD ColdBox CRP.
geo::WireID NearestWireID(geo::Point_t const &pos) const
Returns the ID of wire closest to the specified position.
Definition: PlaneGeo.cxx:649
Signal from induction planes.
Definition: geo_types.h:145
enum geo::_plane_sigtype SigType_t
std::vector< geo::PlaneID > PlaneColl_t
def move(depos, offset)
Definition: depos.py:107
void fillChannelToWireMap(geo::GeometryData_t::CryostatList_t const &Cryostats)
Fills the information about readout channel mapping.
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:82
#define MF_LOG_TRACE(id)
void setEndChannel(raw::ChannelID_t channel)
Sets the ID of the channels after the last valid one.
p
Definition: test.py:223
constexpr bool isValidChannelID(raw::ChannelID_t channel)
Definition: RawTypes.h:37
geo::PlaneDataContainer< readout::ROPID > const & PlaneToROP() const
The readout plane including each wire plane.
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.
ReadoutMappingInfo_t fReadoutMapInfo
Information about TPC sets and readout planes in the geometry.
readout::TPCsetDataContainer< unsigned int > const & ROPcount() const
Number of readout planes in each TPC set.
Test of util::counter and support utilities.
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
static constexpr PlaneType_t kSecondInductionType
Identifier for second induction plane type.
virtual geo::WireID NearestWireID(const TVector3 &worldPos, geo::PlaneID const &planeID) const override
Returns the ID of the wire nearest to the specified position.
Class identifying a set of planes sharing readout channels.
static constexpr PlaneType_t kCollectionType
Identifier for collection plane type.
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.
TPCsetID_t TPCset
Index of the TPC set within its cryostat.
Definition: readout_types.h:90
void set(std::vector< unsigned int > &&TPCsetCount, readout::TPCsetDataContainer< TPCColl_t > &&TPCsetTPCs, readout::TPCsetDataContainer< unsigned int > &&ROPcount, readout::ROPDataContainer< PlaneColl_t > &&ROPplanes, geo::TPCDataContainer< readout::TPCsetID > &&TPCtoTPCset, geo::PlaneDataContainer< readout::ROPID > &&PlaneToROP)
readout::ROPDataContainer< PlaneColl_t > const & ROPplanes() const
All geo::PlaneGeo objects in each readout plane.
virtual bool HasROP(readout::ROPID const &ropid) const override
constexpr raw::ChannelID_t begin() const
Returns the ID of the first channel in the range.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
virtual unsigned int MaxTPCsets() const override
Returns the largest number of TPC sets any cryostat in the detector has.
virtual unsigned int NTPCsets(readout::CryostatID const &cryoid) const override
Returns the total number of TPC sets in the specified cryostat.
unsigned int CryostatID_t
Type for the ID number.
Definition: geo_types.h:191
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
virtual geo::SigType_t SignalTypeForChannelImpl(raw::ChannelID_t const channel) const override
Returns the type of signal on the specified channel.
void resize(unsigned int nCryo, unsigned int nTPCs, unsigned int nPlanes)
Prepares the container with default-constructed data.
Encapsulate the construction of a single detector plane.
geo::PlaneID const & ID() const
Returns the identifier of this plane.
Definition: PlaneGeo.h:203
virtual void Initialize(geo::GeometryData_t const &geodata) override
Prepares the algorithm extracting information from the geometry.
unsigned int Nwires() const
Number of wires in this plane.
Definition: PlaneGeo.h:269
Functions pulling in STL customization if available.
geo::TPCDataContainer< readout::TPCsetID > const & TPCtoTPCset() const
The TPC set including each TPC.
Definitions of geometry vector data types.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
void GetCenter(double *xyz, double localz=0.0) const
Fills the world coordinate of a point on the wire.
Definition: WireGeo.cxx:73
Data in the geometry description.
Definition: GeometryData.h:31
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
Containers to hold one datum per TPC set or readout plane.
const WireGeo & LastWire() const
Return the last wire in the plane.
Definition: PlaneGeo.h:350
LArSoft geometry interface.
Definition: ChannelGeo.h:16
unsigned int dimSize() const
Dimensions of the Level dimension of this container.
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
static QCString * s
Definition: config.cpp:1042
std::size_t PlaneType_t
Type for plane type identifier.
static constexpr PlaneType_t kFirstInductionType
Identifier for first induction plane type.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97
virtual double WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeID) const override
Returns the index of the wire nearest to the specified position.
Encapsulate the construction of a single detector plane.
The data type to uniquely identify a cryostat.
Definition: geo_types.h:190
Signal from collection planes.
Definition: geo_types.h:146
ChannelsInROPStruct const * find(raw::ChannelID_t channel) const
Returns data of the ROP including channel, nullptr if none.