|
19 | 19 | #include <TTree.h> |
20 | 20 | #include "Framework/Logger.h" |
21 | 21 | #include "CommonConstants/LHCConstants.h" |
| 22 | +#include <atomic> |
22 | 23 |
|
23 | 24 | using namespace o2::tpc; |
24 | 25 |
|
@@ -130,29 +131,50 @@ float TPCScaler::getMeanScaler(double timestamp, o2::tpc::Side side) const |
130 | 131 | // sump up values from last ion drift time |
131 | 132 | float sum = 0; |
132 | 133 | float sumW = 0; |
| 134 | + int nOutOfRange = 0; |
133 | 135 | const bool useWeights = mUseWeights && getScalerWeights().isValid(); |
134 | 136 | for (int i = firstIdx; i < lastIdx; ++i) { |
135 | 137 | float weight = 1; |
136 | 138 | if (useWeights) { |
137 | 139 | const double relTSMS = mTimeStampMS + i * mIntegrationTimeMS - timestamp; |
| 140 | + nOutOfRange += !getScalerWeights().isInRange(relTSMS); |
138 | 141 | weight = getScalerWeights().getWeight(relTSMS); |
139 | 142 | } |
140 | 143 | sum += getScalers(i, side) * weight; |
141 | 144 | sumW += weight; |
142 | 145 | } |
| 146 | + |
| 147 | + // values outside the stored weights (e.g. timestamp within the first ion drift time of this object, where the clamped range extends |
| 148 | + // beyond the timestamp) are used with weight 1: reported once per call and at most MaxOutOfRangeReports times per process |
| 149 | + if (nOutOfRange > 0) { |
| 150 | + constexpr int MaxOutOfRangeReports = 20; |
| 151 | + static std::atomic<int> nReports{0}; |
| 152 | + const int report = nReports++; |
| 153 | + if (report < MaxOutOfRangeReports) { |
| 154 | + LOGP(error, "{} of {} scaler values for timestamp {} outside the weights (first timestamp {} ms, sampling {} ms): weight 1 used{}", nOutOfRange, |
| 155 | + lastIdx - firstIdx, timestamp, getScalerWeights().mFirstTimeStampMS, getScalerWeights().mSamplingTimeMS, |
| 156 | + (report + 1 == MaxOutOfRangeReports) ? ", further messages suppressed" : ""); |
| 157 | + } |
| 158 | + } |
| 159 | + |
143 | 160 | if (sumW != 0) { |
144 | 161 | return (sum / sumW); |
145 | 162 | } |
146 | 163 | return 0; |
147 | 164 | } |
148 | 165 |
|
| 166 | +bool TPCScalerWeights::isInRange(float deltaTime) const |
| 167 | +{ |
| 168 | + const int idx = (deltaTime - mFirstTimeStampMS) / mSamplingTimeMS; |
| 169 | + return (idx >= 0) && (idx < static_cast<int>(mWeights.size())); |
| 170 | +} |
| 171 | + |
149 | 172 | float TPCScalerWeights::getWeight(float deltaTime) const |
150 | 173 | { |
151 | 174 | const float idxF = (deltaTime - mFirstTimeStampMS) / mSamplingTimeMS; |
152 | 175 | const int idx = idxF; |
153 | | - if ((idx < 0) || (idx > mWeights.size() - 1)) { |
154 | | - LOGP(error, "Index out of range for deltaTime: {} mFirstTimeStampMS: {} mSamplingTimeMS: {}", deltaTime, mFirstTimeStampMS, mSamplingTimeMS); |
155 | | - // set weight 1 to in case it is out of range. This can only happen if the TPC scaler is not valid for given time |
| 176 | + if (!isInRange(deltaTime)) { |
| 177 | + // set weight 1 to in case it is out of range. This can only happen if the TPC scaler is not valid for given time (reported in getMeanScaler) |
156 | 178 | return 1; |
157 | 179 | } |
158 | 180 |
|
|
0 commit comments