Skip to content

Commit 149ac80

Browse files
committed
Implemented comments of David and Ruben
1 parent d990619 commit 149ac80

10 files changed

Lines changed: 70 additions & 85 deletions

File tree

‎Detectors/TPC/calibration/include/TPCCalibration/CalculatedEdx.h‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class CalculatedEdx
213213
/// \return returns the number of rows where refit/propagation failed (row.propagationFailed) since the last resetDebugCounters(); with setRefit(), this only counts rows where the propagation fallback was also unable to recover the row
214214
long getNPropagationFailed() const { return mNPropagationFailed; }
215215

216-
/// \return returns the number of rows where setRefit()'s RefitTrackAsGPU() could not reach the row and the row's track state instead came from the propagation fallback since the last resetDebugCounters(); always 0 outside setRefit() mode
216+
/// \return returns the number of rows of tracks where setRefit()'s RefitTrackAsGPU() failed and the row's track state instead came from propagating the original track since the last resetDebugCounters(); always 0 outside setRefit() mode
217217
long getNRefitFallback() const { return mNRefitFallback; }
218218

219219
/// \return returns the number of rows gathered by gatherRowClusterData() (processed for refit/propagation) since the last resetDebugCounters()
@@ -400,7 +400,7 @@ class CalculatedEdx
400400
int stackNumber;
401401
StackID stackID;
402402
bool propagationFailed; ///< true if refit/propagation to this row failed, or the resulting track param is NaN, and no fallback recovered it either
403-
bool refitFellBack; ///< true if setRefit() mode's RefitTrackAsGPU() could not reach this row
403+
bool refitFellBack; ///< true if setRefit() mode's refit of this track failed and the row's track state came from propagating the original track
404404
int missingClusters; ///< number of skipped rows since the previous entry in rowData (i.e. rowIndex - previous rowIndex - 1); same for every settings entry since rowOrder does not depend on the settings
405405
bool sameSectorAsPrevRow; ///< true if this row's sector equals the previous entry in rowData's sector
406406
bool missingClusterGapDeadOrEdge; ///< true if any of the missingClusters skipped row(s) would land on a dead channel or off the padrow edge
@@ -433,11 +433,13 @@ class CalculatedEdx
433433
/// \param sectorIndexOld sectorIndex of the previous entry appended to rowData (255 if this is the first row)
434434
/// \param occupancyROC per-region occupancy accumulator, updated in place
435435
/// \param rowData output per-row data; the new row is appended, and rowData.back() (if non-empty) is read as the previous row for the missing-cluster-gap check
436-
/// \param refitAbandoned setRefit() mode only: false as long as RefitTrackAsGPU() keeps succeeding; the first
437-
/// time it fails for this track, set to true and stays true for the rest of the track. On that first
438-
/// failure, the propagation fallback resumes from the track's state just before the failed attempt
439-
/// (i.e. its state after the last successfully refit row), not from the track's pristine pre-loop state.
440-
void gatherRowClusterDataForRow(o2::tpc::TrackTPC& track, const std::vector<o2::tpc::ClusterNative>& fragmentClusters, const std::vector<bool>& fragmentIsShared, unsigned char sectorIndex, unsigned char rowIndex, bool mergeable, unsigned char rowIndexOld, unsigned char sectorIndexOld, std::array<std::vector<unsigned int>, 4>& occupancyROC, std::vector<RowClusterData>& rowData, bool& refitAbandoned);
436+
/// \param refitFailed setRefit() mode only: true if the single per-track refit in refitTrack() failed, in which case the rows are propagated from the track's original state
437+
void gatherRowClusterDataForRow(o2::tpc::TrackTPC& track, const std::vector<o2::tpc::ClusterNative>& fragmentClusters, const std::vector<bool>& fragmentIsShared, unsigned char sectorIndex, unsigned char rowIndex, bool mergeable, unsigned char rowIndexOld, unsigned char sectorIndexOld, std::array<std::vector<unsigned int>, 4>& occupancyROC, std::vector<RowClusterData>& rowData, bool refitFailed);
438+
439+
/// setRefit() mode only: refit the whole track once, outward, so that it ends at the outermost cluster; the track is then propagated row by row in gatherRowClusterDataForRow()
440+
/// \param track input track, mutated in place by the refit; left unchanged if the refit fails
441+
/// \return true if the refit failed
442+
bool refitTrack(o2::tpc::TrackTPC& track);
441443

442444
/// geometrically propagate track (rotating into the row's sector frame first) to xPosition
443445
/// \return true if any of the three attempts succeeded (track left at xPosition); false if all failed (track left unchanged, at its state on entry)
@@ -479,7 +481,7 @@ class CalculatedEdx
479481
std::unordered_map<std::string, std::unique_ptr<o2::utils::TreeStreamRedirector>> mStreamers; ///< debug streamers, keyed by output file name so each debugRootFile gets its own tree
480482
long mDebugTrackIndex{-1}; ///< running index of the track being processed, written to the debug trees so per-cluster rows can be grouped back into tracks
481483
long mNPropagationFailed{0}; ///< number of rows where refit/propagation failed (and the fallback below, if applicable, also failed) since the last resetDebugCounters()
482-
long mNRefitFallback{0}; ///< number of rows where setRefit()'s RefitTrackAsGPU() failed but the propagation fallback recovered the row, since the last resetDebugCounters()
484+
long mNRefitFallback{0}; ///< number of rows of tracks where setRefit()'s RefitTrackAsGPU() failed but propagating the original track recovered the row, since the last resetDebugCounters()
483485
long mNRowsProcessed{0}; ///< number of rows gathered by gatherRowClusterData() since the last resetDebugCounters()
484486
std::vector<long> mNSubThresholdFilledPerSettings; ///< number of row gaps filled as subthreshold clusters, per dEdxSettings list index, since the last resetDebugCounters()
485487

‎Detectors/TPC/calibration/macro/calculatedEdx.C‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void calculatedEdx(const std::string dir = ".",
326326
// per-event summary: refit/propagation failures and how many row gaps were filled as subthreshold clusters per settingsList entry
327327
const long nPropagationFailed = calcdEdx.getNPropagationFailed();
328328
const long nRowsProcessed = calcdEdx.getNRowsProcessed();
329-
const auto& nSubThresholdFilledPerSettings = calcdEdx.getNSubThresholdFilledPerSettings();
329+
const auto nSubThresholdFilledPerSettings = calcdEdx.getNSubThresholdFilledPerSettings(); // copy: resetDebugCounters() below clears the member
330330
calcdEdx.resetDebugCounters();
331331
std::string subThresholdBreakdown;
332332
for (size_t i = 0; i < nSubThresholdFilledPerSettings.size(); i++) {

‎Detectors/TPC/calibration/src/CalculatedEdx.cxx‎

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void CalculatedEdx::gatherRowClusterData(o2::tpc::TrackTPC& track, std::vector<R
261261
{
262262
rowData.clear();
263263

264-
bool refitAbandoned = false;
264+
const bool refitFailed = refitTrack(track);
265265

266266
// handle same (sector, row) clusters
267267
std::vector<std::pair<unsigned char, unsigned char>> rowOrder;
@@ -298,7 +298,7 @@ void CalculatedEdx::gatherRowClusterData(o2::tpc::TrackTPC& track, std::vector<R
298298
}
299299

300300
const bool mergeable = mergeableRows.count(rowKey) > 0;
301-
gatherRowClusterDataForRow(track, fragmentClusters, fragmentIsShared, sectorIndex, rowIndex, mergeable, rowIndexOld, sectorIndexOld, occupancyROC, rowData, refitAbandoned);
301+
gatherRowClusterDataForRow(track, fragmentClusters, fragmentIsShared, sectorIndex, rowIndex, mergeable, rowIndexOld, sectorIndexOld, occupancyROC, rowData, refitFailed);
302302
rowIndexOld = rowIndex;
303303
sectorIndexOld = sectorIndex;
304304
}
@@ -320,6 +320,21 @@ void CalculatedEdx::gatherRowClusterData(o2::tpc::TrackTPC& track, std::vector<R
320320
}
321321
}
322322

323+
bool CalculatedEdx::refitTrack(o2::tpc::TrackTPC& track)
324+
{
325+
if (!mRefit) {
326+
return false;
327+
}
328+
// RefitTrackAsGPU() refits the whole track from its clusters (not just up to the current row) and may write into the track even if it fails, so keep the original state to fall back from
329+
const o2::track::TrackParCov trackBeforeRefit = track;
330+
// outward refit: the track ends at the outermost cluster, i.e. at the start of the cluster reference list that is traversed row by row
331+
const bool failed = (mRefit->RefitTrackAsGPU(track, true, true) < 0) || std::isnan(track.getParam(1));
332+
if (failed) {
333+
static_cast<o2::track::TrackParCov&>(track) = trackBeforeRefit;
334+
}
335+
return failed;
336+
}
337+
323338
bool CalculatedEdx::propagateTrackToX(o2::track::TrackParCov& track, float xPosition, unsigned char sectorIndex) const
324339
{
325340
const o2::track::TrackParCov trackBackup = track;
@@ -347,7 +362,7 @@ bool CalculatedEdx::propagateTrackToX(o2::track::TrackParCov& track, float xPosi
347362
return check;
348363
}
349364

350-
void CalculatedEdx::gatherRowClusterDataForRow(o2::tpc::TrackTPC& track, const std::vector<o2::tpc::ClusterNative>& fragmentClusters, const std::vector<bool>& fragmentIsShared, unsigned char sectorIndex, unsigned char rowIndex, bool mergeable, unsigned char rowIndexOld, unsigned char sectorIndexOld, std::array<std::vector<unsigned int>, 4>& occupancyROC, std::vector<RowClusterData>& rowData, bool& refitAbandoned)
365+
void CalculatedEdx::gatherRowClusterDataForRow(o2::tpc::TrackTPC& track, const std::vector<o2::tpc::ClusterNative>& fragmentClusters, const std::vector<bool>& fragmentIsShared, unsigned char sectorIndex, unsigned char rowIndex, bool mergeable, unsigned char rowIndexOld, unsigned char sectorIndexOld, std::array<std::vector<unsigned int>, 4>& occupancyROC, std::vector<RowClusterData>& rowData, bool refitFailed)
351366
{
352367
RowClusterData row;
353368
row.sectorIndex = sectorIndex;
@@ -418,32 +433,9 @@ void CalculatedEdx::gatherRowClusterDataForRow(o2::tpc::TrackTPC& track, const s
418433
// get the x position of the track
419434
const float xPosition = Mapper::instance().getPadCentre(PadPos(rowIndex, 0)).X();
420435
bool check = true;
421-
bool refitFellBack = false;
422-
if (mRefit) {
423-
if (!refitAbandoned) {
424-
// snapshot the track's state as it stood before this row's refit attempt (i.e. after the previous row's
425-
// successful refit) -- RefitTrackAsGPU() writes back into `track` even on failure, so on failure this is
426-
// the most recent known-good state to fall back from, not the track's pristine pre-loop state
427-
const o2::track::TrackParCov trackBeforeRefit = track;
428-
// refit this track
429-
mRefit->setTrackReferenceX(xPosition);
430-
// RefitTrackAsGPU() returns < 0 when it fails; reachedReference is false when the fit succeeded but the final move-to-reference step could not reach xPosition, so both trigger the fallback.
431-
bool reachedReference = true;
432-
check = (mRefit->RefitTrackAsGPU(track, false, true, &reachedReference) < 0) ? false : reachedReference;
433-
if (!check || std::isnan(track.getParam(1))) {
434-
refitAbandoned = true;
435-
static_cast<o2::track::TrackParCov&>(track) = trackBeforeRefit;
436-
check = propagateTrackToX(track, xPosition, sectorIndex);
437-
refitFellBack = check;
438-
}
439-
} else {
440-
// already abandoned refit for this track (the previous row's RefitTrackAsGPU() failed)
441-
// keep propagating incrementally from `track`'s current state
442-
check = propagateTrackToX(track, xPosition, sectorIndex);
443-
refitFellBack = check;
444-
}
445-
} else if (mPropagateTrack) {
446-
// propagate this track to the plane X=xk (cm) in the field "b" (kG)
436+
if (mRefit || mPropagateTrack) {
437+
// mRefit: the track was refit once in gatherRowClusterData() and is only propagated from row to row here, if that refit failed, the propagation starts from the track's original state
438+
// mPropagateTrack: propagate this track to the plane X=xk (cm) in the field "b" (kG)
447439
check = propagateTrackToX(track, xPosition, sectorIndex);
448440
} else if (mPropagateParams) {
449441
// propagate the params of the track instead of full propagation; same rollback rationale as mPropagateTrack above
@@ -458,7 +450,7 @@ void CalculatedEdx::gatherRowClusterDataForRow(o2::tpc::TrackTPC& track, const s
458450
}
459451

460452
row.propagationFailed = (!check || std::isnan(track.getParam(1)));
461-
row.refitFellBack = refitFellBack && !row.propagationFailed;
453+
row.refitFellBack = mRefit && refitFailed && !row.propagationFailed;
462454
++mNRowsProcessed;
463455
if (row.propagationFailed) {
464456
++mNPropagationFailed;
@@ -509,7 +501,7 @@ void CalculatedEdx::gatherRowClusterData(o2::tpc::TrackTPC& track, const std::ve
509501
{
510502
rowData.clear();
511503

512-
bool refitAbandoned = false;
504+
const bool refitFailed = refitTrack(track);
513505

514506
// handle same (sector, row) clusters
515507
std::vector<std::pair<unsigned char, unsigned char>> rowOrder;
@@ -544,7 +536,7 @@ void CalculatedEdx::gatherRowClusterData(o2::tpc::TrackTPC& track, const std::ve
544536
}
545537

546538
const bool mergeable = mergeableRows.count(rowKey) > 0;
547-
gatherRowClusterDataForRow(track, fragmentClusters, fragmentIsShared, sectorIndex, rowIndex, mergeable, rowIndexOld, sectorIndexOld, occupancyROC, rowData, refitAbandoned);
539+
gatherRowClusterDataForRow(track, fragmentClusters, fragmentIsShared, sectorIndex, rowIndex, mergeable, rowIndexOld, sectorIndexOld, occupancyROC, rowData, refitFailed);
548540
rowData.back().inputClusterIndices = clusterIndices; // positions in the externally supplied clusters vector grouped into this row
549541
rowIndexOld = rowIndex;
550542
sectorIndexOld = sectorIndex;

‎GPU/GPUTracking/Interface/GPUO2InterfaceRefit.cxx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ void GPUO2InterfaceRefit::updateCalib(const TPCFastTransformPOD* trans, float bz
133133
mRefit->SetFastTransform(trans);
134134
}
135135

136-
int32_t GPUO2InterfaceRefit::RefitTrackAsGPU(o2::tpc::TrackTPC& trk, bool outward, bool resetCov, bool* reachedReferenceOut) { return mRefit->RefitTrackAsGPU(trk, outward, resetCov, reachedReferenceOut); }
137-
int32_t GPUO2InterfaceRefit::RefitTrackAsTrackParCov(o2::tpc::TrackTPC& trk, bool outward, bool resetCov, bool* reachedReferenceOut) { return mRefit->RefitTrackAsTrackParCov(trk, outward, resetCov, reachedReferenceOut); }
138-
int32_t GPUO2InterfaceRefit::RefitTrackAsGPU(o2::track::TrackParCov& trk, const o2::tpc::TrackTPCClusRef& clusRef, float time0, float* chi2, bool outward, bool resetCov, bool* reachedReferenceOut) { return mRefit->RefitTrackAsGPU(trk, clusRef, time0, chi2, outward, resetCov, reachedReferenceOut); }
139-
int32_t GPUO2InterfaceRefit::RefitTrackAsTrackParCov(o2::track::TrackParCov& trk, const o2::tpc::TrackTPCClusRef& clusRef, float time0, float* chi2, bool outward, bool resetCov, bool* reachedReferenceOut) { return mRefit->RefitTrackAsTrackParCov(trk, clusRef, time0, chi2, outward, resetCov, reachedReferenceOut); }
136+
int32_t GPUO2InterfaceRefit::RefitTrackAsGPU(o2::tpc::TrackTPC& trk, bool outward, bool resetCov) { return mRefit->RefitTrackAsGPU(trk, outward, resetCov); }
137+
int32_t GPUO2InterfaceRefit::RefitTrackAsTrackParCov(o2::tpc::TrackTPC& trk, bool outward, bool resetCov) { return mRefit->RefitTrackAsTrackParCov(trk, outward, resetCov); }
138+
int32_t GPUO2InterfaceRefit::RefitTrackAsGPU(o2::track::TrackParCov& trk, const o2::tpc::TrackTPCClusRef& clusRef, float time0, float* chi2, bool outward, bool resetCov) { return mRefit->RefitTrackAsGPU(trk, clusRef, time0, chi2, outward, resetCov); }
139+
int32_t GPUO2InterfaceRefit::RefitTrackAsTrackParCov(o2::track::TrackParCov& trk, const o2::tpc::TrackTPCClusRef& clusRef, float time0, float* chi2, bool outward, bool resetCov) { return mRefit->RefitTrackAsTrackParCov(trk, clusRef, time0, chi2, outward, resetCov); }
140140
void GPUO2InterfaceRefit::setIgnoreErrorsAtTrackEnds(bool v) { mRefit->mIgnoreErrorsOnTrackEnds = v; }
141141
void GPUO2InterfaceRefit::setTrackReferenceX(float v) { mParam->rec.tpc.trackReferenceX = v; }
142142

‎GPU/GPUTracking/Interface/GPUO2InterfaceRefit.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ class GPUO2InterfaceRefit
6464
GPUO2InterfaceRefit(const o2::tpc::ClusterNativeAccess* cl, const o2::gpu::TPCFastTransformPOD* trans, float bzNominalGPU, const o2::tpc::TPCClRefElem* trackRef, uint32_t nHbfPerTf = 0, const uint8_t* sharedmap = nullptr, const uint32_t* occupancymap = nullptr, int32_t occupancyMapSize = -1, const std::vector<o2::tpc::TrackTPC>* trks = nullptr, o2::base::Propagator* p = nullptr);
6565
~GPUO2InterfaceRefit();
6666

67-
int32_t RefitTrackAsGPU(o2::tpc::TrackTPC& trk, bool outward = false, bool resetCov = false, bool* reachedReferenceOut = nullptr);
68-
int32_t RefitTrackAsTrackParCov(o2::tpc::TrackTPC& trk, bool outward = false, bool resetCov = false, bool* reachedReferenceOut = nullptr);
69-
int32_t RefitTrackAsGPU(o2::track::TrackParCov& trk, const o2::tpc::TrackTPCClusRef& clusRef, float time0, float* chi2 = nullptr, bool outward = false, bool resetCov = false, bool* reachedReferenceOut = nullptr);
70-
int32_t RefitTrackAsTrackParCov(o2::track::TrackParCov& trk, const o2::tpc::TrackTPCClusRef& clusRef, float time0, float* chi2 = nullptr, bool outward = false, bool resetCov = false, bool* reachedReferenceOut = nullptr);
67+
int32_t RefitTrackAsGPU(o2::tpc::TrackTPC& trk, bool outward = false, bool resetCov = false);
68+
int32_t RefitTrackAsTrackParCov(o2::tpc::TrackTPC& trk, bool outward = false, bool resetCov = false);
69+
int32_t RefitTrackAsGPU(o2::track::TrackParCov& trk, const o2::tpc::TrackTPCClusRef& clusRef, float time0, float* chi2 = nullptr, bool outward = false, bool resetCov = false);
70+
int32_t RefitTrackAsTrackParCov(o2::track::TrackParCov& trk, const o2::tpc::TrackTPCClusRef& clusRef, float time0, float* chi2 = nullptr, bool outward = false, bool resetCov = false);
7171
void setTrackReferenceX(float v);
7272
void setIgnoreErrorsAtTrackEnds(bool v);
7373
void updateCalib(const o2::gpu::TPCFastTransformPOD* trans, float bzNominalGPU);

‎GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,11 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger* GPUrestrict() merger, int32_
304304
relTime /= clusterCount;
305305
relTime = relTime - CAMath::Round(relTime);
306306
if (acc) {
307-
dEdx.fillCluster(qtot, qmax, cluster.row, cluster.sector, mP[2], mP[3], merger->GetConstantMem()->calibObjects, zz, pad, relTime, iTrk, clusterState);
307+
dEdx.fillCluster(qtot, qmax, cluster.row, cluster.sector, mP[2], mP[3], merger->GetConstantMem()->calibObjects, zz, pad, relTime GPUCA_DEBUG_STREAMER_CHECK(, iTrk, clusterState));
308308
}
309309
if GPUCA_RTC_CONSTEXPR (GPUCA_GET_CONSTEXPR(param.rec.tpc, dEdxClusterRejectionFlagMask) != GPUCA_GET_CONSTEXPR(param.rec.tpc, dEdxClusterRejectionFlagMaskAlt)) {
310310
if (accAlt) {
311-
dEdxAlt.fillCluster(qtot, qmax, cluster.row, cluster.sector, mP[2], mP[3], merger->GetConstantMem()->calibObjects, zz, pad, relTime, iTrk, clusterState);
311+
dEdxAlt.fillCluster(qtot, qmax, cluster.row, cluster.sector, mP[2], mP[3], merger->GetConstantMem()->calibObjects, zz, pad, relTime GPUCA_DEBUG_STREAMER_CHECK(, iTrk, clusterState));
312312
}
313313
}
314314
}
@@ -364,16 +364,14 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger* GPUrestrict() merger, int32_
364364
return true;
365365
}
366366

367-
GPUdni() bool GPUTPCGMTrackParam::MoveToReference(GPUTPCGMPropagator& prop, const GPUParam& param, float& Alpha)
367+
GPUdni() void GPUTPCGMTrackParam::MoveToReference(GPUTPCGMPropagator& prop, const GPUParam& param, float& Alpha)
368368
{
369369
static constexpr float kDeg2Rad = M_PI / 180.f;
370370
static constexpr float kSectAngle = 2 * M_PI / 18.f;
371371

372-
bool reachedReference = true;
373372
if (param.rec.tpc.trackReferenceX <= 500) {
374373
GPUTPCGMTrackParam save = *this;
375374
float saveAlpha = Alpha;
376-
reachedReference = false;
377375
for (int32_t attempt = 0; attempt < 3; attempt++) {
378376
float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / kDeg2Rad / 20.f) * kSectAngle;
379377
Alpha += dAngle;
@@ -382,7 +380,7 @@ GPUdni() bool GPUTPCGMTrackParam::MoveToReference(GPUTPCGMPropagator& prop, cons
382380
}
383381
ConstrainSinPhi();
384382
if (CAMath::Abs(mP[0]) <= mX * CAMath::Tan(kSectAngle / 2.f)) {
385-
return true;
383+
return;
386384
}
387385
}
388386
*this = save;
@@ -394,7 +392,6 @@ GPUdni() bool GPUTPCGMTrackParam::MoveToReference(GPUTPCGMPropagator& prop, cons
394392
ConstrainSinPhi();
395393
Alpha += dAngle;
396394
}
397-
return reachedReference;
398395
}
399396

400397
GPUd() void GPUTPCGMTrackParam::MirrorTo(GPUTPCGMPropagator& GPUrestrict() prop, float toY, float toZ, bool inFlyDirection, const GPUParam& param, uint8_t row, uint8_t clusterState, bool mirrorParameters, int8_t sector)

0 commit comments

Comments
 (0)