CMS 3D CMS Logo

EcalFloatCondObjectContainer_PayloadInspector.cc
Go to the documentation of this file.
6 
7 // the data format of the condition to be inspected
9 
10 #include "TH2F.h"
11 #include "TCanvas.h"
12 #include "TStyle.h"
13 #include "TLine.h"
14 #include "TLatex.h"
15 
16 #include <string>
17 
18 namespace {
19  enum { kEBChannels = 61200, kEEChannels = 14648, kSides = 2, kRMS = 5 };
20  enum { MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 85, MAX_IPHI = 360 }; // barrel lower and upper bounds on eta and phi
21  enum { IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100 }; // endcaps lower and upper bounds on x and y
22 
23  /*****************************************************
24  2d plot of ECAL FloatCondObjectContainer of 1 IOV
25  *****************************************************/
26  class EcalFloatCondObjectContainerPlot : public cond::payloadInspector::PlotImage<EcalFloatCondObjectContainer> {
27  public:
28  EcalFloatCondObjectContainerPlot()
29  : cond::payloadInspector::PlotImage<EcalFloatCondObjectContainer>("ECAL FloatCondObjectContainer - 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", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
35  TH2F* endc_p = new TH2F("EE+", "EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
36  TH2F* endc_m = new TH2F("EE-", "EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
37  double EBmean = 0., EBrms = 0., EEmean = 0., EErms = 0.;
38  int EBtot = 0, EEtot = 0;
39 
40  auto iov = iovs.front();
41  std::shared_ptr<EcalFloatCondObjectContainer> payload = fetchPayload(std::get<1>(iov));
42  unsigned int run = std::get<0>(iov);
43  if (payload.get()) {
44  for (int ieta = -MAX_IETA; ieta <= MAX_IETA; ieta++) {
45  Double_t eta = (Double_t)ieta;
46  if (ieta == 0)
47  continue;
48  else if (ieta > 0.)
49  eta = eta - 0.5; // 0.5 to 84.5
50  else
51  eta = eta + 0.5; // -84.5 to -0.5
52  for (int iphi = 1; iphi <= MAX_IPHI; iphi++) {
53  Double_t phi = (Double_t)iphi - 0.5;
54  EBDetId id(ieta, iphi);
55  double val = (*payload)[id.rawId()];
56  barrel->Fill(phi, eta, val);
57  EBmean = EBmean + val;
58  EBrms = EBrms + val * val;
59  EBtot++;
60  }
61  }
62 
63  for (int sign = 0; sign < kSides; sign++) {
64  int thesign = sign == 1 ? 1 : -1;
65  for (int ix = 1; ix <= IX_MAX; ix++) {
66  for (int iy = 1; iy <= IY_MAX; iy++) {
67  if (!EEDetId::validDetId(ix, iy, thesign))
68  continue;
69  EEDetId id(ix, iy, thesign);
70  double val = (*payload)[id.rawId()];
71  EEmean = EEmean + val;
72  EErms = EErms + val * val;
73  EEtot++;
74  if (thesign == 1)
75  endc_p->Fill(ix, iy, val);
76  else
77  endc_m->Fill(ix, iy, val);
78  } // iy
79  } // ix
80  } // side
81  } // payload
82  double vt = (double)EBtot;
83  EBmean = EBmean / vt;
84  EBrms = EBrms / vt - (EBmean * EBmean);
85  EBrms = sqrt(EBrms);
86  if (EBrms == 0.)
87  EBrms = 0.001;
88  double pEBmin = EBmean - kRMS * EBrms;
89  double pEBmax = EBmean + kRMS * EBrms;
90  // std::cout << " mean " << EBmean << " rms " << EBrms << " entries " << EBtot << " min " << pEBmin << " max " << pEBmax << std::endl;
91  vt = (double)EEtot;
92  EEmean = EEmean / vt;
93  EErms = EErms / vt - (EEmean * EEmean);
94  EErms = sqrt(EErms);
95  if (EErms == 0.)
96  EErms = 0.001;
97  double pEEmin = EEmean - kRMS * EErms;
98  double pEEmax = EEmean + kRMS * EErms;
99  // std::cout << " mean " << EEmean << " rms " << EErms << " entries " << EEtot << " min " << pEEmin << " max " << pEEmax << std::endl;
100 
101  gStyle->SetPalette(1);
102  gStyle->SetOptStat(0);
103  TCanvas canvas("CC map", "CC map", 1600, 450);
104  TLatex t1;
105  t1.SetNDC();
106  t1.SetTextAlign(26);
107  t1.SetTextSize(0.05);
108  t1.DrawLatex(0.5, 0.96, Form("Ecal FloatCondObjectContainer, IOV %i", run));
109 
110  float xmi[3] = {0.0, 0.24, 0.76};
111  float xma[3] = {0.24, 0.76, 1.00};
112  TPad** pad = new TPad*[3];
113  for (int obj = 0; obj < 3; obj++) {
114  pad[obj] = new TPad(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
115  pad[obj]->Draw();
116  }
117 
118  pad[0]->cd();
119  DrawEE(endc_m, pEEmin, pEEmax);
120  pad[1]->cd();
121  DrawEB(barrel, pEBmin, pEBmax);
122  pad[2]->cd();
123  DrawEE(endc_p, pEEmin, pEEmax);
124 
125  std::string ImageName(m_imageFileName);
126  canvas.SaveAs(ImageName.c_str());
127  return true;
128  } // fill method
129  };
130 
131  /************************************************************************
132  2d plot of ECAL FloatCondObjectContainer difference between 2 IOVs
133  ************************************************************************/
134  template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
135  class EcalFloatCondObjectContainerDiffBase
136  : public cond::payloadInspector::PlotImage<EcalFloatCondObjectContainer, nIOVs, ntags> {
137  public:
138  EcalFloatCondObjectContainerDiffBase()
139  : cond::payloadInspector::PlotImage<EcalFloatCondObjectContainer, nIOVs, ntags>(
140  "ECAL FloatCondObjectContainer difference") {}
141 
142  bool fill() override {
143  TH2F* barrel = new TH2F("EB", "EB difference", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
144  TH2F* endc_p = new TH2F("EE+", "EE+ difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
145  TH2F* endc_m = new TH2F("EE-", "EE- difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
146  double EBmean = 0., EBrms = 0., EEmean = 0., EErms = 0.;
147  int EBtot = 0, EEtot = 0;
148 
149  unsigned int run[2];
150  float vEB[kEBChannels], vEE[kEEChannels];
151  std::string l_tagname[2];
152  auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
153  l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
154  auto firstiov = iovs.front();
155  run[0] = std::get<0>(firstiov);
156  std::tuple<cond::Time_t, cond::Hash> lastiov;
157  if (ntags == 2) {
158  auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
159  l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
160  lastiov = tag2iovs.front();
161  } else {
162  lastiov = iovs.back();
163  l_tagname[1] = l_tagname[0];
164  }
165  run[1] = std::get<0>(lastiov);
166  for (int irun = 0; irun < nIOVs; irun++) {
167  std::shared_ptr<EcalFloatCondObjectContainer> payload;
168  if (irun == 0) {
169  payload = this->fetchPayload(std::get<1>(firstiov));
170  } else {
171  payload = this->fetchPayload(std::get<1>(lastiov));
172  }
173  if (payload.get()) {
174  for (int ieta = -MAX_IETA; ieta <= MAX_IETA; ieta++) {
175  Double_t eta = (Double_t)ieta;
176  if (ieta == 0)
177  continue;
178  else if (ieta > 0.)
179  eta = eta - 0.5; // 0.5 to 84.5
180  else
181  eta = eta + 0.5; // -84.5 to -0.5
182  for (int iphi = 1; iphi <= MAX_IPHI; iphi++) {
183  Double_t phi = (Double_t)iphi - 0.5;
184  EBDetId id(ieta, iphi);
185  int channel = id.hashedIndex();
186  double val = (*payload)[id.rawId()];
187  if (irun == 0)
188  vEB[channel] = val;
189  else {
190  double diff = val - vEB[channel];
191  barrel->Fill(phi, eta, diff);
192  EBmean = EBmean + diff;
193  EBrms = EBrms + diff * diff;
194  EBtot++;
195  // std::cout << " entry " << EBtot << " mean " << EBmean << " rms " << EBrms << std::endl;
196  }
197  }
198  }
199 
200  for (int sign = 0; sign < kSides; sign++) {
201  int thesign = sign == 1 ? 1 : -1;
202  for (int ix = 1; ix <= IX_MAX; ix++) {
203  for (int iy = 1; iy <= IY_MAX; iy++) {
204  if (!EEDetId::validDetId(ix, iy, thesign))
205  continue;
206  EEDetId id(ix, iy, thesign);
207  int channel = id.hashedIndex();
208  double val = (*payload)[id.rawId()];
209  if (irun == 0)
210  vEE[channel] = val;
211  else {
212  double diff = val - vEE[channel];
213  EEmean = EEmean + diff;
214  EErms = EErms + diff * diff;
215  EEtot++;
216  if (thesign == 1)
217  endc_p->Fill(ix, iy, diff);
218  else
219  endc_m->Fill(ix, iy, diff);
220  }
221  } // iy
222  } // ix
223  } // side
224  } // payload
225  else
226  return false;
227  } // loop over IOVs
228 
229  double vt = (double)EBtot;
230  EBmean = EBmean / vt;
231  EBrms = EBrms / vt - (EBmean * EBmean);
232  EBrms = sqrt(EBrms);
233  if (EBrms == 0.)
234  EBrms = 0.001;
235  double pEBmin = EBmean - kRMS * EBrms;
236  double pEBmax = EBmean + kRMS * EBrms;
237  // std::cout << " mean " << EBmean << " rms " << EBrms << " entries " << EBtot << " min " << pEBmin << " max " << pEBmax << std::endl;
238  vt = (double)EEtot;
239  EEmean = EEmean / vt;
240  EErms = EErms / vt - (EEmean * EEmean);
241  EErms = sqrt(EErms);
242  if (EErms == 0.)
243  EErms = 0.001;
244  double pEEmin = EEmean - kRMS * EErms;
245  double pEEmax = EEmean + kRMS * EErms;
246  // std::cout << " mean " << EEmean << " rms " << EErms << " entries " << EEtot << " min " << pEEmin << " max " << pEEmax << std::endl;
247 
248  gStyle->SetPalette(1);
249  gStyle->SetOptStat(0);
250  TCanvas canvas("CC map", "CC map", 1600, 450);
251  TLatex t1;
252  t1.SetNDC();
253  t1.SetTextAlign(26);
254  int len = l_tagname[0].length() + l_tagname[1].length();
255  if (ntags == 2 && len < 150) {
256  t1.SetTextSize(0.04);
257  t1.DrawLatex(
258  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]));
259  } else {
260  t1.SetTextSize(0.05);
261  t1.DrawLatex(0.5, 0.96, Form("%s, IOV %i - %i", l_tagname[0].c_str(), run[1], run[0]));
262  }
263  float xmi[3] = {0.0, 0.24, 0.76};
264  float xma[3] = {0.24, 0.76, 1.00};
265  TPad** pad = new TPad*[3];
266  for (int obj = 0; obj < 3; obj++) {
267  pad[obj] = new TPad(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
268  pad[obj]->Draw();
269  }
270 
271  pad[0]->cd();
272  DrawEE(endc_m, pEEmin, pEEmax);
273  pad[1]->cd();
274  DrawEB(barrel, pEBmin, pEBmax);
275  pad[2]->cd();
276  DrawEE(endc_p, pEEmin, pEEmax);
277 
278  std::string ImageName(this->m_imageFileName);
279  canvas.SaveAs(ImageName.c_str());
280  return true;
281  } // fill method
282  }; // class EcalFloatCondObjectContainerDiffBase
283  using EcalFloatCondObjectContainerDiffOneTag =
284  EcalFloatCondObjectContainerDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
285  using EcalFloatCondObjectContainerDiffTwoTags =
286  EcalFloatCondObjectContainerDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
287 } // namespace
288 
289 // Register the classes as boost python plugin
291  PAYLOAD_INSPECTOR_CLASS(EcalFloatCondObjectContainerPlot);
292  PAYLOAD_INSPECTOR_CLASS(EcalFloatCondObjectContainerDiffOneTag);
293  PAYLOAD_INSPECTOR_CLASS(EcalFloatCondObjectContainerDiffTwoTags);
294 }
static const int kSides
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)
T sqrt(T t)
Definition: SSEVec.h:19
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
def canvas(sub, attr)
Definition: svgfig.py:482
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)