BadChanValidate_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: BadChanValidate
3 // Module Type: analyzer
4 // File: BadChanValidate_module.cc
5 //
6 // Generated at Fri Jan 30 20:02:58 2015 by Kanika Sachdev using artmod
7 // from cetpkgsupport v1_07_00.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
19 
22 
24 #include "Geometry/Geometry.h"
26 #include "NovaDAQConventions/DAQConventions.h"
27 #include "DAQChannelMap/HardwareDisplay.h"
28 #include "RawData/RawDigit.h"
29 
30 #include "TH2F.h"
31 #include "TFile.h"
32 #include "TMath.h"
33 #include "TTree.h"
34 
35 #include <iomanip>
36 #include <iostream>
37 
38 namespace chaninfo {
39  class BadChanValidate;
40 }
41 
43 public:
44  explicit BadChanValidate(fhicl::ParameterSet const & p);
45  // The destructor generated by the compiler is fine for classes
46  // without bare pointers or other resource use.
47 
48  // Plugins should not be copied or assigned.
49  BadChanValidate(BadChanValidate const &) = delete;
50  BadChanValidate(BadChanValidate &&) = delete;
51 
52 
53  // Required functions.
54  void analyze(art::Event const & e) override;
55 
56  // Selected optional functions.
57  void beginRun(art::Run const & r) override;
58  void beginSubRun(art::SubRun const & sr) override;
59  void endSubRun(art::SubRun const & sr) override;
60  void reconfigure(fhicl::ParameterSet const & p);
61 
62 private:
63 
64  // Declare member data here.
65 
69 
70  unsigned int fRun;
71  unsigned int fSubrun;
72 
73  int fNpass = 0;
76 
77  TH2F* fDBMaskHist;
78  TH2F* fOMMaskHist;
79  TH2F* fDBMinusOM;
80 
81  void BadChansFromDB();
82  void BadChansFromOM();
84 
87 
88 };
89 
90 ///////////////////////////////////////////////////////////////////
91 
93  :
94  EDAnalyzer(p)
95 {
96  this->reconfigure(p);
97 }
98 
99 ///////////////////////////////////////////////////////////////////
100 
102 {
103  fADCLowCut = p.get<int>("ADCLowCut");
104  fADCHighCut = p.get<int>("ADCHighCut");
105  fOnmonFilename = p.get<std::string>("OnmonFilename");
106  fRawDigitLabel = p.get<std::string>("RawDigitLabel");
107 }
108 
109 ///////////////////////////////////////////////////////////////////
110 
112 {
113  fDetID = fGeom->DetId();
114 }
115 
116 ///////////////////////////////////////////////////////////////////
117 
119 {
120 
121  fRun = sr.run();
122  fSubrun = sr.subRun();
123 
125 
126  char *htitledb = new char[100];
127  sprintf(htitledb, "DB Channel Map For Run %d, Subrun %d;Plane;Cell",
128  fRun, fSubrun);
129 
130  char *htitleom = new char[100];
131  sprintf(htitleom, "Onmon Channel Map For Run %d, Subrun %d;Plane;Cell",
132  fRun, fSubrun);
133 
134  int nplanes = fGeom->NPlanes();
135  int ncells = fGeom->Plane(0)->Ncells();
136 
137  char *hnamedb = new char[100];
138  sprintf(hnamedb, "db_mask_%d_%d", fRun, fSubrun);
139 
140  char *hnameom = new char[100];
141  sprintf(hnameom, "om_mask_%d_%d", fRun, fSubrun);
142 
143  fDBMaskHist = tfs->make<TH2F>(hnamedb, htitledb,
144  nplanes+1, -1, nplanes,
145  ncells +1, -1, ncells);
146 
147  fOMMaskHist = tfs->make<TH2F>(hnameom, htitleom,
148  nplanes+1, -1, nplanes,
149  ncells +1, -1, ncells);
150 
151 }
152 
153 
154 ///////////////////////////////////////////////////////////////////
155 
157 {
158 
160  e.getByLabel(fRawDigitLabel, rawdigs);
161 
162  if( rawdigs->empty() || fNpass > 0 )
163  return;
164 
165  BadChansFromDB();
166  BadChansFromOM();
167  fNpass += 1;
168 }
169 
170 ///////////////////////////////////////////////////////////////////
171 
173 {
174 
177 
178  unsigned int nplanes = fGeom->NPlanes();
179  for(unsigned int iplane = 0; iplane < nplanes; ++iplane){
180  unsigned int ncells = fGeom->Plane(iplane)->Ncells();
181  for(unsigned int icell = 0; icell < ncells; ++icell){
182  fDBMaskHist->Fill(iplane, icell, !bad->IsBad(iplane, icell));
183  }// end of loop over cells
184  }// end of loop over planes
185 }// end of BadChansFromDB
186 
187 ///////////////////////////////////////////////////////////////////
188 
190 {
193 
194  std::cout<<"\n";
195  std::cout<<"Name of OnMon File: "<<fOnmonFilename<<std::endl;
196  std::cout<<"\n";
197 
198 
199  TFile *fOnmonFile = new TFile(fOnmonFilename.c_str(),"READ");
200 
201  // Check that we have the right onmon file
202  TTree *header = (TTree*)(fOnmonFile->Get("Header"));
203  assert( header->GetEntries() > 0 );
204 
205  unsigned int omrun, omsubrun;
206  header->SetBranchAddress("Run", &omrun);
207  header->SetBranchAddress("Subrun", &omsubrun);
208  header->GetEntry(0);
209 
210  assert( omrun == fRun &&
211  omsubrun == fSubrun);
212 
213  int ndcm = rh->NDCMs();
214  int ndb = rh->NDiBlocks();
215  TH2F *hitmap[ndb][ndcm];
216 
217  for(int idb = 0; idb < ndb; ++idb){
218  int indcm = rh->GetDiBlock(idb, false).dcm.size();
219 
220  int rhidb = rh->GetDiBlock(idb, false).num;
221  if(fDetID == novadaq::cnv::kNEARDET && idb == 3)
222  indcm = 2;
223 
224  for(int idcm = 0; idcm < indcm; ++idcm){
225  char hname[256];
226  sprintf(hname,"PixelsRateDCM_%02d_%02d",rhidb,idcm+1);
227 
228  fOnmonFile->cd();
229  hitmap[idb][idcm] = (TH2F*)(fOnmonFile->Get(hname));
230 
231  }// end loop over dcms
232  }//end loop over diblock
233 
234  daqchannelmap::DAQChannelMap* daqcmap =
236 
238  hwd.SetupDet(fDetID);
239 
240  for( int idb = 0; idb < ndb ; ++idb ){
241 
242  std::vector<nova::dbi::RunHistory::DCM> dcms = rh->GetDiBlock(idb, false).dcm;
243  int ndcm = dcms.size();
244  int rhidb = rh->GetDiBlock(idb, false).num;
245  if(fDetID == novadaq::cnv::kNEARDET && idb == 3)
246  ndcm = 2;
247 
248  for( int idcm = 0; idcm < ndcm; ++idcm){
249 
250  std::vector<nova::dbi::RunHistory::FEB> febs = dcms[idcm].feb;
251  unsigned int nfebs = febs.size();
252 
253  // In case the subrun is short, there isn't enough
254  // info to compute rates. These hists don't exist then.
255  if(!hitmap[idb][idcm])
256  continue;
257 
258  int nx = hitmap[idb][idcm]->GetXaxis()->GetNbins();
259  int ny = hitmap[idb][idcm]->GetYaxis()->GetNbins();
260 
261  for (int ix=1; ix<=nx; ++ix) {
262  for (int iy=1; iy<=ny; ++iy) {
263 
264  unsigned int ifeb, ipixel;
265  hwd.XYFEB(&ifeb,ix-1,iy-1);
266  hwd.XYPix(&ipixel,ix-1,iy-1);
267 
268  // map to plane and cell in detector
269  daqchannelmap::dchan daqChan = daqcmap->encodeDChan(fDetID,rhidb,
270  idcm+1,ifeb,
271  ipixel);
272  // not so logical chan :/
273  daqchannelmap::lchan logChan = daqcmap->encodeLChan(daqChan);
274 
275  int plane = daqcmap->getPlane(logChan);
276  int cell = daqcmap->getCell(logChan);
277 
278  // check that this FEB was instrumented
279  bool hasAPD = ( ifeb < nfebs && febs[ifeb].hasAPD);
280 
281  float rate = hitmap[idb][idcm]->GetBinContent(ix,iy);
282 
283  // Congruent with IsBad function
284  if(hasAPD){
285 
286  if (rate>0.)
287  rate = TMath::Log10(rate);
288  else
289  rate = -5.;
290 
291  if(rate <= 3.5 && rate >= 0.5)
292  fOMMaskHist->Fill( plane, cell);
293 
294  }
295  else
296  continue;
297 
298  }// end loop over y bins
299  }// end loop over x bins
300 
301  }// end loop over dcms
302  }// end loop over diblocks
303 
304 }// end of BadChansFromOM
305 
306 ///////////////////////////////////////////////////////////////////
307 
309 {
310 
311 
312  //---------------------------------------------------
313  // New addition - Assuming same number for onmon hist
314  int binsX = fDBMaskHist->GetNbinsX();
315  int binsY = fDBMaskHist->GetNbinsY();
316 
317  // counters
318  int dbYes_omNo = 0;
319  int dbNo_omYes = 0;
320 
321  for(int iplane = 0; iplane < binsX; ++iplane){
322  for(int icell = 0; icell < binsY; ++icell){
323 
324  if ( (fDBMaskHist->GetBinContent(iplane,icell) == 1) &&
325  (fOMMaskHist->GetBinContent(iplane,icell) == 0) ){
326  // Do something smart here
327  dbYes_omNo += 1;
328  }
329  else if ( (fDBMaskHist->GetBinContent(iplane,icell) == 0) &&
330  (fOMMaskHist->GetBinContent(iplane,icell) == 1) ){
331  // Do something smart here
332  dbNo_omYes += 1;
333  }
334  else
335  continue;
336 
337  } // end icell
338  } // end iplane
339  //---------------------------------------------------
340 
341  fDBMinusOM = (TH2F*)fDBMaskHist->Clone("fDBMinusOM");
342  fDBMinusOM->Add(fOMMaskHist,-1);
343  fDBMinusOM->GetZaxis()->SetRangeUser(-1,1);
344 
345  char *hnamedf = new char[100];
346  sprintf(hnamedf, "diff_mask_%d_%d", fRun, fSubrun);
347  fDBMinusOM->SetName(hnamedf);
348 
349  char *htitledf = new char[100];
350  sprintf(htitledf, "DB minus Onmon Channel Map For Run %d, Subrun %d;Plane;Cell",
351  fRun, fSubrun);
352  fDBMinusOM->SetTitle(htitledf);
353 
355  tfs->file().cd();
356  fDBMinusOM->Write();
357 
358  int nbins = fDBMinusOM->GetSize();
359  int nfill = 0;
360  for(int i = 0; i < nbins ; i++){
361  if(fDBMinusOM->GetBinContent(i) != 0 )
362  nfill+=1;
363  }
364 
365  //double nfill = fDBMinusOM->GetEntries();
366  double perc = nfill*100/(double)nbins;
367 
368  // New fractions
369  double fracDBgood = dbYes_omNo*100/(double)nbins;
370  double fracOMgood = dbNo_omYes*100/(double)nbins;
371 
372  std::cout<<"\n";
373  std::cout<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
374  std::cout<<"\n";
375  std::cout<<" === Numbers as percentage (%) ===";
376  std::cerr<<"Difference between DB and OnMon masks : "<< std::setprecision(2) << std::fixed << perc << "\n";
377  std::cerr<<"Fraction DB sees good, OnMon sees bad : "<< std::setprecision(4) << std::fixed << fracDBgood << "\n";
378  std::cerr<<"Fraction DB sees bad, OnMon sees good : "<< std::setprecision(4) << std::fixed << fracOMgood << "\n";
379  std::cout<<"\n";
380  std::cout<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
381  std::cout<<"\n";
382 
383 }
384 
385 ///////////////////////////////////////////////////////////////////
386 
387 
388 
void XYPix(unsigned int *pix, unsigned int ix, unsigned int iy)
int NDiBlocks()
gives number of active diblocks only, may be less than 14
Definition: RunHistory.h:394
void reconfigure(fhicl::ParameterSet const &p)
TH2 * rh
Definition: drawXsec.C:5
SubRunNumber_t subRun() const
Definition: SubRun.h:44
art::ServiceHandle< geo::Geometry > fGeom
void XYFEB(unsigned int *feb, unsigned int ix, unsigned int iy)
const char * p
Definition: xmltok.h:285
DiBlock GetDiBlock(int i, bool loadAll=true)
get ith diblock is RH list (which only includes diblocks with activity), starting with i=0...
unsigned int Ncells() const
Number of cells in this plane.
Definition: PlaneGeo.h:43
OStream cerr
Definition: OStream.cxx:7
TFile & file() const
Definition: TFileService.h:63
const PlaneGeo * Plane(unsigned int i) const
DEFINE_ART_MODULE(TestTMapFile)
cell_t getCell(lchan logicalchan) const
Decode the cell number from an lchan.
void endSubRun(art::SubRun const &sr) override
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
Definition: Run.h:31
const int nbins
Definition: cellShifts.C:15
static DAQChannelMap * getInstance(int detID)
T get(std::string const &key) const
Definition: ParameterSet.h:231
void analyze(art::Event const &e) override
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
Near Detector in the NuMI cavern.
void beginSubRun(art::SubRun const &sr) override
caf::StandardRecord * sr
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
OStream cout
Definition: OStream.cxx:6
int nplanes
Definition: geom.C:145
void OnmonNameFor(std::string fname)
std::vector< DCM > dcm
Definition: RunHistory.h:311
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void geom(int which=0)
Definition: geom.C:163
plane_t getPlane(lchan logicalchan) const
Decode the plane number from an lchan.
assert(nhit_max >=nhit_nbins)
TRandom3 r(0)
Interface to the run-by-run list of bad channels.
Definition: BadChanList.h:31
int ncells
Definition: geom.C:124
dchan encodeDChan(int detID, diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
unsigned int NPlanes() const
Float_t e
Definition: plot.C:35
uint32_t dchan
< DAQ Channel Map Package
BadChanValidate(fhicl::ParameterSet const &p)
bool IsBad(int plane, int cell)
void beginRun(art::Run const &r) override
Encapsulate the geometry of one entire detector (near, far, ndos)
RunNumber_t run() const
Definition: SubRun.h:49
enum BeamMode string