File indexing completed on 2024-04-06 12:01:43
0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002
0003 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0004 #include "CondCore/Utilities/interface/PayloadInspector.h"
0005 #include "CondCore/CondDB/interface/Time.h"
0006
0007
0008 #include "CondFormats/PhysicsToolsObjects/interface/PerformancePayloadFromTFormula.h"
0009 #include "CondFormats/DataRecord/interface/PFCalibrationRcd.h"
0010
0011 #include <memory>
0012 #include <sstream>
0013 #include <fstream>
0014 #include <iostream>
0015 #include <array>
0016 #include <map>
0017
0018
0019 #include "TH2F.h"
0020 #include "TF1.h"
0021 #include "TLegend.h"
0022 #include "TCanvas.h"
0023 #include "TLine.h"
0024 #include "TStyle.h"
0025 #include "TLatex.h"
0026 #include "TPave.h"
0027 #include "TPaveStats.h"
0028
0029 using namespace cond::payloadInspector;
0030
0031 class PerformancePayloadFromTFormulaExposed : public PerformancePayloadFromTFormula {
0032 public:
0033 int resultPos(PerformanceResult::ResultType rt) const override {
0034 return PerformancePayloadFromTFormula::resultPos(rt);
0035 }
0036 };
0037
0038 static std::map<PerformanceResult::ResultType, std::string> functType = {
0039 {PerformanceResult::PFfa_BARREL, "PFfa_BARREL"},
0040 {PerformanceResult::PFfa_ENDCAP, "PFfa_ENDCAP"},
0041 {PerformanceResult::PFfb_BARREL, "PFfb_BARREL"},
0042 {PerformanceResult::PFfb_ENDCAP, "PFfb_ENDCAP"},
0043 {PerformanceResult::PFfc_BARREL, "PFfc_BARREL"},
0044 {PerformanceResult::PFfc_ENDCAP, "PFfc_ENDCAP"},
0045
0046 {PerformanceResult::PFfaEta_BARRELH, "PFfaEta_BARRELH"},
0047 {PerformanceResult::PFfaEta_ENDCAPH, "PFfaEta_ENDCAPH"},
0048 {PerformanceResult::PFfbEta_BARRELH, "PFfbEta_BARRELH"},
0049 {PerformanceResult::PFfbEta_ENDCAPH, "PFfbEta_ENDCAPH"},
0050 {PerformanceResult::PFfaEta_BARRELEH, "PFfaEta_BARRELEH"},
0051 {PerformanceResult::PFfaEta_ENDCAPEH, "PFfaEta_ENDCAPEH"},
0052 {PerformanceResult::PFfbEta_BARRELEH, "PFfbEta_BARRELEH"},
0053 {PerformanceResult::PFfbEta_ENDCAPEH, "PFfbEta_ENDCAPEH"},
0054
0055 {PerformanceResult::PFfaEta_BARREL, "PFfaEta_BARREL"},
0056 {PerformanceResult::PFfaEta_ENDCAP, "PFfaEta_ENDCAP"},
0057 {PerformanceResult::PFfbEta_BARREL, "PFfbEta_BARREL"},
0058 {PerformanceResult::PFfbEta_ENDCAP, "PFfbEta_ENDCAP"},
0059
0060 {PerformanceResult::PFfcEta_BARRELH, "PFfcEta_BARRELH"},
0061 {PerformanceResult::PFfcEta_ENDCAPH, "PFfcEta_ENDCAPH"},
0062 {PerformanceResult::PFfdEta_ENDCAPH, "PFfdEta_ENDCAPH"},
0063 {PerformanceResult::PFfcEta_BARRELEH, "PFfcEta_BARRELEH"},
0064 {PerformanceResult::PFfcEta_ENDCAPEH, "PFfcEta_ENDCAPEH"},
0065 {PerformanceResult::PFfdEta_ENDCAPEH, "PFfdEta_ENDCAPEH"}};
0066
0067 template <PerformanceResult::ResultType T>
0068 class PfCalibration : public cond::payloadInspector::PlotImage<PerformancePayloadFromTFormula, SINGLE_IOV> {
0069 public:
0070 PfCalibration()
0071 : cond::payloadInspector::PlotImage<PerformancePayloadFromTFormula, SINGLE_IOV>("Performance Payload formula") {}
0072 bool fill() override {
0073 auto tag = PlotBase::getTag<0>();
0074 auto iov = tag.iovs.front();
0075 std::string tagname = tag.name;
0076 auto payload = fetchPayload(std::get<1>(iov));
0077
0078 if (!payload.get())
0079 return false;
0080
0081 int pos = ((PerformancePayloadFromTFormulaExposed*)payload.get())->resultPos(T);
0082 auto formula = payload->formulaPayload();
0083 auto formula_vec = formula.formulas();
0084 auto limits_vec = formula.limits();
0085 if (pos < 0 || pos > (int)formula_vec.size()) {
0086 edm::LogError("PfCalibration") << "Will not display image for " << functType[T]
0087 << " as it's not contained in the payload!";
0088 return false;
0089 }
0090 TCanvas canvas("PfCalibration", "PfCalibration", 1500, 800);
0091 canvas.cd();
0092 auto formula_string = formula_vec[pos];
0093 auto limits = limits_vec[pos];
0094
0095 auto function_plot = new TF1("f1", formula_string.c_str(), limits.first, limits.second);
0096 function_plot->SetTitle((functType[T] + " " + formula_string).c_str());
0097 function_plot->GetXaxis()->SetTitle("GeV");
0098 function_plot->Draw("");
0099
0100 std::string fileName(m_imageFileName);
0101 canvas.SaveAs(fileName.c_str());
0102
0103 return true;
0104 }
0105 };
0106
0107
0108 PAYLOAD_INSPECTOR_MODULE(PerformancePayloadFromTFormula) {
0109 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfa_BARREL>);
0110 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfa_ENDCAP>);
0111 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfb_BARREL>);
0112 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfb_ENDCAP>);
0113 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfc_BARREL>);
0114 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfc_ENDCAP>);
0115
0116 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfaEta_BARRELH>);
0117 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfaEta_ENDCAPH>);
0118 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfbEta_BARRELH>);
0119 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfbEta_ENDCAPH>);
0120 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfaEta_BARRELEH>);
0121 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfaEta_ENDCAPEH>);
0122 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfbEta_BARRELEH>);
0123 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfbEta_ENDCAPEH>);
0124
0125 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfaEta_BARREL>);
0126 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfaEta_ENDCAP>);
0127 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfbEta_BARREL>);
0128 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfbEta_ENDCAP>);
0129
0130 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfcEta_BARRELH>);
0131 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfcEta_ENDCAPH>);
0132 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfdEta_ENDCAPH>);
0133 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfcEta_BARRELEH>);
0134 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfcEta_ENDCAPEH>);
0135 PAYLOAD_INSPECTOR_CLASS(PfCalibration<PerformanceResult::PFfdEta_ENDCAPEH>);
0136 }