CMS 3D CMS Logo

EcalTPGCrystalStatus_PayloadInspector.cc
Go to the documentation of this file.
7 // the data format of the condition to be inspected
9 
10 #include "TH2F.h"
11 #include "TCanvas.h"
12 #include "TStyle.h"
13 #include "TLine.h"
14 #include "TLatex.h"
15 
16 #include <string>
17 #include <memory>
18 #include <array>
19 
20 namespace {
21  enum { kEBChannels = 61200, kEEChannels = 14648, kSides = 2 };
22  enum { MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 85, MAX_IPHI = 360 }; // barrel lower and upper bounds on eta and phi
23  enum { IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100 }; // endcaps lower and upper bounds on x and y
24 
25  /***********************************************
26  2d plot of ECAL TPGCrystalStatus of 1 IOV
27  ************************************************/
28  class EcalTPGCrystalStatusPlot : public cond::payloadInspector::PlotImage<EcalTPGCrystalStatus> {
29  public:
30  EcalTPGCrystalStatusPlot()
31  : cond::payloadInspector::PlotImage<EcalTPGCrystalStatus>("ECAL TPGCrystalStatus - map ") {
32  setSingleIov(true);
33  }
34 
35  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash>>& iovs) override {
36  TH2F* barrel = new TH2F("EB", "EB TPG Crystal Status", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
37  TH2F* endc_p = new TH2F("EE+", "EE+ TPG Crystal Status", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
38  TH2F* endc_m = new TH2F("EE-", "EE- TPG Crystal Status", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
39  int EBstat = 0, EEstat[2] = {0, 0};
40 
41  auto iov = iovs.front();
42  std::shared_ptr<EcalTPGCrystalStatus> payload = fetchPayload(std::get<1>(iov));
43  unsigned int run = std::get<0>(iov);
44  if (payload.get()) {
45  for (int ieta = -MAX_IETA; ieta <= MAX_IETA; ieta++) {
46  Double_t eta = (Double_t)ieta;
47  if (ieta == 0)
48  continue;
49  else if (ieta > 0.)
50  eta = eta - 0.5; // 0.5 to 84.5
51  else
52  eta = eta + 0.5; // -84.5 to -0.5
53  for (int iphi = 1; iphi <= MAX_IPHI; iphi++) {
54  Double_t phi = (Double_t)iphi - 0.5;
55  EBDetId id(ieta, iphi);
56  double val = (*payload)[id.rawId()].getStatusCode();
57  barrel->Fill(phi, eta, val);
58  if (val > 0)
59  EBstat++;
60  }
61  }
62 
63  for (int sign = 0; sign < kSides; sign++) {
64  int thesign = sign == 1 ? 1 : -1;
65  for (int ix = 1; ix <= IX_MAX; ix++) {
66  for (int iy = 1; iy <= IY_MAX; iy++) {
67  if (!EEDetId::validDetId(ix, iy, thesign))
68  continue;
69  EEDetId id(ix, iy, thesign);
70  double val = (*payload)[id.rawId()].getStatusCode();
71  if (thesign == 1) {
72  endc_p->Fill(ix, iy, val);
73  if (val > 0)
74  EEstat[1]++;
75  } else {
76  endc_m->Fill(ix, iy, val);
77  if (val > 0)
78  EEstat[0]++;
79  }
80  } // iy
81  } // ix
82  } // side
83  } // payload
84 
85  gStyle->SetPalette(1);
86  gStyle->SetOptStat(0);
87  // TCanvas canvas("CC map","CC map", 1600, 450);
88  Double_t w = 1200;
89  Double_t h = 1400;
90  TCanvas canvas("c", "c", w, h);
91  canvas.SetWindowSize(w + (w - canvas.GetWw()), h + (h - canvas.GetWh()));
92 
93  TLatex t1;
94  t1.SetNDC();
95  t1.SetTextAlign(26);
96  t1.SetTextSize(0.05);
97  t1.DrawLatex(0.5, 0.96, Form("Ecal TPGCrystalStatus, IOV %i", run));
98 
99  // float xmi[3] = {0.0 , 0.24, 0.76};
100  // float xma[3] = {0.24, 0.76, 1.00};
101  float xmi[3] = {0.0, 0.0, 0.5};
102  float xma[3] = {1.0, 0.5, 1.0};
103  float ymi[3] = {0.47, 0.0, 0.0};
104  float yma[3] = {0.94, 0.47, 0.47};
105  std::array<std::unique_ptr<TPad>, 3> pad;
106  for (int obj = 0; obj < 3; obj++) {
107  pad[obj] = std::make_unique<TPad>(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], ymi[obj], xma[obj], yma[obj]);
108  pad[obj]->Draw();
109  }
110 
111  pad[0]->cd();
112  DrawEB(barrel, 0., 1.);
113  t1.DrawLatex(0.2, 0.94, Form("%i crystals", EBstat));
114  pad[1]->cd();
115  DrawEE(endc_m, 0., 1.);
116  t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEstat[0]));
117  pad[2]->cd();
118  DrawEE(endc_p, 0., 1.);
119  t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEstat[1]));
120 
121  std::string ImageName(m_imageFileName);
122  canvas.SaveAs(ImageName.c_str());
123  return true;
124  } // fill method
125  };
126 
127  /************************************************************************
128  2d plot of ECAL TPGCrystalStatus difference between 2 IOVs
129  ************************************************************************/
130  template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
131  class EcalTPGCrystalStatusDiffBase : public cond::payloadInspector::PlotImage<EcalTPGCrystalStatus, nIOVs, ntags> {
132  public:
133  EcalTPGCrystalStatusDiffBase()
134  : cond::payloadInspector::PlotImage<EcalTPGCrystalStatus, nIOVs, ntags>("ECAL TPGCrystalStatus difference") {}
135 
136  bool fill() override {
137  TH2F* barrel = new TH2F("EB", "EB difference", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
138  TH2F* endc_p = new TH2F("EE+", "EE+ difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
139  TH2F* endc_m = new TH2F("EE-", "EE- difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
140  int EBstat = 0, EEstat[2] = {0, 0};
141 
142  unsigned int run[2] = {0, 0};
143  float vEB[kEBChannels], vEE[kEEChannels];
144  std::string l_tagname[2];
145  auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
146  l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
147  auto firstiov = iovs.front();
148  run[0] = std::get<0>(firstiov);
149  std::tuple<cond::Time_t, cond::Hash> lastiov;
150  if (ntags == 2) {
151  auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
152  l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
153  lastiov = tag2iovs.front();
154  } else {
155  lastiov = iovs.back();
156  l_tagname[1] = l_tagname[0];
157  }
158  run[1] = std::get<0>(lastiov);
159  for (int irun = 0; irun < nIOVs; irun++) {
160  std::shared_ptr<EcalTPGCrystalStatus> payload;
161  if (irun == 0) {
162  payload = this->fetchPayload(std::get<1>(firstiov));
163  } else {
164  payload = this->fetchPayload(std::get<1>(lastiov));
165  }
166  if (payload.get()) {
167  for (int ieta = -MAX_IETA; ieta <= MAX_IETA; ieta++) {
168  Double_t eta = (Double_t)ieta;
169  if (ieta == 0)
170  continue;
171  else if (ieta > 0.)
172  eta = eta - 0.5; // 0.5 to 84.5
173  else
174  eta = eta + 0.5; // -84.5 to -0.5
175  for (int iphi = 1; iphi <= MAX_IPHI; iphi++) {
176  Double_t phi = (Double_t)iphi - 0.5;
177  EBDetId id(ieta, iphi);
178  int channel = id.hashedIndex();
179  double val = (*payload)[id.rawId()].getStatusCode();
180  if (irun == 0)
181  vEB[channel] = val;
182  else {
183  double diff = val - vEB[channel];
184  barrel->Fill(phi, eta, diff);
185  if (diff != 0)
186  EBstat++;
187  // std::cout << " entry " << EBtot << " mean " << EBmean << " rms " << EBrms << std::endl;
188  }
189  }
190  }
191 
192  for (int sign = 0; sign < kSides; sign++) {
193  int thesign = sign == 1 ? 1 : -1;
194  for (int ix = 1; ix <= IX_MAX; ix++) {
195  for (int iy = 1; iy <= IY_MAX; iy++) {
196  if (!EEDetId::validDetId(ix, iy, thesign))
197  continue;
198  EEDetId id(ix, iy, thesign);
199  int channel = id.hashedIndex();
200  double val = (*payload)[id.rawId()].getStatusCode();
201  if (irun == 0)
202  vEE[channel] = val;
203  else {
204  double diff = val - vEE[channel];
205  if (thesign == 1) {
206  endc_p->Fill(ix, iy, diff);
207  if (diff != 0)
208  EEstat[1]++;
209  } else {
210  endc_m->Fill(ix, iy, diff);
211  if (diff != 0)
212  EEstat[0]++;
213  }
214  }
215  } // iy
216  } // ix
217  } // side
218  } // payload
219  else
220  return false;
221  } // loop over IOVs
222 
223  gStyle->SetPalette(1);
224  gStyle->SetOptStat(0);
225  Double_t w = 1200;
226  Double_t h = 1400;
227  TCanvas canvas("c", "c", w, h);
228  canvas.SetWindowSize(w + (w - canvas.GetWw()), h + (h - canvas.GetWh()));
229 
230  TLatex t1;
231  t1.SetNDC();
232  t1.SetTextAlign(26);
233  int len = l_tagname[0].length() + l_tagname[1].length();
234  if (ntags == 2) {
235  if (len < 80) {
236  t1.SetTextSize(0.03);
237  t1.DrawLatex(0.5, 0.96, Form("%s %i - %s %i", l_tagname[1].c_str(), run[1], l_tagname[0].c_str(), run[0]));
238  } else {
239  t1.SetTextSize(0.05);
240  t1.DrawLatex(0.5, 0.96, Form("Ecal TPGCrystalStatus, IOV %i - %i", run[1], run[0]));
241  }
242  } else {
243  t1.SetTextSize(0.03);
244  t1.DrawLatex(0.5, 0.96, Form("%s, IOV %i - %i", l_tagname[0].c_str(), run[1], run[0]));
245  }
246 
247  // float xmi[3] = {0.0 , 0.24, 0.76};
248  // float xma[3] = {0.24, 0.76, 1.00};
249  float xmi[3] = {0.0, 0.0, 0.5};
250  float xma[3] = {1.0, 0.5, 1.0};
251  float ymi[3] = {0.47, 0.0, 0.0};
252  float yma[3] = {0.94, 0.47, 0.47};
253  std::vector<std::unique_ptr<TPad>> pad;
254  for (int obj = 0; obj < 3; obj++) {
255  pad.emplace_back(new TPad(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], ymi[obj], xma[obj], yma[obj]));
256  pad[obj]->Draw();
257  }
258 
259  pad[0]->cd();
260  DrawEB(barrel, -1., 1.);
261  t1.DrawLatex(0.2, 0.94, Form("%i differences", EBstat));
262  pad[1]->cd();
263  DrawEE(endc_m, -1., 1.);
264  t1.DrawLatex(0.15, 0.92, Form("%i differences", EEstat[0]));
265  pad[2]->cd();
266  DrawEE(endc_p, -1., 1.);
267  t1.DrawLatex(0.15, 0.92, Form("%i differences", EEstat[1]));
268 
269  std::string ImageName(this->m_imageFileName);
270  canvas.SaveAs(ImageName.c_str());
271  return true;
272  } // fill method
273  }; // class EcalTPGCrystalStatusDiffBase
274  using EcalTPGCrystalStatusDiffOneTag = EcalTPGCrystalStatusDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
275  using EcalTPGCrystalStatusDiffTwoTags = EcalTPGCrystalStatusDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
276 
277  /*********************************************************
278  2d plot of EcalTPGCrystalStatus Error Summary of 1 IOV
279  *********************************************************/
280  class EcalTPGCrystalStatusSummaryPlot : public cond::payloadInspector::PlotImage<EcalTPGCrystalStatus> {
281  public:
282  EcalTPGCrystalStatusSummaryPlot()
283  : cond::payloadInspector::PlotImage<EcalTPGCrystalStatus>("Ecal TPGCrystal Status Error Summary - map ") {
284  setSingleIov(true);
285  }
286 
287  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash>>& iovs) override {
288  auto iov = iovs.front(); //get reference to 1st element in the vector iovs
289  std::shared_ptr<EcalTPGCrystalStatus> payload =
290  fetchPayload(std::get<1>(iov)); //std::get<1>(iov) refers to the Hash in the tuple iov
291  unsigned int run = std::get<0>(iov); //referes to Time_t in iov.
292  TH2F* align; //pointer to align which is a 2D histogram
293 
294  int NbRows = 3;
295  int NbColumns = 3;
296 
297  if (payload.get()) { //payload is an iov retrieved from payload using hash.
298 
299  align = new TH2F("Ecal TPGCrystal Status Error Summary",
300  "EB/EE-/EE+ ErrorCount Total Number",
301  NbColumns,
302  0,
303  NbColumns,
304  NbRows,
305  0,
306  NbRows);
307 
308  long unsigned int ebErrorCount = 0;
309  long unsigned int ee1ErrorCount = 0;
310  long unsigned int ee2ErrorCount = 0;
311 
312  long unsigned int ebTotal = (payload->barrelItems()).size();
313  long unsigned int ee1Total = 0;
314  long unsigned int ee2Total = 0;
315 
316  getBarrelErrorSummary<EcalTPGCrystalStatusCode>(payload->barrelItems(), ebErrorCount);
317  getEndCapErrorSummary<EcalTPGCrystalStatusCode>(
318  payload->endcapItems(), ee1ErrorCount, ee2ErrorCount, ee1Total, ee2Total);
319 
320  double row = NbRows - 0.5;
321 
322  //EB summary values
323  align->Fill(0.5, row, 1);
324  align->Fill(1.5, row, ebErrorCount);
325  align->Fill(2.5, row, ebTotal);
326 
327  row--;
328  //EE- summary values
329  align->Fill(0.5, row, 2);
330  align->Fill(1.5, row, ee1ErrorCount);
331  align->Fill(2.5, row, ee1Total);
332 
333  row--;
334 
335  //EE+ summary values
336  align->Fill(0.5, row, 3);
337  align->Fill(1.5, row, ee2ErrorCount);
338  align->Fill(2.5, row, ee2Total);
339 
340  } // if payload.get()
341  else
342  return false;
343 
344  gStyle->SetPalette(1);
345  gStyle->SetOptStat(0);
346  TCanvas canvas("CC map", "CC map", 1000, 1000);
347  TLatex t1;
348  t1.SetNDC();
349  t1.SetTextAlign(26);
350  t1.SetTextSize(0.04);
351  t1.SetTextColor(2);
352  t1.DrawLatex(0.5, 0.96, Form("EcalTPGCrystalStatus Error Summary, IOV %i", run));
353 
354  TPad pad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
355  pad.Draw();
356  pad.cd();
357  align->Draw("TEXT");
358 
359  drawTable(NbRows, NbColumns);
360 
361  align->GetXaxis()->SetTickLength(0.);
362  align->GetXaxis()->SetLabelSize(0.);
363  align->GetYaxis()->SetTickLength(0.);
364  align->GetYaxis()->SetLabelSize(0.);
365 
366  std::string ImageName(m_imageFileName);
367  canvas.SaveAs(ImageName.c_str());
368  return true;
369  } // fill method
370  };
371 
372 } // namespace
373 
374 // Register the classes as boost python plugin
376  PAYLOAD_INSPECTOR_CLASS(EcalTPGCrystalStatusPlot);
377  PAYLOAD_INSPECTOR_CLASS(EcalTPGCrystalStatusDiffOneTag);
378  PAYLOAD_INSPECTOR_CLASS(EcalTPGCrystalStatusDiffTwoTags);
379  PAYLOAD_INSPECTOR_CLASS(EcalTPGCrystalStatusSummaryPlot);
380 }
size
Write out results.
T w() const
static const int kSides
void DrawEE(TH2F *endc, float min, float max)
Definition: EcalDrawUtils.h:29
void DrawEB(TH2F *ebmap, float min, float max)
Definition: EcalDrawUtils.h:4
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
def canvas(sub, attr)
Definition: svgfig.py:482
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void drawTable(int nbRows, int nbColumns)
Definition: EcalDrawUtils.h:91
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)