CMS 3D CMS Logo

EcalTimeOffsetConstant_PayloadInspector.cc
Go to the documentation of this file.
7 
8 // the data format of the condition to be inspected
10 
11 #include "TH2F.h" // a 2-D histogram with four bytes per cell (float)
12 #include "TCanvas.h"
13 #include "TLine.h"
14 #include "TStyle.h"
15 #include "TLatex.h"//write mathematical equations.
16 #include "TPave.h"
17 #include "TPaveStats.h"
18 #include <string>
19 #include <fstream>
20 
21 namespace {
22 
23 /*******************************************************
24  2d plot of Ecal Time Offset Constant of 1 IOV
25  *******************************************************/
26 class EcalTimeOffsetConstantPlot: public cond::payloadInspector::PlotImage<EcalTimeOffsetConstant>{
27  public:
28  EcalTimeOffsetConstantPlot():
29  cond::payloadInspector::PlotImage<EcalTimeOffsetConstant>("Ecal Time Offset Constant - map "){
30  setSingleIov(true);
31  }
32 
33  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs)override {
34  auto iov=iovs.front();
35  std::shared_ptr <EcalTimeOffsetConstant> payload = fetchPayload(std::get<1> (iov));
36  unsigned int run=std::get<0> (iov);
37  TH2F* align;
38  int NbRows;
39 
40  if(payload.get()){
41  NbRows=1;
42  align=new TH2F("Time Offset Constant [ns]","EB EE",2,0,2,NbRows,0,NbRows);
43  EcalTimeOffsetConstant it=(*payload);
44 
45  double row = NbRows-0.5;
46 
47  align->Fill(0.5,row,it.getEBValue());
48  align->Fill(1.5,row,it.getEEValue());
49  }else
50  return false;
51 
52  gStyle->SetPalette(1);
53  gStyle->SetOptStat(0);
54  TCanvas canvas("CC map", "CC map", 1000, 1000);
55  TLatex t1;
56  t1.SetNDC();
57  t1.SetTextAlign(26);
58  t1.SetTextSize(0.05);
59  t1.SetTextColor(2);
60  t1.DrawLatex(0.5, 0.96,Form("Ecal Time Offset Constant, IOV %i", run));
61 
62 
63  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
64  pad->Draw();
65  pad->cd();
66  align->Draw("TEXT");
67 
68  drawTable(NbRows,2);
69 
70  align->GetXaxis()->SetTickLength(0.);
71  align->GetXaxis()->SetLabelSize(0.);
72  align->GetYaxis()->SetTickLength(0.);
73  align->GetYaxis()->SetLabelSize(0.);
74 
75  std::string ImageName(m_imageFileName);
76  canvas.SaveAs(ImageName.c_str());
77 
78  return true;
79  }
80 };
81 
82 
83 /*******************************************************
84  2d plot of Ecal Time Offset Constant difference between 2 IOVs
85 *******************************************************/
86 
87 class EcalTimeOffsetConstantDiff: public cond::payloadInspector::PlotImage<EcalTimeOffsetConstant> {
88 
89 public:
90  EcalTimeOffsetConstantDiff() :
91  cond::payloadInspector::PlotImage<EcalTimeOffsetConstant>("Ecal Time Offset Constant difference") {
92  setSingleIov(false);
93  }
94 
95  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs)override {
96 
97  unsigned int run[2], irun = 0;
98  float val[2]={};
99  TH2F* align = new TH2F("", "", 1, 0., 1., 1, 0., 1.); // pseudo creation
100  int NbRows = 0;
101 
102  for (auto const & iov : iovs) {
103  std::shared_ptr < EcalTimeOffsetConstant > payload = fetchPayload(std::get < 1 > (iov));
104  run[irun] = std::get < 0 > (iov);
105 
106  if (payload.get()) {
107  NbRows = 1;
108 
109  if (irun == 1)
110  align=new TH2F("Ecal Time Offset Constant [ns]","EB EE",2,0,2,NbRows,0,NbRows);
111 
112 
113  EcalTimeOffsetConstant it=(*payload);
114  double row = NbRows - 0.5;
115 
116  if (irun == 0) {
117  val[0] = it.getEBValue();
118  val[1] = it.getEEValue();
119 
120  } else {
121  align->Fill(0.5,row,it.getEBValue()-val[0]);
122  align->Fill(1.5,row,it.getEEValue()-val[1]);
123 
124  row = row - 1.;
125  }
126 
127  } // if payload.get()
128  else
129  return false;
130 
131  irun++;
132  } // loop over IOVs
133 
134  gStyle->SetPalette(1);
135  gStyle->SetOptStat(0);
136  TCanvas canvas("CC map", "CC map", 1000, 1000);
137  TLatex t1;
138  t1.SetNDC();
139  t1.SetTextAlign(26);
140  t1.SetTextSize(0.05);
141  t1.SetTextColor(2);
142  t1.DrawLatex(0.5, 0.96,Form("Ecal Time Offset Constant, IOV %i - %i", run[1],run[0]));
143 
144  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
145  pad->Draw();
146  pad->cd();
147  align->Draw("TEXT");
148 
149  drawTable(NbRows,2);
150 
151  align->GetXaxis()->SetTickLength(0.);
152  align->GetXaxis()->SetLabelSize(0.);
153  align->GetYaxis()->SetTickLength(0.);
154  align->GetYaxis()->SetLabelSize(0.);
155 
156  std::string ImageName(m_imageFileName);
157  canvas.SaveAs(ImageName.c_str());
158 
159  return true;
160  }
161 
162 };
163 
164 } //close namespace
165 
166 // Register the classes as boost python plugin
168  PAYLOAD_INSPECTOR_CLASS(EcalTimeOffsetConstantPlot);
169  PAYLOAD_INSPECTOR_CLASS(EcalTimeOffsetConstantDiff);
170 }
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)=0
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Definition: plugin.cc:24
def canvas(sub, attr)
Definition: svgfig.py:482
void drawTable(int nbRows, int nbColumns)