CMS 3D CMS Logo

EcalGainRatios_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 };
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 
26  /******************************************
27  2d plot of ECAL GainRatios of 1 IOV
28  ******************************************/
29  class EcalGainRatiosPlot : public cond::payloadInspector::PlotImage<EcalGainRatios> {
30  public:
31  EcalGainRatiosPlot() : cond::payloadInspector::PlotImage<EcalGainRatios>("ECAL Gain Ratios - map ") {
32  setSingleIov(true);
33  }
34 
35  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
36  TH2F* barrel_12O6 = new TH2F("EB_12O6", "EB gain 12/6", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
37  TH2F* endc_p_12O6 = new TH2F("EE+_12O6", "EE+ gain 12/6", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
38  TH2F* endc_m_12O6 = new TH2F("EE-_12O6", "EE- gain 12/6", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
39  TH2F* barrel_6O1 = new TH2F("EB_6O1", "EB gain 6/1", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
40  TH2F* endc_p_6O1 = new TH2F("EE+_6O1", "EE+ gain 6/1", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
41  TH2F* endc_m_6O1 = new TH2F("EE-_6O1", "EE- gain 6/1", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
42  TH1F* b_12O6 = new TH1F("b_12O6", "EB gain 12/6", 50, 1.8, 2.1);
43  TH1F* e_12O6 = new TH1F("e_12O6", "EE gain 12/6", 50, 1.8, 2.1);
44  TH1F* b_6O1 = new TH1F("b_6O1", "EB gain 6/1", 100, 5.3, 6.3);
45  TH1F* e_6O1 = new TH1F("e_6O1", "EE gain 6/1", 100, 5.3, 6.3);
46 
47  auto iov = iovs.front();
48  std::shared_ptr<EcalGainRatios> payload = fetchPayload(std::get<1>(iov));
49  unsigned int run = std::get<0>(iov);
50  if (payload.get()) {
51  // looping over the EB channels, via the dense-index, mapped into EBDetId's
52  for (int cellid = 0; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) { // loop on EB cells
53  uint32_t rawid = EBDetId::unhashIndex(cellid);
54  Double_t phi = (Double_t)(EBDetId(rawid)).iphi() - 0.5;
55  Double_t eta = (Double_t)(EBDetId(rawid)).ieta();
56  if (eta > 0.)
57  eta = eta - 0.5; // 0.5 to 84.5
58  else
59  eta = eta + 0.5; // -84.5 to -0.5
60  barrel_12O6->Fill(phi, eta, (*payload)[rawid].gain12Over6());
61  barrel_6O1->Fill(phi, eta, (*payload)[rawid].gain6Over1());
62  b_12O6->Fill((*payload)[rawid].gain12Over6());
63  b_6O1->Fill((*payload)[rawid].gain6Over1());
64  } // loop over cellid
65 
66  // looping over the EE channels
67  for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) {
68  if (!EEDetId::validHashIndex(cellid))
69  continue;
70  uint32_t rawid = EEDetId::unhashIndex(cellid);
71  EEDetId myEEId(rawid);
72  if (myEEId.zside() == 1) {
73  endc_p_12O6->Fill(myEEId.ix(), myEEId.iy(), (*payload)[rawid].gain12Over6());
74  endc_p_6O1->Fill(myEEId.ix(), myEEId.iy(), (*payload)[rawid].gain6Over1());
75  } else {
76  endc_m_12O6->Fill(myEEId.ix(), myEEId.iy(), (*payload)[rawid].gain12Over6());
77  endc_m_6O1->Fill(myEEId.ix(), myEEId.iy(), (*payload)[rawid].gain6Over1());
78  }
79  e_12O6->Fill((*payload)[rawid].gain12Over6());
80  e_6O1->Fill((*payload)[rawid].gain6Over1());
81  } // validDetId
82  } // if payload.get()
83  else
84  return false;
85 
86  gStyle->SetPalette(1);
87  gStyle->SetOptStat(0);
88  TCanvas canvas("CC map", "CC map", 1680, 1320);
89  TLatex t1;
90  t1.SetNDC();
91  t1.SetTextAlign(26);
92  t1.SetTextSize(0.05);
93  t1.DrawLatex(0.5, 0.96, Form("Ecal Gain Ratios, IOV %i", run));
94 
95  float xmi[3] = {0.0, 0.22, 0.78};
96  float xma[3] = {0.22, 0.78, 1.00};
97  TPad*** pad = new TPad**[2];
98  for (int gId = 0; gId < 2; gId++) {
99  pad[gId] = new TPad*[3];
100  for (int obj = 0; obj < 3; obj++) {
101  float yma = 0.94 - (0.32 * gId);
102  float ymi = yma - 0.28;
103  pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId), Form("p_%i_%i", obj, gId), xmi[obj], ymi, xma[obj], yma);
104  pad[gId][obj]->Draw();
105  }
106  }
107  TPad** pad1 = new TPad*[4];
108  for (int obj = 0; obj < 4; obj++) {
109  float xmi = 0.26 * obj;
110  float xma = xmi + 0.22;
111  pad1[obj] = new TPad(Form("p1_%i", obj), Form("p1_%i", obj), xmi, 0.0, xma, 0.32);
112  pad1[obj]->Draw();
113  }
114 
115  float min12O6 = 1.8, max12O6 = 2.1, min6O1 = 5.3, max6O1 = 6.3;
116  pad[0][0]->cd();
117  DrawEE(endc_m_12O6, min12O6, max12O6);
118  endc_m_12O6->SetStats(false);
119  pad[0][1]->cd();
120  DrawEB(barrel_12O6, min12O6, max12O6);
121  barrel_12O6->SetStats(false);
122  pad[0][2]->cd();
123  DrawEE(endc_p_12O6, min12O6, max12O6);
124  endc_p_12O6->SetStats(false);
125  pad[1][0]->cd();
126  DrawEE(endc_m_6O1, min6O1, max6O1);
127  endc_m_6O1->SetStats(false);
128  pad[1][1]->cd();
129  DrawEB(barrel_6O1, min6O1, max6O1);
130  barrel_6O1->SetStats(false);
131  pad[1][2]->cd();
132  DrawEE(endc_p_6O1, min6O1, max6O1);
133  endc_p_6O1->SetStats(false);
134 
135  gStyle->SetOptStat(111110);
136  pad1[0]->cd();
137  b_12O6->Draw();
138  pad1[0]->Update();
139  TPaveStats* st = (TPaveStats*)b_12O6->FindObject("stats");
140  st->SetX1NDC(0.6); //new x start position
141  st->SetY1NDC(0.75); //new y start position
142  pad1[1]->cd();
143  e_12O6->Draw();
144  pad1[0]->Update();
145  st = (TPaveStats*)e_12O6->FindObject("stats");
146  st->SetX1NDC(0.6); //new x start position
147  st->SetY1NDC(0.75); //new y start position
148  pad1[2]->cd();
149  b_6O1->Draw();
150  pad1[0]->Update();
151  st = (TPaveStats*)b_6O1->FindObject("stats");
152  st->SetX1NDC(0.6); //new x start position
153  st->SetY1NDC(0.75); //new y start position
154  pad1[3]->cd();
155  e_6O1->Draw();
156  pad1[0]->Update();
157  st = (TPaveStats*)e_6O1->FindObject("stats");
158  st->SetX1NDC(0.6); //new x start position
159  st->SetY1NDC(0.75); //new y start position
160 
161  std::string ImageName(m_imageFileName);
162  canvas.SaveAs(ImageName.c_str());
163  return true;
164  } // fill method
165  };
166 
167  /**********************************************************
168  2d plot of ECAL GainRatios difference between 2 IOVs
169  **********************************************************/
170  template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
171  class EcalGainRatiosDiffBase : public cond::payloadInspector::PlotImage<EcalGainRatios, nIOVs, ntags> {
172  public:
173  EcalGainRatiosDiffBase()
174  : cond::payloadInspector::PlotImage<EcalGainRatios, nIOVs, ntags>("ECAL Gain Ratios difference") {}
175 
176  bool fill() override {
177  TH2F* barrel_12O6 =
178  new TH2F("EB_12O6", "EB gain 12/6 difference", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
179  TH2F* endc_p_12O6 =
180  new TH2F("EE+_12O6", "EE+ gain 12/6 difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
181  TH2F* endc_m_12O6 =
182  new TH2F("EE-_12O6", "EE- gain 12/6 difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
183  TH2F* barrel_6O1 =
184  new TH2F("EB_6O1", "EB gain 6/1 difference", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
185  TH2F* endc_p_6O1 =
186  new TH2F("EE+_6O1", "EE+ gain 6/1 difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
187  TH2F* endc_m_6O1 =
188  new TH2F("EE-_6O1", "EE- gain 6/1 difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
189  TH1F* b_12O6 = new TH1F("b_12O6", "EB gain 12/6 difference", 50, -0.1, 0.1);
190  TH1F* e_12O6 = new TH1F("e_12O6", "EE gain 12/6 difference", 50, -0.1, 0.1);
191  TH1F* b_6O1 = new TH1F("b_6O1", "EB gain 6/1 difference", 100, -0.1, 0.1);
192  TH1F* e_6O1 = new TH1F("e_6O1", "EE gain 6/1 difference", 100, -0.1, 0.1);
193 
194  unsigned int run[2];
195  float gEB[3][kEBChannels], gEE[3][kEEChannels];
196  std::string l_tagname[2];
197  auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
198  l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
199  auto firstiov = iovs.front();
200  run[0] = std::get<0>(firstiov);
201  std::tuple<cond::Time_t, cond::Hash> lastiov;
202  if (ntags == 2) {
203  auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
204  l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
205  lastiov = tag2iovs.front();
206  } else {
207  lastiov = iovs.back();
208  l_tagname[1] = l_tagname[0];
209  }
210  run[1] = std::get<0>(lastiov);
211  for (int irun = 0; irun < nIOVs; irun++) {
212  std::shared_ptr<EcalGainRatios> payload;
213  if (irun == 0) {
214  payload = this->fetchPayload(std::get<1>(firstiov));
215  } else {
216  payload = this->fetchPayload(std::get<1>(lastiov));
217  }
218  if (payload.get()) {
219  // looping over the EB channels, via the dense-index, mapped into EBDetId's
220  for (int cellid = 0; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) { // loop on EB cells
221  uint32_t rawid = EBDetId::unhashIndex(cellid);
222  if (irun == 0) {
223  gEB[0][cellid] = (*payload)[rawid].gain12Over6();
224  gEB[1][cellid] = (*payload)[rawid].gain6Over1();
225  } else {
226  Double_t phi = (Double_t)(EBDetId(rawid)).iphi() - 0.5;
227  Double_t eta = (Double_t)(EBDetId(rawid)).ieta();
228  if (eta > 0.)
229  eta = eta - 0.5; // 0.5 to 84.5
230  else
231  eta = eta + 0.5; // -84.5 to -0.5
232  float diff = gEB[0][cellid] - (*payload)[rawid].gain12Over6();
233  barrel_12O6->Fill(phi, eta, diff);
234  b_12O6->Fill(diff);
235  diff = gEB[1][cellid] - (*payload)[rawid].gain6Over1();
236  barrel_6O1->Fill(phi, eta, diff);
237  b_6O1->Fill(diff);
238  }
239  } // loop over cellid
240 
241  // looping over the EE channels
242  for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) {
243  if (!EEDetId::validHashIndex(cellid))
244  continue;
245  uint32_t rawid = EEDetId::unhashIndex(cellid);
246  EEDetId myEEId(rawid);
247  if (irun == 0) {
248  gEE[0][cellid] = (*payload)[rawid].gain12Over6();
249  gEE[1][cellid] = (*payload)[rawid].gain6Over1();
250  } else {
251  float diff1 = gEE[0][cellid] - (*payload)[rawid].gain12Over6();
252  float diff2 = gEE[1][cellid] - (*payload)[rawid].gain6Over1();
253  if (myEEId.zside() == 1) {
254  endc_p_12O6->Fill(myEEId.ix(), myEEId.iy(), diff1);
255  endc_p_6O1->Fill(myEEId.ix(), myEEId.iy(), diff2);
256  } else {
257  endc_m_12O6->Fill(myEEId.ix(), myEEId.iy(), diff1);
258  endc_m_6O1->Fill(myEEId.ix(), myEEId.iy(), diff2);
259  }
260  e_12O6->Fill(diff1);
261  e_6O1->Fill(diff2);
262  }
263  } // loop over cellid
264  } // if payload.get()
265  else
266  return false;
267  } // loop over IOVs
268 
269  gStyle->SetPalette(1);
270  gStyle->SetOptStat(0);
271  TCanvas canvas("CC map", "CC map", 1680, 1320);
272  TLatex t1;
273  t1.SetNDC();
274  t1.SetTextAlign(26);
275  int len = l_tagname[0].length() + l_tagname[1].length();
276  if (ntags == 2 && len < 70) {
277  t1.SetTextSize(0.03);
278  t1.DrawLatex(
279  0.5, 0.96, Form("%s IOV %i - %s IOV %i", l_tagname[1].c_str(), run[1], l_tagname[0].c_str(), run[0]));
280  } else {
281  t1.SetTextSize(0.05);
282  t1.DrawLatex(0.5, 0.96, Form("%s, IOV %i - %i", l_tagname[0].c_str(), run[1], run[0]));
283  }
284 
285  float xmi[3] = {0.0, 0.22, 0.78};
286  float xma[3] = {0.22, 0.78, 1.00};
287  TPad*** pad = new TPad**[2];
288  for (int gId = 0; gId < 2; gId++) {
289  pad[gId] = new TPad*[3];
290  for (int obj = 0; obj < 3; obj++) {
291  float yma = 0.94 - (0.32 * gId);
292  float ymi = yma - 0.28;
293  pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId), Form("p_%i_%i", obj, gId), xmi[obj], ymi, xma[obj], yma);
294  pad[gId][obj]->Draw();
295  }
296  }
297  TPad** pad1 = new TPad*[4];
298  for (int obj = 0; obj < 4; obj++) {
299  float xmi = 0.26 * obj;
300  float xma = xmi + 0.22;
301  pad1[obj] = new TPad(Form("p1_%i", obj), Form("p1_%i", obj), xmi, 0.0, xma, 0.32);
302  pad1[obj]->Draw();
303  }
304 
305  float min12O6 = -0.1, max12O6 = 0.1, min6O1 = -0.1, max6O1 = 0.1;
306  pad[0][0]->cd();
307  DrawEE(endc_m_12O6, min12O6, max12O6);
308  endc_m_12O6->SetStats(false);
309  pad[0][1]->cd();
310  DrawEB(barrel_12O6, min12O6, max12O6);
311  barrel_12O6->SetStats(false);
312  pad[0][2]->cd();
313  DrawEE(endc_p_12O6, min12O6, max12O6);
314  endc_p_12O6->SetStats(false);
315  pad[1][0]->cd();
316  DrawEE(endc_m_6O1, min6O1, max6O1);
317  endc_m_6O1->SetStats(false);
318  pad[1][1]->cd();
319  DrawEB(barrel_6O1, min6O1, max6O1);
320  barrel_6O1->SetStats(false);
321  pad[1][2]->cd();
322  DrawEE(endc_p_6O1, min6O1, max6O1);
323  endc_p_6O1->SetStats(false);
324 
325  gStyle->SetOptStat(111110);
326  pad1[0]->cd();
327  b_12O6->Draw();
328  pad1[0]->Update();
329  TPaveStats* st = (TPaveStats*)b_12O6->FindObject("stats");
330  st->SetX1NDC(0.6); //new x start position
331  st->SetY1NDC(0.75); //new y start position
332  pad1[1]->cd();
333  e_12O6->Draw();
334  pad1[0]->Update();
335  st = (TPaveStats*)e_12O6->FindObject("stats");
336  st->SetX1NDC(0.6); //new x start position
337  st->SetY1NDC(0.75); //new y start position
338  pad1[2]->cd();
339  b_6O1->Draw();
340  pad1[0]->Update();
341  st = (TPaveStats*)b_6O1->FindObject("stats");
342  st->SetX1NDC(0.6); //new x start position
343  st->SetY1NDC(0.75); //new y start position
344  pad1[3]->cd();
345  e_6O1->Draw();
346  pad1[0]->Update();
347  st = (TPaveStats*)e_6O1->FindObject("stats");
348  st->SetX1NDC(0.6); //new x start position
349  st->SetY1NDC(0.75); //new y start position
350 
351  std::string ImageName(this->m_imageFileName);
352  canvas.SaveAs(ImageName.c_str());
353  return true;
354  } // fill method
355  }; // class EcalGainRatiosDiffBase
356  using EcalGainRatiosDiffOneTag = EcalGainRatiosDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
357  using EcalGainRatiosDiffTwoTags = EcalGainRatiosDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
358 
359 } // namespace
360 
361 // Register the classes as boost python plugin
363  PAYLOAD_INSPECTOR_CLASS(EcalGainRatiosPlot);
364  PAYLOAD_INSPECTOR_CLASS(EcalGainRatiosDiffOneTag);
365  PAYLOAD_INSPECTOR_CLASS(EcalGainRatiosDiffTwoTags);
366 }
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
static bool validHashIndex(int i)
Definition: EEDetId.h:239
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 EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
Definition: plugin.cc:23
def canvas(sub, attr)
Definition: svgfig.py:482
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)