File indexing completed on 2024-04-06 12:01:31
0001 #ifndef CONDCORE_CTPPSPLUGINS_PPSTIMINGCALIBRATIONPAYLOADINSPECTORHELPER_H
0002 #define CONDCORE_CTPPSPLUGINS_PPSTIMINGCALIBRATIONPAYLOADINSPECTORHELPER_H
0003
0004
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0007 #include "CondCore/Utilities/interface/PayloadInspector.h"
0008 #include "CondCore/CondDB/interface/Time.h"
0009 #include "CondFormats/PPSObjects/interface/PPSTimingCalibration.h"
0010
0011
0012 #include <memory>
0013 #include <sstream>
0014
0015
0016 #include "TCanvas.h"
0017 #include "TStyle.h"
0018 #include "TH2F.h"
0019 #include "TLatex.h"
0020 #include "TGraph.h"
0021
0022 namespace PPSTimingCalibrationPI {
0023 enum parameter { parameter0 = 0, parameter1 = 1, parameter2 = 2, parameter3 = 3 };
0024
0025 inline std::string getStringFromParamEnum(const parameter& parameter) {
0026 const std::map<int, std::string> parameters = {{parameter0, "parameter 0"},
0027 {parameter1, "parameter 1"},
0028 {parameter2, "parameter 2"},
0029 {parameter3, "parameter 3"}};
0030
0031 auto it = parameters.find(parameter);
0032 if (it != parameters.end()) {
0033 return it->second;
0034 } else {
0035 return "no param";
0036 }
0037 }
0038
0039 const std::string ARM = "db (0,1)";
0040 const std::string STATION = "station (1,2)";
0041 const std::string PLANE = "plane (0-3)";
0042 const std::string CHANNEL = "channel (0-11)";
0043 }
0044
0045
0046
0047
0048 template <PPSTimingCalibrationPI::parameter param, class PayloadType>
0049 class ParametersPerRun : public cond::payloadInspector::HistoryPlot<PayloadType, float> {
0050 public:
0051 ParametersPerRun()
0052 : cond::payloadInspector::HistoryPlot<PayloadType, float>(
0053 "Parameter " + PPSTimingCalibrationPI::getStringFromParamEnum(param) + " vs. Runs",
0054 PPSTimingCalibrationPI::getStringFromParamEnum(param)) {
0055 cond::payloadInspector::PlotBase::addInputParam(PPSTimingCalibrationPI::ARM);
0056 cond::payloadInspector::PlotBase::addInputParam(PPSTimingCalibrationPI::STATION);
0057 cond::payloadInspector::PlotBase::addInputParam(PPSTimingCalibrationPI::PLANE);
0058 cond::payloadInspector::PlotBase::addInputParam(PPSTimingCalibrationPI::CHANNEL);
0059 }
0060
0061 float getFromPayload(PayloadType& payload) override {
0062 auto paramValues = cond::payloadInspector::PlotBase::inputParamValues();
0063 auto db = paramValues.find(PPSTimingCalibrationPI::ARM)->second;
0064 auto station = paramValues.find(PPSTimingCalibrationPI::STATION)->second;
0065 auto plane = paramValues.find(PPSTimingCalibrationPI::PLANE)->second;
0066 auto channel = paramValues.find(PPSTimingCalibrationPI::CHANNEL)->second;
0067
0068 return payload.parameters(std::stoi(db), std::stoi(station), std::stoi(plane), std::stoi(channel))[param];
0069 }
0070 };
0071
0072
0073
0074
0075 template <PPSTimingCalibrationPI::parameter param, class PayloadType>
0076 class ParametersPerChannel : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
0077 public:
0078 ParametersPerChannel()
0079 : cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV>(
0080 "PPSTimingCalibration parameters per channel") {
0081 cond::payloadInspector::PlotBase::addInputParam(PPSTimingCalibrationPI::ARM);
0082 cond::payloadInspector::PlotBase::addInputParam(PPSTimingCalibrationPI::STATION);
0083 cond::payloadInspector::PlotBase::addInputParam(PPSTimingCalibrationPI::PLANE);
0084 }
0085
0086 bool fill() override {
0087 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
0088 auto tagname = tag.name;
0089 auto iov = tag.iovs.back();
0090 auto m_payload = this->fetchPayload(std::get<1>(iov));
0091
0092 auto paramValues = cond::payloadInspector::PlotBase::inputParamValues();
0093 auto db = paramValues.find(PPSTimingCalibrationPI::ARM)->second;
0094 auto station = paramValues.find(PPSTimingCalibrationPI::STATION)->second;
0095 auto plane = paramValues.find(PPSTimingCalibrationPI::PLANE)->second;
0096
0097 if (m_payload != nullptr) {
0098 TCanvas canvas(
0099 "PPSTimingCalibration parameters per channel", "PPSTimingCalibration parameters per channel", 1400, 1000);
0100 canvas.cd(1);
0101 canvas.SetGrid();
0102 const Int_t n = 12;
0103 Double_t x[n];
0104 Double_t y[n];
0105 for (int i = 0; i < n; i++) {
0106 y[i] = m_payload->parameters(std::stoi(db), std::stoi(station), std::stoi(plane), i)[param];
0107 x[i] = i;
0108 }
0109
0110 TGraph* graph = new TGraph(n, x, y);
0111 graph->SetTitle(("PPSTimingCalibration db = " + db + ", " + "station = " + station + ", " + "plane = " + plane +
0112 ", " + PPSTimingCalibrationPI::getStringFromParamEnum(param) + " PER channel; channel; " +
0113 PPSTimingCalibrationPI::getStringFromParamEnum(param))
0114 .c_str());
0115 graph->SetMarkerColor(2);
0116 graph->SetMarkerSize(1.5);
0117 graph->SetMarkerStyle(21);
0118 graph->GetXaxis()->SetRangeUser(-.5, 11.5);
0119 graph->GetXaxis()->SetNdivisions(16);
0120 graph->GetYaxis()->SetNdivisions(32);
0121 graph->Draw("AP");
0122
0123 std::string fileName(this->m_imageFileName);
0124 canvas.SaveAs(fileName.c_str());
0125
0126 return true;
0127 } else {
0128 return false;
0129 }
0130 }
0131 };
0132
0133 #endif