BadChanList.h
Go to the documentation of this file.
1 ///
2 /// \brief Interface to the run-by-run list of bad channels
3 /// \author betancourt@physics.umn.edu, jpaley@anl.gov
4 /// \date
5 ///
6 #ifndef CHANINFO_BADCHANLIST_H
7 #define CHANINFO_BADCHANLIST_H
8 
9 #include <vector>
10 #include <map>
11 #include <string>
12 #include <ctime>
13 
14 // NOvA includes
15 #include "RawData/RawDigit.h"
17 #include "NovaDAQConventions/DAQConventions.h"
18 #include "DAQChannelMap/DAQChannelMap.h"
19 
20 //Framework includes
25 //#include "art/Persistency/Provenance/Timestamp.h"
26 #include "fhiclcpp/ParameterSet.h"
27 #include "CLHEP/Random/RandFlat.h"
28 
29 namespace nova{namespace dbi{class Table;}}
30 
31 namespace chaninfo {
32 
33  const size_t FD_NUM_PLANES = 896;
34  const size_t FD_NUM_CELLS = 384;
35 
36  ///
37  /// Interface to the run-by-run list of bad channels
38  ///
39  class BadChanList {
40  public:
41  // Get a BadChanList instance here
43  ~BadChanList();
44 
45  void preBeginRun(art::Run const& run);
46  void postBeginSubRun(art::SubRun const& subrun);
47  void preBeginEvent ( art::Event const & evt);
48 
49  int Apply(art::PtrVector<rawdata::RawDigit>& rd);
50  int Apply(std::vector< art::Ptr<rawdata::RawDigit> >& rd);
51  int Apply(std::vector< const rawdata::RawDigit*>&);
52 
53  bool IsBad(int plane, int cell);
54  bool IsLowEfficiency(int plane, int cell);
55  void reconfigure(fhicl::ParameterSet p);
56 
57  void LoadNewData();
58 
59  int NBadInSubRun(int i);
60 
61  private:
62  // This does the real work, and IsBad usually returns a cached value
63  bool IsBadUncached(int plane, int cell);
64 
65  // If fEventCheck, return true if the DCM containing this channel has no hits in this
66  // event and false otherwise. Otherwise, return false. This is an effective check
67  // for dropped DCMS at the FD. It seems suspect for the ND, which is quiet enough
68  // to have validly empty DCMs.
69  bool InDroppedDCM(int plane, int cell);
70 
71  void SetRandomBadChannels();
72 
73  void LoadCosmicEff(int newrun, int newsubrun);
74 
75  // T = RawDigit or CellHit
76  template<class T> void CountDCMHits(const std::vector<T>& digitcol);
77 
78  // private data members for BadChanList class
79  int fApplyBadChan; ///< Option to activate the bad channels
80  int fMCRunNumber; ///< Run number for the MC
81  int fMCSubrunNumber; ///< Subrun number for the MC
82 
83  int fNBadSR;
84 
86 
89 
90  bool fAbortIfNoneFound; ///< Option to throw an exception if no channel rate state rows are returned from dB.
91 
93 
94  bool fIsPerfect;
95 
97 
99 
100  std::unordered_set<geo::OfflineChan> fLowEfficiency; ///< set of low eff channels
101  std::unordered_set<geo::OfflineChan> fRandomBCMap; ///< random bad channel map
102 
104 
105  bool fEventCheck; ///< do we check each event for dropped DCMs?
106 
107  std::string fRawDigitLabel; ///< what is the name of the raw digits ART object
109 
110  bool fNewCosmicEffTable; ///< Use new-style table?
111 
112  float fRandomBadChannelFraction; ///< If >0, ignore DB and set this fraction bad at random
113 
114  /// Vector index is the subrun number, set contains all the bad channels
115  std::vector<std::unordered_set<geo::OfflineChan>> fBadChans;
116  std::vector<std::unordered_set<int>> fDropOuts; ///< [subrun][tchan]
117 
118  int fRun;
119  int fSubRun;
120 
121  time_t fMinVldTime; ///< Minimum time used in database request
122 
123  time_t fMaxVldTime; ///< Maximum time used in database request
124 
125 
126 
130 
132 
133  std::unique_ptr<CLHEP::RandFlat> fFlatRand;
134 
135  int fDCMHits[12][14]; ///< count hits in each DCM each event to look for dropped DCMs
136 
137  std::vector<std::string> fKBCList;
138  std::vector<geo::OfflineChan> fKnownBadChannels;
139 
140  // Cache the answers to IsBad here. Regenerate on each subrun change. It
141  // requires that we don't ever build a detector bigger than the Far Detector
142  // (or for some reason number some kind of virtual plane or cells higher
143  // than its planes and cells). For simplicity, always allocate enough memory
144  // for the FD, since that's only 42kB.
145  std::bitset<FD_NUM_PLANES*FD_NUM_CELLS> fIsBadCache;
147  };
148 }
150 #endif
151 ////////////////////////////////////////////////////////////////////////
std::vector< std::string > fKBCList
Definition: BadChanList.h:137
std::string fValidityTagNearDet
Definition: BadChanList.h:127
std::string fBadChanCSVFile
Definition: BadChanList.h:103
const size_t FD_NUM_CELLS
Definition: BadChanList.h:34
std::unordered_set< geo::OfflineChan > fRandomBCMap
random bad channel map
Definition: BadChanList.h:101
const char * p
Definition: xmltok.h:285
#define DECLARE_ART_SERVICE(svc, scope)
Definition: ServiceMacros.h:91
Definition: Run.h:31
bool fAbortIfNoneFound
Option to throw an exception if no channel rate state rows are returned from dB.
Definition: BadChanList.h:90
std::string fValidityTagFarDet
Definition: BadChanList.h:128
std::vector< std::unordered_set< int > > fDropOuts
[subrun][tchan]
Definition: BadChanList.h:116
float fRandomBadChannelFraction
If >0, ignore DB and set this fraction bad at random.
Definition: BadChanList.h:112
std::vector< geo::OfflineChan > fKnownBadChannels
Definition: BadChanList.h:138
std::bitset< FD_NUM_PLANES *FD_NUM_CELLS > fIsBadCache
Definition: BadChanList.h:145
bool fEventCheck
do we check each event for dropped DCMs?
Definition: BadChanList.h:105
bool fNewCosmicEffTable
Use new-style table?
Definition: BadChanList.h:110
std::unordered_set< geo::OfflineChan > fLowEfficiency
set of low eff channels
Definition: BadChanList.h:100
std::string fRawDigitLabel
what is the name of the raw digits ART object
Definition: BadChanList.h:107
int evt
time_t fMaxVldTime
Maximum time used in database request.
Definition: BadChanList.h:123
const size_t FD_NUM_PLANES
Definition: BadChanList.h:33
Hold drift constants from current run.
Definition: DriftCache.h:17
std::string fCellHitLabel
Definition: BadChanList.h:108
Definition: run.py:1
int fMCRunNumber
Run number for the MC.
Definition: BadChanList.h:80
std::string fFEBDropoutTag
Definition: BadChanList.h:129
time_t fMinVldTime
Minimum time used in database request.
Definition: BadChanList.h:121
Interface to the run-by-run list of bad channels.
Definition: BadChanList.h:31
int fMCSubrunNumber
Subrun number for the MC.
Definition: BadChanList.h:81
int fApplyBadChan
Option to activate the bad channels.
Definition: BadChanList.h:79
std::unique_ptr< CLHEP::RandFlat > fFlatRand
Definition: BadChanList.h:133
std::vector< std::unordered_set< geo::OfflineChan > > fBadChans
Vector index is the subrun number, set contains all the bad channels.
Definition: BadChanList.h:115
Simple object representing a (plane, cell) pair.
Definition: fwd.h:28
enum BeamMode string