CMS 3D CMS Logo

PfCalibration_PayloadInspector.cc
Go to the documentation of this file.
2 
6 
7 // the data format of the condition to be inspected
10 
11 #include <memory>
12 #include <sstream>
13 #include <fstream>
14 #include <iostream>
15 #include <array>
16 #include <map>
17 
18 // include ROOT
19 #include "TH2F.h"
20 #include "TF1.h"
21 #include "TLegend.h"
22 #include "TCanvas.h"
23 #include "TLine.h"
24 #include "TStyle.h"
25 #include "TLatex.h"
26 #include "TPave.h"
27 #include "TPaveStats.h"
28 
29 using namespace cond::payloadInspector;
30 
32 public:
35  }
36 };
37 
38 static std::map<PerformanceResult::ResultType, std::string> functType = {
39  {PerformanceResult::PFfa_BARREL, "PFfa_BARREL"},
40  {PerformanceResult::PFfa_ENDCAP, "PFfa_ENDCAP"},
41  {PerformanceResult::PFfb_BARREL, "PFfb_BARREL"},
42  {PerformanceResult::PFfb_ENDCAP, "PFfb_ENDCAP"},
43  {PerformanceResult::PFfc_BARREL, "PFfc_BARREL"},
44  {PerformanceResult::PFfc_ENDCAP, "PFfc_ENDCAP"},
45 
46  {PerformanceResult::PFfaEta_BARRELH, "PFfaEta_BARRELH"},
47  {PerformanceResult::PFfaEta_ENDCAPH, "PFfaEta_ENDCAPH"},
48  {PerformanceResult::PFfbEta_BARRELH, "PFfbEta_BARRELH"},
49  {PerformanceResult::PFfbEta_ENDCAPH, "PFfbEta_ENDCAPH"},
50  {PerformanceResult::PFfaEta_BARRELEH, "PFfaEta_BARRELEH"},
51  {PerformanceResult::PFfaEta_ENDCAPEH, "PFfaEta_ENDCAPEH"},
52  {PerformanceResult::PFfbEta_BARRELEH, "PFfbEta_BARRELEH"},
53  {PerformanceResult::PFfbEta_ENDCAPEH, "PFfbEta_ENDCAPEH"},
54 
55  {PerformanceResult::PFfaEta_BARREL, "PFfaEta_BARREL"},
56  {PerformanceResult::PFfaEta_ENDCAP, "PFfaEta_ENDCAP"},
57  {PerformanceResult::PFfbEta_BARREL, "PFfbEta_BARREL"},
58  {PerformanceResult::PFfbEta_ENDCAP, "PFfbEta_ENDCAP"},
59 
60  {PerformanceResult::PFfcEta_BARRELH, "PFfcEta_BARRELH"},
61  {PerformanceResult::PFfcEta_ENDCAPH, "PFfcEta_ENDCAPH"},
62  {PerformanceResult::PFfdEta_ENDCAPH, "PFfdEta_ENDCAPH"},
63  {PerformanceResult::PFfcEta_BARRELEH, "PFfcEta_BARRELEH"},
64  {PerformanceResult::PFfcEta_ENDCAPEH, "PFfcEta_ENDCAPEH"},
65  {PerformanceResult::PFfdEta_ENDCAPEH, "PFfdEta_ENDCAPEH"}};
66 
67 template <PerformanceResult::ResultType T>
68 class PfCalibration : public cond::payloadInspector::PlotImage<PerformancePayloadFromTFormula, SINGLE_IOV> {
69 public:
71  : cond::payloadInspector::PlotImage<PerformancePayloadFromTFormula, SINGLE_IOV>("Performance Payload formula") {}
72  bool fill() override {
73  auto tag = PlotBase::getTag<0>();
74  auto iov = tag.iovs.front();
75  std::string tagname = tag.name;
76  auto payload = fetchPayload(std::get<1>(iov));
77 
78  if (!payload.get())
79  return false;
80 
81  int pos = ((PerformancePayloadFromTFormulaExposed*)payload.get())->resultPos(T);
82  auto formula = payload->formulaPayload();
83  auto formula_vec = formula.formulas();
84  auto limits_vec = formula.limits();
85  if (pos < 0 || pos > (int)formula_vec.size()) {
86  edm::LogError("PfCalibration") << "Will not display image for " << functType[T]
87  << " as it's not contained in the payload!";
88  return false;
89  }
90  TCanvas canvas("PfCalibration", "PfCalibration", 1500, 800);
91  canvas.cd();
92  auto formula_string = formula_vec[pos];
93  auto limits = limits_vec[pos];
94 
95  auto function_plot = new TF1("f1", formula_string.c_str(), limits.first, limits.second);
96  function_plot->SetTitle((functType[T] + " " + formula_string).c_str());
97  function_plot->GetXaxis()->SetTitle("GeV");
98  function_plot->Draw("");
99 
100  std::string fileName(m_imageFileName);
101  canvas.SaveAs(fileName.c_str());
102 
103  return true;
104  }
105 };
106 
107 // Register the classes as boost python plugin
115 
124 
129 
136 }
virtual int resultPos(PerformanceResult::ResultType r) const
Log< level::Error, false > LogError
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
int resultPos(PerformanceResult::ResultType rt) const override
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
def canvas(sub, attr)
Definition: svgfig.py:482
long double T
static std::map< PerformanceResult::ResultType, std::string > functType