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