Skip to content

Commit

Permalink
make sum pos / neg after correction
Browse files Browse the repository at this point in the history
  • Loading branch information
wiechula committed Nov 15, 2024
1 parent caab206 commit 9ee3790
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions Detectors/TPC/base/src/CommonModeCorrection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ CommonModeCorrection::CMInfo CommonModeCorrection::getCommonMode(gsl::span<const
const float adcPad = adcPadRaw - pedestal;
const float adcPadNorm = (kCM > 0) ? adcPad / kCM : 0;

if (adcPad > mSumPosThreshold) {
cmInfo.sumPos += adcPad;
} else {
cmInfo.sumNeg += adcPadNorm;
++cmInfo.nNeg;
}

if (adcPadRaw > 1023.7) {
++cmInfo.nSaturation;
}
Expand Down Expand Up @@ -122,13 +115,23 @@ CommonModeCorrection::CMInfo CommonModeCorrection::getCommonMode(gsl::span<const
cmInfo.cmValueStd = commonModeStd;
cmInfo.nPadsUsed = entriesCM;

if (mOccupancyThreshold > 0) {
for (size_t iPad = 0; iPad < values.size(); ++iPad) {
const float kCM = mLimitKFactor ? fixedSizeToFloat<6>(floatToFixedSize<8, 6>(cmKValues[iPad])) : cmKValues[iPad];
const float pedestal = mLimitPedestal ? fixedSizeToFloat(floatToFixedSize(pedestals[iPad])) : pedestals[iPad];
const float adcPadRaw = values[iPad];
const float adcPad = adcPadRaw - pedestal;
if (adcPad - kCM * commonMode > mOccupancyThreshold) {
for (size_t iPad = 0; iPad < values.size(); ++iPad) {
const float kCM = mLimitKFactor ? fixedSizeToFloat<6>(floatToFixedSize<8, 6>(cmKValues[iPad])) : cmKValues[iPad];
const float pedestal = mLimitPedestal ? fixedSizeToFloat(floatToFixedSize(pedestals[iPad])) : pedestals[iPad];
const float adcPadRaw = values[iPad];
const float adcPad = adcPadRaw - pedestal;
const float adcPadNorm = (kCM > 0) ? adcPad / kCM : 0;
const float adcPadCorr = adcPad - kCM * commonMode;

if (adcPadCorr > mSumPosThreshold) {
cmInfo.sumPos += adcPadCorr;
} else {
cmInfo.sumNeg += adcPadNorm;
++cmInfo.nNeg;
}

if (mOccupancyThreshold > 0) {
if (adcPadCorr > mOccupancyThreshold) {
++cmInfo.nOccupancy;
}
}
Expand Down Expand Up @@ -243,14 +246,11 @@ int CommonModeCorrection::getCommonMode(std::vector<Digit>& digits, std::vector<
if (doArtificialCM) {
charge = std::clamp(charge + mArtificialCM * cmkValue, 0.f, 1023.f);
}
data.adcValues.emplace_back(charge);
data.cmKValues.emplace_back(cmkValue);
data.pedestals.emplace_back(pedestal);

lastCRU = digit.getCRU();
lastTimeBin = timeBin;
maxTimeBinProcessed = std::max(lastTimeBin, maxTimeBinProcessed);

bool isInjectedCMPad = false;
if (hasInjectedCMValue) {
const auto posLow = mCMInjectIDLower[lastCRU % 10];
const auto posUpper = mCMInjectIDUpper[lastCRU % 10];
Expand All @@ -259,19 +259,27 @@ int CommonModeCorrection::getCommonMode(std::vector<Digit>& digits, std::vector<
if (row == posLow.row) {
if (pad == posLow.pad) {
cmInjectedLower = digit.getChargeFloat();
isInjectedCMPad = true;
// LOGP(info, "setting lower CM value cru {}, row {}, pad {}: {:012b}", digit.getCRU(), row, pad, floatToFixedSize(digit.getChargeFloat()));
}
}
if (row == posUpper.row) {
if (pad == posUpper.pad) {
cmInjectedUpper = digit.getChargeFloat();
isInjectedCMPad = true;
// LOGP(info, "setting upper CM value cru {}, row {}, pad {}: {:012b}", digit.getCRU(), row, pad, floatToFixedSize(digit.getChargeFloat()));
if (cmInjectedUpper == 0) {
LOGP(info, "cm upper = 0 cru {}, row {}, pad {}", digit.getCRU(), row, pad);
}
}
}
}

if (!isInjectedCMPad) {
data.adcValues.emplace_back(charge);
data.cmKValues.emplace_back(cmkValue);
data.pedestals.emplace_back(pedestal);
}
}
{
auto& cmValuesCRU = cmValues[lastCRU];
Expand Down

0 comments on commit 9ee3790

Please sign in to comment.