File indexing completed on 2024-09-07 04:35:29
0001 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0002 #include "CondCore/Utilities/interface/PayloadInspector.h"
0003 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0004 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0005 #include "CondCore/EcalPlugins/plugins/EcalDrawUtils.h"
0006 #include "FWCore/ParameterSet/interface/FileInPath.h"
0007
0008
0009 #include "CondFormats/EcalObjects/interface/EcalTPGStripStatus.h"
0010
0011 #include "TH2F.h"
0012 #include "TCanvas.h"
0013 #include "TStyle.h"
0014 #include "TLine.h"
0015 #include "TLatex.h"
0016
0017 #include <string>
0018 #include <array>
0019 #include <memory>
0020
0021 namespace {
0022 enum { NTCC = 108, NTower = 28, NStrip = 5, NXtal = 5 };
0023 enum { IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100 };
0024
0025
0026
0027
0028 class EcalTPGStripStatusPlot : public cond::payloadInspector::PlotImage<EcalTPGStripStatus> {
0029 public:
0030 EcalTPGStripStatusPlot() : cond::payloadInspector::PlotImage<EcalTPGStripStatus>("ECAL TPGStripStatus - map ") {
0031 setSingleIov(true);
0032 }
0033
0034 bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0035 TH2F* endc_p = new TH2F("EE+", "EE+ TPG Strip Status", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0036 TH2F* endc_m = new TH2F("EE-", "EE- TPG Strip Status", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0037 int EEstat[2] = {0, 0};
0038
0039 std::string mappingFile = "Geometry/EcalMapping/data/EEMap.txt";
0040 std::ifstream f(edm::FileInPath(mappingFile).fullPath().c_str());
0041 if (!f.good()) {
0042 std::cout << "EcalTPGStripStatus File EEMap.txt not found" << std::endl;
0043 throw cms::Exception("FileNotFound");
0044 }
0045
0046 uint32_t rawEE[NTCC][NTower][NStrip][NXtal];
0047 int NbrawEE[NTCC][NTower][NStrip];
0048 for (int TCC = 0; TCC < NTCC; TCC++)
0049 for (int TT = 0; TT < NTower; TT++)
0050 for (int ST = 0; ST < NStrip; ST++)
0051 NbrawEE[TCC][TT][ST] = 0;
0052 while (!f.eof()) {
0053 int ix, iy, iz, CL;
0054 int dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip;
0055 int tccid, tower, pseudostrip_in_TCC, pseudostrip_in_TT;
0056 f >> ix >> iy >> iz >> CL >> dccid >> towerid >> pseudostrip_in_SC >> xtal_in_pseudostrip >> tccid >> tower >>
0057 pseudostrip_in_TCC >> pseudostrip_in_TT;
0058 EEDetId detid(ix, iy, iz, EEDetId::XYMODE);
0059 uint32_t rawId = detid.denseIndex();
0060 if (tccid > NTCC || tower > NTower || pseudostrip_in_TT > NStrip || xtal_in_pseudostrip > NXtal)
0061 std::cout << " tccid " << tccid << " tower " << tower << " pseudostrip_in_TT " << pseudostrip_in_TT
0062 << " xtal_in_pseudostrip " << xtal_in_pseudostrip << std::endl;
0063 else {
0064 rawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1][xtal_in_pseudostrip - 1] = rawId;
0065 NbrawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1]++;
0066 }
0067 }
0068 f.close();
0069 double wei[2] = {0., 0.};
0070
0071 auto iov = iovs.front();
0072 std::shared_ptr<EcalTPGStripStatus> payload = fetchPayload(std::get<1>(iov));
0073 unsigned int run = std::get<0>(iov);
0074 if (payload.get()) {
0075 const EcalTPGStripStatusMap& stripMap = (*payload).getMap();
0076
0077 EcalTPGStripStatusMapIterator itSt;
0078 for (itSt = stripMap.begin(); itSt != stripMap.end(); ++itSt) {
0079 if (itSt->second > 0) {
0080
0081 int strip = itSt->first / 8;
0082 int pseudostrip = strip & 0x7;
0083 strip /= 8;
0084 int tt = strip & 0x7F;
0085 strip /= 128;
0086 int tccid = strip & 0x7F;
0087 int NbXtalInStrip = NbrawEE[tccid - 1][tt - 1][pseudostrip - 1];
0088 if (NbXtalInStrip != NXtal)
0089 std::cout << " Strip TCC " << tccid << " TT " << tt << " ST " << pseudostrip << " Nx Xtals "
0090 << NbXtalInStrip << std::endl;
0091
0092
0093 for (int Xtal = 0; Xtal < NbXtalInStrip; Xtal++) {
0094 uint32_t rawId = rawEE[tccid - 1][tt - 1][pseudostrip - 1][Xtal];
0095
0096 EEDetId detid = EEDetId::detIdFromDenseIndex(rawId);
0097 float x = (float)detid.ix();
0098 float y = (float)detid.iy();
0099 int iz = detid.zside();
0100 if (iz == -1)
0101 iz++;
0102 if (Xtal == 0)
0103 wei[iz] += 1.;
0104 if (iz == 0) {
0105 endc_m->Fill(x + 0.5, y + 0.5, wei[iz]);
0106 EEstat[0]++;
0107 } else {
0108 endc_p->Fill(x + 0.5, y + 0.5, wei[iz]);
0109 EEstat[1]++;
0110 }
0111
0112 }
0113 }
0114 }
0115 }
0116
0117
0118 gStyle->SetPalette(1);
0119 gStyle->SetOptStat(0);
0120 const Int_t NRGBs = 5;
0121 const Int_t NCont = 255;
0122
0123 Double_t stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
0124 Double_t red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
0125 Double_t green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
0126 Double_t blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
0127 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
0128 gStyle->SetNumberContours(NCont);
0129
0130 Double_t w = 1200;
0131 Double_t h = 650;
0132 TCanvas canvas("c", "c", w, h);
0133
0134
0135 TLatex t1;
0136 t1.SetNDC();
0137 t1.SetTextAlign(26);
0138 t1.SetTextSize(0.05);
0139 t1.DrawLatex(0.5, 0.96, Form("Ecal TPGStripStatus, IOV %i", run));
0140
0141 float xmi[2] = {0.0, 0.5};
0142 float xma[2] = {0.5, 1.0};
0143 std::array<std::unique_ptr<TPad>, 2> pad;
0144 for (int obj = 0; obj < 2; obj++) {
0145 pad[obj] = std::make_unique<TPad>(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
0146 pad[obj]->Draw();
0147 }
0148
0149 pad[0]->cd();
0150 DrawEE(endc_m, 0., wei[0]);
0151 t1.SetTextSize(0.03);
0152 t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEstat[0]));
0153 pad[1]->cd();
0154 DrawEE(endc_p, 0., wei[1]);
0155 t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEstat[1]));
0156
0157 std::string ImageName(m_imageFileName);
0158 canvas.SaveAs(ImageName.c_str());
0159 return true;
0160 }
0161 };
0162
0163
0164
0165
0166 template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
0167 class EcalTPGStripStatusDiffBase : public cond::payloadInspector::PlotImage<EcalTPGStripStatus, nIOVs, ntags> {
0168 public:
0169 EcalTPGStripStatusDiffBase()
0170 : cond::payloadInspector::PlotImage<EcalTPGStripStatus, nIOVs, ntags>("ECAL TPGStripStatus difference") {}
0171
0172 bool fill() override {
0173 TH2F* endc_p = new TH2F("EE+", "EE+ TPG Strip Status", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0174 TH2F* endc_m = new TH2F("EE-", "EE- TPG Strip Status", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0175 int EEstat[2][2] = {{0, 0}, {0, 0}};
0176
0177 std::string mappingFile = "Geometry/EcalMapping/data/EEMap.txt";
0178 std::ifstream f(edm::FileInPath(mappingFile).fullPath().c_str());
0179 if (!f.good()) {
0180 std::cout << "EcalTPGStripStatus File EEMap.txt not found" << std::endl;
0181 throw cms::Exception("FileNotFound");
0182 }
0183
0184 uint32_t rawEE[NTCC][NTower][NStrip][NXtal];
0185 int NbrawEE[NTCC][NTower][NStrip];
0186 for (int TCC = 0; TCC < NTCC; TCC++)
0187 for (int TT = 0; TT < NTower; TT++)
0188 for (int ST = 0; ST < NStrip; ST++)
0189 NbrawEE[TCC][TT][ST] = 0;
0190 while (!f.eof()) {
0191 int ix, iy, iz, CL;
0192 int dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip;
0193 int tccid, tower, pseudostrip_in_TCC, pseudostrip_in_TT;
0194 f >> ix >> iy >> iz >> CL >> dccid >> towerid >> pseudostrip_in_SC >> xtal_in_pseudostrip >> tccid >> tower >>
0195 pseudostrip_in_TCC >> pseudostrip_in_TT;
0196 EEDetId detid(ix, iy, iz, EEDetId::XYMODE);
0197 uint32_t rawId = detid.denseIndex();
0198 if (tccid > NTCC || tower > NTower || pseudostrip_in_TT > NStrip || xtal_in_pseudostrip > NXtal)
0199 std::cout << " tccid " << tccid << " tower " << tower << " pseudostrip_in_TT " << pseudostrip_in_TT
0200 << " xtal_in_pseudostrip " << xtal_in_pseudostrip << std::endl;
0201 else {
0202 rawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1][xtal_in_pseudostrip - 1] = rawId;
0203 NbrawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1]++;
0204 }
0205 }
0206 f.close();
0207
0208 unsigned int run[2] = {0, 0};
0209 int vEE[100];
0210 int istat = 0;
0211 std::string l_tagname[2];
0212 auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
0213 l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
0214 auto firstiov = iovs.front();
0215 run[0] = std::get<0>(firstiov);
0216 std::tuple<cond::Time_t, cond::Hash> lastiov;
0217 if (ntags == 2) {
0218 auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
0219 l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
0220 lastiov = tag2iovs.front();
0221 } else {
0222 lastiov = iovs.back();
0223 l_tagname[1] = l_tagname[0];
0224 }
0225 run[1] = std::get<0>(lastiov);
0226 for (int irun = 0; irun < nIOVs; irun++) {
0227 std::shared_ptr<EcalTPGStripStatus> payload;
0228 if (irun == 0) {
0229 payload = this->fetchPayload(std::get<1>(firstiov));
0230 } else {
0231 payload = this->fetchPayload(std::get<1>(lastiov));
0232 }
0233 if (payload.get()) {
0234 const EcalTPGStripStatusMap& stripMap = (*payload).getMap();
0235
0236 EcalTPGStripStatusMapIterator itSt;
0237 for (itSt = stripMap.begin(); itSt != stripMap.end(); ++itSt) {
0238 if (itSt->second > 0) {
0239 int ID = itSt->first / 8;
0240 if (irun == 0 && istat < 100) {
0241 vEE[istat] = ID;
0242
0243 istat++;
0244 if (istat == 100)
0245 std::cout << " limit on number of strips reached, stop keeping others" << std::endl;
0246 } else {
0247 bool found = false;
0248 for (int is = 0; is < istat; is++) {
0249
0250 if (vEE[is] == ID) {
0251
0252 found = true;
0253 vEE[is] = -1;
0254 break;
0255 }
0256 }
0257 if (!found) {
0258
0259
0260 int strip = ID;
0261 int pseudostrip = strip & 0x7;
0262 strip /= 8;
0263 int tt = strip & 0x7F;
0264 strip /= 128;
0265 int tccid = strip & 0x7F;
0266 int NbXtalInStrip = NbrawEE[tccid - 1][tt - 1][pseudostrip - 1];
0267 if (NbXtalInStrip != NXtal)
0268 std::cout << " Strip TCC " << tccid << " TT " << tt << " ST " << pseudostrip << " Nx Xtals "
0269 << NbXtalInStrip << std::endl;
0270 for (int Xtal = 0; Xtal < NbXtalInStrip; Xtal++) {
0271 uint32_t rawId = rawEE[tccid - 1][tt - 1][pseudostrip - 1][Xtal];
0272
0273 EEDetId detid = EEDetId::detIdFromDenseIndex(rawId);
0274 float x = (float)detid.ix();
0275 float y = (float)detid.iy();
0276 int iz = detid.zside();
0277 if (iz == -1)
0278 iz++;
0279 if (iz == 0) {
0280 endc_m->Fill(x + 0.5, y + 0.5, 1.);
0281 EEstat[0][0]++;
0282 } else {
0283 endc_p->Fill(x + 0.5, y + 0.5, 1.);
0284 EEstat[1][0]++;
0285 }
0286
0287 }
0288 }
0289 }
0290 }
0291 }
0292 }
0293 else
0294 return false;
0295
0296 }
0297
0298
0299 for (int is = 0; is < istat; is++) {
0300 if (vEE[is] != -1) {
0301
0302
0303 int strip = vEE[is];
0304 int pseudostrip = strip & 0x7;
0305 strip /= 8;
0306 int tt = strip & 0x7F;
0307 strip /= 128;
0308 int tccid = strip & 0x7F;
0309 int NbXtalInStrip = NbrawEE[tccid - 1][tt - 1][pseudostrip - 1];
0310 if (NbXtalInStrip != NXtal)
0311 std::cout << " Strip TCC " << tccid << " TT " << tt << " ST " << pseudostrip << " Nx Xtals "
0312 << NbXtalInStrip << std::endl;
0313 for (int Xtal = 0; Xtal < NbXtalInStrip; Xtal++) {
0314 uint32_t rawId = rawEE[tccid - 1][tt - 1][pseudostrip - 1][Xtal];
0315
0316 EEDetId detid = EEDetId::detIdFromDenseIndex(rawId);
0317 float x = (float)detid.ix();
0318 float y = (float)detid.iy();
0319 int iz = detid.zside();
0320 if (iz == -1)
0321 iz++;
0322 if (iz == 0) {
0323 endc_m->Fill(x + 0.5, y + 0.5, -1.);
0324 EEstat[0][1]++;
0325 } else {
0326 endc_p->Fill(x + 0.5, y + 0.5, -1.);
0327 EEstat[1][1]++;
0328 }
0329
0330 }
0331 }
0332 }
0333
0334 gStyle->SetPalette(1);
0335 gStyle->SetOptStat(0);
0336 const Int_t NRGBs = 5;
0337 const Int_t NCont = 255;
0338
0339 Double_t stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
0340 Double_t red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
0341 Double_t green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
0342 Double_t blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
0343 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
0344 gStyle->SetNumberContours(NCont);
0345
0346 Double_t w = 1200;
0347 Double_t h = 650;
0348 TCanvas canvas("c", "c", w, h);
0349
0350
0351 TLatex t1;
0352 t1.SetNDC();
0353 t1.SetTextAlign(26);
0354 int len = l_tagname[0].length() + l_tagname[1].length();
0355 if (ntags == 2) {
0356 if (len < 180) {
0357 t1.SetTextSize(0.03);
0358 t1.DrawLatex(0.5, 0.96, Form("%s %i - %s %i", l_tagname[1].c_str(), run[1], l_tagname[0].c_str(), run[0]));
0359 } else {
0360 t1.SetTextSize(0.05);
0361 t1.DrawLatex(0.5, 0.96, Form("Ecal TPGStripStatus, IOV %i - %i", run[1], run[0]));
0362 }
0363 } else {
0364 t1.SetTextSize(0.05);
0365 t1.DrawLatex(0.5, 0.96, Form("%s, IOV %i - %i", l_tagname[0].c_str(), run[1], run[0]));
0366 }
0367
0368 float xmi[2] = {0.0, 0.5};
0369 float xma[2] = {0.5, 1.0};
0370 std::array<std::unique_ptr<TPad>, 2> pad;
0371 for (int obj = 0; obj < 2; obj++) {
0372 pad[obj] = std::make_unique<TPad>(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
0373 pad[obj]->Draw();
0374 }
0375
0376 pad[0]->cd();
0377 DrawEE(endc_m, -1.0, 1.0);
0378 t1.SetTextSize(0.03);
0379 t1.DrawLatex(0.15, 0.92, Form("new %i old %i", EEstat[0][0], EEstat[0][1]));
0380 pad[1]->cd();
0381 DrawEE(endc_p, -1.0, 1.0);
0382 t1.DrawLatex(0.15, 0.92, Form("new %i old %i", EEstat[1][0], EEstat[1][1]));
0383
0384 std::string ImageName(this->m_imageFileName);
0385 canvas.SaveAs(ImageName.c_str());
0386 return true;
0387 }
0388 };
0389 using EcalTPGStripStatusDiffOneTag = EcalTPGStripStatusDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
0390 using EcalTPGStripStatusDiffTwoTags = EcalTPGStripStatusDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
0391
0392
0393
0394
0395 class EcalTPGStripStatusSummaryPlot : public cond::payloadInspector::PlotImage<EcalTPGStripStatus> {
0396 public:
0397 EcalTPGStripStatusSummaryPlot()
0398 : cond::payloadInspector::PlotImage<EcalTPGStripStatus>("Ecal TPGStrip Status Summary - map ") {
0399 setSingleIov(true);
0400 }
0401
0402 bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0403 auto iov = iovs.front();
0404 std::shared_ptr<EcalTPGStripStatus> payload =
0405 fetchPayload(std::get<1>(iov));
0406 unsigned int run = std::get<0>(iov);
0407 TH2F* align;
0408
0409 int NbRows = 1;
0410 int NbColumns = 2;
0411
0412 if (payload.get()) {
0413 const EcalTPGStripStatusMap& stripMap = (*payload).getMap();
0414
0415 align = new TH2F("Ecal TPGStrip Status Summary",
0416 "Total NumberOfMasked",
0417 NbColumns,
0418 0,
0419 NbColumns,
0420 NbRows,
0421 0,
0422 NbRows);
0423
0424 int NbMaskedTT = 0;
0425
0426 for (EcalTPGStripStatusMapIterator it = stripMap.begin(); it != stripMap.end(); ++it)
0427 if ((*it).second > 0)
0428 NbMaskedTT++;
0429
0430 align->Fill(0.5, 0.5, stripMap.size());
0431 align->Fill(1.5, 0.5, NbMaskedTT);
0432
0433 }
0434 else
0435 return false;
0436
0437 gStyle->SetPalette(1);
0438 gStyle->SetOptStat(0);
0439 TCanvas canvas("CC map", "CC map", 1000, 1000);
0440 TLatex t1;
0441 t1.SetNDC();
0442 t1.SetTextAlign(26);
0443 t1.SetTextSize(0.04);
0444 t1.SetTextColor(2);
0445 t1.DrawLatex(0.5, 0.96, Form("Endcap:Number of masked Trigger Strips, IOV %i", run));
0446
0447 TPad pad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
0448 pad.Draw();
0449 pad.cd();
0450 align->Draw("TEXT");
0451
0452 drawTable(NbRows, NbColumns);
0453
0454 align->GetXaxis()->SetTickLength(0.);
0455 align->GetXaxis()->SetLabelSize(0.);
0456 align->GetYaxis()->SetTickLength(0.);
0457 align->GetYaxis()->SetLabelSize(0.);
0458
0459 std::string ImageName(m_imageFileName);
0460 canvas.SaveAs(ImageName.c_str());
0461 return true;
0462 }
0463 };
0464
0465 }
0466
0467
0468 PAYLOAD_INSPECTOR_MODULE(EcalTPGStripStatus) {
0469 PAYLOAD_INSPECTOR_CLASS(EcalTPGStripStatusPlot);
0470 PAYLOAD_INSPECTOR_CLASS(EcalTPGStripStatusDiffOneTag);
0471 PAYLOAD_INSPECTOR_CLASS(EcalTPGStripStatusDiffTwoTags);
0472 PAYLOAD_INSPECTOR_CLASS(EcalTPGStripStatusSummaryPlot);
0473 }