Skip to content

Commit 6bd502e

Browse files
chiarazampollishahor02
authored andcommitted
Possibility to retry to calibrate with a lower frequency than the update interval
Case of mCheckIntervalInfiniteSlot = 0 clang-format Fixes from review Fix clang-format braces space braces again clang-format
1 parent 88a4a50 commit 6bd502e

File tree

6 files changed

+44
-224
lines changed

6 files changed

+44
-224
lines changed

Detectors/Calibration/include/DetectorsCalibration/TimeSlotCalibration.h

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ class TimeSlotCalibration
3737
uint64_t getSlotLength() const { return mSlotLength; }
3838
void setSlotLength(uint64_t v) { mSlotLength = v < 1 ? 1 : v; }
3939

40-
uint64_t getUpdateInterval() const { return mUpdateInterval; }
41-
void setUpdateInterval(uint64_t v) { mUpdateInterval = v; }
40+
uint64_t getCheckIntervalInfiniteSlot() const { return mCheckIntervalInfiniteSlot; }
41+
void setCheckIntervalInfiniteSlot(uint64_t v) { mCheckIntervalInfiniteSlot = v; }
42+
43+
uint64_t getCheckDeltaIntervalInfiniteSlot() const { return mCheckDeltaIntervalInfiniteSlot; }
44+
void setCheckDeltaIntervalInfiniteSlot(uint64_t v) { mCheckDeltaIntervalInfiniteSlot = v < 1 ? mCheckIntervalInfiniteSlot : v; } // if the delta is 0, we ignore it
4245

4346
TFType getFirstTF() const { return mFirstTF; }
4447
void setFirstTF(TFType v) { mFirstTF = v; }
@@ -83,12 +86,16 @@ class TimeSlotCalibration
8386
uint64_t mSlotLength = 1;
8487
uint64_t mMaxSlotsDelay = 3;
8588
bool mUpdateAtTheEndOfRunOnly = false;
86-
uint64_t mUpdateInterval = 1; // will be used if the TF length is INFINITE_TF_int64 to decide
87-
// when to check if to call the finalize; otherwise it is called
88-
// at every new TF; note that this is an approximation,
89-
// since TFs come in async order
90-
TFType mLastCheckedTF = 0; // will be used if the TF length is INFINITE_TF_int64 to book-keep
91-
// the last TF at which we tried to calibrate
89+
uint64_t mCheckIntervalInfiniteSlot = 1; // will be used if the TF length is INFINITE_TF_int64 to decide
90+
// when to check if to call the finalize; otherwise it is called
91+
// at every new TF; note that this is an approximation,
92+
// since TFs come in async order
93+
TFType mLastCheckedTFInfiniteSlot = 0; // will be used if the TF length is INFINITE_TF_int64 to book-keep
94+
// the last TF at which we tried to calibrate
95+
uint64_t mCheckDeltaIntervalInfiniteSlot = 1; // will be used if the TF length is INFINITE_TF_int64 when
96+
// the check on the statistics returned false, to determine
97+
// after how many TF to check again.
98+
bool mWasCheckedInfiniteSlot = false; // flag to know whether the statistics of the infinite slot was already checked
9299

93100
ClassDef(TimeSlotCalibration, 1);
94101
};
@@ -113,8 +120,9 @@ bool TimeSlotCalibration<Input, Container>::process(TFType tf, const gsl::span<c
113120

114121
auto& slotTF = getSlotForTF(tf);
115122
slotTF.getContainer()->fill(data);
116-
if (tf > mMaxSeenTF)
117-
mMaxSeenTF = tf; // keep track of the most recent TF processed
123+
if (tf > mMaxSeenTF) {
124+
mMaxSeenTF = tf; // keep track of the most recent TF processed
125+
}
118126
if (!mUpdateAtTheEndOfRunOnly) { // if you update at the end of run only, you don't check at every TF which slots can be closed
119127
// check if some slots are done
120128
checkSlotsToFinalize(tf, maxDelay);
@@ -137,16 +145,21 @@ void TimeSlotCalibration<Input, Container>::checkSlotsToFinalize(TFType tf, int
137145
// if we have one slot only which is INFINITE_TF_int64 long, and we are not at the end of run (tf != INFINITE_TF),
138146
// we need to check if we got enough statistics, and if so, redefine the slot
139147
if (mSlots.size() == 1 && mSlots[0].getTFEnd() == INFINITE_TF_int64) {
140-
if (tf >= mUpdateInterval + mLastCheckedTF || tf == INFINITE_TF) {
141-
LOG(DEBUG) << "mMaxSeenTF = " << mMaxSeenTF << ", mLastCheckedTF = " << mLastCheckedTF << ", mSlots[0].getTFStart() = " << mSlots[0].getTFStart();
148+
uint64_t checkInterval = mCheckIntervalInfiniteSlot + mLastCheckedTFInfiniteSlot;
149+
if (mWasCheckedInfiniteSlot) {
150+
checkInterval = mCheckDeltaIntervalInfiniteSlot + mLastCheckedTFInfiniteSlot;
151+
}
152+
if (tf >= checkInterval || tf == INFINITE_TF) {
153+
LOG(DEBUG) << "mMaxSeenTF = " << mMaxSeenTF << ", mLastCheckedTFInfiniteSlot = " << mLastCheckedTFInfiniteSlot << ", checkInterval = " << checkInterval << ", mSlots[0].getTFStart() = " << mSlots[0].getTFStart();
142154
if (tf == INFINITE_TF) {
143155
LOG(INFO) << "End of run reached, trying to calibrate what we have, if we have enough statistics";
144156
} else {
145157
LOG(INFO) << "Calibrating as soon as we have enough statistics:";
146-
LOG(INFO) << "Update interval passed, checking slot for " << mSlots[0].getTFStart() << " <= TF <= " << mSlots[0].getTFEnd();
158+
LOG(INFO) << "Update interval passed (" << checkInterval << "), checking slot for " << mSlots[0].getTFStart() << " <= TF <= " << mSlots[0].getTFEnd();
147159
}
148-
mLastCheckedTF = tf;
160+
mLastCheckedTFInfiniteSlot = tf;
149161
if (hasEnoughData(mSlots[0])) {
162+
mWasCheckedInfiniteSlot = false;
150163
mSlots[0].setTFStart(mLastClosedTF);
151164
mSlots[0].setTFEnd(mMaxSeenTF);
152165
LOG(INFO) << "Finalizing slot for " << mSlots[0].getTFStart() << " <= TF <= " << mSlots[0].getTFEnd();
@@ -160,6 +173,7 @@ void TimeSlotCalibration<Input, Container>::checkSlotsToFinalize(TFType tf, int
160173
}
161174
} else {
162175
LOG(INFO) << "Not enough data to calibrate";
176+
mWasCheckedInfiniteSlot = true;
163177
}
164178
} else {
165179
LOG(DEBUG) << "Not trying to calibrate: either not at EoS, or update interval not passed";

Detectors/TOF/calibration/include/TOFCalibration/TOFChannelCalibrator.h

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ class TOFChannelCalibrator final : public o2::calibration::TimeSlotCalibration<T
130130
int i1 = int(x[0]) % 96;
131131
int i2 = int(x[0]) / 96 ? (i1 + 48) : (i1 + 1);
132132

133-
if (i1 < 0)
133+
if (i1 < 0) {
134134
return 0;
135-
if (i2 >= Geo::NPADS)
135+
}
136+
if (i2 >= Geo::NPADS) {
136137
return 0;
138+
}
137139

138140
return (params[i1] - params[i2]);
139141
}
@@ -192,16 +194,12 @@ class TOFChannelCalibrator final : public o2::calibration::TimeSlotCalibration<T
192194
float xp[NCOMBINSTRIP], exp[NCOMBINSTRIP], deltat[NCOMBINSTRIP], edeltat[NCOMBINSTRIP], fracUnderPeak[Geo::NPADS];
193195

194196
for (int sector = 0; sector < Geo::NSECTORS; sector++) {
195-
//for (int sector = 0; sector < 1; sector++) {
196197
int offsetsector = sector * Geo::NSTRIPXSECTOR * Geo::NPADS;
197198
for (int istrip = 0; istrip < Geo::NSTRIPXSECTOR; istrip++) {
198-
//for (int istrip = 0; istrip < 38; istrip++) {
199199
int offsetstrip = istrip * Geo::NPADS + offsetsector;
200200
int goodpoints = 0;
201201

202-
for (int ichLocal = 0; ichLocal < Geo::NPADS; ichLocal++) {
203-
fracUnderPeak[ichLocal] = 0.0;
204-
}
202+
memset(&fracUnderPeak[0], 0, sizeof(fracUnderPeak));
205203

206204
for (int ipair = 0; ipair < NCOMBINSTRIP; ipair++) {
207205
int chinsector = ipair + istrip * NCOMBINSTRIP;
@@ -214,19 +212,6 @@ class TOFChannelCalibrator final : public o2::calibration::TimeSlotCalibration<T
214212
// make the slice of the 2D histogram so that we have the 1D of the current channel
215213
std::vector<float> fitValues;
216214
std::vector<float> histoValues;
217-
/* //less efficient way
218-
int startCount = chinsector * c->getNbins();
219-
int counts = -1;
220-
for (auto&& x : indexed(c->getHisto(sector))) {
221-
counts++;
222-
if (counts < startCount) continue;
223-
if (x.index(1) > chinsector) { // we passed the needed channel
224-
//LOG(INFO) << "x.index(1) > chinsectormax) > chinsectormax: BREAKING";
225-
break;
226-
}
227-
histoValues.push_back(x.get());
228-
}
229-
*/
230215
std::vector<int> entriesPerChannel = c->getEntriesPerChannel();
231216
if (entriesPerChannel.at(ich) == 0) {
232217
continue; // skip always since a channel with 0 entries is normal, it will be flagged as problematic
@@ -277,19 +262,6 @@ class TOFChannelCalibrator final : public o2::calibration::TimeSlotCalibration<T
277262
intmax = mRange;
278263
}
279264

280-
/*
281-
// needed if we calculate the integral using the values
282-
int binmin = c->findBin(intmin);
283-
int binmax = c->findBin(intmax);
284-
285-
// for now these checks are useless, as we pass the value of the bin
286-
if (binmin < 0)
287-
binmin = 1; // avoid to take the underflow bin (can happen in case the sigma is too large)
288-
if (binmax >= c->getNbins())
289-
binmax = c->getNbins()-1; // avoid to take the overflow bin (can happen in case the sigma is too large)
290-
float fractionUnderPeak = (c->integral(ch, binmin, binmax) + addduetoperiodicity) / c->integral(ch, 1, c->nbins());
291-
*/
292-
293265
xp[goodpoints] = ipair + 0.5; // pair index
294266
exp[goodpoints] = 0.0; // error on pair index (dummy since it is on the pair index)
295267
deltat[goodpoints] = fitValues[1]; // delta between offsets from channels in pair (from the fit) - in ps
@@ -354,19 +326,6 @@ class TOFChannelCalibrator final : public o2::calibration::TimeSlotCalibration<T
354326
}
355327
std::vector<float> fitValues;
356328
std::vector<float> histoValues;
357-
/* //less efficient way
358-
int startCount = chinsector * c->getNbins();
359-
int counts = -1;
360-
for (auto&& x : indexed(c->getHisto(sector))) {
361-
counts++;
362-
if (counts < startCount) continue;
363-
if (x.index(1) > chinsector) { // we passed the needed channel
364-
//LOG(INFO) << "x.index(1) > chinsectormax) > chinsectormax: BREAKING";
365-
break;
366-
}
367-
histoValues.push_back(x.get());
368-
}
369-
*/
370329
std::vector<int> entriesPerChannel = c->getEntriesPerChannel();
371330
if (entriesPerChannel.at(ich) == 0) {
372331
continue; // skip always since a channel with 0 entries is normal, it will be flagged as problematic
@@ -418,18 +377,6 @@ class TOFChannelCalibrator final : public o2::calibration::TimeSlotCalibration<T
418377
intmax = mRange;
419378
}
420379

421-
/*
422-
// needed if we calculate the integral using the values
423-
int binmin = c->findBin(intmin);
424-
int binmax = c->findBin(intmax);
425-
426-
// for now these checks are useless, as we pass the value of the bin
427-
if (binmin < 0)
428-
binmin = 1; // avoid to take the underflow bin (can happen in case the sigma is too large)
429-
if (binmax >= c->getNbins())
430-
binmax = c->getNbins()-1; // avoid to take the overflow bin (can happen in case the sigma is too large)
431-
float fractionUnderPeak = (c->integral(ch, binmin, binmax) + addduetoperiodicity) / c->integral(ch, 1, c->nbins());
432-
*/
433380
fractionUnderPeak = entriesInChannel > 0 ? c->integral(ich, intmin, intmax) / entriesInChannel : 0;
434381
// now we need to store the results in the TimeSlewingObject
435382
ts.setFractionUnderPeak(ich / Geo::NPADSXSECTOR, ich % Geo::NPADSXSECTOR, fractionUnderPeak);

Detectors/TOF/calibration/src/TOFChannelCalibrator.cxx

Lines changed: 0 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -278,82 +278,6 @@ float TOFChannelData::integral(int chmin, int chmax, float binmin, float binmax)
278278

279279
return res2;
280280

281-
/* // what is below is only for alternative methods which all proved to be slower
282-
float res = 0, res1 = 0;
283-
//TStopwatch t1, t2,
284-
int startCount = chinsectormin * mNBins + binxmin;
285-
int endCount = chinsectormax * mNBins + binxmax; // = startCount + (chinsectormax - chinsectormin) * mNBins + (binxmax - binxmin);
286-
LOG(DEBUG) << "startCount = " << startCount << " endCount = " << endCount-1;
287-
//t2.Start();
288-
int counts = -1;
289-
for (auto&& x : indexed(mHisto[sector])) {
290-
counts++;
291-
if (counts < startCount) continue;
292-
if (x.bin(0).lower() > binmax && chinsectormin == chinsectormax) { // all others also will be > but only if chmin = chmax; in the other cases, we should jump to the next row,which for now we cannot do in boost
293-
// LOG(INFO) << "x.bin(0).lower() > binmax && chinsectormin == chinsectormax: BREAKING";
294-
break;
295-
}
296-
if (x.index(1) > chinsectormax) { // we passed the needed channel
297-
//LOG(INFO) << "x.index(1) > chinsectormax: BREAKING";
298-
break;
299-
}
300-
if ( (x.bin(0).upper() > binmin) && (x.bin(0).lower() <= binmax) && (x.index(1) >= chinsectormin)) { // I have to keep the condition "&& (x.bin(0).lower() <= binmax)" because I can break only if chmin == chmax
301-
res1 += x.get();
302-
//if (x.get() != 0) LOG(INFO) << "ind = " << counts << " will add bin " << x.index(0)
303-
// << " along x (in [" << x.bin(0).lower() << ", "
304-
// << x.bin(0).upper() << "], and bin " << x.index(1) << " along y" << " with content " << x.get() << " --> res1 = " << res1;
305-
}
306-
}
307-
//t2.Stop();
308-
//LOG(DEBUG) << "Time for integral looping over restricted range (result = " << res1 << "):";
309-
//t2.Print();
310-
//t1.Start();
311-
ind = -1;
312-
for (auto&& x : indexed(mHisto[sector])) {
313-
ind++;
314-
if ((x.bin(0).upper() > binmin && x.bin(0).lower() < binmax) && (x.index(1) >= chinsectormin && x.index(1) <= chinsectormax)) {
315-
res += x.get();
316-
//if (x.get() != 0) LOG(INFO) << "ind = " << ind << " will add bin " << x.index(0)
317-
// << " along x (in [" << x.bin(0).lower() << ", "
318-
// << x.bin(0).upper() << "], and bin " << x.index(1) << " along y" << " with content " << x.get();
319-
}
320-
}
321-
//t1.Stop();
322-
//LOG(DEBUG) << "Time for integral looping (result = " << res << "):";
323-
//t1.Print();
324-
LOG(DEBUG) << "Reducing... ";
325-
//TStopwatch t;
326-
//t.Start();
327-
if (binmin == binmax) binmax += 1.e-1;
328-
float chinsectorminfl = float(chinsectormin);
329-
float chinsectormaxfl = float(chinsectormax);
330-
chinsectormaxfl += 1.e-1; // we need to add a bit because the upper value otherwise is not included
331-
LOG(DEBUG) << "chinsectorminfl = " << chinsectorminfl << ", chinsectormaxfl = " << chinsectormaxfl << ", binmin= " << binmin << ", binmax = " << binmax;
332-
LOG(DEBUG) << "chinsectormin = " << chinsectormin << ", chinsectormax = " << chinsectormax;
333-
auto hch = boost::histogram::algorithm::reduce(mHisto[sector],
334-
boost::histogram::algorithm::shrink(1, chinsectorminfl, chinsectormaxfl),
335-
boost::histogram::algorithm::shrink(0, binmin, binmax));
336-
//t.Stop();
337-
//LOG(DEBUG) << "Time for projection with shrink";
338-
//t.Print();
339-
//LOG(DEBUG) << "...done.";
340-
341-
//int sizeBeforeAxis1 = mHisto[sector].axis(1).size();
342-
//int sizeAfterAxis1 = hch.axis(1).size();
343-
//int sizeBeforeAxis0 = mHisto[sector].axis(0).size();
344-
//int sizeAfterAxis0 = hch.axis(0).size();
345-
//std::cout << "axis size before reduction: axis 0: " << sizeBeforeAxis0 << ", axis 1: " << sizeBeforeAxis1 << std::endl;
346-
//std::cout << "axis size after reduction: axis 0: " << sizeAfterAxis0 << ", axis 1: " << sizeAfterAxis1 << std::endl;
347-
348-
//t.Start();
349-
auto indhch = indexed(hch);
350-
const double enthchInd = std::accumulate(indhch.begin(), indhch.end(), 0.0);
351-
//t.Stop();
352-
//LOG(DEBUG) << "Time for accumulate (result = " << enthchInd << ")";
353-
//t.Print();
354-
355-
return enthchInd;
356-
*/
357281
}
358282

359283
//_____________________________________________
@@ -398,76 +322,6 @@ float TOFChannelData::integral(int chmin, int chmax, int binxmin, int binxmax) c
398322
//t3.Print();
399323
return res2;
400324

401-
/* // all that is below is alternative methods, all proved to be slower
402-
float res = 0, res1 = 0;
403-
//TStopwatch t1, t2;
404-
int ind = -1;
405-
int startCount = chinsectormin * mNBins + binxmin;
406-
int endCount = chinsectormax * mNBins + binxmax; // = startCount + (chinsectormax - chinsectormin) * mNBins + (binxmax - binxmin);
407-
LOG(DEBUG) << "startCount = " << startCount << " endCount = " << endCount-1;
408-
//t2.Start();
409-
int counts = -1;
410-
for (auto&& x : indexed(mHisto[sector])) {
411-
counts++;
412-
if (counts < startCount) continue;
413-
if (x.index(0) > binxmax && chinsectormin == chinsectormax) { // all others also will be > but only if chmin = chmax; in the other cases, we should jump to the next row,which for now we cannot do in boost
414-
//LOG(INFO) << "x.index(0) > binxmax && chinsectormin == chinsectormax: BREAKING";
415-
break;
416-
}
417-
if (x.index(1) > chinsectormax) { // we passed the needed channel
418-
//LOG(INFO) << "x.index(1) > chinsectormax) > chinsectormax: BREAKING";
419-
break;
420-
}
421-
if ( (x.index(0) >= binxmin) && (x.index(0) <= binxmax) && (x.index(1) >= chinsectormin)) { // I have to keep the condition "&& (x.bin(0).lower() <= binmax)" because I can break only if chmin == chmax
422-
res1 += x.get();
423-
// if (x.get() != 0)
424-
// LOG(INFO) << "ind = " << counts << " will add bin " << x.index(0)
425-
// << " along x (in [" << x.bin(0).lower() << ", "
426-
// << x.bin(0).upper() << "], and bin " << x.index(1) << " along y" << " with content " << x.get()
427-
// << " --> res1 = " << res1;
428-
}
429-
}
430-
//t2.Stop();
431-
//LOG(DEBUG) << "Time for integral looping over restricted range (result = " << res1 << "):";
432-
//t2.Print();
433-
//t1.Start();
434-
for (auto&& x : indexed(mHisto[sector])) {
435-
ind++;
436-
if ((x.index(0) >= binxmin && x.index(0) <= binxmax) && (x.index(1) >= chinsectormin && x.index(1) <= chinsectormax)) {
437-
res += x.get();
438-
//LOG(INFO) << "ind = " << ind << " will add bin " << x.index(0) << " along x and bin " << x.index(1) << " along y";
439-
}
440-
}
441-
//t1.Stop();
442-
//LOG(DEBUG) << "Time for integral looping (result = " << res << "):";
443-
//t1.Print();
444-
//LOG(DEBUG) << "Reducing... ";
445-
//TStopwatch t;
446-
//t.Start();
447-
auto hch = boost::histogram::algorithm::reduce(mHisto[sector],
448-
boost::histogram::algorithm::slice(1, chinsectormin, chinsectormax+1),
449-
boost::histogram::algorithm::slice(0, binxmin, binxmax+1)); // we need to add "+1"
450-
//t.Stop();
451-
//LOG(DEBUG) << "Time for projection with slice";
452-
//t.Print();
453-
//LOG(INFO) << "...done.";
454-
455-
//int sizeBeforeAxis1 = mHisto[sector].axis(1).size();
456-
//int sizeAfterAxis1 = hch.axis(1).size();
457-
//int sizeBeforeAxis0 = mHisto[sector].axis(0).size();
458-
//int sizeAfterAxis0 = hch.axis(0).size();
459-
//std::cout << "axis size before reduction: axis 0: " << sizeBeforeAxis0 << ", axis 1: " << sizeBeforeAxis1 << std::endl;
460-
//std::cout << "axis size after reduction: axis 0: " << sizeAfterAxis0 << ", axis 1: " << sizeAfterAxis1 << std::endl;
461-
462-
// first way: using indexed (which excludes under/overflow)
463-
//t.Start();
464-
auto indhch = indexed(hch);
465-
const double enthchInd = std::accumulate(indhch.begin(), indhch.end(), 0.0);
466-
//t.Stop();
467-
//LOG(DEBUG) << "Time for accumulate (result = " << enthchInd << ")";
468-
//t.Print();
469-
return enthchInd;
470-
*/
471325
}
472326

473327
//_____________________________________________

Detectors/TOF/calibration/testWorkflow/TOFCalibCollectorSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class TOFCalibCollectorDevice : public o2::framework::Task
4747
mCollector->setIsTest(isTest);
4848
mCollector->setIsMaxNumberOfHitsAbsolute(absMaxEnt);
4949
mCollector->setSlotLength(std::numeric_limits<long>::max());
50-
mCollector->setUpdateInterval(updateInterval);
50+
mCollector->setCheckIntervalInfiniteSlot(updateInterval);
5151
mCollector->setMaxSlotsDelay(0);
5252
}
5353

0 commit comments

Comments
 (0)