CMS 3D CMS Logo

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