CMS 3D CMS Logo

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