@@ -354,6 +354,17 @@ void fillBuffer(std::pair<std::vector<float>, std::vector<TimeStampType>>& buffe
354354 buffer = std::move (buffTmp);
355355}
356356
357+ // / truncate all parallel vectors of a RollingStats to size n, keeping the leading n entries.
358+ // / Used to keep RobustPressure's members aligned with a `times` vector that got trimmed.
359+ void trimStats (o2::math_utils::RollingStats& stats, size_t n)
360+ {
361+ stats.median .resize (n);
362+ stats.std .resize (n);
363+ stats.nPoints .resize (n);
364+ stats.closestDistanceL .resize (n);
365+ stats.closestDistanceR .resize (n);
366+ }
367+
357368void Pressure::makeRobustPressure (TimeStampType timeInterval, TimeStampType timeIntervalRef, TimeStampType tStart, TimeStampType tEnd, const int nthreads)
358369{
359370 const auto surfaceAtmosPressurePair = surfaceAtmosPressure.getPairOfVector ();
@@ -380,9 +391,9 @@ void Pressure::makeRobustPressure(TimeStampType timeInterval, TimeStampType time
380391
381392 // / minimum number of points in the interval - otherwise use the n closest points
382393 const int minPoints = 4 ;
383- const auto cavernAtmosPressureStats = o2::math_utils::getRollingStatistics (mCavernAtmosPressure1Buff .second , mCavernAtmosPressure1Buff .first , times, timeInterval, nthreads, minPoints, minPoints);
384- const auto cavernAtmosPressure2Stats = o2::math_utils::getRollingStatistics (mCavernAtmosPressure2Buff .second , mCavernAtmosPressure2Buff .first , times, timeInterval, nthreads, minPoints, minPoints);
385- const auto surfaceAtmosPressureStats = o2::math_utils::getRollingStatistics (mSurfaceAtmosPressureBuff .second , mSurfaceAtmosPressureBuff .first , times, timeInterval, nthreads, minPoints, minPoints);
394+ auto cavernAtmosPressureStats = o2::math_utils::getRollingStatistics (mCavernAtmosPressure1Buff .second , mCavernAtmosPressure1Buff .first , times, timeInterval, nthreads, minPoints, minPoints);
395+ auto cavernAtmosPressure2Stats = o2::math_utils::getRollingStatistics (mCavernAtmosPressure2Buff .second , mCavernAtmosPressure2Buff .first , times, timeInterval, nthreads, minPoints, minPoints);
396+ auto surfaceAtmosPressureStats = o2::math_utils::getRollingStatistics (mSurfaceAtmosPressureBuff .second , mSurfaceAtmosPressureBuff .first , times, timeInterval, nthreads, minPoints, minPoints);
386397
387398 // subtract the moving median values from the different sensors if they are ok
388399 std::pair<std::vector<float >, std::vector<TimeStampType>> cavernAtmosPressure12;
@@ -421,9 +432,9 @@ void Pressure::makeRobustPressure(TimeStampType timeInterval, TimeStampType time
421432 fillBuffer (mPressure2SBuff , cavernAtmosPressure2S, tStartRef, minPointsRef);
422433
423434 // get long term median of diffs - this is used for normalization of the pressure values -
424- const auto cavernAtmosPressure12Stats = o2::math_utils::getRollingStatistics (mPressure12Buff .second , mPressure12Buff .first , times, timeIntervalRef, nthreads, 3 , minPointsRef);
425- const auto cavernAtmosPressure1SStats = o2::math_utils::getRollingStatistics (mPressure1SBuff .second , mPressure1SBuff .first , times, timeIntervalRef, nthreads, 3 , minPointsRef);
426- const auto cavernAtmosPressure2SStats = o2::math_utils::getRollingStatistics (mPressure2SBuff .second , mPressure2SBuff .first , times, timeIntervalRef, nthreads, 3 , minPointsRef);
435+ auto cavernAtmosPressure12Stats = o2::math_utils::getRollingStatistics (mPressure12Buff .second , mPressure12Buff .first , times, timeIntervalRef, nthreads, 3 , minPointsRef);
436+ auto cavernAtmosPressure1SStats = o2::math_utils::getRollingStatistics (mPressure1SBuff .second , mPressure1SBuff .first , times, timeIntervalRef, nthreads, 3 , minPointsRef);
437+ auto cavernAtmosPressure2SStats = o2::math_utils::getRollingStatistics (mPressure2SBuff .second , mPressure2SBuff .first , times, timeIntervalRef, nthreads, 3 , minPointsRef);
427438
428439 // calculate diffs of median values
429440 const float maxDist = 20 * timeInterval;
@@ -518,6 +529,27 @@ void Pressure::makeRobustPressure(TimeStampType timeInterval, TimeStampType time
518529
519530 fillBuffer (mRobPressureBuff , robustPressureTmp, tStartRef, minPointsRef);
520531
532+ // drop trailing query times that don't yet have a full look-ahead margin of data
533+ // to their right in the buffer: the smoothing window is ±timeInterval, so without
534+ // it those points would be smoothed with a partially or fully one-sided (past-only)
535+ // window, biasing them low/high and causing a jump at the slot boundary.
536+ const auto & robBuffTimes = mRobPressureBuff .second ;
537+ const TimeStampType lookaheadMargin = 2 * timeInterval;
538+ while (times.size () > 1 && !robBuffTimes.empty () && times.back () + lookaheadMargin > robBuffTimes.back ()) {
539+ times.pop_back ();
540+ }
541+ isOk.resize (times.size ());
542+
543+ // the *Stats above were computed for the untrimmed query grid; truncate them to
544+ // match so all vectors stored in RobustPressure stay parallel/same length as time.
545+ // The dropped tail is simply recomputed (with a proper symmetric window) next slot.
546+ trimStats (cavernAtmosPressureStats, times.size ());
547+ trimStats (cavernAtmosPressure2Stats, times.size ());
548+ trimStats (surfaceAtmosPressureStats, times.size ());
549+ trimStats (cavernAtmosPressure12Stats, times.size ());
550+ trimStats (cavernAtmosPressure1SStats, times.size ());
551+ trimStats (cavernAtmosPressure2SStats, times.size ());
552+
521553 RobustPressure& pOut = robustPressure;
522554 pOut.surfaceAtmosPressure = std::move (surfaceAtmosPressureStats);
523555 pOut.cavernAtmosPressure2 = std::move (cavernAtmosPressure2Stats);
0 commit comments