RemoveBadChannels_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \brief This module creates CellHit object
3 /// \author ??
4 ////////////////////////////////////////////////////////////////////////
5 
6 // Framework includes
14 
15 #include "Calibrator/Calibrator.h"
17 #include "RecoBase/CellHit.h"
19 
20 #include <string>
21 
22 namespace calhit
23 {
24  namespace
25  {
26  struct RemoveBadChannelsParams
27  {
28  template<class T> using Atom = fhicl::Atom<T>;
29  template<class T> using Table = fhicl::Table<T>;
30  using Comment = fhicl::Comment;
31  using Name = fhicl::Name;
32 
33  Atom<bool> removeBadChans
34  {
35  Name("RemoveBadChans"),
36  Comment("Whether or not to remove hits on bad channels.")
37  };
38 
39  Atom<std::string> cellHitLabel
40  {
41  Name("CellHitLabel"),
42  Comment("Where to find CellHits.")
43  };
44  };
45  }
46 
47  /// Create CellHits from RawDigits
49  {
50  public:
51  // Allows 'nova --print-description' to work
53 
54  explicit RemoveBadChannels(const Parameters& params);
55  virtual ~RemoveBadChannels();
56 
57  virtual void beginRun(art::Run& run);
58  virtual void beginSubRun(art::SubRun& subrun);
59  void produce(art::Event& evt);
60 
61  protected:
62  const RemoveBadChannelsParams fParams;
64  };
65 
66  //......................................................................
68  : fParams(params()),
69  fCellHitToken(consumes<std::vector<rb::CellHit>>(fParams.cellHitLabel()))
70  {
71  produces<std::vector<rb::CellHit>>();
72  produces<int, art::InRun>();
73  produces<int, art::InSubRun>();
74  }
75 
76  //......................................................................
78  {
79  }
80 
81  //......................................................................
83  {
85  // if use subrun-level dB masks, don't do this
86  if (! rh->GetDiBlockMaskFromCondb()) {
87  std::unique_ptr<int> mask(new int(rh->GoodDiBlockMask(0,true)));
88  std::cout << __PRETTY_FUNCTION__ << " writing run diblock mask " << std::hex << *mask << std::dec << " to run." << std::endl;
89  run.put(std::move(mask));
90  }
91  }
92 
93  //......................................................................
95  {
97  // do this if we are using subrun-level dB masks
98  if (rh->GetDiBlockMaskFromCondb()) {
99  int sr = subrun.subRun();
100  int tmask = rh->GoodDiBlockMask(sr,false);
101  std::unique_ptr<int> mask(new int(tmask));
102  LOG_DEBUG("RemoveBadChannels") << __PRETTY_FUNCTION__ << " writing subrun diblock mask " << std::hex << tmask << std::dec << " to subrun." << std::endl;
103  subrun.put(std::move(mask));
104  }
105  }
106 
107  //......................................................................
109  {
110  // get the CellHit list
112  evt.getByToken(fCellHitToken, hitcol);
113  if (!hitcol.isValid()) {
114  mf::LogError("RemoveBadChannels") << "Cannot find " << fParams.cellHitLabel() << ". Perhaps you want RemoveBadChannelsFilter instead?";
115  abort();
116  }
117 
118  // define the unique_ptr holding the collection of rb::CellHits to be made
119  auto cellhitcol = std::make_unique<std::vector<rb::CellHit>>();
120 
121  // No valid handle --
122  if (!hitcol.isValid()) {
123  mf::LogError("RemoveBadChannels") << "Cannot find " << fParams.cellHitLabel() << ". Bailing.";
124  abort();
125  }
126 
127 
128  // Expect most of the cells to be good. Don't want to waste time resizing
129  // the array
130  cellhitcol->reserve(hitcol->size());
131 
132  // Make a CellHit for every (non-bad) RawDigit and write it out
133 
134  // Make the hits and write them out
135  if(fParams.removeBadChans()){
138 
139  for(const rb::CellHit& hit: *hitcol){
140  if(!bcl->IsBad(hit.Plane(),
141  hit.Cell())){
142  cellhitcol->push_back(hit);
143  }
144  }
145  }
146  else{
147  for(const rb::CellHit hit: *hitcol){
148  cellhitcol->push_back(hit);
149  }
150  }
151 
152  evt.put(std::move(cellhitcol));
153  }
154 
156 
157 } // end namespace calhit
158 //////////////////////////////////////////////////////////////////////////
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
TH2 * rh
Definition: drawXsec.C:5
SubRunNumber_t subRun() const
Definition: SubRun.h:44
const art::ProductToken< std::vector< rb::CellHit > > fCellHitToken
const RemoveBadChannelsParams fParams
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
art::ProductID put(std::unique_ptr< PROD > &&)
Definition: Run.h:149
DEFINE_ART_MODULE(TestTMapFile)
Definition: Run.h:31
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
bool isValid() const
Definition: Handle.h:189
Create CellHits from RawDigits.
int evt
caf::StandardRecord * sr
virtual void beginSubRun(art::SubRun &subrun)
Perform a "2 point" Hough transform on a collection of hits.
Atom< std::string > cellHitLabel
RemoveBadChannels(const Parameters &params)
Definition: run.py:1
OStream cout
Definition: OStream.cxx:6
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
virtual void beginRun(art::Run &run)
ProductID put(std::unique_ptr< PROD > &&)
Definition: structs.h:12
This module creates CellHit object.
bool GetDiBlockMaskFromCondb() const
Definition: RunHistory.h:368
int GoodDiBlockMask(int subrun=-1, bool reload=false)
bool getByToken(ProductToken< PROD > const &token, Handle< PROD > &result) const
Definition: DataViewImpl.h:387
bool IsBad(int plane, int cell)
Atom< bool > removeBadChans