1 #ifndef CONDCORE_BEAMSPOTPLUGINS_BEAMSPOTPAYLOADINSPECTORHELPER_H 2 #define CONDCORE_BEAMSPOTPLUGINS_BEAMSPOTPAYLOADINSPECTORHELPER_H 13 #include <fmt/printf.h> 32 return std::make_pair(
run,
lumi);
68 std::time_t unixTime =
static_cast<std::time_t
>(hasMicros ? timeValue / 1000000 : timeValue);
71 std::tm* timeInfo = toUTC ? std::gmtime(&unixTime) : std::localtime(&unixTime);
75 std::strftime(
buffer,
sizeof(
buffer),
"%Y-%m-%d %H:%M:%S", timeInfo);
86 const bool addUnits =
false ) {
89 return (addUnits ?
"X [cm]" :
"X");
91 return (addUnits ?
"Y [cm]" :
"Y");
93 return (addUnits ?
"Z [cm]" :
"Z");
95 return (addUnits ?
"#sigma_{X} [cm]" :
"sigmaX");
97 return (addUnits ?
"#sigma_{Y} [cm]" :
"sigmaY");
99 return (addUnits ?
"#sigma_{Z} [cm]" :
"sigmaZ");
101 return (addUnits ?
"#frac{dX}{dZ} [rad]" :
"dx/dz");
103 return (addUnits ?
"#frac{dY}{dZ} [rad]" :
"dy/dz");
105 return "should never be here";
114 template <
class PayloadType>
135 ss <<
"Dumping BeamSpot parameters Data:" << std::endl;
178 template <parameters my_param,
class PayloadType>
186 auto ret = std::make_pair<double, double>(-9999., -9999.);
190 return std::make_pair<double, double>(
payload.x(),
payload.xError());
192 return std::make_pair<double, double>(
payload.y(),
payload.yError());
194 return std::make_pair<double, double>(
payload.z(),
payload.zError());
196 return std::make_pair<double, double>(
payload.beamWidthX(),
payload.beamWidthXError());
198 return std::make_pair<double, double>(
payload.beamWidthY(),
payload.beamWidthYError());
200 return std::make_pair<double, double>(
payload.sigmaZ(),
payload.sigmaZError());
202 return std::make_pair<double, double>(
payload.dxdz(),
payload.dxdzError());
204 return std::make_pair<double, double>(
payload.dydz(),
payload.dydzError());
217 template <parameters my_param,
class PayloadType>
225 auto ret = std::make_pair<double, double>(-9999., -9999.);
229 return std::make_pair<double, double>(
payload.x(),
payload.xError());
231 return std::make_pair<double, double>(
payload.y(),
payload.yError());
233 return std::make_pair<double, double>(
payload.z(),
payload.zError());
235 return std::make_pair<double, double>(
payload.beamWidthX(),
payload.beamWidthXError());
237 return std::make_pair<double, double>(
payload.beamWidthY(),
payload.beamWidthYError());
239 return std::make_pair<double, double>(
payload.sigmaZ(),
payload.sigmaZError());
241 return std::make_pair<double, double>(
payload.dxdz(),
payload.dxdzError());
243 return std::make_pair<double, double>(
payload.dydz(),
payload.dydzError());
256 template <parameters my_param,
class PayloadType>
264 auto ret = std::make_pair<double, double>(-9999., -9999.);
268 return std::make_pair<double, double>(
payload.x(),
payload.xError());
270 return std::make_pair<double, double>(
payload.y(),
payload.yError());
272 return std::make_pair<double, double>(
payload.z(),
payload.zError());
274 return std::make_pair<double, double>(
payload.beamWidthX(),
payload.beamWidthXError());
276 return std::make_pair<double, double>(
payload.beamWidthY(),
payload.beamWidthYError());
278 return std::make_pair<double, double>(
payload.sigmaZ(),
payload.sigmaZError());
280 return std::make_pair<double, double>(
payload.dxdz(),
payload.dxdzError());
282 return std::make_pair<double, double>(
payload.dydz(),
payload.dydzError());
294 template <
class PayloadType>
307 template <
class PayloadType>
312 "Display of BeamSpot parameters") {
313 if constexpr (std::is_same_v<PayloadType, BeamSpotOnlineObjects>) {
321 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
323 auto iov =
tag.iovs.front();
325 gStyle->SetHistMinimumZero(kTRUE);
329 TCanvas
canvas(
"Beam Spot Parameters Summary",
"BeamSpot Parameters summary",
isOnline_ ? 1500 : 1000, 1000);
335 canvas.cd(1)->SetTopMargin(0.05);
336 canvas.cd(1)->SetBottomMargin(0.06);
337 canvas.cd(1)->SetLeftMargin(0.15);
338 canvas.cd(1)->SetRightMargin(0.01);
342 auto h2_BSParameters = std::make_unique<TH2F>(
"Parameters",
"", 2, 0.0, 2.0, 8, 0, 8.);
343 h2_BSParameters->SetStats(
false);
345 std::function<double(parameters, bool)> cutFunctor = [
this](
parameters my_param,
bool isError) {
396 h2_BSParameters->GetXaxis()->SetBinLabel(1,
"Value");
397 h2_BSParameters->GetXaxis()->SetBinLabel(2,
"Error");
399 unsigned int yBin = 8;
403 h2_BSParameters->GetYaxis()->SetBinLabel(
yBin, theLabel.c_str());
404 h2_BSParameters->SetBinContent(1,
yBin, cutFunctor(param,
false));
405 h2_BSParameters->SetBinContent(2,
yBin, cutFunctor(param,
true));
409 h2_BSParameters->GetXaxis()->LabelsOption(
"h");
410 h2_BSParameters->GetYaxis()->SetLabelSize(0.05);
411 h2_BSParameters->GetXaxis()->SetLabelSize(0.05);
412 h2_BSParameters->SetMarkerSize(1.5);
413 h2_BSParameters->Draw(
"TEXT");
418 ltx.SetTextSize(0.030);
420 ltx.SetTextSize(0.025);
422 ltx.SetTextAlign(11);
427 gPad->GetLeftMargin(),
428 1 - gPad->GetTopMargin() + 0.01,
434 canvas.cd(2)->SetTopMargin(0.05);
435 canvas.cd(2)->SetBottomMargin(0.06);
436 canvas.cd(2)->SetLeftMargin(0.25);
437 canvas.cd(2)->SetRightMargin(0.01);
443 for (
int bin = 1;
bin <= extras->GetNbinsY();
bin++) {
445 << extras->GetYaxis()->GetBinLabel(
bin) <<
": " << extras->GetBinContent(1,
bin) <<
"\n";
448 extras->Draw(
"TEXT");
451 gPad->GetLeftMargin(),
452 1 - gPad->GetTopMargin() + 0.01,
456 if constexpr (std::is_same_v<PayloadType, BeamSpotOnlineObjects>) {
458 const auto&
creationTime = test_<cond::Time_t, std::out_of_range>(
464 const auto&
startTime = test_<cond::Time_t, std::out_of_range>(
470 const auto&
endTime = test_<cond::Time_t, std::out_of_range>(
476 ltx.SetTextSize(0.025);
478 gPad->GetLeftMargin() + 0.01,
479 gPad->GetBottomMargin() + 0.15,
482 ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
483 gPad->GetBottomMargin() + 0.085,
486 ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
487 gPad->GetBottomMargin() + 0.025,
491 gPad->GetLeftMargin(), gPad->GetBottomMargin() - 0.05,
"#color[4]{N.B.} TimeStamps are in UTC");
526 return "#sigma_{X} [cm]";
528 return "#sigma_{Y} [cm]";
530 return "#sigma_{Z} [cm]";
532 return "#frac{dX}{dZ} [rad]";
534 return "#frac{dY}{dZ} [rad]";
536 return "should never be here";
544 template <
typename T,
class Except,
class Func,
class Response>
547 LogDebug(
"DisplayParameters") <<
"I have tried" << std::endl;
549 }
catch (
const Except&
e) {
550 LogDebug(
"DisplayParameters") <<
"I have caught!" << std::endl;
552 return static_cast<T>(1);
560 template <
class PayloadType, cond::payloadInspector::IOVMultiplicity nIOVs,
int ntags>
564 :
cond::payloadInspector::
PlotImage<PayloadType, nIOVs,
ntags>(
"Display of BeamSpot parameters differences") {
565 if constexpr (std::is_same_v<PayloadType, BeamSpotOnlineObjects>) {
574 auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
575 auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().
name;
577 auto firstiov = theIOVs.front();
578 std::tuple<cond::Time_t, cond::Hash> lastiov;
584 auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
585 l_tagname = cond::payloadInspector::PlotBase::getTag<1>().
name;
586 lastiov = tag2iovs.front();
588 lastiov = theIOVs.back();
597 TCanvas
canvas(
"Beam Spot Parameters Difference Summary",
"Beam Spot Parameters Difference summary", 1000, 1000);
600 canvas.cd(1)->SetTopMargin(0.08);
601 canvas.cd(1)->SetBottomMargin(0.06);
602 canvas.cd(1)->SetLeftMargin(0.14);
603 canvas.cd(1)->SetRightMargin(0.16);
608 auto h2_BSParameters = std::make_unique<TH2F>(
"Parameters",
"", 2, 0.0, 2.0, 8, 0, 8.);
609 h2_BSParameters->SetStats(
false);
610 h2_BSParameters->GetXaxis()->SetBinLabel(1,
"Value");
611 h2_BSParameters->GetXaxis()->SetBinLabel(2,
"Error");
612 h2_BSParameters->GetXaxis()->LabelsOption(
"h");
613 h2_BSParameters->GetYaxis()->SetLabelSize(0.05);
614 h2_BSParameters->GetXaxis()->SetLabelSize(0.05);
615 h2_BSParameters->SetMarkerSize(1.5);
622 std::stringstream ss1, ss2;
636 unsigned int yBin = 8;
640 h2_BSParameters->GetYaxis()->SetBinLabel(
yBin, theLabel.c_str());
641 h2_BSParameters->SetBinContent(1,
yBin, diffPars[
foo]);
642 h2_BSParameters->SetBinContent(2,
yBin, diffErrors[
foo]);
647 auto h2_BSShadow = (TH2F*)(h2_BSParameters->Clone(
"shadow"));
648 h2_BSShadow->GetZaxis()->SetTitle(
"#Delta Parameter(payload A - payload B)");
649 h2_BSShadow->GetZaxis()->CenterTitle();
650 h2_BSShadow->GetZaxis()->SetTitleOffset(1.5);
653 double max = h2_BSShadow->GetMaximum();
654 double min = h2_BSShadow->GetMinimum();
655 double val_white = 0.;
656 double per_white = (
max !=
min) ? ((val_white -
min) / (
max -
min)) : 0.5;
659 double Red[
number] = {0., 1., 1.};
660 double Green[
number] = {0., 1., 0.};
661 double Blue[
number] = {1., 1., 0.};
662 double Stops[
number] = {0., per_white, 1.};
664 h2_BSShadow->SetContour(nb);
665 TColor::CreateGradientColorTable(
number, Stops, Red, Green, Blue, nb);
667 h2_BSShadow->Draw(
"colz");
668 h2_BSParameters->Draw(
"TEXTsame");
672 ltx.SetTextSize(0.025);
673 ltx.SetTextAlign(11);
683 gPad->GetLeftMargin() - 0.1,
684 1 - gPad->GetTopMargin() + 0.015,
686 "#splitline{A = #color[4]{%s}: %s}{B = #color[4]{%s}: %s}", f_tagname, f_runLSs, l_tagname, l_runLSs))
690 gPad->GetLeftMargin() - 0.1,
691 1 - gPad->GetTopMargin() + 0.015,
692 (fmt::sprintf(
"#splitline{#color[4]{%s}}{A = %s | B = %s}", f_tagname, l_runLSs, f_runLSs)).c_str());
739 return (addUnits ?
"X [cm]" :
"X");
741 return (addUnits ?
"Y [cm]" :
"Y");
743 return (addUnits ?
"Z [cm]" :
"Z");
745 return (addUnits ?
"MeanX [cm]" :
"meanX");
747 return (addUnits ?
"MeanY [cm]" :
"meanY");
749 return (addUnits ?
"MeanZ [cm]" :
"meanZ");
751 return (addUnits ?
"#sigma_{X} [#mum]" :
"sigmaX");
753 return (addUnits ?
"#sigma_{Y} [#mum]" :
"sigmaY");
755 return (addUnits ?
"#sigma_{Z} [cm]" :
"sigmaZ");
757 return (addUnits ?
"#beta* [cm]" :
"BetaStar");
759 return (addUnits ?
"Emittance [cm]" :
"Emittance");
761 return (addUnits ?
"Phi [rad]" :
"Phi");
763 return (addUnits ?
"Alpha [rad]" :
"Alpha");
765 return (addUnits ?
"TimeOffset [ns]" :
"TimeOffset");
767 return "should never be here";
776 template <
class PayloadType>
778 typedef std::array<double, parameters::END_OF_TYPES>
bshelpdata;
795 ss <<
"Dumping SimBeamSpot parameters Data:" << std::endl;
823 template <
class PayloadType>
828 "Display of SimBeamSpot parameters") {}
831 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
833 auto iov =
tag.iovs.front();
835 gStyle->SetHistMinimumZero(kTRUE);
839 TCanvas
canvas(
"Sim Beam Spot Parameters Summary",
"Sim BeamSpot Parameters summary", 1000, 1000);
841 canvas.cd(1)->SetTopMargin(0.05);
842 canvas.cd(1)->SetBottomMargin(0.06);
843 canvas.cd(1)->SetLeftMargin(0.25);
844 canvas.cd(1)->SetRightMargin(0.01);
849 h2_SimBSParameters->SetStats(
false);
851 std::function<double(parameters)> cutFunctor = [
this](
parameters my_param) {
889 h2_SimBSParameters->GetXaxis()->SetBinLabel(1,
"Value");
895 h2_SimBSParameters->GetYaxis()->SetBinLabel(
yBin, theLabel.c_str());
896 h2_SimBSParameters->SetBinContent(1,
yBin, cutFunctor(param));
900 h2_SimBSParameters->GetXaxis()->LabelsOption(
"h");
901 h2_SimBSParameters->GetYaxis()->SetLabelSize(0.05);
902 h2_SimBSParameters->GetXaxis()->SetLabelSize(0.05);
903 h2_SimBSParameters->SetMarkerSize(1.5);
904 h2_SimBSParameters->Draw(
"TEXT");
908 ltx.SetTextSize(0.025);
913 ltx.SetTextAlign(32);
914 ltx.DrawLatexNDC(1 - gPad->GetRightMargin(),
915 1 - gPad->GetTopMargin() + 0.01,
936 template <
class PayloadType, cond::payloadInspector::IOVMultiplicity nIOVs,
int ntags>
941 "Display of Sim BeamSpot parameters differences") {}
945 auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
946 auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().
name;
948 auto firstiov = theIOVs.front();
949 std::tuple<cond::Time_t, cond::Hash> lastiov;
955 auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
956 l_tagname = cond::payloadInspector::PlotBase::getTag<1>().
name;
957 lastiov = tag2iovs.front();
959 lastiov = theIOVs.back();
969 "Sim Beam Spot Parameters Difference Summary",
"Sim Beam Spot Parameters Difference summary", 1000, 1000);
971 canvas.cd(1)->SetTopMargin(0.10);
972 canvas.cd(1)->SetBottomMargin(0.06);
973 canvas.cd(1)->SetLeftMargin(0.23);
974 canvas.cd(1)->SetRightMargin(0.16);
980 h2_SimBSParameters->SetStats(
false);
981 h2_SimBSParameters->GetXaxis()->SetBinLabel(1,
"Value");
982 h2_SimBSParameters->GetXaxis()->LabelsOption(
"h");
983 h2_SimBSParameters->GetYaxis()->SetLabelSize(0.05);
984 h2_SimBSParameters->GetXaxis()->SetLabelSize(0.05);
985 h2_SimBSParameters->SetMarkerSize(1.5);
992 std::stringstream ss1, ss2;
1008 h2_SimBSParameters->GetYaxis()->SetBinLabel(
yBin, theLabel.c_str());
1009 h2_SimBSParameters->SetBinContent(1,
yBin, diffPars[
foo]);
1014 auto h2_SimBSShadow = (TH2F*)(h2_SimBSParameters->Clone(
"shadow"));
1015 h2_SimBSShadow->GetZaxis()->SetTitle(
"#Delta Parameter(payload A - payload B)");
1016 h2_SimBSShadow->GetZaxis()->CenterTitle();
1017 h2_SimBSShadow->GetZaxis()->SetTitleOffset(1.5);
1020 double max = h2_SimBSShadow->GetMaximum();
1021 double min = h2_SimBSShadow->GetMinimum();
1022 double val_white = 0.;
1023 double per_white = (
max !=
min) ? ((val_white -
min) / (
max -
min)) : 0.5;
1026 double Red[
number] = {0., 1., 1.};
1027 double Green[
number] = {0., 1., 0.};
1028 double Blue[
number] = {1., 1., 0.};
1029 double Stops[
number] = {0., per_white, 1.};
1031 h2_SimBSShadow->SetContour(nb);
1032 TColor::CreateGradientColorTable(
number, Stops, Red, Green, Blue, nb);
1034 h2_SimBSShadow->Draw(
"colz");
1035 h2_SimBSParameters->Draw(
"TEXTsame");
1037 auto ltx = TLatex();
1038 ltx.SetTextFont(62);
1039 ltx.SetTextSize(0.025);
1040 ltx.SetTextAlign(11);
1050 gPad->GetLeftMargin(),
1051 1 - gPad->GetTopMargin() + 0.025,
1053 "#splitline{A = #color[4]{%s}: %s}{B = #color[4]{%s}: %s}", f_tagname, f_runLSs, l_tagname, l_runLSs))
1057 gPad->GetLeftMargin(),
1058 1 - gPad->GetTopMargin() + 0.025,
1059 (fmt::sprintf(
"#splitline{#color[4]{%s}}{A = %s | B = %s}", f_tagname, l_runLSs, f_runLSs)).c_str());
const bshelpdata centralValues() const
std::string m_imageFileName
Log< level::Info, true > LogVerbatim
const bshelpdata diffErrors(const BSParamsHelper &bs2, const bool isPull=false) const
const bshelpdata centralValues() const
PlotImage(const std::string &title)
std::shared_ptr< PayloadType > l_payload
std::pair< double, double > getFromPayload(PayloadType &payload) override
virtual std::shared_ptr< TH2F > fillTheExtraHistogram() const
static constexpr double cmToUm
ret
prodAgent to be discontinued
const Time_t kLowMask(0xFFFFFFFF)
std::shared_ptr< PayloadType > m_payload
std::array< double, parameters::END_OF_TYPES > bshelpdata
std::string getStringFromParamEnum(const parameters ¶meter, const bool addUnits=false)
Log< level::Error, false > LogError
std::pair< double, double > getFromPayload(PayloadType &payload) override
std::array< double, parameters::lastLumi > bshelpdata
const bshelpdata diffCentralValues(const BSParamsHelper &bs2, const bool isPull=false) const
static std::string to_string(const XMLCh *ch)
ScatterPlot(const std::string &title, const std::string &xLabel, const std::string &yLabel)
unsigned long long Time_t
std::string convertTimeToDateString(cond::Time_t timeValue, bool hasMicros=false, bool toUTC=true)
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
std::shared_ptr< PayloadType > m_payload
const bshelpdata errors() const
PlotAnnotations m_plotAnnotations
std::shared_ptr< PayloadType > f_payload
RunHistoryPlot(const std::string &title, const std::string &yLabel)
std::pair< double, double > getFromPayload(PayloadType &payload) override
T test_(Func f, Response r) const
std::string getStringFromParamEnum(const parameters ¶meter, const bool addUnits=false)
Log< level::Warning, true > LogPrint
void printDebug(std::stringstream &ss)
virtual std::string getStringFromTypeEnum(const parameters ¶meter) const
const bshelpdata diffCentralValues(const SimBSParamsHelper &bs2, const bool isPull=false) const
static void better_error(const std::exception &e)
SimBSParamsHelper(const std::shared_ptr< PayloadType > &bs)
TimeHistoryPlot(const std::string &title, const std::string &yLabel)
std::shared_ptr< PayloadType > f_payload
HistoryPlot(const std::string &title, const std::string &yLabel)
void printDebug(std::stringstream &ss)
std::tuple< double, double > getFromPayload(PayloadType &payload) override
std::shared_ptr< PayloadType > l_payload
BSParamsHelper(const std::shared_ptr< PayloadType > &bs)
unsigned int ntags() const
virtual std::shared_ptr< TH2F > fillTheExtraHistogram() const
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)