CMS 3D CMS Logo

ESIntercalibConstants_PayloadInspector.cc
Go to the documentation of this file.
4 
5 // the data format of the condition to be inspected
9 
10 #include <memory>
11 #include <sstream>
12 
13 #include "TStyle.h"
14 #include "TH2F.h"
15 #include "TCanvas.h"
16 #include "TLine.h"
17 #include "TLatex.h"
18 
19 
20 namespace {
21  enum {kESChannels = 137216};
22  enum {IX_MIN = 1, IY_MIN = 1, IX_MAX = 40, IY_MAX = 40}; // endcaps lower and upper bounds on x and y
23 
24 
25  /*********************************************************
26  2d plot of ES channel status of 1 IOV
27  *********************************************************/
28  class ESIntercalibConstantsPlot : public cond::payloadInspector::PlotImage<ESIntercalibConstants> {
29 
30  public:
31  ESIntercalibConstantsPlot() : cond::payloadInspector::PlotImage<ESIntercalibConstants>("ES IntercalibConstants") {
32  setSingleIov( true );
33  }
34  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
35 
36  TH2F*** esmap = new TH2F**[2];
37  std::string title[2][2] = {{"ES+F","ES-F"},{"ES+R","ES-R"}};
38  for (int plane = 0; plane < 2; plane++) {
39  esmap[plane] = new TH2F*[2];
40  for (int side = 0; side < 2; side++)
41  esmap[plane][side] = new TH2F(Form("esmap%i%i",plane,side),title[plane][side].c_str(), IX_MAX, 0, IX_MAX, IY_MAX, 0, IY_MAX);
42  }
43  unsigned int run = 0;
44  float valmin = 999.;
45  auto iov = iovs.front();
46  std::shared_ptr<ESIntercalibConstants> payload = fetchPayload( std::get<1>(iov) );
47  run = std::get<0>(iov);
48  if( payload.get() ){
49  // looping over all the ES channels
50  for(int id = 0; id < kESChannels; id++)
51  if(ESDetId::validHashIndex(id)) {
52  ESDetId myESId = ESDetId::unhashIndex(id);
53  int side = myESId.zside(); // -1, 1
54  if(side < 0) side = 1;
55  else side = 0;
56  int plane = myESId.plane() - 1; // 1, 2
57  if(side < 0 || side > 1 || plane < 0 || plane > 1) {
58  std::cout << " channel " << id << " side " << myESId.zside() << " plane " << myESId.plane() << std::endl;
59  return false;
60  }
61  ESIntercalibConstants::const_iterator IC_it = payload->find(myESId);
62  float value = *IC_it;
63  // if(id < 64) std::cout << " channel " << id << " value " << value << std::endl;
64  if(myESId.strip() == 1) { // we get 32 times the same value, plot it only once!
65  esmap[plane][side]->Fill(myESId.six() -1, myESId.siy() -1, value);
66  if(value < valmin) valmin = value;
67  }
68  } // validHashIndex
69  } // payload
70 
71  gStyle->SetOptStat(0);
72  gStyle->SetPalette(1);
73  TCanvas canvas("CC map","CC map",1680,1320);
74  TLatex t1;
75  t1.SetNDC();
76  t1.SetTextAlign(26);
77  t1.SetTextSize(0.05);
78  t1.DrawLatex(0.5, 0.96, Form("ES Intercalib Constants, IOV %i", run));
79  t1.SetTextSize(0.025);
80 
81  float xmi[2] = {0.0, 0.5};
82  float xma[2] = {0.5, 1.0};
83  TPad*** pad = new TPad**[2];
84  for (int plane = 0; plane < 2; plane++) {
85  pad[plane] = new TPad*[2];
86  for (int side = 0; side < 2; side++) {
87  float yma = 0.94 - (0.46 * plane);
88  float ymi = yma - 0.44;
89  pad[plane][side] = new TPad(Form("p_%i_%i", plane, side),Form("p_%i_%i", plane, side),
90  xmi[side], ymi, xma[side], yma);
91  pad[plane][side]->Draw();
92  }
93  }
94 
95  int min = valmin * 10 - 1.;
96  valmin = (float)min / 10.;
97  for (int side = 0; side < 2; side++) {
98  for (int plane = 0; plane < 2; plane++) {
99  pad[plane][side]->cd();
100  esmap[plane][side]->Draw("colz1");
101  esmap[plane][side]->SetMinimum(valmin);
102  DrawES(plane, side);
103  }
104  }
105 
106  std::string ImageName(m_imageFileName);
107  canvas.SaveAs(ImageName.c_str());
108  return true;
109  }// fill method
110  };
111 
112  /************************************************************************
113  2d plot of ES channel status difference between 2 IOVs
114  ************************************************************************/
115  class ESIntercalibConstantsDiff : public cond::payloadInspector::PlotImage<ESIntercalibConstants> {
116 
117  public:
118  ESIntercalibConstantsDiff() : cond::payloadInspector::PlotImage<ESIntercalibConstants>("ES IntercalibConstants difference") {
119  setSingleIov(false);
120  }
121  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
122  TH2F*** esmap = new TH2F**[2];
123  std::string title[2][2] = {{"ES+F","ES-F"},{"ES+R","ES-R"}};
124  for (int plane = 0; plane < 2; plane++) {
125  esmap[plane] = new TH2F*[2];
126  for (int side = 0; side < 2; side++)
127  esmap[plane][side] = new TH2F(Form("esmap%i%i",plane,side),title[plane][side].c_str(), IX_MAX, 0, IX_MAX, IY_MAX, 0, IY_MAX);
128  }
129  unsigned int run[2], irun = 0;
130  float val[kESChannels], valmin = 999.;
131  for ( auto const & iov: iovs) {
132  std::shared_ptr<ESIntercalibConstants> payload = fetchPayload( std::get<1>(iov) );
133  run[irun] = std::get<0>(iov);
134  // std::cout << " irun " << irun << " IOV " << run[irun] << std::endl;
135  if( payload.get() ){
136  for(int id = 0; id < kESChannels; id++) // looping over all the ES channels
137  if(ESDetId::validHashIndex(id)) {
138  ESDetId myESId = ESDetId::unhashIndex(id);
139  // ESIntercalibConstantsCode status_it = (payload->getMap())[myESId];
140  ESIntercalibConstants::const_iterator IC_it = payload->find(myESId);
141  float value = *IC_it;
142  // int status = status_it.getStatusCode();
143  if(irun == 0)
144  val[id] = value;
145  else {
146  int side = myESId.zside(); // -1, 1
147  if(side < 0) side = 1;
148  else side = 0;
149  int plane = myESId.plane() - 1; // 1, 2
150  if(side < 0 || side > 1 || plane < 0 || plane > 1) {
151  std::cout << " channel " << id << " side " << myESId.zside() << " plane " << myESId.plane() << std::endl;
152  return false;
153  }
154  // int diff = status - stat[id];
155  int diff = value - val[id];
156  if(myESId.strip() == 1) { // we get 32 times the same value, plot it only once!
157  esmap[plane][side]->Fill(myESId.six() -1, myESId.siy() -1, diff);
158  if(diff < valmin) valmin = diff;
159  }
160  } // 2nd IOV
161  } // validHashIndex
162  } // payload
163  irun++;
164  } // loop over IOVs
165 
166  gStyle->SetOptStat(0);
167  gStyle->SetPalette(1);
168  TCanvas canvas("CC map","CC map",1680,1320);
169  TLatex t1;
170  t1.SetNDC();
171  t1.SetTextAlign(26);
172  t1.SetTextSize(0.05);
173  t1.DrawLatex(0.5, 0.96, Form("ES Intercalib Constants, IOV %i - %i", run[1], run[0]));
174  t1.SetTextSize(0.025);
175 
176  float xmi[2] = {0.0, 0.5};
177  float xma[2] = {0.5, 1.0};
178  TPad*** pad = new TPad**[2];
179  for (int plane = 0; plane < 2; plane++) {
180  pad[plane] = new TPad*[2];
181  for (int side = 0; side < 2; side++) {
182  float yma = 0.94 - (0.46 * plane);
183  float ymi = yma - 0.44;
184  pad[plane][side] = new TPad(Form("p_%i_%i", plane, side),Form("p_%i_%i", plane, side),
185  xmi[side], ymi, xma[side], yma);
186  pad[plane][side]->Draw();
187  }
188  }
189 
190  int min = valmin * 10 - 1.;
191  valmin = (float)min / 10.;
192  for (int side = 0; side < 2; side++) {
193  for (int plane = 0; plane < 2; plane++) {
194  pad[plane][side]->cd();
195  esmap[plane][side]->Draw("colz1");
196  esmap[plane][side]->SetMinimum(valmin);
197  DrawES(plane, side);
198  }
199  }
200 
201  std::string ImageName(m_imageFileName);
202  canvas.SaveAs(ImageName.c_str());
203  return true;
204  }// fill method
205  };
206 } // close namespace
207 
208 // Register the classes as boost python plugin
210  PAYLOAD_INSPECTOR_CLASS(ESIntercalibConstantsPlot);
211  PAYLOAD_INSPECTOR_CLASS(ESIntercalibConstantsDiff);
212 }
int strip() const
Definition: ESDetId.h:53
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
int six() const
Definition: ESDetId.h:49
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
int siy() const
Definition: ESDetId.h:51
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)=0
Definition: value.py:1
T min(T a, T b)
Definition: MathUtil.h:58
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
int zside() const
Definition: ESDetId.h:45
std::vector< Item >::const_iterator const_iterator
Definition: plugin.cc:24
void DrawES(int plane, int side)
Definition: ESDrawUtils.h:4
int plane() const
Definition: ESDetId.h:47
def canvas(sub, attr)
Definition: svgfig.py:481
static ESDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: ESDetId.cc:62
static bool validHashIndex(int hi)
Definition: ESDetId.h:65