CMS 3D CMS Logo

PPSTimingCalibrationPayloadInspectorHelper.h
Go to the documentation of this file.
1 #ifndef CONDCORE_CTPPSPLUGINS_PPSTIMINGCALIBRATIONPAYLOADINSPECTORHELPER_H
2 #define CONDCORE_CTPPSPLUGINS_PPSTIMINGCALIBRATIONPAYLOADINSPECTORHELPER_H
3 
4 // User includes
10 
11 // system includes
12 #include <memory>
13 #include <sstream>
14 
15 // ROOT includes
16 #include "TCanvas.h"
17 #include "TStyle.h"
18 #include "TH2F.h"
19 #include "TLatex.h"
20 #include "TGraph.h"
21 
23  enum parameter { parameter0 = 0, parameter1 = 1, parameter2 = 2, parameter3 = 3 };
24 
26  const std::map<int, std::string> parameters = {{parameter0, "parameter 0"},
27  {parameter1, "parameter 1"},
28  {parameter2, "parameter 2"},
29  {parameter3, "parameter 3"}};
30 
31  auto it = parameters.find(parameter);
32  if (it != parameters.end()) {
33  return it->second;
34  } else {
35  return "no param";
36  }
37  }
38 
39  const std::string ARM = "db (0,1)";
40  const std::string STATION = "station (1,2)";
41  const std::string PLANE = "plane (0-3)";
42  const std::string CHANNEL = "channel (0-11)";
43 } // namespace PPSTimingCalibrationPI
44 
45 /************************************************
46  History plots
47 *************************************************/
48 template <PPSTimingCalibrationPI::parameter param, class PayloadType>
49 class ParametersPerRun : public cond::payloadInspector::HistoryPlot<PayloadType, float> {
50 public:
52  : cond::payloadInspector::HistoryPlot<PayloadType, float>(
53  "Parameter " + PPSTimingCalibrationPI::getStringFromParamEnum(param) + " vs. Runs",
59  }
60 
61  float getFromPayload(PayloadType& payload) override {
63  auto db = paramValues.find(PPSTimingCalibrationPI::ARM)->second;
64  auto station = paramValues.find(PPSTimingCalibrationPI::STATION)->second;
65  auto plane = paramValues.find(PPSTimingCalibrationPI::PLANE)->second;
66  auto channel = paramValues.find(PPSTimingCalibrationPI::CHANNEL)->second;
67 
68  return payload.parameters(std::stoi(db), std::stoi(station), std::stoi(plane), std::stoi(channel))[param];
69  }
70 };
71 
72 /************************************************
73  Image plots
74 *************************************************/
75 template <PPSTimingCalibrationPI::parameter param, class PayloadType>
76 class ParametersPerChannel : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
77 public:
79  : cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV>(
80  "PPSTimingCalibration parameters per channel") {
84  }
85 
86  bool fill() override {
87  auto tag = cond::payloadInspector::PlotBase::getTag<0>();
88  auto tagname = tag.name;
89  auto iov = tag.iovs.back();
90  auto m_payload = this->fetchPayload(std::get<1>(iov));
91 
93  auto db = paramValues.find(PPSTimingCalibrationPI::ARM)->second;
94  auto station = paramValues.find(PPSTimingCalibrationPI::STATION)->second;
95  auto plane = paramValues.find(PPSTimingCalibrationPI::PLANE)->second;
96 
97  if (m_payload != nullptr) {
98  TCanvas canvas(
99  "PPSTimingCalibration parameters per channel", "PPSTimingCalibration parameters per channel", 1400, 1000);
100  canvas.cd(1);
101  canvas.SetGrid();
102  const Int_t n = 12;
103  Double_t x[n];
104  Double_t y[n];
105  for (int i = 0; i < n; i++) {
106  y[i] = m_payload->parameters(std::stoi(db), std::stoi(station), std::stoi(plane), i)[param];
107  x[i] = i;
108  }
109 
110  TGraph* graph = new TGraph(n, x, y);
111  graph->SetTitle(("PPSTimingCalibration db = " + db + ", " + "station = " + station + ", " + "plane = " + plane +
112  ", " + PPSTimingCalibrationPI::getStringFromParamEnum(param) + " PER channel; channel; " +
114  .c_str());
115  graph->SetMarkerColor(2);
116  graph->SetMarkerSize(1.5);
117  graph->SetMarkerStyle(21);
118  graph->GetXaxis()->SetRangeUser(-.5, 11.5);
119  graph->GetXaxis()->SetNdivisions(16);
120  graph->GetYaxis()->SetNdivisions(32);
121  graph->Draw("AP");
122 
124  canvas.SaveAs(fileName.c_str());
125 
126  return true;
127  } else {
128  return false;
129  }
130  }
131 };
132 
133 #endif
float getFromPayload(PayloadType &payload) override
std::string getStringFromParamEnum(const parameter &parameter)
const std::map< std::string, std::string > & inputParamValues() const
void addInputParam(const std::string &paramName)
HistoryPlot(const std::string &title, const std::string &yLabel)
def canvas(sub, attr)
Definition: svgfig.py:482
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)