CMS 3D CMS Logo

SiStripApvShotCleaner.cc
Go to the documentation of this file.
2 #include <algorithm>
3 
4 //Uncomment the following #define to have print debug
5 //#define DEBUGME
6 
8  : maxNumOfApvs(6), //FED Default: 6 (i.e. max num apvs )
9  stripsPerApv(128),
10  stripsForMedian(64) {}
11 
15  if (in.size() < 64)
16  return false;
17 
18  if (loop(in)) {
19  reset(scan, end);
20  return true;
21  }
22  return false;
23 }
24 
26 #ifdef DEBUGME
27  std::stringstream ss;
28  ss << __func__ << " working on detid " << in.detId() << " for a digi.size=" << in.size();
29 #endif
30 
31  shots_ = false;
32  for (auto& val : shotApv_)
33  val = false;
34 
35  cacheDetId = in.detId();
36 
37  //Find the position in the DetSet where the first strip of an apv should be inserted
38  // needed to deduce if at least stripsForMedian strips per apv have been fired
39  for (size_t i = 0; i <= maxNumOfApvs; ++i) {
40  SiStripDigi d(i * stripsPerApv, 0); //Fake digi, at the edge of the apv
41  pFirstDigiOfApv[i] = std::lower_bound(in.begin(), in.end(), d);
42 
43  //if satisfied it means that the number of digis in the apv i-1 is above stripsForMedia -> apvShot
44  if (i > 0 && pFirstDigiOfApv[i] - pFirstDigiOfApv[i - 1] > stripsForMedian) {
45  shots_ = true;
46  shotApv_[i - 1] = true;
47 #ifdef DEBUGME
48  ss << " found an apv shot of " << pFirstDigiOfApv[i] - pFirstDigiOfApv[i - 1] << " digis in detid " << in.detId()
49  << " apv " << i << std::endl;
50 #endif
51  }
52 
53  //---------------------
54  //Just for debug REMOVE
55  /*
56  if(i>0){
57  ss << "detid " << in.detId() << " apv " << i-1 << " number digis " << pFirstDigiOfApv[i]-pFirstDigiOfApv[i-1] << " \t shot " << shotApv_[i-1] << std::endl;
58  if(pFirstDigiOfApv[i]-pFirstDigiOfApv[i-1]>stripsForMedian-2){
59  edm::DetSet<SiStripDigi>::const_iterator dig=pFirstDigiOfApv[i-1];
60  while(dig!=pFirstDigiOfApv[i]){
61  ss << "\t strip " << dig->strip() << " dig.adc " << dig->adc();
62  dig++;
63  }
64  ss << std::endl;
65  }
66  }
67  */
68  //-------------------------------
69  }
70 
71 #ifdef DEBUGME
72  edm::LogInfo("ApvShot") << ss.str();
73 #endif
74 
75  if (!shots_)
76  return false;
77 
79  return true;
80 }
81 
83  size_t maxNumOfApvs) {
84  vdigis.clear();
85  //loop on Apvs and remove shots. if an apv doesn't have shots, copy it
86  for (size_t i = 0; i < maxNumOfApvs; ++i) {
87  apvDigis.clear();
88 
89  if (shotApv_[i]) {
90  apvDigis.insert(apvDigis.end(), pFirstDigiOfApv[i], pFirstDigiOfApv[i + 1]);
91  subtractCM();
92  std::stable_sort(apvDigis.begin(), apvDigis.end());
93  vdigis.insert(vdigis.end(), apvDigis.begin(), apvDigis.end());
94  } else {
95  vdigis.insert(vdigis.end(), pFirstDigiOfApv[i], pFirstDigiOfApv[i + 1]);
96  }
97  }
98 
99 #ifdef DEBUGME
100  std::stringstream ss;
101  ss << "detid " << cacheDetId << " new digi.size " << vdigis.size() << "\n";
102  for (size_t i = 0; i < vdigis.size(); ++i)
103  ss << "\t " << i << " strip " << vdigis[i].strip() << " adc " << vdigis[i].adc();
104  edm::LogInfo("ApvShot") << ss.str() << std::endl;
105 #endif
106 }
107 
109  //order by charge
110  std::stable_sort(
111  apvDigis.begin(), apvDigis.end(), [](SiStripDigi const& a, SiStripDigi const& b) { return a.adc() > b.adc(); });
112 
113  //ignore case where 64th strip is 0ADC
114  if (apvDigis[stripsForMedian].adc() == 0) {
115 #ifdef DEBUGME
116  std::stringstream ss;
117  ss << "case with strip64=0 --> detid= " << cacheDetId << "\n";
118  edm::LogInfo("ApvShot") << ss.str();
119 #endif
120  return;
121  }
122 
123  //Find the Median
124  float CM = 0.5f * (apvDigis[stripsForMedian].adc() + apvDigis[stripsForMedian - 1].adc());
125 
126  if (CM <= 0)
127  return;
128 
129  //Subtract the median
130  const bool is10bit = apvDigis[0].adc() > 255; // approximation; definitely 10bit in this case
131  size_t i = 0;
132  for (; i < stripsForMedian && apvDigis[i].adc() > CM; ++i) {
133  const uint16_t adc =
134  ((apvDigis[i].adc() > 253) && !is10bit) ? apvDigis[i].adc() : (uint16_t)(apvDigis[i].adc() - CM);
136  }
137  apvDigis.resize(i);
138 
139 #ifdef DEBUGME
140  std::stringstream ss;
141  ss << "[subtractCM] detid " << cacheDetId << " CM is " << CM << " the remaining strips after CM subtraction are "
142  << i;
143  edm::LogInfo("ApvShot") << ss.str();
144 #endif
145 }
146 
150  pDetSet->data.swap(vdigis);
151  a = pDetSet->begin();
152  b = pDetSet->end();
153 }
ecalMGPA::adc
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
Definition: EcalMGPASample.h:11
SiStripApvShotCleaner::dumpInVector
void dumpInVector(edm::DetSet< SiStripDigi >::const_iterator *, size_t)
Definition: SiStripApvShotCleaner.cc:82
mps_fire.i
i
Definition: mps_fire.py:355
SiStripApvShotCleaner.h
edm::DetSet< SiStripDigi >
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
SiStripApvShotCleaner::stripsPerApv
unsigned short stripsPerApv
Definition: SiStripApvShotCleaner.h:47
edm::LogInfo
Definition: MessageLogger.h:254
SiStripApvShotCleaner::apvDigis
std::vector< SiStripDigi > apvDigis
Definition: SiStripApvShotCleaner.h:44
SiStripApvShotCleaner::reset
void reset(edm::DetSet< SiStripDigi >::const_iterator &a, edm::DetSet< SiStripDigi >::const_iterator &b)
Definition: SiStripApvShotCleaner.cc:147
SiStripApvShotCleaner::maxNumOfApvs
unsigned short maxNumOfApvs
Definition: SiStripApvShotCleaner.h:46
end
#define end
Definition: vmac.h:39
SiStripApvShotCleaner::subtractCM
void subtractCM()
Definition: SiStripApvShotCleaner.cc:108
SiStripApvShotCleaner::vdigis
std::vector< SiStripDigi > vdigis
Definition: SiStripApvShotCleaner.h:44
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
SiStripApvShotCleaner::pFirstDigiOfApv
edm::DetSet< SiStripDigi >::const_iterator pFirstDigiOfApv[7]
Definition: SiStripApvShotCleaner.h:42
SiStripApvShotCleaner::pDetSet
std::unique_ptr< edm::DetSet< SiStripDigi > > pDetSet
Definition: SiStripApvShotCleaner.h:45
b
double b
Definition: hdecay.h:118
SiStripApvShotCleaner::stripsForMedian
unsigned short stripsForMedian
Definition: SiStripApvShotCleaner.h:48
cuda_std::lower_bound
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:27
SiStripApvShotCleaner::shotApv_
bool shotApv_[25]
Definition: SiStripApvShotCleaner.h:41
a
double a
Definition: hdecay.h:119
SiStripApvShotCleaner::shots_
bool shots_
Definition: SiStripApvShotCleaner.h:40
recoMuon::in
Definition: RecoMuonEnumerators.h:6
SiStripApvShotCleaner::loop
bool loop(const edmNew::DetSet< SiStripDigi > &in)
Definition: SiStripApvShotCleaner.h:28
heppy_batch.val
val
Definition: heppy_batch.py:351
SiStripApvShotCleaner::clean
bool clean(const edmNew::DetSet< SiStripDigi > &in, edmNew::DetSet< SiStripDigi >::const_iterator &scan, edmNew::DetSet< SiStripDigi >::const_iterator &end)
Definition: SiStripApvShotCleaner.h:19
SiStripApvShotCleaner::cacheDetId
uint32_t cacheDetId
Definition: SiStripApvShotCleaner.h:39
ztail.d
d
Definition: ztail.py:151
SiStripDigi
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
SiStripApvShotCleaner::SiStripApvShotCleaner
SiStripApvShotCleaner()
Definition: SiStripApvShotCleaner.cc:7
edm::DetSet::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSet.h:31