Skip to content

Commit 6f13f28

Browse files
authored
[Common] TOF: allow non existing CCDB time shift objects (#10262)
1 parent 7e43888 commit 6f13f28

File tree

3 files changed

+66
-52
lines changed

3 files changed

+66
-52
lines changed

Common/Core/PID/PIDTOF.cxx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,62 @@ void TOFResoParamsV3::setResolutionParametrizationRun2(std::unordered_map<std::s
4343
}
4444
}
4545

46+
// Time shift for post calibration to realign as a function of eta
47+
void TOFResoParamsV3::setTimeShiftParameters(std::unordered_map<std::string, float> const& pars, const bool positive)
48+
{
49+
std::string baseOpt = positive ? "TimeShift.Pos." : "TimeShift.Neg.";
50+
51+
if (pars.count(baseOpt + "GetN") == 0) { // If the map does not contain the number of eta bins, we assume that no correction has to be applied
52+
return;
53+
}
54+
const int nPoints = static_cast<int>(pars.at(baseOpt + "GetN"));
55+
if (nPoints <= 0) {
56+
LOG(fatal) << "TOFResoParamsV3 shift: time must be positive";
57+
}
58+
TGraph graph;
59+
for (int i = 0; i < nPoints; ++i) {
60+
graph.AddPoint(pars.at(Form("TimeShift.eta%i", i)), pars.at(Form("TimeShift.cor%i", i)));
61+
}
62+
setTimeShiftParameters(&graph, positive);
63+
}
64+
void TOFResoParamsV3::setTimeShiftParameters(std::string const& filename, std::string const& objname, const bool positive)
65+
{
66+
TFile f(filename.c_str(), "READ");
67+
if (f.IsOpen()) {
68+
if (positive) {
69+
f.GetObject(objname.c_str(), gPosEtaTimeCorr);
70+
} else {
71+
f.GetObject(objname.c_str(), gNegEtaTimeCorr);
72+
}
73+
f.Close();
74+
}
75+
LOG(info) << "Set the Time Shift parameters from file " << filename << " and object " << objname << " for " << (positive ? "positive" : "negative");
76+
}
77+
void TOFResoParamsV3::setTimeShiftParameters(TGraph* g, const bool positive)
78+
{
79+
if (!g) {
80+
LOG(info) << "No Time Shift parameter is passed for " << (positive ? "positive" : "negative");
81+
return;
82+
}
83+
if (positive) {
84+
gPosEtaTimeCorr = g;
85+
} else {
86+
gNegEtaTimeCorr = g;
87+
}
88+
LOG(info) << "Set the Time Shift parameters from object " << g->GetName() << " " << g->GetTitle() << " for " << (positive ? "positive" : "negative");
89+
}
90+
float TOFResoParamsV3::getTimeShift(float eta, int16_t sign) const
91+
{
92+
if (sign > 0) {
93+
if (!gPosEtaTimeCorr) {
94+
return 0.f;
95+
}
96+
return gPosEtaTimeCorr->Eval(eta);
97+
}
98+
if (!gNegEtaTimeCorr) {
99+
return 0.f;
100+
}
101+
return gNegEtaTimeCorr->Eval(eta);
102+
}
103+
46104
} // namespace o2::pid::tof

Common/Core/PID/PIDTOF.h

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -237,58 +237,10 @@ class TOFResoParamsV3 : public o2::tof::Parameters<13>
237237
}
238238

239239
// Time shift for post calibration to realign as a function of eta
240-
void setTimeShiftParameters(std::unordered_map<std::string, float> const& pars, bool positive)
241-
{
242-
std::string baseOpt = positive ? "TimeShift.Pos." : "TimeShift.Neg.";
243-
244-
if (pars.count(baseOpt + "GetN") == 0) { // If the map does not contain the number of eta bins, we assume that no correction has to be applied
245-
return;
246-
}
247-
const int nPoints = static_cast<int>(pars.at(baseOpt + "GetN"));
248-
if (nPoints <= 0) {
249-
LOG(fatal) << "TOFResoParamsV3 shift: time must be positive";
250-
}
251-
TGraph graph;
252-
for (int i = 0; i < nPoints; ++i) {
253-
graph.AddPoint(pars.at(Form("TimeShift.eta%i", i)), pars.at(Form("TimeShift.cor%i", i)));
254-
}
255-
setTimeShiftParameters(&graph, positive);
256-
}
257-
void setTimeShiftParameters(std::string const& filename, std::string const& objname, bool positive)
258-
{
259-
TFile f(filename.c_str(), "READ");
260-
if (f.IsOpen()) {
261-
if (positive) {
262-
f.GetObject(objname.c_str(), gPosEtaTimeCorr);
263-
} else {
264-
f.GetObject(objname.c_str(), gNegEtaTimeCorr);
265-
}
266-
f.Close();
267-
}
268-
LOG(info) << "Set the Time Shift parameters from file " << filename << " and object " << objname << " for " << (positive ? "positive" : "negative");
269-
}
270-
void setTimeShiftParameters(TGraph* g, bool positive)
271-
{
272-
if (positive) {
273-
gPosEtaTimeCorr = g;
274-
} else {
275-
gNegEtaTimeCorr = g;
276-
}
277-
LOG(info) << "Set the Time Shift parameters from object " << g->GetName() << " " << g->GetTitle() << " for " << (positive ? "positive" : "negative");
278-
}
279-
float getTimeShift(float eta, int16_t sign) const
280-
{
281-
if (sign > 0) {
282-
if (!gPosEtaTimeCorr) {
283-
return 0.f;
284-
}
285-
return gPosEtaTimeCorr->Eval(eta);
286-
}
287-
if (!gNegEtaTimeCorr) {
288-
return 0.f;
289-
}
290-
return gNegEtaTimeCorr->Eval(eta);
291-
}
240+
void setTimeShiftParameters(std::unordered_map<std::string, float> const& pars, const bool positive);
241+
void setTimeShiftParameters(std::string const& filename, std::string const& objname, const bool positive);
242+
void setTimeShiftParameters(TGraph* g, const bool positive);
243+
float getTimeShift(float eta, int16_t sign) const;
292244

293245
void printTimeShiftParameters() const
294246
{

Common/TableProducer/PID/pidTOFMerge.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ struct TOFCalibConfig {
212212
LOG(info) << "Initializing the time shift for " << (isPositive ? "positive" : "negative")
213213
<< " from ccdb '" << nameShift << "' and timestamp " << mTimestamp
214214
<< " and pass '" << mReconstructionPass << "'";
215+
ccdb->setFatalWhenNull(false);
215216
mRespParamsV3.setTimeShiftParameters(ccdb->template getSpecific<TGraph>(nameShift, mTimestamp, metadata), isPositive);
217+
ccdb->setFatalWhenNull(true);
216218
}
217219
LOG(info) << " test getTimeShift at 0 " << (isPositive ? "pos" : "neg") << ": "
218220
<< mRespParamsV3.getTimeShift(0, isPositive);
@@ -302,7 +304,9 @@ struct TOFCalibConfig {
302304
LOG(info) << "Updating the time shift for " << (isPositive ? "positive" : "negative")
303305
<< " from ccdb '" << nameShift << "' and timestamp " << mTimestamp
304306
<< " and pass '" << mReconstructionPass << "'";
307+
ccdb->setFatalWhenNull(false);
305308
mRespParamsV3.setTimeShiftParameters(ccdb->template getSpecific<TGraph>(nameShift, mTimestamp, metadata), isPositive);
309+
ccdb->setFatalWhenNull(true);
306310
LOG(info) << " test getTimeShift at 0 " << (isPositive ? "pos" : "neg") << ": "
307311
<< mRespParamsV3.getTimeShift(0, isPositive);
308312
};

0 commit comments

Comments
 (0)