CMS 3D CMS Logo

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