File indexing completed on 2024-09-07 04:35:34
0001
0002 #include <iostream>
0003 #include <memory>
0004 #include <sstream>
0005 #include <fmt/printf.h>
0006
0007
0008 #include "CalibTracker/StandaloneTrackerTopology/interface/StandaloneTrackerTopology.h"
0009 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
0010 #include "CondCore/CondDB/interface/Time.h"
0011 #include "CondCore/SiStripPlugins/interface/SiStripPayloadInspectorHelper.h"
0012 #include "CondCore/Utilities/interface/PayloadInspector.h"
0013 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0014 #include "CondFormats/SiStripObjects/interface/SiStripDetSummary.h"
0015 #include "CondFormats/SiStripObjects/interface/SiStripDetVOff.h"
0016
0017
0018 #include "TH2F.h"
0019 #include "TLegend.h"
0020 #include "TCanvas.h"
0021 #include "TLine.h"
0022 #include "TStyle.h"
0023 #include "TLatex.h"
0024 #include "TPave.h"
0025 #include "TPaveStats.h"
0026 #include "TGaxis.h"
0027
0028 namespace {
0029
0030 using namespace cond::payloadInspector;
0031
0032 class SiStripDetVOff_LV : public TimeHistoryPlot<SiStripDetVOff, int> {
0033 public:
0034 SiStripDetVOff_LV() : TimeHistoryPlot<SiStripDetVOff, int>("Nr of mod with LV OFF vs time", "nLVOff") {}
0035
0036 int getFromPayload(SiStripDetVOff& payload) override { return payload.getLVoffCounts(); }
0037 };
0038
0039 class SiStripDetVOff_HV : public TimeHistoryPlot<SiStripDetVOff, int> {
0040 public:
0041 SiStripDetVOff_HV() : TimeHistoryPlot<SiStripDetVOff, int>("Nr of mod with HV OFF vs time", "nHVOff") {}
0042
0043 int getFromPayload(SiStripDetVOff& payload) override { return payload.getHVoffCounts(); }
0044 };
0045
0046 namespace SiStripDetVOffPI {
0047 enum type { t_LV = 0, t_HV = 1, t_V };
0048 }
0049
0050
0051
0052
0053 template <SiStripDetVOffPI::type my_type>
0054 class SiStripDetVOff_TrackerMapBase : public PlotImage<SiStripDetVOff, SINGLE_IOV> {
0055 public:
0056 SiStripDetVOff_TrackerMapBase() : PlotImage<SiStripDetVOff, SINGLE_IOV>("Tracker Map: Is Module VOff") {}
0057
0058 bool fill() override {
0059 auto tag = PlotBase::getTag<0>();
0060 auto iov = tag.iovs.front();
0061 auto tagname = tag.name;
0062 unsigned long IOVsince = std::get<0>(iov);
0063 std::shared_ptr<SiStripDetVOff> payload = fetchPayload(std::get<1>(iov));
0064
0065 std::unique_ptr<TrackerMap> tmap = std::make_unique<TrackerMap>("SiStripIsModuleVOff");
0066 tmap->setPalette(1);
0067 std::string titleMap{};
0068
0069 switch (my_type) {
0070 case SiStripDetVOffPI::t_LV: {
0071 titleMap = fmt::sprintf("TrackerMap of LV VOff modules | Tag: %s | IOV: %s", tagname, getIOVsince(IOVsince));
0072 break;
0073 }
0074 case SiStripDetVOffPI::t_HV: {
0075 titleMap = fmt::sprintf("TrackerMap of HV VOff modules | Tag: %s | IOV: %s", tagname, getIOVsince(IOVsince));
0076 break;
0077 }
0078 case SiStripDetVOffPI::t_V: {
0079 titleMap =
0080 fmt::sprintf("TrackerMap of VOff modules (HV or LV) | Tag: %s | IOV: %s", tagname, getIOVsince(IOVsince));
0081 break;
0082 }
0083 default:
0084 edm::LogError("SiStripDetVOff_IsModuleVOff_TrackerMap") << "Unrecognized type: " << my_type << std::endl;
0085 break;
0086 }
0087
0088 tmap->setTitle(titleMap);
0089
0090 std::vector<uint32_t> detid;
0091 payload->getDetIds(detid);
0092
0093 for (const auto& d : detid) {
0094 if ((payload->IsModuleLVOff(d) && (my_type == SiStripDetVOffPI::t_LV)) ||
0095 (payload->IsModuleHVOff(d) && (my_type == SiStripDetVOffPI::t_HV)) ||
0096 (payload->IsModuleVOff(d) && (my_type == SiStripDetVOffPI::t_V))) {
0097 tmap->fill(d, 1.);
0098 }
0099 }
0100
0101 std::string fileName(m_imageFileName);
0102
0103 tmap->save(true, 0., 1.01, fileName);
0104
0105 return true;
0106 }
0107
0108 private:
0109 const char* getIOVsince(const unsigned long IOV) {
0110 int run = 0;
0111 static char buf[256];
0112
0113 if (IOV < 4294967296) {
0114 run = IOV;
0115 std::sprintf(buf, "%d", run);
0116 } else {
0117 run = IOV >> 32;
0118 time_t t = run;
0119 struct tm lt;
0120 localtime_r(&t, <);
0121 strftime(buf, sizeof(buf), "%F %R:%S", <);
0122 buf[sizeof(buf) - 1] = 0;
0123 }
0124 return buf;
0125 }
0126 };
0127
0128 using SiStripDetVOff_IsModuleVOff_TrackerMap = SiStripDetVOff_TrackerMapBase<SiStripDetVOffPI::t_V>;
0129 using SiStripDetVOff_IsModuleLVOff_TrackerMap = SiStripDetVOff_TrackerMapBase<SiStripDetVOffPI::t_LV>;
0130 using SiStripDetVOff_IsModuleHVOff_TrackerMap = SiStripDetVOff_TrackerMapBase<SiStripDetVOffPI::t_HV>;
0131
0132
0133
0134
0135 template <SiStripDetVOffPI::type my_type>
0136 class SiStripDetVOffListOfModules : public Histogram1DD<SiStripDetVOff, SINGLE_IOV> {
0137 public:
0138 SiStripDetVOffListOfModules()
0139 : Histogram1DD<SiStripDetVOff, SINGLE_IOV>(
0140 "SiStrip Off modules", "SiStrip Off modules", 15148, 0., 15148., "DetId of VOff module") {}
0141
0142 bool fill() override {
0143 auto tag = PlotBase::getTag<0>();
0144 for (auto const& iov : tag.iovs) {
0145 std::shared_ptr<SiStripDetVOff> payload = Base::fetchPayload(std::get<1>(iov));
0146 if (payload.get()) {
0147 std::vector<uint32_t> detid;
0148 payload->getDetIds(detid);
0149 int i = 0;
0150
0151
0152
0153 for (const auto& d : detid) {
0154 switch (my_type) {
0155 case SiStripDetVOffPI::t_LV: {
0156 if (payload->IsModuleLVOff(d)) {
0157
0158 fillWithBinAndValue(i, double(d));
0159 }
0160 break;
0161 }
0162 case SiStripDetVOffPI::t_HV: {
0163 if (payload->IsModuleHVOff(d)) {
0164
0165 fillWithBinAndValue(i, double(d));
0166 }
0167 break;
0168 }
0169 case SiStripDetVOffPI::t_V: {
0170 if (payload->IsModuleVOff(d)) {
0171
0172 fillWithBinAndValue(i, double(d));
0173 }
0174 break;
0175 }
0176 default:
0177 edm::LogError("SiStripDetVOffListOfModules") << "Unrecognized type: " << my_type << std::endl;
0178 break;
0179 }
0180 i++;
0181 }
0182 }
0183 }
0184 return true;
0185 }
0186 };
0187
0188 using SiStripVOffListOfModules = SiStripDetVOffListOfModules<SiStripDetVOffPI::t_V>;
0189 using SiStripLVOffListOfModules = SiStripDetVOffListOfModules<SiStripDetVOffPI::t_LV>;
0190 using SiStripHVOffListOfModules = SiStripDetVOffListOfModules<SiStripDetVOffPI::t_HV>;
0191
0192
0193
0194
0195
0196 class SiStripDetVOffTest : public Histogram1D<SiStripDetVOff, SINGLE_IOV> {
0197 public:
0198 SiStripDetVOffTest()
0199 : Histogram1D<SiStripDetVOff, SINGLE_IOV>("SiStrip DetVOff test", "SiStrip DetVOff test", 10, 0.0, 10.0),
0200 m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(
0201 edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())} {}
0202
0203 bool fill() override {
0204 auto tag = PlotBase::getTag<0>();
0205 for (auto const& iov : tag.iovs) {
0206 std::shared_ptr<SiStripDetVOff> payload = Base::fetchPayload(std::get<1>(iov));
0207 if (payload.get()) {
0208 std::vector<uint32_t> detid;
0209 payload->getDetIds(detid);
0210
0211 SiStripDetSummary summaryHV{&m_trackerTopo};
0212 SiStripDetSummary summaryLV{&m_trackerTopo};
0213
0214 for (const auto& d : detid) {
0215 if (payload->IsModuleLVOff(d))
0216 summaryLV.add(d);
0217 if (payload->IsModuleHVOff(d))
0218 summaryHV.add(d);
0219 }
0220 std::map<unsigned int, SiStripDetSummary::Values> mapHV = summaryHV.getCounts();
0221 std::map<unsigned int, SiStripDetSummary::Values> mapLV = summaryLV.getCounts();
0222
0223
0224
0225
0226 std::stringstream ss;
0227 ss << "Summary of HV off detectors:" << std::endl;
0228 summaryHV.print(ss, true);
0229
0230 ss << "Summary of LV off detectors:" << std::endl;
0231 summaryLV.print(ss, true);
0232
0233 std::cout << ss.str() << std::endl;
0234
0235 }
0236 }
0237 return true;
0238 }
0239 private:
0240 TrackerTopology m_trackerTopo;
0241 };
0242
0243
0244
0245
0246
0247 class SiStripDetVOffByRegion : public PlotImage<SiStripDetVOff, SINGLE_IOV> {
0248 public:
0249 SiStripDetVOffByRegion()
0250 : PlotImage<SiStripDetVOff, SINGLE_IOV>("SiStrip DetVOff By Region"),
0251 m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(
0252 edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())} {}
0253
0254 bool fill() override {
0255 auto tag = PlotBase::getTag<0>();
0256 auto iov = tag.iovs.front();
0257 std::shared_ptr<SiStripDetVOff> payload = fetchPayload(std::get<1>(iov));
0258
0259 unsigned long IOV = std::get<0>(iov);
0260 int run = 0;
0261 if (IOV < 4294967296) {
0262 run = std::get<0>(iov);
0263 } else {
0264 run = IOV >> 32;
0265 }
0266
0267 std::vector<uint32_t> detid;
0268 payload->getDetIds(detid);
0269
0270 SiStripDetSummary summaryHV{&m_trackerTopo};
0271 SiStripDetSummary summaryLV{&m_trackerTopo};
0272
0273 for (const auto& d : detid) {
0274 if (payload->IsModuleLVOff(d))
0275 summaryLV.add(d);
0276 if (payload->IsModuleHVOff(d))
0277 summaryHV.add(d);
0278 }
0279 std::map<unsigned int, SiStripDetSummary::Values> mapHV = summaryHV.getCounts();
0280 std::map<unsigned int, SiStripDetSummary::Values> mapLV = summaryLV.getCounts();
0281 std::vector<unsigned int> keys;
0282 std::transform(
0283 mapHV.begin(),
0284 mapHV.end(),
0285 std::back_inserter(keys),
0286 [](const std::map<unsigned int, SiStripDetSummary::Values>::value_type& pair) { return pair.first; });
0287
0288
0289
0290 TCanvas canvas("DetVOff Partion summary", "SiStripDetVOff region summary", 1200, 1000);
0291 canvas.cd();
0292 auto h_HV = std::make_unique<TH1F>(
0293 "HVbyRegion", "SiStrip HV/LV summary by region;; modules with HV off", mapHV.size(), 0., mapHV.size());
0294 auto h_LV = std::make_unique<TH1F>(
0295 "LVbyRegion", "SiStrip HV/LV summary by region;; modules with LV off", mapLV.size(), 0., mapLV.size());
0296
0297 h_HV->SetStats(false);
0298 h_LV->SetStats(false);
0299
0300 h_HV->SetTitle(nullptr);
0301 h_LV->SetTitle(nullptr);
0302
0303 canvas.SetBottomMargin(0.18);
0304 canvas.SetLeftMargin(0.10);
0305 canvas.SetRightMargin(0.10);
0306 canvas.Modified();
0307
0308 std::vector<int> boundaries;
0309 unsigned int iBin = 0;
0310
0311 std::string detector;
0312 std::string currentDetector;
0313
0314 for (const auto& index : keys) {
0315 iBin++;
0316 int countHV = mapHV[index].count;
0317 int countLV = mapLV[index].count;
0318
0319 if (currentDetector.empty())
0320 currentDetector = "TIB";
0321
0322 switch ((index) / 1000) {
0323 case 1:
0324 detector = "TIB";
0325 break;
0326 case 2:
0327 detector = "TOB";
0328 break;
0329 case 3:
0330 detector = "TEC";
0331 break;
0332 case 4:
0333 detector = "TID";
0334 break;
0335 }
0336
0337 h_HV->SetBinContent(iBin, countHV);
0338 h_HV->GetXaxis()->SetBinLabel(iBin, SiStripPI::regionType(index).second);
0339 h_HV->GetXaxis()->LabelsOption("v");
0340
0341 h_LV->SetBinContent(iBin, countLV);
0342 h_LV->GetXaxis()->SetBinLabel(iBin, SiStripPI::regionType(index).second);
0343 h_LV->GetXaxis()->LabelsOption("v");
0344
0345 if (detector != currentDetector) {
0346 boundaries.push_back(iBin);
0347 currentDetector = detector;
0348 }
0349 }
0350
0351 auto extrema = SiStripPI::getExtrema(h_LV.get(), h_HV.get());
0352 h_HV->GetYaxis()->SetRangeUser(extrema.first, extrema.second);
0353 h_LV->GetYaxis()->SetRangeUser(extrema.first, extrema.second);
0354
0355 h_HV->SetMarkerStyle(20);
0356 h_HV->SetMarkerSize(1);
0357 h_HV->SetLineColor(kRed);
0358 h_HV->SetMarkerColor(kRed);
0359 h_HV->Draw("HIST");
0360 h_HV->Draw("TEXT45same");
0361
0362 h_LV->SetMarkerStyle(21);
0363 h_LV->SetMarkerSize(1);
0364 h_LV->SetLineColor(kBlue);
0365 h_LV->SetLineStyle(9);
0366 h_LV->SetMarkerColor(kBlue);
0367 h_LV->Draw("HISTsame");
0368 h_LV->Draw("TEXT45same");
0369
0370 canvas.Update();
0371 canvas.cd();
0372
0373 TLine l[boundaries.size()];
0374 unsigned int i = 0;
0375 for (const auto& line : boundaries) {
0376 l[i] = TLine(
0377 h_HV->GetBinLowEdge(line), canvas.cd()->GetUymin(), h_HV->GetBinLowEdge(line), canvas.cd()->GetUymax());
0378 l[i].SetLineWidth(1);
0379 l[i].SetLineStyle(9);
0380 l[i].SetLineColor(2);
0381 l[i].Draw("same");
0382 i++;
0383 }
0384
0385 TLegend legend = TLegend(0.45, 0.80, 0.90, 0.9);
0386 legend.SetHeader((std::get<1>(iov)).c_str(), "C");
0387 legend.AddEntry(h_HV.get(), ("HV channels: " + std::to_string(payload->getHVoffCounts())).c_str(), "PL");
0388 legend.AddEntry(h_LV.get(), ("LV channels: " + std::to_string(payload->getLVoffCounts())).c_str(), "PL");
0389 legend.SetTextSize(0.025);
0390 legend.Draw("same");
0391
0392 TLatex t1;
0393 t1.SetNDC();
0394 t1.SetTextAlign(26);
0395 t1.SetTextSize(0.05);
0396 if (IOV < 4294967296)
0397 t1.DrawLatex(0.5, 0.96, Form("SiStrip DetVOff, IOV %i", run));
0398 else {
0399 time_t t = run;
0400 char buf[256];
0401 struct tm lt;
0402 localtime_r(&t, <);
0403 strftime(buf, sizeof(buf), "%F %R:%S", <);
0404 buf[sizeof(buf) - 1] = 0;
0405 t1.DrawLatex(0.5, 0.96, Form("SiStrip DetVOff, IOV %s", buf));
0406 }
0407
0408
0409 h_HV.get()->GetYaxis()->SetLabelOffset(999);
0410 h_HV.get()->GetYaxis()->SetTickLength(0);
0411 h_HV.get()->GetYaxis()->SetTitleOffset(999);
0412
0413 h_LV.get()->GetYaxis()->SetLabelOffset(999);
0414 h_LV.get()->GetYaxis()->SetTickLength(0);
0415 h_LV.get()->GetYaxis()->SetTitleOffset(999);
0416
0417
0418 auto l_axis = std::make_unique<TGaxis>(
0419 gPad->GetUxmin(), gPad->GetUymin(), gPad->GetUxmin(), gPad->GetUymax(), 0, extrema.second, 510);
0420 l_axis->SetLineColor(kRed);
0421 l_axis->SetTextColor(kRed);
0422 l_axis->SetLabelColor(kRed);
0423 l_axis->SetTitleOffset(1.2);
0424 l_axis->SetTitleColor(kRed);
0425 l_axis->SetTitle(h_HV.get()->GetYaxis()->GetTitle());
0426 l_axis->Draw();
0427
0428
0429 auto r_axis = std::make_unique<TGaxis>(
0430 gPad->GetUxmax(), gPad->GetUymin(), gPad->GetUxmax(), gPad->GetUymax(), 0, extrema.second, 510, "+L");
0431 r_axis->SetLineColor(kBlue);
0432 r_axis->SetTextColor(kBlue);
0433 r_axis->SetLabelColor(kBlue);
0434 r_axis->SetTitleColor(kBlue);
0435 r_axis->SetTitleOffset(1.2);
0436 r_axis->SetTitle(h_LV.get()->GetYaxis()->GetTitle());
0437 r_axis->Draw();
0438
0439 std::string fileName(m_imageFileName);
0440 canvas.SaveAs(fileName.c_str());
0441
0442 return true;
0443 }
0444
0445 private:
0446 TrackerTopology m_trackerTopo;
0447 };
0448
0449 }
0450
0451 PAYLOAD_INSPECTOR_MODULE(SiStripDetVOff) {
0452 PAYLOAD_INSPECTOR_CLASS(SiStripDetVOff_LV);
0453 PAYLOAD_INSPECTOR_CLASS(SiStripDetVOff_HV);
0454 PAYLOAD_INSPECTOR_CLASS(SiStripDetVOff_IsModuleVOff_TrackerMap);
0455 PAYLOAD_INSPECTOR_CLASS(SiStripDetVOff_IsModuleLVOff_TrackerMap);
0456 PAYLOAD_INSPECTOR_CLASS(SiStripDetVOff_IsModuleHVOff_TrackerMap);
0457 PAYLOAD_INSPECTOR_CLASS(SiStripDetVOffTest);
0458 PAYLOAD_INSPECTOR_CLASS(SiStripVOffListOfModules);
0459 PAYLOAD_INSPECTOR_CLASS(SiStripLVOffListOfModules);
0460 PAYLOAD_INSPECTOR_CLASS(SiStripHVOffListOfModules);
0461 PAYLOAD_INSPECTOR_CLASS(SiStripDetVOffByRegion);
0462 }