CMS 3D CMS Logo

EcalLaserAPDPNRatiosRef_PayloadInspector.cc
Go to the documentation of this file.
8 // the data format of the condition to be inspected
10 
11 #include "TH2F.h"
12 #include "TCanvas.h"
13 #include "TStyle.h"
14 #include "TLine.h"
15 #include "TLatex.h"
16 
17 #include <memory>
18 #include <sstream>
19 #include <array>
20 
21 namespace {
22  enum { kEBChannels = 61200, kEEChannels = 14648 };
23  enum {
24  MIN_IETA = 1,
25  MIN_IPHI = 1,
26  MAX_IETA = 85,
27  MAX_IPHI = 360,
28  EBhistEtaMax = 171
29  }; // barrel lower and upper bounds on eta and phi
30  enum {
31  IX_MIN = 1,
32  IY_MIN = 1,
33  IX_MAX = 100,
34  IY_MAX = 100,
35  EEhistXMax = 220
36  }; // endcaps lower and upper bounds on x and y
37 
38  /****************************************************************
39  2d histogram of ECAL barrel Laser APDPN Ratios Ref of 1 IOV
40  *****************************************************************/
41 
42  // inherit from one of the predefined plot class: Histogram2D
43  class EcalLaserAPDPNRatiosRefEBMap : public cond::payloadInspector::Histogram2D<EcalLaserAPDPNRatiosRef> {
44  public:
45  EcalLaserAPDPNRatiosRefEBMap()
46  : cond::payloadInspector::Histogram2D<EcalLaserAPDPNRatiosRef>("ECAL Barrel Laser APDPN Ratios Ref- map ",
47  "iphi",
48  MAX_IPHI,
49  MIN_IPHI,
50  MAX_IPHI + 1,
51  "ieta",
53  -MAX_IETA,
54  MAX_IETA + 1) {
55  Base::setSingleIov(true);
56  }
57 
58  // Histogram2D::fill (virtual) needs be overridden - the implementation should use fillWithValue
59  bool fill() override {
60  auto tag = PlotBase::getTag<0>();
61  for (auto const& iov : tag.iovs) {
62  std::shared_ptr<EcalLaserAPDPNRatiosRef> payload = Base::fetchPayload(std::get<1>(iov));
63  if (payload.get()) {
64  // looping over the EB channels, via the dense-index, mapped into EBDetId's
65  if (payload->barrelItems().empty())
66  return false;
67  // set to -1 for ieta 0 (no crystal)
68  for (int iphi = MIN_IPHI; iphi < MAX_IPHI + 1; iphi++)
69  fillWithValue(iphi, 0, -1);
70 
71  for (int cellid = EBDetId::MIN_HASH; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) {
72  uint32_t rawid = EBDetId::unhashIndex(cellid);
73 
74  // check the existence of ECAL LaserAPDPNRatiosRef, for a given ECAL barrel channel
76  if (value_ptr == payload->end())
77  continue; // cell absent from payload
78 
79  float weight = (float)(*value_ptr);
80 
81  // fill the Histogram2D here
82  fillWithValue((EBDetId(rawid)).iphi(), (EBDetId(rawid)).ieta(), weight);
83  } // loop over cellid
84  } // if payload.get()
85  } // loop over IOV's (1 in this case)
86 
87  return true;
88 
89  } //fill method
90  };
91 
92  /****************************************************************
93  2d histogram of ECAL EndCaps Laser APDPN Ratios Ref of 1 IOV
94  ****************************************************************/
95  class EcalLaserAPDPNRatiosRefEEMap : public cond::payloadInspector::Histogram2D<EcalLaserAPDPNRatiosRef> {
96  private:
97  int EEhistSplit = 20;
98 
99  public:
100  EcalLaserAPDPNRatiosRefEEMap()
101  : cond::payloadInspector::Histogram2D<EcalLaserAPDPNRatiosRef>("ECAL Endcap Laser APDPN Ratios Ref- map ",
102  "ix",
103  EEhistXMax,
104  IX_MIN,
105  EEhistXMax + 1,
106  "iy",
107  IY_MAX,
108  IY_MIN,
109  IY_MAX + 1) {
110  Base::setSingleIov(true);
111  }
112 
113  bool fill() override {
114  auto tag = PlotBase::getTag<0>();
115  for (auto const& iov : tag.iovs) {
116  std::shared_ptr<EcalLaserAPDPNRatiosRef> payload = Base::fetchPayload(std::get<1>(iov));
117  if (payload.get()) {
118  if (payload->endcapItems().empty())
119  return false;
120 
121  // set to -1 everywhwere
122  for (int ix = IX_MIN; ix < EEhistXMax + 1; ix++)
123  for (int iy = IY_MAX; iy < IY_MAX + 1; iy++)
124  fillWithValue(ix, iy, -1);
125 
126  for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) { // loop on EE cells
127  if (EEDetId::validHashIndex(cellid)) {
128  uint32_t rawid = EEDetId::unhashIndex(cellid);
129  EcalFloatCondObjectContainer::const_iterator value_ptr = payload->find(rawid);
130  if (value_ptr == payload->end())
131  continue; // cell absent from payload
132 
133  float weight = (float)(*value_ptr);
134  EEDetId myEEId(rawid);
135  if (myEEId.zside() == -1)
136  fillWithValue(myEEId.ix(), myEEId.iy(), weight);
137  else
138  fillWithValue(myEEId.ix() + IX_MAX + EEhistSplit, myEEId.iy(), weight);
139  } // validDetId
140  } // loop over cellid
141 
142  } // payload
143  } // loop over IOV's (1 in this case)
144  return true;
145  } // fill method
146  };
147 
148  /****************************************************
149  2d plot of Ecal Laser APDPN Ratios Ref of 1 IOV
150  ****************************************************/
151  class EcalLaserAPDPNRatiosRefPlot : public cond::payloadInspector::PlotImage<EcalLaserAPDPNRatiosRef> {
152  public:
153  EcalLaserAPDPNRatiosRefPlot()
154  : cond::payloadInspector::PlotImage<EcalLaserAPDPNRatiosRef>("Ecal Laser APDPN Ratios Ref - map ") {
155  setSingleIov(true);
156  }
157 
158  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
159  TH2F* barrel =
160  new TH2F("EB", "Laser APDPN Ratios Ref EB", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
161  TH2F* endc_p =
162  new TH2F("EE+", "Laser APDPN Ratios Ref EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
163  TH2F* endc_m =
164  new TH2F("EE-", "Laser APDPN Ratios Ref EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
165 
166  auto iov = iovs.front();
167  std::shared_ptr<EcalLaserAPDPNRatiosRef> payload = fetchPayload(std::get<1>(iov));
168  unsigned int run = std::get<0>(iov);
169 
170  if (payload.get()) {
171  if (payload->barrelItems().empty())
172  return false;
173 
174  fillEBMap_SingleIOV<EcalLaserAPDPNRatiosRef>(payload, barrel);
175 
176  if (payload->endcapItems().empty())
177  return false;
178 
179  fillEEMap_SingleIOV<EcalLaserAPDPNRatiosRef>(payload, endc_m, endc_p);
180 
181  } // payload
182 
183  gStyle->SetPalette(1);
184  gStyle->SetOptStat(0);
185  TCanvas canvas("CC map", "CC map", 1600, 450);
186  TLatex t1;
187  t1.SetNDC();
188  t1.SetTextAlign(26);
189  t1.SetTextSize(0.04);
190  t1.DrawLatex(0.5, 0.96, Form("Ecal Laser APDPN Ratios Ref, IOV %i", run));
191 
192  float xmi[3] = {0.0, 0.24, 0.76};
193  float xma[3] = {0.24, 0.76, 1.00};
194  std::array<std::unique_ptr<TPad>, 3> pad;
195  for (int obj = 0; obj < 3; obj++) {
196  pad[obj] = std::make_unique<TPad>(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
197  pad[obj]->Draw();
198  }
199  // EcalDrawMaps ICMap;
200  pad[0]->cd();
201  // ICMap.DrawEE(endc_m, 0., 2.);
202  DrawEE(endc_m, 0., 2.5);
203  pad[1]->cd();
204  // ICMap.DrawEB(barrel, 0., 2.);
205  DrawEB(barrel, 0., 2.5);
206  pad[2]->cd();
207  // ICMap.DrawEE(endc_p, 0., 2.);
208  DrawEE(endc_p, 0., 2.5);
209 
210  std::string ImageName(m_imageFileName);
211  canvas.SaveAs(ImageName.c_str());
212  return true;
213  } // fill method
214  };
215 
216  /********************************************************************
217  2d plot of Ecal Laser APDPN Ratios Ref difference between 2 IOVs
218  ********************************************************************/
219  template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags, int method>
220  class EcalLaserAPDPNRatiosRefBase : public cond::payloadInspector::PlotImage<EcalLaserAPDPNRatiosRef, nIOVs, ntags> {
221  public:
222  EcalLaserAPDPNRatiosRefBase()
223  : cond::payloadInspector::PlotImage<EcalLaserAPDPNRatiosRef, nIOVs, ntags>(
224  "Ecal Laser APDPN Ratios Ref difference ") {}
225 
226  bool fill() override {
227  TH2F* barrel =
228  new TH2F("EB", "Laser APDPN Ratios Ref EB", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
229  TH2F* endc_p =
230  new TH2F("EE+", "Laser APDPN Ratios Ref EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
231  TH2F* endc_m =
232  new TH2F("EE-", "Laser APDPN Ratios Ref EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
233  float pEBmin, pEEmin, pEBmax, pEEmax;
234  pEBmin = 10.;
235  pEEmin = 10.;
236  pEBmax = -10.;
237  pEEmax = -10.;
238 
239  unsigned int run[2];
240  std::string l_tagname[2];
241  float pEB[kEBChannels], pEE[kEEChannels];
242  auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
243  l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
244  auto firstiov = iovs.front();
245  run[0] = std::get<0>(firstiov);
246  std::tuple<cond::Time_t, cond::Hash> lastiov;
247  if (ntags == 2) {
248  auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
249  l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
250  lastiov = tag2iovs.front();
251  } else {
252  lastiov = iovs.back();
253  l_tagname[1] = l_tagname[0];
254  }
255  run[1] = std::get<0>(lastiov);
256 
257  for (int irun = 0; irun < nIOVs; irun++) {
258  std::shared_ptr<EcalLaserAPDPNRatiosRef> payload;
259  if (irun == 0) {
260  payload = this->fetchPayload(std::get<1>(firstiov));
261  } else {
262  payload = this->fetchPayload(std::get<1>(lastiov));
263  }
264  if (payload.get()) {
265  if (!payload->barrelItems().empty())
266  fillEBMap_TwoIOVs<EcalLaserAPDPNRatiosRef>(payload, barrel, irun, pEB, pEBmin, pEBmax, method);
267  if (!payload->endcapItems().empty())
268  fillEEMap_TwoIOVs<EcalLaserAPDPNRatiosRef>(payload, endc_m, endc_p, irun, pEE, pEEmin, pEEmax, method);
269  } // payload
270  } // loop over IOVs
271 
272  gStyle->SetPalette(1);
273  gStyle->SetOptStat(0);
274  TCanvas canvas("CC map", "CC map", 1600, 450);
275  TLatex t1;
276  t1.SetNDC();
277  t1.SetTextAlign(26);
278  t1.SetTextSize(0.04);
279  t1.DrawLatex(0.5, 0.96, Form("Ecal Laser APDPN Ratios Ref Diff, IOV %i - %i", run[1], run[0]));
280 
281  float xmi[3] = {0.0, 0.24, 0.76};
282  float xma[3] = {0.24, 0.76, 1.00};
283  std::array<std::unique_ptr<TPad>, 3> pad;
284 
285  for (int obj = 0; obj < 3; obj++) {
286  pad[obj] = std::make_unique<TPad>(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
287  pad[obj]->Draw();
288  }
289 
290  pad[0]->cd();
291  DrawEE(endc_m, pEEmin, pEEmax);
292  pad[1]->cd();
293  DrawEB(barrel, pEBmin, pEBmax);
294  pad[2]->cd();
295  DrawEE(endc_p, pEEmin, pEEmax);
296 
297  std::string ImageName(this->m_imageFileName);
298  canvas.SaveAs(ImageName.c_str());
299  return true;
300  } // fill method
301  };
302  using EcalLaserAPDPNRatiosRefDiffOneTag = EcalLaserAPDPNRatiosRefBase<cond::payloadInspector::SINGLE_IOV, 1, 0>;
303  using EcalLaserAPDPNRatiosRefDiffTwoTags = EcalLaserAPDPNRatiosRefBase<cond::payloadInspector::SINGLE_IOV, 2, 0>;
304  using EcalLaserAPDPNRatiosRefRatioOneTag = EcalLaserAPDPNRatiosRefBase<cond::payloadInspector::SINGLE_IOV, 1, 1>;
305  using EcalLaserAPDPNRatiosRefRatioTwoTags = EcalLaserAPDPNRatiosRefBase<cond::payloadInspector::SINGLE_IOV, 2, 1>;
306 
307  /**********************************************************
308  2d plot of Ecal Laser APDPN Ratios Ref Summary of 1 IOV
309  **********************************************************/
310  class EcalLaserAPDPNRatiosRefSummaryPlot : public cond::payloadInspector::PlotImage<EcalLaserAPDPNRatiosRef> {
311  public:
312  EcalLaserAPDPNRatiosRefSummaryPlot()
313  : cond::payloadInspector::PlotImage<EcalLaserAPDPNRatiosRef>("Ecal Laser APDPN RatiosRef Summary- map ") {
314  setSingleIov(true);
315  }
316 
317  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
318  auto iov = iovs.front();
319  std::shared_ptr<EcalLaserAPDPNRatiosRef> payload = fetchPayload(std::get<1>(iov));
320  unsigned int run = std::get<0>(iov);
321  TH2F* align;
322  int NbRows;
323 
324  if (payload.get()) {
325  NbRows = 2;
326  align = new TH2F("", "", 0, 0, 0, 0, 0, 0);
327 
328  float mean_x_EB = 0.0f;
329  float mean_x_EE = 0.0f;
330 
331  float rms_EB = 0.0f;
332  float rms_EE = 0.0f;
333 
334  int num_x_EB = 0;
335  int num_x_EE = 0;
336 
337  payload->summary(mean_x_EB, rms_EB, num_x_EB, mean_x_EE, rms_EE, num_x_EE);
339  align, "Ecal Laser APDPN Ratios Ref", mean_x_EB, rms_EB, num_x_EB, mean_x_EE, rms_EE, num_x_EE);
340 
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("Ecal Laser APDPN Ratios Ref 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, 4);
360 
361  std::string ImageName(m_imageFileName);
362  canvas.SaveAs(ImageName.c_str());
363 
364  return true;
365  }
366  };
367 
368 } // namespace
369 
370 // Register the classes as boost python plugin
372  PAYLOAD_INSPECTOR_CLASS(EcalLaserAPDPNRatiosRefEBMap);
373  PAYLOAD_INSPECTOR_CLASS(EcalLaserAPDPNRatiosRefEEMap);
374  PAYLOAD_INSPECTOR_CLASS(EcalLaserAPDPNRatiosRefPlot);
375  PAYLOAD_INSPECTOR_CLASS(EcalLaserAPDPNRatiosRefDiffOneTag);
376  PAYLOAD_INSPECTOR_CLASS(EcalLaserAPDPNRatiosRefDiffTwoTags);
377  PAYLOAD_INSPECTOR_CLASS(EcalLaserAPDPNRatiosRefRatioOneTag);
378  PAYLOAD_INSPECTOR_CLASS(EcalLaserAPDPNRatiosRefRatioTwoTags);
379  PAYLOAD_INSPECTOR_CLASS(EcalLaserAPDPNRatiosRefSummaryPlot);
380 }
void fillTableWithSummary(TH2F *&align, std::string title, const float &mean_x_EB, const float &rms_EB, const int &num_x_EB, const float &mean_x_EE, const float &rms_EE, const int &num_x_EE)
Definition: weight.py:1
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)
static const int MIN_HASH
Definition: EBDetId.h:149
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
std::vector< Item >::const_iterator const_iterator
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
void drawTable(int nbRows, int nbColumns)
Definition: EcalDrawUtils.h:91