CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EcalTPGPedestals_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"
12 #include "TCanvas.h"
13 #include "TLine.h"
14 #include "TStyle.h"
15 #include "TLatex.h"
16 #include "TPave.h"
17 #include "TPaveStats.h"
18 #include <string>
19 #include <fstream>
20 
21 namespace {
22  enum { kEBChannels = 61200, kEEChannels = 14648, kGains = 3, kSides = 2 };
23  enum { MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 85, MAX_IPHI = 360 }; // barrel lower and upper bounds on eta and phi
24  enum { IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100 }; // endcaps lower and upper bounds on x and y
25  int gainValues[kGains] = {12, 6, 1};
26 
27  /**************************************************
28  2d plot of ECAL TPGPedestals of 1 IOV
29  **************************************************/
30  class EcalTPGPedestalsPlot : public cond::payloadInspector::PlotImage<EcalTPGPedestals> {
31  public:
32  EcalTPGPedestalsPlot() : cond::payloadInspector::PlotImage<EcalTPGPedestals>("ECAL Gain Ratios - map ") {
33  setSingleIov(true);
34  }
35 
36  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
37  TH2F** barrel_m = new TH2F*[kGains];
38  TH2F** endc_p_m = new TH2F*[kGains];
39  TH2F** endc_m_m = new TH2F*[kGains];
40  float mEBmin[kGains], mEEmin[kGains], mEBmax[kGains], mEEmax[kGains];
41  for (int gainId = 0; gainId < kGains; gainId++) {
42  barrel_m[gainId] = new TH2F(Form("EBm%i", gainId),
43  Form("EB mean_x%i ", gainValues[gainId]),
44  MAX_IPHI,
45  0,
46  MAX_IPHI,
47  2 * MAX_IETA,
48  -MAX_IETA,
49  MAX_IETA);
50  endc_p_m[gainId] = new TH2F(Form("EE+m%i", gainId),
51  Form("EE+ mean_x%i", gainValues[gainId]),
52  IX_MAX,
53  IX_MIN,
54  IX_MAX + 1,
55  IY_MAX,
56  IY_MIN,
57  IY_MAX + 1);
58  endc_m_m[gainId] = new TH2F(Form("EE-m%i", gainId),
59  Form("EE- mean_x%i", gainValues[gainId]),
60  IX_MAX,
61  IX_MIN,
62  IX_MAX + 1,
63  IY_MAX,
64  IY_MIN,
65  IY_MAX + 1);
66  mEBmin[gainId] = 10.;
67  mEEmin[gainId] = 10.;
68  mEBmax[gainId] = -10.;
69  mEEmax[gainId] = -10.;
70  }
71 
72  // std::ofstream fout;
73  // fout.open("./bid.txt");
74  auto iov = iovs.front();
75  std::shared_ptr<EcalTPGPedestals> payload = fetchPayload(std::get<1>(iov));
76  unsigned int run = std::get<0>(iov);
77  if (payload.get()) {
78  for (int sign = 0; sign < kSides; sign++) {
79  int thesign = sign == 1 ? 1 : -1;
80 
81  for (int ieta = 0; ieta < MAX_IETA; ieta++) {
82  for (int iphi = 0; iphi < MAX_IPHI; iphi++) {
83  EBDetId id((ieta + 1) * thesign, iphi + 1);
84  float y = -1 - ieta;
85  if (sign == 1)
86  y = ieta;
87  float val = (*payload)[id.rawId()].mean_x12;
88  barrel_m[0]->Fill(iphi, y, val);
89  if (val < mEBmin[0])
90  mEBmin[0] = val;
91  if (val > mEBmax[0])
92  mEBmax[0] = val;
93  val = (*payload)[id.rawId()].mean_x6;
94  barrel_m[1]->Fill(iphi, y, val);
95  if (val < mEBmin[1])
96  mEBmin[1] = val;
97  if (val > mEBmax[1])
98  mEBmax[1] = val;
99  val = (*payload)[id.rawId()].mean_x1;
100  barrel_m[2]->Fill(iphi, y, val);
101  if (val < mEBmin[2])
102  mEBmin[2] = val;
103  if (val > mEBmax[2])
104  mEBmax[2] = val;
105  } // iphi
106  } // ieta
107 
108  for (int ix = 0; ix < IX_MAX; ix++) {
109  for (int iy = 0; iy < IY_MAX; iy++) {
110  if (!EEDetId::validDetId(ix + 1, iy + 1, thesign))
111  continue;
112  EEDetId id(ix + 1, iy + 1, thesign);
113  float val = (*payload)[id.rawId()].mean_x12;
114  if (thesign == 1)
115  endc_p_m[0]->Fill(ix + 1, iy + 1, val);
116  else
117  endc_m_m[0]->Fill(ix + 1, iy + 1, val);
118  if (val < mEEmin[0])
119  mEEmin[0] = val;
120  if (val > mEEmax[0])
121  mEEmax[0] = val;
122  val = (*payload)[id.rawId()].mean_x6;
123  if (thesign == 1)
124  endc_p_m[1]->Fill(ix + 1, iy + 1, val);
125  else
126  endc_m_m[1]->Fill(ix + 1, iy + 1, val);
127  if (val < mEEmin[1])
128  mEEmin[1] = val;
129  if (val > mEEmax[1])
130  mEEmax[1] = val;
131  val = (*payload)[id.rawId()].mean_x1;
132  if (thesign == 1)
133  endc_p_m[2]->Fill(ix + 1, iy + 1, val);
134  else
135  endc_m_m[2]->Fill(ix + 1, iy + 1, val);
136  if (val < mEEmin[2])
137  mEEmin[2] = val;
138  if (val > mEEmax[2])
139  mEEmax[2] = val;
140  // fout << " x " << ix << " y " << " val " << val << std::endl;
141  } // iy
142  } // ix
143  } // side
144  } // if payload.get()
145  else
146  return false;
147  // std::cout << " min " << rEEmin[2] << " max " << rEEmax[2] << std::endl;
148  // fout.close();
149 
150  gStyle->SetPalette(1);
151  gStyle->SetOptStat(0);
152  TCanvas canvas("CC map", "CC map", 1200, 900);
153  TLatex t1;
154  t1.SetNDC();
155  t1.SetTextAlign(26);
156  t1.SetTextSize(0.05);
157  t1.DrawLatex(0.5, 0.96, Form("Ecal Gain TPGPedestals, IOV %i", run));
158 
159  float xmi[3] = {0.0, 0.22, 0.78};
160  float xma[3] = {0.22, 0.78, 1.00};
161  TPad*** pad = new TPad**[kGains];
162  for (int gId = 0; gId < kGains; gId++) {
163  pad[gId] = new TPad*[3];
164  for (int obj = 0; obj < 3; obj++) {
165  float yma = 0.94 - (0.32 * gId);
166  float ymi = yma - 0.30;
167  pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId), Form("p_%i_%i", obj, gId), xmi[obj], ymi, xma[obj], yma);
168  pad[gId][obj]->Draw();
169  }
170  }
171 
172  for (int gId = 0; gId < kGains; gId++) {
173  pad[gId][0]->cd();
174  DrawEE(endc_m_m[gId], mEEmin[gId], mEEmax[gId]);
175  pad[gId][1]->cd();
176  DrawEB(barrel_m[gId], mEBmin[gId], mEBmax[gId]);
177  pad[gId][2]->cd();
178  DrawEE(endc_p_m[gId], mEEmin[gId], mEEmax[gId]);
179  }
180 
181  std::string ImageName(m_imageFileName);
182  canvas.SaveAs(ImageName.c_str());
183  return true;
184  } // fill method
185  };
186 
187  /******************************************************************
188  2d plot of ECAL TPGPedestals difference between 2 IOVs
189  ******************************************************************/
190  template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags, int method>
191  class EcalTPGPedestalsBase : public cond::payloadInspector::PlotImage<EcalTPGPedestals, nIOVs, ntags> {
192  public:
193  EcalTPGPedestalsBase()
194  : cond::payloadInspector::PlotImage<EcalTPGPedestals, nIOVs, ntags>("ECAL Gain Ratios comparison") {}
195  bool fill() override {
196  TH2F** barrel_m = new TH2F*[kGains];
197  TH2F** endc_p_m = new TH2F*[kGains];
198  TH2F** endc_m_m = new TH2F*[kGains];
199  float mEBmin[kGains], mEEmin[kGains], mEBmax[kGains], mEEmax[kGains];
200  float mEB[kGains][kEBChannels], mEE[kGains][kEEChannels];
201  for (int gainId = 0; gainId < kGains; gainId++) {
202  barrel_m[gainId] = new TH2F(Form("EBm%i", gainId),
203  Form("EB mean_x%i ", gainValues[gainId]),
204  MAX_IPHI,
205  0,
206  MAX_IPHI,
207  2 * MAX_IETA,
208  -MAX_IETA,
209  MAX_IETA);
210  endc_p_m[gainId] = new TH2F(Form("EE+m%i", gainId),
211  Form("EE+ mean_x%i", gainValues[gainId]),
212  IX_MAX,
213  IX_MIN,
214  IX_MAX + 1,
215  IY_MAX,
216  IY_MIN,
217  IY_MAX + 1);
218  endc_m_m[gainId] = new TH2F(Form("EE-m%i", gainId),
219  Form("EE- mean_x%i", gainValues[gainId]),
220  IX_MAX,
221  IX_MIN,
222  IX_MAX + 1,
223  IY_MAX,
224  IY_MIN,
225  IY_MAX + 1);
226  mEBmin[gainId] = 10.;
227  mEEmin[gainId] = 10.;
228  mEBmax[gainId] = -10.;
229  mEEmax[gainId] = -10.;
230  }
231 
232  unsigned int run[2];
233  std::string l_tagname[2];
234  auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
235  l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
236  auto firstiov = iovs.front();
237  run[0] = std::get<0>(firstiov);
238  std::tuple<cond::Time_t, cond::Hash> lastiov;
239  if (ntags == 2) {
240  auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
241  l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
242  lastiov = tag2iovs.front();
243  } else {
244  lastiov = iovs.back();
245  l_tagname[1] = l_tagname[0];
246  }
247  run[1] = std::get<0>(lastiov);
248  for (int irun = 0; irun < nIOVs; irun++) {
249  std::shared_ptr<EcalTPGPedestals> payload;
250  if (irun == 0) {
251  payload = this->fetchPayload(std::get<1>(firstiov));
252  } else {
253  payload = this->fetchPayload(std::get<1>(lastiov));
254  }
255  if (payload.get()) {
256  float dr;
257  for (int sign = 0; sign < kSides; sign++) {
258  int thesign = sign == 1 ? 1 : -1;
259 
260  for (int ieta = 0; ieta < MAX_IETA; ieta++) {
261  for (int iphi = 0; iphi < MAX_IPHI; iphi++) {
262  EBDetId id((ieta + 1) * thesign, iphi + 1);
263  int hashindex = id.hashedIndex();
264  float y = -1 - ieta;
265  if (sign == 1)
266  y = ieta;
267  float val = (*payload)[id.rawId()].mean_x12;
268  if (irun == 0) {
269  mEB[0][hashindex] = val;
270  } else {
271  if (method == 0)
272  dr = val - mEB[0][hashindex];
273  else {
274  if (mEB[0][hashindex] == 0.) {
275  if (val == 0.)
276  dr = 1.;
277  else
278  dr = 9999.;
279  } else
280  dr = val / mEB[0][hashindex];
281  }
282  barrel_m[0]->Fill(iphi, y, dr);
283  if (dr < mEBmin[0])
284  mEBmin[0] = dr;
285  if (dr > mEBmax[0])
286  mEBmax[0] = dr;
287  }
288  val = (*payload)[id.rawId()].mean_x6;
289  if (irun == 0) {
290  mEB[1][hashindex] = val;
291  } else {
292  if (method == 0)
293  dr = val - mEB[1][hashindex];
294  else {
295  if (mEB[1][hashindex] == 0.) {
296  if (val == 0.)
297  dr = 1.;
298  else
299  dr = 9999.;
300  } else
301  dr = val / mEB[1][hashindex];
302  }
303  barrel_m[1]->Fill(iphi, y, dr);
304  if (dr < mEBmin[1])
305  mEBmin[1] = dr;
306  if (dr > mEBmax[1])
307  mEBmax[1] = dr;
308  }
309  val = (*payload)[id.rawId()].mean_x1;
310  if (irun == 0) {
311  mEB[2][hashindex] = val;
312  } else {
313  if (method == 0)
314  dr = val - mEB[2][hashindex];
315  else {
316  if (mEB[2][hashindex] == 0.) {
317  if (val == 0.)
318  dr = 1.;
319  else
320  dr = 9999.;
321  } else
322  dr = val / mEB[2][hashindex];
323  }
324  barrel_m[2]->Fill(iphi, y, dr);
325  if (dr < mEBmin[2])
326  mEBmin[2] = dr;
327  if (dr > mEBmax[2])
328  mEBmax[2] = dr;
329  }
330  } // iphi
331  } // ieta
332 
333  for (int ix = 0; ix < IX_MAX; ix++) {
334  for (int iy = 0; iy < IY_MAX; iy++) {
335  if (!EEDetId::validDetId(ix + 1, iy + 1, thesign))
336  continue;
337  EEDetId id(ix + 1, iy + 1, thesign);
338  int hashindex = id.hashedIndex();
339  float val = (*payload)[id.rawId()].mean_x12;
340  if (irun == 0) {
341  mEE[0][hashindex] = val;
342  } else {
343  if (method == 0)
344  dr = val - mEE[0][hashindex];
345  else {
346  if (mEE[0][hashindex] == 0.) {
347  if (val == 0.)
348  dr = 1.;
349  else
350  dr = 9999.;
351  } else
352  dr = val / mEE[0][hashindex];
353  }
354  if (thesign == 1)
355  endc_p_m[0]->Fill(ix + 1, iy + 1, dr);
356  else
357  endc_m_m[0]->Fill(ix + 1, iy + 1, dr);
358  if (dr < mEEmin[0])
359  mEEmin[0] = dr;
360  if (dr > mEEmax[0])
361  mEEmax[0] = dr;
362  }
363  val = (*payload)[id.rawId()].mean_x6;
364  if (irun == 0) {
365  mEE[1][hashindex] = val;
366  } else {
367  if (method == 0)
368  dr = val - mEE[1][hashindex];
369  else {
370  if (mEE[1][hashindex] == 0.) {
371  if (val == 0.)
372  dr = 1.;
373  else
374  dr = 9999.;
375  } else
376  dr = val / mEE[1][hashindex];
377  }
378  if (thesign == 1)
379  endc_p_m[1]->Fill(ix + 1, iy + 1, dr);
380  else
381  endc_m_m[1]->Fill(ix + 1, iy + 1, dr);
382  if (dr < mEEmin[1])
383  mEEmin[1] = dr;
384  if (dr > mEEmax[1])
385  mEEmax[1] = dr;
386  }
387  val = (*payload)[id.rawId()].mean_x1;
388  if (irun == 0) {
389  mEE[2][hashindex] = val;
390  } else {
391  if (method == 0)
392  dr = val - mEE[2][hashindex];
393  else {
394  if (mEE[2][hashindex] == 0.) {
395  if (val == 0.)
396  dr = 1.;
397  else
398  dr = 9999.;
399  } else
400  dr = val / mEE[2][hashindex];
401  }
402  if (thesign == 1)
403  endc_p_m[2]->Fill(ix + 1, iy + 1, dr);
404  else
405  endc_m_m[2]->Fill(ix + 1, iy + 1, dr);
406  if (dr < mEEmin[2])
407  mEEmin[2] = dr;
408  if (dr > mEEmax[2])
409  mEEmax[2] = dr;
410  }
411  // fout << " x " << ix << " y " << " dr " << dr << std::endl;
412  } // iy
413  } // ix
414  } // side
415  } // if payload.get()
416  else
417  return false;
418  } // loop over IOVs
419 
420  gStyle->SetPalette(1);
421  gStyle->SetOptStat(0);
422  TCanvas canvas("CC map", "CC map", 1200, 900);
423  TLatex t1;
424  t1.SetNDC();
425  t1.SetTextAlign(26);
426  int len = l_tagname[0].length() + l_tagname[1].length();
427  std::string dr[2] = {"-", "/"};
428  if (ntags == 2) {
429  if (len < 150) {
430  t1.SetTextSize(0.03);
431  t1.DrawLatex(
432  0.5,
433  0.96,
434  Form("%s %i %s %s %i", l_tagname[1].c_str(), run[1], dr[method].c_str(), l_tagname[0].c_str(), run[0]));
435  } else {
436  t1.SetTextSize(0.03);
437  t1.DrawLatex(0.5, 0.96, Form("Ecal TPGPedestals, IOV %i %s %i", run[1], dr[method].c_str(), run[0]));
438  }
439  } else {
440  t1.SetTextSize(0.03);
441  t1.DrawLatex(0.5, 0.96, Form("%s, IOV %i %s %i", l_tagname[0].c_str(), run[1], dr[method].c_str(), run[0]));
442  }
443 
444  float xmi[3] = {0.0, 0.22, 0.78};
445  float xma[3] = {0.22, 0.78, 1.00};
446  TPad*** pad = new TPad**[kGains];
447  for (int gId = 0; gId < kGains; gId++) {
448  pad[gId] = new TPad*[3];
449  for (int obj = 0; obj < 3; obj++) {
450  float yma = 0.94 - (0.32 * gId);
451  float ymi = yma - 0.30;
452  pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId), Form("p_%i_%i", obj, gId), xmi[obj], ymi, xma[obj], yma);
453  pad[gId][obj]->Draw();
454  }
455  }
456 
457  for (int gId = 0; gId < kGains; gId++) {
458  pad[gId][0]->cd();
459  DrawEE(endc_m_m[gId], mEEmin[gId], mEEmax[gId]);
460  pad[gId][1]->cd();
461  DrawEB(barrel_m[gId], mEBmin[gId], mEBmax[gId]);
462  pad[gId][2]->cd();
463  DrawEE(endc_p_m[gId], mEEmin[gId], mEEmax[gId]);
464  }
465 
466  std::string ImageName(this->m_imageFileName);
467  canvas.SaveAs(ImageName.c_str());
468  return true;
469  } // fill method
470  }; // class EcalTPGPedestalsDiffBase
471  using EcalTPGPedestalsDiffOneTag = EcalTPGPedestalsBase<cond::payloadInspector::SINGLE_IOV, 1, 0>;
472  using EcalTPGPedestalsDiffTwoTags = EcalTPGPedestalsBase<cond::payloadInspector::SINGLE_IOV, 2, 0>;
473  using EcalTPGPedestalsRatioOneTag = EcalTPGPedestalsBase<cond::payloadInspector::SINGLE_IOV, 1, 1>;
474  using EcalTPGPedestalsRatioTwoTags = EcalTPGPedestalsBase<cond::payloadInspector::SINGLE_IOV, 2, 1>;
475 
476 } // namespace
477 
478 // Register the classes as boost python plugin
480  PAYLOAD_INSPECTOR_CLASS(EcalTPGPedestalsPlot);
481  PAYLOAD_INSPECTOR_CLASS(EcalTPGPedestalsDiffOneTag);
482  PAYLOAD_INSPECTOR_CLASS(EcalTPGPedestalsDiffTwoTags);
483  PAYLOAD_INSPECTOR_CLASS(EcalTPGPedestalsRatioOneTag);
484  PAYLOAD_INSPECTOR_CLASS(EcalTPGPedestalsRatioTwoTags);
485 }
uint16_t *__restrict__ id
double sign(double x)
static const int kSides
const Int_t gainValues[kGains]
void DrawEE(TH2F *endc, float min, float max)
Definition: EcalDrawUtils.h:29
void DrawEB(TH2F *ebmap, float min, float max)
Definition: EcalDrawUtils.h:4
def canvas
Definition: svgfig.py:482
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
constexpr int gainId(sample_type sample)
get the gainId (2 bits)
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
const Int_t kGains