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 counter = 0;
434  int n_noisyrocs_all = 0;
435  int n_noisyrocs_barrel = 0;
436  int n_noisyrocs_endcap = 0;
437  int n_verynoisyrocs_all = 0;
438  int n_verynoisyrocs_barrel = 0;
439  int n_verynoisyrocs_endcap = 0;
440 
441  for (int fid = 0; fid < 40; fid++) {
442  for (std::map<uint32_t, std::vector<std::pair<std::pair<int, int>, float>>>::const_iterator it =
443  noisyDetIds_.begin();
444  it != noisyDetIds_.end();
445  it++) {
446  uint32_t detid = (*it).first;
447  std::vector<std::pair<std::pair<int, int>, float>> noisyPixels = (*it).second;
448  // now convert into online conventions:
449  for (int fedid = 0; fedid <= 40; ++fedid) {
450  SiPixelFrameConverter converter(theCablingMap, fedid);
451  uint32_t newDetId = detid;
452  if (converter.hasDetUnit(newDetId)) {
453  realfedID = fedid;
454  break;
455  }
456  }
457  if (fid == realfedID) {
458  if (realfedID == -1)
459  continue;
460  DetId detId(detid);
461  uint32_t detSubId = detId.subdetId();
463  bool HalfModule = false;
464  if (detSubId == 2) { // FPIX
465  PixelEndcapName nameworker(detid);
466  outputname = nameworker.name();
467  } else if (detSubId == 1) { // BPIX
468  PixelBarrelName nameworker(detid);
469  outputname = nameworker.name();
470  HalfModule = nameworker.isHalfModule();
471 
472  } else {
473  continue;
474  }
475  std::map<int, int> myrocmap;
476  myfedmap[detid] = realfedID;
477  mynamemap[detid] = outputname;
478 
479  for (std::vector<std::pair<std::pair<int, int>, float>>::const_iterator pxl = noisyPixels.begin();
480  pxl != noisyPixels.end();
481  pxl++) {
482  std::pair<int, int> offlineaddress = (*pxl).first;
483  float Noise_frac = (*pxl).second;
484  int offlineColumn = offlineaddress.first;
485  int offlineRow = offlineaddress.second;
486  counter++;
487 
489  SiPixelFrameConverter formatter(theCablingMap, realfedID);
490  sipixelobjects::DetectorIndex detector = {detid, offlineRow, offlineColumn};
491  formatter.toCabling(cabling, detector);
492  // cabling should now contain cabling.roc and cabling.dcol and
493  // cabling.pxid however, the coordinates now need to be converted
494  // from dcl,pxid to the row,col coordinates used in the calibration
495  // info
497  loc.dcol = cabling.dcol;
498  loc.pxid = cabling.pxid;
499 
500  sipixelobjects::LocalPixel locpixel(loc);
501  assert(realfedID >= 0);
502  assert(cabling.link >= 0);
503  assert(cabling.roc >= 0);
504  sipixelobjects::CablingPathToDetUnit path = {static_cast<unsigned int>(realfedID),
505  static_cast<unsigned int>(cabling.link),
506  static_cast<unsigned int>(cabling.roc)};
507  const sipixelobjects::PixelROC *theRoc = theCablingMap->findItem(path);
508  // END of FIX
509 
510  int onlineColumn = locpixel.rocCol();
511  int onlineRow = locpixel.rocRow();
512  myrocmap[(theRoc->idInDetUnit())]++;
513 
514  // ROC numbers in the barrel go from 8 to 15 instead of 0 to 7 in
515  // half modules. This is a fix to get the roc number, and add 8 to
516  // it if: it's a Barrel module AND on the minus side AND a Half
517  // module
518 
519  int rocnumber = -1;
520 
521  if ((detSubId == 1) && (outputname.find("mO") != string::npos || outputname.find("mI") != string::npos) &&
522  (HalfModule)) {
523  rocnumber = theRoc->idInDetUnit() + 8;
524  } else {
525  rocnumber = theRoc->idInDetUnit();
526  }
527 
528  myfile_ << "NAME: " << outputname << " , DETID: " << detid << " , OFFLINE: col,row: " << offlineColumn
529  << "," << offlineRow << " \t , ONLINE: roc,col,row: " << rocnumber << "," << onlineColumn << ","
530  << onlineRow << " \t , fed,dcol,pixid,link: " << realfedID << "," << loc.dcol << "," << loc.pxid
531  << "," << cabling.link << ", Noise fraction: " << Noise_frac << std::endl;
532  }
533  for (std::map<int, int>::const_iterator nrc = myrocmap.begin(); nrc != myrocmap.end(); nrc++) {
534  if ((*nrc).second > 0) {
535  n_noisyrocs_all++;
536  if (detSubId == 2) {
537  n_noisyrocs_endcap++;
538  } else if (detSubId == 1) {
539  n_noisyrocs_barrel++;
540  }
541  }
542  if ((*nrc).second > 40) {
543  n_verynoisyrocs_all++;
544  if (detSubId == 2) {
545  n_verynoisyrocs_endcap++;
546  } else if (detSubId == 1) {
547  n_verynoisyrocs_barrel++;
548  }
549  }
550  }
551  }
552  }
553  }
554  myfile_ << "There are " << n_noisyrocs_all
555  << " noisy ROCs (ROCs with at least 1 noisy pixel) in the entire "
556  "detector. "
557  << n_noisyrocs_endcap << " are in the FPIX and " << n_noisyrocs_barrel << " are in the BPIX. " << endl;
558  myfile_ << "There are " << n_verynoisyrocs_all
559  << " highly noisy ROCs (ROCs with at least 10% of all pixels "
560  "passing the noise threshold) in the entire detector. "
561  << n_verynoisyrocs_endcap << " are in the FPIX and " << n_verynoisyrocs_barrel << " are in the BPIX. "
562  << endl;
563  }
564  myfile_.close();
565  return;
566 }
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:737
virtual std::string pwd()
Definition: DQMStore.cc:20
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:19
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)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
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:690
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:717