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 
58 uint16_t SiStripRawProcessingAlgorithms::suppressHybridData(const uint16_t maxNStrips,
59  const edm::DetSet<SiStripDigi>& hybridDigis,
60  edm::DetSet<SiStripDigi>& suppressedDigis,
61  uint16_t firstAPV) {
62  uint16_t nAPVFlagged = 0; // Count of flagged APVs
63  auto currentDigi = hybridDigis.begin();
64  const auto endDigi = hybridDigis.end();
65  auto currentAPV = firstAPV;
66 
67  // Loop through the APVs in the range
68  while (currentDigi != endDigi) {
69  // Determine the range of digis belonging to the current APV
70  const auto nextAPVBoundary = SiStripDigi((currentAPV + 1) * 128, 0);
71 
72  // Reject any APV larger than the max possible
73  if (nextAPVBoundary.strip() > maxNStrips) {
74  edm::LogError("SiStripRawProcessingAlgorithms")
75  << "In DetId " << suppressedDigis.id << " encountered APV boundary with strip number "
76  << nextAPVBoundary.strip() << ", which exceeds the maximum allowed value for this module (" << maxNStrips
77  << "). Exiting loop.";
78  break;
79  }
80 
81  const auto nextAPVDigi = std::lower_bound(currentDigi, endDigi, nextAPVBoundary);
82  const auto nDigisInAPV = std::distance(currentDigi, nextAPVDigi);
83 
84  // Handle based on the number of digis in the current APV
85  if (nDigisInAPV > 64) {
86  // Process hybrid data for noisy APV
87  digivector_t workDigis(128, -1024);
88 
89  // Populate `workDigis` with values from `currentDigi`
90  for (auto it = currentDigi; it != nextAPVDigi; ++it) {
91  workDigis[it->strip() - 128 * currentAPV] = it->adc() * 2 - 1024;
92  }
93 
94  // Perform pedestal subtraction
95  digivector_t workDigisPedSubtracted(workDigis);
96  subtractorCMN->subtract(hybridDigis.id, currentAPV, workDigis);
97 
98  // Inspect and restore digis
99  const auto apvFlagged = restorer->inspectAndRestore(
100  hybridDigis.id, currentAPV, workDigisPedSubtracted, workDigis, subtractorCMN->getAPVsCM());
101  nAPVFlagged += apvFlagged;
102 
103  // Process based on the APV flag
104  if (getAPVFlags()[currentAPV]) {
105  // Suppress flagged APVs
106  suppressor->suppress(workDigis, currentAPV, suppressedDigis);
107  } else {
108  // Handle bad APV: not flagged but exceeds threshold
109  for (uint16_t i = 0; i < 128; ++i) {
110  const auto digi = workDigisPedSubtracted[i];
111  if (digi > 0) {
112  suppressedDigis.push_back(SiStripDigi(currentAPV * 128 + i, suppressor->truncate(digi)));
113  }
114  }
115  }
116  } else {
117  // Already zero-suppressed: copy and truncate
118  std::transform(currentDigi, nextAPVDigi, std::back_inserter(suppressedDigis), [this](const SiStripDigi& inDigi) {
119  return SiStripDigi(inDigi.strip(), suppressor->truncate(inDigi.adc()));
120  });
121  }
122 
123  // Move to the next APV
124  currentDigi = nextAPVDigi;
125  ++currentAPV;
126  }
127 
128  return nAPVFlagged;
129 }
130 
144  uint16_t firstAPV,
145  digivector_t& procRawDigis,
147  subtractorPed->subtract(id, firstAPV * 128, procRawDigis);
148  return suppressProcessedRawData(id, firstAPV, procRawDigis, output);
149 }
150 
163  digivector_t rawdigis;
164  rawdigis.reserve(rawDigis.size());
165  std::transform(std::begin(rawDigis), std::end(rawDigis), std::back_inserter(rawdigis), [](SiStripRawDigi digi) {
166  return digi.adc();
167  });
168  return suppressVirginRawData(rawDigis.id, 0, rawdigis, output);
169 }
170 
184  uint16_t firstAPV,
185  digivector_t& procRawDigis,
187  digivector_t procRawDigisPedSubtracted;
188 
189  int16_t nAPVFlagged = 0;
190  if (doAPVRestore)
191  procRawDigisPedSubtracted.assign(procRawDigis.begin(), procRawDigis.end());
192  subtractorCMN->subtract(id, firstAPV, procRawDigis);
193  if (doAPVRestore)
194  nAPVFlagged =
195  restorer->inspectAndRestore(id, firstAPV, procRawDigisPedSubtracted, procRawDigis, subtractorCMN->getAPVsCM());
196  suppressor->suppress(procRawDigis, firstAPV, output);
197  return nAPVFlagged;
198 }
199 
212  digivector_t rawdigis;
213  rawdigis.reserve(rawDigis.size());
214  std::transform(std::begin(rawDigis), std::end(rawDigis), std::back_inserter(rawdigis), [](SiStripRawDigi digi) {
215  return digi.adc();
216  });
217  return suppressProcessedRawData(rawDigis.id, 0, rawdigis, output);
218 }
219 
236  uint16_t firstAPV,
237  digivector_t& procRawDigis,
239  digivector_t procRawDigisPedSubtracted;
240 
241  for (auto& digi : procRawDigis) {
242  digi += 1024;
243  } // adding one MSB
244 
245  subtractorPed->subtract(id, firstAPV * 128, procRawDigis); // all strips are pedestals subtracted
246 
247  for (auto& digi : procRawDigis) {
248  digi /= 2;
249  }
250 
251  procRawDigisPedSubtracted.assign(procRawDigis.begin(), procRawDigis.end());
252 
253  subtractorCMN->subtract(id, firstAPV, procRawDigis);
254 
255  const auto nAPVFlagged = restorer->inspect(id, firstAPV, procRawDigis, subtractorCMN->getAPVsCM());
256 
257  for (auto& digi : procRawDigis) {
258  digi *= 2;
259  }
260 
261  const std::vector<bool>& apvf = getAPVFlags();
262  const std::size_t nAPVs = procRawDigis.size() / 128;
263  for (uint16_t iAPV = firstAPV; iAPV < nAPVs + firstAPV; ++iAPV) {
264  if (apvf[iAPV]) {
265  //GB 23/6/08: truncation should be done at the very beginning
266  for (uint16_t i = 0; i < 128; ++i) {
267  const int16_t digi = procRawDigisPedSubtracted[128 * (iAPV - firstAPV) + i];
268  output.push_back(SiStripDigi(128 * iAPV + i, (digi < 0 ? 0 : suppressor->truncate(digi))));
269  }
270  } else {
271  const auto firstDigiIt = std::begin(procRawDigis) + 128 * (iAPV - firstAPV);
272  std::vector<int16_t> singleAPVdigi(firstDigiIt, firstDigiIt + 128);
273  suppressor->suppress(singleAPVdigi, iAPV, output);
274  }
275  }
276 
277  return nAPVFlagged;
278 }
279 
293  edm::DetSet<SiStripDigi>& suppressedDigis) {
294  digivector_t rawdigis;
295  rawdigis.reserve(rawDigis.size());
296  std::transform(std::begin(rawDigis), std::end(rawDigis), std::back_inserter(rawdigis), [](SiStripRawDigi digi) {
297  return digi.adc();
298  });
299  return convertVirginRawToHybrid(rawDigis.id, 0, rawdigis, suppressedDigis);
300 }
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
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
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_
Log< level::Error, false > LogError
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
uint16_t suppressHybridData(const uint16_t maxStrip, const edm::DetSet< SiStripDigi > &inDigis, edm::DetSet< SiStripDigi > &suppressedDigis, uint16_t firstAPV=0)
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
Definition: output.py:1
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
unsigned transform(const HcalDetId &id, unsigned transformCode)