CMS 3D CMS Logo

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