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