CalHit_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 "RawData/RawDigit.h"
18 #include "RecoBase/CellHit.h"
20 
21 #include <string>
22 
23 namespace calhit
24 {
25  namespace
26  {
27  struct CalHitParams
28  {
29  template<class T> using Atom = fhicl::Atom<T>;
30  template<class T> using Table = fhicl::Table<T>;
31  using Comment = fhicl::Comment;
32  using Name = fhicl::Name;
33 
34  Atom<bool> removeBadChans
35  {
36  Name("RemoveBadChans"),
37  Comment("Whether or not to remove hits on bad channels.")
38  };
39 
40  Atom<std::string> rawDataLabel
41  {
42  Name("RawDataLabel"),
43  Comment("Where to find RawDigits.")
44  };
45  };
46  }
47 
48  /// Create CellHits from RawDigits
49  class CalHit : public art::EDProducer
50  {
51  public:
52  // Allows 'nova --print-description' to work
54 
55  explicit CalHit(const Parameters& params);
56  virtual ~CalHit();
57 
58  virtual void beginRun(art::Run& run);
59  virtual void beginSubRun(art::SubRun& subrun);
60  void produce(art::Event& evt);
61 
62  protected:
63  const CalHitParams fParams;
65  };
66 
67  //......................................................................
68  CalHit::CalHit(const Parameters& params)
69  : fParams(params()),
70  fRawDigitToken(consumes<std::vector<rawdata::RawDigit>>(fParams.rawDataLabel()))
71  {
72  produces<std::vector<rb::CellHit>>();
73  produces<int, art::InRun>();
74  produces<int, art::InSubRun>();
75  }
76 
77  //......................................................................
79  {
80  }
81 
82  //......................................................................
84  {
86  // if use subrun-level dB masks, don't do this
87  if (! rh->GetDiBlockMaskFromCondb()) {
88  std::unique_ptr<int> mask(new int(rh->GoodDiBlockMask(0,true)));
89  std::cout << __PRETTY_FUNCTION__ << " writing run diblock mask " << std::hex << *mask << std::dec << " to run." << std::endl;
90  run.put(std::move(mask));
91  }
92  }
93 
94  //......................................................................
96  {
98  // do this if we are using subrun-level dB masks
99  if (rh->GetDiBlockMaskFromCondb()) {
100  int sr = subrun.subRun();
101  int tmask = rh->GoodDiBlockMask(sr,false);
102  std::unique_ptr<int> mask(new int(tmask));
103  LOG_DEBUG("CalHit") << __PRETTY_FUNCTION__ << " writing subrun diblock mask " << std::hex << tmask << std::dec << " to subrun." << std::endl;
104  subrun.put(std::move(mask));
105  }
106  }
107 
108  //......................................................................
110  {
111  // get the RawDigit list
113  evt.getByToken(fRawDigitToken, digitcol);
114 
115  // define the unique_ptr holding the collection of rb::CellHits to be made
116  auto cellhitcol = std::make_unique<std::vector<rb::CellHit>>();
117 
118  // Expect most of the cells to be good. Don't want to waste time resizing
119  // the array
120  cellhitcol->reserve(digitcol->size());
121 
122  // Get a Calibrator instance for this event
124 
125  // Make a CellHit for every (non-bad) RawDigit and write it out
126 
127  // Make the hits and write them out
128  if(fParams.removeBadChans()){
131 
132  for(const rawdata::RawDigit& dig: *digitcol){
133  if(!bcl->IsBad(cmap->GetPlane(&dig),
134  cmap->GetCell(&dig))){
135  cellhitcol->push_back(cal->MakeCellHit(&dig));
136  }
137  }
138  }
139  else{
140  for(const rawdata::RawDigit& dig: *digitcol){
141  cellhitcol->push_back(cal->MakeCellHit(&dig));
142  }
143  }
144 
145  evt.put(std::move(cellhitcol));
146  }
147 
149 
150 } // end namespace calhit
151 //////////////////////////////////////////////////////////////////////////
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
const CalHitParams fParams
TH2 * rh
Definition: drawXsec.C:5
SubRunNumber_t subRun() const
Definition: SubRun.h:44
const art::ProductToken< std::vector< rawdata::RawDigit > > fRawDigitToken
CalHit(const Parameters &params)
Definition of connection map class.
Definition: CMap.h:19
art::ProductID put(std::unique_ptr< PROD > &&)
Definition: Run.h:149
DEFINE_ART_MODULE(TestTMapFile)
Create CellHits from RawDigits.
rb::CellHit MakeCellHit(const rawdata::RawDigit *rawdigit)
Definition: Run.h:31
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
int evt
unsigned short GetPlane(const rawdata::RawDigit *dig)
Definition: CMap.cxx:285
caf::StandardRecord * sr
virtual void beginRun(art::Run &run)
Definition: run.py:1
OStream cout
Definition: OStream.cxx:6
virtual void beginSubRun(art::SubRun &subrun)
Atom< bool > removeBadChans
ProductID put(std::unique_ptr< PROD > &&)
virtual ~CalHit()
This module creates CellHit object.
void produce(art::Event &evt)
bool GetDiBlockMaskFromCondb() const
Definition: RunHistory.h:368
unsigned short GetCell(const rawdata::RawDigit *dig)
Definition: CMap.cxx:327
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< std::string > rawDataLabel