CMS 3D CMS Logo

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