1 #ifndef CONDCORE_SIPIXELPLUGINS_SIPIXELGAINCALIBHELPER_H 2 #define CONDCORE_SIPIXELPLUGINS_SIPIXELGAINCALIBHELPER_H 17 #include <type_traits> 20 #include <fmt/printf.h> 31 #include "TPaveStats.h" 36 using AvgMap = std::map<uint32_t, float>;
38 namespace gainCalibPI {
41 static const std::array<std::string, 3>
t_titles = {{
"gain",
"pedestal",
"correlation"}};
45 template <
typename PayloadType>
46 static std::array<std::shared_ptr<TH1F>, 2>
fillDiffAndRatio(
const std::shared_ptr<PayloadType>& payload_A,
47 const std::shared_ptr<PayloadType>& payload_B,
49 std::array<std::shared_ptr<TH1F>, 2> arr;
51 std::vector<uint32_t> detids_A;
52 payload_A->getDetIds(detids_A);
53 std::vector<uint32_t> detids_B;
54 payload_B->getDetIds(detids_B);
56 std::vector<float> v_ratios;
57 std::vector<float> v_diffs;
59 if (detids_A != detids_B) {
60 edm::LogError(
"fillDiffAndRatio") <<
"the list of DetIds for the two payloads are not equal" 61 <<
" cannot make any comparison!" << std::endl;
64 assert(detids_A == detids_B);
65 for (
const auto&
d : detids_A) {
66 auto range = payload_A->getRange(
d);
67 int numberOfRowsToAverageOver = payload_A->getNumberOfRowsToAverageOver();
68 int ncols = payload_A->getNCols(
d);
69 int nRocsInRow = (
range.second -
range.first) /
ncols / numberOfRowsToAverageOver;
70 unsigned int nRowsForHLT = 1;
71 int nrows =
std::max((payload_A->getNumberOfRowsToAverageOver() * nRocsInRow),
74 auto rAndCol_A = payload_A->getRangeAndNCols(
d);
75 auto rAndCol_B = payload_B->getRangeAndNCols(
d);
76 bool isDeadCol, isNoisyCol;
80 for (
int row = 0; row < nrows; row++) {
83 auto gainA = payload_A->getGain(
col, row, rAndCol_A.first, rAndCol_A.second, isDeadCol, isNoisyCol);
84 auto gainB = payload_B->getGain(
col, row, rAndCol_B.first, rAndCol_B.second, isDeadCol, isNoisyCol);
85 ratio = gainB != 0 ? (gainA / gainB) : -1.;
90 auto pedA = payload_A->getPed(
col, row, rAndCol_A.first, rAndCol_A.second, isDeadCol, isNoisyCol);
91 auto pedB = payload_B->getPed(
col, row, rAndCol_B.first, rAndCol_B.second, isDeadCol, isNoisyCol);
92 ratio = pedB != 0 ? (pedA / pedB) : -1.;
97 edm::LogError(
"gainCalibPI::fillTheHisto") <<
"Unrecognized type " << theType << std::endl;
101 v_diffs.push_back(
diff);
102 v_ratios.push_back(
ratio);
107 std::sort(v_diffs.begin(), v_diffs.end());
108 std::sort(v_ratios.begin(), v_ratios.end());
110 double minDiff = v_diffs.front();
111 double maxDiff = v_diffs.back();
112 double minRatio = v_ratios.front();
113 double maxRatio = v_ratios.back();
115 arr[0] = std::make_shared<TH1F>(
"h_Ratio",
"", 50, minRatio - 1., maxRatio + 1.);
116 arr[1] = std::make_shared<TH1F>(
"h_Diff",
"", 50, minDiff - 1.,
maxDiff + 1.);
118 for (
const auto& r : v_ratios) {
121 for (
const auto&
d : v_diffs) {
129 template <
typename PayloadType>
131 std::shared_ptr<TH1F> h1,
133 const std::vector<uint32_t>& wantedIds = {}) {
134 std::vector<uint32_t> detids;
135 if (wantedIds.empty()) {
138 detids.assign(wantedIds.begin(), wantedIds.end());
141 for (
const auto&
d : detids) {
147 int numberOfRowsToAverageOver =
payload->getNumberOfRowsToAverageOver();
149 int nRocsInRow = (
range.second -
range.first) /
ncols / numberOfRowsToAverageOver;
150 unsigned int nRowsForHLT = 1;
151 int nrows =
std::max((
payload->getNumberOfRowsToAverageOver() * nRocsInRow),
154 auto rangeAndCol =
payload->getRangeAndNCols(
d);
158 COUT <<
"NCOLS: " <<
payload->getNCols(
d) <<
" " << rangeAndCol.second <<
" NROWS:" << nrows
159 <<
", RANGES: " << rangeAndCol.first.second - rangeAndCol.first.first
160 <<
", Ratio: " <<
float(rangeAndCol.first.second - rangeAndCol.first.first) / rangeAndCol.second
166 for (
int row = 0; row < nrows; row++) {
169 quid =
payload->getGain(
col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
172 quid =
payload->getPed(
col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
175 edm::LogError(
"gainCalibPI::fillTheHisto") <<
"Unrecognized type " << theType << std::endl;
186 template <
typename PayloadType>
190 std::vector<uint32_t> detids;
193 for (
const auto&
d : detids) {
195 int numberOfRowsToAverageOver =
payload->getNumberOfRowsToAverageOver();
197 int nRocsInRow = (
range.second -
range.first) /
ncols / numberOfRowsToAverageOver;
198 unsigned int nRowsForHLT = 1;
199 int nrows =
std::max((
payload->getNumberOfRowsToAverageOver() * nRocsInRow),
202 auto rangeAndCol =
payload->getRangeAndNCols(
d);
209 for (
int row = 0; row < nrows; row++) {
214 payload->getGain(
col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
217 sumOfX +=
payload->getPed(
col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
220 edm::LogError(
"gainCalibPI::fillThePerModuleMap") <<
"Unrecognized type " << theType << std::endl;
226 map[
d] = sumOfX / nPixels;
232 template <
typename PayloadType>
234 std::shared_ptr<TH1> hBPix,
235 std::shared_ptr<TH1> hFPix,
237 std::vector<uint32_t> detids;
242 for (
const auto&
d : detids) {
245 int numberOfRowsToAverageOver =
payload->getNumberOfRowsToAverageOver();
247 int nRocsInRow = (
range.second -
range.first) /
ncols / numberOfRowsToAverageOver;
248 unsigned int nRowsForHLT = 1;
249 int nrows =
std::max((
payload->getNumberOfRowsToAverageOver() * nRocsInRow),
252 auto rangeAndCol =
payload->getRangeAndNCols(
d);
257 for (
int row = 0; row < nrows; row++) {
258 float gain =
payload->getGain(
col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
259 float ped =
payload->getPed(
col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
263 if (isCorrelation_) {
271 if (isCorrelation_) {
279 edm::LogError(
"gainCalibPI::fillTheHistos") <<
d <<
" is not a Pixel DetId" << std::endl;
293 template <gainCalibPI::type myType,
class PayloadType>
299 Form(
"SiPixelGainCalibration %s Values",
TypeName[myType])) {
300 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
302 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
305 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
310 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
311 auto iov =
tag.iovs.front();
315 gStyle->SetOptStat(
"emr");
317 float minimum(9999.);
318 float maximum(-9999.);
322 maximum =
payload->getGainHigh();
323 minimum =
payload->getGainLow();
326 maximum =
payload->getPedHigh();
327 minimum =
payload->getPedLow();
334 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
335 auto h1 = std::make_shared<TH1F>(Form(
"%s values",
TypeName[myType]),
336 Form(
"SiPixel Gain Calibration %s - %s;per %s %s;# %ss",
354 h1->GetYaxis()->SetRangeUser(0.1, h1->GetMaximum() * 10.);
355 h1->SetFillColor(kBlue);
356 h1->SetMarkerStyle(20);
357 h1->SetMarkerSize(1);
365 TLegend
legend = TLegend(0.40, 0.88, 0.94, 0.93);
366 legend.SetHeader((
"Payload hash: #bf{" + (std::get<1>(iov)) +
"}").c_str(),
370 legend.SetTextSize(0.025);
373 TPaveStats* st = (TPaveStats*)h1->FindObject(
"stats");
374 st->SetTextSize(0.03);
380 ltx.SetTextSize(0.05);
381 ltx.SetTextAlign(11);
382 ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.1,
383 1 - gPad->GetTopMargin() + 0.01,
384 (
"SiPixel Gain Calibration IOV:" +
std::to_string(std::get<0>(iov))).c_str());
400 template <
bool isBarrel, gainCalibPI::type myType,
class PayloadType>
406 Form(
"SiPixelGainCalibration %s Values Per Region",
TypeName[myType])) {
409 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
411 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
414 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
419 gStyle->SetOptStat(
"mr");
421 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
422 auto iov =
tag.iovs.front();
427 auto ip = paramValues.find(
"SetLog");
428 if (ip != paramValues.end()) {
429 auto answer = ip->second;
432 <<
"\nERROR: " << answer
433 <<
" is not a valid setting for this parameter, please use True,False,1,0,Yes,No \n\n";
439 std::vector<uint32_t> detids;
442 float minimum(9999.);
443 float maximum(-9999.);
447 maximum =
payload->getGainHigh();
448 minimum =
payload->getGainLow();
451 maximum =
payload->getPedHigh();
452 minimum =
payload->getPedLow();
478 Form(
"# %ss", (
isForHLT_ ?
"column" :
"pixel")),
492 myPlots.setLogScale();
494 myPlots.beautify(kBlue, -1);
497 TLegend
legend = TLegend(0.45, 0.88, 0.91, 0.92);
498 legend.SetHeader((
"hash: #bf{" + (std::get<1>(iov)) +
"}").c_str(),
502 legend.SetTextSize(0.025);
505 unsigned int maxPads =
isBarrel ? 4 : 12;
506 for (
unsigned int c = 1;
c <= maxPads;
c++) {
517 ltx.SetTextSize(0.05);
518 ltx.SetTextAlign(11);
520 for (
unsigned int c = 1;
c <= maxPads;
c++) {
523 auto leftX = setLog ? 0. : 0.1;
524 ltx.DrawLatexNDC(gPad->GetLeftMargin() + leftX,
525 1 - gPad->GetTopMargin() + 0.01,
553 Form(
"SiPixelGainCalibration %s Values Per Region %i tag(s)",
TypeName[myType],
ntags)) {
556 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
558 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
561 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
566 gStyle->SetOptStat(
"mr");
571 auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
572 auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().
name;
574 auto firstiov = theIOVs.front();
575 std::tuple<cond::Time_t, cond::Hash> lastiov;
581 auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
582 l_tagname = cond::payloadInspector::PlotBase::getTag<1>().
name;
583 lastiov = tag2iovs.front();
585 lastiov = theIOVs.back();
591 auto ip = paramValues.find(
"SetLog");
592 if (ip != paramValues.end()) {
593 auto answer = ip->second;
596 <<
"\nERROR: " << answer
597 <<
" is not a valid setting for this parameter, please use True,False,1,0,Yes,No \n\n";
601 std::shared_ptr<PayloadType> last_payload = this->
fetchPayload(std::get<1>(lastiov));
602 std::shared_ptr<PayloadType> first_payload = this->
fetchPayload(std::get<1>(firstiov));
607 std::vector<uint32_t> f_detids, l_detids;
608 last_payload->getDetIds(l_detids);
609 first_payload->getDetIds(f_detids);
611 float minimum(9999.);
612 float maximum(-9999.);
616 maximum =
std::max(last_payload->getGainHigh(), first_payload->getGainHigh());
617 minimum =
std::min(last_payload->getGainLow(), first_payload->getGainLow());
620 maximum =
std::max(last_payload->getPedHigh(), first_payload->getPedHigh());
621 minimum =
std::min(last_payload->getPedLow(), first_payload->getPedLow());
640 const char* path_toTopologyXML = l_phaseInfo.
pathToTopoXML();
647 Form(
"Last SiPixel Gain Calibration %s - %s", (
isForHLT_ ?
"ForHLT" :
"Offline"),
TypeName[myType]),
649 Form(
"# %ss", (
isForHLT_ ?
"column" :
"pixel")),
654 path_toTopologyXML = f_phaseInfo.pathToTopoXML();
661 Form(
"First SiPixel Gain Calibration %s - %s", (
isForHLT_ ?
"ForHLT" :
"Offline"),
TypeName[myType]),
663 Form(
"# %ss", (
isForHLT_ ?
"column" :
"pixel")),
677 f_myPlots.setLogScale();
678 l_myPlots.setLogScale();
681 l_myPlots.beautify(kRed, -1);
682 f_myPlots.beautify(kAzure, -1);
684 l_myPlots.draw(
canvas,
isBarrel,
"HIST", f_phaseInfo.isPhase1Comparison(l_phaseInfo));
685 f_myPlots.draw(
canvas,
isBarrel,
"HISTsames", f_phaseInfo.isPhase1Comparison(l_phaseInfo));
688 l_myPlots.rescaleMax(f_myPlots);
692 std::unique_ptr<TLegend>
legend;
694 legend = std::make_unique<TLegend>(0.36, 0.86, 0.94, 0.92);
695 legend->AddEntry(l_myPlots.getHistoFromMap(colorTag).get(), (
"#color[2]{" + l_tagname +
"}").c_str(),
"F");
696 legend->AddEntry(f_myPlots.getHistoFromMap(colorTag).get(), (
"#color[4]{" + f_tagname +
"}").c_str(),
"F");
697 legend->SetTextSize(0.024);
699 legend = std::make_unique<TLegend>(0.58, 0.80, 0.90, 0.92);
700 legend->AddEntry(l_myPlots.getHistoFromMap(colorTag).get(), (
"#color[2]{" + lastIOVsince +
"}").c_str(),
"F");
701 legend->AddEntry(f_myPlots.getHistoFromMap(colorTag).get(), (
"#color[4]{" + firstIOVsince +
"}").c_str(),
"F");
702 legend->SetTextSize(0.040);
706 unsigned int maxPads =
isBarrel ? 4 : 12;
707 for (
unsigned int c = 1;
c <= maxPads;
c++) {
719 ltx.SetTextSize(0.05);
720 ltx.SetTextAlign(11);
722 for (
unsigned int c = 1;
c <= maxPads;
c++) {
725 auto leftX = setLog ? 0. : 0.1;
726 ltx.DrawLatexNDC(gPad->GetLeftMargin() + leftX,
727 1 - gPad->GetTopMargin() + 0.01,
748 template <
class PayloadType>
754 "SiPixelGainCalibration gain/pedestal correlations") {
755 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
757 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
760 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
765 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
766 auto iov =
tag.iovs.front();
768 gStyle->SetOptStat(
"emr");
769 gStyle->SetPalette(1);
773 TCanvas
canvas(
"Canv",
"Canv", 1400, 800);
777 auto hBPix = std::make_shared<TH2F>(
"Correlation BPIX",
778 Form(
"SiPixel Gain Calibration %s BPIx;per %s gains;per %s pedestals",
789 auto hFPix = std::make_shared<TH2F>(
"Correlation FPIX",
790 Form(
"SiPixel Gain Calibration %s FPix;per %s gains;per %s pedestals",
801 for (
unsigned int i : {1, 2}) {
814 hBPix->GetYaxis()->SetTitleOffset(1.65);
821 hFPix->GetYaxis()->SetTitleOffset(1.65);
824 TLegend
legend = TLegend(0.3, 0.92, 0.70, 0.95);
825 legend.SetHeader((
"Payload hash: #bf{" + (std::get<1>(iov)) +
"}").c_str(),
828 legend.SetTextSize(0.025);
837 ltx.SetTextSize(0.045);
838 ltx.SetTextAlign(11);
840 ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
841 1 - gPad->GetTopMargin() + 0.01,
842 (
"SiPixel Gain Calibration IOV:" +
std::to_string(std::get<0>(iov))).c_str());
844 ltx.DrawLatexNDC(0.75, 0.15,
"BPIX");
847 ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
848 1 - gPad->GetTopMargin() + 0.01,
849 (
"SiPixel Gain Calibration IOV:" +
std::to_string(std::get<0>(iov))).c_str());
851 ltx.DrawLatexNDC(0.75, 0.15,
"FPIX");
856 canvas.SaveAs(
"out.root");
869 template <gainCalibPI::type myType,
class PayloadType>
875 Form(
"SiPixelGainCalibrationOffline %s Values By Partition",
TypeName[myType])) {
876 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
878 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
881 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
886 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
887 auto iov =
tag.iovs.front();
889 gStyle->SetOptStat(
"emr");
893 TCanvas
canvas(
"Canv",
"Canv", 1400, 800);
897 float minimum(9999.);
898 float maximum(-9999.);
902 maximum =
payload->getGainHigh();
903 minimum =
payload->getGainLow();
906 maximum =
payload->getPedHigh();
907 minimum =
payload->getPedLow();
914 auto hBPix = std::make_shared<TH1F>(Form(
"%s BPIX",
TypeName[myType]),
915 Form(
"SiPixel Gain Calibration %s BPIx -%s;per %s %s (BPix);# %ss",
925 auto hFPix = std::make_shared<TH1F>(Form(
"%s FPIX",
TypeName[myType]),
926 Form(
"SiPixel Gain Calibration %s FPix -%s;per %s %s (FPix);# %ss",
936 for (
unsigned int i : {1, 2}) {
946 hBPix->GetYaxis()->SetRangeUser(0.1, hBPix->GetMaximum() * 10);
947 hBPix->SetFillColor(kBlue);
948 hBPix->SetMarkerStyle(20);
949 hBPix->SetMarkerSize(1);
953 hBPix->SetStats(
true);
957 hFPix->GetYaxis()->SetRangeUser(0.1, hFPix->GetMaximum() * 10);
958 hFPix->SetFillColor(kBlue);
959 hFPix->SetMarkerStyle(20);
960 hFPix->SetMarkerSize(1);
964 hFPix->SetStats(
true);
968 TLegend
legend = TLegend(0.32, 0.92, 0.97, 0.95);
969 legend.SetHeader((
"Payload hash: #bf{" + (std::get<1>(iov)) +
"}").c_str(),
973 legend.SetTextSize(0.025);
980 TPaveStats* st1 = (TPaveStats*)hBPix->FindObject(
"stats");
981 st1->SetTextSize(0.03);
985 TPaveStats* st2 = (TPaveStats*)hFPix->FindObject(
"stats");
986 st2->SetTextSize(0.03);
992 ltx.SetTextSize(0.045);
993 ltx.SetTextAlign(11);
995 ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
996 1 - gPad->GetTopMargin() + 0.01,
997 (
"SiPixel Gain Calibration IOV:" +
std::to_string(std::get<0>(iov))).c_str());
1000 ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
1001 1 - gPad->GetTopMargin() + 0.01,
1002 (
"SiPixel Gain Calibration IOV:" +
std::to_string(std::get<0>(iov))).c_str());
1018 template <gainCalibPI::type myType,
class PayloadType>
1023 Form(
"SiPixelGainCalibration %s Values Comparison",
TypeName[myType])) {
1024 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
1031 gStyle->SetOptStat(
"emr");
1032 TGaxis::SetExponentOffset(-0.1, 0.01,
"y");
1033 TH1F::SetDefaultSumw2(
true);
1035 std::vector<std::tuple<cond::Time_t, cond::Hash>> sorted_iovs = iovs;
1037 std::sort(begin(sorted_iovs), end(sorted_iovs), [](
auto const&
t1,
auto const&
t2) {
1038 return std::get<0>(
t1) < std::get<0>(
t2);
1040 auto firstiov = sorted_iovs.front();
1041 auto lastiov = sorted_iovs.back();
1043 std::shared_ptr<PayloadType> last_payload = this->
fetchPayload(std::get<1>(lastiov));
1044 std::shared_ptr<PayloadType> first_payload = this->
fetchPayload(std::get<1>(firstiov));
1049 float minimum(9999.);
1050 float maximum(-9999.);
1054 maximum =
std::max(last_payload->getGainHigh(), first_payload->getGainHigh());
1055 minimum =
std::min(last_payload->getGainLow(), first_payload->getGainLow());
1058 maximum =
std::max(last_payload->getPedHigh(), first_payload->getPedHigh());
1059 minimum =
std::min(last_payload->getPedLow(), first_payload->getPedLow());
1066 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
1068 auto hfirst = std::make_shared<TH1F>(Form(
"First, IOV %s", firstIOVsince.c_str()),
1069 Form(
"SiPixel Gain Calibration %s - %s;per %s %s;# %ss",
1079 auto hlast = std::make_shared<TH1F>(Form(
"Last, IOV %s", lastIOVsince.c_str()),
1080 Form(
"SiPixel Gain Calibration %s - %s;per %s %s;# %ss",
1099 hfirst->GetYaxis()->SetRangeUser(1., extrema.second * 10);
1101 hfirst->SetTitle(
"");
1102 hfirst->SetLineColor(kRed);
1103 hfirst->SetBarWidth(0.95);
1104 hfirst->Draw(
"hist");
1106 hlast->SetTitle(
"");
1107 hlast->SetFillColorAlpha(kBlue, 0.20);
1108 hlast->SetBarWidth(0.95);
1109 hlast->Draw(
"histsames");
1112 hfirst->SetStats(
true);
1114 hlast->SetStats(
true);
1118 TLegend
legend = TLegend(0.45, 0.86, 0.74, 0.94);
1122 legend.AddEntry(hfirst.get(), (
"payload: #color[2]{" + std::get<1>(firstiov) +
"}").c_str(),
"F");
1123 legend.AddEntry(hlast.get(), (
"payload: #color[4]{" + std::get<1>(lastiov) +
"}").c_str(),
"F");
1124 legend.SetTextSize(0.022);
1128 TPaveStats* st1 = (TPaveStats*)hfirst->FindObject(
"stats");
1129 st1->SetTextSize(0.021);
1130 st1->SetLineColor(kRed);
1131 st1->SetTextColor(kRed);
1134 TPaveStats* st2 = (TPaveStats*)hlast->FindObject(
"stats");
1135 st2->SetTextSize(0.021);
1136 st2->SetLineColor(kBlue);
1137 st2->SetTextColor(kBlue);
1140 auto ltx = TLatex();
1141 ltx.SetTextFont(62);
1143 ltx.SetTextSize(0.047);
1144 ltx.SetTextAlign(11);
1145 ltx.DrawLatexNDC(gPad->GetLeftMargin(),
1146 1 - gPad->GetTopMargin() + 0.01,
1147 (
"SiPixel Gain Calibration IOV:#color[2]{" +
std::to_string(std::get<0>(firstiov)) +
1148 "} vs IOV:#color[4]{" +
std::to_string(std::get<0>(lastiov)) +
"}")
1154 canvas.SaveAs(
"out.root");
1165 template <gainCalibPI::type myType,
class PayloadType>
1175 template <gainCalibPI::type myType,
class PayloadType>
1187 template <gainCalibPI::type myType, cond::payloadInspector::IOVMultiplicity nIOVs,
int ntags,
class PayloadType>
1192 Form(
"SiPixelGainCalibration %s Diff and Ratio %i tag(s)",
TypeName[myType],
ntags)) {
1193 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
1201 gStyle->SetOptStat(
"emr");
1202 TGaxis::SetExponentOffset(-0.1, 0.01,
"y");
1203 TH1F::SetDefaultSumw2(
true);
1208 auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
1209 auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().
name;
1211 auto firstiov = theIOVs.front();
1212 std::tuple<cond::Time_t, cond::Hash> lastiov;
1218 auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
1219 l_tagname = cond::payloadInspector::PlotBase::getTag<1>().
name;
1220 lastiov = tag2iovs.front();
1222 lastiov = theIOVs.back();
1225 std::shared_ptr<PayloadType> last_payload = this->
fetchPayload(std::get<1>(lastiov));
1226 std::shared_ptr<PayloadType> first_payload = this->
fetchPayload(std::get<1>(firstiov));
1231 TCanvas
canvas(
"Canv",
"Canv", 1300, 800);
1241 array[0]->SetTitle(Form(
"SiPixel Gain Calibration %s - %s;per %s %s ratio;# %ss",
1248 array[1]->SetTitle(Form(
"SiPixel Gain Calibration %s - %s;per %s %s difference;# %ss",
1256 array[0]->SetTitle(
"");
1257 array[0]->SetLineColor(kBlack);
1258 array[0]->SetFillColor(kRed);
1259 array[0]->SetBarWidth(0.90);
1260 array[0]->SetMaximum(
array[0]->GetMaximum() * 10);
1261 array[0]->Draw(
"bar");
1263 array[0]->SetStats(
true);
1266 array[1]->SetTitle(
"");
1267 array[1]->SetLineColor(kBlack);
1268 array[1]->SetFillColor(kBlue);
1269 array[1]->SetBarWidth(0.90);
1270 array[1]->SetMaximum(
array[1]->GetMaximum() * 10);
1271 array[1]->Draw(
"bar");
1273 array[1]->SetStats(
true);
1279 latex.SetTextSize(0.024);
1280 latex.SetTextAlign(13);
1284 fmt::sprintf(
"#scale[1.2]{SiPixelGainCalibration%s Ratio}", (
isForHLT_ ?
"ForHLT" :
"Offline")).c_str());
1287 .41, .91, (
"#splitline{#font[12]{" + f_tagname +
"}}{ / #font[12]{" + l_tagname +
"}}").c_str());
1289 latex.DrawLatexNDC(.41, .91, (firstIOVsince +
" / " + lastIOVsince).c_str());
1294 latex2.SetTextSize(0.024);
1295 latex2.SetTextAlign(13);
1296 latex2.DrawLatexNDC(
1299 fmt::sprintf(
"#scale[1.2]{SiPixelGainCalibration%s Diff}", (
isForHLT_ ?
"ForHLT" :
"Offline")).c_str());
1301 latex2.DrawLatexNDC(
1302 .41, .91, (
"#splitline{#font[12]{" + f_tagname +
"}}{ - #font[12]{" + l_tagname +
"}}").c_str());
1304 latex2.DrawLatexNDC(.41, .91, (firstIOVsince +
" - " + lastIOVsince).c_str());
1307 TPaveStats* st1 = (TPaveStats*)
array[0]->FindObject(
"stats");
1308 st1->SetTextSize(0.027);
1309 st1->SetLineColor(kRed);
1310 st1->SetTextColor(kRed);
1313 TPaveStats* st2 = (TPaveStats*)
array[1]->FindObject(
"stats");
1314 st2->SetTextSize(0.027);
1315 st2->SetLineColor(kBlue);
1316 st2->SetTextColor(kBlue);
1319 auto ltx = TLatex();
1320 ltx.SetTextFont(62);
1322 ltx.SetTextSize(0.040);
1323 ltx.SetTextAlign(11);
1326 gPad->GetLeftMargin(),
1327 1 - gPad->GetTopMargin() + 0.01,
1328 fmt::sprintf(
"SiPixel %s Ratio, IOV %s / %s",
TypeName[myType], firstIOVsince, lastIOVsince).c_str());
1332 gPad->GetLeftMargin(),
1333 1 - gPad->GetTopMargin() + 0.01,
1334 fmt::sprintf(
"SiPixel %s Diff, IOV %s - %s",
TypeName[myType], firstIOVsince, lastIOVsince).c_str());
1339 canvas.SaveAs(
"out.root");
1355 template <gainCalibPI::type myType,
class PayloadType, SiPixelPI::DetType myDetType>
1361 Form(
"SiPixelGainCalibration %s Barrel Pixel Map",
TypeName[myType])),
1364 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
1366 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
1369 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
1374 TGaxis::SetMaxDigits(2);
1376 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
1378 auto iov =
tag.iovs.front();
1386 std::map<uint32_t, float> GainCalibMap_;
1389 edm::LogError(
label_) <<
"SiPixelGainCalibration maps are not supported for non-Phase1 Pixel geometries !";
1390 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
1398 std::array<double, n_layers> b_minima = {{999., 999., 999., 999.}};
1399 std::array<double, n_rings> f_minima = {{999., 999.}};
1401 for (
const auto& element : GainCalibMap_) {
1405 if (element.second < b_minima.at(layer - 1)) {
1406 b_minima.at(layer - 1) = element.second;
1411 if (element.second < f_minima.at(
ring - 1)) {
1412 f_minima.at(
ring - 1) = element.second;
1418 gStyle->SetOptStat(0);
1429 const auto headerText = fmt::sprintf(
"#color[4]{%s}, IOV: #color[4]{%s}",
tagname, IOVstring);
1431 switch (myDetType) {
1443 <<
"\nERROR: unrecognized Pixel Detector part " << std::endl;
1447 for (
unsigned int lay = 1; lay <=
n_layers; lay++) {
1452 COUT <<
" layer:" << lay <<
" max:" << h_bpix_Gains[lay - 1]->GetMaximum() <<
" min: " << b_minima.at(lay - 1)
1455 h_bpix_Gains[lay - 1]->GetZaxis()->SetRangeUser(b_minima.at(lay - 1) - 0.001,
1456 h_bpix_Gains[lay - 1]->GetMaximum() + 0.001);
1466 COUT <<
" ring:" <<
ring <<
" max:" << h_fpix_Gains[
ring - 1]->GetMaximum()
1467 <<
" min: " << f_minima.at(
ring - 1) << std::endl;
1469 h_fpix_Gains[
ring - 1]->GetZaxis()->SetRangeUser(f_minima.at(
ring - 1) - 0.001,
1470 h_fpix_Gains[
ring - 1]->GetMaximum() + 0.001);
1494 template <gainCalibPI::type myType,
class PayloadType, cond::payloadInspector::IOVMultiplicity nIOVs,
int ntags>
1500 Form(
"SiPixelGainCalibration %s Comparison by Region",
TypeName[myType])) {
1501 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
1503 label_ =
"SiPixelGainCalibrationOffline_PayloadInspector";
1506 label_ =
"SiPixelGainCalibrationForHLT_PayloadInspector";
1511 gStyle->SetPaintTextFormat(
".3f");
1514 auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
1515 auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().
name;
1517 auto firstiov = theIOVs.front();
1518 std::tuple<cond::Time_t, cond::Hash> lastiov;
1524 auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
1525 l_tagname = cond::payloadInspector::PlotBase::getTag<1>().
name;
1526 lastiov = tag2iovs.front();
1528 lastiov = theIOVs.back();
1531 std::shared_ptr<PayloadType> last_payload = this->
fetchPayload(std::get<1>(lastiov));
1532 std::shared_ptr<PayloadType> first_payload = this->
fetchPayload(std::get<1>(firstiov));
1534 std::map<uint32_t, float> f_GainsMap_;
1537 std::map<uint32_t, float> l_GainsMap_;
1543 TCanvas
canvas(
"Comparison",
"Comparison", 1600, 800);
1548 std::map<SiPixelPI::regions, std::shared_ptr<TH1F>> FirstGains_spectraByRegion;
1549 std::map<SiPixelPI::regions, std::shared_ptr<TH1F>> LastGains_spectraByRegion;
1550 std::shared_ptr<TH1F> summaryFirst;
1551 std::shared_ptr<TH1F> summaryLast;
1553 float minimum(9999.);
1554 float maximum(-9999.);
1558 maximum =
std::max(last_payload->getGainHigh(), first_payload->getGainHigh());
1559 minimum =
std::min(last_payload->getGainLow(), first_payload->getGainLow());
1562 maximum =
std::max(last_payload->getPedHigh(), first_payload->getPedHigh());
1563 minimum =
std::min(last_payload->getPedLow(), first_payload->getPedLow());
1575 FirstGains_spectraByRegion[
part] =
1576 std::make_shared<TH1F>(Form(
"hfirstGains_%s", s_part.c_str()),
1577 Form(
";%s #LT %s #GT;n. of modules", s_part.c_str(),
TypeName[myType]),
1582 LastGains_spectraByRegion[
part] =
1583 std::make_shared<TH1F>(Form(
"hlastGains_%s", s_part.c_str()),
1584 Form(
";%s #LT %s #GT;n. of modules", s_part.c_str(),
TypeName[myType]),
1590 summaryFirst = std::make_shared<TH1F>(
"first Summary",
1591 Form(
"Summary of #LT per %s %s #GT;;average %s",
1595 FirstGains_spectraByRegion.size(),
1597 FirstGains_spectraByRegion.size());
1599 summaryLast = std::make_shared<TH1F>(
"last Summary",
1600 Form(
"Summary of #LT per %s %s #GT;;average %s",
1604 LastGains_spectraByRegion.size(),
1606 LastGains_spectraByRegion.size());
1609 const char* path_toTopologyXML = f_phaseInfo.pathToTopoXML();
1617 for (
const auto&
it : f_GainsMap_) {
1624 t_info_fromXML.
init();
1629 FirstGains_spectraByRegion[thePart]->Fill(
it.second);
1633 path_toTopologyXML = l_phaseInfo.pathToTopoXML();
1641 for (
const auto&
it : l_GainsMap_) {
1648 t_info_fromXML.
init();
1653 LastGains_spectraByRegion[thePart]->Fill(
it.second);
1664 FirstGains_spectraByRegion[
part]->GetMean() > 10.e-6 ? FirstGains_spectraByRegion[
part]->GetMean() : 0.;
1665 summaryFirst->SetBinContent(
bin, f_mean);
1671 LastGains_spectraByRegion[
part]->GetMean() > 10.e-6 ? LastGains_spectraByRegion[
part]->GetMean() : 0.;
1672 summaryLast->SetBinContent(
bin, l_mean);
1678 summaryFirst->SetMarkerColor(kRed);
1679 summaryFirst->GetXaxis()->LabelsOption(
"v");
1680 summaryFirst->GetXaxis()->SetLabelSize(0.05);
1681 summaryFirst->GetYaxis()->SetTitleOffset(0.9);
1684 summaryLast->SetMarkerColor(kBlue);
1685 summaryLast->GetYaxis()->SetTitleOffset(0.9);
1686 summaryLast->GetXaxis()->LabelsOption(
"v");
1687 summaryLast->GetXaxis()->SetLabelSize(0.05);
1694 summaryFirst->SetFillColor(kRed);
1695 summaryLast->SetFillColor(kBlue);
1697 summaryFirst->SetBarWidth(0.45);
1698 summaryFirst->SetBarOffset(0.1);
1700 summaryLast->SetBarWidth(0.4);
1701 summaryLast->SetBarOffset(0.55);
1703 summaryLast->SetMarkerSize(1.2);
1704 summaryFirst->SetMarkerSize(1.2);
1706 float max = (summaryFirst->GetMaximum() > summaryLast->GetMaximum()) ? summaryFirst->GetMaximum()
1707 : summaryLast->GetMaximum();
1709 summaryFirst->GetYaxis()->SetRangeUser(0.,
std::max(0.,
max * 1.40));
1711 summaryFirst->Draw(
"b text0");
1712 summaryLast->Draw(
"b text0 same");
1714 TLegend
legend = TLegend(0.52, 0.80, 0.98, 0.9);
1715 legend.SetHeader(Form(
"#LT %s #GT value comparison",
TypeName[myType]),
1718 legend.SetHeader(
"#mu_{H} value comparison",
"C");
1721 l_tagOrHash = l_tagname;
1722 f_tagOrHash = f_tagname;
1724 l_tagOrHash = std::get<1>(lastiov);
1725 f_tagOrHash = std::get<1>(firstiov);
1730 (
"IOV: #scale[1.2]{" +
std::to_string(std::get<0>(lastiov)) +
"} | #color[4]{" + l_tagOrHash +
"}").c_str(),
1734 (
"IOV: #scale[1.2]{" +
std::to_string(std::get<0>(firstiov)) +
"} | #color[2]{" + f_tagOrHash +
"}").c_str(),
1737 legend.SetTextSize(0.025);
std::string m_imageFileName
static const std::array< std::string, 3 > t_titles
PlotImage(const std::string &title)
void drawMaps(TCanvas &canvas, const std::string &text="")
unsigned int pxbLayer(const DetId &id) const
SiPixelGainCalibrationValuesPerRegion()
SiPixelGainCalibDiffAndRatioBase()
SiPixelGainCalibrationMap()
SiPixelGainCalibrationValuesByPart()
static constexpr std::array< int, 3 > k_height
const std::vector< std::string > IDlabels
const char * pathToTopoXML()
void fillGeometryInfo(const DetId &detId, const TrackerTopology &tTopo, const SiPixelPI::phase &ph)
void drawBarrelMaps(TCanvas &canvas, const std::string &text="")
Log< level::Error, false > LogError
std::pair< float, float > getExtrema(TH1 *h1, TH1 *h2)
static constexpr int n_rings
constexpr Detector det() const
get the detector field from this detid
static std::array< std::shared_ptr< TH1F >, 2 > fillDiffAndRatio(const std::shared_ptr< PayloadType > &payload_A, const std::shared_ptr< PayloadType > &payload_B, const gainCalibPI::type &theType)
bool checkAnswerOK(std::string &answer, bool &result)
static std::string to_string(const XMLCh *ch)
void fillWholeModule(const uint32_t &detid, double value)
static constexpr int n_layers
static void fillThePerModuleMap(const std::shared_ptr< PayloadType > &payload, AvgMap &map, gainCalibPI::type theType)
SiPixelGainCalibrationByRegionComparisonBase()
void drawForwardMaps(TCanvas &canvas, const std::string &text="")
void setSingleIov(bool flag)
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
std::array< std::shared_ptr< TH2D >, 4 > getLayerMaps()
static const unsigned int phase1size
PlotAnnotations m_plotAnnotations
SiPixelPI::regions filterThePartition()
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
constexpr char const * TypeName[2]
const std::vector< PixelId > PixelIDs
static void fillTheHisto(const std::shared_ptr< PayloadType > &payload, std::shared_ptr< TH1F > h1, gainCalibPI::type theType, const std::vector< uint32_t > &wantedIds={})
void adjustCanvasMargins(TVirtualPad *pad, float top, float bottom, float left, float right)
SiPixelGainCalibrationValueComparisonSingleTag()
void adjustStats(TPaveStats *stats, float X1, float Y1, float X2, float Y2)
const std::map< std::string, std::string > & inputParamValues() const
void addInputParam(const std::string ¶mName)
SiPixelGainCalibrationValues()
void bookAll(std::string title_label, std::string x_label, std::string y_label, const int nbins, const float xmin, const float xmax)
int ring(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
void makeNicePlotStyle(TH1 *hist)
float maxDiff(float one, float two, float three, float four)
void displayNotSupported(TCanvas &canv, const unsigned int size)
static void fillTheHistos(const std::shared_ptr< PayloadType > &payload, std::shared_ptr< TH1 > hBPix, std::shared_ptr< TH1 > hFPix, gainCalibPI::type theType)
void setTwoTags(bool flag)
bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash >> &iovs) override
std::map< uint32_t, float > AvgMap
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
SiPixelGainCalibrationValuesComparisonPerRegion()
std::string getStringFromRegionEnum(SiPixelPI::regions e)
Log< level::Warning, false > LogWarning
std::array< std::shared_ptr< TH2D >, 2 > getRingMaps()
unsigned int ntags() const
static const std::vector< uint32_t > attachedDets(const PixelRegions::PixelId theId, const TrackerTopology *trackTopo, const SiPixelPI::phase &ph)
TrackerTopology m_trackerTopo
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
SiPixelGainCalibrationValueComparisonBase()
SiPixelGainCalibrationCorrelations()