1 #ifndef CONDCORE_BEAMSPOTPLUGINS_BEAMSPOTPAYLOADINSPECTORHELPER_H
2 #define CONDCORE_BEAMSPOTPLUGINS_BEAMSPOTPAYLOADINSPECTORHELPER_H
12 #include <fmt/printf.h>
24 namespace BeamSpotPI {
28 auto run = (since >> 32);
30 return std::make_pair(
run,
lumi);
64 const bool addUnits =
false ) {
67 return (addUnits ?
"X [cm]" :
"X");
69 return (addUnits ?
"Y [cm]" :
"Y");
71 return (addUnits ?
"Z [cm]" :
"Z");
73 return (addUnits ?
"#sigma_{X} [cm]" :
"sigmaX");
75 return (addUnits ?
"#sigma_{Y} [cm]" :
"sigmaY");
77 return (addUnits ?
"#sigma_{Z} [cm]" :
"sigmaZ");
79 return (addUnits ?
"#frac{dX}{dZ} [rad]" :
"dx/dz");
81 return (addUnits ?
"#frac{dY}{dZ} [rad]" :
"dy/dz");
83 return "should never be here";
92 template <
class PayloadType>
110 ss <<
"Dumping BeamSpot parameters Data:" << std::endl;
153 template <parameters my_param,
class PayloadType>
157 : cond::payloadInspector::
HistoryPlot<PayloadType, std::pair<double, double> >(
161 auto ret = std::make_pair<double, double>(-9999., -9999.);
165 return std::make_pair<double, double>(payload.x(), payload.xError());
167 return std::make_pair<double, double>(payload.y(), payload.yError());
169 return std::make_pair<double, double>(payload.z(), payload.zError());
171 return std::make_pair<double, double>(payload.beamWidthX(), payload.beamWidthXError());
173 return std::make_pair<double, double>(payload.beamWidthY(), payload.beamWidthYError());
175 return std::make_pair<double, double>(payload.sigmaZ(), payload.sigmaZError());
177 return std::make_pair<double, double>(payload.dxdz(), payload.dxdzError());
179 return std::make_pair<double, double>(payload.dydz(), payload.dydzError());
192 template <parameters my_param,
class PayloadType>
196 : cond::payloadInspector::
RunHistoryPlot<PayloadType, std::pair<double, double> >(
200 auto ret = std::make_pair<double, double>(-9999., -9999.);
204 return std::make_pair<double, double>(payload.x(), payload.xError());
206 return std::make_pair<double, double>(payload.y(), payload.yError());
208 return std::make_pair<double, double>(payload.z(), payload.zError());
210 return std::make_pair<double, double>(payload.beamWidthX(), payload.beamWidthXError());
212 return std::make_pair<double, double>(payload.beamWidthY(), payload.beamWidthYError());
214 return std::make_pair<double, double>(payload.sigmaZ(), payload.sigmaZError());
216 return std::make_pair<double, double>(payload.dxdz(), payload.dxdzError());
218 return std::make_pair<double, double>(payload.dydz(), payload.dydzError());
231 template <parameters my_param,
class PayloadType>
235 : cond::payloadInspector::
TimeHistoryPlot<PayloadType, std::pair<double, double> >(
239 auto ret = std::make_pair<double, double>(-9999., -9999.);
243 return std::make_pair<double, double>(payload.x(), payload.xError());
245 return std::make_pair<double, double>(payload.y(), payload.yError());
247 return std::make_pair<double, double>(payload.z(), payload.zError());
249 return std::make_pair<double, double>(payload.beamWidthX(), payload.beamWidthXError());
251 return std::make_pair<double, double>(payload.beamWidthY(), payload.beamWidthYError());
253 return std::make_pair<double, double>(payload.sigmaZ(), payload.sigmaZError());
255 return std::make_pair<double, double>(payload.dxdz(), payload.dxdzError());
257 return std::make_pair<double, double>(payload.dydz(), payload.dydzError());
269 template <
class PayloadType>
275 return std::make_tuple(payload.x(), payload.y());
282 template <
class PayloadType>
287 "Display of BeamSpot parameters") {
288 if constexpr (std::is_same_v<PayloadType, BeamSpotOnlineObjects>) {
296 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
298 auto iov =
tag.iovs.front();
300 gStyle->SetHistMinimumZero(kTRUE);
304 TCanvas
canvas(
"Beam Spot Parameters Summary",
"BeamSpot Parameters summary",
isOnline_ ? 1500 : 1000, 1000);
310 canvas.cd(1)->SetTopMargin(0.05);
311 canvas.cd(1)->SetBottomMargin(0.06);
312 canvas.cd(1)->SetLeftMargin(0.15);
313 canvas.cd(1)->SetRightMargin(0.01);
314 canvas.cd(1)->Modified();
315 canvas.cd(1)->SetGrid();
317 auto h2_BSParameters = std::make_unique<TH2F>(
"Parameters",
"", 2, 0.0, 2.0, 8, 0, 8.);
318 h2_BSParameters->SetStats(
false);
320 std::function<double(parameters, bool)> cutFunctor = [
this](
parameters my_param,
bool isError) {
371 h2_BSParameters->GetXaxis()->SetBinLabel(1,
"Value");
372 h2_BSParameters->GetXaxis()->SetBinLabel(2,
"Error");
374 unsigned int yBin = 8;
378 h2_BSParameters->GetYaxis()->SetBinLabel(yBin, theLabel.c_str());
379 h2_BSParameters->SetBinContent(1, yBin, cutFunctor(param,
false));
380 h2_BSParameters->SetBinContent(2, yBin, cutFunctor(param,
true));
384 h2_BSParameters->GetXaxis()->LabelsOption(
"h");
385 h2_BSParameters->GetYaxis()->SetLabelSize(0.05);
386 h2_BSParameters->GetXaxis()->SetLabelSize(0.05);
387 h2_BSParameters->SetMarkerSize(1.5);
388 h2_BSParameters->Draw(
"TEXT");
393 ltx.SetTextSize(0.030);
395 ltx.SetTextSize(0.025);
397 ltx.SetTextAlign(11);
402 gPad->GetLeftMargin(),
403 1 - gPad->GetTopMargin() + 0.01,
409 canvas.cd(2)->SetTopMargin(0.05);
410 canvas.cd(2)->SetBottomMargin(0.06);
411 canvas.cd(2)->SetLeftMargin(0.25);
412 canvas.cd(2)->SetRightMargin(0.01);
413 canvas.cd(2)->Modified();
414 canvas.cd(2)->SetGrid();
418 for (
int bin = 1;
bin <= extras->GetNbinsY();
bin++) {
420 << extras->GetYaxis()->GetBinLabel(
bin) <<
": " << extras->GetBinContent(1,
bin) <<
"\n";
423 extras->Draw(
"TEXT");
426 gPad->GetLeftMargin(),
427 1 - gPad->GetTopMargin() + 0.01,
432 canvas.SaveAs(fileName.c_str());
437 canvas.SaveAs(fileName.c_str());
463 return "#sigma_{X} [cm]";
465 return "#sigma_{Y} [cm]";
467 return "#sigma_{Z} [cm]";
469 return "#frac{dX}{dZ} [rad]";
471 return "#frac{dY}{dZ} [rad]";
473 return "should never be here";
481 template <
class PayloadType, cond::payloadInspector::IOVMultiplicity nIOVs,
int ntags>
485 : cond::payloadInspector::
PlotImage<PayloadType, nIOVs,
ntags>(
"Display of BeamSpot parameters differences") {
486 if constexpr (std::is_same_v<PayloadType, BeamSpotOnlineObjects>) {
495 auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().
iovs;
496 auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().
name;
498 auto firstiov = theIOVs.front();
499 std::tuple<cond::Time_t, cond::Hash> lastiov;
505 auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().
iovs;
506 l_tagname = cond::payloadInspector::PlotBase::getTag<1>().
name;
507 lastiov = tag2iovs.front();
509 lastiov = theIOVs.back();
518 TCanvas
canvas(
"Beam Spot Parameters Difference Summary",
"Beam Spot Parameters Difference summary", 1000, 1000);
521 canvas.cd(1)->SetTopMargin(0.08);
522 canvas.cd(1)->SetBottomMargin(0.06);
523 canvas.cd(1)->SetLeftMargin(0.14);
524 canvas.cd(1)->SetRightMargin(0.16);
525 canvas.cd(1)->Modified();
526 canvas.cd(1)->SetGrid();
529 auto h2_BSParameters = std::make_unique<TH2F>(
"Parameters",
"", 2, 0.0, 2.0, 8, 0, 8.);
530 h2_BSParameters->SetStats(
false);
531 h2_BSParameters->GetXaxis()->SetBinLabel(1,
"Value");
532 h2_BSParameters->GetXaxis()->SetBinLabel(2,
"Error");
533 h2_BSParameters->GetXaxis()->LabelsOption(
"h");
534 h2_BSParameters->GetYaxis()->SetLabelSize(0.05);
535 h2_BSParameters->GetXaxis()->SetLabelSize(0.05);
536 h2_BSParameters->SetMarkerSize(1.5);
543 std::stringstream ss1, ss2;
557 unsigned int yBin = 8;
561 h2_BSParameters->GetYaxis()->SetBinLabel(yBin, theLabel.c_str());
562 h2_BSParameters->SetBinContent(1, yBin, diffPars[foo]);
563 h2_BSParameters->SetBinContent(2, yBin, diffErrors[foo]);
568 auto h2_BSShadow = (TH2F*)(h2_BSParameters->Clone(
"shadow"));
569 h2_BSShadow->GetZaxis()->SetTitle(
"#Delta Parameter(payload A - payload B)");
570 h2_BSShadow->GetZaxis()->CenterTitle();
571 h2_BSShadow->GetZaxis()->SetTitleOffset(1.5);
574 double max = h2_BSShadow->GetMaximum();
575 double min = h2_BSShadow->GetMinimum();
576 double val_white = 0.;
577 double per_white = (max !=
min) ? ((val_white - min) / (max -
min)) : 0.5;
579 const int Number = 3;
580 double Red[Number] = {0., 1., 1.};
581 double Green[Number] = {0., 1., 0.};
582 double Blue[Number] = {1., 1., 0.};
583 double Stops[Number] = {0., per_white, 1.};
585 h2_BSShadow->SetContour(nb);
586 TColor::CreateGradientColorTable(Number, Stops, Red, Green, Blue, nb);
588 h2_BSShadow->Draw(
"colz");
589 h2_BSParameters->Draw(
"TEXTsame");
593 ltx.SetTextSize(0.025);
594 ltx.SetTextAlign(11);
604 gPad->GetLeftMargin() - 0.1,
605 1 - gPad->GetTopMargin() + 0.015,
607 "#splitline{A = #color[4]{%s}: %s}{B = #color[4]{%s}: %s}", f_tagname, f_runLSs, l_tagname, l_runLSs))
611 gPad->GetLeftMargin() - 0.1,
612 1 - gPad->GetTopMargin() + 0.015,
613 (fmt::sprintf(
"#splitline{#color[4]{%s}}{A = %s | B = %s}", f_tagname, l_runLSs, f_runLSs)).c_str());
617 canvas.SaveAs(fileName.c_str());
std::string m_imageFileName
Log< level::Info, true > LogVerbatim
const bshelpdata centralValues() const
virtual std::string getStringFromTypeEnum(const parameters ¶meter) const
PlotImage(const std::string &title)
tuple ret
prodAgent to be discontinued
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
unsigned int ntags() const
virtual std::shared_ptr< TH2F > fillTheExtraHistogram() const
const Time_t kLowMask(0xFFFFFFFF)
std::string to_string(const V &value)
std::tuple< double, double > getFromPayload(PayloadType &payload) override
ScatterPlot(const std::string &title, const std::string &xLabel, const std::string &yLabel)
virtual std::shared_ptr< TH2F > fillTheExtraHistogram() const
std::array< double, 8 > bshelpdata
const bshelpdata errors() const
unsigned long long Time_t
const bshelpdata diffErrors(const BSParamsHelper &bs2, const bool isPull=false) const
PlotAnnotations m_plotAnnotations
std::pair< double, double > getFromPayload(PayloadType &payload) override
RunHistoryPlot(const std::string &title, const std::string &yLabel)
Log< level::Warning, true > LogPrint
BSParamsHelper(const std::shared_ptr< PayloadType > &bs)
void printDebug(std::stringstream &ss)
TimeHistoryPlot(const std::string &title, const std::string &yLabel)
std::shared_ptr< PayloadType > f_payload
HistoryPlot(const std::string &title, const std::string &yLabel)
const bshelpdata diffCentralValues(const BSParamsHelper &bs2, const bool isPull=false) const
std::string getStringFromParamEnum(const parameters ¶meter, const bool addUnits=false)
std::pair< double, double > getFromPayload(PayloadType &payload) override
std::pair< double, double > getFromPayload(PayloadType &payload) override
std::shared_ptr< PayloadType > m_payload
std::shared_ptr< PayloadType > l_payload
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)