CMS 3D CMS Logo

DaqScopeModeTask.cc
Go to the documentation of this file.
8 
9 using namespace sistrip;
10 
11 // -----------------------------------------------------------------------------
12 //
14  : CommissioningTask(dqm, conn, "DaqScopeModeTask"),
15  scopeFrame_(),
16  nBins_(256), //@@ number of strips per FED channel
17  nBinsSpy_(298), //@@ in case of spy events includes header and trailing tick
18  parameters_(pset) {}
19 
20 // -----------------------------------------------------------------------------
21 //
23 
24 // -----------------------------------------------------------------------------
25 //
27  LogTrace(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]";
28 
30  if (not(parameters_.existsAs<bool>("isSpy") and parameters_.getParameter<bool>("isSpy"))) {
35  fedKey(),
37  connection().lldChannel(),
39  .title();
40 
41  scopeFrame_.histo(dqm()->book1D(title, title, nBins_, -0.5, nBins_ - 0.5));
42 
46  scopeFrame_.isProfile_ = false;
47  } else { // use spy run to measure pedestal and tick height
48 
49  std::string extra_info;
50  peds_.resize(2);
51  extra_info = sistrip::extrainfo::pedestals_;
52 
53  peds_[0].isProfile_ = true;
57  fedKey(),
59  connection().lldChannel(),
60  extra_info)
61  .title();
62 
63  peds_[0].histo(dqm()->bookProfile(title, title, nBins_, -0.5, nBins_ * 1. - 0.5, 1025, 0., 1025.));
64 
65  peds_[0].vNumOfEntries_.resize(nBins_, 0);
66  peds_[0].vSumOfContents_.resize(nBins_, 0);
67  peds_[0].vSumOfSquares_.resize(nBins_, 0);
68 
69  // Noise histogram
70  extra_info = sistrip::extrainfo::noise_;
71  peds_[1].isProfile_ = true;
72 
76  fedKey(),
78  connection().lldChannel(),
79  extra_info)
80  .title();
81 
82  peds_[1].histo(dqm()->bookProfile(title, title, nBins_, -0.5, nBins_ * 1. - 0.5, 1025, 0., 1025.));
83 
84  peds_[1].vNumOfEntries_.resize(nBins_, 0);
85  peds_[1].vSumOfContents_.resize(nBins_, 0);
86  peds_[1].vSumOfSquares_.resize(nBins_, 0);
87 
88  // Common mode histograms
89  cm_.resize(2);
90  int nbins = 1024;
91 
92  for (uint16_t iapv = 0; iapv < 2; iapv++) {
96  fedKey(),
98  connection().i2cAddr(iapv),
100  .title();
101 
102  cm_[iapv].histo(dqm()->book1D(title, title, nbins, -0.5, nbins * 1. - 0.5));
103  cm_[iapv].isProfile_ = false;
104 
105  cm_[iapv].vNumOfEntries_.resize(nbins, 0);
106  cm_[iapv].vNumOfEntries_.resize(nbins, 0);
107  }
108 
109  // high and low header histograms
113  fedKey(),
115  connection().lldChannel(),
117  .title();
118 
119  lowHeader_.histo(dqm()->book1D(title, title, nbins, -0.5, 1024 * 1. - 0.5));
120  lowHeader_.isProfile_ = false;
121  lowHeader_.vNumOfEntries_.resize(nbins, 0);
122 
126  fedKey(),
128  connection().lldChannel(),
130  .title();
131 
132  highHeader_.histo(dqm()->book1D(title, title, nbins, -0.5, 1024 * 1. - 0.5));
133  highHeader_.isProfile_ = false;
134  highHeader_.vNumOfEntries_.resize(nbins, 0);
135 
140  fedKey(),
142  connection().lldChannel(),
144  .title();
145 
146  scopeFrame_.histo(dqm()->bookProfile(title, title, nBinsSpy_, -0.5, nBinsSpy_ * 1. - 0.5, 1025, 0., 1025.));
147 
151  scopeFrame_.isProfile_ = true;
152  }
153 }
154 
155 // -----------------------------------------------------------------------------
156 //
158  // Only fill every 'N' events
159  if (not(parameters_.existsAs<bool>("isSpy") and parameters_.getParameter<bool>("isSpy"))) {
160  if (!updateFreq() || fillCntr() % updateFreq()) {
161  return;
162  }
163  }
164 
165  if (digis.data.size() != nBins_) { //@@ check scope mode length?
166  edm::LogWarning(mlDqmSource_) << "[DaqScopeModeTask::" << __func__ << "]"
167  << " Unexpected number of digis (" << digis.data.size()
168  << ") wrt number of histogram bins (" << nBins_ << ")!";
169  }
170 
171  if (not(parameters_.existsAs<bool>("isSpy") and parameters_.getParameter<bool>("isSpy"))) {
172  uint16_t bins = digis.data.size() < nBins_ ? digis.data.size() : nBins_;
173  for (uint16_t ibin = 0; ibin < bins; ibin++) {
174  updateHistoSet(scopeFrame_, ibin, digis.data[ibin].adc());
175  }
176  } else {
177  // fill the pedestal histograms as done in the pedestal task
178  // Check number of digis
179  uint16_t nbins = peds_[0].vNumOfEntries_.size();
180  if (digis.data.size() < nbins) {
181  nbins = digis.data.size();
182  }
183 
184  uint16_t napvs = nbins / 128;
185  std::vector<uint32_t> cm;
186  cm.resize(napvs, 0);
187 
188  // Calc common mode for both APVs
189  std::vector<uint16_t> adc;
190  for (uint16_t iapv = 0; iapv < napvs; iapv++) {
191  adc.clear();
192  adc.reserve(128);
193 
194  for (uint16_t ibin = 0; ibin < 128; ibin++) {
195  if ((iapv * 128) + ibin < nbins) {
196  adc.push_back(digis.data[(iapv * 128) + ibin].adc());
197  }
198  }
199 
200  sort(adc.begin(), adc.end());
201  uint16_t index = adc.size() % 2 ? adc.size() / 2 : adc.size() / 2 - 1;
202  if (!adc.empty()) {
203  cm[iapv] = static_cast<uint32_t>(adc[index]);
204  }
205  }
206 
207  for (uint16_t ibin = 0; ibin < nbins; ibin++) {
208  float digiVal = digis.data[ibin].adc();
209  updateHistoSet(peds_[0], ibin, digiVal); // peds and raw noise
210  float diff = digiVal - static_cast<float>(cm[ibin / 128]);
211  updateHistoSet(peds_[1], ibin, diff); // residuals and real noise
212  }
213 
214  if (cm.size() < cm_.size()) {
215  edm::LogWarning(mlDqmSource_) << "[PedestalsTask::" << __func__ << "]"
216  << " Fewer CM values than expected: " << cm.size();
217  }
218 
219  updateHistoSet(cm_[0], cm[0]);
220  updateHistoSet(cm_[1], cm[1]);
221  }
222 }
223 
224 // -----------------------------------------------------------------------------
225 //
227  const edm::DetSet<SiStripRawDigi>& digis,
228  const edm::DetSet<SiStripRawDigi>& digisAlt) {
229  // Only fill every 'N' events
230  if (not(parameters_.existsAs<bool>("isSpy") and parameters_.getParameter<bool>("isSpy"))) {
231  if (!updateFreq() || fillCntr() % updateFreq()) {
232  return;
233  }
234  }
235 
236  if (digis.data.size() != nBins_) { //@@ check scope mode length?
237  edm::LogWarning(mlDqmSource_) << "[DaqScopeModeTask::" << __func__ << "]"
238  << " Unexpected number of digis (" << digis.data.size()
239  << ") wrt number of histogram bins (" << nBins_ << ")!";
240  }
241 
242  if (not(parameters_.existsAs<bool>("isSpy") and parameters_.getParameter<bool>("isSpy"))) {
243  uint16_t bins = digis.data.size() < nBins_ ? digis.data.size() : nBins_;
244  for (uint16_t ibin = 0; ibin < bins; ibin++) {
245  updateHistoSet(scopeFrame_, ibin, digis.data[ibin].adc());
246  }
247  } else {
248  // fill the pedestal histograms as done in the pedestal task
249  // Check number of digis
250  uint16_t nbins = peds_[0].vNumOfEntries_.size();
251  if (digis.data.size() < nbins) {
252  nbins = digis.data.size();
253  }
254 
255  uint16_t napvs = nbins / 128;
256  std::vector<uint32_t> cm;
257  cm.resize(napvs, 0);
258 
259  // Calc common mode for both APVs
260  std::vector<uint16_t> adc;
261  for (uint16_t iapv = 0; iapv < napvs; iapv++) {
262  adc.clear();
263  adc.reserve(128);
264  for (uint16_t ibin = 0; ibin < 128; ibin++) {
265  if ((iapv * 128) + ibin < nbins) {
266  adc.push_back(digis.data[(iapv * 128) + ibin].adc());
267  }
268  }
269  sort(adc.begin(), adc.end());
270  uint16_t index = adc.size() % 2 ? adc.size() / 2 : adc.size() / 2 - 1;
271  if (!adc.empty()) {
272  cm[iapv] = static_cast<uint32_t>(adc[index]);
273  }
274  }
275 
277  for (uint16_t ibin = 0; ibin < nbins; ibin++) {
278  float digiVal = digis.data[ibin].adc();
279  updateHistoSet(peds_[0], ibin, digiVal); // peds and raw noise
280  float diff = digiVal - static_cast<float>(cm[ibin / 128]);
281  updateHistoSet(peds_[1], ibin, diff); // residuals and real noise
282  }
283 
284  if (cm.size() < cm_.size()) {
285  edm::LogWarning(mlDqmSource_) << "[PedestalsTask::" << __func__ << "]"
286  << " Fewer CM values than expected: " << cm.size();
287  }
288 
289  updateHistoSet(cm_[0], cm[0]);
290  updateHistoSet(cm_[1], cm[1]);
291 
292  uint16_t bins = digisAlt.data.size() < nBinsSpy_ ? digisAlt.data.size() : nBinsSpy_;
293  for (uint16_t ibin = 0; ibin < bins; ibin++) {
294  updateHistoSet(scopeFrame_, ibin, digisAlt.data[ibin].adc());
295  }
296 
297  // Header low and high for both APVs
298  std::vector<uint32_t> adcHeader_high;
299  std::vector<uint32_t> adcHeader_low;
300 
301  float threshold_high = (digisAlt.data[286].adc() + digisAlt.data[287].adc()) / 4;
302  float threshold_low = 100;
303  int minNumberForHeader = 4;
304  bool goodHeaderFound = false;
305  int nConsecutiveHigh = 0;
306  adcHeader_high.clear();
307  adcHeader_high.reserve(30);
308  adcHeader_low.clear();
309  adcHeader_low.reserve(30);
310 
311  for (uint16_t ibin = 6; ibin < 11; ibin++) {
312  if (digisAlt.data[ibin].adc() > threshold_high) {
313  nConsecutiveHigh++;
314  }
315  }
316 
317  if (nConsecutiveHigh > minNumberForHeader)
318  goodHeaderFound = true; // if nConsecutiveHigh > 4 --> good header found
319  if (goodHeaderFound == false)
320  return;
321  for (uint16_t ibin = 0; ibin < 30; ibin++) {
322  if (digisAlt.data[ibin].adc() > threshold_high &&
323  goodHeaderFound) { // save of samples above avg(trailing ticks)/4
324  adcHeader_high.push_back(digisAlt.data[ibin].adc());
325  }
326  if (digisAlt.data[ibin].adc() < threshold_low && goodHeaderFound) {
327  adcHeader_low.push_back(digisAlt.data[ibin].adc());
328  }
329  }
330  if (adcHeader_low.empty() || adcHeader_high.empty()) {
331  return;
332  }
333  for (uint16_t i = 0; i < adcHeader_low.size(); i++) {
334  updateHistoSet(lowHeader_, adcHeader_low[i]);
335  }
336  for (uint16_t i = 0; i < adcHeader_high.size(); i++) {
337  updateHistoSet(highHeader_, adcHeader_high[i]);
338  }
339  }
340 }
341 
342 // -----------------------------------------------------------------------------
343 //
345  const edm::DetSet<SiStripRawDigi>& digis,
346  const edm::DetSet<SiStripRawDigi>& digisAlt,
347  const std::vector<uint16_t>& stripOnCluster) {
348  // Only fill every 'N' events
349  if (not(parameters_.existsAs<bool>("isSpy") and parameters_.getParameter<bool>("isSpy"))) {
350  if (!updateFreq() || fillCntr() % updateFreq()) {
351  return;
352  }
353  }
354 
355  if (digis.data.size() != nBins_) { //@@ check scope mode length?
356  edm::LogWarning(mlDqmSource_) << "[DaqScopeModeTask::" << __func__ << "]"
357  << " Unexpected number of digis (" << digis.data.size()
358  << ") wrt number of histogram bins (" << nBins_ << ")!";
359  }
360 
361  if (not(parameters_.existsAs<bool>("isSpy") and parameters_.getParameter<bool>("isSpy"))) {
362  uint16_t bins = digis.data.size() < nBins_ ? digis.data.size() : nBins_;
363  for (uint16_t ibin = 0; ibin < bins; ibin++) {
364  updateHistoSet(scopeFrame_, ibin, digis.data[ibin].adc());
365  }
366  } else {
367  // fill the pedestal histograms as done in the pedestal task
368  uint16_t nbins = peds_[0].vNumOfEntries_.size();
369  if (digis.data.size() < nbins) {
370  nbins = digis.data.size();
371  }
372  uint16_t napvs = nbins / 128;
373  std::vector<uint32_t> cm;
374  cm.resize(napvs, 0);
375  // Calc common mode for both APVs
376  std::vector<uint16_t> adc;
377  for (uint16_t iapv = 0; iapv < napvs; iapv++) {
378  adc.clear();
379  adc.reserve(128);
380  for (uint16_t ibin = 0; ibin < 128; ibin++) {
381  if ((iapv * 128) + ibin < nbins) {
382  if (std::find(stripOnCluster.begin(), stripOnCluster.end(), (iapv * 128) + ibin) ==
383  stripOnCluster.end()) // if not found, strip is good
384  adc.push_back(digis.data[(iapv * 128) + ibin].adc());
385  }
386  }
387  sort(adc.begin(), adc.end());
388  uint16_t index = adc.size() % 2 ? adc.size() / 2 : adc.size() / 2 - 1;
389  if (!adc.empty()) {
390  cm[iapv] = static_cast<uint32_t>(adc[index]);
391  }
392  }
393 
395  for (uint16_t ibin = 0; ibin < nbins; ibin++) {
396  if (std::find(stripOnCluster.begin(), stripOnCluster.end(), ibin) != stripOnCluster.end()) {
397  continue;
398  }
399  float digiVal = digis.data[ibin].adc();
400  updateHistoSet(peds_[0], ibin, digiVal); // peds and raw noise
401  float diff = digiVal - static_cast<float>(cm[ibin / 128]);
402  updateHistoSet(peds_[1], ibin, diff); // residuals and real noise
403  }
404 
405  if (cm.size() < cm_.size()) {
406  edm::LogWarning(mlDqmSource_) << "[PedestalsTask::" << __func__ << "]"
407  << " Fewer CM values than expected: " << cm.size();
408  }
409 
410  updateHistoSet(cm_[0], cm[0]);
411  updateHistoSet(cm_[1], cm[1]);
412 
413  uint16_t bins = digisAlt.data.size() < nBinsSpy_ ? digisAlt.data.size() : nBinsSpy_;
414  for (uint16_t ibin = 0; ibin < bins; ibin++) {
415  updateHistoSet(scopeFrame_, ibin, digisAlt.data[ibin].adc());
416  }
417  // Header low and high for both APVs
418  std::vector<uint32_t> adcHeader_high;
419  std::vector<uint32_t> adcHeader_low;
420 
421  float threshold_high = (digisAlt.data[286].adc() + digisAlt.data[287].adc()) / 4;
422  float threshold_low = 120;
423  int minNumberForHeader = 4;
424  bool goodHeaderFound = false;
425  int nConsecutiveHigh = 0;
426  adcHeader_high.clear();
427  adcHeader_high.reserve(30);
428  adcHeader_low.clear();
429  adcHeader_low.reserve(30);
430 
431  for (uint16_t ibin = 6; ibin < 11; ibin++) {
432  if (digisAlt.data[ibin].adc() > threshold_high) {
433  nConsecutiveHigh++;
434  }
435  }
436 
437  if (nConsecutiveHigh > minNumberForHeader)
438  goodHeaderFound = true; // if nConsecutiveHigh > 4 --> good header found
439  if (goodHeaderFound == false)
440  return;
441  for (uint16_t ibin = 0; ibin < 30; ibin++) {
442  if (digisAlt.data[ibin].adc() > threshold_high &&
443  goodHeaderFound) { // save of samples above avg(trailing ticks)/4
444  adcHeader_high.push_back(digisAlt.data[ibin].adc());
445  }
446  if (digisAlt.data[ibin].adc() < threshold_low && goodHeaderFound) {
447  adcHeader_low.push_back(digisAlt.data[ibin].adc());
448  }
449  }
450  if (adcHeader_low.empty() || adcHeader_high.empty()) {
451  return;
452  }
453  for (uint16_t i = 0; i < adcHeader_low.size(); i++) {
454  updateHistoSet(lowHeader_, adcHeader_low[i]);
455  }
456  for (uint16_t i = 0; i < adcHeader_high.size(); i++) {
457  updateHistoSet(highHeader_, adcHeader_high[i]);
458  }
459  }
460 }
461 
462 // -----------------------------------------------------------------------------
463 //
465  if (not(parameters_.existsAs<bool>("isSpy") and parameters_.getParameter<bool>("isSpy")))
467  else {
468  updateHistoSet(peds_[0]);
469  TProfile* histo = ExtractTObject<TProfile>().extract(peds_[1].histo());
470  for (uint16_t ii = 0; ii < peds_[1].vNumOfEntries_.size(); ++ii) {
471  float mean = 0.;
472  float spread = 0.;
473  float entries = peds_[1].vNumOfEntries_[ii];
474  if (entries > 0.) {
475  mean = peds_[1].vSumOfContents_[ii] / entries;
476  spread = sqrt(peds_[1].vSumOfSquares_[ii] / entries - mean * mean);
477  }
478 
479  float noise = spread;
480  float error = 0; // sqrt(entries) / entries;
482  }
483 
484  updateHistoSet(cm_[0]);
485  updateHistoSet(cm_[1]);
486 
490  }
491 }
static const char noise_[]
std::vector< float > vNumOfEntries_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ParameterSet parameters_
parameters useful for the spy
Utility class that holds histogram title.
DaqScopeModeTask(DQMStore *, const FedChannelConnection &, const edm::ParameterSet &)
static const char mlDqmSource_[]
std::vector< float > vSumOfContents_
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
sistrip classes
#define LogTrace(id)
void updateHistoSet(HistoSet &, const uint32_t &bin, const float &value)
std::vector< HistoSet > peds_
void book() override
static const char scopeModeHeaderLow_[]
const uint32_t & fillCntr() const
Class containning control, module, detector and connection information, at the level of a FED channel...
T sqrt(T t)
Definition: SSEVec.h:19
void fill(const SiStripEventSummary &, const edm::DetSet< SiStripRawDigi > &) override
static void setBinContent(TProfile *const profile, const uint32_t &bin, const double &entries, const double &mean, const double &spread)
static const char commonMode_[]
const uint32_t & fedKey() const
std::vector< HistoSet > cm_
DQMStore *const dqm() const
ii
Definition: cuy.py:589
int extract(std::vector< int > *output, const std::string &dati)
static const char pedestals_[]
static const char scopeModeHeaderHigh_[]
~DaqScopeModeTask() override
void update() override
collection_type data
Definition: DetSet.h:80
void histo(MonitorElement *)
conn
Definition: getInfo.py:9
static const char scopeModeFrame_[]
std::vector< double > vSumOfSquares_
const uint32_t & updateFreq() const
const std::string & title() const
const FedChannelConnection & connection() const
Log< level::Warning, false > LogWarning
Definition: DQMStore.h:18
uint16_t *__restrict__ uint16_t const *__restrict__ adc