Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
detvar::RandomChannelStatusProvider Class Reference

#include <RandomChannelStatusService.h>

Inheritance diagram for detvar::RandomChannelStatusProvider:
lariov::ChannelStatusProvider lar::UncopiableAndUnmovableClass

Public Member Functions

bool IsBad (raw::ChannelID_t chan) const override
 Returns whether the specified channel is bad in the current run. More...
 
bool IsPresent (raw::ChannelID_t) const override
 Returns whether the specified channel is physical and connected to wire. More...
 
bool IsNoisy (raw::ChannelID_t) const override
 Returns whether the specified channel is noisy in the current run. More...
 
std::set< raw::ChannelID_tGoodChannels () const override
 Returns a copy of set of good channel IDs for the current run. More...
 
std::set< raw::ChannelID_tBadChannels () const override
 Returns a copy of set of bad channel IDs for the current run. More...
 
std::set< raw::ChannelID_tNoisyChannels () const override
 Returns a copy of set of noisy channel IDs for the current run. More...
 
- Public Member Functions inherited from lariov::ChannelStatusProvider
 ChannelStatusProvider ()=default
 Default constructor. More...
 
 ChannelStatusProvider (ChannelStatusProvider const &)=delete
 
 ChannelStatusProvider (ChannelStatusProvider &&)=delete
 
ChannelStatusProvideroperator= (ChannelStatusProvider const &)=delete
 
ChannelStatusProvideroperator= (ChannelStatusProvider &&)=delete
 
virtual ~ChannelStatusProvider ()=default
 Virtual destructor; destructs nothing. More...
 
virtual bool IsGood (raw::ChannelID_t channel) const
 Returns whether the specified channel is physical and good. More...
 
virtual Status_t Status (raw::ChannelID_t channel) const
 Returns a status integer with arbitrary meaning. More...
 
virtual bool HasStatus (raw::ChannelID_t channel) const
 Returns whether the specified status is a valid one. More...
 

Protected Types

enum  EMode_t {
  kUnknown, kRandomAPAs, kRandomAPAsides, kRandomBoards,
  kRandomChips, kRandomChans
}
 

Protected Member Functions

 RandomChannelStatusProvider (const fhicl::ParameterSet &pset)
 
void MarkChansBad (unsigned int target)
 
void MarkAPAsBad (unsigned int target)
 
void MarkAPASidesBad (unsigned int target)
 
void MarkBoardsOrChipsBad (EMode_t mode, unsigned int target)
 
void MarkBoardBad (int board, const std::vector< std::vector< raw::ChannelID_t >> &chans)
 
void MarkChipBad (int board, int chip, const geo::GeometryCore *geom, const std::vector< std::vector< raw::ChannelID_t >> &chans)
 

Protected Attributes

std::set< raw::ChannelID_tfBadChans
 
std::set< raw::ChannelID_tfGoodChans
 

Friends

class RandomChannelStatusService
 

Additional Inherited Members

- Public Types inherited from lariov::ChannelStatusProvider
using Status_t = unsigned short
 type representing channel status More...
 
using ChannelSet_t = std::set< raw::ChannelID_t >
 Type of set of channel IDs. More...
 
- Static Public Member Functions inherited from lariov::ChannelStatusProvider
static bool IsValidStatus (Status_t status)
 Returns whether the specified status is a valid one. More...
 
- Static Public Attributes inherited from lariov::ChannelStatusProvider
static constexpr Status_t InvalidStatus = std::numeric_limits<Status_t>::max()
 Value or invalid status. More...
 

Detailed Description

Definition at line 12 of file RandomChannelStatusService.h.

Member Enumeration Documentation

Enumerator
kUnknown 
kRandomAPAs 

"APAs"

kRandomAPAsides 

"APAsides"

kRandomBoards 

"boards"

kRandomChips 

"chips"

kRandomChans 

"channels"

Definition at line 36 of file RandomChannelStatusService.h.

Constructor & Destructor Documentation

detvar::RandomChannelStatusProvider::RandomChannelStatusProvider ( const fhicl::ParameterSet pset)
protected

Definition at line 174 of file RandomChannelStatusService_service.cc.

175  {
176  const double badfrac = pset.get<double>("BadChanFrac");
177 
178  EMode_t mode = kUnknown;
179 
180  const std::string modestr = pset.get<std::string>("Mode");
181  if(modestr == "channels") mode = kRandomChans;
182  if(modestr == "APAs") mode = kRandomAPAs;
183  if(modestr == "APAsides") mode = kRandomAPAsides;
184  if(modestr == "boards") mode = kRandomBoards;
185  if(modestr == "chips") mode = kRandomChips;
186  if(mode == kUnknown){
187  std::cout << "RandomChannelStatusService: unknown mode '"
188  << modestr << "'" << std::endl;
189  abort();
190  }
191 
193 
194  // TODO don't seem to be able to access the RandomNumberGenerator service
195  // from here, let alone anything to do with seeds.
196  // const unsigned int seed = pset.get<unsigned int>("Seed", sim::GetRandomNumberSeed());
197  // auto& engine = createEngine(seed);
198  // CLHEP::RandFlat r(engine);
199 
200  const unsigned int target = badfrac*geom->Nchannels();
201 
202  switch(mode){
203  case kRandomChans: MarkChansBad(target); break;
204 
205  case kRandomAPAs: MarkAPAsBad(target); break;
206 
207  case kRandomAPAsides: MarkAPASidesBad(target); break;
208 
209  case kRandomBoards:
210  case kRandomChips:
211  MarkBoardsOrChipsBad(mode, target);
212  break;
213 
214  default:
215  abort(); // impossible
216  }
217 
218  // goodchans = allchans - badchans
219  std::set<raw::ChannelID_t> allchans;
220  for(geo::WireID wire: geom->IterateWireIDs())
221  allchans.insert(geom->PlaneWireToChannel(wire));
222 
223  std::set_difference(allchans.begin(), allchans.end(),
224  fBadChans.begin(), fBadChans.end(),
225  std::inserter(fGoodChans, fGoodChans.begin()));
226  }
std::string string
Definition: nybbler.cc:12
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
IteratorBox< wire_id_iterator,&GeometryCore::begin_wire_id,&GeometryCore::end_wire_id > IterateWireIDs() const
Enables ranged-for loops on all wire IDs of the detector.
void MarkBoardsOrChipsBad(EMode_t mode, unsigned int target)
T get(std::string const &key) const
Definition: ParameterSet.h:271
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
QTextStream & endl(QTextStream &s)

Member Function Documentation

std::set<raw::ChannelID_t> detvar::RandomChannelStatusProvider::BadChannels ( ) const
inlineoverridevirtual

Returns a copy of set of bad channel IDs for the current run.

Implements lariov::ChannelStatusProvider.

Definition at line 28 of file RandomChannelStatusService.h.

29  {
30  return fBadChans;
31  }
std::set<raw::ChannelID_t> detvar::RandomChannelStatusProvider::GoodChannels ( ) const
inlineoverridevirtual

Returns a copy of set of good channel IDs for the current run.

Implements lariov::ChannelStatusProvider.

Definition at line 23 of file RandomChannelStatusService.h.

24  {
25  return fGoodChans;
26  }
bool detvar::RandomChannelStatusProvider::IsBad ( raw::ChannelID_t  channel) const
inlineoverridevirtual

Returns whether the specified channel is bad in the current run.

Implements lariov::ChannelStatusProvider.

Definition at line 15 of file RandomChannelStatusService.h.

16  {
17  return fBadChans.count(chan);
18  }
bool detvar::RandomChannelStatusProvider::IsNoisy ( raw::ChannelID_t  channel) const
inlineoverridevirtual

Returns whether the specified channel is noisy in the current run.

Implements lariov::ChannelStatusProvider.

Definition at line 21 of file RandomChannelStatusService.h.

21 {return false;}
bool detvar::RandomChannelStatusProvider::IsPresent ( raw::ChannelID_t  channel) const
inlineoverridevirtual

Returns whether the specified channel is physical and connected to wire.

Implements lariov::ChannelStatusProvider.

Definition at line 20 of file RandomChannelStatusService.h.

20 {return true;}
void detvar::RandomChannelStatusProvider::MarkAPAsBad ( unsigned int  target)
protected

Definition at line 256 of file RandomChannelStatusService_service.cc.

257  {
259 
260  std::map<readout::TPCsetID, std::set<raw::ChannelID_t>> tpcset_to_chans;
261  for(const readout::TPCsetID& ts: geom->IterateTPCsetIDs()){
262  // There is no version of IterateWireIDs over a TPCset. Use another layer
263  // of indirection.
264  for(geo::TPCID t: geom->TPCsetToTPCs(ts)){
265  for(const geo::WireID& wire: geom->IterateWireIDs(t)){
266  const raw::ChannelID_t chan = geom->PlaneWireToChannel(wire);
267  tpcset_to_chans[ts].insert(chan);
268  }
269  }
270  }
271 
272  RandomTPC tpcs(geom.get());
273 
274  while(fBadChans.size() < target){
275  // Mark all the channels in this TPCset (both sides of an APA) bad
276  const readout::TPCsetID t = tpcs.GetTPCset();
277  for(raw::ChannelID_t chan: tpcset_to_chans[t]){
278  fBadChans.insert(chan);
279  }
280 
281  std::cout << "RandomChannelStatusService: Generated "
282  << fBadChans.size() << " bad channels of "
283  << target << " required" << std::endl;
284  }
285  }
T * get() const
Definition: ServiceHandle.h:63
Class identifying a set of TPC sharing readout channels.
Definition: readout_types.h:70
IteratorBox< wire_id_iterator,&GeometryCore::begin_wire_id,&GeometryCore::end_wire_id > IterateWireIDs() const
Enables ranged-for loops on all wire IDs of the detector.
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
IteratorBox< TPCset_id_iterator,&GeometryCore::begin_TPCset_id,&GeometryCore::end_TPCset_id > IterateTPCsetIDs() const
Enables ranged-for loops on all TPC set IDs of the detector.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
std::vector< geo::TPCID > TPCsetToTPCs(readout::TPCsetID const &tpcsetid) const
Returns a list of ID of TPCs belonging to the specified TPC set.
QTextStream & endl(QTextStream &s)
void detvar::RandomChannelStatusProvider::MarkAPASidesBad ( unsigned int  target)
protected

Definition at line 288 of file RandomChannelStatusService_service.cc.

289  {
291 
292  std::map<geo::TPCID, std::vector<raw::ChannelID_t>> tpc_to_chans;
293  for(const geo::TPCID& t: geom->IterateTPCIDs()){
294  // Geometry doesn't provide a way to directly iterate the channels in the
295  // TPC. Instead iterate the wires and convert to channels
296  for(const geo::WireID& wire: geom->IterateWireIDs(t)){
297  const raw::ChannelID_t chan = geom->PlaneWireToChannel(wire);
298  // But this also gives us wires that are actually attached to the other
299  // face and just wrapped onto this face. So long as the order of the
300  // vector returned from this function is meaningful, this should work
301  // to keep just the ones we need.
302  if(geom->ChannelToWire(chan)[0] == wire)
303  tpc_to_chans[t].push_back(chan);
304  }
305  }
306 
307  RandomTPC tpcs(geom.get());
308 
309  while(fBadChans.size() < target){
310  const geo::TPCID t = tpcs.GetTPC();
311 
312  // Mark all the channels in this TPC (ie APA side) bad
313  for(raw::ChannelID_t chan: tpc_to_chans[t]){
314  fBadChans.insert(chan);
315  }
316 
317  std::cout << "RandomChannelStatusService: Generated "
318  << fBadChans.size() << " bad channels of "
319  << target << " required" << std::endl;
320  }
321  }
T * get() const
Definition: ServiceHandle.h:63
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
IteratorBox< TPC_id_iterator,&GeometryCore::begin_TPC_id,&GeometryCore::end_TPC_id > IterateTPCIDs() const
Enables ranged-for loops on all TPC IDs of the detector.
IteratorBox< wire_id_iterator,&GeometryCore::begin_wire_id,&GeometryCore::end_wire_id > IterateWireIDs() const
Enables ranged-for loops on all wire IDs of the detector.
fInnerVessel push_back(Point(-578.400000, 0.000000, 0.000000))
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
QTextStream & endl(QTextStream &s)
void detvar::RandomChannelStatusProvider::MarkBoardBad ( int  board,
const std::vector< std::vector< raw::ChannelID_t >> &  chans 
)
protected

Definition at line 358 of file RandomChannelStatusService_service.cc.

360  {
361  // Check we succesfully got a single side of an APA
362  assert(chans[geo::kU].size() == 400);
363  assert(chans[geo::kV].size() == 400);
364  assert(chans[geo::kW].size() == 480);
365 
366  for(int i = 0; i < 40; ++i) fBadChans.insert(chans[geo::kU][board*40+i]);
367  for(int i = 0; i < 40; ++i) fBadChans.insert(chans[geo::kV][board*40+i]);
368  for(int i = 0; i < 48; ++i) fBadChans.insert(chans[geo::kW][board*48+i]);
369  }
Planes which measure V.
Definition: geo_types.h:130
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
Planes which measure U.
Definition: geo_types.h:129
Planes which measure W (third view for Bo, MicroBooNE, etc).
Definition: geo_types.h:131
void detvar::RandomChannelStatusProvider::MarkBoardsOrChipsBad ( EMode_t  mode,
unsigned int  target 
)
protected

Definition at line 325 of file RandomChannelStatusService_service.cc.

326  {
328 
329  RandomTPC tpcs(geom.get());
330 
331  // Generate exactly the requested fraction of bad channels (rather than a
332  // random sample with that probability). Should make results of studies
333  // less noisy.
334  while(fBadChans.size() < target){
335  const geo::TPCID t = tpcs.GetTPC();
336 
337  const std::vector<std::vector<raw::ChannelID_t>> chans = ChannelsForTPC(geom.get(), t);
338 
339  // An APA has 20 boards total, 10 on each side. ie a side has 480 W wires
340  // and 400+400 U+V wires.
341  const int board = gRandom->Integer(10);
342 
343  if(mode == kRandomBoards) MarkBoardBad(board, chans);
344 
345  if(mode == kRandomChips){
346  const int chip = 1+gRandom->Integer(8); // One of 8 chips
347  MarkChipBad(board, chip, geom.get(), chans);
348  }
349 
350  std::cout << "RandomChannelStatusService: Generated "
351  << fBadChans.size() << " bad channels of "
352  << target << " required" << std::endl;
353  }
354  }
T * get() const
Definition: ServiceHandle.h:63
std::vector< std::vector< raw::ChannelID_t > > ChannelsForTPC(const geo::GeometryCore *geom, geo::TPCID tpc)
void MarkBoardBad(int board, const std::vector< std::vector< raw::ChannelID_t >> &chans)
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
void MarkChipBad(int board, int chip, const geo::GeometryCore *geom, const std::vector< std::vector< raw::ChannelID_t >> &chans)
QTextStream & endl(QTextStream &s)
void detvar::RandomChannelStatusProvider::MarkChansBad ( unsigned int  target)
protected

Definition at line 229 of file RandomChannelStatusService_service.cc.

230  {
232 
233  // Geometry doesn't have a way to iterate directly over channels. Iterate
234  // over the wires and convert them. Use a set to remove duplicates
235  std::set<raw::ChannelID_t> allchans;
236  for(geo::WireID wire: geom->IterateWireIDs())
237  allchans.insert(geom->PlaneWireToChannel(wire));
238 
239  // But a vector is much easier to pick from randomly. This will be used for
240  // the random chans mode.
241  const std::vector<raw::ChannelID_t> vchans(allchans.begin(),
242  allchans.end());
243 
244  // Generate exactly the requested fraction of bad channels (rather than a
245  // random sample with that probability). Should make results of studies
246  // less noisy.
247  while(fBadChans.size() < target){
248  // Insert a random element. There will be duplicates, but the set will
249  // filter them out. Shouldn't be too inefficient for the low bad
250  // channel fractions we'll use in practice.
251  fBadChans.insert(vchans[gRandom->Integer(vchans.size())]);
252  } // end while
253  }
IteratorBox< wire_id_iterator,&GeometryCore::begin_wire_id,&GeometryCore::end_wire_id > IterateWireIDs() const
Enables ranged-for loops on all wire IDs of the detector.
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
void detvar::RandomChannelStatusProvider::MarkChipBad ( int  board,
int  chip,
const geo::GeometryCore geom,
const std::vector< std::vector< raw::ChannelID_t >> &  chans 
)
protected

Definition at line 373 of file RandomChannelStatusService_service.cc.

376  {
377  // Check we succesfully got a single side of an APA
378  assert(chans[geo::kU].size() == 400);
379  assert(chans[geo::kV].size() == 400);
380  assert(chans[geo::kW].size() == 480);
381 
382  // Knock out all the channels in this chip
383  for(int chan = 0; chan <= 15; ++chan){
384  geo::View_t view = geo::kUnknown;
385  // TODO the table calls this a "spot". We're using it as an index into
386  // the sorted list of channel IDs for this view (by Z coordinate). That
387  // could be wrong, but the Geometry doesn't seem to have any coresponding
388 
389  // concept.
390  int spot;
391  ChipAndChannelToSpot(chip, chan, view, spot);
392 
393  // How many wires to add on between each board
394  const int stride = (view == geo::kW) ? 48 : 40;
395 
396  assert(spot+board*stride <= int(chans[view].size()));
397  fBadChans.insert(chans[view][spot+board*stride-1]);
398  } // end for chan
399  }
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Planes which measure V.
Definition: geo_types.h:130
Unknown view.
Definition: geo_types.h:136
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
Planes which measure U.
Definition: geo_types.h:129
Planes which measure W (third view for Bo, MicroBooNE, etc).
Definition: geo_types.h:131
void ChipAndChannelToSpot(int chip, int chan, geo::View_t &view, int &wire)
std::set<raw::ChannelID_t> detvar::RandomChannelStatusProvider::NoisyChannels ( ) const
inlineoverridevirtual

Returns a copy of set of noisy channel IDs for the current run.

Implements lariov::ChannelStatusProvider.

Definition at line 33 of file RandomChannelStatusService.h.

33 {return {};}

Friends And Related Function Documentation

friend class RandomChannelStatusService
friend

Definition at line 46 of file RandomChannelStatusService.h.

Member Data Documentation

std::set<raw::ChannelID_t> detvar::RandomChannelStatusProvider::fBadChans
protected

Definition at line 64 of file RandomChannelStatusService.h.

std::set<raw::ChannelID_t> detvar::RandomChannelStatusProvider::fGoodChans
protected

Definition at line 64 of file RandomChannelStatusService.h.


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