1 #ifndef CONDCORE_SIPIXELPLUGINS_SIPIXELGAINCALIBHELPER_H
2 #define CONDCORE_SIPIXELPLUGINS_SIPIXELGAINCALIBHELPER_H
16 #include <type_traits>
19 #include <fmt/printf.h>
30 #include "TPaveStats.h"
35 using AvgMap = std::map<uint32_t, float>;
37 namespace gainCalibPI {
43 template <
typename PayloadType>
44 static std::array<std::shared_ptr<TH1F>, 2>
fillDiffAndRatio(
const std::shared_ptr<PayloadType>& payload_A,
45 const std::shared_ptr<PayloadType>& payload_B,
47 std::array<std::shared_ptr<TH1F>, 2> arr;
49 std::vector<uint32_t> detids_A;
50 payload_A->getDetIds(detids_A);
51 std::vector<uint32_t> detids_B;
52 payload_B->getDetIds(detids_B);
54 std::vector<float> v_ratios;
55 std::vector<float> v_diffs;
57 if (detids_A != detids_B) {
58 edm::LogError(
"fillDiffAndRatio") <<
"the list of DetIds for the two payloads are not equal"
59 <<
" cannot make any comparison!" << std::endl;
62 assert(detids_A == detids_B);
63 for (
const auto&
d : detids_A) {
64 auto range = payload_A->getRange(
d);
65 int numberOfRowsToAverageOver = payload_A->getNumberOfRowsToAverageOver();
66 int ncols = payload_A->getNCols(
d);
67 int nRocsInRow = (
range.second -
range.first) /
ncols / numberOfRowsToAverageOver;
68 unsigned int nRowsForHLT = 1;
69 int nrows =
std::max((payload_A->getNumberOfRowsToAverageOver() * nRocsInRow),
72 auto rAndCol_A = payload_A->getRangeAndNCols(
d);
73 auto rAndCol_B = payload_B->getRangeAndNCols(
d);
74 bool isDeadCol, isNoisyCol;
78 for (
int row = 0; row < nrows; row++) {
81 auto gainA = payload_A->getGain(
col, row, rAndCol_A.first, rAndCol_A.second, isDeadCol, isNoisyCol);
82 auto gainB = payload_B->getGain(
col, row, rAndCol_B.first, rAndCol_B.second, isDeadCol, isNoisyCol);
83 ratio = gainB != 0 ? (gainA / gainB) : -1.;
88 auto pedA = payload_A->getPed(
col, row, rAndCol_A.first, rAndCol_A.second, isDeadCol, isNoisyCol);
89 auto pedB = payload_B->getPed(
col, row, rAndCol_B.first, rAndCol_B.second, isDeadCol, isNoisyCol);
90 ratio = pedB != 0 ? (pedA / pedB) : -1.;
95 edm::LogError(
"gainCalibPI::fillTheHisto") <<
"Unrecognized type " << theType << std::endl;
99 v_diffs.push_back(
diff);
100 v_ratios.push_back(
ratio);
105 std::sort(v_diffs.begin(), v_diffs.end());
106 std::sort(v_ratios.begin(), v_ratios.end());
108 double minDiff = v_diffs.front();
109 double maxDiff = v_diffs.back();
110 double minRatio = v_ratios.front();
111 double maxRatio = v_ratios.back();
113 arr[0] = std::make_shared<TH1F>(
"h_Ratio",
"", 50, minRatio - 1., maxRatio + 1.);
114 arr[1] = std::make_shared<TH1F>(
"h_Diff",
"", 50, minDiff - 1.,
maxDiff + 1.);
116 for (
const auto&
r : v_ratios) {
119 for (
const auto&
d : v_diffs) {
127 template <
typename PayloadType>
129 std::shared_ptr<TH1F> h1,
131 const std::vector<uint32_t>& wantedIds = {}) {
132 std::vector<uint32_t> detids;
133 if (wantedIds.empty()) {
136 detids.assign(wantedIds.begin(), wantedIds.end());
139 for (
const auto&
d : detids) {
145 int numberOfRowsToAverageOver =
payload->getNumberOfRowsToAverageOver();
147 int nRocsInRow = (
range.second -
range.first) /
ncols / numberOfRowsToAverageOver;
148 unsigned int nRowsForHLT = 1;
149 int nrows =
std::max((
payload->getNumberOfRowsToAverageOver() * nRocsInRow),
152 auto rangeAndCol =
payload->getRangeAndNCols(
d);
156 COUT <<
"NCOLS: " <<
payload->getNCols(
d) <<
" " << rangeAndCol.second <<
" NROWS:" << nrows
157 <<
", RANGES: " << rangeAndCol.first.second - rangeAndCol.first.first
158 <<
", Ratio: " <<
float(rangeAndCol.first.second - rangeAndCol.first.first) / rangeAndCol.second
164 for (
int row = 0; row < nrows; row++) {
167 quid =
payload->getGain(
col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
170 quid =
payload->getPed(
col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
173 edm::LogError(
"gainCalibPI::fillTheHisto") <<
"Unrecognized type " << theType << std::endl;
184 template <
typename PayloadType>
188 std::vector<uint32_t> detids;
191 for (
const auto&
d : detids) {
193 int numberOfRowsToAverageOver =
payload->getNumberOfRowsToAverageOver();
195 int nRocsInRow = (
range.second -
range.first) /
ncols / numberOfRowsToAverageOver;
196 unsigned int nRowsForHLT = 1;
197 int nrows =
std::max((
payload->getNumberOfRowsToAverageOver() * nRocsInRow),
200 auto rangeAndCol =
payload->getRangeAndNCols(
d);
207 for (
int row = 0; row < nrows; row++) {
212 payload->getGain(
col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
215 sumOfX +=
payload->getPed(
col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
218 edm::LogError(
"gainCalibPI::fillThePerModuleMap") <<
"Unrecognized type " << theType << std::endl;
224 map[
d] = sumOfX / nPixels;
230 template <
typename PayloadType>
232 std::shared_ptr<TH1> hBPix,
233 std::shared_ptr<TH1> hFPix,
235 std::vector<uint32_t> detids;
240 for (
const auto&
d : detids) {
243 int numberOfRowsToAverageOver =
payload->getNumberOfRowsToAverageOver();
245 int nRocsInRow = (
range.second -
range.first) /
ncols / numberOfRowsToAverageOver;
246 unsigned int nRowsForHLT = 1;
247 int nrows =
std::max((
payload->getNumberOfRowsToAverageOver() * nRocsInRow),
250 auto rangeAndCol =
payload->getRangeAndNCols(
d);
255 for (
int row = 0; row < nrows; row++) {
256 float gain =
payload->getGain(
col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
257 float ped =
payload->getPed(
col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
261 if (isCorrelation_) {
262 hBPix->Fill(
gain, ped);
269 if (isCorrelation_) {
270 hFPix->Fill(
gain, ped);
277 edm::LogError(
"gainCalibPI::fillTheHistos") <<
d <<
" is not a Pixel DetId" << std::endl;
286 constexpr
char const*
TypeName[2] = {
"Gains",
"Pedestals"};
291 template <gainCalibPI::type myType,
class PayloadType>
297 Form(
"SiPixelGainCalibration %s Values",
TypeName[myType])) {
298 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
300 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
303 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
308 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
309 auto iov =
tag.iovs.front();
313 gStyle->SetOptStat(
"emr");
315 float minimum(9999.);
316 float maximum(-9999.);
320 maximum =
payload->getGainHigh();
321 minimum =
payload->getGainLow();
324 maximum =
payload->getPedHigh();
325 minimum =
payload->getPedLow();
332 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
333 auto h1 = std::make_shared<TH1F>(Form(
"%s values",
TypeName[myType]),
334 Form(
"SiPixel Gain Calibration %s - %s;per %s %s;# %ss",
352 h1->GetYaxis()->SetRangeUser(0.1, h1->GetMaximum() * 10.);
353 h1->SetFillColor(kBlue);
354 h1->SetMarkerStyle(20);
355 h1->SetMarkerSize(1);
363 TLegend
legend = TLegend(0.40, 0.88, 0.94, 0.93);
364 legend.SetHeader((
"Payload hash: #bf{" + (std::get<1>(iov)) +
"}").c_str(),
368 legend.SetTextSize(0.025);
371 TPaveStats* st = (TPaveStats*)h1->FindObject(
"stats");
372 st->SetTextSize(0.03);
378 ltx.SetTextSize(0.05);
379 ltx.SetTextAlign(11);
380 ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.1,
381 1 - gPad->GetTopMargin() + 0.01,
382 (
"SiPixel Gain Calibration IOV:" + std::to_string(std::get<0>(iov))).c_str());
398 template <
bool isBarrel, gainCalibPI::type myType,
class PayloadType>
404 Form(
"SiPixelGainCalibration %s Values Per Region",
TypeName[myType])) {
407 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
409 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
412 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
416 bool fill()
override {
417 gStyle->SetOptStat(
"mr");
419 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
420 auto iov =
tag.iovs.front();
425 auto ip = paramValues.find(
"SetLog");
426 if (ip != paramValues.end()) {
427 auto answer = boost::lexical_cast<std::string>(ip->second);
431 <<
" is not a valid setting for this parameter, please use True,False,1,0,Yes,No \n\n";
437 std::vector<uint32_t> detids;
440 float minimum(9999.);
441 float maximum(-9999.);
445 maximum =
payload->getGainHigh();
446 minimum =
payload->getGainLow();
449 maximum =
payload->getPedHigh();
450 minimum =
payload->getPedLow();
476 Form(
"# %ss", (
isForHLT_ ?
"column" :
"pixel")),
490 myPlots.setLogScale();
492 myPlots.beautify(kBlue, -1);
495 TLegend
legend = TLegend(0.45, 0.88, 0.91, 0.92);
496 legend.SetHeader((
"hash: #bf{" + (std::get<1>(iov)) +
"}").c_str(),
500 legend.SetTextSize(0.025);
503 unsigned int maxPads =
isBarrel ? 4 : 12;
504 for (
unsigned int c = 1;
c <= maxPads;
c++) {
515 ltx.SetTextSize(0.05);
516 ltx.SetTextAlign(11);
518 for (
unsigned int c = 1;
c <= maxPads;
c++) {
521 auto leftX = setLog ? 0. : 0.1;
522 ltx.DrawLatexNDC(gPad->GetLeftMargin() + leftX,
523 1 - gPad->GetTopMargin() + 0.01,
551 Form(
"SiPixelGainCalibration %s Values Per Region %i tag(s)",
TypeName[myType],
ntags)) {
554 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
556 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
559 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
563 bool fill()
override {
564 gStyle->SetOptStat(
"mr");
569 auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
570 auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().name;
572 auto firstiov = theIOVs.front();
573 std::tuple<cond::Time_t, cond::Hash> lastiov;
579 auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
580 l_tagname = cond::payloadInspector::PlotBase::getTag<1>().name;
581 lastiov = tag2iovs.front();
583 lastiov = theIOVs.back();
589 auto ip = paramValues.find(
"SetLog");
590 if (ip != paramValues.end()) {
591 auto answer = boost::lexical_cast<std::string>(ip->second);
595 <<
" is not a valid setting for this parameter, please use True,False,1,0,Yes,No \n\n";
599 std::shared_ptr<PayloadType> last_payload = this->
fetchPayload(std::get<1>(lastiov));
600 std::shared_ptr<PayloadType> first_payload = this->
fetchPayload(std::get<1>(firstiov));
602 std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
603 std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
605 std::vector<uint32_t> f_detids, l_detids;
606 last_payload->getDetIds(l_detids);
607 first_payload->getDetIds(f_detids);
609 float minimum(9999.);
610 float maximum(-9999.);
614 maximum =
std::max(last_payload->getGainHigh(), first_payload->getGainHigh());
615 minimum =
std::min(last_payload->getGainLow(), first_payload->getGainLow());
618 maximum =
std::max(last_payload->getPedHigh(), first_payload->getPedHigh());
619 minimum =
std::min(last_payload->getPedLow(), first_payload->getPedLow());
638 const char* path_toTopologyXML = l_phaseInfo.
pathToTopoXML();
645 Form(
"Last SiPixel Gain Calibration %s - %s", (
isForHLT_ ?
"ForHLT" :
"Offline"),
TypeName[myType]),
647 Form(
"# %ss", (
isForHLT_ ?
"column" :
"pixel")),
652 path_toTopologyXML = f_phaseInfo.pathToTopoXML();
659 Form(
"First SiPixel Gain Calibration %s - %s", (
isForHLT_ ?
"ForHLT" :
"Offline"),
TypeName[myType]),
661 Form(
"# %ss", (
isForHLT_ ?
"column" :
"pixel")),
675 f_myPlots.setLogScale();
676 l_myPlots.setLogScale();
679 l_myPlots.beautify(kRed, -1);
680 f_myPlots.beautify(kAzure, -1);
682 l_myPlots.draw(
canvas,
isBarrel,
"HIST", f_phaseInfo.isPhase1Comparison(l_phaseInfo));
683 f_myPlots.draw(
canvas,
isBarrel,
"HISTsames", f_phaseInfo.isPhase1Comparison(l_phaseInfo));
686 l_myPlots.rescaleMax(f_myPlots);
690 std::unique_ptr<TLegend>
legend;
692 legend = std::make_unique<TLegend>(0.36, 0.86, 0.94, 0.92);
693 legend->AddEntry(l_myPlots.getHistoFromMap(colorTag).get(), (
"#color[2]{" + l_tagname +
"}").c_str(),
"F");
694 legend->AddEntry(f_myPlots.getHistoFromMap(colorTag).get(), (
"#color[4]{" + f_tagname +
"}").c_str(),
"F");
695 legend->SetTextSize(0.024);
697 legend = std::make_unique<TLegend>(0.58, 0.80, 0.90, 0.92);
698 legend->AddEntry(l_myPlots.getHistoFromMap(colorTag).get(), (
"#color[2]{" + lastIOVsince +
"}").c_str(),
"F");
699 legend->AddEntry(f_myPlots.getHistoFromMap(colorTag).get(), (
"#color[4]{" + firstIOVsince +
"}").c_str(),
"F");
700 legend->SetTextSize(0.040);
704 unsigned int maxPads =
isBarrel ? 4 : 12;
705 for (
unsigned int c = 1;
c <= maxPads;
c++) {
717 ltx.SetTextSize(0.05);
718 ltx.SetTextAlign(11);
720 for (
unsigned int c = 1;
c <= maxPads;
c++) {
723 auto leftX = setLog ? 0. : 0.1;
724 ltx.DrawLatexNDC(gPad->GetLeftMargin() + leftX,
725 1 - gPad->GetTopMargin() + 0.01,
727 "} vs #color[2]{" + std::to_string(std::get<0>(lastiov)) +
"}")
746 template <
class PayloadType>
752 "SiPixelGainCalibration gain/pedestal correlations") {
753 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
755 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
758 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
762 bool fill()
override {
763 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
764 auto iov =
tag.iovs.front();
766 gStyle->SetOptStat(
"emr");
767 gStyle->SetPalette(1);
771 TCanvas
canvas(
"Canv",
"Canv", 1400, 800);
775 auto hBPix = std::make_shared<TH2F>(
"Correlation BPIX",
776 Form(
"SiPixel Gain Calibration %s BPIx;per %s gains;per %s pedestals",
787 auto hFPix = std::make_shared<TH2F>(
"Correlation FPIX",
788 Form(
"SiPixel Gain Calibration %s FPix;per %s gains;per %s pedestals",
799 for (
unsigned int i : {1, 2}) {
812 hBPix->GetYaxis()->SetTitleOffset(1.65);
819 hFPix->GetYaxis()->SetTitleOffset(1.65);
822 TLegend
legend = TLegend(0.3, 0.92, 0.70, 0.95);
823 legend.SetHeader((
"Payload hash: #bf{" + (std::get<1>(iov)) +
"}").c_str(),
826 legend.SetTextSize(0.025);
835 ltx.SetTextSize(0.045);
836 ltx.SetTextAlign(11);
838 ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
839 1 - gPad->GetTopMargin() + 0.01,
840 (
"SiPixel Gain Calibration IOV:" + std::to_string(std::get<0>(iov))).c_str());
842 ltx.DrawLatexNDC(0.75, 0.15,
"BPIX");
845 ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
846 1 - gPad->GetTopMargin() + 0.01,
847 (
"SiPixel Gain Calibration IOV:" + std::to_string(std::get<0>(iov))).c_str());
849 ltx.DrawLatexNDC(0.75, 0.15,
"FPIX");
854 canvas.SaveAs(
"out.root");
867 template <gainCalibPI::type myType,
class PayloadType>
873 Form(
"SiPixelGainCalibrationOffline %s Values By Partition",
TypeName[myType])) {
874 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
876 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
879 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
883 bool fill()
override {
884 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
885 auto iov =
tag.iovs.front();
887 gStyle->SetOptStat(
"emr");
891 TCanvas
canvas(
"Canv",
"Canv", 1400, 800);
895 float minimum(9999.);
896 float maximum(-9999.);
900 maximum =
payload->getGainHigh();
901 minimum =
payload->getGainLow();
904 maximum =
payload->getPedHigh();
905 minimum =
payload->getPedLow();
912 auto hBPix = std::make_shared<TH1F>(Form(
"%s BPIX",
TypeName[myType]),
913 Form(
"SiPixel Gain Calibration %s BPIx -%s;per %s %s (BPix);# %ss",
923 auto hFPix = std::make_shared<TH1F>(Form(
"%s FPIX",
TypeName[myType]),
924 Form(
"SiPixel Gain Calibration %s FPix -%s;per %s %s (FPix);# %ss",
934 for (
unsigned int i : {1, 2}) {
944 hBPix->GetYaxis()->SetRangeUser(0.1, hBPix->GetMaximum() * 10);
945 hBPix->SetFillColor(kBlue);
946 hBPix->SetMarkerStyle(20);
947 hBPix->SetMarkerSize(1);
951 hBPix->SetStats(
true);
955 hFPix->GetYaxis()->SetRangeUser(0.1, hFPix->GetMaximum() * 10);
956 hFPix->SetFillColor(kBlue);
957 hFPix->SetMarkerStyle(20);
958 hFPix->SetMarkerSize(1);
962 hFPix->SetStats(
true);
966 TLegend
legend = TLegend(0.32, 0.92, 0.97, 0.95);
967 legend.SetHeader((
"Payload hash: #bf{" + (std::get<1>(iov)) +
"}").c_str(),
971 legend.SetTextSize(0.025);
978 TPaveStats* st1 = (TPaveStats*)hBPix->FindObject(
"stats");
979 st1->SetTextSize(0.03);
983 TPaveStats* st2 = (TPaveStats*)hFPix->FindObject(
"stats");
984 st2->SetTextSize(0.03);
990 ltx.SetTextSize(0.045);
991 ltx.SetTextAlign(11);
993 ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
994 1 - gPad->GetTopMargin() + 0.01,
995 (
"SiPixel Gain Calibration IOV:" + std::to_string(std::get<0>(iov))).c_str());
998 ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
999 1 - gPad->GetTopMargin() + 0.01,
1000 (
"SiPixel Gain Calibration IOV:" + std::to_string(std::get<0>(iov))).c_str());
1016 template <gainCalibPI::type myType,
class PayloadType>
1021 Form(
"SiPixelGainCalibration %s Values Comparison",
TypeName[myType])) {
1022 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
1028 bool fill(
const std::vector<std::tuple<cond::Time_t, cond::Hash>>& iovs)
override {
1029 gStyle->SetOptStat(
"emr");
1030 TGaxis::SetExponentOffset(-0.1, 0.01,
"y");
1031 TH1F::SetDefaultSumw2(
true);
1033 std::vector<std::tuple<cond::Time_t, cond::Hash>> sorted_iovs = iovs;
1035 std::sort(begin(sorted_iovs),
end(sorted_iovs), [](
auto const&
t1,
auto const&
t2) {
1036 return std::get<0>(
t1) < std::get<0>(
t2);
1038 auto firstiov = sorted_iovs.front();
1039 auto lastiov = sorted_iovs.back();
1041 std::shared_ptr<PayloadType> last_payload = this->
fetchPayload(std::get<1>(lastiov));
1042 std::shared_ptr<PayloadType> first_payload = this->
fetchPayload(std::get<1>(firstiov));
1044 std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
1045 std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
1047 float minimum(9999.);
1048 float maximum(-9999.);
1052 maximum =
std::max(last_payload->getGainHigh(), first_payload->getGainHigh());
1053 minimum =
std::min(last_payload->getGainLow(), first_payload->getGainLow());
1056 maximum =
std::max(last_payload->getPedHigh(), first_payload->getPedHigh());
1057 minimum =
std::min(last_payload->getPedLow(), first_payload->getPedLow());
1064 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
1066 auto hfirst = std::make_shared<TH1F>(Form(
"First, IOV %s", firstIOVsince.c_str()),
1067 Form(
"SiPixel Gain Calibration %s - %s;per %s %s;# %ss",
1077 auto hlast = std::make_shared<TH1F>(Form(
"Last, IOV %s", lastIOVsince.c_str()),
1078 Form(
"SiPixel Gain Calibration %s - %s;per %s %s;# %ss",
1097 hfirst->GetYaxis()->SetRangeUser(1., extrema.second * 10);
1099 hfirst->SetTitle(
"");
1100 hfirst->SetLineColor(kRed);
1101 hfirst->SetBarWidth(0.95);
1102 hfirst->Draw(
"hist");
1104 hlast->SetTitle(
"");
1105 hlast->SetFillColorAlpha(kBlue, 0.20);
1106 hlast->SetBarWidth(0.95);
1107 hlast->Draw(
"histsames");
1110 hfirst->SetStats(
true);
1112 hlast->SetStats(
true);
1116 TLegend
legend = TLegend(0.45, 0.86, 0.74, 0.94);
1120 legend.AddEntry(hfirst.get(), (
"payload: #color[2]{" + std::get<1>(firstiov) +
"}").c_str(),
"F");
1121 legend.AddEntry(hlast.get(), (
"payload: #color[4]{" + std::get<1>(lastiov) +
"}").c_str(),
"F");
1122 legend.SetTextSize(0.022);
1126 TPaveStats* st1 = (TPaveStats*)hfirst->FindObject(
"stats");
1127 st1->SetTextSize(0.021);
1128 st1->SetLineColor(kRed);
1129 st1->SetTextColor(kRed);
1132 TPaveStats* st2 = (TPaveStats*)hlast->FindObject(
"stats");
1133 st2->SetTextSize(0.021);
1134 st2->SetLineColor(kBlue);
1135 st2->SetTextColor(kBlue);
1138 auto ltx = TLatex();
1139 ltx.SetTextFont(62);
1141 ltx.SetTextSize(0.047);
1142 ltx.SetTextAlign(11);
1143 ltx.DrawLatexNDC(gPad->GetLeftMargin(),
1144 1 - gPad->GetTopMargin() + 0.01,
1145 (
"SiPixel Gain Calibration IOV:#color[2]{" + std::to_string(std::get<0>(firstiov)) +
1146 "} vs IOV:#color[4]{" + std::to_string(std::get<0>(lastiov)) +
"}")
1152 canvas.SaveAs(
"out.root");
1163 template <gainCalibPI::type myType,
class PayloadType>
1173 template <gainCalibPI::type myType,
class PayloadType>
1185 template <gainCalibPI::type myType, cond::payloadInspector::IOVMultiplicity nIOVs,
int ntags,
class PayloadType>
1190 Form(
"SiPixelGainCalibration %s Diff and Ratio %i tag(s)",
TypeName[myType],
ntags)) {
1191 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
1198 bool fill()
override {
1199 gStyle->SetOptStat(
"emr");
1200 TGaxis::SetExponentOffset(-0.1, 0.01,
"y");
1201 TH1F::SetDefaultSumw2(
true);
1206 auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
1207 auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().name;
1209 auto firstiov = theIOVs.front();
1210 std::tuple<cond::Time_t, cond::Hash> lastiov;
1216 auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
1217 l_tagname = cond::payloadInspector::PlotBase::getTag<1>().name;
1218 lastiov = tag2iovs.front();
1220 lastiov = theIOVs.back();
1223 std::shared_ptr<PayloadType> last_payload = this->
fetchPayload(std::get<1>(lastiov));
1224 std::shared_ptr<PayloadType> first_payload = this->
fetchPayload(std::get<1>(firstiov));
1226 std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
1227 std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
1229 TCanvas
canvas(
"Canv",
"Canv", 1300, 800);
1239 array[0]->SetTitle(Form(
"SiPixel Gain Calibration %s - %s;per %s %s ratio;# %ss",
1246 array[1]->SetTitle(Form(
"SiPixel Gain Calibration %s - %s;per %s %s difference;# %ss",
1254 array[0]->SetTitle(
"");
1255 array[0]->SetLineColor(kBlack);
1256 array[0]->SetFillColor(kRed);
1257 array[0]->SetBarWidth(0.90);
1258 array[0]->SetMaximum(
array[0]->GetMaximum() * 10);
1259 array[0]->Draw(
"bar");
1261 array[0]->SetStats(
true);
1264 array[1]->SetTitle(
"");
1265 array[1]->SetLineColor(kBlack);
1266 array[1]->SetFillColor(kBlue);
1267 array[1]->SetBarWidth(0.90);
1268 array[1]->SetMaximum(
array[1]->GetMaximum() * 10);
1269 array[1]->Draw(
"bar");
1271 array[1]->SetStats(
true);
1277 latex.SetTextSize(0.024);
1278 latex.SetTextAlign(13);
1282 fmt::sprintf(
"#scale[1.2]{SiPixelGainCalibration%s Ratio}", (
isForHLT_ ?
"ForHLT" :
"Offline")).c_str());
1285 .41, .91, (
"#splitline{#font[12]{" + f_tagname +
"}}{ / #font[12]{" + l_tagname +
"}}").c_str());
1287 latex.DrawLatexNDC(.41, .91, (firstIOVsince +
" / " + lastIOVsince).c_str());
1292 latex2.SetTextSize(0.024);
1293 latex2.SetTextAlign(13);
1294 latex2.DrawLatexNDC(
1297 fmt::sprintf(
"#scale[1.2]{SiPixelGainCalibration%s Diff}", (
isForHLT_ ?
"ForHLT" :
"Offline")).c_str());
1299 latex2.DrawLatexNDC(
1300 .41, .91, (
"#splitline{#font[12]{" + f_tagname +
"}}{ - #font[12]{" + l_tagname +
"}}").c_str());
1302 latex2.DrawLatexNDC(.41, .91, (firstIOVsince +
" - " + lastIOVsince).c_str());
1305 TPaveStats* st1 = (TPaveStats*)
array[0]->FindObject(
"stats");
1306 st1->SetTextSize(0.027);
1307 st1->SetLineColor(kRed);
1308 st1->SetTextColor(kRed);
1311 TPaveStats* st2 = (TPaveStats*)
array[1]->FindObject(
"stats");
1312 st2->SetTextSize(0.027);
1313 st2->SetLineColor(kBlue);
1314 st2->SetTextColor(kBlue);
1317 auto ltx = TLatex();
1318 ltx.SetTextFont(62);
1320 ltx.SetTextSize(0.040);
1321 ltx.SetTextAlign(11);
1324 gPad->GetLeftMargin(),
1325 1 - gPad->GetTopMargin() + 0.01,
1326 fmt::sprintf(
"SiPixel %s Ratio, IOV %s / %s",
TypeName[myType], firstIOVsince, lastIOVsince).c_str());
1330 gPad->GetLeftMargin(),
1331 1 - gPad->GetTopMargin() + 0.01,
1332 fmt::sprintf(
"SiPixel %s Diff, IOV %s - %s",
TypeName[myType], firstIOVsince, lastIOVsince).c_str());
1337 canvas.SaveAs(
"out.root");
1353 template <gainCalibPI::type myType,
class PayloadType>
1359 Form(
"SiPixelGainCalibration %s Barrel Pixel Map",
TypeName[myType])),
1362 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
1364 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
1367 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
1371 bool fill()
override {
1372 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
1373 auto iov =
tag.iovs.front();
1377 static const int n_layers = 4;
1378 int nlad_list[n_layers] = {6, 14, 22, 32};
1382 std::array<TH2D*, n_layers> h_bpix_Gains;
1384 for (
unsigned int lay = 1; lay <= 4; lay++) {
1385 int nlad = nlad_list[lay - 1];
1389 h_bpix_Gains[lay - 1] =
new TH2D(
name.c_str(),
1394 (nlad * 4 + 2) * divide_roc,
1399 std::map<uint32_t, float> GainCalibMap_;
1402 edm::LogError(
label_) <<
"SiPixelGainCalibration maps are not supported for non-Phase1 Pixel geometries !";
1403 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
1411 std::array<double, 4> minima = {{999., 999., 999., 999.}};
1413 for (
const auto& element : GainCalibMap_) {
1422 COUT <<
"layer:" << layer <<
" ladder:" <<
ladder <<
" module:" << module <<
" signed ladder: " << s_ladder
1423 <<
" signed module: " << s_module << std::endl;
1425 if (element.second < minima.at(layer - 1))
1426 minima.at(layer - 1) = element.second;
1429 for (
const auto&
bin : rocsToMask) {
1430 h_bpix_Gains[layer - 1]->SetBinContent(
bin.first,
bin.second, element.second);
1435 gStyle->SetOptStat(0);
1437 TCanvas
canvas(
"Summary",
"Summary", 1200, 1200);
1440 for (
unsigned int lay = 1; lay <= 4; lay++) {
1443 COUT <<
" layer:" << lay <<
" max:" << h_bpix_Gains[lay - 1]->GetMaximum() <<
" min: " << minima.at(lay - 1)
1447 h_bpix_Gains[lay - 1]->GetZaxis()->SetRangeUser(minima.at(lay - 1) - 0.001,
1448 h_bpix_Gains[lay - 1]->GetMaximum() + 0.001);
1453 for (
unsigned int lay = 1; lay <= 4; lay++) {
1455 auto ltx = TLatex();
1456 ltx.SetTextFont(62);
1457 ltx.SetTextColor(kBlue);
1458 ltx.SetTextSize(0.055);
1459 ltx.SetTextAlign(11);
1460 ltx.DrawLatexNDC(gPad->GetLeftMargin(),
1461 1 - gPad->GetTopMargin() + 0.01,
1463 ? (
"IOV:" + std::to_string(unpacked.second)).c_str()
1464 : (std::to_string(unpacked.first) +
"," + std::to_string(unpacked.second)).c_str());
1485 template <gainCalibPI::type myType,
class PayloadType>
1491 Form(
"SiPixelGainCalibration %s Forward Pixel Map",
TypeName[myType])),
1494 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
1496 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
1499 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
1503 bool fill()
override {
1504 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
1505 auto iov =
tag.iovs.front();
1508 static const int n_rings = 2;
1509 std::array<TH2D*, n_rings> h_fpix_Gains;
1514 int n =
ring == 1 ? 92 : 140;
1515 float y =
ring == 1 ? 11.5 : 17.5;
1519 h_fpix_Gains[
ring - 1] =
1520 new TH2D(
name.c_str(),
title.c_str(), 56 * divide_roc, -3.5, 3.5,
n * divide_roc, -
y,
y);
1523 std::map<uint32_t, float> GainCalibMap_;
1526 edm::LogError(
label_) <<
"SiPixelGainCalibration maps are not supported for non-Phase1 Pixel geometries !";
1527 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
1535 std::array<double, 2> minima = {{999., 999.}};
1537 for (
const auto& element : GainCalibMap_) {
1546 COUT <<
"ring:" <<
ring <<
" blade: " << s_blade <<
" panel: " << panel
1547 <<
" signed blade/panel: " << s_blade_panel <<
" disk: " << s_disk << std::endl;
1549 if (element.second < minima.at(
ring - 1))
1550 minima.at(
ring - 1) = element.second;
1553 for (
const auto&
bin : rocsToMask) {
1554 h_fpix_Gains[
ring - 1]->SetBinContent(
bin.first,
bin.second, element.second);
1559 gStyle->SetOptStat(0);
1561 TCanvas
canvas(
"Summary",
"Summary", 1200, 600);
1567 COUT <<
" ringer:" <<
ring <<
" max:" << h_fpix_Gains[
ring - 1]->GetMaximum() <<
" min: " << minima.at(
ring - 1)
1571 h_fpix_Gains[
ring - 1]->GetZaxis()->SetRangeUser(minima.at(
ring - 1) - 0.001,
1572 h_fpix_Gains[
ring - 1]->GetMaximum() + 0.001);
1579 auto ltx = TLatex();
1580 ltx.SetTextFont(62);
1581 ltx.SetTextColor(kBlue);
1582 ltx.SetTextSize(0.05);
1583 ltx.SetTextAlign(11);
1584 ltx.DrawLatexNDC(gPad->GetLeftMargin(),
1585 1 - gPad->GetTopMargin() + 0.01,
1587 ? (
"IOV:" + std::to_string(unpacked.second)).c_str()
1588 : (std::to_string(unpacked.first) +
"," + std::to_string(unpacked.second)).c_str());
1607 template <gainCalibPI::type myType,
class PayloadType, cond::payloadInspector::IOVMultiplicity nIOVs,
int ntags>
1613 Form(
"SiPixelGainCalibration %s Comparison by Region",
TypeName[myType])) {
1614 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
1616 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
1619 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
1623 bool fill()
override {
1624 gStyle->SetPaintTextFormat(
".3f");
1627 auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
1628 auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().name;
1630 auto firstiov = theIOVs.front();
1631 std::tuple<cond::Time_t, cond::Hash> lastiov;
1637 auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
1638 l_tagname = cond::payloadInspector::PlotBase::getTag<1>().name;
1639 lastiov = tag2iovs.front();
1641 lastiov = theIOVs.back();
1644 std::shared_ptr<PayloadType> last_payload = this->
fetchPayload(std::get<1>(lastiov));
1645 std::shared_ptr<PayloadType> first_payload = this->
fetchPayload(std::get<1>(firstiov));
1647 std::map<uint32_t, float> f_GainsMap_;
1650 std::map<uint32_t, float> l_GainsMap_;
1653 std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
1654 std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
1656 TCanvas
canvas(
"Comparison",
"Comparison", 1600, 800);
1661 std::map<SiPixelPI::regions, std::shared_ptr<TH1F>> FirstGains_spectraByRegion;
1662 std::map<SiPixelPI::regions, std::shared_ptr<TH1F>> LastGains_spectraByRegion;
1663 std::shared_ptr<TH1F> summaryFirst;
1664 std::shared_ptr<TH1F> summaryLast;
1666 float minimum(9999.);
1667 float maximum(-9999.);
1671 maximum =
std::max(last_payload->getGainHigh(), first_payload->getGainHigh());
1672 minimum =
std::min(last_payload->getGainLow(), first_payload->getGainLow());
1675 maximum =
std::max(last_payload->getPedHigh(), first_payload->getPedHigh());
1676 minimum =
std::min(last_payload->getPedLow(), first_payload->getPedLow());
1688 FirstGains_spectraByRegion[
part] =
1689 std::make_shared<TH1F>(Form(
"hfirstGains_%s", s_part.c_str()),
1690 Form(
";%s #LT %s #GT;n. of modules", s_part.c_str(),
TypeName[myType]),
1695 LastGains_spectraByRegion[
part] =
1696 std::make_shared<TH1F>(Form(
"hlastGains_%s", s_part.c_str()),
1697 Form(
";%s #LT %s #GT;n. of modules", s_part.c_str(),
TypeName[myType]),
1703 summaryFirst = std::make_shared<TH1F>(
"first Summary",
1704 Form(
"Summary of #LT per %s %s #GT;;average %s",
1708 FirstGains_spectraByRegion.size(),
1710 FirstGains_spectraByRegion.size());
1712 summaryLast = std::make_shared<TH1F>(
"last Summary",
1713 Form(
"Summary of #LT per %s %s #GT;;average %s",
1717 LastGains_spectraByRegion.size(),
1719 LastGains_spectraByRegion.size());
1722 const char* path_toTopologyXML = f_phaseInfo.pathToTopoXML();
1730 for (
const auto& it : f_GainsMap_) {
1737 t_info_fromXML.
init();
1738 DetId detid(it.first);
1742 FirstGains_spectraByRegion[thePart]->Fill(it.second);
1746 path_toTopologyXML = l_phaseInfo.pathToTopoXML();
1754 for (
const auto& it : l_GainsMap_) {
1761 t_info_fromXML.
init();
1762 DetId detid(it.first);
1766 LastGains_spectraByRegion[thePart]->Fill(it.second);
1777 FirstGains_spectraByRegion[
part]->GetMean() > 10.e-6 ? FirstGains_spectraByRegion[
part]->GetMean() : 0.;
1778 summaryFirst->SetBinContent(
bin, f_mean);
1784 LastGains_spectraByRegion[
part]->GetMean() > 10.e-6 ? LastGains_spectraByRegion[
part]->GetMean() : 0.;
1785 summaryLast->SetBinContent(
bin, l_mean);
1791 summaryFirst->SetMarkerColor(kRed);
1792 summaryFirst->GetXaxis()->LabelsOption(
"v");
1793 summaryFirst->GetXaxis()->SetLabelSize(0.05);
1794 summaryFirst->GetYaxis()->SetTitleOffset(0.9);
1797 summaryLast->SetMarkerColor(kBlue);
1798 summaryLast->GetYaxis()->SetTitleOffset(0.9);
1799 summaryLast->GetXaxis()->LabelsOption(
"v");
1800 summaryLast->GetXaxis()->SetLabelSize(0.05);
1807 summaryFirst->SetFillColor(kRed);
1808 summaryLast->SetFillColor(kBlue);
1810 summaryFirst->SetBarWidth(0.45);
1811 summaryFirst->SetBarOffset(0.1);
1813 summaryLast->SetBarWidth(0.4);
1814 summaryLast->SetBarOffset(0.55);
1816 summaryLast->SetMarkerSize(1.2);
1817 summaryFirst->SetMarkerSize(1.2);
1819 float max = (summaryFirst->GetMaximum() > summaryLast->GetMaximum()) ? summaryFirst->GetMaximum()
1820 : summaryLast->GetMaximum();
1822 summaryFirst->GetYaxis()->SetRangeUser(0.,
std::max(0.,
max * 1.40));
1824 summaryFirst->Draw(
"b text0");
1825 summaryLast->Draw(
"b text0 same");
1827 TLegend
legend = TLegend(0.52, 0.80, 0.98, 0.9);
1828 legend.SetHeader(Form(
"#LT %s #GT value comparison",
TypeName[myType]),
1831 legend.SetHeader(
"#mu_{H} value comparison",
"C");
1834 l_tagOrHash = l_tagname;
1835 f_tagOrHash = f_tagname;
1837 l_tagOrHash = std::get<1>(lastiov);
1838 f_tagOrHash = std::get<1>(firstiov);
1843 (
"IOV: #scale[1.2]{" + std::to_string(std::get<0>(lastiov)) +
"} | #color[4]{" + l_tagOrHash +
"}").c_str(),
1847 (
"IOV: #scale[1.2]{" + std::to_string(std::get<0>(firstiov)) +
"} | #color[2]{" + f_tagOrHash +
"}").c_str(),