CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiStripFedZeroSuppression.cc
Go to the documentation of this file.
2 
7 
8 //#define DEBUG_SiStripZeroSuppression_
9 //#define ML_DEBUG
10 using namespace std;
11 
13  if (noiseWatcher_.check(es)) {
14  noise_ = &es.getData(noiseToken_);
15  }
16  if (thresholdWatcher_.check(es)) {
17  threshold_ = &es.getData(thresholdToken_);
18  }
19 }
20 
21 void SiStripFedZeroSuppression::suppress(const std::vector<SiStripDigi>& in,
22  std::vector<SiStripDigi>& selectedSignal,
23  uint32_t detID) {
24  suppress(in, selectedSignal, detID, *noise_, *threshold_);
25 }
26 
27 void SiStripFedZeroSuppression::suppress(const std::vector<SiStripDigi>& in,
28  std::vector<SiStripDigi>& selectedSignal,
29  uint32_t detID,
30  const SiStripNoises& noise,
31  const SiStripThreshold& threshold) {
32  int i;
33  int inSize = in.size();
34  SiStripNoises::Range detNoiseRange = noise.getRange(detID);
35  SiStripThreshold::Range detThRange = threshold.getRange(detID);
36 
37  // reserving more than needed, but quicker than one at a time
38  selectedSignal.clear();
39  selectedSignal.reserve(inSize);
40  for (i = 0; i < inSize; i++) {
41  //Find adc values for neighbouring strips
42  const uint32_t strip = (uint32_t)in[i].strip();
43 
44  adc = in[i].adc();
45 
46  SiStripThreshold::Data thresholds = threshold.getData(strip, detThRange);
47  theFEDlowThresh = static_cast<int16_t>(thresholds.getLth() * noise.getNoiseFast(strip, detNoiseRange) + 0.5);
48  theFEDhighThresh = static_cast<int16_t>(thresholds.getHth() * noise.getNoiseFast(strip, detNoiseRange) + 0.5);
49 
50  adcPrev = -9999;
51  adcNext = -9999;
52  adcPrev2 = -9999;
53  adcNext2 = -9999;
54 
55  /*
56  Since we are not running on
57  Raw data we need to initialize
58  all the FED threshold
59  */
60 
61  theNextFEDlowThresh = theFEDlowThresh;
62  theNext2FEDlowThresh = theFEDlowThresh;
63  thePrevFEDlowThresh = theFEDlowThresh;
64  thePrev2FEDlowThresh = theFEDlowThresh;
65  theNeighFEDlowThresh = theFEDlowThresh;
66 
67  theNextFEDhighThresh = theFEDhighThresh;
68  thePrevFEDhighThresh = theFEDhighThresh;
69  theNeighFEDhighThresh = theFEDhighThresh;
70 
71  if (((strip) % 128) == 127) {
72  adcNext = 0;
73  theNextFEDlowThresh = 9999;
74  theNextFEDhighThresh = 9999;
75  } else if (i + 1 < inSize && in[i + 1].strip() == strip + 1) {
76  adcNext = in[i + 1].adc();
77  SiStripThreshold::Data thresholds_1 = threshold.getData(strip + 1, detThRange);
78  theNextFEDlowThresh =
79  static_cast<int16_t>(thresholds_1.getLth() * noise.getNoiseFast(strip + 1, detNoiseRange) + 0.5);
80  theNextFEDhighThresh =
81  static_cast<int16_t>(thresholds_1.getHth() * noise.getNoiseFast(strip + 1, detNoiseRange) + 0.5);
82  if (((strip) % 128) == 126) {
83  adcNext2 = 0;
84  theNext2FEDlowThresh = 9999;
85  } else if (i + 2 < inSize && in[i + 2].strip() == strip + 2) {
86  adcNext2 = in[i + 2].adc();
87  theNext2FEDlowThresh = static_cast<int16_t>(
88  threshold.getData(strip + 2, detThRange).getLth() * noise.getNoiseFast(strip + 2, detNoiseRange) + 0.5);
89  }
90  }
91 
92  if (((strip) % 128) == 0) {
93  adcPrev = 0;
94  thePrevFEDlowThresh = 9999;
95  thePrevFEDhighThresh = 9999;
96  } else if (i - 1 >= 0 && in[i - 1].strip() == strip - 1) {
97  adcPrev = in[i - 1].adc();
98  SiStripThreshold::Data thresholds_1 = threshold.getData(strip - 1, detThRange);
99  thePrevFEDlowThresh =
100  static_cast<int16_t>(thresholds_1.getLth() * noise.getNoiseFast(strip - 1, detNoiseRange) + 0.5);
101  thePrevFEDhighThresh =
102  static_cast<int16_t>(thresholds_1.getHth() * noise.getNoiseFast(strip - 1, detNoiseRange) + 0.5);
103  if (((strip) % 128) == 1) {
104  adcPrev2 = 0;
105  thePrev2FEDlowThresh = 9999;
106  } else if (i - 2 >= 0 && in[i - 2].strip() == strip - 2) {
107  adcPrev2 = in[i - 2].adc();
108  thePrev2FEDlowThresh = static_cast<int16_t>(
109  threshold.getData(strip - 2, detThRange).getLth() * noise.getNoiseFast(strip - 2, detNoiseRange) + 0.5);
110  }
111  }
112 
113  if (adcNext <= adcPrev) {
114  adcMaxNeigh = adcPrev;
115  theNeighFEDlowThresh = thePrevFEDlowThresh;
116  theNeighFEDhighThresh = thePrevFEDhighThresh;
117  } else {
118  adcMaxNeigh = adcNext;
119  theNeighFEDlowThresh = theNextFEDlowThresh;
120  theNeighFEDhighThresh = theNextFEDhighThresh;
121  }
122 
123  if (isAValidDigi()) {
124  selectedSignal.push_back(SiStripDigi(strip, adc));
125  }
126  }
127 }
128 
130  const uint32_t detID = out.id;
131  SiStripNoises::Range detNoiseRange = noise_->getRange(detID);
132  SiStripThreshold::Range detThRange = threshold_->getRange(detID);
133 #ifdef DEBUG_SiStripZeroSuppression_
134  if (edm::isDebugEnabled())
135  LogTrace("SiStripZeroSuppression")
136  << "[SiStripFedZeroSuppression::suppress] Zero suppression on edm::DetSet<SiStripRawDigi>: detID " << detID
137  << " size = " << in.data.size();
138 #endif
140  for (; in_iter != in.data.end(); in_iter++) {
141  const uint32_t strip = (uint32_t)(in_iter - in.data.begin());
142 
143 #ifdef DEBUG_SiStripZeroSuppression_
144  if (edm::isDebugEnabled())
145  LogTrace("SiStripZeroSuppression") << "[SiStripFedZeroSuppression::suppress] detID= " << detID
146  << " strip= " << strip << " adc= " << in_iter->adc();
147 #endif
148  adc = in_iter->adc();
149 
150  SiStripThreshold::Data thresholds = threshold_->getData(strip, detThRange);
151  theFEDlowThresh = static_cast<int16_t>(thresholds.getLth() * noise_->getNoiseFast(strip, detNoiseRange) + 0.5);
152  theFEDhighThresh = static_cast<int16_t>(thresholds.getHth() * noise_->getNoiseFast(strip, detNoiseRange) + 0.5);
153 
154  adcPrev = -9999;
155  adcNext = -9999;
156  /*
157  If a strip is the last one on the chip
158  set its next neighbor's thresholds to infinity
159  because the FED does not merge clusters across
160  chip boundaries right now
161  */
162  if (strip % 128 == 127) {
163  adcNext = 0;
164  theNextFEDlowThresh = 9999;
165  theNextFEDhighThresh = 9999;
166  } else {
167  adcNext = (in_iter + 1)->adc();
168  SiStripThreshold::Data thresholds_1 = threshold_->getData(strip + 1, detThRange);
169  theNextFEDlowThresh =
170  static_cast<int16_t>(thresholds_1.getLth() * noise_->getNoiseFast(strip + 1, detNoiseRange) + 0.5);
171  theNextFEDhighThresh =
172  static_cast<int16_t>(thresholds_1.getHth() * noise_->getNoiseFast(strip + 1, detNoiseRange) + 0.5);
173  }
174  /*
175  Similarily, for the first strip
176  on a chip
177  */
178  if (strip % 128 == 0) {
179  adcPrev = 0;
180  thePrevFEDlowThresh = 9999;
181  thePrevFEDhighThresh = 9999;
182  } else {
183  adcPrev = (in_iter - 1)->adc();
184  SiStripThreshold::Data thresholds_1 = threshold_->getData(strip - 1, detThRange);
185  thePrevFEDlowThresh =
186  static_cast<int16_t>(thresholds_1.getLth() * noise_->getNoiseFast(strip - 1, detNoiseRange) + 0.5);
187  thePrevFEDhighThresh =
188  static_cast<int16_t>(thresholds_1.getHth() * noise_->getNoiseFast(strip - 1, detNoiseRange) + 0.5);
189  }
190  if (adcNext < adcPrev) {
191  adcMaxNeigh = adcPrev;
192  theNeighFEDlowThresh = thePrevFEDlowThresh;
193  theNeighFEDhighThresh = thePrevFEDhighThresh;
194  } else {
195  adcMaxNeigh = adcNext;
196  theNeighFEDlowThresh = theNextFEDlowThresh;
197  theNeighFEDhighThresh = theNextFEDhighThresh;
198  }
199 
200  //Find adc values for next neighbouring strips
201  adcPrev2 = -9999;
202  adcNext2 = -9999;
203  thePrev2FEDlowThresh = 1;
204  theNext2FEDlowThresh = 1;
205  if (strip % 128 >= 126) {
206  adcNext2 = 0;
207  theNext2FEDlowThresh = 9999;
208  } else if (strip % 128 < 126) {
209  adcNext2 = (in_iter + 2)->adc();
210  theNext2FEDlowThresh = static_cast<int16_t>(
211  threshold_->getData(strip + 2, detThRange).getLth() * noise_->getNoiseFast(strip + 2, detNoiseRange) + 0.5);
212  }
213  if (strip % 128 <= 1) {
214  adcPrev2 = 0;
215  thePrev2FEDlowThresh = 9999;
216  } else if (strip % 128 > 1) {
217  adcPrev2 = (in_iter - 2)->adc();
218  thePrev2FEDlowThresh = static_cast<int16_t>(
219  threshold_->getData(strip - 2, detThRange).getLth() * noise_->getNoiseFast(strip - 2, detNoiseRange) + 0.5);
220  }
221  //GB 23/6/08: truncation should be done at the very beginning
222  if (isAValidDigi())
223  out.data.push_back(SiStripDigi(strip, truncate(in_iter->adc())));
224  }
225 }
226 
227 void SiStripFedZeroSuppression::fillThresholds_(const uint32_t detID, size_t size) {
228  SiStripNoises::Range detNoiseRange = noise_->getRange(detID);
229  SiStripThreshold::Range detThRange = threshold_->getRange(detID);
230 
231  if (highThr_.size() != size) {
232  highThr_.resize(size);
233  lowThr_.resize(size);
234  noises_.resize(size);
235  highThrSN_.resize(size);
236  lowThrSN_.resize(size);
237  }
238 
239  noise_->allNoises(noises_, detNoiseRange);
240  threshold_->allThresholds(lowThrSN_, highThrSN_, detThRange); // thresholds as S/N
241  for (size_t strip = 0; strip < size; ++strip) {
242  float noise = noises_[strip];
243  // uncomment line below to check bluk noise decoding
244  //assert( noise == noiseHandle->getNoiseFast(strip,detNoiseRange) );
245  highThr_[strip] = static_cast<int16_t>(highThrSN_[strip] * noise + 0.5 + 1e-6);
246  lowThr_[strip] = static_cast<int16_t>(lowThrSN_[strip] * noise + 0.5 + 1e-6);
247  // Note: it's a bit wierd, but there are some cases for which 'highThrSN_[strip]*noise' is an exact integer
248  // but due to roundoffs it gets rounded to the integer below if.
249  // Apparently the optimized code inlines differently and this changes the roundoff.
250  // The +1e-6 fixes the problem. [GPetruc]
251  }
252 }
253 
254 void SiStripFedZeroSuppression::suppress(const std::vector<int16_t>& in,
255  uint16_t firstAPV,
257  const uint32_t detID = out.id;
258  size_t size = in.size();
259 #ifdef DEBUG_SiStripZeroSuppression_
260  if (edm::isDebugEnabled())
261  LogTrace("SiStripZeroSuppression")
262  << "[SiStripFedZeroSuppression::suppress] Zero suppression on std::vector<int16_t>: detID " << detID
263  << " size = " << in.size();
264 #endif
265 
266  fillThresholds_(detID, size + firstAPV * 128); // want to decouple this from the other cost
267 
268  std::vector<int16_t>::const_iterator in_iter = in.begin();
269  uint16_t strip = firstAPV * 128;
270  for (; strip < size + firstAPV * 128; ++strip, ++in_iter) {
271  size_t strip_mod_128 = strip & 127;
272 #ifdef DEBUG_SiStripZeroSuppression_
273  if (edm::isDebugEnabled())
274  LogTrace("SiStripZeroSuppression") << "[SiStripFedZeroSuppression::suppress] detID= " << detID
275  << " strip= " << strip << " adc= " << *in_iter;
276 #endif
277  adc = *in_iter;
278 
279  theFEDlowThresh = lowThr_[strip];
280  theFEDhighThresh = highThr_[strip];
281 
282  //Find adc values for neighbouring strips
283 
284  /*
285  If a strip is the last one on the chip
286  set its next neighbor's thresholds to infinity
287  because the FED does not merge clusters across
288  chip boundaries right now
289  */
290 
291  //adcPrev = -9999; // useless, they are set
292  //adcNext = -9999; // in the next lines in any case
293  if (strip_mod_128 == 127) {
294  adcNext = 0;
295  theNextFEDlowThresh = 9999;
296  theNextFEDhighThresh = 9999;
297  } else {
298  adcNext = *(in_iter + 1);
299  theNextFEDlowThresh = lowThr_[strip + 1];
300  theNextFEDhighThresh = highThr_[strip + 1];
301  }
302 
303  /*
304  Similarily, for the first strip
305  on a chip
306  */
307  if (strip_mod_128 == 0) {
308  adcPrev = 0;
309  thePrevFEDlowThresh = 9999;
310  thePrevFEDhighThresh = 9999;
311  } else {
312  adcPrev = *(in_iter - 1);
313  thePrevFEDlowThresh = lowThr_[strip - 1];
314  thePrevFEDhighThresh = highThr_[strip - 1];
315  }
316 
317  if (adcNext < adcPrev) {
318  adcMaxNeigh = adcPrev;
319  theNeighFEDlowThresh = thePrevFEDlowThresh;
320  theNeighFEDhighThresh = thePrevFEDhighThresh;
321  } else {
322  adcMaxNeigh = adcNext;
323  theNeighFEDlowThresh = theNextFEDlowThresh;
324  theNeighFEDhighThresh = theNextFEDhighThresh;
325  }
326 
327  //Find adc values for next neighbouring strips
328  //adcPrev2 = -9999; //
329  //adcNext2 = -9999; // useless to set them here
330  //thePrev2FEDlowThresh = 1; // they are overwritten always in the next 8 lines
331  //theNext2FEDlowThresh = 1; //
332  if (strip_mod_128 >= 126) {
333  adcNext2 = 0;
334  theNext2FEDlowThresh = 9999;
335  //} else if ( strip_mod_128 < 126 ) { // if it's not >= then is <, no need to "if" again
336  } else {
337  adcNext2 = *(in_iter + 2);
338  theNext2FEDlowThresh = lowThr_[strip + 2];
339  }
340  if (strip_mod_128 <= 1) {
341  adcPrev2 = 0;
342  thePrev2FEDlowThresh = 9999;
343  //} else if ( strip_mod_128 > 1 ) { // same as above
344  } else {
345  adcPrev2 = *(in_iter - 2);
346  thePrev2FEDlowThresh = lowThr_[strip - 2];
347  ;
348  }
349 
350  if (isAValidDigi()) {
351 #ifdef DEBUG_SiStripZeroSuppression_
352  if (edm::isDebugEnabled())
353  LogTrace("SiStripZeroSuppression")
354  << "[SiStripFedZeroSuppression::suppress] DetId " << out.id << " strip " << strip << " adc " << *in_iter
355  << " digiCollection size " << out.data.size();
356 #endif
357  //GB 23/6/08: truncation should be done at the very beginning
358  out.push_back(SiStripDigi(strip, (*in_iter < 0 ? 0 : truncate(*in_iter))));
359  }
360  }
361 }
362 
364 #ifdef DEBUG_SiStripZeroSuppression_
365 
366  if (edm::isDebugEnabled()) {
367  LogTrace("SiStripZeroSuppression") << "[SiStripFedZeroSuppression::suppress] "
368  << "\n\t adc " << adc << "\n\t adcPrev " << adcPrev << "\n\t adcNext " << adcNext
369  << "\n\t adcMaxNeigh " << adcMaxNeigh << "\n\t adcPrev2 " << adcPrev2
370  << "\n\t adcNext2 " << adcNext2 << std::endl;
371 
372  LogTrace("SiStripZeroSuppression") << "[SiStripFedZeroSuppression::suppress] "
373  << "\n\t theFEDlowThresh " << theFEDlowThresh << "\n\t theFEDhighThresh "
374  << theFEDhighThresh << "\n\t thePrevFEDlowThresh " << thePrevFEDlowThresh
375  << "\n\t thePrevFEDhighThresh " << thePrevFEDhighThresh
376  << "\n\t theNextFEDlowThresh " << theNextFEDlowThresh
377  << "\n\t theNextFEDhighThresh " << theNextFEDhighThresh
378  << "\n\t theNeighFEDlowThresh " << theNeighFEDlowThresh
379  << "\n\t theNeighFEDhighThresh " << theNeighFEDhighThresh
380  << "\n\t thePrev2FEDlowThresh " << thePrev2FEDlowThresh
381  << "\n\t theNext2FEDlowThresh " << theNext2FEDlowThresh << std::endl;
382  }
383 #endif
384  // Decide if this strip should be accepted.
385  bool accept = false;
386  switch (theFEDalgorithm) {
387  case 1:
388  accept = (adc >= theFEDlowThresh);
389  break;
390  case 2:
391  accept = (adc >= theFEDhighThresh || (adc >= theFEDlowThresh && adcMaxNeigh >= theNeighFEDlowThresh));
392  break;
393  case 3:
394  accept = (adc >= theFEDhighThresh || (adc >= theFEDlowThresh && adcMaxNeigh >= theNeighFEDhighThresh));
395  break;
396  case 4:
397  accept =
398  ((adc >= theFEDhighThresh) //Test for adc>highThresh (same as algorithm 2)
399  || ((adc >= theFEDlowThresh) //Test for adc>lowThresh, with neighbour adc>lowThresh (same as algorithm 2)
400  && (adcMaxNeigh >= theNeighFEDlowThresh)) ||
401  ((adc < theFEDlowThresh) //Test for adc<lowThresh
402  && (((adcPrev >= thePrevFEDhighThresh) //with both neighbours>highThresh
403  && (adcNext >= theNextFEDhighThresh)) ||
404  ((adcPrev >= thePrevFEDhighThresh) //OR with previous neighbour>highThresh and
405  && (adcNext >= theNextFEDlowThresh) //both the next neighbours>lowThresh
406  && (adcNext2 >= theNext2FEDlowThresh)) ||
407  ((adcNext >= theNextFEDhighThresh) //OR with next neighbour>highThresh and
408  && (adcPrev >= thePrevFEDlowThresh) //both the previous neighbours>lowThresh
409  && (adcPrev2 >= thePrev2FEDlowThresh)) ||
410  ((adcNext >= theNextFEDlowThresh) //OR with both next neighbours>lowThresh and
411  && (adcNext2 >= theNext2FEDlowThresh) //both the previous neighbours>lowThresh
412  && (adcPrev >= thePrevFEDlowThresh) && (adcPrev2 >= thePrev2FEDlowThresh)))));
413  break;
414  case 5:
415  accept = adc > 0;
416  break;
417  }
418  return accept;
419 }
static const char noise_[]
bool isDebugEnabled()
void init(const edm::EventSetup &es)
void push_back(const T &t)
Definition: DetSet.h:66
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
#define LogTrace(id)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
static float getNoiseFast(const uint16_t &strip, const Range &range)
Definition: SiStripNoises.h:68
SiStripThreshold::Data getData(const uint16_t &strip, const Range &range) const
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
__shared__ int noise
std::pair< ContainerIterator, ContainerIterator > Range
void suppress(const std::vector< SiStripDigi > &in, std::vector< SiStripDigi > &selectedSignal, uint32_t detId, const SiStripNoises &, const SiStripThreshold &)
collection_type data
Definition: DetSet.h:80
const Range getRange(const uint32_t detID) const
det_id_type id
Definition: DetSet.h:79
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
const Range getRange(const uint32_t &detID) const
void fillThresholds_(const uint32_t detID, size_t size)
tuple size
Write out results.
uint16_t *__restrict__ uint16_t const *__restrict__ adc