diff --git a/CondCore/SiPixelPlugins/interface/SiPixelTemplateHelper.h b/CondCore/SiPixelPlugins/interface/SiPixelTemplateHelper.h index 873856e23addc..148d91168f24b 100644 --- a/CondCore/SiPixelPlugins/interface/SiPixelTemplateHelper.h +++ b/CondCore/SiPixelPlugins/interface/SiPixelTemplateHelper.h @@ -504,6 +504,277 @@ namespace templateHelper { std::string label_; }; + enum headerParam { + k_ID = 0, + k_NTy = 1, + k_NTyx = 2, + k_NTxx = 3, + k_Dtype = 4, + k_qscale = 5, + k_lorywidth = 6, + k_lorxwidth = 7, + k_lorybias = 8, + k_lorxbias = 9, + k_Vbias = 10, + k_temperature = 11, + k_fluence = 12, + k_s50 = 13, + k_ss50 = 14, + k_title = 15, + k_templ_version = 16, + k_Bfield = 17, + k_fbin = 18, + k_END_OF_TYPES = 19, + }; + + static constexpr const char* header_types[] = {"ID;templated ID", + "NTy;number of template y entries", + "NTyx;number of template y-slices of x entries", + "NTxx;number of template x-entries in each slice", + "Dtype;detector type (0=BPix, 1=FPix)", + "qScale;charge scaling correction", + "lorxwidth;estimate of the y-Lorentz width", + "lorywidth;estimate of the x-Lorentz width", + "lorybias;estimate of the y-Lorentz bias", + "lorxbias;estimate of the x-Lorentz bias", + "Vbias;detector bias [V]", + "temperature;detector temperature [K]", + "fluence;radiation fluence [n_{eq}/cm^{2}] ", + "s50;1/2 of the multihit dcol threshold [e]", + "ss50;1/2 of the single hit dcol threshold [e]", + "title;title", + "template version;template version number", + "B-field;B-field [T]", + "fbin;Qbin in Q_{clus}/Q_{avg}", + "NOT HERE;NOT HERE"}; + + // class to display values of the template header information in a Phase1 Pixel Map + template + class SiPixelTemplateHeaderInfo + : public cond::payloadInspector::PlotImage { + struct header_info { + int ID; //!< template ID number + int NTy; //!< number of Template y entries + int NTyx; //!< number of Template y-slices of x entries + int NTxx; //!< number of Template x-entries in each slice + int Dtype; //!< detector type (0=BPix, 1=FPix) + float qscale; //!< Charge scaling to match cmssw and pixelav + float lorywidth; //!< estimate of y-lorentz width for optimal resolution + float lorxwidth; //!< estimate of x-lorentz width for optimal resolution + float lorybias; //!< estimate of y-lorentz bias + float lorxbias; //!< estimate of x-lorentz bias + float Vbias; //!< detector bias potential in Volts + float temperature; //!< detector temperature in deg K + float fluence; //!< radiation fluence in n_eq/cm^2 + float s50; //!< 1/2 of the multihit dcol threshold in electrons + float ss50; //!< 1/2 of the single hit dcol threshold in electrons + char title[80]; //!< template title + int templ_version; //!< Version number of the template to ensure code compatibility + float Bfield; //!< Bfield in Tesla + float fbin[3]; //!< The QBin definitions in Q_clus/Q_avg + }; + + public: + SiPixelTemplateHeaderInfo() + : cond::payloadInspector::PlotImage( + "SiPixel CPE conditions Map of header quantities") { + if constexpr (std::is_same_v) { + isTemplate_ = false; + label_ = "SiPixelGenErrorDBObject_PayloadInspector"; + } else { + isTemplate_ = true; + label_ = "SiPixelTemplateDBObject_PayloadInspector"; + } + } + + bool fill() override { + gStyle->SetPalette(kRainBow); + if (!(myParam == headerParam::k_Vbias || myParam == headerParam::k_Dtype)) { + TGaxis::SetMaxDigits(2); + } + + auto tag = cond::payloadInspector::PlotBase::getTag<0>(); + auto iov = tag.iovs.front(); + const auto& tagname = tag.name; + std::vector thePixelTemp_; + std::shared_ptr payload = this->fetchPayload(std::get<1>(iov)); + + if (payload.get()) { + if (!TransientType::pushfile(*payload, thePixelTemp_)) { + throw cms::Exception(label_) << "\nERROR: Templates not filled correctly. Check the conditions. Using " + "payload version " + << payload->version() << "\n\n"; + } + + // store the map of ID / interesting quantities + SiPixelTemplate templ(thePixelTemp_); + for (const auto& theTemp : thePixelTemp_) { + header_info info; + info.ID = theTemp.head.ID; + info.NTy = theTemp.head.NTy; + info.NTyx = theTemp.head.NTyx; + info.NTxx = theTemp.head.NTxx; + info.Dtype = theTemp.head.Dtype; + info.qscale = theTemp.head.qscale; + info.lorywidth = theTemp.head.lorywidth; + info.lorxwidth = theTemp.head.lorxwidth; + info.lorybias = theTemp.head.lorybias; + info.lorxbias = theTemp.head.lorxbias; + info.Vbias = theTemp.head.Vbias; + info.temperature = theTemp.head.temperature; + info.fluence = theTemp.head.fluence; + info.s50 = theTemp.head.s50; + info.ss50 = theTemp.head.ss50; + info.templ_version = theTemp.head.templ_version; + info.Bfield = theTemp.head.Bfield; + theInfos_[theTemp.head.ID] = info; + } + + // Book the TH2Poly + Phase1PixelMaps theMaps(""); + if (myType == SiPixelPI::t_all) { + theMaps.resetOption("COLZA L"); + } else { + theMaps.resetOption("COLZL"); + } + + std::string input{header_types[myParam]}; + std::string delimiter = ";"; + std::string first = input.substr(0, input.find(delimiter)); + std::string second = input.substr(input.find(delimiter) + 1); + + if (myType == SiPixelPI::t_barrel) { + theMaps.bookBarrelHistograms("templateLABarrel", first.c_str(), second.c_str()); + } else if (myType == SiPixelPI::t_forward) { + theMaps.bookForwardHistograms("templateLAForward", first.c_str(), second.c_str()); + } else if (myType == SiPixelPI::t_all) { + theMaps.bookBarrelHistograms("templateLA", first.c_str(), second.c_str()); + theMaps.bookForwardHistograms("templateLA", first.c_str(), second.c_str()); + } else { + edm::LogError(label_) << " un-recognized detector type " << myType << std::endl; + return false; + } + + std::map templMap = payload->getTemplateIDs(); + if (templMap.size() == SiPixelPI::phase0size || templMap.size() > SiPixelPI::phase1size) { + edm::LogError(label_) + << "There are " << templMap.size() + << " DetIds in this payload. SiPixelTempate Lorentz Angle maps are not supported for non-Phase1 Pixel " + "geometries !"; + TCanvas canvas("Canv", "Canv", 1200, 1000); + SiPixelPI::displayNotSupported(canvas, templMap.size()); + std::string fileName(this->m_imageFileName); + canvas.SaveAs(fileName.c_str()); + return false; + } else { + if (templMap.size() < SiPixelPI::phase1size) { + edm::LogWarning(label_) << "\n ********* WARNING! ********* \n There are " << templMap.size() + << " DetIds in this payload !" + << "\n **************************** \n"; + } + } + + for (auto const& entry : templMap) { + //templ.interpolate(entry.second, 0.f, 0.f, 1.f, 1.f); + + const auto& theInfo = theInfos_[entry.second]; + + std::function cutFunctor = [](headerParam my_param, header_info myInfo) { + float ret(-999.); + switch (my_param) { + case k_ID: + return (float)myInfo.ID; + case k_NTy: + return (float)myInfo.NTy; + case k_NTyx: + return (float)myInfo.NTyx; + case k_NTxx: + return (float)myInfo.NTxx; + case k_Dtype: + return (float)myInfo.Dtype; + case k_qscale: + return (float)myInfo.qscale; + case k_lorywidth: + return (float)myInfo.lorywidth; + case k_lorxwidth: + return (float)myInfo.lorxwidth; + case k_lorybias: + return (float)myInfo.lorybias; + case k_lorxbias: + return (float)myInfo.lorxbias; + case k_Vbias: + return (float)myInfo.Vbias; + case k_temperature: + return (float)myInfo.temperature; + case k_fluence: + return (float)myInfo.fluence; + case k_s50: + return (float)myInfo.s50; + case k_ss50: + return (float)myInfo.ss50; + case k_title: + return (float)myInfo.templ_version; + case k_Bfield: + return (float)myInfo.Bfield; + case k_END_OF_TYPES: + return ret; + default: + return ret; + } + }; + + auto detid = DetId(entry.first); + if (myType == SiPixelPI::t_all) { + if ((detid.subdetId() == PixelSubdetector::PixelBarrel)) { + theMaps.fillBarrelBin("templateLA", entry.first, cutFunctor(myParam, theInfo)); + } + if ((detid.subdetId() == PixelSubdetector::PixelEndcap)) { + theMaps.fillForwardBin("templateLA", entry.first, cutFunctor(myParam, theInfo)); + } + } else if ((detid.subdetId() == PixelSubdetector::PixelBarrel) && (myType == SiPixelPI::t_barrel)) { + theMaps.fillBarrelBin("templateLABarrel", entry.first, cutFunctor(myParam, theInfo)); + } else if ((detid.subdetId() == PixelSubdetector::PixelEndcap) && (myType == SiPixelPI::t_forward)) { + theMaps.fillForwardBin("templateLAForward", entry.first, cutFunctor(myParam, theInfo)); + } + } + + theMaps.beautifyAllHistograms(); + + TCanvas canvas("Canv", "Canv", (myType == SiPixelPI::t_barrel) ? 1200 : 1600, 1000); + if (myType == SiPixelPI::t_barrel) { + theMaps.drawBarrelMaps("templateLABarrel", canvas); + } else if (myType == SiPixelPI::t_forward) { + theMaps.drawForwardMaps("templateLAForward", canvas); + } else if (myType == SiPixelPI::t_all) { + theMaps.drawSummaryMaps("templateLA", canvas); + } + + canvas.cd(); + TPaveText ksPt(0, 0, 0.88, 0.04, "NDC"); + ksPt.SetBorderSize(0); + ksPt.SetFillColor(0); + const char* textToAdd = Form("%s Tag: #color[2]{%s}, IOV: #color[2]{%s}. Payload hash: #color[2]{%s}", + (isTemplate_ ? "Template" : "GenError"), + tagname.c_str(), + std::to_string(std::get<0>(iov)).c_str(), + (std::get<1>(iov)).c_str()); + ksPt.AddText(textToAdd); + ksPt.Draw(); + + std::string fileName(this->m_imageFileName); + canvas.SaveAs(fileName.c_str()); + } + return true; + } // fill + + protected: + bool isTemplate_; + std::string label_; + + private: + std::map theInfos_; + }; + } // namespace templateHelper #endif diff --git a/CondCore/SiPixelPlugins/plugins/SiPixelTemplateDBObject_PayloadInspector.cc b/CondCore/SiPixelPlugins/plugins/SiPixelTemplateDBObject_PayloadInspector.cc index 73e5df5fbe066..724a489753074 100644 --- a/CondCore/SiPixelPlugins/plugins/SiPixelTemplateDBObject_PayloadInspector.cc +++ b/CondCore/SiPixelPlugins/plugins/SiPixelTemplateDBObject_PayloadInspector.cc @@ -137,6 +137,7 @@ namespace { auto tag = PlotBase::getTag<0>(); auto iov = tag.iovs.front(); + const auto& tagname = tag.name; std::vector thePixelTemp_; std::shared_ptr payload = fetchPayload(std::get<1>(iov)); @@ -243,6 +244,17 @@ namespace { theMaps.drawSummaryMaps("templateLA", canvas); } + canvas.cd(); + TPaveText ksPt(0, 0, 0.88, 0.04, "NDC"); + ksPt.SetBorderSize(0); + ksPt.SetFillColor(0); + const char* textToAdd = Form("Template Tag: #color[2]{%s}, IOV: #color[2]{%s}. Payload hash: #color[2]{%s}", + tagname.c_str(), + std::to_string(std::get<0>(iov)).c_str(), + (std::get<1>(iov)).c_str()); + ksPt.AddText(textToAdd); + ksPt.Draw(); + canvas.cd(); std::string fileName(m_imageFileName); canvas.SaveAs(fileName.c_str()); @@ -281,6 +293,43 @@ namespace { using SiPixelTemplateIDsFPixMap = SiPixelIDs; using SiPixelTemplateIDsMap = SiPixelIDs; + //************************************************ + // TH2Poly Map of qScale + //***********************************************/ + using SiPixelTemplateQScaleBPixMap = SiPixelTemplateHeaderInfo; + using SiPixelTemplateQScaleFPixMap = SiPixelTemplateHeaderInfo; + using SiPixelTemplateQScaleMap = SiPixelTemplateHeaderInfo; + + //************************************************ + // TH2Poly Map of Vbias + //***********************************************/ + using SiPixelTemplateVbiasBPixMap = SiPixelTemplateHeaderInfo; + using SiPixelTemplateVbiasFPixMap = SiPixelTemplateHeaderInfo; + using SiPixelTemplateVbiasMap = SiPixelTemplateHeaderInfo; } // namespace // Register the classes as boost python plugin @@ -295,4 +344,10 @@ PAYLOAD_INSPECTOR_MODULE(SiPixelTemplateDBObject) { PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateLAMap); PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateLABPixMap); PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateLAFPixMap); + PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateQScaleBPixMap); + PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateQScaleFPixMap); + PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateQScaleMap); + PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateVbiasBPixMap); + PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateVbiasFPixMap); + PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateVbiasMap); } diff --git a/CondCore/SiPixelPlugins/test/testSiPixelPayloadInspector.cpp b/CondCore/SiPixelPlugins/test/testSiPixelPayloadInspector.cpp index 3b94cf916ae54..4b22d7fea4270 100644 --- a/CondCore/SiPixelPlugins/test/testSiPixelPayloadInspector.cpp +++ b/CondCore/SiPixelPlugins/test/testSiPixelPayloadInspector.cpp @@ -156,6 +156,10 @@ int main(int argc, char** argv) { histo19.process(connectionString, PI::mk_input(tag, start, end)); edm::LogPrint("testSiPixelPayloadInspector") << histo19.data() << std::endl; + SiPixelTemplateQScaleMap histoQscale; + histoQscale.process(connectionString, PI::mk_input(tag, start, end)); + edm::LogPrint("testSiPixelPayloadInspector") << histoQscale.data() << std::endl; + // SiPixelVCal tag = "SiPixelVCal_v1"; diff --git a/CondCore/SiPixelPlugins/test/testSiPixelTemplateDBObject.sh b/CondCore/SiPixelPlugins/test/testSiPixelTemplateDBObject.sh index e87dea0971781..9bb7c45e8cd4d 100755 --- a/CondCore/SiPixelPlugins/test/testSiPixelTemplateDBObject.sh +++ b/CondCore/SiPixelPlugins/test/testSiPixelTemplateDBObject.sh @@ -90,6 +90,17 @@ getPayloadData.py \ mv *.png $W_DIR/plots_Template/HeaderTitles.png +getPayloadData.py \ + --plugin pluginSiPixelTemplateDBObject_PayloadInspector \ + --plot plot_SiPixelTemplateQScaleMap \ + --tag SiPixelTemplateDBObject38Tv3_express \ + --time_type Run \ + --iovs '{"start_iov": "326083", "end_iov": "326083"}' \ + --db Prod \ + --test ; + +mv *.png $W_DIR/plots_Template/QScaleMap.png + getPayloadData.py \ --plugin pluginSiPixel2DTemplateDBObject_PayloadInspector \ --plot plot_SiPixel2DTemplateHeaderTable \ diff --git a/DQM/TrackerRemapper/src/Phase1PixelMaps.cc b/DQM/TrackerRemapper/src/Phase1PixelMaps.cc index 6a2a0aceb4336..db06e79a252f9 100644 --- a/DQM/TrackerRemapper/src/Phase1PixelMaps.cc +++ b/DQM/TrackerRemapper/src/Phase1PixelMaps.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -334,7 +335,6 @@ void Phase1PixelMaps::setForwardScale(const std::string& currentHistoName, std:: //============================================================================ void Phase1PixelMaps::drawBarrelMaps(const std::string& currentHistoName, TCanvas& canvas, const char* drawOption) { - canvas.Divide(2, 2); auto found = (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) != m_knownNames.end()); if (!m_isBooked.first || !found) { @@ -342,15 +342,20 @@ void Phase1PixelMaps::drawBarrelMaps(const std::string& currentHistoName, TCanva return; } + TPad* pad1 = new TPad("pad1", "pad1", 0.0, 0.025, 1.0, 1.0); + TPad* pad2 = new TPad("pad2", "pad2", 0.0, 0.00, 1.0, 0.025); + pad1->Divide(2, 2); + pad1->Draw(); + pad2->Draw(); for (int i = 1; i <= 4; i++) { - canvas.cd(i); + pad1->cd(i); if (strcmp(m_option, "text") == 0) { - canvas.cd(i)->SetRightMargin(0.02); + pad1->cd(i)->SetRightMargin(0.02); pxbTh2PolyBarrel[currentHistoName].at(i - 1)->SetMarkerColor(kRed); } else { if (m_autorescale) rescaleAllBarrel(currentHistoName); - adjustCanvasMargins(canvas.cd(i), 0.07, 0.12, 0.10, 0.18); + adjustCanvasMargins(pad1->cd(i), 0.07, 0.12, 0.10, 0.18); } if (drawOption) { pxbTh2PolyBarrel[currentHistoName].at(i - 1)->Draw("L"); @@ -364,7 +369,6 @@ void Phase1PixelMaps::drawBarrelMaps(const std::string& currentHistoName, TCanva //============================================================================ void Phase1PixelMaps::drawForwardMaps(const std::string& currentHistoName, TCanvas& canvas, const char* drawOption) { - canvas.Divide(3, 2); auto found = (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) != m_knownNames.end()); if (!m_isBooked.second || !found) { @@ -372,15 +376,21 @@ void Phase1PixelMaps::drawForwardMaps(const std::string& currentHistoName, TCanv return; } + TPad* pad1 = new TPad("pad1", "pad1", 0.0, 0.025, 1.0, 1.0); + TPad* pad2 = new TPad("pad2", "pad2", 0.0, 0.00, 1.0, 0.025); + pad1->Divide(3, 2); + pad1->Draw(); + pad2->Draw(); + for (int i = 1; i <= 6; i++) { - canvas.cd(i); + pad1->cd(i); if (strcmp(m_option, "text") == 0) { - canvas.cd(i)->SetRightMargin(0.02); + pad1->cd(i)->SetRightMargin(0.02); pxfTh2PolyForward[currentHistoName].at(i - 1)->SetMarkerColor(kRed); } else { if (m_autorescale) rescaleAllForward(currentHistoName); - adjustCanvasMargins(canvas.cd(i), 0.07, 0.12, 0.10, 0.18); + adjustCanvasMargins(pad1->cd(i), 0.07, 0.12, 0.10, 0.18); } if (drawOption) { pxfTh2PolyForward[currentHistoName].at(i - 1)->Draw("L"); @@ -401,11 +411,16 @@ void Phase1PixelMaps::drawSummaryMaps(const std::string& currentHistoName, TCanv return; } - canvas.Divide(2, 1); - canvas.cd(1); + TPad* pad1 = new TPad("pad1", "pad1", 0.0, 0.025, 1.0, 1.0); + TPad* pad2 = new TPad("pad2", "pad2", 0.0, 0.00, 1.0, 0.025); + pad1->Divide(2, 1); + pad1->Draw(); + pad2->Draw(); + + pad1->cd(1); std::string temp(m_option); // create a std string auto isText = (temp.find("text") != std::string::npos); - adjustCanvasMargins(canvas.cd(1), 0.07, 0.02, 0.01, isText ? 0.05 : 0.15); + adjustCanvasMargins(pad1->cd(1), 0.07, 0.02, 0.01, isText ? 0.05 : 0.15); if (isText) { pxbTh2PolyBarrelSummary[currentHistoName]->SetMarkerColor(kRed); pxbTh2PolyBarrelSummary[currentHistoName]->SetMarkerSize(0.5); @@ -414,8 +429,8 @@ void Phase1PixelMaps::drawSummaryMaps(const std::string& currentHistoName, TCanv pxbTh2PolyBarrelSummary[currentHistoName]->Draw("AL"); pxbTh2PolyBarrelSummary[currentHistoName]->Draw(fmt::sprintf("%s%ssame", m_option, drawOption).c_str()); - canvas.cd(2); - adjustCanvasMargins(canvas.cd(2), 0.07, 0.02, 0.01, isText ? 0.05 : 0.15); + pad1->cd(2); + adjustCanvasMargins(pad1->cd(2), 0.07, 0.02, 0.01, isText ? 0.05 : 0.15); if (isText) { pxfTh2PolyForwardSummary[currentHistoName]->SetMarkerColor(kRed); pxfTh2PolyForwardSummary[currentHistoName]->SetMarkerSize(0.5);