CMS 3D CMS Logo

SiPixelInformationExtractor.cc
Go to the documentation of this file.
1 
12 
14 
17 
25 
28 
34 
35 #include "Rtypes.h"
36 #include "TAxis.h"
37 #include "TClass.h"
38 #include "TH1F.h"
39 #include "TH2F.h"
40 #include "TImage.h"
41 #include "TImageDump.h"
42 #include "TPad.h"
43 #include "TPaveLabel.h"
44 #include "TPaveText.h"
45 #include "TProfile.h"
46 #include "TROOT.h"
47 #include "TRandom.h"
48 #include "TStopwatch.h"
49 #include "TString.h"
50 #include "TStyle.h"
51 #include "TSystem.h"
52 #include "TText.h"
53 
54 #include <cmath>
55 #include <iostream>
56 #include <map>
57 
58 #include <cstdlib> // for free() - Root can allocate with malloc() - sigh...
59 
60 using namespace std;
61 using namespace edm;
62 
63 //------------------------------------------------------------------------------
67 SiPixelInformationExtractor::SiPixelInformationExtractor(bool offlineXMLfile) : offlineXMLfile_(offlineXMLfile) {
68  edm::LogInfo("SiPixelInformationExtractor") << " Creating SiPixelInformationExtractor "
69  << "\n";
70 
71  readReference_ = false;
72 }
73 
74 //------------------------------------------------------------------------------
79  edm::LogInfo("SiPixelInformationExtractor") << " Deleting SiPixelInformationExtractor "
80  << "\n";
81 }
82 
83 //------------------------------------------------------------------------------
88 
89 //============================================================================================================
90 // -- Return type of ME
91 //
93  string qtype = theMe->getRootObject()->IsA()->GetName();
94  if (qtype.find("TH1") != string::npos) {
95  return "TH1";
96  } else if (qtype.find("TH2") != string::npos) {
97  return "TH2";
98  } else if (qtype.find("TH3") != string::npos) {
99  return "TH3";
100  }
101  return "TH1";
102 }
103 
104 //------------------------------------------------------------------------------
109 void SiPixelInformationExtractor::getItemList(const multimap<string, string> &req_map,
110  string item_name,
111  vector<string> &items) {
112  items.clear();
113  for (multimap<string, string>::const_iterator it = req_map.begin(); it != req_map.end(); it++) {
114  if (it->first == item_name) {
115  items.push_back(it->second);
116  }
117  }
118 }
119 
120 //------------------------------------------------------------------------------
125 bool SiPixelInformationExtractor::hasItem(multimap<string, string> &req_map, string item_name) {
126  multimap<string, string>::iterator pos = req_map.find(item_name);
127  if (pos != req_map.end())
128  return true;
129  return false;
130 }
131 
132 //------------------------------------------------------------------------------
137 std::string SiPixelInformationExtractor::getItemValue(const std::multimap<std::string, std::string> &req_map,
138  std::string item_name) {
139  std::multimap<std::string, std::string>::const_iterator pos = req_map.find(item_name);
140  std::string value = " ";
141  if (pos != req_map.end()) {
142  value = pos->second;
143  }
144  return value;
145 }
146 std::string SiPixelInformationExtractor::getItemValue(std::multimap<std::string, std::string> &req_map,
147  std::string item_name) {
148  std::multimap<std::string, std::string>::iterator pos = req_map.find(item_name);
149  std::string value = " ";
150  if (pos != req_map.end()) {
151  value = pos->second;
152  }
153  return value;
154 }
155 
156 //
157 // -- Get color name from status
158 //
161  col = "#00ff00";
162  else if (status == dqm::qstatus::WARNING)
163  col = "#ffff00";
164  else if (status == dqm::qstatus::ERROR)
165  col = "#ff0000";
166  else if (status == dqm::qstatus::OTHER)
167  col = "#ffa500";
168  else
169  col = "#0000ff";
170 }
171 //
172 // -- Get Image name from ME
173 //
174 void SiPixelInformationExtractor::selectColor(string &col, vector<QReport *> &reports) {
175  int istat = 999;
176  int status = 0;
177  for (vector<QReport *>::const_iterator it = reports.begin(); it != reports.end(); it++) {
178  status = (*it)->getStatus();
179  if (status > istat)
180  istat = status;
181  }
183 }
184 //
185 // -- Get Image name from status
186 //
189  name = "images/LI_green.gif";
190  else if (status == dqm::qstatus::WARNING)
191  name = "images/LI_yellow.gif";
192  else if (status == dqm::qstatus::ERROR)
193  name = "images/LI_red.gif";
194  else if (status == dqm::qstatus::OTHER)
195  name = "images/LI_orange.gif";
196  else
197  name = "images/LI_blue.gif";
198 }
199 //
200 // -- Get Image name from ME
201 //
202 void SiPixelInformationExtractor::selectImage(string &name, vector<QReport *> &reports) {
203  int istat = 999;
204  int status = 0;
205  for (vector<QReport *>::const_iterator it = reports.begin(); it != reports.end(); it++) {
206  status = (*it)->getStatus();
207  if (status > istat)
208  istat = status;
209  }
211 }
212 
213 //------------------------------------------------------------------------------
217 void SiPixelInformationExtractor::computeStatus(MonitorElement *theME, double &colorValue, pair<double, double> &norm) {
218  double normalizationX = 1;
219  double normalizationY = 1;
220  double meanX = 0;
221  double meanY = 0;
222 
223  colorValue = 0;
224 
225  pair<double, double> normX;
226  pair<double, double> normY;
227 
228  string theMEType = getMEType(theME);
229 
230  if (theMEType.find("TH1") != string::npos) {
231  meanX = (double)theME->getMean();
232  getNormalization(theME, normX, "TH1");
233  normalizationX = fabs(normX.second - normX.first);
234  if (normalizationX == 0) {
235  normalizationX = 1.E-20;
236  }
237  colorValue = meanX / normalizationX;
238  norm.first = normX.first;
239  norm.second = normX.second;
240  }
241 
242  if (theMEType.find("TH2") != string::npos) {
243  meanX = (double)theME->getMean(1);
244  meanY = (double)theME->getMean(2);
245  getNormalization2D(theME, normX, normY, "TH2");
246  normalizationX = fabs(normX.second - normX.first);
247  normalizationY = fabs(normY.second - normY.first);
248  if (normalizationX == 0) {
249  normalizationX = 1.E-20;
250  }
251  if (normalizationY == 0) {
252  normalizationY = 1.E-20;
253  }
254  double cVX = meanX / normalizationX;
255  double cVY = meanY / normalizationY;
256  colorValue = sqrt(cVX * cVX + cVY * cVY);
257  if (normalizationX >= normalizationY) {
258  norm.first = normX.first;
259  norm.second = normX.second;
260  } else {
261  norm.first = normY.first;
262  norm.second = normY.second;
263  }
264  }
265 
266  return;
267 }
268 
269 //------------------------------------------------------------------------------
274  pair<double, double> &norm,
275  std::string theMEType) {
276  double normLow = 0;
277  double normHigh = 0;
278 
279  if (theMEType.find("TH1") != string::npos) {
280  normHigh = (double)theME->getNbinsX();
281  norm.first = normLow;
282  norm.second = normHigh;
283  }
284 }
285 
286 //------------------------------------------------------------------------------
291  pair<double, double> &normX,
292  pair<double, double> &normY,
293  std::string theMEType) {
294  double normLow = 0;
295  double normHigh = 0;
296 
297  if (theMEType.find("TH2") != string::npos) {
298  normHigh = (double)theME->getNbinsX();
299  normX.first = normLow;
300  normX.second = normHigh;
301  normHigh = (double)theME->getNbinsY();
302  normY.first = normLow;
303  normY.second = normHigh;
304  }
305 }
306 
307 //------------------------------------------------------------------------------
313  const string &mEName = mE->getName();
314 
315  int detId = 0;
316 
317  if (mEName.find("_3") != string::npos) {
318  string detIdString = mEName.substr((mEName.find_last_of('_')) + 1, 9);
319  std::istringstream isst;
320  isst.str(detIdString);
321  isst >> detId;
322  }
323  return detId;
324 }
325 
327 
329  // std::cout<<"BOOK NOISY PIXEL MEs!"<<std::endl;
330  iBooker.cd();
331  if (noiseRate_ >= 0.) {
332  iBooker.setCurrentFolder("Pixel/Barrel");
333  EventRateBarrelPixels = iBooker.book1D("barrelEventRate", "Digi event rate for all Barrel pixels", 1000, 0., 0.01);
334  EventRateBarrelPixels->setAxisTitle("Event Rate", 1);
335  EventRateBarrelPixels->setAxisTitle("Number of Pixels", 2);
336  iBooker.cd();
337  iBooker.setCurrentFolder("Pixel/Endcap");
338  EventRateEndcapPixels = iBooker.book1D("endcapEventRate", "Digi event rate for all Endcap pixels", 1000, 0., 0.01);
339  EventRateEndcapPixels->setAxisTitle("Event Rate", 1);
340  EventRateEndcapPixels->setAxisTitle("Number of Pixels", 2);
341  }
342 }
343 
345 
347  DQMStore::IGetter &iGetter,
348  bool init,
349  float noiseRate_,
350  int noiseRateDenominator_,
351  const SiPixelFedCablingMap *theCablingMap) {
352  if (init) {
353  endOfModules_ = false;
354  nevents_ = noiseRateDenominator_;
355  if (nevents_ == -1) {
356  iBooker.cd();
357  iGetter.cd();
358  iBooker.setCurrentFolder("Pixel/EventInfo");
359  iGetter.setCurrentFolder("Pixel/EventInfo");
360  nevents_ = (iGetter.get("Pixel/EventInfo/processedEvents"))->getIntValue();
361  }
362  iBooker.cd();
363  iGetter.cd();
364  myfile_.open("NoisyPixelList.txt", ios::app);
365  myfile_ << "Noise summary, ran over " << nevents_ << " events, threshold was set to " << noiseRate_ << std::endl;
366  }
367  string currDir = iBooker.pwd();
368  string dname = currDir.substr(currDir.find_last_of('/') + 1);
369 
370  if (dname.find("Module_") != string::npos) {
371  vector<string> meVec = iGetter.getMEs();
372  for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
373  string full_path = currDir + "/" + (*it);
374  if (full_path.find("hitmap_siPixelDigis") != string::npos) {
375  MonitorElement *me = iGetter.get(full_path);
376  if (!me)
377  continue;
378  int detid = getDetId(me);
379  int pixcol = -1;
380  int pixrow = -1;
381  std::vector<std::pair<std::pair<int, int>, float>> noisyPixelsInModule;
382  TH2F *hothisto = me->getTH2F();
383  if (hothisto) {
384  for (int i = 1; i != hothisto->GetNbinsX() + 1; i++) {
385  for (int j = 1; j != hothisto->GetNbinsY() + 1; j++) {
386  float value = (hothisto->GetBinContent(i, j)) / float(nevents_);
387  if (me->getPathname().find("Barrel") != string::npos) {
388  EventRateBarrelPixels = iGetter.get("Pixel/Barrel/barrelEventRate");
391  } else if (me->getPathname().find("Endcap") != string::npos) {
392  EventRateEndcapPixels = iGetter.get("Pixel/Endcap/endcapEventRate");
395  }
396  if (value > noiseRate_) {
397  pixcol = i - 1;
398  pixrow = j - 1;
399 
400  std::pair<int, int> address(pixcol, pixrow);
401  std::pair<std::pair<int, int>, float> PixelStats(address, value);
402  noisyPixelsInModule.push_back(PixelStats);
403  }
404  }
405  }
406  }
407  noisyDetIds_[detid] = noisyPixelsInModule;
408  }
409  }
410  }
411  vector<string> subDirVec = iGetter.getSubdirs();
412  for (vector<string>::const_iterator ic = subDirVec.begin(); ic != subDirVec.end(); ic++) {
413  if ((*ic).find("AdditionalPixelErrors") != string::npos)
414  continue;
415  iGetter.cd(*ic);
416  iBooker.cd(*ic);
417  init = false;
418  findNoisyPixels(iBooker, iGetter, init, noiseRate_, noiseRateDenominator_, theCablingMap);
419  iBooker.goUp();
420  iGetter.setCurrentFolder(iBooker.pwd());
421  }
422 
423  if (iBooker.pwd().find("EventInfo") != string::npos)
424  endOfModules_ = true;
425 
426  if (!endOfModules_)
427  return;
428  if (currDir == "Pixel/EventInfo/reportSummaryContents") {
429  std::vector<std::pair<sipixelobjects::DetectorIndex, double>> pixelvec;
430  std::map<uint32_t, int> myfedmap;
431  std::map<uint32_t, std::string> mynamemap;
432  int realfedID = -1;
433  int n_noisyrocs_all = 0;
434  int n_noisyrocs_barrel = 0;
435  int n_noisyrocs_endcap = 0;
436  int n_verynoisyrocs_all = 0;
437  int n_verynoisyrocs_barrel = 0;
438  int n_verynoisyrocs_endcap = 0;
439 
440  for (int fid = 0; fid < 40; fid++) {
441  for (std::map<uint32_t, std::vector<std::pair<std::pair<int, int>, float>>>::const_iterator it =
442  noisyDetIds_.begin();
443  it != noisyDetIds_.end();
444  it++) {
445  uint32_t detid = (*it).first;
446  std::vector<std::pair<std::pair<int, int>, float>> noisyPixels = (*it).second;
447  // now convert into online conventions:
448  for (int fedid = 0; fedid <= 40; ++fedid) {
449  SiPixelFrameConverter converter(theCablingMap, fedid);
450  uint32_t newDetId = detid;
451  if (converter.hasDetUnit(newDetId)) {
452  realfedID = fedid;
453  break;
454  }
455  }
456  if (fid == realfedID) {
457  if (realfedID == -1)
458  continue;
459  DetId detId(detid);
460  uint32_t detSubId = detId.subdetId();
462  bool HalfModule = false;
463  if (detSubId == 2) { // FPIX
464  PixelEndcapName nameworker(detid);
465  outputname = nameworker.name();
466  } else if (detSubId == 1) { // BPIX
467  PixelBarrelName nameworker(detid);
468  outputname = nameworker.name();
469  HalfModule = nameworker.isHalfModule();
470 
471  } else {
472  continue;
473  }
474  std::map<int, int> myrocmap;
475  myfedmap[detid] = realfedID;
476  mynamemap[detid] = outputname;
477 
478  for (std::vector<std::pair<std::pair<int, int>, float>>::const_iterator pxl = noisyPixels.begin();
479  pxl != noisyPixels.end();
480  pxl++) {
481  std::pair<int, int> offlineaddress = (*pxl).first;
482  float Noise_frac = (*pxl).second;
483  int offlineColumn = offlineaddress.first;
484  int offlineRow = offlineaddress.second;
485 
487  SiPixelFrameConverter formatter(theCablingMap, realfedID);
488  sipixelobjects::DetectorIndex detector = {detid, offlineRow, offlineColumn};
489  formatter.toCabling(cabling, detector);
490  // cabling should now contain cabling.roc and cabling.dcol and
491  // cabling.pxid however, the coordinates now need to be converted
492  // from dcl,pxid to the row,col coordinates used in the calibration
493  // info
495  loc.dcol = cabling.dcol;
496  loc.pxid = cabling.pxid;
497 
498  sipixelobjects::LocalPixel locpixel(loc);
499  assert(realfedID >= 0);
500  assert(cabling.link >= 0);
501  assert(cabling.roc >= 0);
502  sipixelobjects::CablingPathToDetUnit path = {static_cast<unsigned int>(realfedID),
503  static_cast<unsigned int>(cabling.link),
504  static_cast<unsigned int>(cabling.roc)};
505  const sipixelobjects::PixelROC *theRoc = theCablingMap->findItem(path);
506  // END of FIX
507 
508  int onlineColumn = locpixel.rocCol();
509  int onlineRow = locpixel.rocRow();
510  myrocmap[(theRoc->idInDetUnit())]++;
511 
512  // ROC numbers in the barrel go from 8 to 15 instead of 0 to 7 in
513  // half modules. This is a fix to get the roc number, and add 8 to
514  // it if: it's a Barrel module AND on the minus side AND a Half
515  // module
516 
517  int rocnumber = -1;
518 
519  if ((detSubId == 1) && (outputname.find("mO") != string::npos || outputname.find("mI") != string::npos) &&
520  (HalfModule)) {
521  rocnumber = theRoc->idInDetUnit() + 8;
522  } else {
523  rocnumber = theRoc->idInDetUnit();
524  }
525 
526  myfile_ << "NAME: " << outputname << " , DETID: " << detid << " , OFFLINE: col,row: " << offlineColumn
527  << "," << offlineRow << " \t , ONLINE: roc,col,row: " << rocnumber << "," << onlineColumn << ","
528  << onlineRow << " \t , fed,dcol,pixid,link: " << realfedID << "," << loc.dcol << "," << loc.pxid
529  << "," << cabling.link << ", Noise fraction: " << Noise_frac << std::endl;
530  }
531  for (std::map<int, int>::const_iterator nrc = myrocmap.begin(); nrc != myrocmap.end(); nrc++) {
532  if ((*nrc).second > 0) {
533  n_noisyrocs_all++;
534  if (detSubId == 2) {
535  n_noisyrocs_endcap++;
536  } else if (detSubId == 1) {
537  n_noisyrocs_barrel++;
538  }
539  }
540  if ((*nrc).second > 40) {
541  n_verynoisyrocs_all++;
542  if (detSubId == 2) {
543  n_verynoisyrocs_endcap++;
544  } else if (detSubId == 1) {
545  n_verynoisyrocs_barrel++;
546  }
547  }
548  }
549  }
550  }
551  }
552  myfile_ << "There are " << n_noisyrocs_all
553  << " noisy ROCs (ROCs with at least 1 noisy pixel) in the entire "
554  "detector. "
555  << n_noisyrocs_endcap << " are in the FPIX and " << n_noisyrocs_barrel << " are in the BPIX. " << endl;
556  myfile_ << "There are " << n_verynoisyrocs_all
557  << " highly noisy ROCs (ROCs with at least 10% of all pixels "
558  "passing the noise threshold) in the entire detector. "
559  << n_verynoisyrocs_endcap << " are in the FPIX and " << n_verynoisyrocs_barrel << " are in the BPIX. "
560  << endl;
561  }
562  myfile_.close();
563  return;
564 }
SiPixelInformationExtractor(bool offlineXMLfile)
Constructor of the SiPixelInformationExtractor class.
void getNormalization(MonitorElement *mE, std::pair< double, double > &norm, std::string theMEType)
(Documentation under construction).
static const int OTHER
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
virtual std::vector< std::string > getMEs() const
Definition: DQMStore.cc:759
virtual std::string pwd()
Definition: DQMStore.cc:20
int toCabling(sipixelobjects::ElectronicIndex &cabling, const sipixelobjects::DetectorIndex &detector) const
void computeStatus(MonitorElement *mE, double &colorValue, std::pair< double, double > &norm)
(Documentation under construction).
static const int WARNING
assert(be >=bs)
bool hasItem(std::multimap< std::string, std::string > &req_map, std::string item_name)
(Documentation under construction).
identify pixel inside single ROC
Definition: LocalPixel.h:7
void readConfiguration()
Read Configuration File.
void Fill(long long x)
void findNoisyPixels(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, bool init, float noiseRate, int noiseRateDenominator, const SiPixelFedCablingMap *theCablingMap)
bool isHalfModule() const
full or half module
std::string name() const override
from base class
T sqrt(T t)
Definition: SSEVec.h:23
void bookNoisyPixels(DQMStore::IBooker &iBooker, float noiseRate, bool Tier0Flag)
const sipixelobjects::PixelROC * findItem(const sipixelobjects::CablingPathToDetUnit &path) const final
void selectImage(std::string &name, int status)
Definition: value.py:1
void getNormalization2D(MonitorElement *mE, std::pair< double, double > &normX, std::pair< double, double > &normY, std::string theMEType)
(Documentation under construction).
std::string getMEType(MonitorElement *mE)
virtual int getNbinsY() const
get # of bins in Y-axis
double collumn and pixel ID in double collumn representation
Definition: LocalPixel.h:19
Log< level::Info, false > LogInfo
Definition: init.py:1
std::map< uint32_t, std::vector< std::pair< std::pair< int, int >, float > > > noisyDetIds_
Definition: DetId.h:17
std::string name() const override
from base class
std::string getItemValue(const std::multimap< std::string, std::string > &req_map, std::string item_name)
(Documentation under construction).
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:712
void selectColor(std::string &col, int status)
void getItemList(const std::multimap< std::string, std::string > &req_map, std::string item_name, std::vector< std::string > &items)
(Documentation under construction).
const std::string & getName() const
get name of ME
virtual double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
int getDetId(MonitorElement *mE)
(Documentation under construction).
HLT enums.
col
Definition: cuy.py:1009
static const int STATUS_OK
~SiPixelInformationExtractor()
Destructor of the SiPixelInformationExtractor class.
virtual int getNbinsX() const
get # of bins in X-axis
TObject * getRootObject() const override
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
unsigned int idInDetUnit() const
id of this ROC in DetUnit etermined by token path
Definition: PixelROC.h:37
static const int ERROR
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
virtual DQM_DEPRECATED std::vector< std::string > getSubdirs() const
Definition: DQMStore.cc:739