From b8f074abbeef429bed1de16623ab935787733e4e Mon Sep 17 00:00:00 2001 From: mmusich Date: Wed, 7 Jul 2021 11:24:29 +0200 Subject: [PATCH 1/3] implement few bug-fixes in SiPixelVCal_PayloadInspector --- .../plugins/SiPixelVCal_PayloadInspector.cc | 173 ++++++++++-------- 1 file changed, 94 insertions(+), 79 deletions(-) diff --git a/CondCore/SiPixelPlugins/plugins/SiPixelVCal_PayloadInspector.cc b/CondCore/SiPixelPlugins/plugins/SiPixelVCal_PayloadInspector.cc index 7afd151eeb8e3..9f937d1ffdb3b 100644 --- a/CondCore/SiPixelPlugins/plugins/SiPixelVCal_PayloadInspector.cc +++ b/CondCore/SiPixelPlugins/plugins/SiPixelVCal_PayloadInspector.cc @@ -33,6 +33,8 @@ namespace { + using namespace cond::payloadInspector; + namespace SiPixelVCalPI { enum type { t_slope = 0, t_offset = 1 }; } @@ -42,15 +44,14 @@ namespace { *************************************************/ // inherit from one of the predefined plot class: Histogram1D template - class SiPixelVCalValue : public cond::payloadInspector::Histogram1D { + class SiPixelVCalValue : public Histogram1D { public: SiPixelVCalValue() - : cond::payloadInspector::Histogram1D( - "SiPixel VCal values", - "SiPixel VCal values", - 100, - myType == SiPixelVCalPI::t_slope ? 40. : -700, - myType == SiPixelVCalPI::t_slope ? 60. : 0) {} + : Histogram1D("SiPixel VCal values", + "SiPixel VCal values", + 100, + myType == SiPixelVCalPI::t_slope ? 40. : -700, + myType == SiPixelVCalPI::t_slope ? 60. : 0) {} bool fill() override { auto tag = PlotBase::getTag<0>(); @@ -77,10 +78,9 @@ namespace { /************************************************ 1d histogram of SiPixelVCal of 1 IOV *************************************************/ - class SiPixelVCalValues : public cond::payloadInspector::PlotImage { + class SiPixelVCalValues : public PlotImage { public: - SiPixelVCalValues() - : cond::payloadInspector::PlotImage("SiPixelVCal Values") {} + SiPixelVCalValues() : PlotImage("SiPixelVCal Values") {} bool fill() override { gStyle->SetOptStat("emr"); @@ -195,17 +195,15 @@ namespace { 1d histogram of SiPixelVCal of 1 IOV per region *************************************************/ template - class SiPixelVCalValuesPerRegion - : public cond::payloadInspector::PlotImage { + class SiPixelVCalValuesPerRegion : public PlotImage { public: - SiPixelVCalValuesPerRegion() - : cond::payloadInspector::PlotImage( - "SiPixelVCal Values per region") {} + SiPixelVCalValuesPerRegion() : PlotImage("SiPixelVCal Values per region") {} bool fill() override { gStyle->SetOptStat("emr"); auto tag = PlotBase::getTag<0>(); + auto tagname = tag.name; auto iov = tag.iovs.front(); std::shared_ptr payload = fetchPayload(std::get<1>(iov)); SiPixelVCal::mapToDetId Map_; @@ -279,7 +277,11 @@ namespace { canvas.cd(c); ltx.DrawLatexNDC(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, - (PixelRegions::IDlabels.at(index) + ", IOV:" + std::to_string(std::get<0>(iov))).c_str()); + fmt::sprintf("%s, #color[2]{%s, IOV: %s}", + PixelRegions::IDlabels.at(index), + tagname, + std::to_string(std::get<0>(iov))) + .c_str()); } std::string fileName(m_imageFileName); @@ -298,20 +300,18 @@ namespace { /************************************************ 1d histogram of SiPixelVCal (slope or offset) of 2 IOV per region *************************************************/ - template - class SiPixelVCalValuesComparisonPerRegion - : public cond::payloadInspector::PlotImage { + template + class SiPixelVCalValuesCompareSubdet : public PlotImage { public: - SiPixelVCalValuesComparisonPerRegion() - : cond::payloadInspector::PlotImage( - Form("SiPixelVCal Values Comparisons per region %i tags(s)", ntags)) {} + SiPixelVCalValuesCompareSubdet() + : PlotImage(Form("SiPixelVCal Values Comparisons by Subdet %i tags(s)", ntags)) {} bool fill() override { gStyle->SetOptStat("emr"); // trick to deal with the multi-ioved tag and two tag case at the same time - auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs; - auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().name; + auto theIOVs = PlotBase::getTag<0>().iovs; + auto f_tagname = PlotBase::getTag<0>().name; std::string l_tagname = ""; auto firstiov = theIOVs.front(); std::tuple lastiov; @@ -320,8 +320,8 @@ namespace { assert(this->m_plotAnnotations.ntags < 3); if (this->m_plotAnnotations.ntags == 2) { - auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs; - l_tagname = cond::payloadInspector::PlotBase::getTag<1>().name; + auto tag2iovs = PlotBase::getTag<1>().iovs; + l_tagname = PlotBase::getTag<1>().name; lastiov = tag2iovs.front(); } else { lastiov = theIOVs.back(); @@ -373,14 +373,16 @@ namespace { auto l_tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath(path_toTopologyXML).fullPath()); + auto delta = std::abs(max - min) / 10.; + auto l_myPlots = PixelRegions::PixelRegionContainers(&l_tTopo, l_phaseInfo.phase()); l_myPlots.bookAll( fmt::sprintf("SiPixel VCal %s,last", (myType == SiPixelVCalPI::t_slope ? "slope" : "offset")), fmt::sprintf("SiPixel VCal %s", (myType == SiPixelVCalPI::t_slope ? " slope [ADC/VCal]" : " offset [ADC]")), "#modules", 50, - min * 0.9, - max * 1.1); + min - delta, + max + delta); for (const auto &element : l_Map_) { l_myPlots.fill(element.first, element.second); @@ -402,8 +404,8 @@ namespace { fmt::sprintf("SiPixel VCal %s", (myType == SiPixelVCalPI::t_slope ? " slope [ADC/VCal]" : " offset [ADC]")), "#modules", 50, - min * 0.9, - max * 1.1); + min - delta, + max + delta); for (const auto &element : f_Map_) { f_myPlots.fill(element.first, element.second); @@ -465,45 +467,61 @@ namespace { } }; - using SiPixelVCalSlopesBarrelCompareSingleTag = SiPixelVCalValuesComparisonPerRegion; + using SiPixelVCalSlopesBarrelCompareSingleTag = + SiPixelVCalValuesCompareSubdet; using SiPixelVCalOffsetsBarrelCompareSingleTag = - SiPixelVCalValuesComparisonPerRegion; + SiPixelVCalValuesCompareSubdet; using SiPixelVCalSlopesEndcapCompareSingleTag = - SiPixelVCalValuesComparisonPerRegion; + SiPixelVCalValuesCompareSubdet; using SiPixelVCalOffsetsEndcapCompareSingleTag = - SiPixelVCalValuesComparisonPerRegion; + SiPixelVCalValuesCompareSubdet; - using SiPixelVCalSlopesBarrelCompareTwoTags = SiPixelVCalValuesComparisonPerRegion; - using SiPixelVCalOffsetsBarrelCompareTwoTags = SiPixelVCalValuesComparisonPerRegion; + using SiPixelVCalSlopesBarrelCompareTwoTags = + SiPixelVCalValuesCompareSubdet; + using SiPixelVCalOffsetsBarrelCompareTwoTags = + SiPixelVCalValuesCompareSubdet; - using SiPixelVCalSlopesEndcapCompareTwoTags = SiPixelVCalValuesComparisonPerRegion; + using SiPixelVCalSlopesEndcapCompareTwoTags = + SiPixelVCalValuesCompareSubdet; using SiPixelVCalOffsetsEndcapCompareTwoTags = - SiPixelVCalValuesComparisonPerRegion; + SiPixelVCalValuesCompareSubdet; /************************************************ 1d histogram of SiPixelVCal of 1 IOV *************************************************/ - template - class SiPixelVCalValueComparisonBase : public cond::payloadInspector::PlotImage { + template + class SiPixelVCalValueComparisonBase : public PlotImage { public: SiPixelVCalValueComparisonBase() - : cond::payloadInspector::PlotImage("SiPixelVCal Values Comparison") {} - bool fill(const std::vector> &iovs) override { + : PlotImage(Form("SiPixelVCal Synoptic Values Comparison %i tag(s)", ntags)) {} + + bool fill() override { TH1F::SetDefaultSumw2(true); - std::vector> sorted_iovs = iovs; - // make absolute sure the IOVs are sortd by since - std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) { - return std::get<0>(t1) < std::get<0>(t2); - }); - auto firstiov = sorted_iovs.front(); - auto lastiov = sorted_iovs.back(); + + // trick to deal with the multi-ioved tag and two tag case at the same time + auto theIOVs = PlotBase::getTag<0>().iovs; + auto f_tagname = PlotBase::getTag<0>().name; + std::string l_tagname = ""; + auto firstiov = theIOVs.front(); + std::tuple lastiov; + + // we don't support (yet) comparison with more than 2 tags + assert(this->m_plotAnnotations.ntags < 3); + + if (this->m_plotAnnotations.ntags == 2) { + auto tag2iovs = PlotBase::getTag<1>().iovs; + l_tagname = PlotBase::getTag<1>().name; + lastiov = tag2iovs.front(); + } else { + lastiov = theIOVs.back(); + } SiPixelVCal::mapToDetId l_Map_; SiPixelVCal::mapToDetId f_Map_; - std::shared_ptr last_payload = fetchPayload(std::get<1>(lastiov)); + std::shared_ptr last_payload = this->fetchPayload(std::get<1>(lastiov)); if (myType == SiPixelVCalPI::t_slope) { l_Map_ = last_payload->getAllSlopes(); } else { @@ -511,7 +529,7 @@ namespace { } auto l_extrema = SiPixelPI::findMinMaxInMap(l_Map_); - std::shared_ptr first_payload = fetchPayload(std::get<1>(firstiov)); + std::shared_ptr first_payload = this->fetchPayload(std::get<1>(firstiov)); if (myType == SiPixelVCalPI::t_slope) { f_Map_ = first_payload->getAllSlopes(); } else { @@ -521,6 +539,7 @@ namespace { auto max = (l_extrema.second > f_extrema.second) ? l_extrema.second : f_extrema.second; auto min = (l_extrema.first < f_extrema.first) ? l_extrema.first : f_extrema.first; + auto delta = std::abs(max - min) / 10.; std::string lastIOVsince = std::to_string(std::get<0>(lastiov)); std::string firstIOVsince = std::to_string(std::get<0>(firstiov)); @@ -534,8 +553,8 @@ namespace { (myType == SiPixelVCalPI::t_slope ? " slope [ADC/VCal]" : " offset [ADC]")) .c_str(), 50, - min * 0.9, - max * 1.1)); + min - delta, + max + delta)); hfirst->SetStats(false); auto hlast = std::unique_ptr( @@ -545,8 +564,8 @@ namespace { (myType == SiPixelVCalPI::t_slope ? " slope [ADC/VCal]" : " offset [ADC]")) .c_str(), 50, - min * 0.9, - max * 1.1)); + min - delta, + max + delta)); hlast->SetStats(false); SiPixelPI::adjustCanvasMargins(canvas.cd(), 0.06, 0.12, 0.12, 0.05); @@ -586,38 +605,34 @@ namespace { auto ltx = TLatex(); ltx.SetTextFont(62); - ltx.SetTextSize(0.047); + ltx.SetTextSize(0.040); ltx.SetTextAlign(11); - ltx.DrawLatexNDC(gPad->GetLeftMargin(), - 1 - gPad->GetTopMargin() + 0.01, - ("SiPixel VCal IOV: #color[2]{" + std::to_string(std::get<0>(firstiov)) + - "} vs IOV: #color[4]{" + std::to_string(std::get<0>(lastiov)) + "}") - .c_str()); + std::string ltxText; + if (this->m_plotAnnotations.ntags == 2) { + ltxText = fmt::sprintf("#color[2]{%s, %s} vs #color[4]{%s, %s}", + f_tagname, + std::to_string(std::get<0>(firstiov)), + l_tagname, + std::to_string(std::get<0>(lastiov))); + } else { + ltxText = fmt::sprintf("%s IOV: #color[2]{%s} vs IOV: #color[4]{%s}", + f_tagname, + std::to_string(std::get<0>(firstiov)), + std::to_string(std::get<0>(lastiov))); + } + ltx.DrawLatexNDC(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, ltxText.c_str()); - std::string fileName(m_imageFileName); + std::string fileName(this->m_imageFileName); canvas.SaveAs(fileName.c_str()); return true; } }; - template - class SiPixelVCalValueComparisonSingleTag : public SiPixelVCalValueComparisonBase { - public: - SiPixelVCalValueComparisonSingleTag() : SiPixelVCalValueComparisonBase() { this->setSingleIov(false); } - }; - - template - class SiPixelVCalValueComparisonTwoTags : public SiPixelVCalValueComparisonBase { - public: - SiPixelVCalValueComparisonTwoTags() : SiPixelVCalValueComparisonBase() { this->setTwoTags(true); } - }; - - using SiPixelVCalSlopesComparisonSingleTag = SiPixelVCalValueComparisonSingleTag; - using SiPixelVCalOffsetsComparisonSingleTag = SiPixelVCalValueComparisonSingleTag; - - using SiPixelVCalSlopesComparisonTwoTags = SiPixelVCalValueComparisonTwoTags; - using SiPixelVCalOffsetsComparisonTwoTags = SiPixelVCalValueComparisonTwoTags; + using SiPixelVCalSlopesComparisonSingleTag = SiPixelVCalValueComparisonBase; + using SiPixelVCalOffsetsComparisonSingleTag = SiPixelVCalValueComparisonBase; + using SiPixelVCalSlopesComparisonTwoTags = SiPixelVCalValueComparisonBase; + using SiPixelVCalOffsetsComparisonTwoTags = SiPixelVCalValueComparisonBase; } // namespace From 9000fd6dd3dfa3f2091e5783dab25791511f434e Mon Sep 17 00:00:00 2001 From: mmusich Date: Wed, 7 Jul 2021 11:31:47 +0200 Subject: [PATCH 2/3] add SiPixelVCal test script --- .../SiPixelPlugins/test/testSiPixelVCal.sh | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 CondCore/SiPixelPlugins/test/testSiPixelVCal.sh diff --git a/CondCore/SiPixelPlugins/test/testSiPixelVCal.sh b/CondCore/SiPixelPlugins/test/testSiPixelVCal.sh new file mode 100755 index 0000000000000..4a26d111a7585 --- /dev/null +++ b/CondCore/SiPixelPlugins/test/testSiPixelVCal.sh @@ -0,0 +1,59 @@ +#!/bin/bash +# Save current working dir so img can be outputted there later +W_DIR=$(pwd); +# Set SCRAM architecture var +SCRAM_ARCH=slc7_amd64_gcc900; +export SCRAM_ARCH; +source /afs/cern.ch/cms/cmsset_default.sh; +eval `scram run -sh`; +# Go back to original working directory +cd $W_DIR; +# Run get payload data script +if [ -d $W_DIR/plots_VCal ]; then + rm -fr $W_DIR/plots_VCal +fi + +mkdir $W_DIR/plots_VCal + +TAGA=SiPixelVCal_v1 +TAGB=SiPixelVCal_phase1_2021_v0 + +## start with single tag plots + +singleTagPlots=(SiPixelVCalValues SiPixelVCalSlopeValuesBarrel SiPixelVCalSlopeValuesEndcap SiPixelVCalOffsetValuesBarrel SiPixelVCalOffsetValuesEndcap) + +for i in "${singleTagPlots[@]}" +do + echo "Processing: $i plot" + + getPayloadData.py \ + --plugin pluginSiPixelVCal_PayloadInspector \ + --plot plot_${i} \ + --tag $TAGA \ + --time_type Run \ + --iovs '{"start_iov": "1", "end_iov": "1"}' \ + --db Prep \ + --test; + + mv *.png $W_DIR/plots_VCal/${i}.png +done + +twoTagPlots=(SiPixelVCalSlopesBarrelCompareTwoTags SiPixelVCalOffsetsBarrelCompareTwoTags SiPixelVCalSlopesEndcapCompareTwoTags SiPixelVCalOffsetsEndcapCompareTwoTags SiPixelVCalSlopesComparisonTwoTags SiPixelVCalOffsetsComparisonTwoTags) + +for j in "${twoTagPlots[@]}" +do + echo "Processing: $j plot" + + getPayloadData.py \ + --plugin pluginSiPixelVCal_PayloadInspector \ + --plot plot_${j} \ + --tag $TAGA \ + --tagtwo $TAGB \ + --time_type Run \ + --iovs '{"start_iov": "1", "end_iov": "1"}' \ + --iovstwo '{"start_iov": "1", "end_iov": "1"}' \ + --db Prep \ + --test; + + mv *.png $W_DIR/plots_VCal/${j}.png +done From 9e4545b6e1f3c44666297ed5f44c2b13acfcdb0b Mon Sep 17 00:00:00 2001 From: mmusich Date: Wed, 7 Jul 2021 12:04:22 +0200 Subject: [PATCH 3/3] migrate SiPixelLorentzAngle_PayloadInspector to use class templates from #29622 --- .../SiPixelLorentzAngle_PayloadInspector.cc | 74 +++++++++++-------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/CondCore/SiPixelPlugins/plugins/SiPixelLorentzAngle_PayloadInspector.cc b/CondCore/SiPixelPlugins/plugins/SiPixelLorentzAngle_PayloadInspector.cc index 66f3678066beb..4adb701009f1c 100644 --- a/CondCore/SiPixelPlugins/plugins/SiPixelLorentzAngle_PayloadInspector.cc +++ b/CondCore/SiPixelPlugins/plugins/SiPixelLorentzAngle_PayloadInspector.cc @@ -404,27 +404,41 @@ namespace { SiPixelLorentzAngleValuesComparisonPerRegion; /************************************************ - 1d histogram of SiPixelLorentzAngle of 1 IOV + 1d histogram of SiPixelLorentzAngle comparisons *************************************************/ - class SiPixelLorentzAngleValueComparisonBase : public PlotImage { + template + class SiPixelLorentzAngleValueComparisonBase : public PlotImage { public: SiPixelLorentzAngleValueComparisonBase() - : PlotImage("SiPixelLorentzAngle Values Comparison") {} - bool fill(const std::vector> &iovs) override { + : PlotImage(Form("SiPixelLorentzAngle Values Comparison %i tag(s)", ntags)) { + } + + bool fill() override { TH1F::SetDefaultSumw2(true); - std::vector> sorted_iovs = iovs; - // make absolute sure the IOVs are sortd by since - std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) { - return std::get<0>(t1) < std::get<0>(t2); - }); - auto firstiov = sorted_iovs.front(); - auto lastiov = sorted_iovs.back(); - - std::shared_ptr last_payload = fetchPayload(std::get<1>(lastiov)); + + // trick to deal with the multi-ioved tag and two tag case at the same time + auto theIOVs = PlotBase::getTag<0>().iovs; + auto f_tagname = PlotBase::getTag<0>().name; + std::string l_tagname = ""; + auto firstiov = theIOVs.front(); + std::tuple lastiov; + + // we don't support (yet) comparison with more than 2 tags + assert(this->m_plotAnnotations.ntags < 3); + + if (this->m_plotAnnotations.ntags == 2) { + auto tag2iovs = PlotBase::getTag<1>().iovs; + l_tagname = PlotBase::getTag<1>().name; + lastiov = tag2iovs.front(); + } else { + lastiov = theIOVs.back(); + } + + std::shared_ptr last_payload = this->fetchPayload(std::get<1>(lastiov)); std::map l_LAMap_ = last_payload->getLorentzAngles(); auto l_extrema = SiPixelPI::findMinMaxInMap(l_LAMap_); - std::shared_ptr first_payload = fetchPayload(std::get<1>(firstiov)); + std::shared_ptr first_payload = this->fetchPayload(std::get<1>(firstiov)); std::map f_LAMap_ = first_payload->getLorentzAngles(); auto f_extrema = SiPixelPI::findMinMaxInMap(f_LAMap_); @@ -495,28 +509,30 @@ namespace { //ltx.SetTextColor(kBlue); ltx.SetTextSize(0.047); ltx.SetTextAlign(11); - ltx.DrawLatexNDC(gPad->GetLeftMargin(), - 1 - gPad->GetTopMargin() + 0.01, - ("SiPixel Lorentz Angle IOV: #color[2]{" + std::to_string(std::get<0>(firstiov)) + - "} vs IOV: #color[4]{" + std::to_string(std::get<0>(lastiov)) + "}") - .c_str()); + std::string ltxText; + if (this->m_plotAnnotations.ntags == 2) { + ltxText = fmt::sprintf("#color[2]{%s, %s} vs #color[4]{%s, %s}", + f_tagname, + std::to_string(std::get<0>(firstiov)), + l_tagname, + std::to_string(std::get<0>(lastiov))); + } else { + ltxText = fmt::sprintf("%s IOV: #color[2]{%s} vs IOV: #color[4]{%s}", + f_tagname, + std::to_string(std::get<0>(firstiov)), + std::to_string(std::get<0>(lastiov))); + } + ltx.DrawLatexNDC(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, ltxText.c_str()); - std::string fileName(m_imageFileName); + std::string fileName(this->m_imageFileName); canvas.SaveAs(fileName.c_str()); return true; } }; - class SiPixelLorentzAngleValueComparisonSingleTag : public SiPixelLorentzAngleValueComparisonBase { - public: - SiPixelLorentzAngleValueComparisonSingleTag() : SiPixelLorentzAngleValueComparisonBase() { setSingleIov(false); } - }; - - class SiPixelLorentzAngleValueComparisonTwoTags : public SiPixelLorentzAngleValueComparisonBase { - public: - SiPixelLorentzAngleValueComparisonTwoTags() : SiPixelLorentzAngleValueComparisonBase() { setTwoTags(true); } - }; + using SiPixelLorentzAngleValueComparisonSingleTag = SiPixelLorentzAngleValueComparisonBase; + using SiPixelLorentzAngleValueComparisonTwoTags = SiPixelLorentzAngleValueComparisonBase; /************************************************ Summary Comparison per region of SiPixelLorentzAngle between 2 IOVs