File indexing completed on 2023-03-17 10:46:07
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/EcalTPGFineGrainStripEE.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 <memory>
0019 #include <array>
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 EcalTPGFineGrainStripEEPlot : public cond::payloadInspector::PlotImage<EcalTPGFineGrainStripEE> {
0029 public:
0030 EcalTPGFineGrainStripEEPlot()
0031 : cond::payloadInspector::PlotImage<EcalTPGFineGrainStripEE>("EcalTPGFineGrainStripEE - map ") {
0032 setSingleIov(true);
0033 }
0034
0035 bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0036 TH2F* endc_thresh_p =
0037 new TH2F("EE+", "EE+ TPGFineGrainStrip Threshold", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0038 TH2F* endc_thresh_m =
0039 new TH2F("EE-", "EE- TPGFineGrainStrip Threshold", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0040
0041 TH2F* endc_lut_p =
0042 new TH2F("EE+", "EE+ TPG Crystal Status Lut", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0043 TH2F* endc_lut_m =
0044 new TH2F("EE-", "EE- TPG Crystal Status Lut", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0045 int EEcount[2] = {0, 0};
0046
0047 std::string mappingFile = "Geometry/EcalMapping/data/EEMap.txt";
0048 std::ifstream f(edm::FileInPath(mappingFile).fullPath().c_str());
0049 if (!f.good()) {
0050 std::cout << "EcalTPGFineGrainStripEE File EEMap.txt not found" << std::endl;
0051 throw cms::Exception("FileNotFound");
0052 }
0053
0054 uint32_t rawEE[NTCC][NTower][NStrip][NXtal];
0055 int NbrawEE[NTCC][NTower][NStrip];
0056 for (int TCC = 0; TCC < NTCC; TCC++)
0057 for (int TT = 0; TT < NTower; TT++)
0058 for (int ST = 0; ST < NStrip; ST++)
0059 NbrawEE[TCC][TT][ST] = 0;
0060
0061 while (!f.eof()) {
0062 int ix, iy, iz, CL;
0063 int dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip;
0064 int tccid, tower, pseudostrip_in_TCC, pseudostrip_in_TT;
0065 f >> ix >> iy >> iz >> CL >> dccid >> towerid >> pseudostrip_in_SC >> xtal_in_pseudostrip >> tccid >> tower >>
0066 pseudostrip_in_TCC >> pseudostrip_in_TT;
0067
0068 EEDetId detid(ix, iy, iz, EEDetId::XYMODE);
0069 uint32_t rawId = detid.denseIndex();
0070 if (tccid > NTCC || tower > NTower || pseudostrip_in_TT > NStrip || xtal_in_pseudostrip > NXtal) {
0071
0072
0073 } else {
0074 rawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1][xtal_in_pseudostrip - 1] = rawId;
0075 NbrawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1]++;
0076 }
0077 }
0078
0079 f.close();
0080
0081
0082 auto iov = iovs.front();
0083 std::shared_ptr<EcalTPGFineGrainStripEE> payload = fetchPayload(std::get<1>(iov));
0084 unsigned int run = std::get<0>(iov);
0085 double max1 = 1.0, max2 = 1.0;
0086
0087 if (payload.get()) {
0088 const EcalTPGFineGrainStripEEMap& stripMap = (*payload).getMap();
0089
0090 EcalTPGFineGrainStripEEMapIterator itSt;
0091 for (itSt = stripMap.begin(); itSt != stripMap.end(); ++itSt) {
0092 EcalTPGFineGrainStripEE::Item item = (*itSt).second;
0093
0094
0095 int strip = itSt->first / 8;
0096 int pseudostrip = strip & 0x7;
0097 strip /= 8;
0098 int tt = strip & 0x7F;
0099 strip /= 128;
0100 int tccid = strip & 0x7F;
0101 int NbXtalInStrip = NbrawEE[tccid - 1][tt - 1][pseudostrip - 1];
0102
0103
0104
0105 for (int Xtal = 0; Xtal < NbXtalInStrip; Xtal++) {
0106 uint32_t rawId = rawEE[tccid - 1][tt - 1][pseudostrip - 1][Xtal];
0107
0108 EEDetId detid = EEDetId::detIdFromDenseIndex(rawId);
0109 float x = (float)detid.ix();
0110 float y = (float)detid.iy();
0111 int iz = detid.zside();
0112 if (iz == -1)
0113 iz++;
0114
0115 if (iz == 0) {
0116 endc_thresh_m->Fill(x + 0.5, y + 0.5, item.threshold);
0117 endc_lut_m->Fill(x + 0.5, y + 0.5, item.lut);
0118 EEcount[0]++;
0119
0120 if (max1 < item.threshold)
0121 max1 = item.threshold;
0122
0123 if (max2 < item.lut)
0124 max2 = item.lut;
0125
0126 } else {
0127 endc_thresh_p->Fill(x + 0.5, y + 0.5, item.threshold);
0128 endc_lut_p->Fill(x + 0.5, y + 0.5, item.lut);
0129 EEcount[1]++;
0130
0131 if (max1 < item.threshold)
0132 max1 = item.threshold;
0133
0134 if (max2 < item.lut)
0135 max2 = item.lut;
0136 }
0137 }
0138 }
0139 }
0140
0141
0142 gStyle->SetPalette(1);
0143 gStyle->SetOptStat(0);
0144 const Int_t NRGBs = 5;
0145 const Int_t NCont = 255;
0146
0147 Double_t stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
0148 Double_t red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
0149 Double_t green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
0150 Double_t blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
0151 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
0152 gStyle->SetNumberContours(NCont);
0153
0154 Double_t w = 1200;
0155 Double_t h = 1400;
0156 TCanvas canvas("c", "c", w, h);
0157
0158 TLatex t1;
0159 t1.SetNDC();
0160 t1.SetTextAlign(26);
0161 t1.SetTextSize(0.04);
0162 t1.DrawLatex(0.5, 0.96, Form("Ecal TPG Fine Grain StripEE, IOV %i", run));
0163
0164 float xmi[4] = {0.0, 0.5, 0.0, 0.5};
0165 float xma[4] = {0.5, 1.0, 0.5, 1.0};
0166
0167 float ymi[4] = {0.47, 0.47, 0.0, 0.0};
0168 float yma[4] = {0.94, 0.94, 0.47, 0.47};
0169 std::array<std::unique_ptr<TPad>, 4> pad;
0170 for (int obj = 0; obj < 4; obj++) {
0171 pad[obj] = std::make_unique<TPad>(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], ymi[obj], xma[obj], yma[obj]);
0172 pad[obj]->Draw();
0173 }
0174
0175
0176
0177 pad[0]->cd();
0178 DrawEE(endc_thresh_m, 0., max1);
0179 t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEcount[0]));
0180
0181 pad[1]->cd();
0182 DrawEE(endc_thresh_p, 0., max1);
0183 t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEcount[1]));
0184
0185 pad[2]->cd();
0186 DrawEE(endc_lut_m, 0., max2);
0187 t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEcount[0]));
0188
0189 pad[3]->cd();
0190 DrawEE(endc_lut_p, 0., max2);
0191 t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEcount[1]));
0192
0193 std::string ImageName(m_imageFileName);
0194
0195 canvas.SaveAs(ImageName.c_str());
0196
0197 delete endc_lut_p;
0198 delete endc_lut_m;
0199 delete endc_thresh_p;
0200 delete endc_thresh_m;
0201 return true;
0202 }
0203 };
0204
0205 }
0206
0207
0208 PAYLOAD_INSPECTOR_MODULE(EcalTPGFineGrainStripEE) { PAYLOAD_INSPECTOR_CLASS(EcalTPGFineGrainStripEEPlot); }