Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-12 01:59:34

0001 #ifndef CONDCORE_CTPPSPLUGINS_PPSTIMINGCALIBRATIONPAYLOADINSPECTORHELPER_H
0002 #define CONDCORE_CTPPSPLUGINS_PPSTIMINGCALIBRATIONPAYLOADINSPECTORHELPER_H
0003 
0004 // User includes
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 // system includes
0012 #include <memory>
0013 #include <sstream>
0014 
0015 // ROOT includes
0016 #include "TCanvas.h"
0017 #include "TStyle.h"
0018 #include "TH2F.h"
0019 #include "TLatex.h"
0020 #include "TGraph.h"
0021 
0022 class PPSTimingCalibrationPI {
0023 public:
0024   enum parameter { parameter0 = 0, parameter1 = 1, parameter2 = 2, parameter3 = 3 };
0025 
0026   enum conditions_db { db0 = 0, db1 = 1 };
0027 
0028   enum conditions_plane { plane0 = 0, plane1 = 1, plane2 = 2, plane3 = 3 };
0029 
0030   enum conditions_channel {
0031     channel0 = 0,
0032     channel1 = 1,
0033     channel2 = 2,
0034     channel3 = 3,
0035     channel4 = 4,
0036     channel5 = 5,
0037     channel6 = 6,
0038     channel7 = 7,
0039     channel8 = 8,
0040     channel9 = 9,
0041     channel10 = 10,
0042     channel11 = 11
0043 
0044   };
0045 
0046   static std::string getStringFromParamEnum(const parameter& parameter) {
0047     switch (parameter) {
0048       case 0:
0049         return "parameter 0";
0050       case 1:
0051         return "parameter 1";
0052       case 2:
0053         return "parameter 2";
0054       case 3:
0055         return "parameter 3";
0056 
0057       default:
0058         return "not here";
0059     }
0060   }
0061 
0062   static std::string getStringFromDbEnum(const conditions_db& db) {
0063     switch (db) {
0064       case 0:
0065         return "db = 0";
0066       case 1:
0067         return "db = 1";
0068 
0069       default:
0070         return "not here";
0071     }
0072   }
0073 
0074   static std::string getStringFromPlaneEnum(const conditions_plane& plane) {
0075     switch (plane) {
0076       case 0:
0077         return "plane = 0";
0078       case 1:
0079         return "plane = 1";
0080       case 2:
0081         return "plane = 2";
0082       case 3:
0083         return "plane = 3";
0084 
0085       default:
0086         return "not here";
0087     }
0088   }
0089 
0090   static std::string getStringFromChannelEnum(const conditions_channel& channel) {
0091     switch (channel) {
0092       case 0:
0093         return "channel = 0";
0094       case 1:
0095         return "channel = 1";
0096       case 2:
0097         return "channel = 2";
0098       case 3:
0099         return "channel = 3";
0100       case 4:
0101         return "channel = 4";
0102       case 5:
0103         return "channel = 5";
0104       case 6:
0105         return "channel = 6";
0106       case 7:
0107         return "channel = 7";
0108       case 8:
0109         return "channel = 8";
0110       case 9:
0111         return "channel = 9";
0112       case 10:
0113         return "channel = 10";
0114       case 11:
0115         return "channel = 11";
0116 
0117       default:
0118         return "not here";
0119     }
0120   }
0121 };
0122 
0123 /************************************************
0124     History plots
0125 *************************************************/
0126 template <PPSTimingCalibrationPI::conditions_db db,
0127           PPSTimingCalibrationPI::conditions_plane plane,
0128           PPSTimingCalibrationPI::conditions_channel channel,
0129           PPSTimingCalibrationPI::parameter param,
0130           class PayloadType>
0131 class ParametersPerRun : public cond::payloadInspector::HistoryPlot<PayloadType, float> {
0132 public:
0133   ParametersPerRun()
0134       : cond::payloadInspector::HistoryPlot<PayloadType, float>(
0135             PPSTimingCalibrationPI::getStringFromParamEnum(param) + " " +
0136                 PPSTimingCalibrationPI::getStringFromDbEnum(db) + " " +
0137                 PPSTimingCalibrationPI::getStringFromPlaneEnum(plane) + " " +
0138                 PPSTimingCalibrationPI::getStringFromChannelEnum(channel) + " vs. Runs",
0139             PPSTimingCalibrationPI::getStringFromParamEnum(param)) {}
0140 
0141   float getFromPayload(PayloadType& payload) override { return payload.parameters(db, 1, plane, channel)[param]; }
0142 };
0143 
0144 /************************************************
0145     X-Y correlation plots
0146 *************************************************/
0147 template <PPSTimingCalibrationPI::conditions_db db,
0148           PPSTimingCalibrationPI::conditions_plane plane,
0149           PPSTimingCalibrationPI::conditions_channel channel,
0150           PPSTimingCalibrationPI::parameter param1,
0151           PPSTimingCalibrationPI::parameter param2,
0152           class PayloadType>
0153 class PpPCorrelation : public cond::payloadInspector::ScatterPlot<PayloadType, double, double> {
0154 public:
0155   PpPCorrelation()
0156       : cond::payloadInspector::ScatterPlot<PayloadType, double, double>(
0157             "TimingCalibration " + PPSTimingCalibrationPI::getStringFromParamEnum(param1) + " vs. " +
0158                 PPSTimingCalibrationPI::getStringFromParamEnum(param2) + " on " +
0159                 PPSTimingCalibrationPI::getStringFromDbEnum(db) + " " +
0160                 PPSTimingCalibrationPI::getStringFromPlaneEnum(plane) + " " +
0161                 PPSTimingCalibrationPI::getStringFromChannelEnum(channel),
0162             PPSTimingCalibrationPI::getStringFromParamEnum(param1),
0163             PPSTimingCalibrationPI::getStringFromParamEnum(param2)) {}
0164 
0165   std::tuple<double, double> getFromPayload(PayloadType& payload) override {
0166     return std::make_tuple(payload.parameters(db, 1, plane, channel)[param1],
0167                            payload.parameters(db, 1, plane, channel)[param2]);
0168   }
0169 };
0170 
0171 /************************************************
0172     Other plots
0173 *************************************************/
0174 template <PPSTimingCalibrationPI::conditions_db db,
0175           PPSTimingCalibrationPI::conditions_plane plane,
0176           PPSTimingCalibrationPI::parameter param,
0177           class PayloadType>
0178 class ParametersPerChannel : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
0179 public:
0180   ParametersPerChannel()
0181       : cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV>(
0182             "PPSTimingCalibration parameters per channel") {}
0183 
0184   bool fill() override {
0185     auto tag = cond::payloadInspector::PlotBase::getTag<0>();
0186     auto tagname = tag.name;
0187     auto iov = tag.iovs.back();
0188     auto m_payload = this->fetchPayload(std::get<1>(iov));
0189 
0190     if (m_payload != nullptr) {
0191       TCanvas canvas(
0192           "PPSTimingCalibration parameters per channel", "PPSTimingCalibration parameters per channel", 1400, 1000);
0193       canvas.cd(1);
0194       canvas.SetGrid();
0195       const Int_t n = 12;
0196       Double_t x[n];
0197       Double_t y[n];
0198       for (int i = 0; i < n; i++) {
0199         y[i] = m_payload->parameters(db, 1, plane, i)[param];
0200         x[i] = i;
0201       }
0202 
0203       TGraph* graph = new TGraph(n, x, y);
0204       graph->SetTitle(("PPSTimingCalibration " + PPSTimingCalibrationPI::getStringFromDbEnum(db) + " " +
0205                        PPSTimingCalibrationPI::getStringFromPlaneEnum(plane) + " " +
0206                        PPSTimingCalibrationPI::getStringFromParamEnum(param) + " per channel; channel; parameter")
0207                           .c_str());
0208       graph->SetMarkerColor(2);
0209       graph->SetMarkerSize(1.5);
0210       graph->SetMarkerStyle(21);
0211       graph->GetXaxis()->SetRangeUser(-.5, 11.5);
0212       graph->GetXaxis()->SetNdivisions(16);
0213       graph->GetYaxis()->SetNdivisions(32);
0214       graph->Draw("AP");
0215 
0216       std::string fileName(this->m_imageFileName);
0217       canvas.SaveAs(fileName.c_str());
0218 
0219       return true;
0220     } else {
0221       return false;
0222     }
0223   }
0224 };
0225 
0226 #endif