Skip to content

Commit f3c6fd9

Browse files
committed
fixes in TOF calibration workflow
1 parent c79eb13 commit f3c6fd9

10 files changed

Lines changed: 159 additions & 26 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class CalibTimeSlewingParamTOF
8484
}
8585

8686
CalibTimeSlewingParamTOF& operator+=(const CalibTimeSlewingParamTOF& other);
87+
void bind();
8788

8889
private:
8990
std::array<int, NCHANNELXSECTOR> mChannelStartSec0;

DataFormats/Detectors/TOF/src/CalibTimeSlewingParamTOF.cxx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ float CalibTimeSlewingParamTOF::getChannelOffset(int channel) const
3535
{
3636
return evalTimeSlewing(channel, 0);
3737
}
38+
void CalibTimeSlewingParamTOF::bind()
39+
{
40+
mGlobalOffset[0] = &mGlobalOffsetSec0;
41+
mGlobalOffset[1] = &mGlobalOffsetSec1;
42+
mGlobalOffset[2] = &mGlobalOffsetSec2;
43+
mGlobalOffset[3] = &mGlobalOffsetSec3;
44+
mGlobalOffset[4] = &mGlobalOffsetSec4;
45+
mGlobalOffset[5] = &mGlobalOffsetSec5;
46+
mGlobalOffset[6] = &mGlobalOffsetSec6;
47+
mGlobalOffset[7] = &mGlobalOffsetSec7;
48+
mGlobalOffset[8] = &mGlobalOffsetSec8;
49+
mGlobalOffset[9] = &mGlobalOffsetSec9;
50+
mGlobalOffset[10] = &mGlobalOffsetSec10;
51+
mGlobalOffset[11] = &mGlobalOffsetSec11;
52+
mGlobalOffset[12] = &mGlobalOffsetSec12;
53+
mGlobalOffset[13] = &mGlobalOffsetSec13;
54+
mGlobalOffset[14] = &mGlobalOffsetSec14;
55+
mGlobalOffset[15] = &mGlobalOffsetSec15;
56+
mGlobalOffset[16] = &mGlobalOffsetSec16;
57+
mGlobalOffset[17] = &mGlobalOffsetSec17;
58+
}
3859

3960
//______________________________________________
4061
float CalibTimeSlewingParamTOF::evalTimeSlewing(int channel, float totIn) const

Detectors/GlobalTracking/src/MatchTOF.cxx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ void MatchTOF::run(const o2::globaltracking::RecoContainer& inp)
6565
mTimerMatchITSTPC.Reset();
6666
mTimerTot.Reset();
6767

68+
mCalibInfoTOF.clear();
69+
6870
for (int i = 0; i < trkType::SIZEALL; i++) {
6971
mMatchedTracks[i].clear();
7072
mOutTOFLabels[i].clear();
@@ -1093,10 +1095,13 @@ void MatchTOF::selectBestMatches()
10931095
}
10941096

10951097
// add also calibration infos
1096-
mCalibInfoTOF.emplace_back(mTOFClusWork[matchingPair.getTOFClIndex()].getMainContributingChannel(),
1097-
int(mTOFClusWork[matchingPair.getTOFClIndex()].getTimeRaw() * 1E12), // add time stamp
1098-
mTOFClusWork[matchingPair.getTOFClIndex()].getTimeRaw() - intLT.getTOF(o2::track::PID::Pion) - t0info,
1099-
mTOFClusWork[matchingPair.getTOFClIndex()].getTot());
1098+
if (sourceID == o2::dataformats::GlobalTrackID::ITSTPC) {
1099+
mCalibInfoTOF.emplace_back(mTOFClusWork[matchingPair.getTOFClIndex()].getMainContributingChannel(),
1100+
int(mTOFClusWork[matchingPair.getTOFClIndex()].getTimeRaw() * 1E-12), // add time stamp
1101+
mTOFClusWork[matchingPair.getTOFClIndex()].getTimeRaw() - t0info - intLT.getTOF(o2::track::PID::Pion),
1102+
mTOFClusWork[matchingPair.getTOFClIndex()].getTot());
1103+
}
1104+
11001105
if (mMCTruthON) {
11011106
const auto& labelsTOF = mTOFClusLabels->getLabels(matchingPair.getTOFClIndex());
11021107
auto& labelTrack = mTracksLblWork[trkType][itrk];

Detectors/GlobalTrackingWorkflow/src/TOFEventTimeChecker.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ using TimeSlewing = o2::dataformats::CalibTimeSlewingParamTOF;
8484

8585
bool MyFilter(const MyTrack& tr)
8686
{
87-
return (tr.mP < 2.0 && tr.mEta > o2::tof::Utils::mEtaMin && tr.mEta < o2::tof::Utils::mEtaMax && tr.mHasTOF);
87+
return (tr.mP < 2.0 && tr.mEta > o2::tof::Utils::mEtaMin && tr.mEta < o2::tof::Utils::mEtaMax && tr.mHasTOF && tr.mSource == 1);
8888
} // accept all
8989

9090
namespace o2

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class Utils
3030

3131
static bool hasFillScheme();
3232
static int getNinteractionBC();
33-
static void addBC(float toftime);
34-
static void addBC(double toftime) { addBC(float(toftime)); }
35-
static void addInteractionBC(int bc) { mFillScheme.push_back(bc); }
33+
static void addBC(float toftime, bool subLatency = false);
34+
static void addBC(double toftime, bool subLatency = false) { addBC(float(toftime), subLatency); }
35+
static void addInteractionBC(int bc, bool subLatency = false) { mFillScheme.push_back(bc); }
3636
static int getInteractionBC(int ibc) { return mFillScheme[ibc]; }
37-
static double subtractInteractionBC(double time);
38-
static float subtractInteractionBC(float time);
37+
static double subtractInteractionBC(double time, bool subLatency = false);
38+
static float subtractInteractionBC(float time, bool subLatency = false);
3939
static void init();
4040
static void printFillScheme();
4141

Detectors/TOF/base/src/Utils.cxx

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,21 @@ int Utils::getNinteractionBC()
5252
return mFillScheme.size();
5353
}
5454

55-
double Utils::subtractInteractionBC(double time)
55+
double Utils::subtractInteractionBC(double time, bool subLatency)
5656
{
57+
static const int deltalat = o2::tof::Geo::BC_IN_ORBIT - o2::tof::Geo::LATENCYWINDOW_IN_BC;
5758
int bc = int(time * o2::tof::Geo::BC_TIME_INPS_INV + 0.2);
59+
60+
if (subLatency) {
61+
if (bc >= o2::tof::Geo::LATENCYWINDOW_IN_BC) {
62+
bc -= o2::tof::Geo::LATENCYWINDOW_IN_BC;
63+
time -= o2::tof::Geo::LATENCYWINDOW_IN_BC * o2::tof::Geo::BC_TIME_INPS;
64+
} else {
65+
bc += deltalat;
66+
time += deltalat * o2::tof::Geo::BC_TIME_INPS;
67+
}
68+
}
69+
5870
int bcOrbit = bc % o2::constants::lhc::LHCMaxBunches;
5971

6072
int dbc = o2::constants::lhc::LHCMaxBunches, bcc = bc;
@@ -77,9 +89,21 @@ double Utils::subtractInteractionBC(double time)
7789
return time;
7890
}
7991

80-
float Utils::subtractInteractionBC(float time)
92+
float Utils::subtractInteractionBC(float time, bool subLatency)
8193
{
94+
static const int deltalat = o2::tof::Geo::BC_IN_ORBIT - o2::tof::Geo::LATENCYWINDOW_IN_BC;
8295
int bc = int(time * o2::tof::Geo::BC_TIME_INPS_INV + 0.2);
96+
97+
if (subLatency) {
98+
if (bc >= o2::tof::Geo::LATENCYWINDOW_IN_BC) {
99+
bc -= o2::tof::Geo::LATENCYWINDOW_IN_BC;
100+
time -= o2::tof::Geo::LATENCYWINDOW_IN_BC * o2::tof::Geo::BC_TIME_INPS;
101+
} else {
102+
bc += deltalat;
103+
time += deltalat * o2::tof::Geo::BC_TIME_INPS;
104+
}
105+
}
106+
83107
int bcOrbit = bc % o2::constants::lhc::LHCMaxBunches;
84108

85109
int dbc = o2::constants::lhc::LHCMaxBunches, bcc = bc;
@@ -88,13 +112,21 @@ float Utils::subtractInteractionBC(float time)
88112
bcc = bc - bcOrbit + getInteractionBC(k);
89113
dbc = abs(bcOrbit - getInteractionBC(k));
90114
}
115+
if (abs(bcOrbit - getInteractionBC(k) + o2::constants::lhc::LHCMaxBunches) < dbc) { // in case k is close to the right border (last BC of the orbit)
116+
bcc = bc - bcOrbit + getInteractionBC(k) - o2::constants::lhc::LHCMaxBunches;
117+
dbc = abs(bcOrbit - getInteractionBC(k) + o2::constants::lhc::LHCMaxBunches);
118+
}
119+
if (abs(bcOrbit - getInteractionBC(k) - o2::constants::lhc::LHCMaxBunches) < dbc) { // in case k is close to the left border (BC=0)
120+
bcc = bc - bcOrbit + getInteractionBC(k) + o2::constants::lhc::LHCMaxBunches;
121+
dbc = abs(bcOrbit - getInteractionBC(k) - o2::constants::lhc::LHCMaxBunches);
122+
}
91123
}
92124
time -= o2::tof::Geo::BC_TIME_INPS * bcc;
93125

94126
return time;
95127
}
96128

97-
void Utils::addBC(float toftime)
129+
void Utils::addBC(float toftime, bool subLatency)
98130
{
99131
if (!mIsInit) {
100132
init();
@@ -114,8 +146,19 @@ void Utils::addBC(float toftime)
114146
}
115147

116148
// just fill
149+
static const int deltalat = o2::tof::Geo::BC_IN_ORBIT - o2::tof::Geo::LATENCYWINDOW_IN_BC;
117150
int bc = int(toftime * o2::tof::Geo::BC_TIME_INPS_INV + 0.2) % o2::constants::lhc::LHCMaxBunches;
118151

152+
if (subLatency) {
153+
if (bc >= o2::tof::Geo::LATENCYWINDOW_IN_BC) {
154+
bc -= o2::tof::Geo::LATENCYWINDOW_IN_BC;
155+
toftime -= o2::tof::Geo::LATENCYWINDOW_IN_BC * o2::tof::Geo::BC_TIME_INPS;
156+
} else {
157+
bc += deltalat;
158+
toftime += deltalat * o2::tof::Geo::BC_TIME_INPS;
159+
}
160+
}
161+
119162
mBCmult[bc]++;
120163

121164
if (mBCmult[bc] > mMaxBC) {

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
#include "CCDB/CcdbApi.h"
3838
#include <boost/format.hpp>
3939

40+
//#define DEBUGGING
41+
42+
#ifdef DEBUGGING
43+
#include "TProfile.h"
44+
#include "TH2F.h"
45+
#endif
46+
4047
using o2::math_utils::fitGaus;
4148

4249
namespace o2
@@ -59,7 +66,11 @@ class TOFChannelData
5966
LOG(INFO) << "Default c-tor, not to be used";
6067
}
6168

69+
#ifndef DEBUGGING
6270
TOFChannelData(int nb, float r, CalibTOFapi* cta, int nElsPerSector = o2::tof::Geo::NPADSXSECTOR, bool perstrip = false, bool safe = false) : mNBins(nb), mRange(r), mCalibTOFapi(cta), mNElsPerSector(nElsPerSector), mPerStrip(perstrip), mSafeMode(safe)
71+
#else
72+
TOFChannelData(int nb, float r, CalibTOFapi* cta, int nElsPerSector = o2::tof::Geo::NPADSXSECTOR, bool perstrip = false, bool safe = false, TH2F* h = nullptr) : mNBins(nb), mRange(r), mCalibTOFapi(cta), mNElsPerSector(nElsPerSector), mPerStrip(perstrip), mSafeMode(safe), mChannelDist(h)
73+
#endif
6374
{
6475
if (r <= 0. || nb < 1) {
6576
throw std::runtime_error("Wrong initialization of the histogram");
@@ -111,6 +122,10 @@ class TOFChannelData
111122
std::array<boostHisto, 18> mHisto;
112123
std::vector<int> mEntries; // vector containing number of entries per channel
113124

125+
#ifdef DEBUGGING
126+
TH2F* mChannelDist;
127+
#endif
128+
114129
CalibTOFapi* mCalibTOFapi = nullptr; // calibTOFapi to correct the t-text
115130
int mNElsPerSector = o2::tof::Geo::NPADSXSECTOR;
116131

@@ -131,6 +146,11 @@ class TOFChannelCalibrator final : public o2::calibration::TimeSlotCalibration<T
131146
using CcdbObjectInfoVector = std::vector<CcdbObjectInfo>;
132147
using TimeSlewingVector = std::vector<TimeSlewing>;
133148

149+
#ifdef DEBUGGING
150+
TProfile* mFitCal; //("fitCal",";channel;offset (ps)",13104,0,157248);
151+
TH2F* mChannelDist; //("channelDist",";channel; t - t_{exp}^{#pi} (ps)",13104,0,157248,1000,-100000,100000);
152+
#endif
153+
134154
protected:
135155
std::deque<o2::calibration::TimeSlot<o2::tof::TOFChannelData>>& getSlots() { return o2::calibration::TimeSlotCalibration<T, o2::tof::TOFChannelData>::getSlots(); }
136156

@@ -166,6 +186,10 @@ class TOFChannelCalibrator final : public o2::calibration::TimeSlotCalibration<T
166186
mLinFitters[i].SetDim(3);
167187
mLinFitters[i].SetFormula("pol2");
168188
}
189+
#ifdef DEBUGGING
190+
mFitCal = new TProfile("fitCal", ";channel;offset (ps)", 157248, 0, 157248);
191+
mChannelDist = new TH2F("channelDist", ";channel; t - t_{exp}^{#pi} (ps)", 157248, 0, 157248, 1000, -100000, 100000);
192+
#endif
169193
}
170194

171195
~TOFChannelCalibrator() final = default;
@@ -202,7 +226,12 @@ class TOFChannelCalibrator final : public o2::calibration::TimeSlotCalibration<T
202226
auto& cont = getSlots();
203227
auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
204228
int nElements = mCalibWithCosmics ? NCOMBINSTRIP * Geo::NSTRIPXSECTOR : Geo::NPADSXSECTOR; // if we calibrate with cosmics, we pass the number of possible combinations per sector; otherwise, the number of pads per sector
229+
#ifndef DEBUGGING
205230
slot.setContainer(std::make_unique<TOFChannelData>(mNBins, mRange, mCalibTOFapi, nElements, mPerStrip, mSafeMode));
231+
#else
232+
slot.setContainer(std::make_unique<TOFChannelData>(mNBins, mRange, mCalibTOFapi, nElements, mPerStrip, mSafeMode, mChannelDist));
233+
#endif
234+
206235
return slot;
207236
}
208237

0 commit comments

Comments
 (0)