CMS 3D CMS Logo

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