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
|
#include "DQM/SiStripCommissioningAnalysis/interface/DaqScopeModeAlgorithm.h"
#include "CondFormats/SiStripObjects/interface/DaqScopeModeAnalysis.h"
#include "DataFormats/SiStripCommon/interface/SiStripHistoTitle.h"
#include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "TH1.h"
#include "TProfile.h"
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace sistrip;
// ----------------------------------------------------------------------------
//
DaqScopeModeAlgorithm::DaqScopeModeAlgorithm(const edm::ParameterSet& pset, DaqScopeModeAnalysis* const anal)
: CommissioningAlgorithm(anal),
histo_(nullptr, ""),
headerLow_(nullptr, ""),
headerHigh_(nullptr, ""),
hPeds_(nullptr, ""),
hNoise_(nullptr, ""),
deadStripMax_(pset.getParameter<double>("DeadStripMax")),
noisyStripMin_(pset.getParameter<double>("NoisyStripMin")) {
;
}
// ----------------------------------------------------------------------------
//
void DaqScopeModeAlgorithm::extract(const std::vector<TH1*>& histos) {
if (!anal()) {
edm::LogWarning(mlCommissioning_) << "[DaqScopeModeAlgorithm::" << __func__ << "]"
<< " NULL pointer to base Analysis object!";
return;
}
// Extract FED key from histo title
if (!histos.empty()) {
anal()->fedKey(extractFedKey(histos.front()));
}
// Extract histograms
std::vector<TH1*>::const_iterator ihis = histos.begin();
for (; ihis != histos.end(); ihis++) {
// Check for NULL pointer
if (!(*ihis)) {
continue;
}
// Check name
SiStripHistoTitle title((*ihis)->GetName());
if (title.runType() != sistrip::DAQ_SCOPE_MODE) {
anal()->addErrorCode(sistrip::unexpectedTask_);
continue;
}
// Extract timing histo
// Extract peds and noise histos (check for legacy names first!)
if (title.extraInfo().find(sistrip::extrainfo::pedsAndRawNoise_) != std::string::npos) {
hPeds_.first = *ihis;
hPeds_.second = (*ihis)->GetName();
} else if (title.extraInfo().find(sistrip::extrainfo::pedsAndCmSubNoise_) != std::string::npos) {
hNoise_.first = *ihis;
hNoise_.second = (*ihis)->GetName();
} else if (title.extraInfo().find(sistrip::extrainfo::pedestals_) != std::string::npos) {
hPeds_.first = *ihis;
hPeds_.second = (*ihis)->GetName();
} else if (title.extraInfo().find(sistrip::extrainfo::noise_) != std::string::npos) {
hNoise_.first = *ihis;
hNoise_.second = (*ihis)->GetName();
} else if (title.extraInfo().find(sistrip::extrainfo::commonMode_) != std::string::npos) {
//@@ something here for CM plots?
} else if (title.extraInfo().find(sistrip::extrainfo::scopeModeFrame_) != std::string::npos) {
histo_.first = *ihis;
histo_.second = (*ihis)->GetName();
} else if (title.extraInfo().find(sistrip::extrainfo::scopeModeHeaderLow_) != std::string::npos) {
headerLow_.first = *ihis;
headerLow_.second = (*ihis)->GetName();
} else if (title.extraInfo().find(sistrip::extrainfo::scopeModeHeaderHigh_) != std::string::npos) {
headerHigh_.first = *ihis;
headerHigh_.second = (*ihis)->GetName();
}
}
}
// ----------------------------------------------------------------------------
//
void DaqScopeModeAlgorithm::analyse() {
if (!anal()) {
edm::LogWarning(mlCommissioning_) << "[DaqScopeModeAlgorithm::" << __func__ << "]"
<< " NULL pointer to base Analysis object!";
return;
}
CommissioningAnalysis* tmp = const_cast<CommissioningAnalysis*>(anal());
DaqScopeModeAnalysis* anal = dynamic_cast<DaqScopeModeAnalysis*>(tmp);
if (!anal) {
edm::LogWarning(mlCommissioning_) << "[DaqScopeModeAlgorithm::" << __func__ << "]"
<< " NULL pointer to derived Analysis object!";
return;
}
// Analysis level wants all the informations --> it will work only on Spy-events
if (!hPeds_.first) {
anal->addErrorCode(sistrip::nullPtr_);
return;
}
if (!hNoise_.first) {
anal->addErrorCode(sistrip::nullPtr_);
return;
}
if (!histo_.first) {
anal->addErrorCode(sistrip::nullPtr_);
return;
}
if (!headerLow_.first) {
anal->addErrorCode(sistrip::nullPtr_);
return;
}
if (!headerHigh_.first) {
anal->addErrorCode(sistrip::nullPtr_);
return;
}
/// pedestal
TProfile* peds_histo = dynamic_cast<TProfile*>(hPeds_.first);
TProfile* noise_histo = dynamic_cast<TProfile*>(hNoise_.first);
/// scope-mode profile
TProfile* scope_histo = dynamic_cast<TProfile*>(histo_.first);
TH1F* headerLow_histo = dynamic_cast<TH1F*>(headerLow_.first);
TH1F* headerHigh_histo = dynamic_cast<TH1F*>(headerHigh_.first);
if (!peds_histo) {
anal->addErrorCode(sistrip::nullPtr_);
return;
}
if (!noise_histo) {
anal->addErrorCode(sistrip::nullPtr_);
return;
}
if (!scope_histo) {
anal->addErrorCode(sistrip::nullPtr_);
return;
}
if (!headerLow_histo) {
anal->addErrorCode(sistrip::nullPtr_);
return;
}
if (!headerHigh_histo) {
anal->addErrorCode(sistrip::nullPtr_);
return;
}
if (peds_histo->GetNbinsX() != 256) {
anal->addErrorCode(sistrip::numberOfBins_);
return;
}
if (noise_histo->GetNbinsX() != 256) {
anal->addErrorCode(sistrip::numberOfBins_);
return;
}
if (scope_histo->GetNbinsX() != 298) {
anal->addErrorCode(sistrip::numberOfBins_);
return;
}
// Calculate pedestals and noise
// Iterate through APVs
for (uint16_t iapv = 0; iapv < 2; iapv++) {
// Used to calc mean and rms for peds and noise
float p_sum = 0., p_sum2 = 0., p_max = -1. * sistrip::invalid_, p_min = sistrip::invalid_;
float n_sum = 0., n_sum2 = 0., n_max = -1. * sistrip::invalid_, n_min = sistrip::invalid_;
float r_sum = 0., r_sum2 = 0., r_max = -1. * sistrip::invalid_, r_min = sistrip::invalid_;
// Iterate through strips of APV
for (uint16_t istr = 0; istr < 128; istr++) {
uint16_t strip = iapv * 128 + istr;
// Pedestals and raw noise
if (peds_histo) {
if (peds_histo->GetBinEntries(strip + 1)) {
anal->peds_[iapv][istr] = peds_histo->GetBinContent(strip + 1);
p_sum += anal->peds_[iapv][istr];
p_sum2 += (anal->peds_[iapv][istr] * anal->peds_[iapv][istr]);
if (anal->peds_[iapv][istr] > p_max) {
p_max = anal->peds_[iapv][istr];
}
if (anal->peds_[iapv][istr] < p_min) {
p_min = anal->peds_[iapv][istr];
}
anal->raw_[iapv][istr] = peds_histo->GetBinError(strip + 1);
r_sum += anal->raw_[iapv][istr];
r_sum2 += (anal->raw_[iapv][istr] * anal->raw_[iapv][istr]);
if (anal->raw_[iapv][istr] > r_max) {
r_max = anal->raw_[iapv][istr];
}
if (anal->raw_[iapv][istr] < r_min) {
r_min = anal->raw_[iapv][istr];
}
}
}
// Noise
if (noise_histo) {
if (noise_histo->GetBinEntries(strip + 1)) {
anal->noise_[iapv][istr] = noise_histo->GetBinContent(strip + 1);
n_sum += anal->noise_[iapv][istr];
n_sum2 += (anal->noise_[iapv][istr] * anal->noise_[iapv][istr]);
if (anal->noise_[iapv][istr] > n_max) {
n_max = anal->noise_[iapv][istr];
}
if (anal->noise_[iapv][istr] < n_min) {
n_min = anal->noise_[iapv][istr];
}
}
}
} // strip loop
// Calc mean and rms for peds
if (!anal->peds_[iapv].empty()) {
p_sum /= static_cast<float>(anal->peds_[iapv].size());
p_sum2 /= static_cast<float>(anal->peds_[iapv].size());
anal->pedsMean_[iapv] = p_sum;
anal->pedsSpread_[iapv] = sqrt(fabs(p_sum2 - p_sum * p_sum));
}
// Calc mean and rms for noise
if (!anal->noise_[iapv].empty()) {
n_sum /= static_cast<float>(anal->noise_[iapv].size());
n_sum2 /= static_cast<float>(anal->noise_[iapv].size());
anal->noiseMean_[iapv] = n_sum;
anal->noiseSpread_[iapv] = sqrt(fabs(n_sum2 - n_sum * n_sum));
}
// Calc mean and rms for raw noise
if (!anal->raw_[iapv].empty()) {
r_sum /= static_cast<float>(anal->raw_[iapv].size());
r_sum2 /= static_cast<float>(anal->raw_[iapv].size());
anal->rawMean_[iapv] = r_sum;
anal->rawSpread_[iapv] = sqrt(fabs(r_sum2 - r_sum * r_sum));
}
// Set max and min values for peds, noise and raw noise
if (p_max > -1. * sistrip::maximum_) {
anal->pedsMax_[iapv] = p_max;
}
if (p_min < 1. * sistrip::maximum_) {
anal->pedsMin_[iapv] = p_min;
}
if (n_max > -1. * sistrip::maximum_) {
anal->noiseMax_[iapv] = n_max;
}
if (n_min < 1. * sistrip::maximum_) {
anal->noiseMin_[iapv] = n_min;
}
if (r_max > -1. * sistrip::maximum_) {
anal->rawMax_[iapv] = r_max;
}
if (r_min < 1. * sistrip::maximum_) {
anal->rawMin_[iapv] = r_min;
}
// Set dead and noisy strips
for (uint16_t istr = 0; istr < 128; istr++) {
if (anal->noiseMin_[iapv] > sistrip::maximum_ || anal->noiseMax_[iapv] > sistrip::maximum_) {
continue;
}
if (anal->noise_[iapv][istr] < (anal->noiseMean_[iapv] - deadStripMax_ * anal->noiseSpread_[iapv])) {
anal->dead_[iapv].push_back(istr);
} else if (anal->noise_[iapv][istr] > (anal->noiseMean_[iapv] + noisyStripMin_ * anal->noiseSpread_[iapv])) {
anal->noisy_[iapv].push_back(istr);
}
}
} // apv loop
//// Tick-Mark --> just store values and check if the height is significant
//anal->peak_ = (scope_histo->GetBinContent(287)+scope_histo->GetBinContent(288))/2.;
//anal->base_ = (scope_histo->GetBinContent(1)+scope_histo->GetBinContent(2)+scope_histo->GetBinContent(3)+scope_histo->GetBinContent(4)+scope_histo->GetBinContent(5))/5.;
anal->peak_ = headerHigh_histo->GetMean();
anal->base_ = headerLow_histo->GetMean();
anal->height_ = anal->peak_ - anal->base_;
if (anal->height_ < DaqScopeModeAnalysis::tickMarkHeightThreshold_) {
anal->addErrorCode(sistrip::smallTickMarkHeight_);
return;
}
}
|