16#ifndef O2_ITSMFT_CTFCODER_H
17#define O2_ITSMFT_CTFCODER_H
47 static constexpr o2::detectors::DetID ID{N == o2::detectors::DetID::ITS ? o2::detectors::DetID::ITS : o2::detectors::DetID::MFT};
56 template <typename VEC>
61 template <typename VROF, typename VCLUS, typename VPAT>
65 template <typename VROF, typename VDIG>
79 template <typename VROF, typename VCLUS, typename VPAT>
83 template <typename VROF, typename VDIG>
86 void appendToTree(TTree&
tree,
CTF& ec,
int id = -1);
89 bool mDoStaggering{
false};
94template <
typename VEC>
100 int strobeLength = mDoStaggering ? par.roFrameLayerLengthInBC[
layer] : par.roFrameLengthInBC;
119 auto szIni = estimateCompressedSize(compCl);
125 ec->setHeader(compCl.
header);
127 ec->setANSHeader(mANSVersion);
130#define ENCODEITSMFT(part, slot, bits) CTF::get(buff.data())->encode(part, int(slot), bits, optField[int(slot)], &buff, mCoders[int(slot)], getMemMarginFactor());
151template <
typename VROF,
typename VCLUS,
typename VPAT>
155 auto compCl = decodeCompressedClusters(ec, iosize);
157 uint32_t nLayers = mDoStaggering ? par.getNLayers() : 1;
158 if (compCl.header.maxStreams != nLayers) {
159 throw std::runtime_error(fmt::format(
"header maxStreams={} is not the same as NStreams={} in {}staggered mode", compCl.header.maxStreams, nLayers, mDoStaggering ?
"" :
"non-"));
168template <
typename VROF,
typename VDIG>
172 auto compCl = decodeCompressedClusters(ec, iosize);
173 decompress(compCl, rofRecVec, digVec, noiseMap,
clPattLookup);
180template <
typename VROF,
typename VCLUS,
typename VPAT>
184 RowColBuff firedPixBuff{}, maskedPixBuff{};
191 uint32_t clCount = 0, chipCount = 0;
192 auto pattIt = compCl.
pattMap.begin();
193 auto pattItStored = pattIt;
198 auto clusterize = [&](
uint16_t chipID, int16_t
row, int16_t
col,
int leftFired) {
199#ifdef _ALLOW_DIAGONAL_ALPIDE_CLUSTERS_
200 const std::array<int16_t, 8> walkRow = {1, -1, 0, 0, 1, 1, -1, -1};
201 const std::array<int16_t, 8> walkCol = {0, 0, -1, 1, 1, -1, 1, 1};
203 const std::array<int16_t, 4> walkRow = {1, -1, 0, 0};
204 const std::array<int16_t, 4> walkCol = {0, 0, -1, 1};
206 Clusterer::BBox
bbox(chipID);
208 std::function<
bool(int16_t, int16_t)> checkPixelAndNeighbours = [&](int16_t ir1, int16_t ic1) {
210 auto checkPixel = [&](int16_t ir1, int16_t ic1) {
211 if (pmat[ir1][ic1]) {
212 pmat[ir1][ic1] =
false;
214 firedPixBuff.emplace_back(
r,
c);
222 if (checkPixel(ir1, ic1) && leftFired) {
224 while (checkPixelAndNeighbours(ir1 + walkRow[iw], ic1 + walkCol[iw]) && ++iw < walkRow.size()) {
231 firedPixBuff.clear();
232 for (
auto s : maskedPixBuff) {
235 checkPixelAndNeighbours(
s.getRowDirect() + walkRow[iw],
s.getCol() + walkCol[iw]);
236 if (!firedPixBuff.empty()) {
237 bbox.chipID = chipID;
239 firedPixBuff.clear();
242 }
while (leftFired && ++iw < walkRow.size());
249 auto reclusterize = [&]() {
253 auto pattItPrev = pattIt;
254 maskedPixBuff.clear();
255 int rowRef = clus.getRow(), colRef = clus.getCol();
257 throw std::runtime_error(
"Clusters contain pattern IDs, but no dictionary is provided...");
263 float xCOG = 0, zCOG = 0;
265 rowRef -= round(xCOG);
266 colRef -= round(zCOG);
271 if (rowSpan == 1 && colSpan == 1) {
272 if (noiseMap->
isNoisy(clus.getChipID(), rowRef, colRef)) {
273 std::copy(pattItStored, pattItPrev, back_inserter(
pattVec));
274 pattItStored = pattIt;
280 for (
int ir = 0;
ir < rowSpan;
ir++) {
281 int row = rowRef +
ir;
282 for (
int ic = 0; ic < colSpan; ic++) {
284 if (noiseMap->
isNoisy(clus.getChipID(),
row, colRef + ic)) {
285 maskedPixBuff.emplace_back(
ir + 1, ic + 1);
286 pmat[
ir + 1][ic + 1] =
false;
289 pmat[
ir + 1][ic + 1] =
true;
293 pmat[
ir + 1][ic + 1] =
false;
300 std::copy(pattItStored, pattItPrev, back_inserter(
pattVec));
301 pattItStored = pattIt;
303 clusterize(clus.getChipID(), rowRef, colRef, nPixels);
312 auto& rofRec = rofRecVec[irof];
319 rofRec.setBCData(prevIR);
320 rofRec.setFirstEntry(
cclusVec.size());
327 auto& clus =
cclusVec.emplace_back();
328 if (inChip++ < compCl.
chipMul[chipCount]) {
329 clus.setCol((
col += compCl.
colInc[clCount]));
331 chipID += compCl.
chipInc[++chipCount];
333 clus.setCol((
col = compCl.
colInc[clCount]));
335 clus.setRow(compCl.
row[clCount]);
336 clus.setPatternID(compCl.
pattID[clCount]);
337 clus.setChipID(chipID);
346 rofRec.setNEntries(
cclusVec.size() - rofRec.getFirstEntry());
349 if (pattItStored != pattIt) {
350 std::copy(pattItStored, pattIt, back_inserter(
pattVec));
361 throw std::runtime_error(
"mismatch between expected and counter number of clusters");
368template <
typename VROF,
typename VDIG>
369void CTFCoder<N>::decompress(
const CompressedClusters& compCl, VROF& rofRecVec, VDIG& digVec,
const NoiseMap* noiseMap,
const LookUp&
clPattLookup)
371 rofRecVec.resize(compCl.header.nROFs);
372 digVec.reserve(compCl.header.nClusters * 2);
374 uint32_t clCount = 0, chipCount = 0;
375 auto pattIt = compCl.pattMap.begin();
377 for (
uint32_t irof = 0; irof < compCl.header.nROFs; irof++) {
378 size_t chipStartNDig = digVec.size();
380 auto& rofRec = rofRecVec[irof];
381 if (compCl.orbitIncROF[irof]) {
382 prevIR.bc = compCl.bcIncROF[irof];
383 prevIR.orbit += compCl.orbitIncROF[irof];
385 prevIR.bc += compCl.bcIncROF[irof];
387 rofRec.setBCData(prevIR);
388 rofRec.setFirstEntry(digVec.size());
391 uint16_t chipID = compCl.firstChipROF[irof],
col = 0;
393 for (
uint32_t icl = 0; icl < compCl.nclusROF[irof]; icl++) {
394 if (inChip++ < compCl.chipMul[chipCount]) {
395 col += compCl.colInc[clCount];
398 auto added = digVec.size() - chipStartNDig;
400 std::sort(digVec.end() - added, digVec.end(),
401 [](Digit&
a, Digit&
b) { return a.getColumn() < b.getColumn() || (a.getColumn() == b.getColumn() && a.getRow() < b.getRow()); });
403 chipStartNDig = digVec.size();
404 chipID += compCl.chipInc[++chipCount];
405#ifdef _CHECK_INCREMENTES_
406 if (int16_t(compCl.chipInc[chipCount]) < 0) {
407 LOG(warning) <<
"Negative chip increment " << int16_t(compCl.chipInc[chipCount]) <<
" -> " << chipID;
411 col = compCl.colInc[clCount];
413 uint16_t rowRef = compCl.row[clCount], colRef =
col;
414 auto pattID = compCl.pattID[clCount];
419 throw std::runtime_error(
"Clusters contain pattern IDs, but no dictionary is provided...");
425 float xCOG = 0., zCOG = 0.;
427 rowRef -= round(xCOG);
428 colRef -= round(zCOG);
435 auto fillRowCol = [&digVec, chipID, rowRef, colRef, noiseMap](
int r,
int c) {
438 if (noiseMap && noiseMap->isNoisy(chipID,
r,
c)) {
445 auto added = digVec.size() - chipStartNDig;
447 std::sort(digVec.end() - added, digVec.end(),
448 [](Digit&
a, Digit&
b) { return a.getColumn() < b.getColumn() || (a.getColumn() == b.getColumn() && a.getRow() < b.getRow()); });
451 if (compCl.nclusROF[irof]) {
454 rofRec.setNEntries(digVec.size() - rofRec.getFirstEntry());
457 assert(pattIt == compCl.pattMap.end());
458 assert(chipCount == compCl.header.nChips);
460 if (clCount != compCl.header.nClusters) {
461 LOGP(
error,
"expected {} but counted {} clusters in {} ROFRecords", compCl.header.nClusters, clCount, compCl.header.nROFs);
462 if (clCount > compCl.header.nClusters) {
463 throw std::runtime_error(
"mismatch between expected and counter number of clusters");
Declarations for CTFCoderBase class (support of external dictionaries)
Definition of the ITSMFT compact cluster.
unsigned short int uint16_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
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 maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc bool
char error[CURL_ERROR_SIZE]
#define ENCODEITSMFT(part, slot, bits)
Definition of the ITS cluster finder.
Definition of the LookUp class.
Definition of the ITSMFT NoiseMap.
Transient data classes for single pixel and set of pixels from current chip.
static const DPLAlpideParam< N > & Instance()
<<======================== Auxiliary classes =======================<<
static constexpr int getNBlocks()
EncodedBlocks< CTFHeader, N, uint32_t > base
static auto create(void *head, size_t sz)
create container from arbitrary buffer of predefined size (in bytes!!!). Head is supposed to respect ...
Static class with identifiers, bitmasks and names for ALICE detectors.
void createCoders(const std::vector< char > &bufVec, o2::ctf::CTFCoderBase::OpType op) final
~CTFCoder() final=default
static constexpr o2::detectors::DetID ID
std::array< std::array< bool, ClusterPattern::MaxRowSpan+2 >, ClusterPattern::MaxColSpan+2 > PMatrix
CTFCoder(o2::ctf::CTFCoderBase::OpType op, bool doStag, const std::string &ctfdictOpt="none")
o2::ctf::CTFIOSize encode(VEC &buff, const gsl::span< const ROFRecord > &rofRecVec, const gsl::span< const CompClusterExt > &cclusVec, const gsl::span< const unsigned char > &pattVec, const LookUp &clPattLookup, int layer)
entropy-encode clusters to buffer with CTF
std::vector< PixelData > RowColBuff
o2::ctf::CTFIOSize decode(const CTF::base &ec, VROF &rofRecVec, VCLUS &cclusVec, VPAT &pattVec, const NoiseMap *noiseMap, const LookUp &clPattLookup)
entropy decode clusters from buffer with CTF
int getRowSpan() const
Returns the number of rows.
void acquirePattern(iterator &pattIt)
int getColumnSpan() const
Returns the number of columns.
static int getCOG(int rowSpan, int colSpan, const unsigned char patt[MaxPatternBytes], float &xCOG, float &zCOG)
Static: Compute pattern's COG position. Returns the number of fired pixels.
void process(Processor procRowCol)
bool isSet(int row, int col) const
static constexpr uint8_t MaxColSpan
static void streamCluster(const std::vector< PixelData > &pixbuf, const std::array< Label, MaxLabels > *lblBuff, const BBox &bbox, const LookUp &pattIdConverter, VCLUS *compClusPtr, VPAT *patternsPtr, MCTruth *labelsClusPtr, int nlab, bool isHuge=false)
static constexpr unsigned short InvalidPatternID
auto getPattern(int id) const
bool isGroup(int id) const
NoiseMap class for the ITS and MFT.
bool isNoisy(int chip, int row, int col) const
GLboolean GLboolean GLboolean b
GLenum GLuint GLint GLint layer
GLboolean GLboolean GLboolean GLboolean a
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
wrapper for the Entropy-encoded clusters of the TF
Compressed but not yet entropy-encoded clusters.
std::vector< int16_t > chipInc
number of clusters in ROF
std::vector< int16_t > bcIncROF
1st chip ID in the ROF
std::vector< int32_t > orbitIncROF
increment of ROF BC wrt BC of previous ROF
std::vector< uint16_t > pattID
increment of pixel column wrt that of prev. pixel (sometimes can be slightly negative)
std::vector< uint16_t > firstChipROF
std::vector< uint32_t > nclusROF
increment of ROF orbit wrt orbit of previous ROF
std::vector< uint8_t > pattMap
cluster pattern ID
std::vector< uint16_t > row
clusters in chip
std::vector< int16_t > colInc
row of fired pixel
std::vector< uint16_t > chipMul
increment of chipID wrt that of prev. chip
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
o2::InteractionRecord ir(0, 0)
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))
std::vector< unsigned char > pattVec
std::vector< CompClusterExt > cclusVec