File indexing completed on 2024-04-06 12:08:19
0001
0002
0003
0004
0005
0006
0007 #include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
0008 #include "DQM/SiPixelMonitorClient/interface/ANSIColors.h"
0009 #include "DQM/SiPixelMonitorClient/interface/SiPixelEDAClient.h"
0010 #include "DQM/SiPixelMonitorClient/interface/SiPixelInformationExtractor.h"
0011 #include "DQM/SiPixelMonitorClient/interface/SiPixelUtility.h"
0012
0013 #include "DQMServices/Core/interface/DQMStore.h"
0014
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "FWCore/ParameterSet/interface/FileInPath.h"
0017
0018 #include "DataFormats/DetId/interface/DetId.h"
0019 #include "DataFormats/GeometrySurface/interface/Surface.h"
0020 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0021 #include "DataFormats/SiPixelDetId/interface/PixelBarrelNameUpgrade.h"
0022 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0023 #include "DataFormats/SiPixelDetId/interface/PixelEndcapNameUpgrade.h"
0024 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0025
0026 #include "CondFormats/SiPixelObjects/interface/DetectorIndex.h"
0027 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h"
0028
0029 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0030 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0031 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0032 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0033 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
0034
0035 #include "Rtypes.h"
0036 #include "TAxis.h"
0037 #include "TClass.h"
0038 #include "TH1F.h"
0039 #include "TH2F.h"
0040 #include "TImage.h"
0041 #include "TImageDump.h"
0042 #include "TPad.h"
0043 #include "TPaveLabel.h"
0044 #include "TPaveText.h"
0045 #include "TProfile.h"
0046 #include "TROOT.h"
0047 #include "TRandom.h"
0048 #include "TStopwatch.h"
0049 #include "TString.h"
0050 #include "TStyle.h"
0051 #include "TSystem.h"
0052 #include "TText.h"
0053
0054 #include <cmath>
0055 #include <iostream>
0056 #include <map>
0057
0058 #include <cstdlib> // for free() - Root can allocate with malloc() - sigh...
0059
0060 using namespace std;
0061 using namespace edm;
0062
0063
0064
0065
0066
0067 SiPixelInformationExtractor::SiPixelInformationExtractor(bool offlineXMLfile) : offlineXMLfile_(offlineXMLfile) {
0068 edm::LogInfo("SiPixelInformationExtractor") << " Creating SiPixelInformationExtractor "
0069 << "\n";
0070
0071 readReference_ = false;
0072 }
0073
0074
0075
0076
0077
0078 SiPixelInformationExtractor::~SiPixelInformationExtractor() {
0079 edm::LogInfo("SiPixelInformationExtractor") << " Deleting SiPixelInformationExtractor "
0080 << "\n";
0081 }
0082
0083
0084
0085
0086
0087 void SiPixelInformationExtractor::readConfiguration() {}
0088
0089
0090
0091
0092 std::string SiPixelInformationExtractor::getMEType(MonitorElement *theMe) {
0093 string qtype = theMe->getRootObject()->IsA()->GetName();
0094 if (qtype.find("TH1") != string::npos) {
0095 return "TH1";
0096 } else if (qtype.find("TH2") != string::npos) {
0097 return "TH2";
0098 } else if (qtype.find("TH3") != string::npos) {
0099 return "TH3";
0100 }
0101 return "TH1";
0102 }
0103
0104
0105
0106
0107
0108
0109 void SiPixelInformationExtractor::getItemList(const multimap<string, string> &req_map,
0110 string item_name,
0111 vector<string> &items) {
0112 items.clear();
0113 for (multimap<string, string>::const_iterator it = req_map.begin(); it != req_map.end(); it++) {
0114 if (it->first == item_name) {
0115 items.push_back(it->second);
0116 }
0117 }
0118 }
0119
0120
0121
0122
0123
0124
0125 bool SiPixelInformationExtractor::hasItem(multimap<string, string> &req_map, string item_name) {
0126 multimap<string, string>::iterator pos = req_map.find(item_name);
0127 if (pos != req_map.end())
0128 return true;
0129 return false;
0130 }
0131
0132
0133
0134
0135
0136
0137 std::string SiPixelInformationExtractor::getItemValue(const std::multimap<std::string, std::string> &req_map,
0138 std::string item_name) {
0139 std::multimap<std::string, std::string>::const_iterator pos = req_map.find(item_name);
0140 std::string value = " ";
0141 if (pos != req_map.end()) {
0142 value = pos->second;
0143 }
0144 return value;
0145 }
0146 std::string SiPixelInformationExtractor::getItemValue(std::multimap<std::string, std::string> &req_map,
0147 std::string item_name) {
0148 std::multimap<std::string, std::string>::iterator pos = req_map.find(item_name);
0149 std::string value = " ";
0150 if (pos != req_map.end()) {
0151 value = pos->second;
0152 }
0153 return value;
0154 }
0155
0156
0157
0158
0159 void SiPixelInformationExtractor::selectColor(string &col, int status) {
0160 if (status == dqm::qstatus::STATUS_OK)
0161 col = "#00ff00";
0162 else if (status == dqm::qstatus::WARNING)
0163 col = "#ffff00";
0164 else if (status == dqm::qstatus::ERROR)
0165 col = "#ff0000";
0166 else if (status == dqm::qstatus::OTHER)
0167 col = "#ffa500";
0168 else
0169 col = "#0000ff";
0170 }
0171
0172
0173
0174 void SiPixelInformationExtractor::selectColor(string &col, vector<QReport *> &reports) {
0175 int istat = 999;
0176 int status = 0;
0177 for (vector<QReport *>::const_iterator it = reports.begin(); it != reports.end(); it++) {
0178 status = (*it)->getStatus();
0179 if (status > istat)
0180 istat = status;
0181 }
0182 selectColor(col, status);
0183 }
0184
0185
0186
0187 void SiPixelInformationExtractor::selectImage(string &name, int status) {
0188 if (status == dqm::qstatus::STATUS_OK)
0189 name = "images/LI_green.gif";
0190 else if (status == dqm::qstatus::WARNING)
0191 name = "images/LI_yellow.gif";
0192 else if (status == dqm::qstatus::ERROR)
0193 name = "images/LI_red.gif";
0194 else if (status == dqm::qstatus::OTHER)
0195 name = "images/LI_orange.gif";
0196 else
0197 name = "images/LI_blue.gif";
0198 }
0199
0200
0201
0202 void SiPixelInformationExtractor::selectImage(string &name, vector<QReport *> &reports) {
0203 int istat = 999;
0204 int status = 0;
0205 for (vector<QReport *>::const_iterator it = reports.begin(); it != reports.end(); it++) {
0206 status = (*it)->getStatus();
0207 if (status > istat)
0208 istat = status;
0209 }
0210 selectImage(name, status);
0211 }
0212
0213
0214
0215
0216
0217 void SiPixelInformationExtractor::computeStatus(MonitorElement *theME, double &colorValue, pair<double, double> &norm) {
0218 double normalizationX = 1;
0219 double normalizationY = 1;
0220 double meanX = 0;
0221 double meanY = 0;
0222
0223 colorValue = 0;
0224
0225 pair<double, double> normX;
0226 pair<double, double> normY;
0227
0228 string theMEType = getMEType(theME);
0229
0230 if (theMEType.find("TH1") != string::npos) {
0231 meanX = (double)theME->getMean();
0232 getNormalization(theME, normX, "TH1");
0233 normalizationX = fabs(normX.second - normX.first);
0234 if (normalizationX == 0) {
0235 normalizationX = 1.E-20;
0236 }
0237 colorValue = meanX / normalizationX;
0238 norm.first = normX.first;
0239 norm.second = normX.second;
0240 }
0241
0242 if (theMEType.find("TH2") != string::npos) {
0243 meanX = (double)theME->getMean(1);
0244 meanY = (double)theME->getMean(2);
0245 getNormalization2D(theME, normX, normY, "TH2");
0246 normalizationX = fabs(normX.second - normX.first);
0247 normalizationY = fabs(normY.second - normY.first);
0248 if (normalizationX == 0) {
0249 normalizationX = 1.E-20;
0250 }
0251 if (normalizationY == 0) {
0252 normalizationY = 1.E-20;
0253 }
0254 double cVX = meanX / normalizationX;
0255 double cVY = meanY / normalizationY;
0256 colorValue = sqrt(cVX * cVX + cVY * cVY);
0257 if (normalizationX >= normalizationY) {
0258 norm.first = normX.first;
0259 norm.second = normX.second;
0260 } else {
0261 norm.first = normY.first;
0262 norm.second = normY.second;
0263 }
0264 }
0265
0266 return;
0267 }
0268
0269
0270
0271
0272
0273 void SiPixelInformationExtractor::getNormalization(MonitorElement *theME,
0274 pair<double, double> &norm,
0275 std::string theMEType) {
0276 double normLow = 0;
0277 double normHigh = 0;
0278
0279 if (theMEType.find("TH1") != string::npos) {
0280 normHigh = (double)theME->getNbinsX();
0281 norm.first = normLow;
0282 norm.second = normHigh;
0283 }
0284 }
0285
0286
0287
0288
0289
0290 void SiPixelInformationExtractor::getNormalization2D(MonitorElement *theME,
0291 pair<double, double> &normX,
0292 pair<double, double> &normY,
0293 std::string theMEType) {
0294 double normLow = 0;
0295 double normHigh = 0;
0296
0297 if (theMEType.find("TH2") != string::npos) {
0298 normHigh = (double)theME->getNbinsX();
0299 normX.first = normLow;
0300 normX.second = normHigh;
0301 normHigh = (double)theME->getNbinsY();
0302 normY.first = normLow;
0303 normY.second = normHigh;
0304 }
0305 }
0306
0307
0308
0309
0310
0311
0312 int SiPixelInformationExtractor::getDetId(MonitorElement *mE) {
0313 const string &mEName = mE->getName();
0314
0315 int detId = 0;
0316
0317 if (mEName.find("_3") != string::npos) {
0318 string detIdString = mEName.substr((mEName.find_last_of('_')) + 1, 9);
0319 std::istringstream isst;
0320 isst.str(detIdString);
0321 isst >> detId;
0322 }
0323 return detId;
0324 }
0325
0326
0327
0328 void SiPixelInformationExtractor::bookNoisyPixels(DQMStore::IBooker &iBooker, float noiseRate_, bool Tier0Flag) {
0329
0330 iBooker.cd();
0331 if (noiseRate_ >= 0.) {
0332 iBooker.setCurrentFolder("Pixel/Barrel");
0333 EventRateBarrelPixels = iBooker.book1D("barrelEventRate", "Digi event rate for all Barrel pixels", 1000, 0., 0.01);
0334 EventRateBarrelPixels->setAxisTitle("Event Rate", 1);
0335 EventRateBarrelPixels->setAxisTitle("Number of Pixels", 2);
0336 iBooker.cd();
0337 iBooker.setCurrentFolder("Pixel/Endcap");
0338 EventRateEndcapPixels = iBooker.book1D("endcapEventRate", "Digi event rate for all Endcap pixels", 1000, 0., 0.01);
0339 EventRateEndcapPixels->setAxisTitle("Event Rate", 1);
0340 EventRateEndcapPixels->setAxisTitle("Number of Pixels", 2);
0341 }
0342 }
0343
0344
0345
0346 void SiPixelInformationExtractor::findNoisyPixels(DQMStore::IBooker &iBooker,
0347 DQMStore::IGetter &iGetter,
0348 bool init,
0349 float noiseRate_,
0350 int noiseRateDenominator_,
0351 const SiPixelFedCablingMap *theCablingMap) {
0352 if (init) {
0353 endOfModules_ = false;
0354 nevents_ = noiseRateDenominator_;
0355 if (nevents_ == -1) {
0356 iBooker.cd();
0357 iGetter.cd();
0358 iBooker.setCurrentFolder("Pixel/EventInfo");
0359 iGetter.setCurrentFolder("Pixel/EventInfo");
0360 nevents_ = (iGetter.get("Pixel/EventInfo/processedEvents"))->getIntValue();
0361 }
0362 iBooker.cd();
0363 iGetter.cd();
0364 myfile_.open("NoisyPixelList.txt", ios::app);
0365 myfile_ << "Noise summary, ran over " << nevents_ << " events, threshold was set to " << noiseRate_ << std::endl;
0366 }
0367 string currDir = iBooker.pwd();
0368 string dname = currDir.substr(currDir.find_last_of('/') + 1);
0369
0370 if (dname.find("Module_") != string::npos) {
0371 vector<string> meVec = iGetter.getMEs();
0372 for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
0373 string full_path = currDir + "/" + (*it);
0374 if (full_path.find("hitmap_siPixelDigis") != string::npos) {
0375 MonitorElement *me = iGetter.get(full_path);
0376 if (!me)
0377 continue;
0378 int detid = getDetId(me);
0379 int pixcol = -1;
0380 int pixrow = -1;
0381 std::vector<std::pair<std::pair<int, int>, float>> noisyPixelsInModule;
0382 TH2F *hothisto = me->getTH2F();
0383 if (hothisto) {
0384 for (int i = 1; i != hothisto->GetNbinsX() + 1; i++) {
0385 for (int j = 1; j != hothisto->GetNbinsY() + 1; j++) {
0386 float value = (hothisto->GetBinContent(i, j)) / float(nevents_);
0387 if (me->getPathname().find("Barrel") != string::npos) {
0388 EventRateBarrelPixels = iGetter.get("Pixel/Barrel/barrelEventRate");
0389 if (EventRateBarrelPixels)
0390 EventRateBarrelPixels->Fill(value);
0391 } else if (me->getPathname().find("Endcap") != string::npos) {
0392 EventRateEndcapPixels = iGetter.get("Pixel/Endcap/endcapEventRate");
0393 if (EventRateEndcapPixels)
0394 EventRateEndcapPixels->Fill(value);
0395 }
0396 if (value > noiseRate_) {
0397 pixcol = i - 1;
0398 pixrow = j - 1;
0399
0400 std::pair<int, int> address(pixcol, pixrow);
0401 std::pair<std::pair<int, int>, float> PixelStats(address, value);
0402 noisyPixelsInModule.push_back(PixelStats);
0403 }
0404 }
0405 }
0406 }
0407 noisyDetIds_[detid] = noisyPixelsInModule;
0408 }
0409 }
0410 }
0411 vector<string> subDirVec = iGetter.getSubdirs();
0412 for (vector<string>::const_iterator ic = subDirVec.begin(); ic != subDirVec.end(); ic++) {
0413 if ((*ic).find("AdditionalPixelErrors") != string::npos)
0414 continue;
0415 iGetter.cd(*ic);
0416 iBooker.cd(*ic);
0417 init = false;
0418 findNoisyPixels(iBooker, iGetter, init, noiseRate_, noiseRateDenominator_, theCablingMap);
0419 iBooker.goUp();
0420 iGetter.setCurrentFolder(iBooker.pwd());
0421 }
0422
0423 if (iBooker.pwd().find("EventInfo") != string::npos)
0424 endOfModules_ = true;
0425
0426 if (!endOfModules_)
0427 return;
0428 if (currDir == "Pixel/EventInfo/reportSummaryContents") {
0429 std::vector<std::pair<sipixelobjects::DetectorIndex, double>> pixelvec;
0430 std::map<uint32_t, int> myfedmap;
0431 std::map<uint32_t, std::string> mynamemap;
0432 int realfedID = -1;
0433 int n_noisyrocs_all = 0;
0434 int n_noisyrocs_barrel = 0;
0435 int n_noisyrocs_endcap = 0;
0436 int n_verynoisyrocs_all = 0;
0437 int n_verynoisyrocs_barrel = 0;
0438 int n_verynoisyrocs_endcap = 0;
0439
0440 for (int fid = 0; fid < 40; fid++) {
0441 for (std::map<uint32_t, std::vector<std::pair<std::pair<int, int>, float>>>::const_iterator it =
0442 noisyDetIds_.begin();
0443 it != noisyDetIds_.end();
0444 it++) {
0445 uint32_t detid = (*it).first;
0446 std::vector<std::pair<std::pair<int, int>, float>> noisyPixels = (*it).second;
0447
0448 for (int fedid = 0; fedid <= 40; ++fedid) {
0449 SiPixelFrameConverter converter(theCablingMap, fedid);
0450 uint32_t newDetId = detid;
0451 if (converter.hasDetUnit(newDetId)) {
0452 realfedID = fedid;
0453 break;
0454 }
0455 }
0456 if (fid == realfedID) {
0457 if (realfedID == -1)
0458 continue;
0459 DetId detId(detid);
0460 uint32_t detSubId = detId.subdetId();
0461 std::string outputname;
0462 bool HalfModule = false;
0463 if (detSubId == 2) {
0464 PixelEndcapName nameworker(detid);
0465 outputname = nameworker.name();
0466 } else if (detSubId == 1) {
0467 PixelBarrelName nameworker(detid);
0468 outputname = nameworker.name();
0469 HalfModule = nameworker.isHalfModule();
0470
0471 } else {
0472 continue;
0473 }
0474 std::map<int, int> myrocmap;
0475 myfedmap[detid] = realfedID;
0476 mynamemap[detid] = outputname;
0477
0478 for (std::vector<std::pair<std::pair<int, int>, float>>::const_iterator pxl = noisyPixels.begin();
0479 pxl != noisyPixels.end();
0480 pxl++) {
0481 std::pair<int, int> offlineaddress = (*pxl).first;
0482 float Noise_frac = (*pxl).second;
0483 int offlineColumn = offlineaddress.first;
0484 int offlineRow = offlineaddress.second;
0485
0486 sipixelobjects::ElectronicIndex cabling;
0487 SiPixelFrameConverter formatter(theCablingMap, realfedID);
0488 sipixelobjects::DetectorIndex detector = {detid, offlineRow, offlineColumn};
0489 formatter.toCabling(cabling, detector);
0490
0491
0492
0493
0494 sipixelobjects::LocalPixel::DcolPxid loc;
0495 loc.dcol = cabling.dcol;
0496 loc.pxid = cabling.pxid;
0497
0498 sipixelobjects::LocalPixel locpixel(loc);
0499 assert(realfedID >= 0);
0500 assert(cabling.link >= 0);
0501 assert(cabling.roc >= 0);
0502 sipixelobjects::CablingPathToDetUnit path = {static_cast<unsigned int>(realfedID),
0503 static_cast<unsigned int>(cabling.link),
0504 static_cast<unsigned int>(cabling.roc)};
0505 const sipixelobjects::PixelROC *theRoc = theCablingMap->findItem(path);
0506
0507
0508 int onlineColumn = locpixel.rocCol();
0509 int onlineRow = locpixel.rocRow();
0510 myrocmap[(theRoc->idInDetUnit())]++;
0511
0512
0513
0514
0515
0516
0517 int rocnumber = -1;
0518
0519 if ((detSubId == 1) && (outputname.find("mO") != string::npos || outputname.find("mI") != string::npos) &&
0520 (HalfModule)) {
0521 rocnumber = theRoc->idInDetUnit() + 8;
0522 } else {
0523 rocnumber = theRoc->idInDetUnit();
0524 }
0525
0526 myfile_ << "NAME: " << outputname << " , DETID: " << detid << " , OFFLINE: col,row: " << offlineColumn
0527 << "," << offlineRow << " \t , ONLINE: roc,col,row: " << rocnumber << "," << onlineColumn << ","
0528 << onlineRow << " \t , fed,dcol,pixid,link: " << realfedID << "," << loc.dcol << "," << loc.pxid
0529 << "," << cabling.link << ", Noise fraction: " << Noise_frac << std::endl;
0530 }
0531 for (std::map<int, int>::const_iterator nrc = myrocmap.begin(); nrc != myrocmap.end(); nrc++) {
0532 if ((*nrc).second > 0) {
0533 n_noisyrocs_all++;
0534 if (detSubId == 2) {
0535 n_noisyrocs_endcap++;
0536 } else if (detSubId == 1) {
0537 n_noisyrocs_barrel++;
0538 }
0539 }
0540 if ((*nrc).second > 40) {
0541 n_verynoisyrocs_all++;
0542 if (detSubId == 2) {
0543 n_verynoisyrocs_endcap++;
0544 } else if (detSubId == 1) {
0545 n_verynoisyrocs_barrel++;
0546 }
0547 }
0548 }
0549 }
0550 }
0551 }
0552 myfile_ << "There are " << n_noisyrocs_all
0553 << " noisy ROCs (ROCs with at least 1 noisy pixel) in the entire "
0554 "detector. "
0555 << n_noisyrocs_endcap << " are in the FPIX and " << n_noisyrocs_barrel << " are in the BPIX. " << endl;
0556 myfile_ << "There are " << n_verynoisyrocs_all
0557 << " highly noisy ROCs (ROCs with at least 10% of all pixels "
0558 "passing the noise threshold) in the entire detector. "
0559 << n_verynoisyrocs_endcap << " are in the FPIX and " << n_verynoisyrocs_barrel << " are in the BPIX. "
0560 << endl;
0561 }
0562 myfile_.close();
0563 return;
0564 }