20 #include <fmt/printf.h>
31 #include "TPaveStats.h"
37 enum type { t_slope = 0, t_offset = 1 };
44 template <SiPixelVCalPI::type myType>
49 "SiPixel VCal values",
50 "SiPixel VCal values",
55 bool fill()
override {
56 auto tag = PlotBase::getTag<0>();
57 for (
auto const &iov :
tag.iovs) {
60 auto VCalMap_ =
payload->getSlopeAndOffset();
61 for (
const auto &element : VCalMap_) {
62 if (myType == SiPixelVCalPI::t_slope) {
64 }
else if (myType == SiPixelVCalPI::t_offset) {
74 using SiPixelVCalSlopeValue = SiPixelVCalValue<SiPixelVCalPI::t_slope>;
75 using SiPixelVCalOffsetValue = SiPixelVCalValue<SiPixelVCalPI::t_offset>;
85 bool fill()
override {
86 gStyle->SetOptStat(
"emr");
88 auto tag = PlotBase::getTag<0>();
89 auto iov =
tag.iovs.front();
91 auto VCalMap_ =
payload->getSlopeAndOffset();
93 auto slopes =
payload->getAllSlopes();
107 auto o_range = (o_extrema.second - o_extrema.first) / 10.;
109 TCanvas
canvas(
"Canv",
"Canv", 1000, 1000);
113 std::make_shared<TH1F>(
"slope value",
114 "SiPixel VCal slope value;SiPixel VCal slope value [ADC/VCal units];# modules",
116 s_extrema.first * 0.9,
117 s_extrema.second * 1.1);
119 auto h_offset = std::make_shared<TH1F>(
"offset value",
120 "SiPixel VCal offset value;SiPixel VCal offset value [ADC];# modules",
122 o_extrema.first - o_range,
123 o_extrema.second + o_range);
125 for (
unsigned int i = 1;
i <= 2;
i++) {
129 for (
const auto &
slope : slopes) {
130 h_slope->Fill(
slope.second);
134 h_offset->Fill(
offset.second);
138 adjustHisto(h_slope);
141 TLegend
legend = TLegend(0.40, 0.83, 0.94, 0.93);
142 legend.SetHeader((
"Payload hash: #bf{" + (std::get<1>(iov)) +
"}").c_str(),
144 legend.AddEntry(h_slope.get(), (
"TAG: " +
tag.name).c_str(),
"F");
145 legend.SetTextSize(0.035);
149 TPaveStats *st = (TPaveStats *)h_slope->FindObject(
"stats");
150 st->SetTextSize(0.035);
155 ltx.SetTextSize(0.05);
156 ltx.SetTextAlign(11);
157 ltx.DrawLatexNDC(gPad->GetLeftMargin(),
158 1 - gPad->GetTopMargin() + 0.01,
159 (
"SiPixel VCal Slope IOV:" + std::to_string(std::get<0>(iov))).c_str());
162 adjustHisto(h_offset);
166 ltx.DrawLatexNDC(gPad->GetLeftMargin(),
167 1 - gPad->GetTopMargin() + 0.01,
168 (
"SiPixel VCal Offset IOV:" + std::to_string(std::get<0>(iov))).c_str());
170 TPaveStats *st2 = (TPaveStats *)h_offset->FindObject(
"stats");
171 st2->SetTextSize(0.035);
181 void adjustHisto(
const std::shared_ptr<TH1F> &
histo) {
183 histo->GetYaxis()->SetRangeUser(0.,
histo->GetMaximum() * 1.30);
184 histo->SetFillColor(kRed);
185 histo->SetMarkerStyle(20);
186 histo->SetMarkerSize(1);
189 histo->SetStats(
true);
190 histo->GetYaxis()->SetTitleOffset(0.9);
197 template <
bool isBarrel, SiPixelVCalPI::type myType>
198 class SiPixelVCalValuesPerRegion
201 SiPixelVCalValuesPerRegion()
203 "SiPixelVCal Values per region") {}
205 bool fill()
override {
206 gStyle->SetOptStat(
"emr");
208 auto tag = PlotBase::getTag<0>();
209 auto iov =
tag.iovs.front();
212 if (myType == SiPixelVCalPI::t_slope) {
213 Map_ =
payload->getAllSlopes();
215 Map_ =
payload->getAllOffsets();
218 auto range = (extrema.second - extrema.first) / 10.;
237 myPlots.
bookAll((myType == SiPixelVCalPI::t_slope) ?
"SiPixel VCal slope value" :
"SiPixel VCal offset value",
238 (myType == SiPixelVCalPI::t_slope) ?
"SiPixel VCal slope value [ADC/VCal units]"
239 :
"SiPixel VCal offset value [ADC]",
242 extrema.first -
range,
243 extrema.second +
range);
247 for (
const auto &element : Map_) {
248 myPlots.fill(element.first, element.second);
254 TLegend
legend = TLegend(0.40, 0.88, 0.93, 0.90);
255 legend.SetHeader((
"Hash: #bf{" + (std::get<1>(iov)) +
"}").c_str(),
258 legend.SetTextSize(0.025);
261 unsigned int maxPads =
isBarrel ? 4 : 12;
262 for (
unsigned int c = 1;
c <= maxPads;
c++) {
273 ltx.SetTextSize(0.05);
274 ltx.SetTextAlign(11);
276 for (
unsigned int c = 1;
c <= maxPads;
c++) {
280 ltx.DrawLatexNDC(gPad->GetLeftMargin(),
281 1 - gPad->GetTopMargin() + 0.01,
292 using SiPixelVCalSlopeValuesBarrel = SiPixelVCalValuesPerRegion<true, SiPixelVCalPI::t_slope>;
293 using SiPixelVCalSlopeValuesEndcap = SiPixelVCalValuesPerRegion<false, SiPixelVCalPI::t_slope>;
295 using SiPixelVCalOffsetValuesBarrel = SiPixelVCalValuesPerRegion<true, SiPixelVCalPI::t_offset>;
296 using SiPixelVCalOffsetValuesEndcap = SiPixelVCalValuesPerRegion<false, SiPixelVCalPI::t_offset>;
301 template <
bool isBarrel,
int ntags, SiPixelVCalPI::type myType>
302 class SiPixelVCalValuesComparisonPerRegion
305 SiPixelVCalValuesComparisonPerRegion()
307 Form(
"SiPixelVCal Values Comparisons per region %i tags(s)", ntags)) {}
309 bool fill()
override {
310 gStyle->SetOptStat(
"emr");
313 auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
314 auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().name;
316 auto firstiov = theIOVs.front();
317 std::tuple<cond::Time_t, cond::Hash> lastiov;
320 assert(this->m_plotAnnotations.ntags < 3);
322 if (this->m_plotAnnotations.ntags == 2) {
323 auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
324 l_tagname = cond::payloadInspector::PlotBase::getTag<1>().name;
325 lastiov = tag2iovs.front();
327 lastiov = theIOVs.back();
333 std::shared_ptr<SiPixelVCal> last_payload = this->
fetchPayload(std::get<1>(lastiov));
334 if (myType == SiPixelVCalPI::t_slope) {
335 l_Map_ = last_payload->getAllSlopes();
337 l_Map_ = last_payload->getAllOffsets();
341 std::shared_ptr<SiPixelVCal> first_payload = this->
fetchPayload(std::get<1>(firstiov));
342 if (myType == SiPixelVCalPI::t_slope) {
343 f_Map_ = first_payload->getAllSlopes();
345 f_Map_ = first_payload->getAllOffsets();
350 auto max = (l_extrema.second > f_extrema.second) ? l_extrema.second : f_extrema.second;
351 auto min = (l_extrema.first < f_extrema.first) ? l_extrema.first : f_extrema.first;
353 std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
354 std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
371 const char *path_toTopologyXML = l_phaseInfo.
pathToTopoXML();
378 fmt::sprintf(
"SiPixel VCal %s,last", (myType == SiPixelVCalPI::t_slope ?
"slope" :
"offset")),
379 fmt::sprintf(
"SiPixel VCal %s", (myType == SiPixelVCalPI::t_slope ?
" slope [ADC/VCal]" :
" offset [ADC]")),
385 for (
const auto &element : l_Map_) {
386 l_myPlots.fill(element.first, element.second);
389 l_myPlots.beautify();
394 path_toTopologyXML = f_phaseInfo.pathToTopoXML();
401 fmt::sprintf(
"SiPixel VCal %s,first", (myType == SiPixelVCalPI::t_slope ?
"slope" :
"offset")),
402 fmt::sprintf(
"SiPixel VCal %s", (myType == SiPixelVCalPI::t_slope ?
" slope [ADC/VCal]" :
" offset [ADC]")),
408 for (
const auto &element : f_Map_) {
409 f_myPlots.fill(element.first, element.second);
412 f_myPlots.beautify(kAzure, kBlue);
416 l_myPlots.rescaleMax(f_myPlots);
421 std::unique_ptr<TLegend>
legend;
422 if (this->m_plotAnnotations.ntags == 2) {
423 legend = std::make_unique<TLegend>(0.36, 0.86, 0.94, 0.92);
424 legend->AddEntry(l_myPlots.getHistoFromMap(colorTag).get(), (
"#color[2]{" + l_tagname +
"}").c_str(),
"F");
425 legend->AddEntry(f_myPlots.getHistoFromMap(colorTag).get(), (
"#color[4]{" + f_tagname +
"}").c_str(),
"F");
426 legend->SetTextSize(0.024);
428 legend = std::make_unique<TLegend>(0.58, 0.80, 0.90, 0.92);
429 legend->AddEntry(l_myPlots.getHistoFromMap(colorTag).get(), (
"#color[2]{" + lastIOVsince +
"}").c_str(),
"F");
430 legend->AddEntry(f_myPlots.getHistoFromMap(colorTag).get(), (
"#color[4]{" + firstIOVsince +
"}").c_str(),
"F");
431 legend->SetTextSize(0.040);
435 unsigned int maxPads =
isBarrel ? 4 : 12;
436 for (
unsigned int c = 1;
c <= maxPads;
c++) {
448 ltx.SetTextSize(0.05);
449 ltx.SetTextAlign(11);
451 for (
unsigned int c = 1;
c <= maxPads;
c++) {
454 ltx.DrawLatexNDC(gPad->GetLeftMargin(),
455 1 - gPad->GetTopMargin() + 0.01,
457 "} vs #color[2]{" + std::to_string(std::get<0>(lastiov)) +
"}")
468 using SiPixelVCalSlopesBarrelCompareSingleTag = SiPixelVCalValuesComparisonPerRegion<true, 1, SiPixelVCalPI::t_slope>;
469 using SiPixelVCalOffsetsBarrelCompareSingleTag =
470 SiPixelVCalValuesComparisonPerRegion<true, 1, SiPixelVCalPI::t_offset>;
472 using SiPixelVCalSlopesEndcapCompareSingleTag =
473 SiPixelVCalValuesComparisonPerRegion<false, 1, SiPixelVCalPI::t_slope>;
474 using SiPixelVCalOffsetsEndcapCompareSingleTag =
475 SiPixelVCalValuesComparisonPerRegion<false, 1, SiPixelVCalPI::t_offset>;
477 using SiPixelVCalSlopesBarrelCompareTwoTags = SiPixelVCalValuesComparisonPerRegion<true, 2, SiPixelVCalPI::t_slope>;
478 using SiPixelVCalOffsetsBarrelCompareTwoTags = SiPixelVCalValuesComparisonPerRegion<true, 2, SiPixelVCalPI::t_offset>;
480 using SiPixelVCalSlopesEndcapCompareTwoTags = SiPixelVCalValuesComparisonPerRegion<false, 2, SiPixelVCalPI::t_slope>;
481 using SiPixelVCalOffsetsEndcapCompareTwoTags =
482 SiPixelVCalValuesComparisonPerRegion<false, 2, SiPixelVCalPI::t_offset>;
488 template <SiPixelVCalPI::type myType>
491 SiPixelVCalValueComparisonBase()
492 :
cond::payloadInspector::PlotImage<
SiPixelVCal>(
"SiPixelVCal Values Comparison") {}
493 bool fill(
const std::vector<std::tuple<cond::Time_t, cond::Hash>> &iovs)
override {
494 TH1F::SetDefaultSumw2(
true);
495 std::vector<std::tuple<cond::Time_t, cond::Hash>> sorted_iovs = iovs;
497 std::sort(begin(sorted_iovs),
end(sorted_iovs), [](
auto const &
t1,
auto const &
t2) {
498 return std::get<0>(
t1) < std::get<0>(
t2);
500 auto firstiov = sorted_iovs.front();
501 auto lastiov = sorted_iovs.back();
506 std::shared_ptr<SiPixelVCal> last_payload =
fetchPayload(std::get<1>(lastiov));
507 if (myType == SiPixelVCalPI::t_slope) {
508 l_Map_ = last_payload->getAllSlopes();
510 l_Map_ = last_payload->getAllOffsets();
514 std::shared_ptr<SiPixelVCal> first_payload =
fetchPayload(std::get<1>(firstiov));
515 if (myType == SiPixelVCalPI::t_slope) {
516 f_Map_ = first_payload->getAllSlopes();
518 f_Map_ = first_payload->getAllOffsets();
522 auto max = (l_extrema.second > f_extrema.second) ? l_extrema.second : f_extrema.second;
523 auto min = (l_extrema.first < f_extrema.first) ? l_extrema.first : f_extrema.first;
525 std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
526 std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
528 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
530 auto hfirst = std::unique_ptr<TH1F>(
531 new TH1F(
"value_first",
532 fmt::sprintf(
"SiPixel VCal %s value;SiPixel VCal %s ;# modules",
533 (myType == SiPixelVCalPI::t_slope ?
"slope" :
"offset"),
534 (myType == SiPixelVCalPI::t_slope ?
" slope [ADC/VCal]" :
" offset [ADC]"))
539 hfirst->SetStats(
false);
541 auto hlast = std::unique_ptr<TH1F>(
542 new TH1F(
"value_last",
543 fmt::sprintf(
"SiPixel VCal %s value;SiPixel VCal %s ;# modules",
544 (myType == SiPixelVCalPI::t_slope ?
"slope" :
"offset"),
545 (myType == SiPixelVCalPI::t_slope ?
" slope [ADC/VCal]" :
" offset [ADC]"))
550 hlast->SetStats(
false);
555 for (
const auto &element : f_Map_) {
556 hfirst->Fill(element.second);
559 for (
const auto &element : l_Map_) {
560 hlast->Fill(element.second);
564 hfirst->GetYaxis()->SetRangeUser(extrema.first, extrema.second * 1.10);
566 hfirst->SetTitle(
"");
567 hfirst->SetFillColor(kRed);
568 hfirst->SetBarWidth(0.95);
569 hfirst->Draw(
"histbar");
572 hlast->SetFillColorAlpha(kBlue, 0.20);
573 hlast->SetBarWidth(0.95);
574 hlast->Draw(
"histbarsame");
581 TLegend
legend = TLegend(0.30, 0.86, 0.95, 0.94);
582 legend.AddEntry(hfirst.get(), (
"payload: #color[2]{" + std::get<1>(firstiov) +
"}").c_str(),
"F");
583 legend.AddEntry(hlast.get(), (
"payload: #color[4]{" + std::get<1>(lastiov) +
"}").c_str(),
"F");
584 legend.SetTextSize(0.025);
589 ltx.SetTextSize(0.047);
590 ltx.SetTextAlign(11);
591 ltx.DrawLatexNDC(gPad->GetLeftMargin(),
592 1 - gPad->GetTopMargin() + 0.01,
593 (
"SiPixel VCal IOV: #color[2]{" + std::to_string(std::get<0>(firstiov)) +
594 "} vs IOV: #color[4]{" + std::to_string(std::get<0>(lastiov)) +
"}")
604 template <SiPixelVCalPI::type myType>
605 class SiPixelVCalValueComparisonSingleTag :
public SiPixelVCalValueComparisonBase<myType> {
607 SiPixelVCalValueComparisonSingleTag() : SiPixelVCalValueComparisonBase<myType>() { this->setSingleIov(
false); }
610 template <SiPixelVCalPI::type myType>
611 class SiPixelVCalValueComparisonTwoTags :
public SiPixelVCalValueComparisonBase<myType> {
613 SiPixelVCalValueComparisonTwoTags() : SiPixelVCalValueComparisonBase<myType>() { this->setTwoTags(
true); }
616 using SiPixelVCalSlopesComparisonSingleTag = SiPixelVCalValueComparisonSingleTag<SiPixelVCalPI::t_slope>;
617 using SiPixelVCalOffsetsComparisonSingleTag = SiPixelVCalValueComparisonSingleTag<SiPixelVCalPI::t_offset>;
619 using SiPixelVCalSlopesComparisonTwoTags = SiPixelVCalValueComparisonTwoTags<SiPixelVCalPI::t_slope>;
620 using SiPixelVCalOffsetsComparisonTwoTags = SiPixelVCalValueComparisonTwoTags<SiPixelVCalPI::t_offset>;