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 public:
24  enum parameter { parameter0 = 0, parameter1 = 1, parameter2 = 2, parameter3 = 3 };
25 
26  enum conditions_db { db0 = 0, db1 = 1 };
27 
28  enum conditions_plane { plane0 = 0, plane1 = 1, plane2 = 2, plane3 = 3 };
29 
31  channel0 = 0,
32  channel1 = 1,
33  channel2 = 2,
34  channel3 = 3,
35  channel4 = 4,
36  channel5 = 5,
37  channel6 = 6,
38  channel7 = 7,
39  channel8 = 8,
40  channel9 = 9,
41  channel10 = 10,
42  channel11 = 11
43 
44  };
45 
47  switch (parameter) {
48  case 0:
49  return "parameter 0";
50  case 1:
51  return "parameter 1";
52  case 2:
53  return "parameter 2";
54  case 3:
55  return "parameter 3";
56 
57  default:
58  return "not here";
59  }
60  }
61 
63  switch (db) {
64  case 0:
65  return "db = 0";
66  case 1:
67  return "db = 1";
68 
69  default:
70  return "not here";
71  }
72  }
73 
75  switch (plane) {
76  case 0:
77  return "plane = 0";
78  case 1:
79  return "plane = 1";
80  case 2:
81  return "plane = 2";
82  case 3:
83  return "plane = 3";
84 
85  default:
86  return "not here";
87  }
88  }
89 
91  switch (channel) {
92  case 0:
93  return "channel = 0";
94  case 1:
95  return "channel = 1";
96  case 2:
97  return "channel = 2";
98  case 3:
99  return "channel = 3";
100  case 4:
101  return "channel = 4";
102  case 5:
103  return "channel = 5";
104  case 6:
105  return "channel = 6";
106  case 7:
107  return "channel = 7";
108  case 8:
109  return "channel = 8";
110  case 9:
111  return "channel = 9";
112  case 10:
113  return "channel = 10";
114  case 11:
115  return "channel = 11";
116 
117  default:
118  return "not here";
119  }
120  }
121 };
122 
123 /************************************************
124  History plots
125 *************************************************/
130  class PayloadType>
131 class ParametersPerRun : public cond::payloadInspector::HistoryPlot<PayloadType, float> {
132 public:
134  : cond::payloadInspector::HistoryPlot<PayloadType, float>(
136  PPSTimingCalibrationPI::getStringFromDbEnum(db) + " " +
137  PPSTimingCalibrationPI::getStringFromPlaneEnum(plane) + " " +
138  PPSTimingCalibrationPI::getStringFromChannelEnum(channel) + " vs. Runs",
140 
141  float getFromPayload(PayloadType& payload) override { return payload.parameters(db, 1, plane, channel)[param]; }
142 };
143 
144 /************************************************
145  X-Y correlation plots
146 *************************************************/
152  class PayloadType>
153 class PpPCorrelation : public cond::payloadInspector::ScatterPlot<PayloadType, double, double> {
154 public:
156  : cond::payloadInspector::ScatterPlot<PayloadType, double, double>(
157  "TimingCalibration " + PPSTimingCalibrationPI::getStringFromParamEnum(param1) + " vs. " +
159  PPSTimingCalibrationPI::getStringFromDbEnum(db) + " " +
160  PPSTimingCalibrationPI::getStringFromPlaneEnum(plane) + " " +
161  PPSTimingCalibrationPI::getStringFromChannelEnum(channel),
164 
165  std::tuple<double, double> getFromPayload(PayloadType& payload) override {
166  return std::make_tuple(payload.parameters(db, 1, plane, channel)[param1],
167  payload.parameters(db, 1, plane, channel)[param2]);
168  }
169 };
170 
171 /************************************************
172  Other plots
173 *************************************************/
177  class PayloadType>
178 class ParametersPerChannel : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
179 public:
181  : cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV>(
182  "PPSTimingCalibration parameters per channel") {}
183 
184  bool fill() override {
185  auto tag = cond::payloadInspector::PlotBase::getTag<0>();
186  auto tagname = tag.name;
187  auto iov = tag.iovs.back();
188  auto m_payload = this->fetchPayload(std::get<1>(iov));
189 
190  if (m_payload != nullptr) {
191  TCanvas canvas(
192  "PPSTimingCalibration parameters per channel", "PPSTimingCalibration parameters per channel", 1400, 1000);
193  canvas.cd(1);
194  canvas.SetGrid();
195  const Int_t n = 12;
196  Double_t x[n];
197  Double_t y[n];
198  for (int i = 0; i < n; i++) {
199  y[i] = m_payload->parameters(db, 1, plane, i)[param];
200  x[i] = i;
201  }
202 
203  TGraph* graph = new TGraph(n, x, y);
204  graph->SetTitle(("PPSTimingCalibration " + PPSTimingCalibrationPI::getStringFromDbEnum(db) + " " +
206  PPSTimingCalibrationPI::getStringFromParamEnum(param) + " per channel; channel; parameter")
207  .c_str());
208  graph->SetMarkerColor(2);
209  graph->SetMarkerSize(1.5);
210  graph->SetMarkerStyle(21);
211  graph->GetXaxis()->SetRangeUser(-.5, 11.5);
212  graph->GetXaxis()->SetNdivisions(16);
213  graph->GetYaxis()->SetNdivisions(32);
214  graph->Draw("AP");
215 
217  canvas.SaveAs(fileName.c_str());
218 
219  return true;
220  } else {
221  return false;
222  }
223  }
224 };
225 
226 #endif
static std::string getStringFromChannelEnum(const conditions_channel &channel)
ScatterPlot(const std::string &title, const std::string &xLabel, const std::string &yLabel)
static std::string getStringFromPlaneEnum(const conditions_plane &plane)
static std::string getStringFromParamEnum(const parameter &parameter)
static std::string getStringFromDbEnum(const conditions_db &db)
float getFromPayload(PayloadType &payload) override
HistoryPlot(const std::string &title, const std::string &yLabel)
std::string getStringFromParamEnum(const parameters &parameter, const bool addUnits=false)
Definition: plugin.cc:23
std::tuple< double, double > getFromPayload(PayloadType &payload) override
def canvas(sub, attr)
Definition: svgfig.py:482
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)