CMS 3D CMS Logo

EcalPulseCovariances_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, TEMPLATESAMPLES = 12 };
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 PulseCovariances of 1 IOV
25  *****************************************************/
26  class EcalPulseCovariancesPlot : public cond::payloadInspector::PlotImage<EcalPulseCovariances> {
27  public:
28  EcalPulseCovariancesPlot()
29  : cond::payloadInspector::PlotImage<EcalPulseCovariances>("ECAL PulseCovariances - 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*[TEMPLATESAMPLES];
35  TH2F** endc_p = new TH2F*[TEMPLATESAMPLES];
36  TH2F** endc_m = new TH2F*[TEMPLATESAMPLES];
37  // long double EBmean[TEMPLATESAMPLES], EBrms[TEMPLATESAMPLES], EEmean[TEMPLATESAMPLES], EErms[TEMPLATESAMPLES];
38  // int EBtot[TEMPLATESAMPLES], EEtot[TEMPLATESAMPLES];
39  double pEBmin[TEMPLATESAMPLES], pEBmax[TEMPLATESAMPLES], pEEmin[TEMPLATESAMPLES], pEEmax[TEMPLATESAMPLES];
40  for (int s = 0; s < TEMPLATESAMPLES; ++s) {
41  barrel[s] = new TH2F(
42  Form("EBs%i", s), Form("sample %i EB", s), MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
43  endc_p[s] = new TH2F(
44  Form("EE+s%i", s), Form("sample %i EE+", s), IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
45  endc_m[s] = new TH2F(
46  Form("EE-s%i", s), Form("sample %i EE-", s), IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
47  /* EBmean[s] = 0.;
48  EBrms[s] = 0.;
49  EEmean[s] = 0.;
50  EErms[s] = 0.;
51  EBtot[s] = 0;
52  EEtot[s] = 0;*/
53  pEBmin[s] = 10.;
54  pEBmax[s] = -10.;
55  pEEmin[s] = 10.;
56  pEEmax[s] = -10.;
57  }
58 
59  auto iov = iovs.front();
60  std::shared_ptr<EcalPulseCovariances> payload = fetchPayload(std::get<1>(iov));
61  unsigned int run = std::get<0>(iov);
62  if (payload.get()) {
63  // int chan = 0;
64  for (int ieta = -MAX_IETA; ieta <= MAX_IETA; ieta++) {
65  Double_t eta = (Double_t)ieta;
66  if (ieta == 0)
67  continue;
68  else if (ieta > 0.)
69  eta = eta - 0.5; // 0.5 to 84.5
70  else
71  eta = eta + 0.5; // -84.5 to -0.5
72  for (int iphi = 1; iphi <= MAX_IPHI; iphi++) {
73  Double_t phi = (Double_t)iphi - 0.5;
74  EBDetId id(ieta, iphi);
75  /*
76  chan++;
77  if(chan < 20) std::cout << " channel " << chan << " hash " << id.hashedIndex() << " raw " << id.rawId() << std::endl;
78  int rawId = id.rawId();
79  EcalPulseCovariance pulse = (*payload)[rawId];
80  if(chan < 20) {
81  for(int i = 0; i < TEMPLATESAMPLES; ++i) {
82  std::cout << std::setw(2) << i;
83  for(int j = 0; j < TEMPLATESAMPLES; ++j) {
84  double val = pulse.covval[i][j];
85  std::cout << " " << std::setw(10) << val ;
86  }
87  std::cout << std::endl;
88  }
89  }
90  */
91  for (int s = 0; s < TEMPLATESAMPLES; ++s) {
92  double val = (*payload)[id.rawId()].covval[0][s];
93  barrel[s]->Fill(phi, eta, val);
94  // EBmean[s] = EBmean[s] + val;
95  // EBrms[s] = EBrms[s] + val * val;
96  // EBtot[s]++;
97  if (val < pEBmin[s])
98  pEBmin[s] = val;
99  if (val > pEBmax[s])
100  pEBmax[s] = val;
101  }
102  }
103  }
104 
105  for (int sign = 0; sign < kSides; sign++) {
106  int thesign = sign == 1 ? 1 : -1;
107  for (int ix = 1; ix <= IX_MAX; ix++) {
108  for (int iy = 1; iy <= IY_MAX; iy++) {
109  if (!EEDetId::validDetId(ix, iy, thesign))
110  continue;
111  EEDetId id(ix, iy, thesign);
112  for (int s = 0; s < TEMPLATESAMPLES; ++s) {
113  double val = (*payload)[id.rawId()].covval[0][s];
114  // EEmean[s] = EEmean[s] + val;
115  // EErms[s] = EErms[s] + val * val;
116  // EEtot[s]++;
117  if (val < pEEmin[s])
118  pEEmin[s] = val;
119  if (val > pEEmax[s])
120  pEEmax[s] = val;
121  if (thesign == 1)
122  endc_p[s]->Fill(ix, iy, val);
123  else
124  endc_m[s]->Fill(ix, iy, val);
125  }
126  } // iy
127  } // ix
128  } // side
129  } // payload
130  /*
131  for(int s = 0; s < TEMPLATESAMPLES; ++s) {
132  std::cout << "EB sample " << s << " mean " << EBmean[s] << " rms " << EBrms[s] << " entries " << EBtot[s]
133  << " EE mean " << EEmean[s] << " rms " << EErms[s] << " entries " << EEtot[s] << std::endl;
134  double vt =(double)EBtot[s];
135  EBmean[s] = EBmean[s] / vt;
136  EBrms[s] = EBrms[s] / vt - (EBmean[s] * EBmean[s]);
137  if(EBrms[s] > 0) EBrms[s] = sqrt(EBrms[s]);
138  else EBrms[s] = 1.e-06;
139  pEBmin[s] = EBmean[s] - kRMS * EBrms[s];
140  pEBmax[s] = EBmean[s] + kRMS * EBrms[s];
141  std::cout << "EB sample " << s << " mean " << EBmean[s] << " rms " << EBrms[s] << " entries " << EBtot[s] << " min " << pEBmin[s] << " max " << pEBmax[s] << std::endl;
142  // if(pEBmin[s] <= 0.) pEBmin[s] = 1.e-06;
143  vt =(double)EEtot[s];
144  EEmean[s] = EEmean[s] / vt;
145  EErms[s] = EErms[s] / vt - (EEmean[s] * EEmean[s]);
146  if(EErms[s] > 0) EErms[s] = sqrt(EErms[s]);
147  else EErms[s] = 1.e-06;
148  pEEmin[s] = EEmean[s] - kRMS * EErms[s];
149  pEEmax[s] = EEmean[s] + kRMS * EErms[s];
150  std::cout << "EE sample " << s << " mean " << EEmean[s] << " rms " << EErms[s] << " entries " << EEtot[s] << " min " << pEEmin[s] << " max " << pEEmax[s] << std::endl;
151  // if(pEEmin[s] <= 0.) pEEmin[s] = 1.e-06;
152  }
153  */
154  // for(int s = 0; s < TEMPLATESAMPLES; ++s)
155  // std::cout << " sample " << s << " EB min " << pEBmin[s] << " max " << pEBmax[s] << " EE min " << pEEmin[s] << " max " << pEEmax[s] << std::endl;
156  gStyle->SetPalette(1);
157  gStyle->SetOptStat(0);
158  TCanvas canvas("CC map", "CC map", 1600, 2800);
159  TLatex t1;
160  t1.SetNDC();
161  t1.SetTextAlign(26);
162  t1.SetTextSize(0.05);
163  t1.DrawLatex(0.5, 0.96, Form("Ecal PulseCovariances, IOV %i", run));
164 
165  float xmi[3] = {0.0, 0.24, 0.76};
166  float xma[3] = {0.24, 0.76, 1.00};
167  TPad*** pad = new TPad**[6];
168  for (int s = 0; s < 6; s++) {
169  pad[s] = new TPad*[3];
170  for (int obj = 0; obj < 3; obj++) {
171  float yma = 0.94 - (0.16 * s);
172  float ymi = yma - 0.14;
173  pad[s][obj] = new TPad(Form("p_%i_%i", obj, s), Form("p_%i_%i", obj, s), xmi[obj], ymi, xma[obj], yma);
174  pad[s][obj]->Draw();
175  }
176  }
177 
178  int ipad = 0;
179  for (int s = 0; s < 7; ++s) { // plot only the measured ones, not the extrapolated
180  // for(int s = 7; s<12; ++s) { // plot only the extrapolated ones
181  if (s == 2)
182  continue; // do not plot the maximum sample, which is 0 by default
183  pad[ipad][0]->cd();
184  if (pEBmin[s] == pEBmax[s]) { // same values everywhere!..
185  pEBmin[s] = pEBmin[s] - 1.e-06;
186  pEBmax[s] = pEBmax[s] + 1.e-06;
187  }
188  if (pEEmin[s] == pEEmax[s]) {
189  pEEmin[s] = pEEmin[s] - 1.e-06;
190  pEEmax[s] = pEEmax[s] + 1.e-06;
191  }
192  DrawEE(endc_m[s], pEEmin[s], pEEmax[s]);
193  // pad[ipad][0]->SetLogz(1);
194  pad[ipad][1]->cd();
195  DrawEB(barrel[s], pEBmin[s], pEBmax[s]);
196  // pad[ipad][1]->SetLogz(1);
197  pad[ipad][2]->cd();
198  DrawEE(endc_p[s], pEEmin[s], pEEmax[s]);
199  // pad[ipad][2]->SetLogz(1);
200  ipad++;
201  }
202 
203  std::string ImageName(m_imageFileName);
204  canvas.SaveAs(ImageName.c_str());
205  return true;
206  } // fill method
207  };
208 
209  /*****************************************************
210  2d plot of ECAL PulseCovariances matrix of 1 IOV
211  *****************************************************/
212  class EcalPulseCovariancesMatrix : public cond::payloadInspector::PlotImage<EcalPulseCovariances> {
213  public:
214  EcalPulseCovariancesMatrix()
215  : cond::payloadInspector::PlotImage<EcalPulseCovariances>("ECAL PulseCovariances - matrix ") {
216  setSingleIov(true);
217  }
218 
219  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
220  double EBmean[TEMPLATESAMPLES][TEMPLATESAMPLES], EBrms[TEMPLATESAMPLES][TEMPLATESAMPLES],
221  EEmean[TEMPLATESAMPLES][TEMPLATESAMPLES], EErms[TEMPLATESAMPLES][TEMPLATESAMPLES];
222  for (int i = 0; i < TEMPLATESAMPLES; i++) {
223  for (int j = 0; j < TEMPLATESAMPLES; j++) {
224  EBmean[i][j] = 0.;
225  EBrms[i][j] = 0.;
226  EEmean[i][j] = 0.;
227  EErms[i][j] = 0.;
228  }
229  }
230 
231  auto iov = iovs.front();
232  std::shared_ptr<EcalPulseCovariances> payload = fetchPayload(std::get<1>(iov));
233  unsigned int run = std::get<0>(iov);
234  if (payload.get()) {
235  for (int ieta = -MAX_IETA; ieta <= MAX_IETA; ieta++) {
236  for (int iphi = 1; iphi <= MAX_IPHI; iphi++) {
237  EBDetId id(ieta, iphi);
238  for (int i = 0; i < TEMPLATESAMPLES; ++i) {
239  for (int j = 0; j < TEMPLATESAMPLES; ++j) {
240  double val = (*payload)[id.rawId()].covval[i][j];
241  EBmean[i][j] = EBmean[i][j] + val;
242  EBrms[i][j] = EBrms[i][j] + val * val;
243  }
244  }
245  }
246  }
247 
248  for (int sign = 0; sign < kSides; sign++) {
249  int thesign = sign == 1 ? 1 : -1;
250  for (int ix = 1; ix <= IX_MAX; ix++) {
251  for (int iy = 1; iy <= IY_MAX; iy++) {
252  if (!EEDetId::validDetId(ix, iy, thesign))
253  continue;
254  EEDetId id(ix, iy, thesign);
255  for (int i = 0; i < TEMPLATESAMPLES; i++) {
256  for (int j = 0; j < TEMPLATESAMPLES; j++) {
257  double val = (*payload)[id.rawId()].covval[i][j];
258  EEmean[i][j] = EEmean[i][j] + val;
259  EErms[i][j] = EErms[i][j] + val * val;
260  }
261  }
262  } // iy
263  } // ix
264  } // side
265  } // payload
266 
267  TH2F* barrel_m =
268  new TH2F("EBm", "EB mean", TEMPLATESAMPLES, 0, TEMPLATESAMPLES, TEMPLATESAMPLES, 0., TEMPLATESAMPLES);
269  TH2F* barrel_r =
270  new TH2F("EBr", "EB rms", TEMPLATESAMPLES, 0, TEMPLATESAMPLES, TEMPLATESAMPLES, 0., TEMPLATESAMPLES);
271  TH2F* endcap_m =
272  new TH2F("EEm", "EE mean", TEMPLATESAMPLES, 0, TEMPLATESAMPLES, TEMPLATESAMPLES, 0., TEMPLATESAMPLES);
273  TH2F* endcap_r =
274  new TH2F("EEr", "EE rms", TEMPLATESAMPLES, 0, TEMPLATESAMPLES, TEMPLATESAMPLES, 0., TEMPLATESAMPLES);
275  for (int i = 0; i < TEMPLATESAMPLES; i++) {
276  // std::cout << "EB sample " << i << std::endl
277  // std::cout << "EB sample " << i;
278  for (int j = 0; j < TEMPLATESAMPLES; j++) {
279  double vt = (double)kEBChannels;
280  EBmean[i][j] = EBmean[i][j] / vt;
281  barrel_m->Fill(i, j, EBmean[i][j]);
282  EBrms[i][j] = EBrms[i][j] / vt - (EBmean[i][j] * EBmean[i][j]);
283  if (EBrms[i][j] >= 0)
284  EBrms[i][j] = sqrt(EBrms[i][j]);
285  else
286  EBrms[i][j] = 0.;
287  barrel_r->Fill(i, j, EBrms[i][j]);
288  // std::cout << "EB sample " << j << " mean " << EBmean[i][j] << " rms " << EBrms[i][j] << std::endl;
289  // std::cout << " " << std::setw(10) << EBrms[i][j];
290  vt = (double)kEEChannels;
291  EEmean[i][j] = EEmean[i][j] / vt;
292  endcap_m->Fill(i, j, EEmean[i][j]);
293  EErms[i][j] = EErms[i][j] / vt - (EEmean[i][j] * EEmean[i][j]);
294  if (EErms[i][j] >= 0)
295  EErms[i][j] = sqrt(EErms[i][j]);
296  else
297  EErms[i][j] = 0.;
298  endcap_r->Fill(i, j, EErms[i][j]);
299  // std::cout << "EE sample " << j << " mean " << EEmean[i][j] << " rms " << EErms[i][j] << std::endl;
300  }
301  // std::cout << std::endl;
302  }
303 
304  gStyle->SetPalette(1);
305  gStyle->SetOptStat(0);
306  TCanvas canvas("CC map", "CC map", 1440, 1500);
307  TLatex t1;
308  t1.SetNDC();
309  t1.SetTextAlign(26);
310  t1.SetTextSize(0.05);
311  t1.DrawLatex(0.5, 0.96, Form("Ecal PulseCovariances, IOV %i", run));
312 
313  float xmi[2] = {0.0, 0.5};
314  float xma[2] = {0.5, 1.0};
315  TPad*** pad = new TPad**[2];
316  for (int s = 0; s < 2; s++) {
317  pad[s] = new TPad*[2];
318  for (int obj = 0; obj < 2; obj++) {
319  float yma = 0.94 - (0.47 * s);
320  float ymi = yma - 0.45;
321  pad[s][obj] = new TPad(Form("p_%i_%i", obj, s), Form("p_%i_%i", obj, s), xmi[obj], ymi, xma[obj], yma);
322  pad[s][obj]->Draw();
323  }
324  }
325 
326  pad[0][0]->cd();
327  // barrel_m->Draw("COLZ1");
328  grid(barrel_m);
329  pad[0][1]->cd();
330  // endcap_m->Draw("COLZ1");
331  grid(endcap_m);
332  pad[1][0]->cd();
333  // barrel_r->Draw("COLZ1");
334  grid(barrel_r);
335  pad[1][1]->cd();
336  // endcap_r->Draw("COLZ1");
337  grid(endcap_r);
338 
339  std::string ImageName(m_imageFileName);
340  canvas.SaveAs(ImageName.c_str());
341  return true;
342  } // fill method
343 
344  void grid(TH2F* matrix) {
345  matrix->Draw("COLZ1");
346  TLine* lh = new TLine(1., 0., 1., 1.);
347  lh->SetLineWidth(2);
348  TLine* lv = new TLine(1., 0., 1., 1.);
349  lv->SetLineWidth(2);
350  // double max = (double)TEMPLATESAMPLES;
351  for (int i = 1; i < TEMPLATESAMPLES; i++) {
352  // double x = (double)i;
353  lv = new TLine(i, 0., i, TEMPLATESAMPLES);
354  lv->Draw();
355  lh = new TLine(0., i, TEMPLATESAMPLES, i);
356  lh->Draw();
357  }
358  }
359  };
360 
361 } // namespace
362 
363 // Register the classes as boost python plugin
365  PAYLOAD_INSPECTOR_CLASS(EcalPulseCovariancesPlot);
366  PAYLOAD_INSPECTOR_CLASS(EcalPulseCovariancesMatrix);
367 }
static const int kSides
bool int lh
Definition: SIMDVec.h:20
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)
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
Definition: plugin.cc:23
def canvas(sub, attr)
Definition: svgfig.py:482
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)