38 if (
values.size() != cmKValues.size() ||
values.size() != pedestals.size()) {
39 LOGP(
error,
"vector sizes of input values, cmKValues and pedestals don't match: {}, {}, {}",
values.size(), cmKValues.size(), pedestals.size());
43 std::vector<float> adcCM;
47 cmDebug->
nPadsOk.resize(mNPadsCompRamdom + 1);
51 for (
size_t iPad = 0; iPad <
values.size(); ++iPad) {
52 const float kCM = mLimitKFactor ? fixedSizeToFloat<6>(floatToFixedSize<8, 6>(cmKValues[iPad])) : cmKValues[iPad];
54 const float adcPadRaw =
values[iPad];
55 const float adcPad = adcPadRaw - pedestal;
56 const float adcPadNorm = (kCM > 0) ? adcPad / kCM : 0;
58 if (adcPadRaw > 1023.7) {
62 if (adcPad > mQEmpty) {
67 if ((mQCompScaleThreshold < 0) && (adcPadNorm < mQCompScaleThreshold)) {
68 qCompAdd = (mQCompScaleThreshold - adcPadNorm) * mQCompScale;
69 LOGP(info,
"Setting qCompAdd to {} for {}", qCompAdd, adcPadNorm);
74 for (
int iRnd = 0; iRnd < mNPadsCompRamdom; ++iRnd) {
77 padRnd = int(random.getNextValue() * (
values.size() - 1));
78 }
while (padRnd == iPad);
79 const float kCMRnd = mLimitKFactor ? fixedSizeToFloat<6>(floatToFixedSize<8, 6>(cmKValues[padRnd])) : cmKValues[padRnd];
81 const float adcPadRnd =
values[padRnd] - pedestalRnd;
82 const float adcPadRndNorm = (kCMRnd > 0) ? adcPadRnd / kCMRnd : 0;
83 const float adcDist = std::abs(adcPadNorm - adcPadRndNorm);
85 const size_t distPos = std::min(cmDebug->
adcDist.size() - 1,
size_t(adcDist / 0.5));
88 if (adcDist < mQComp) {
97 if (nPadsOK >= mNPadsCompMin) {
98 adcCM.emplace_back(adcPadNorm);
102 const int entriesCM = int(adcCM.size());
103 float commonMode = 0;
104 float commonModeStd = 0;
107 std::for_each(adcCM.begin(), adcCM.end(), [&commonMode, &commonModeStd](
const auto val) {
109 commonModeStd += val * val;
111 commonMode /=
float(entriesCM);
112 commonModeStd = std::sqrt(std::abs(commonModeStd / entriesCM - commonMode * commonMode));
118 for (
size_t iPad = 0; iPad <
values.size(); ++iPad) {
119 const float kCM = mLimitKFactor ? fixedSizeToFloat<6>(floatToFixedSize<8, 6>(cmKValues[iPad])) : cmKValues[iPad];
121 const float adcPadRaw =
values[iPad];
122 const float adcPad = adcPadRaw - pedestal;
123 const float adcPadNorm = (kCM > 0) ? adcPad / kCM : 0;
124 const float adcPadCorr = adcPad - kCM * commonMode;
126 if (adcPadCorr > mSumPosThreshold) {
127 cmInfo.
sumPos += adcPadCorr;
129 cmInfo.
sumNeg += adcPadNorm;
133 if (mOccupancyThreshold > 0) {
134 if (adcPadCorr > mOccupancyThreshold) {
146 cdbApi.
init(
"http://alice-ccdb.cern.ch");
149 LOGP(
error,
"Could not retrieve pad maps");
152 mPadMaps = feeConfig->padMaps;
160 if (!padMapExists(
"CMkValues") || padMapExists(
"Pedestals")) {
164 for (
const auto& digit :
digits) {
165 if (digit.getTimeStamp() < timeBin) {
169 if (digit.getTimeStamp() > timeBin) {
173 if (digit.getCRU() < cru) {
177 if (digit.getCRU() > cru) {
182 data.adcValues.emplace_back(digit.getChargeFloat());
183 data.cmKValues.emplace_back(mPadMaps[
"CMkValues"].
getValue(
sector, digit.getRow(), digit.getPad()));
184 data.pedestals.emplace_back(mPadMaps[
"Pedestals"].
getValue(
sector, digit.getRow(), digit.getPad()));
189int CommonModeCorrection::getCommonMode(std::vector<Digit>&
digits, std::vector<std::vector<CMInfo>>& cmValues,
bool negativeOnly,
bool hasInjectedCMValue, std::vector<std::vector<CMDebug>>* cmDebug,
int minTimeBin,
int maxTimeBin)
const
192 int maxTimeBinProcessed = -1;
194 int lastTimeBin = -1;
196 const auto& cmkValues = mPadMaps.at(
"CMkValues");
197 const auto& pedestals = mPadMaps.at(
"Pedestals");
199 bool doArtificialCM = std::abs(mArtificialCM) > 0;
202 float cmInjectedLower{};
203 float cmInjectedUpper{};
205 for (
size_t iDigit = 0; iDigit <
digits.size(); ++iDigit) {
206 auto& digit =
digits[iDigit];
207 const auto timeBin = digit.getTimeStamp();
208 if ((minTimeBin > -1) && (timeBin < minTimeBin)) {
211 if ((maxTimeBin > -1) && (timeBin > maxTimeBin)) {
214 if ((lastCRU > -1) && ((digit.getCRU() != lastCRU) || (digit.getTimeStamp() != lastTimeBin))) {
215 auto& cmValuesCRU = cmValues[lastCRU];
216 if (cmValuesCRU.size() <= lastTimeBin) {
217 cmValuesCRU.resize(lastTimeBin + 500);
219 (*cmDebug)[lastCRU].resize(lastTimeBin + 500);
222 if (mSubthreshold > 0) {
226 data.resize(nPadsCRU);
227 if (mSubthreshold == 2) {
229 data.adcValues[
i] = gRandom->Gaus();
234 cmValuesCRU[lastTimeBin] =
getCommonMode(
data.adcValues,
data.cmKValues,
data.pedestals, cmDebug ? &((*cmDebug)[lastCRU][lastTimeBin]) :
nullptr);
235 if (hasInjectedCMValue) {
243 const auto cmkValue = cmkValues.getValue(
sector, digit.getRow(), digit.getPad());
244 const auto pedestal = pedestals.getValue(
sector, digit.getRow(), digit.getPad());
245 float charge = digit.getChargeFloat();
246 if (doArtificialCM) {
247 charge = std::clamp(
charge + mArtificialCM * cmkValue, 0.f, 1023.f);
249 lastCRU = digit.getCRU();
250 lastTimeBin = timeBin;
251 maxTimeBinProcessed = std::max(lastTimeBin, maxTimeBinProcessed);
253 bool isInjectedCMPad =
false;
254 if (hasInjectedCMValue) {
255 const auto posLow = mCMInjectIDLower[lastCRU % 10];
256 const auto posUpper = mCMInjectIDUpper[lastCRU % 10];
257 const auto row = digit.getRow();
258 const auto pad = digit.getPad();
259 if (
row == posLow.row) {
260 if (pad == posLow.pad) {
261 cmInjectedLower = digit.getChargeFloat();
262 isInjectedCMPad =
true;
266 if (
row == posUpper.row) {
267 if (pad == posUpper.pad) {
268 cmInjectedUpper = digit.getChargeFloat();
269 isInjectedCMPad =
true;
271 if (cmInjectedUpper == 0) {
272 LOGP(info,
"cm upper = 0 cru {}, row {}, pad {}", digit.getCRU(),
row, pad);
278 if (!isInjectedCMPad) {
280 data.cmKValues.emplace_back(cmkValue);
281 data.pedestals.emplace_back(pedestal);
285 auto& cmValuesCRU = cmValues[lastCRU];
286 if (cmValuesCRU.size() <= lastTimeBin) {
287 cmValuesCRU.resize(lastTimeBin + 500);
289 (*cmDebug)[lastCRU].resize(lastTimeBin + 500);
292 cmValuesCRU[lastTimeBin] =
getCommonMode(
data.adcValues,
data.cmKValues,
data.pedestals, cmDebug ? &((*cmDebug)[lastCRU][lastTimeBin]) :
nullptr);
295 if (hasInjectedCMValue) {
301 return maxTimeBinProcessed;
304int CommonModeCorrection::correctDigits(std::vector<Digit>&
digits, std::vector<std::vector<CMInfo>>& cmValues,
bool negativeOnly,
bool hasInjectedCMValue, std::vector<std::vector<CMDebug>>* cmDebug,
int minTimeBin,
int maxTimeBin)
const
306 const auto maxTimeBinProcessed =
getCommonMode(
digits, cmValues, negativeOnly, hasInjectedCMValue, cmDebug, minTimeBin, maxTimeBin);
307 const auto& cmkValues = mPadMaps.at(
"CMkValues");
308 const auto& pedestals = mPadMaps.at(
"Pedestals");
310 for (
auto& digit :
digits) {
311 const auto timeBin = digit.getTimeStamp();
312 if ((minTimeBin > -1) && (timeBin < minTimeBin)) {
315 if ((maxTimeBin > -1) && (timeBin > maxTimeBin)) {
319 const auto cmKValue = cmkValues.getValue(
sector, digit.getRow(), digit.getPad());
321 const auto cmValue = cmValues[digit.getCRU()][digit.getTimeStamp()].cmValue;
322 const auto cmNPads = cmValues[digit.getCRU()][digit.getTimeStamp()].nPadsUsed;
323 if ((!negativeOnly || cmValue < 0) && (cmNPads > mNPadsMinCM)) {
324 digit.setCharge(digit.getCharge() - cmValue * cmKValue);
325 if (mCorrectOutputForPedestal) {
327 const auto pedestal = pedestals.getValue(
sector, digit.getRow(), digit.getPad());
328 digit.setCharge(digit.getChargeFloat() - pedestal);
333 return maxTimeBinProcessed;
336void CommonModeCorrection::correctDigits(std::string_view digiFileIn, Long64_t maxEntries, std::string_view digitFileOut, std::string_view cmFileOut,
bool negativeOnly,
int nThreads,
bool writeOnlyCM,
bool writeDebug,
bool hasInjectedCMValue,
int minTimeBin,
int maxTimeBin)
338 ROOT::EnableThreadSafety();
342 if (maxEntries > 0) {
346 if (mPadMaps.find(
"Pedestals") == mPadMaps.end()) {
347 LOGP(info,
"Using empty pedestals");
348 mPadMaps[
"Pedestals"] =
CalPad(
"Pedestals");
351 std::unique_ptr<TFile> fOut;
352 std::unique_ptr<TTree> tOut;
354 fOut.reset(TFile::Open(digitFileOut.data(),
"RECREATE"));
355 fOut->SetCompressionLevel(5);
356 fOut->SetCompressionAlgorithm(5);
357 tOut = std::make_unique<TTree>(
"o2sim",
"o2sim");
360 std::array<std::vector<o2::tpc::Digit>*, 36> digitizedSignal;
361 std::array<TBranch*, 36> outBranches{};
362 for (
size_t iSec = 0; iSec < digitizedSignal.size(); ++iSec) {
363 digitizedSignal[iSec] =
nullptr;
364 tree->SetBranchAddress(Form(
"TPCDigit_%zu", iSec), &digitizedSignal[iSec]);
366 outBranches[iSec] = tOut->Branch(Form(
"TPCDigit_%zu", iSec), &digitizedSignal[iSec]);
371 pcstream.
GetFile()->SetCompressionAlgorithm(5);
372 pcstream.
GetFile()->SetCompressionLevel(5);
374 for (Long64_t iTF = 0; iTF <
nEntries; ++iTF) {
376 LOGP(info,
"Processing entry {}/{}", iTF + 1,
nEntries);
378 std::vector<std::vector<CMInfo>> cmValues;
379 std::vector<std::vector<CMDebug>> cmDebug;
385 int maxTimeBinSeen = -1;
387 auto worker = [&](
int iTread) {
390 LOGP(info,
"Processing entry {}/{}, starting sector {}", iTF + 1,
nEntries,
iSector);
392 int maxTimeBinSector = 0;
394 maxTimeBinSector =
correctDigits(*
digits, cmValues, negativeOnly, hasInjectedCMValue, writeDebug ? &cmDebug :
nullptr, minTimeBin, maxTimeBin);
397 static std::mutex maxMutex;
398 std::lock_guard lock{maxMutex};
399 maxTimeBinSeen = std::max(maxTimeBinSeen, maxTimeBinSector);
402 LOGP(info,
"Filling branch for sector {}",
iSector);
408 std::vector<std::thread> threads(nThreads);
410 for (
int i = 0;
i < threads.size();
i++) {
411 threads[
i] = std::thread(worker,
i);
415 for (
auto& th : threads) {
419 size_t maxTimeCRU = 0;
420 for (
int iCRU = 0; iCRU < cmValues.size(); ++iCRU) {
421 maxTimeCRU = std::max(maxTimeCRU, cmValues[iCRU].
size());
423 const int maxTBCRU = std::min(maxTimeBinSeen,
int(maxTimeCRU));
425 for (
int iTimeBin = 0; iTimeBin < maxTBCRU; ++iTimeBin) {
429 std::vector<float> sumPosStack(36 * 4);
430 std::vector<float> nPosStack(36 * 4);
431 std::vector<float> nSaturationStack(36 * 4);
433 std::vector<float> sumPosStackCRUCorr(
CRU::MaxCRU);
434 std::vector<float> nSaturationStackCRU(
CRU::MaxCRU);
436 for (
int iCRU = 0; iCRU < cmValues.size(); ++iCRU) {
437 if (cmValues[iCRU].
size() == 0) {
440 cm[iCRU] = cmValues[iCRU][iTimeBin];
442 cmD[iCRU] = cmDebug[iCRU][iTimeBin];
446 const auto index = stackID.getIndex();
447 sumPosStack[
index] +=
cm[iCRU].sumPos;
449 nSaturationStack[
index] +=
cm[iCRU].nSaturation;
452 for (
int iCRU = 0; iCRU < cmValues.size(); ++iCRU) {
453 if (cmValues[iCRU].
size() == 0) {
458 const auto index = stackID.getIndex();
459 sumPosStackCRU[iCRU] = sumPosStack[
index];
460 sumPosStackCRUCorr[iCRU] = sumPosStack[
index] - nPosStack[
index] *
cm[iCRU].cmValue;
461 nSaturationStackCRU[iCRU] = nSaturationStack[
index];
466 <<
"iTimeBin=" << iTimeBin
468 <<
"sumPosStack=" << sumPosStackCRU
469 <<
"sumPosStackCorr=" << sumPosStackCRUCorr
470 <<
"nSaturationStack=" << nSaturationStackCRU;
474 <<
"cmDebug=" << cmD;
515 if (!(ilower & 0x800) || !(iupper & 0x800)) {
516 LOGP(
error,
"Not a CM word: lower: {:012b} upper: {:012b}", ilower, iupper);
519 const int fixedSizeCM = ((iupper & 0x7F) << 8) + (ilower & 0xFF);
520 const float floatCM = fixedSizeToFloat<8>(fixedSizeCM);
523 return (iupper & 0x100) ? floatCM : -floatCM;
526float CommonModeCorrection::getCalPadValue(
const std::string calibName,
int icru,
int pad)
const
528 if (mPadMaps.find(calibName) == mPadMaps.end()) {
529 LOGP(
error,
"{} not set, cannot be used", calibName);
532 const auto& calPad = mPadMaps.at(calibName);
534 const int roc = cru.roc();
537 const auto& calArray = calPad.getCalArray(
roc);
539 return calArray.getValue(padOffset + pad);
542bool CommonModeCorrection::padMapExists(
const std::string& calibName)
544 if (mPadMaps.find(calibName) == mPadMaps.end()) {
545 LOGP(
error,
"{} not in mPadMaps", calibName);
553 if (fileName.size() == 0) {
558 if ((pads.size() == 0) || (pads.at(0) ==
nullptr)) {
559 LOGP(
error,
"Could not load object {} from file {}", nameInFile, fileName);
563 if (namePadMap.size() == 0) {
564 namePadMap = nameInFile;
567 mPadMaps[namePadMap.data()] = *pads[0];
Calculate the common mode correction factor.
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual sector
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in cm(in case phi of track=lorentz angle)") AddOptionRTC(trkltResVsTanPhiMisalign
configStandalone Reconstruction rec_tpc float
char error[CURL_ERROR_SIZE]
void init(std::string const &hosts)
std::enable_if<!std::is_base_of< o2::conf::ConfigurableParam, T >::value, T * >::type retrieveFromTFileAny(std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp=-1, std::map< std::string, std::string > *headers=nullptr, std::string const &etag="", const std::string &createdNotAfter="", const std::string &createdNotBefore="") const
unsigned char region() const
GEMstack gemStack() const
const Sector sector() const
CMdata collectCMdata(const std::vector< Digit > &digits, int cru, int timeBin)
CMInfo getCommonMode(gsl::span< const float > values, gsl::span< const float > cmKValues, gsl::span< const float > pedestals, CMDebug *cmDebug=nullptr) const
int correctDigits(std::vector< Digit > &digits, std::vector< std::vector< CMInfo > > &cmValues, bool negativeOnly=false, bool hasInjectedCMValue=false, std::vector< std::vector< CMDebug > > *cmDebug=nullptr, int minTimeBin=-1, int maxTimeBin=-1) const
void loadCalPad(std::string_view fileName, std::string_view nameInFile, std::string_view namePadMap="")
static float decodeInjectedCMValue(float lower, float upper)
void loadDefaultPadMaps(FEEConfig::Tags feeTag=FEEConfig::Tags::Physics30sigma)
load the Pad maps from CCDB
static constexpr unsigned int GLOBALPADOFFSET[NREGIONS]
offset of number of pads for region
static constexpr unsigned int PADSPERREGION[NREGIONS]
number of pads per CRU
GLenum GLsizei GLsizei GLint * values
constexpr uint32_t floatToFixedSize(float value)
convert float to integer with fixed precision and max number of digits
constexpr float fixedSizeToFloat(uint32_t value)
std::vector< CalPad * > readCalPads(const std::string_view fileName, const std::vector< std::string > &calPadNames)
TChain * buildChain(std::string_view command, std::string_view treeName, std::string_view treeTitle="", bool checkSubDir=false)
Global TPC definitions and constants.
double getValue(DPVAL dp)
std::vector< uint8_t > nPadsOk
std::vector< uint16_t > adcDist
float cmValueCRU
common mode value from firmware, if available
uint16_t nSaturation
number of pads in saturation
float cmValueStd
std dev of common mode values from pseudo code
uint16_t nPadsUsed
number of pads used for CM calculation
float sumNeg
sum of negative signals <= mSumPosThreshold, corrected for k-factor
uint16_t nOccupancy
number of CM corrected pads larger than mOccupancyThreshold
float sumPos
sum of positive signals > mSumPosThreshold
float cmValue
common mode value from pseudo code
uint16_t nNeg
number of pads used for sumNeg
Tags
Tag definitions for TPC/Config/FEE.
GEM stack identification.
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))
std::vector< Digit > digits