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