Skip to content

Commit 13b27ba

Browse files
noferinidavidrohr
authored andcommitted
update on tof calibration
1 parent 7c175a6 commit 13b27ba

9 files changed

Lines changed: 197 additions & 12 deletions

File tree

DataFormats/Detectors/TOF/include/DataFormatsTOF/CalibInfoTOF.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class CalibInfoTOF
4343
void setFlags(int flags) { mFlags = flags; }
4444
float getFlags() const { return mFlags; }
4545

46+
int getMask() const { return mMask; }
47+
4648
// for event time maker
4749
float tofSignal() const { return mDeltaTimePi; }
4850
float tofExpSignalPi() const { return 0.0; }

DataFormats/Detectors/TOF/include/DataFormatsTOF/CalibTimeSlewingParamTOF.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class CalibTimeSlewingParamTOF
3737
CalibTimeSlewingParamTOF& operator=(const CalibTimeSlewingParamTOF& source) = default;
3838

3939
float getChannelOffset(int channel) const;
40+
void setChannelOffset(int channel, float val);
4041

4142
float evalTimeSlewing(int channel, float tot) const;
4243

DataFormats/Detectors/TOF/src/CalibTimeSlewingParamTOF.cxx

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ float CalibTimeSlewingParamTOF::getChannelOffset(int channel) const
3535
{
3636
return evalTimeSlewing(channel, 0);
3737
}
38+
39+
//______________________________________________
40+
void CalibTimeSlewingParamTOF::setChannelOffset(int channel, float val)
41+
{
42+
int sector = channel / NCHANNELXSECTOR;
43+
channel = channel % NCHANNELXSECTOR;
44+
45+
(*(mGlobalOffset[sector]))[channel] = val;
46+
}
47+
//______________________________________________
3848
void CalibTimeSlewingParamTOF::bind()
3949
{
4050
mGlobalOffset[0] = &mGlobalOffsetSec0;
@@ -55,12 +65,87 @@ void CalibTimeSlewingParamTOF::bind()
5565
mGlobalOffset[15] = &mGlobalOffsetSec15;
5666
mGlobalOffset[16] = &mGlobalOffsetSec16;
5767
mGlobalOffset[17] = &mGlobalOffsetSec17;
68+
69+
mChannelStart[0] = &mChannelStartSec0;
70+
mChannelStart[1] = &mChannelStartSec1;
71+
mChannelStart[2] = &mChannelStartSec2;
72+
mChannelStart[3] = &mChannelStartSec3;
73+
mChannelStart[4] = &mChannelStartSec4;
74+
mChannelStart[5] = &mChannelStartSec5;
75+
mChannelStart[6] = &mChannelStartSec6;
76+
mChannelStart[7] = &mChannelStartSec7;
77+
mChannelStart[8] = &mChannelStartSec8;
78+
mChannelStart[9] = &mChannelStartSec9;
79+
mChannelStart[10] = &mChannelStartSec10;
80+
mChannelStart[11] = &mChannelStartSec11;
81+
mChannelStart[12] = &mChannelStartSec12;
82+
mChannelStart[13] = &mChannelStartSec13;
83+
mChannelStart[14] = &mChannelStartSec14;
84+
mChannelStart[15] = &mChannelStartSec15;
85+
mChannelStart[16] = &mChannelStartSec16;
86+
mChannelStart[17] = &mChannelStartSec17;
87+
88+
mTimeSlewing[0] = &mTimeSlewingSec0;
89+
mTimeSlewing[1] = &mTimeSlewingSec1;
90+
mTimeSlewing[2] = &mTimeSlewingSec2;
91+
mTimeSlewing[3] = &mTimeSlewingSec3;
92+
mTimeSlewing[4] = &mTimeSlewingSec4;
93+
mTimeSlewing[5] = &mTimeSlewingSec5;
94+
mTimeSlewing[6] = &mTimeSlewingSec6;
95+
mTimeSlewing[7] = &mTimeSlewingSec7;
96+
mTimeSlewing[8] = &mTimeSlewingSec8;
97+
mTimeSlewing[9] = &mTimeSlewingSec9;
98+
mTimeSlewing[10] = &mTimeSlewingSec10;
99+
mTimeSlewing[11] = &mTimeSlewingSec11;
100+
mTimeSlewing[12] = &mTimeSlewingSec12;
101+
mTimeSlewing[13] = &mTimeSlewingSec13;
102+
mTimeSlewing[14] = &mTimeSlewingSec14;
103+
mTimeSlewing[15] = &mTimeSlewingSec15;
104+
mTimeSlewing[16] = &mTimeSlewingSec16;
105+
mTimeSlewing[17] = &mTimeSlewingSec17;
106+
107+
mFractionUnderPeak[0] = &mFractionUnderPeakSec0;
108+
mFractionUnderPeak[1] = &mFractionUnderPeakSec1;
109+
mFractionUnderPeak[2] = &mFractionUnderPeakSec2;
110+
mFractionUnderPeak[3] = &mFractionUnderPeakSec3;
111+
mFractionUnderPeak[4] = &mFractionUnderPeakSec4;
112+
mFractionUnderPeak[5] = &mFractionUnderPeakSec5;
113+
mFractionUnderPeak[6] = &mFractionUnderPeakSec6;
114+
mFractionUnderPeak[7] = &mFractionUnderPeakSec7;
115+
mFractionUnderPeak[8] = &mFractionUnderPeakSec8;
116+
mFractionUnderPeak[9] = &mFractionUnderPeakSec9;
117+
mFractionUnderPeak[10] = &mFractionUnderPeakSec10;
118+
mFractionUnderPeak[11] = &mFractionUnderPeakSec11;
119+
mFractionUnderPeak[12] = &mFractionUnderPeakSec12;
120+
mFractionUnderPeak[13] = &mFractionUnderPeakSec13;
121+
mFractionUnderPeak[14] = &mFractionUnderPeakSec14;
122+
mFractionUnderPeak[15] = &mFractionUnderPeakSec15;
123+
mFractionUnderPeak[16] = &mFractionUnderPeakSec16;
124+
mFractionUnderPeak[17] = &mFractionUnderPeakSec17;
125+
126+
mSigmaPeak[0] = &mSigmaPeakSec0;
127+
mSigmaPeak[1] = &mSigmaPeakSec1;
128+
mSigmaPeak[2] = &mSigmaPeakSec2;
129+
mSigmaPeak[3] = &mSigmaPeakSec3;
130+
mSigmaPeak[4] = &mSigmaPeakSec4;
131+
mSigmaPeak[5] = &mSigmaPeakSec5;
132+
mSigmaPeak[6] = &mSigmaPeakSec6;
133+
mSigmaPeak[7] = &mSigmaPeakSec7;
134+
mSigmaPeak[8] = &mSigmaPeakSec8;
135+
mSigmaPeak[9] = &mSigmaPeakSec9;
136+
mSigmaPeak[10] = &mSigmaPeakSec10;
137+
mSigmaPeak[11] = &mSigmaPeakSec11;
138+
mSigmaPeak[12] = &mSigmaPeakSec12;
139+
mSigmaPeak[13] = &mSigmaPeakSec13;
140+
mSigmaPeak[14] = &mSigmaPeakSec14;
141+
mSigmaPeak[15] = &mSigmaPeakSec15;
142+
mSigmaPeak[16] = &mSigmaPeakSec16;
143+
mSigmaPeak[17] = &mSigmaPeakSec17;
58144
}
59145

60146
//______________________________________________
61147
float CalibTimeSlewingParamTOF::evalTimeSlewing(int channel, float totIn) const
62148
{
63-
64149
// totIn is in ns
65150
// the correction is returned in ps
66151

@@ -75,8 +160,8 @@ float CalibTimeSlewingParamTOF::evalTimeSlewing(int channel, float totIn) const
75160
if (n < 0) {
76161
return 0.;
77162
}
78-
79163
int nstop = mTimeSlewing[sector]->size();
164+
80165
if (channel < NCHANNELXSECTOR - 1) {
81166
nstop = (*(mChannelStart[sector]))[channel + 1];
82167
}

Detectors/TOF/base/include/TOFBase/CalibTOFapi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class CalibTOFapi
6666
}
6767
void readLHCphase();
6868
void readTimeSlewingParam();
69+
void readTimeSlewingParamFromFile(const char* filename);
6970
void readDiagnosticFrequencies();
7071
void loadDiagnosticFrequencies();
7172
void readActiveMap();

Detectors/TOF/base/include/TOFBase/Utils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class Utils
5656
static float mEtaMax;
5757
static float mLHCPhase;
5858

59+
static int addMaskBC(int mask, int channel);
60+
static int getMaxUsed();
61+
static int getMaxUsedChannel(int channel);
62+
5963
private:
6064
static std::vector<int> mFillScheme;
6165
static int mBCmult[o2::constants::lhc::LHCMaxBunches];
@@ -70,6 +74,10 @@ class Utils
7074
static int mNsample;
7175
static int mIsample;
7276
static float mPhases[100];
77+
static uint64_t mMaskBC[16];
78+
static uint64_t mMaskBCUsed[16];
79+
static int mMaskBCchan[o2::tof::Geo::NCHANNELS][16];
80+
static int mMaskBCchanUsed[o2::tof::Geo::NCHANNELS][16];
7381

7482
ClassDefNV(Utils, 1);
7583
};

Detectors/TOF/base/src/CalibTOFapi.cxx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ void CalibTOFapi::readTimeSlewingParam()
9999
}
100100
}
101101

102+
//______________________________________________________________________
103+
void CalibTOFapi::readTimeSlewingParamFromFile(const char* filename)
104+
{
105+
TFile* f = TFile::Open(filename);
106+
if (f) {
107+
mSlewParam = (SlewParam*)f->Get("ccdb_object");
108+
} else {
109+
LOG(info) << "File " << filename << " not found";
110+
}
111+
}
112+
102113
//______________________________________________________________________
103114

104115
void CalibTOFapi::readDiagnosticFrequencies()
@@ -278,8 +289,8 @@ float CalibTOFapi::getTimeCalibration(int ich, float tot, float phase) const
278289
// time calibration to correct measured TOF times
279290

280291
float corr = 0;
281-
if (!mLHCphase || !mSlewParam) {
282-
LOG(warning) << "Either LHC phase or slewing object null: mLHCphase = " << mLHCphase << ", mSlewParam = " << mSlewParam;
292+
if (!mSlewParam) {
293+
LOG(warning) << "slewing object null: mSlewParam = " << mSlewParam;
283294
return corr;
284295
}
285296
// printf("LHC phase apply\n");

Detectors/TOF/base/src/Utils.cxx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ o2::dataformats::CalibInfoTOF Utils::mCalibTracks[NTRACKS_REQUESTED];
3838
int Utils::mNsample = 0;
3939
int Utils::mIsample = 0;
4040
float Utils::mPhases[100];
41+
uint64_t Utils::mMaskBC[16] = {};
42+
uint64_t Utils::mMaskBCUsed[16] = {};
43+
int Utils::mMaskBCchan[o2::tof::Geo::NCHANNELS][16] = {};
44+
int Utils::mMaskBCchanUsed[o2::tof::Geo::NCHANNELS][16] = {};
4145

4246
void Utils::addInteractionBC(int bc, bool fromCollisonCotext)
4347
{
@@ -256,3 +260,49 @@ bool Utils::hasFillScheme()
256260

257261
return false;
258262
}
263+
264+
int Utils::addMaskBC(int mask, int channel)
265+
{
266+
int mask2 = (mask >> 16);
267+
int cmask = 1;
268+
int used = 0;
269+
for (int ibit = 0; ibit < 16; ibit++) {
270+
if (mask & cmask) {
271+
mMaskBCchan[channel][ibit]++;
272+
mMaskBC[ibit]++;
273+
}
274+
if (mask2 & cmask) {
275+
mMaskBCchanUsed[channel][ibit]++;
276+
mMaskBCUsed[ibit]++;
277+
used = ibit - 8;
278+
}
279+
cmask *= 2;
280+
}
281+
return used;
282+
}
283+
284+
int Utils::getMaxUsed()
285+
{
286+
int cmask = 0;
287+
uint64_t val = 10; // at least 10 entry required
288+
for (int ibit = 0; ibit < 16; ibit++) {
289+
if (mMaskBC[ibit] > val) {
290+
val = mMaskBC[ibit];
291+
cmask = ibit - 8;
292+
}
293+
}
294+
return cmask;
295+
}
296+
297+
int Utils::getMaxUsedChannel(int channel)
298+
{
299+
int cmask = 0;
300+
int val = 10; // at least 10 entry required
301+
for (int ibit = 0; ibit < 16; ibit++) {
302+
if (mMaskBCchan[channel][ibit] > val) {
303+
val = mMaskBCchan[channel][ibit];
304+
cmask = ibit - 8;
305+
}
306+
}
307+
return cmask;
308+
}

Detectors/TOF/calibration/src/LHCClockCalibrator.cxx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "CCDB/CcdbApi.h"
1717
#include "DetectorsCalibration/Utils.h"
1818
#include "DetectorsRaw/HBFUtils.h"
19+
#include "TOFBase/Utils.h"
1920

2021
namespace o2
2122
{
@@ -41,7 +42,9 @@ void LHCClockDataHisto::fill(const gsl::span<const o2::dataformats::CalibInfoTOF
4142
auto ch = data[i].getTOFChIndex();
4243
auto dt = data[i].getDeltaTimePi();
4344
auto tot = data[i].getTot();
44-
auto corr = calibApi->getTimeCalibration(ch, tot, 0.); // we take into offsets and time slewing but not lhc phase
45+
int used = o2::tof::Utils::addMaskBC(data[i].getMask(), data[i].getTOFChIndex()); // fill the current BC candidate mask and return the one used
46+
dt -= used * o2::tof::Geo::BC_TIME_INPS; // report the time using the current 0 deltaBC as reference (the right one will be added later)
47+
auto corr = calibApi->getTimeCalibration(ch, tot, 0.); // we take into offsets and time slewing but not lhc phase
4548
dt -= corr;
4649

4750
// printf("ch=%d - tot=%f - corr=%f -> dtcorr = %f (range=%f, bin=%d)\n",ch,tot,corr,dt,range,int((dt+range)*v2Bin));
@@ -98,14 +101,16 @@ void LHCClockCalibrator::finalizeSlot(Slot& slot)
98101

99102
std::map<std::string, std::string> md;
100103
LHCphase l;
104+
int tobeused = o2::tof::Utils::getMaxUsed();
105+
fitValues[1] += tobeused * o2::tof::Geo::BC_TIME_INPS; // adjust by adding the right BC
101106
l.addLHCphase(0, fitValues[1]);
102107
l.addLHCphase(o2::ccdb::CcdbObjectInfo::INFINITE_TIMESTAMP_SECONDS, fitValues[1]);
103108
auto clName = o2::utils::MemFileHelper::getClassName(l);
104109
auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
105110

106111
auto starting = slot.getStartTimeMS();
107112
auto stopping = slot.getEndTimeMS() + 5 * getSlotLength() + getMaxSlotsDelay();
108-
LOG(info) << "starting = " << starting << " - stopping = " << stopping << " -> phase = " << fitValues[1] << " ps";
113+
LOG(info) << "starting = " << starting << " - stopping = " << stopping << " -> phase = " << fitValues[1] << " ps (added BC = " << tobeused << ")";
109114
l.setStartValidity(starting);
110115
l.setEndValidity(stopping);
111116

Detectors/TOF/calibration/src/TOFChannelCalibrator.cxx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,18 @@ void TOFChannelData::fill(const gsl::span<const o2::dataformats::CalibInfoTOF> d
7474
auto tot = data[i].getTot();
7575
// TO BE DISCUSSED: could it be that the LHCphase is too old? If we ar ein sync mode, it could be that it is not yet created for the current run, so the one from the previous run (which could be very old) is used. But maybe it does not matter much, since soon enough a calibrated LHC phase should be produced
7676
auto corr = mCalibTOFapi->getTimeCalibration(ch, tot); // we take into account LHCphase, offsets and time slewing
77-
7877
auto dtcorr = dt - corr;
7978

79+
int used = o2::tof::Utils::addMaskBC(data[i].getMask(), data[i].getTOFChIndex()); // fill the current BC candidate mask and return the one used
80+
dtcorr -= used * o2::tof::Geo::BC_TIME_INPS;
81+
8082
// add calib info for computation of LHC phase
8183
Utils::addCalibTrack(dtcorr);
8284

83-
dtcorr -= Utils::mLHCPhase;
85+
// uncomment to enable auto correction of LHC phase
86+
// dtcorr -= Utils::mLHCPhase;
8487

85-
LOG(debug) << "LHCphase = " << Utils::mLHCPhase;
88+
LOG(debug) << "Residual LHCphase = " << Utils::mLHCPhase;
8689

8790
#ifdef DEBUGGING
8891
mChannelDist->Fill(ch, dtcorr);
@@ -653,8 +656,8 @@ void TOFChannelCalibrator<T>::finalizeSlotWithTracks(Slot& slot)
653656

654657
// for the CCDB entry
655658
std::map<std::string, std::string> md;
656-
TimeSlewing& ts = mCalibTOFapi->getSlewParamObj(); // we take the current CCDB object, since we want to simply update the offset
657-
// ts.bind();
659+
TimeSlewing ts = mCalibTOFapi->getSlewParamObj(); // we take the current CCDB object, since we want to simply update the offset
660+
ts.bind();
658661

659662
#ifdef WITH_OPENMP
660663
if (mNThreads < 1) {
@@ -681,11 +684,13 @@ void TOFChannelCalibrator<T>::finalizeSlotWithTracks(Slot& slot)
681684
int ich = chinsector + sector * Geo::NPADSXSECTOR;
682685
auto entriesInChannel = entriesPerChannel.at(ich);
683686
if (entriesInChannel == 0) {
687+
ts.setChannelOffset(ich, 0.0);
684688
continue; // skip always since a channel with 0 entries is normal, it will be flagged as problematic
685689
}
686690

687691
if (entriesInChannel < mMinEntries) {
688692
LOG(debug) << "channel " << ich << " will not be calibrated since it has only " << entriesInChannel << " entries (min = " << mMinEntries << ")";
693+
ts.setChannelOffset(ich, 0.0);
689694
continue;
690695
}
691696

@@ -709,6 +714,7 @@ void TOFChannelCalibrator<T>::finalizeSlotWithTracks(Slot& slot)
709714
LOG(info) << "Channel " << ich << " :: Fit failed with result = " << fitres;
710715
ts.setFractionUnderPeak(ich / Geo::NPADSXSECTOR, ich % Geo::NPADSXSECTOR, -1);
711716
ts.setSigmaPeak(ich / Geo::NPADSXSECTOR, ich % Geo::NPADSXSECTOR, 99999);
717+
ts.setChannelOffset(ich, 0.0);
712718
continue;
713719
}
714720

@@ -737,7 +743,23 @@ void TOFChannelCalibrator<T>::finalizeSlotWithTracks(Slot& slot)
737743
// now we need to store the results in the TimeSlewingObject
738744
ts.setFractionUnderPeak(ich / Geo::NPADSXSECTOR, ich % Geo::NPADSXSECTOR, fractionUnderPeak);
739745
ts.setSigmaPeak(ich / Geo::NPADSXSECTOR, ich % Geo::NPADSXSECTOR, abs(fitValues[2]));
740-
ts.updateOffsetInfo(ich, fitValues[1]);
746+
747+
int tobeused = o2::tof::Utils::getMaxUsedChannel(ich);
748+
fitValues[1] += tobeused * o2::tof::Geo::BC_TIME_INPS; // adjust by adding the right BC
749+
750+
if (abs(fitValues[1]) > mRange) {
751+
ts.setFractionUnderPeak(ich / Geo::NPADSXSECTOR, ich % Geo::NPADSXSECTOR, -1);
752+
ts.setSigmaPeak(ich / Geo::NPADSXSECTOR, ich % Geo::NPADSXSECTOR, 99999);
753+
}
754+
755+
bool isProb = ts.getFractionUnderPeak(ich) < 0.5 || ts.getSigmaPeak(ich) > 1000;
756+
757+
if (!isProb) {
758+
ts.updateOffsetInfo(ich, fitValues[1]);
759+
} else {
760+
ts.setChannelOffset(ich, 0.0);
761+
}
762+
741763
#ifdef DEBUGGING
742764
mFitCal->Fill(ich, fitValues[1]);
743765
#endif

0 commit comments

Comments
 (0)