Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip hybrid zero suppression: do less work if the APV is already zero-suppressed #29759

Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,8 @@ void ClusterFiller::fill(StripClusterizerAlgorithm::output_t::TSFastFiller& reco
lmode,
pCode);
if (fedchannelunpacker::StatusCode::SUCCESS == st_ch) {
SiStripRawProcessingAlgorithms::digivector_t workRawDigis;
rawAlgos.convertHybridDigiToRawDigiVector(unpDigis, workRawDigis);
edm::DetSet<SiStripDigi> suppDigis{id};
rawAlgos.suppressHybridData(id, ipair * 2, workRawDigis, suppDigis);
rawAlgos.suppressHybridData(unpDigis, suppDigis, ipair * 2);
std::copy(std::begin(suppDigis), std::end(suppDigis), perStripAdder);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ class SiStripRawProcessingAlgorithms {

uint16_t suppressHybridData(const edm::DetSet<SiStripDigi>& inDigis,
edm::DetSet<SiStripDigi>& suppressedDigis,
digivector_t& rawDigis);
uint16_t suppressHybridData(uint32_t detId,
uint16_t firstAPV,
digivector_t& processedRawDigis,
edm::DetSet<SiStripDigi>& suppressedDigis);
uint16_t firstAPV = 0);

uint16_t suppressVirginRawData(uint32_t detId,
uint16_t firstAPV,
Expand All @@ -48,8 +44,6 @@ class SiStripRawProcessingAlgorithms {
uint16_t convertVirginRawToHybrid(const edm::DetSet<SiStripRawDigi>& rawDigis,
edm::DetSet<SiStripDigi>& suppressedDigis);

void convertHybridDigiToRawDigiVector(const edm::DetSet<SiStripDigi>& inDigis, digivector_t& rawDigis);

inline const std::vector<bool>& getAPVFlags() const { return restorer->getAPVFlags(); }
inline const SiStripAPVRestorer::baselinemap_t& getBaselineMap() const { return restorer->getBaselineMap(); }
inline const std::map<uint16_t, SiStripAPVRestorer::digimap_t>& getSmoothedPoints() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ SiStripZeroSuppression::SiStripZeroSuppression(edm::ParameterSet const& conf)
throw cms::Exception("Invalid option") << "When producing data in the hybrid format, the APV restorer must be "
"configured with APVInspectMode='HybridEmulation'";

if ((!hybridInputs.empty()) && produceRawDigis) {
edm::LogInfo("SiStripZeroSuppression") << "Raw digis will not be saved for hybrid inputs";
}

if (!(rawInputs.empty() && hybridInputs.empty())) {
output_base.reserve(16000);
if (produceRawDigis)
if (produceRawDigis && !rawInputs.empty())
output_base_raw.reserve(16000);
if (storeCM)
output_apvcm.reserve(16000);
Expand Down Expand Up @@ -105,7 +109,7 @@ inline void SiStripZeroSuppression::clearOutputs() {
}
inline void SiStripZeroSuppression::putOutputs(edm::Event& evt, const std::string& tagName) {
evt.put(std::make_unique<edm::DetSetVector<SiStripDigi>>(output_base), tagName);
if (produceRawDigis)
if (produceRawDigis && !rawInputs.empty())
evt.put(std::make_unique<edm::DetSetVector<SiStripRawDigi>>(output_base_raw), tagName);
if (produceCalculatedBaseline)
evt.put(std::make_unique<edm::DetSetVector<SiStripProcessedRawDigi>>(output_baseline), "BADAPVBASELINE" + tagName);
Expand Down Expand Up @@ -146,16 +150,12 @@ inline void SiStripZeroSuppression::processHybrid(const edm::DetSetVector<SiStri
for (const auto& inDigis : input) {
edm::DetSet<SiStripDigi> suppressedDigis(inDigis.id);

std::vector<int16_t> rawDigis;
const auto nAPVflagged = algorithms->suppressHybridData(inDigis, suppressedDigis, rawDigis);
uint16_t nAPVflagged = 0;
nAPVflagged = algorithms->suppressHybridData(inDigis, suppressedDigis);

storeExtraOutput(inDigis.id, nAPVflagged);
if (!suppressedDigis.empty() && (storeInZScollBadAPV || nAPVflagged == 0))
if (!suppressedDigis.empty())
output_base.push_back(std::move(suppressedDigis));

if (produceRawDigis && nAPVflagged > 0) {
output_base_raw.push_back(formatRawDigis(inDigis.id, rawDigis));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,53 +42,6 @@ void SiStripRawProcessingAlgorithms::initialize(const edm::EventSetup& es, const
restorer->loadMeanCMMap(e);
}

/**
* Zero-suppress "hybrid" raw data
*
* Subtracts common-mode noise, and inspects the digis then.
* If flagged by the APV inspector, the zero-suppression is performed as usual;
* otherwise the positive inputs are copied.
*
* @param id module DetId
* @param firstAPV index of the first APV considered
* @param procRawDigis input (processed raw) ADCs. Note that this means that
* ADCs for all strips are expected, so zero-suppressed data should be filled with zeros for the suppressed strips.
* Output: the ADCs after all subtractions, but before zero-suppression.
* @param output zero-suppressed digis
* @return number of restored APVs
*/
//IMPORTANT: don't forget the conversion from hybrids on the bad APVs (*2 -1024)
uint16_t SiStripRawProcessingAlgorithms::suppressHybridData(uint32_t id,
uint16_t firstAPV,
digivector_t& procRawDigis,
edm::DetSet<SiStripDigi>& suppressedDigis) {
digivector_t procRawDigisPedSubtracted(procRawDigis);

subtractorCMN->subtract(id, firstAPV, procRawDigis);

const auto nAPVFlagged =
restorer->inspectAndRestore(id, firstAPV, procRawDigisPedSubtracted, procRawDigis, subtractorCMN->getAPVsCM());

const std::vector<bool>& apvf = getAPVFlags();
const std::size_t nAPVs = procRawDigis.size() / 128;
for (uint16_t iAPV = firstAPV; iAPV < firstAPV + nAPVs; ++iAPV) {
if (apvf[iAPV]) {
const auto firstDigiIt = std::begin(procRawDigis) + 128 * (iAPV - firstAPV);
std::vector<int16_t> singleAPVdigi(firstDigiIt, firstDigiIt + 128);
suppressor->suppress(singleAPVdigi, iAPV, suppressedDigis);
} else {
for (uint16_t i = 0; i < 128; ++i) {
const int16_t digi = procRawDigisPedSubtracted[128 * (iAPV - firstAPV) + i];
if (digi > 0) {
suppressedDigis.push_back(SiStripDigi(iAPV * 128 + i, suppressor->truncate(digi)));
}
}
}
}

return nAPVFlagged;
}

/**
* Zero-suppress "hybrid" raw data
*
Expand All @@ -97,47 +50,50 @@ uint16_t SiStripRawProcessingAlgorithms::suppressHybridData(uint32_t id,
* Otherwise, the positive inputs are copied.
*
* @param hybridDigis input ADCs in ZS format (regular ZS or "hybrid", i.e. processed as x->(x+1024-ped)/2)
* @param output zero-suppressed digis
* @param RawDigis processed ADCs
* @param suppressedDigis zero-suppressed digis
* @param firstAPV (optional) number of the first APV for which digis are should be handled (otherwise all present)
*
* @return number of restored APVs
*/
uint16_t SiStripRawProcessingAlgorithms::suppressHybridData(const edm::DetSet<SiStripDigi>& hybridDigis,
edm::DetSet<SiStripDigi>& suppressedDigis,
digivector_t& rawDigis) {
convertHybridDigiToRawDigiVector(hybridDigis, rawDigis);
return suppressHybridData(hybridDigis.id, 0, rawDigis, suppressedDigis);
}

/**
* Convert hybrid digis to a list of processed raw ADCs
*
* Non-zero-suppressed APVs are identified by the number of ADCs found (above 64),
* and the ADCs converted into normal processed format (x->x*2-1024).
* For zero-supppressed APVs the absent strips are set to zero ADC.
*
* @param inDigis input (non-ZS hybrid or ZS) data
* @param RawDigis processed raw (or zero-filled ZS) ADCs
*/
void SiStripRawProcessingAlgorithms::convertHybridDigiToRawDigiVector(const edm::DetSet<SiStripDigi>& inDigis,
digivector_t& rawDigis) {
const auto stripModuleGeom = dynamic_cast<const StripGeomDetUnit*>(trGeo->idToDetUnit(inDigis.id));
const std::size_t nStrips = stripModuleGeom->specificTopology().nstrips();
const std::size_t nAPVs = nStrips / 128;

rawDigis.assign(nStrips, 0);
std::vector<uint16_t> stripsPerAPV(nAPVs, 0);

for (SiStripDigi digi : inDigis) {
rawDigis[digi.strip()] = digi.adc();
++stripsPerAPV[digi.strip() / 128];
}

for (uint16_t iAPV = 0; iAPV < nAPVs; ++iAPV) {
if (stripsPerAPV[iAPV] > 64) {
for (uint16_t strip = iAPV * 128; strip < (iAPV + 1) * 128; ++strip)
rawDigis[strip] = rawDigis[strip] * 2 - 1024;
uint16_t firstAPV) {
uint16_t nAPVFlagged = 0;
auto beginAPV = hybridDigis.begin();
const auto indigis_end = hybridDigis.end();
auto iAPV = firstAPV;
while (beginAPV != indigis_end) {
const auto endAPV = std::lower_bound(beginAPV, indigis_end, SiStripDigi((iAPV + 1) * 128, 0));
const auto nDigisInAPV = std::distance(beginAPV, endAPV);
if (nDigisInAPV > 64) {
digivector_t workDigis(128, -1024);
for (auto it = beginAPV; it != endAPV; ++it) {
workDigis[it->strip() - 128 * iAPV] = it->adc() * 2 - 1024;
}
digivector_t workDigisPedSubtracted(workDigis);
subtractorCMN->subtract(hybridDigis.id, iAPV, workDigis);
const auto apvFlagged = restorer->inspectAndRestore(
hybridDigis.id, iAPV, workDigisPedSubtracted, workDigis, subtractorCMN->getAPVsCM());
nAPVFlagged += apvFlagged;
if (getAPVFlags()[iAPV]) {
suppressor->suppress(workDigis, iAPV, suppressedDigis);
} else { // bad APV: more than 64 but not flagged
for (uint16_t i = 0; i != 128; ++i) {
const auto digi = workDigisPedSubtracted[i];
if (digi > 0) {
suppressedDigis.push_back(SiStripDigi(iAPV * 128 + i, suppressor->truncate(digi)));
}
}
}
} else { // already zero-suppressed, copy and truncate
std::transform(beginAPV, endAPV, std::back_inserter(suppressedDigis), [this](const SiStripDigi inDigi) {
return SiStripDigi(inDigi.strip(), suppressor->truncate(inDigi.adc()));
});
}
beginAPV = endAPV;
++iAPV;
}
return nAPVFlagged;
}

/**
Expand Down