CMS 3D CMS Logo

SiStripConfObject_PayloadInspector.cc
Go to the documentation of this file.
1 
12 
13 // the data format of the condition to be inspected
19 
20 // helper function
22 
23 #include <memory>
24 #include <sstream>
25 #include <iostream>
26 #include <regex>
27 
28 // include ROOT
29 #include "TH2F.h"
30 #include "TF1.h"
31 #include "TLegend.h"
32 #include "TCanvas.h"
33 #include "TLine.h"
34 #include "TStyle.h"
35 #include "TLatex.h"
36 
37 namespace {
38 
39  using namespace cond::payloadInspector;
40 
41  // test class
42  class SiStripConfObjectTest : public Histogram1D<SiStripConfObject, SINGLE_IOV> {
43  public:
44  SiStripConfObjectTest()
46  "SiStrip Configuration Object test", "SiStrip Configuration Object test", 1, 0.0, 1.0) {}
47 
48  bool fill() override {
49  auto tag = PlotBase::getTag<0>();
50  for (auto const& iov : tag.iovs) {
51  std::shared_ptr<SiStripConfObject> payload = Base::fetchPayload(std::get<1>(iov));
52  if (payload.get()) {
53  fillWithValue(1.);
54 
55  std::stringstream ss;
56  ss << "Summary of strips configuration object:" << std::endl;
57 
58  SiStripConfObject::parMap::const_iterator it = payload->parameters.begin();
59  for (; it != payload->parameters.end(); ++it) {
60  ss << "parameter name = " << it->first << " value = " << it->second << std::endl;
61  }
62 
63  std::cout << ss.str() << std::endl;
64 
65  } // payload
66  } // iovs
67  return true;
68  } // fill
69  };
70 
71  // display class
72  class SiStripConfObjectDisplay : public PlotImage<SiStripConfObject, SINGLE_IOV> {
73  public:
74  SiStripConfObjectDisplay() : PlotImage<SiStripConfObject, SINGLE_IOV>("Display Configuration Values") {}
75 
76  bool fill() override {
77  auto tag = PlotBase::getTag<0>();
78  auto iov = tag.iovs.front();
79  std::shared_ptr<SiStripConfObject> payload = fetchPayload(std::get<1>(iov));
80 
81  unsigned int run = std::get<0>(iov);
82  std::vector<float> y_line;
83 
84  TLatex t1;
85  t1.SetNDC();
86  t1.SetTextAlign(26);
87  t1.SetTextSize(0.045);
88  t1.SetTextColor(2);
89 
90  TLatex latex;
91  latex.SetNDC();
92  latex.SetTextSize(0.035);
93 
94  unsigned int configsize_ = payload->parameters.size();
95  TLine lines[configsize_ + 1];
96 
97  auto h_Config = std::make_unique<TH1F>("ConfigParamter", ";;configuration value", configsize_, 0., configsize_);
98  h_Config->SetStats(false);
99 
100  bool isShiftAndXTalk = payload->isParameter("shift_IB1Deco");
101 
102  // different canvases for for different types of conditions
103  int c_width = isShiftAndXTalk ? 2000 : 1000;
104  int c_height = isShiftAndXTalk ? 1000 : 800;
105 
106  TCanvas canvas("Configuration Summary", "Configuration Summary", c_width, c_height);
107  canvas.cd();
108 
109  // if its for APV phase offsets
110  if (!isShiftAndXTalk) {
111  t1.DrawLatex(0.5, 0.96, Form("SiStrip ConfObject, IOV %i", run));
112  latex.DrawLatex(0.1, 0.92, "Parameter");
113  latex.DrawLatex(0.6, 0.92, "Value");
114  y_line.push_back(0.92);
115  latex.SetTextFont(42);
116  latex.SetTextColor(kBlack);
117 
118  SiStripConfObject::parMap::const_iterator it = payload->parameters.begin();
119  unsigned int count = 0;
120  for (; it != payload->parameters.end(); ++it) {
121  count++;
122  float y_loc = 0.92 - (0.90 / configsize_) * count;
123  latex.SetTextSize(std::min(0.035, 0.95 / configsize_));
124  latex.DrawLatex(0.1, y_loc, (it->first).c_str());
125  latex.DrawLatex(0.6, y_loc, (it->second).c_str());
126  y_line.push_back(y_loc);
127  }
128 
129  unsigned int iL = 0;
130  for (const auto& line : y_line) {
131  lines[iL] = TLine(gPad->GetUxmin(), line, gPad->GetUxmax(), line);
132  lines[iL].SetLineWidth(1);
133  lines[iL].SetLineStyle(9);
134  lines[iL].SetLineColor(2);
135  lines[iL].Draw("same");
136  iL++;
137  }
138 
139  }
140  // if it's for shifts and cross-talk
141  else {
142  canvas.SetBottomMargin(0.16);
143  canvas.SetLeftMargin(0.08);
144  canvas.SetRightMargin(0.02);
145  canvas.SetTopMargin(0.05);
146  canvas.Modified();
147 
148  SiStripConfObject::parMap::const_iterator it = payload->parameters.begin();
149 
150  unsigned int count = 0;
151  for (; it != payload->parameters.end(); ++it) {
152  count++;
153 
154  h_Config->SetBinContent(count, std::stof(it->second));
155  h_Config->GetXaxis()->SetBinLabel(count, (std::regex_replace(it->first, std::regex("_"), " ")).c_str());
156  }
157 
158  SiStripPI::makeNicePlotStyle(h_Config.get());
159  h_Config->GetYaxis()->SetTitleOffset(0.8);
160  h_Config->GetXaxis()->SetLabelSize(0.03);
161  h_Config->SetMaximum(h_Config->GetMaximum() * 1.20);
162  h_Config->SetFillColorAlpha(kRed, 0.35);
163  h_Config->Draw();
164  h_Config->Draw("textsame");
165 
166  t1.DrawLatex(0.5, 0.96, Form("SiStrip ConfObject, IOV %i: Payload %s", run, (std::get<1>(iov)).c_str()));
167  }
168 
169  std::string fileName(m_imageFileName);
170  canvas.SaveAs(fileName.c_str());
171 
172  return true;
173  }
174  };
175 
176 } // namespace
177 
179  PAYLOAD_INSPECTOR_CLASS(SiStripConfObjectTest);
180  PAYLOAD_INSPECTOR_CLASS(SiStripConfObjectDisplay);
181 }
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
void makeNicePlotStyle(TH1 *hist)
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
def canvas(sub, attr)
Definition: svgfig.py:482