CMS 3D CMS Logo

EcalTPGTowerStatus_PayloadInspector.cc
Go to the documentation of this file.
8 
9 // the data format of the condition to be inspected
11 
12 #include "TH2F.h"
13 #include "TCanvas.h"
14 #include "TStyle.h"
15 #include "TLine.h"
16 #include "TLatex.h"
17 
18 #include <string>
19 
20 namespace {
21  enum { kEBTotalTowers = 2448 };
22  enum { MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 17, MAX_IPHI = 72 }; // barrel lower and upper bounds on eta and phi
23 
24  /***********************************************
25  2d plot of ECAL TPGTowerStatus of 1 IOV
26  ************************************************/
27  class EcalTPGTowerStatusPlot : public cond::payloadInspector::PlotImage<EcalTPGTowerStatus> {
28  public:
29  EcalTPGTowerStatusPlot() : cond::payloadInspector::PlotImage<EcalTPGTowerStatus>("ECAL TPGTowerStatus - map ") {
30  setSingleIov(true);
31  }
32 
33  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
34  TH2F* barrel = new TH2F("EB", "EB TPG Tower Status", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
35  int EBstat = 0;
36 
37  auto iov = iovs.front();
38  std::shared_ptr<EcalTPGTowerStatus> payload = fetchPayload(std::get<1>(iov));
39  unsigned int run = std::get<0>(iov);
40  if (payload.get()) {
41  const EcalTPGTowerStatusMap& towerMap = (*payload).getMap();
42  // std::cout << " tower map size " << towerMap.size() << std::endl;
44  for (it = towerMap.begin(); it != towerMap.end(); ++it) {
45  if ((*it).second > 0) {
46  EcalTrigTowerDetId ttId((*it).first);
47  int ieta = ttId.ieta();
48  // if(ieta < 0) ieta--; // -1 to -17
49  int iphi = ttId.iphi() - 1; // 0 to 71
50  // std::cout << " sub det " << ttId.subDet() << " phi " << iphi << " eta " << ieta << std::endl;
51  // ieta goes from -18 to -2 and 1 to 17. Change it to -17/-1 and 0/16
52  ieta--;
53  if (ttId.subDet() == 1) { // barrel
54  barrel->Fill(iphi, ieta, (*it).second);
55  EBstat++;
56  }
57  }
58  }
59  } // payload
60 
61  gStyle->SetPalette(1);
62  gStyle->SetOptStat(0);
63  // TCanvas canvas("CC map","CC map", 1600, 450);
64  Double_t w = 1400;
65  Double_t h = 1200;
66  TCanvas canvas("c", "c", w, h);
67  // canvas.SetWindowSize(w + (w - canvas.GetWw()), h + (h - canvas.GetWh()));
68 
69  TLatex t1;
70  t1.SetNDC();
71  t1.SetTextAlign(26);
72  t1.SetTextSize(0.05);
73  t1.DrawLatex(0.5, 0.96, Form("Ecal TPGTowerStatus, IOV %i", run));
74 
75  TPad** pad = new TPad*;
76  for (int obj = 0; obj < 1; obj++) {
77  pad[obj] = new TPad(Form("p_%i", obj), Form("p_%i", obj), 0.0, 0.04, 1.0, 0.94);
78  pad[obj]->Draw();
79  }
80  t1.SetTextSize(0.03);
81  t1.DrawLatex(0.2, 0.88, Form("%i towers", EBstat));
82  // canvas.cd();
83  pad[0]->cd();
84  // barrel->SetStats(false);
85  barrel->Draw("col");
86  TLine* l = new TLine(0., 0., 0., 0.);
87  l->SetLineWidth(1);
88  for (int i = 0; i < MAX_IETA; i++) {
89  Double_t x = 4. + (i * 4);
90  l = new TLine(x, -MAX_IETA, x, MAX_IETA);
91  l->Draw();
92  }
93  l = new TLine(0., 0., 72., 0.);
94  l->Draw();
95 
96  std::string ImageName(m_imageFileName);
97  canvas.SaveAs(ImageName.c_str());
98  return true;
99  } // fill method
100  };
101 
102  /************************************************************************
103  2d plot of ECAL TPGTowerStatus difference between 2 IOVs
104  ************************************************************************/
105  template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
106  class EcalTPGTowerStatusDiffBase : public cond::payloadInspector::PlotImage<EcalTPGTowerStatus, nIOVs, ntags> {
107  public:
108  EcalTPGTowerStatusDiffBase()
109  : cond::payloadInspector::PlotImage<EcalTPGTowerStatus, nIOVs, ntags>("ECAL TPGTowerStatus difference") {}
110 
111  bool fill() override {
112  TH2F* barrel = new TH2F("EB", "EB difference", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
113  // int EBstat[2] = {0, 0};
114  int EBstat = 0;
115 
116  unsigned int run[2] = {0, 0}, vEB[kEBTotalTowers];
117  std::string l_tagname[2];
118  auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
119  l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
120  auto firstiov = iovs.front();
121  run[0] = std::get<0>(firstiov);
122  std::tuple<cond::Time_t, cond::Hash> lastiov;
123  if (ntags == 2) {
124  auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
125  l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
126  lastiov = tag2iovs.front();
127  } else {
128  lastiov = iovs.back();
129  l_tagname[1] = l_tagname[0];
130  }
131  run[1] = std::get<0>(lastiov);
132  for (int irun = 0; irun < nIOVs; irun++) {
133  std::shared_ptr<EcalTPGTowerStatus> payload;
134  if (irun == 0) {
135  payload = this->fetchPayload(std::get<1>(firstiov));
136  } else {
137  payload = this->fetchPayload(std::get<1>(lastiov));
138  }
139  if (payload.get()) {
140  const EcalTPGTowerStatusMap& towerMap = (*payload).getMap();
141  // std::cout << " tower map size " << towerMap.size() << std::endl;
143  for (it = towerMap.begin(); it != towerMap.end(); ++it) {
144  EcalTrigTowerDetId ttId((*it).first);
145  int ieta = ttId.ieta();
146  if (ieta < 0)
147  ieta--; // 1 to 17
148  int iphi = ttId.iphi() - 1; // 0 to 71
149  int towerId = ttId.hashedIndex();
150  int stat = (*it).second;
151  if (irun == 0) {
152  if (ttId.subDet() == 1) { // barrel
153  vEB[towerId] = stat;
154  if (stat > 0) { // bad tower
155  if (towerId >= kEBTotalTowers)
156  std::cout << " strange tower Id " << towerId << std::endl;
157  }
158  } // barrel
159  } // 1st run
160  else { // 2nd run
161  if (ttId.subDet() == 1) { // barrel
162  if (stat > 0) { // bad tower
163  if (towerId >= kEBTotalTowers)
164  std::cout << " strange tower Id " << towerId << std::endl;
165  // else std::cout << " phi " << iphi << " eta " << ieta << std::endl;
166  } // bad tower
167  int diff = stat - vEB[towerId];
168  // ieta goes from -18 to -2 and 1 to 17. Change it to -17/-1 and 0/16
169  ieta--;
170  if (diff != 0)
171  barrel->Fill(iphi, ieta, diff);
172  // vEB[towerId] = 0;
173  EBstat += diff;
174  } // barrel
175  } // 2nd run
176  } // loop over towers
177  } // payload
178  else
179  return false;
180  } // loop over IOVs
181  /*
182  // now check if towers have disappered
183  for(int it = 0; it < kEBTotalTowers; it++) {
184  if(vEB[it] != 0) {
185  std::cout << " tower " << vEB[it] << " not found in run 2, plot it" << std::endl;
186  EcalTrigTowerDetId ttId = EBId[it];
187  int ieta = ttId.ieta();
188  // ieta goes from -18 to -2 and 1 to 17. Change it to -17/-1 and 0/16
189  ieta--;
190  int iphi = ttId.iphi() - 1; // 0 to 71
191  barrel->Fill(iphi, ieta, vEB[it]);
192  }
193  }
194  */
195  gStyle->SetPalette(1);
196  gStyle->SetOptStat(0);
197  Double_t w = 1400;
198  Double_t h = 1200;
199  TCanvas canvas("c", "c", w, h);
200  // canvas.SetWindowSize(w + (w - canvas.GetWw()), h + (h - canvas.GetWh()));
201 
202  TLatex t1;
203  t1.SetNDC();
204  t1.SetTextAlign(26);
205  int len = l_tagname[0].length() + l_tagname[1].length();
206  if (ntags == 2) {
207  if (len < 80) {
208  t1.SetTextSize(0.03);
209  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]));
210  } else {
211  t1.SetTextSize(0.05);
212  t1.DrawLatex(0.5, 0.96, Form("Ecal TPGTowerStatus, IOV %i - %i", run[1], run[0]));
213  }
214  } else {
215  t1.SetTextSize(0.05);
216  t1.DrawLatex(0.5, 0.96, Form("%s, IOV %i - %i", l_tagname[0].c_str(), run[1], run[0]));
217  }
218  t1.SetTextSize(0.05);
219 
220  TPad** pad = new TPad*;
221  for (int obj = 0; obj < 1; obj++) {
222  pad[obj] = new TPad(Form("p_%i", obj), Form("p_%i", obj), 0.0, 0.04, 1.0, 0.94);
223  pad[obj]->Draw();
224  }
225  t1.SetTextSize(0.03);
226  t1.DrawLatex(0.2, 0.88, Form("%i tower(s)", EBstat));
227 
228  pad[0]->cd();
229  // barrel->SetStats(false);
230  barrel->Draw("colz");
231  TLine* l = new TLine(0., 0., 0., 0.);
232  l->SetLineWidth(1);
233  for (int i = 0; i < MAX_IETA; i++) {
234  Double_t x = 4. + (i * 4);
235  l = new TLine(x, -MAX_IETA, x, MAX_IETA);
236  l->Draw();
237  }
238  l = new TLine(0., 0., 72., 0.);
239  l->Draw();
240 
241  std::string ImageName(this->m_imageFileName);
242  canvas.SaveAs(ImageName.c_str());
243  return true;
244  } // fill method
245  }; // class EcalTPGTowerStatusDiffBase
246  using EcalTPGTowerStatusDiffOneTag = EcalTPGTowerStatusDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
247  using EcalTPGTowerStatusDiffTwoTags = EcalTPGTowerStatusDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
248 
249  /*******************************************************
250  2d plot of EcalTPGTowerStatus Error Summary of 1 IOV
251  ********************************************************/
252  class EcalTPGTowerStatusSummaryPlot : public cond::payloadInspector::PlotImage<EcalTPGTowerStatus> {
253  public:
254  EcalTPGTowerStatusSummaryPlot()
255  : cond::payloadInspector::PlotImage<EcalTPGTowerStatus>("Ecal TPGTower Status Summary - map ") {
256  setSingleIov(true);
257  }
258 
259  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
260  auto iov = iovs.front(); //get reference to 1st element in the vector iovs
261  std::shared_ptr<EcalTPGTowerStatus> payload =
262  fetchPayload(std::get<1>(iov)); //std::get<1>(iov) refers to the Hash in the tuple iov
263  unsigned int run = std::get<0>(iov); //referes to Time_t in iov.
264  TH2F* align; //pointer to align which is a 2D histogram
265 
266  int NbRows = 1;
267  int NbColumns = 2;
268 
269  if (payload.get()) { //payload is an iov retrieved from payload using hash.
270  const EcalTPGTowerStatusMap& towerMap = (*payload).getMap();
271 
272  align = new TH2F("Ecal TPGTower Status Summary",
273  "Total NumberOfMasked",
274  NbColumns,
275  0,
276  NbColumns,
277  NbRows,
278  0,
279  NbRows);
280 
281  int NbMaskedTT = 0;
282 
283  for (EcalTPGTowerStatusMapIterator it = towerMap.begin(); it != towerMap.end(); ++it)
284  if ((*it).second > 0)
285  NbMaskedTT++;
286 
287  align->Fill(0.5, 0.5, towerMap.size());
288  align->Fill(1.5, 0.5, NbMaskedTT);
289 
290  } // if payload.get()
291  else
292  return false;
293 
294  gStyle->SetPalette(1);
295  gStyle->SetOptStat(0);
296  TCanvas canvas("CC map", "CC map", 1000, 1000);
297  TLatex t1;
298  t1.SetNDC();
299  t1.SetTextAlign(26);
300  t1.SetTextSize(0.04);
301  t1.SetTextColor(2);
302  t1.DrawLatex(0.5, 0.96, Form("Barrel masked Trigger Towers, IOV %i", run));
303 
304  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
305  pad->Draw();
306  pad->cd();
307  align->Draw("TEXT");
308 
309  drawTable(NbRows, NbColumns);
310 
311  align->GetXaxis()->SetTickLength(0.);
312  align->GetXaxis()->SetLabelSize(0.);
313  align->GetYaxis()->SetTickLength(0.);
314  align->GetYaxis()->SetLabelSize(0.);
315 
316  std::string ImageName(m_imageFileName);
317  canvas.SaveAs(ImageName.c_str());
318  return true;
319  } // fill method
320  };
321 
322 } // namespace
323 
324 // Register the classes as boost python plugin
326  PAYLOAD_INSPECTOR_CLASS(EcalTPGTowerStatusPlot);
327  PAYLOAD_INSPECTOR_CLASS(EcalTPGTowerStatusDiffOneTag);
328  PAYLOAD_INSPECTOR_CLASS(EcalTPGTowerStatusDiffTwoTags);
329  PAYLOAD_INSPECTOR_CLASS(EcalTPGTowerStatusSummaryPlot);
330 }
std::map< uint32_t, uint16_t >::const_iterator EcalTPGTowerStatusMapIterator
std::map< uint32_t, uint16_t > EcalTPGTowerStatusMap
T w() const
unsigned ttId(DetId const &, EcalElectronicsMapping const *)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
unsigned towerId(DetId const &, EcalElectronicsMapping const *)
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Definition: plugin.cc:23
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)