CMS 3D CMS Logo

SiStripRawProcessingAlgorithms.cc
Go to the documentation of this file.
2 
12 #include <memory>
13 
15  std::unique_ptr<SiStripPedestalsSubtractor> ped,
16  std::unique_ptr<SiStripCommonModeNoiseSubtractor> cmn,
17  std::unique_ptr<SiStripFedZeroSuppression> zs,
18  std::unique_ptr<SiStripAPVRestorer> res,
19  bool doAPVRest,
20  bool useCMMap)
21  : subtractorPed(std::move(ped)),
22  subtractorCMN(std::move(cmn)),
23  suppressor(std::move(zs)),
24  restorer(std::move(res)),
25  doAPVRestore(doAPVRest),
26  useCMMeanMap(useCMMap),
28 
30  subtractorPed->init(es);
31  subtractorCMN->init(es);
32  suppressor->init(es);
33  if (restorer.get())
34  restorer->init(es);
35 
36  trGeo = &es.getData(tkGeomToken_);
37 }
38 
40  initialize(es);
41  if (restorer.get() && doAPVRestore && useCMMeanMap)
42  restorer->loadMeanCMMap(e);
43 }
44 
59  edm::DetSet<SiStripDigi>& suppressedDigis,
60  uint16_t firstAPV) {
61  uint16_t nAPVFlagged = 0;
62  auto beginAPV = hybridDigis.begin();
63  const auto indigis_end = hybridDigis.end();
64  auto iAPV = firstAPV;
65  while (beginAPV != indigis_end) {
66  const auto endAPV = std::lower_bound(beginAPV, indigis_end, SiStripDigi((iAPV + 1) * 128, 0));
67  const auto nDigisInAPV = std::distance(beginAPV, endAPV);
68  if (nDigisInAPV > 64) {
69  digivector_t workDigis(128, -1024);
70  for (auto it = beginAPV; it != endAPV; ++it) {
71  workDigis[it->strip() - 128 * iAPV] = it->adc() * 2 - 1024;
72  }
73  digivector_t workDigisPedSubtracted(workDigis);
74  subtractorCMN->subtract(hybridDigis.id, iAPV, workDigis);
75  const auto apvFlagged = restorer->inspectAndRestore(
76  hybridDigis.id, iAPV, workDigisPedSubtracted, workDigis, subtractorCMN->getAPVsCM());
77  nAPVFlagged += apvFlagged;
78  if (getAPVFlags()[iAPV]) {
79  suppressor->suppress(workDigis, iAPV, suppressedDigis);
80  } else { // bad APV: more than 64 but not flagged
81  for (uint16_t i = 0; i != 128; ++i) {
82  const auto digi = workDigisPedSubtracted[i];
83  if (digi > 0) {
84  suppressedDigis.push_back(SiStripDigi(iAPV * 128 + i, suppressor->truncate(digi)));
85  }
86  }
87  }
88  } else { // already zero-suppressed, copy and truncate
89  std::transform(beginAPV, endAPV, std::back_inserter(suppressedDigis), [this](const SiStripDigi inDigi) {
90  return SiStripDigi(inDigi.strip(), suppressor->truncate(inDigi.adc()));
91  });
92  }
93  beginAPV = endAPV;
94  ++iAPV;
95  }
96  return nAPVFlagged;
97 }
98 
112  uint16_t firstAPV,
113  digivector_t& procRawDigis,
115  subtractorPed->subtract(id, firstAPV * 128, procRawDigis);
116  return suppressProcessedRawData(id, firstAPV, procRawDigis, output);
117 }
118 
131  digivector_t rawdigis;
132  rawdigis.reserve(rawDigis.size());
133  std::transform(std::begin(rawDigis), std::end(rawDigis), std::back_inserter(rawdigis), [](SiStripRawDigi digi) {
134  return digi.adc();
135  });
136  return suppressVirginRawData(rawDigis.id, 0, rawdigis, output);
137 }
138 
152  uint16_t firstAPV,
153  digivector_t& procRawDigis,
155  digivector_t procRawDigisPedSubtracted;
156 
157  int16_t nAPVFlagged = 0;
158  if (doAPVRestore)
159  procRawDigisPedSubtracted.assign(procRawDigis.begin(), procRawDigis.end());
160  subtractorCMN->subtract(id, firstAPV, procRawDigis);
161  if (doAPVRestore)
162  nAPVFlagged =
163  restorer->inspectAndRestore(id, firstAPV, procRawDigisPedSubtracted, procRawDigis, subtractorCMN->getAPVsCM());
164  suppressor->suppress(procRawDigis, firstAPV, output);
165  return nAPVFlagged;
166 }
167 
180  digivector_t rawdigis;
181  rawdigis.reserve(rawDigis.size());
182  std::transform(std::begin(rawDigis), std::end(rawDigis), std::back_inserter(rawdigis), [](SiStripRawDigi digi) {
183  return digi.adc();
184  });
185  return suppressProcessedRawData(rawDigis.id, 0, rawdigis, output);
186 }
187 
204  uint16_t firstAPV,
205  digivector_t& procRawDigis,
207  digivector_t procRawDigisPedSubtracted;
208 
209  for (auto& digi : procRawDigis) {
210  digi += 1024;
211  } // adding one MSB
212 
213  subtractorPed->subtract(id, firstAPV * 128, procRawDigis); // all strips are pedestals subtracted
214 
215  for (auto& digi : procRawDigis) {
216  digi /= 2;
217  }
218 
219  procRawDigisPedSubtracted.assign(procRawDigis.begin(), procRawDigis.end());
220 
221  subtractorCMN->subtract(id, firstAPV, procRawDigis);
222 
223  const auto nAPVFlagged = restorer->inspect(id, firstAPV, procRawDigis, subtractorCMN->getAPVsCM());
224 
225  for (auto& digi : procRawDigis) {
226  digi *= 2;
227  }
228 
229  const std::vector<bool>& apvf = getAPVFlags();
230  const std::size_t nAPVs = procRawDigis.size() / 128;
231  for (uint16_t iAPV = firstAPV; iAPV < nAPVs + firstAPV; ++iAPV) {
232  if (apvf[iAPV]) {
233  //GB 23/6/08: truncation should be done at the very beginning
234  for (uint16_t i = 0; i < 128; ++i) {
235  const int16_t digi = procRawDigisPedSubtracted[128 * (iAPV - firstAPV) + i];
236  output.push_back(SiStripDigi(128 * iAPV + i, (digi < 0 ? 0 : suppressor->truncate(digi))));
237  }
238  } else {
239  const auto firstDigiIt = std::begin(procRawDigis) + 128 * (iAPV - firstAPV);
240  std::vector<int16_t> singleAPVdigi(firstDigiIt, firstDigiIt + 128);
241  suppressor->suppress(singleAPVdigi, iAPV, output);
242  }
243  }
244 
245  return nAPVFlagged;
246 }
247 
261  edm::DetSet<SiStripDigi>& suppressedDigis) {
262  digivector_t rawdigis;
263  rawdigis.reserve(rawDigis.size());
264  std::transform(std::begin(rawDigis), std::end(rawDigis), std::back_inserter(rawdigis), [](SiStripRawDigi digi) {
265  return digi.adc();
266  });
267  return convertVirginRawToHybrid(rawDigis.id, 0, rawdigis, suppressedDigis);
268 }
iterator end()
Definition: DetSet.h:58
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
uint16_t suppressVirginRawData(uint32_t detId, uint16_t firstAPV, digivector_t &procRawDigis, edm::DetSet< SiStripDigi > &output)
void push_back(const T &t)
Definition: DetSet.h:66
const std::unique_ptr< SiStripPedestalsSubtractor > subtractorPed
uint16_t suppressProcessedRawData(uint32_t detId, uint16_t firstAPV, digivector_t &procRawDigis, edm::DetSet< SiStripDigi > &output)
SiStripAPVRestorer::digivector_t digivector_t
uint16_t convertVirginRawToHybrid(uint32_t detId, uint16_t firstAPV, digivector_t &inDigis, edm::DetSet< SiStripDigi > &rawDigis)
SiStripRawProcessingAlgorithms(edm::ConsumesCollector iC, std::unique_ptr< SiStripPedestalsSubtractor > ped, std::unique_ptr< SiStripCommonModeNoiseSubtractor > cmn, std::unique_ptr< SiStripFedZeroSuppression > zs, std::unique_ptr< SiStripAPVRestorer > res, bool doAPVRest, bool useCMMap)
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
uint16_t adc() const
const std::unique_ptr< SiStripAPVRestorer > restorer
Definition: Electron.h:6
const uint16_t & strip() const
Definition: SiStripDigi.h:33
const uint16_t & adc() const
Definition: SiStripDigi.h:34
const std::unique_ptr< SiStripCommonModeNoiseSubtractor > subtractorCMN
bool getData(T &iHolder) const
Definition: EventSetup.h:122
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
iterator begin()
Definition: DetSet.h:57
const std::unique_ptr< SiStripFedZeroSuppression > suppressor
const std::vector< bool > & getAPVFlags() const
det_id_type id
Definition: DetSet.h:79
void initialize(const edm::EventSetup &)
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
size_type size() const
Definition: DetSet.h:61
def move(src, dest)
Definition: eostools.py:511
uint16_t suppressHybridData(const edm::DetSet< SiStripDigi > &inDigis, edm::DetSet< SiStripDigi > &suppressedDigis, uint16_t firstAPV=0)
unsigned transform(const HcalDetId &id, unsigned transformCode)