Skip to content

Commit cc1907f

Browse files
mfagginMattia Faggin
andauthored
[PWGHF] align mcPidTof with pidTofMerge as in PR 8616. (#8715)
Co-authored-by: Mattia Faggin <mfaggin@cern.ch>
1 parent 1141080 commit cc1907f

File tree

1 file changed

+88
-30
lines changed

1 file changed

+88
-30
lines changed

PWGHF/TableProducer/mcPidTof.cxx

Lines changed: 88 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <utility>
2121
#include <vector>
2222
#include <string>
23+
#include <unordered_map>
2324

2425
#include <TPDGCode.h>
2526

@@ -71,6 +72,7 @@ struct TOFCalibConfig {
7172
mParamFileName = opt.cfgParamFileName.value;
7273
mParametrizationPath = opt.cfgParametrizationPath.value;
7374
mReconstructionPass = opt.cfgReconstructionPass.value;
75+
mReconstructionPassDefault = opt.cfgReconstructionPassDefault.value;
7476
mLoadResponseFromCCDB = opt.cfgLoadResponseFromCCDB.value;
7577
mFatalOnPassNotAvailable = opt.cfgFatalOnPassNotAvailable.value;
7678
mEnableTimeDependentResponse = opt.cfgEnableTimeDependentResponse.value;
@@ -81,7 +83,7 @@ struct TOFCalibConfig {
8183
template <typename VType>
8284
void getCfg(o2::framework::InitContext& initContext, const std::string name, VType& v, const std::string task)
8385
{
84-
if (!getTaskOptionValue(initContext, task, name, v, true)) {
86+
if (!getTaskOptionValue(initContext, task, name, v, false)) {
8587
LOG(fatal) << "Could not get " << name << " from " << task << " task";
8688
}
8789
}
@@ -93,10 +95,11 @@ struct TOFCalibConfig {
9395
getCfg(initContext, "ccdb-path-grplhcif", mPathGrpLhcIf, task);
9496
getCfg(initContext, "ccdb-timestamp", mTimestamp, task);
9597
getCfg(initContext, "timeShiftCCDBPathPos", mTimeShiftCCDBPathPos, task);
96-
getCfg(initContext, "timeShiftCCDBPathNeg", mTimeShiftCCDBPathPos, task);
98+
getCfg(initContext, "timeShiftCCDBPathNeg", mTimeShiftCCDBPathNeg, task);
9799
getCfg(initContext, "paramFileName", mParamFileName, task);
98100
getCfg(initContext, "parametrizationPath", mParametrizationPath, task);
99101
getCfg(initContext, "reconstructionPass", mReconstructionPass, task);
102+
getCfg(initContext, "reconstructionPassDefault", mReconstructionPassDefault, task);
100103
getCfg(initContext, "loadResponseFromCCDB", mLoadResponseFromCCDB, task);
101104
getCfg(initContext, "fatalOnPassNotAvailable", mFatalOnPassNotAvailable, task);
102105
getCfg(initContext, "enableTimeDependentResponse", mEnableTimeDependentResponse, task);
@@ -129,49 +132,63 @@ struct TOFCalibConfig {
129132
}
130133
LOG(info) << "Using parameter collection, starting from pass '" << mReconstructionPass << "'";
131134

132-
const std::string fname = mParamFileName;
133-
if (!fname.empty()) { // Loading the parametrization from file
134-
LOG(info) << "Loading exp. sigma parametrization from file " << fname << ", using param: " << mParametrizationPath;
135-
if (1) {
136-
o2::tof::ParameterCollection paramCollection;
137-
paramCollection.loadParamFromFile(fname, mParametrizationPath);
138-
LOG(info) << "+++ Loaded parameter collection from file +++";
139-
if (!paramCollection.retrieveParameters(mRespParamsV3, mReconstructionPass)) {
140-
if (mFatalOnPassNotAvailable) {
141-
LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", mReconstructionPass.data());
135+
if (!mParamFileName.empty()) { // Loading the parametrization from file
136+
LOG(info) << "Loading exp. sigma parametrization from file " << mParamFileName << ", using param: " << mParametrizationPath << " and pass " << mReconstructionPass;
137+
o2::tof::ParameterCollection paramCollection;
138+
paramCollection.loadParamFromFile(mParamFileName, mParametrizationPath);
139+
LOG(info) << "+++ Loaded parameter collection from file +++";
140+
if (!paramCollection.retrieveParameters(mRespParamsV3, mReconstructionPass)) {
141+
if (mFatalOnPassNotAvailable) {
142+
LOG(fatal) << "Pass '" << mReconstructionPass << "' not available in the retrieved object from file";
143+
} else {
144+
LOG(warning) << "Pass '" << mReconstructionPass << "' not available in the retrieved object from file, fetching '" << mReconstructionPassDefault << "'";
145+
if (!paramCollection.retrieveParameters(mRespParamsV3, mReconstructionPassDefault)) {
146+
paramCollection.print();
147+
LOG(fatal) << "Cannot get default pass for calibration " << mReconstructionPassDefault;
142148
} else {
143-
LOGF(warning, "Pass '%s' not available in the retrieved CCDB object", mReconstructionPass.data());
149+
mRespParamsV3.setResolutionParametrization(paramCollection.getPars(mReconstructionPassDefault));
150+
mRespParamsV3.setMomentumChargeShiftParameters(paramCollection.getPars(mReconstructionPassDefault));
151+
mRespParamsV3.printMomentumChargeShiftParameters();
144152
}
145-
} else {
146-
mRespParamsV3.setMomentumChargeShiftParameters(paramCollection.getPars(mReconstructionPass));
147-
mRespParamsV3.printMomentumChargeShiftParameters();
148153
}
149-
} else {
150-
mRespParamsV3.loadParamFromFile(fname.data(), mParametrizationPath);
154+
} else { // Pass is available, load non standard parameters
155+
mRespParamsV3.setResolutionParametrization(paramCollection.getPars(mReconstructionPass));
156+
mRespParamsV3.setMomentumChargeShiftParameters(paramCollection.getPars(mReconstructionPass));
157+
mRespParamsV3.printMomentumChargeShiftParameters();
151158
}
152-
} else if (mLoadResponseFromCCDB) { // Loading it from CCDB
159+
} else if (mLoadResponseFromCCDB && !mEnableTimeDependentResponse) { // Loading it from CCDB
153160
LOG(info) << "Loading exp. sigma parametrization from CCDB, using path: " << mParametrizationPath << " for timestamp " << mTimestamp;
154161
o2::tof::ParameterCollection* paramCollection = ccdb->template getForTimeStamp<o2::tof::ParameterCollection>(mParametrizationPath, mTimestamp);
155162
paramCollection->print();
156163
if (!paramCollection->retrieveParameters(mRespParamsV3, mReconstructionPass)) { // Attempt at loading the parameters with the pass defined
157164
if (mFatalOnPassNotAvailable) {
158-
LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", mReconstructionPass.data());
165+
LOG(fatal) << "Pass '" << mReconstructionPass << "' not available in the retrieved CCDB object";
159166
} else {
160-
LOGF(warning, "Pass '%s' not available in the retrieved CCDB object", mReconstructionPass.data());
167+
LOG(warning) << "Pass '" << mReconstructionPass << "' not available in the retrieved CCDB object, fetching '" << mReconstructionPassDefault << "'";
168+
if (!paramCollection->retrieveParameters(mRespParamsV3, mReconstructionPassDefault)) {
169+
paramCollection->print();
170+
LOG(fatal) << "Cannot get default pass for calibration " << mReconstructionPassDefault;
171+
} else {
172+
mRespParamsV3.setResolutionParametrization(paramCollection->getPars(mReconstructionPassDefault));
173+
mRespParamsV3.setMomentumChargeShiftParameters(paramCollection->getPars(mReconstructionPassDefault));
174+
mRespParamsV3.printMomentumChargeShiftParameters();
175+
}
161176
}
162177
} else { // Pass is available, load non standard parameters
178+
mRespParamsV3.setResolutionParametrization(paramCollection->getPars(mReconstructionPass));
163179
mRespParamsV3.setMomentumChargeShiftParameters(paramCollection->getPars(mReconstructionPass));
164180
mRespParamsV3.printMomentumChargeShiftParameters();
165181
}
182+
} else {
183+
std::unordered_map<std::string, float> m;
184+
mRespParamsV3.setResolutionParametrization(m);
166185
}
167-
// Calibration object is defined
168-
mRespParamsV3.print();
169186

170187
// Loading additional calibration objects
171188
if (mTimeShiftCCDBPathPos != "") {
172189
if (mTimeShiftCCDBPathPos.find(".root") != std::string::npos) {
173190
mRespParamsV3.setTimeShiftParameters(mTimeShiftCCDBPathPos, "ccdb_object", true);
174-
} else {
191+
} else if (!mEnableTimeDependentResponse) {
175192
if (mReconstructionPass == "") {
176193
mRespParamsV3.setTimeShiftParameters(ccdb->template getForTimeStamp<TGraph>(mTimeShiftCCDBPathPos, mTimestamp), true);
177194
} else {
@@ -184,7 +201,7 @@ struct TOFCalibConfig {
184201
if (mTimeShiftCCDBPathNeg != "") {
185202
if (mTimeShiftCCDBPathNeg.find(".root") != std::string::npos) {
186203
mRespParamsV3.setTimeShiftParameters(mTimeShiftCCDBPathNeg, "ccdb_object", false);
187-
} else {
204+
} else if (!mEnableTimeDependentResponse) {
188205
if (mReconstructionPass == "") {
189206
mRespParamsV3.setTimeShiftParameters(ccdb->template getForTimeStamp<TGraph>(mTimeShiftCCDBPathNeg, mTimestamp), false);
190207
} else {
@@ -194,6 +211,10 @@ struct TOFCalibConfig {
194211
}
195212
}
196213
}
214+
215+
// Calibration object is defined
216+
LOG(info) << "Parametrization at init time:";
217+
mRespParamsV3.print();
197218
}
198219

199220
template <typename CCDBObject, typename BcType>
@@ -221,13 +242,48 @@ struct TOFCalibConfig {
221242
if (!mEnableTimeDependentResponse) {
222243
return;
223244
}
224-
LOG(debug) << "Updating parametrization from path '" << mParametrizationPath << "' and timestamp " << mTimestamp;
225-
if (!ccdb->template getForTimeStamp<o2::tof::ParameterCollection>(mParametrizationPath, mTimestamp)->retrieveParameters(mRespParamsV3, mReconstructionPass)) {
226-
if (mFatalOnPassNotAvailable) {
227-
LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", mReconstructionPass.data());
245+
LOG(info) << "Updating parametrization from path '" << mParametrizationPath << "' and timestamp " << mTimestamp << " and reconstruction pass '" << mReconstructionPass << "'";
246+
if (mParamFileName.empty()) { // Not loading if parametrization from file
247+
if (!ccdb->template getForTimeStamp<o2::tof::ParameterCollection>(mParametrizationPath, mTimestamp)->retrieveParameters(mRespParamsV3, mReconstructionPass)) {
248+
if (mFatalOnPassNotAvailable) {
249+
LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", mReconstructionPass.data());
250+
} else {
251+
LOGF(warning, "Pass '%s' not available in the retrieved CCDB object, fetching '%s'", mReconstructionPass.data(), mReconstructionPassDefault.data());
252+
if (!ccdb->template getForTimeStamp<o2::tof::ParameterCollection>(mParametrizationPath, mTimestamp)->retrieveParameters(mRespParamsV3, mReconstructionPassDefault)) {
253+
ccdb->template getForTimeStamp<o2::tof::ParameterCollection>(mParametrizationPath, mTimestamp)->print();
254+
LOG(fatal) << "Cannot get default pass for calibration " << mReconstructionPassDefault;
255+
}
256+
}
257+
}
258+
}
259+
260+
// Loading additional calibration objects
261+
if (mTimeShiftCCDBPathPos != "") {
262+
if (mTimeShiftCCDBPathPos.find(".root") != std::string::npos) {
263+
mRespParamsV3.setTimeShiftParameters(mTimeShiftCCDBPathPos, "ccdb_object", true);
264+
} else {
265+
if (mReconstructionPass == "") {
266+
mRespParamsV3.setTimeShiftParameters(ccdb->template getForTimeStamp<TGraph>(mTimeShiftCCDBPathPos, mTimestamp), true);
267+
} else {
268+
std::map<std::string, std::string> metadata;
269+
metadata["RecoPassName"] = mReconstructionPass;
270+
mRespParamsV3.setTimeShiftParameters(ccdb->template getSpecific<TGraph>(mTimeShiftCCDBPathPos, mTimestamp, metadata), true);
271+
}
272+
}
273+
}
274+
if (mTimeShiftCCDBPathNeg != "") {
275+
if (mTimeShiftCCDBPathNeg.find(".root") != std::string::npos) {
276+
mRespParamsV3.setTimeShiftParameters(mTimeShiftCCDBPathNeg, "ccdb_object", false);
228277
} else {
229-
LOGF(warning, "Pass '%s' not available in the retrieved CCDB object", mReconstructionPass.data());
278+
if (mReconstructionPass == "") {
279+
mRespParamsV3.setTimeShiftParameters(ccdb->template getForTimeStamp<TGraph>(mTimeShiftCCDBPathNeg, mTimestamp), false);
280+
} else {
281+
std::map<std::string, std::string> metadata;
282+
metadata["RecoPassName"] = mReconstructionPass;
283+
mRespParamsV3.setTimeShiftParameters(ccdb->template getSpecific<TGraph>(mTimeShiftCCDBPathNeg, mTimestamp, metadata), false);
284+
}
230285
}
286+
LOG(info) << " test getTimeShift neg: " << mRespParamsV3.getTimeShift(0, false);
231287
}
232288
return;
233289
}
@@ -248,6 +304,7 @@ struct TOFCalibConfig {
248304
std::string mParamFileName;
249305
std::string mParametrizationPath;
250306
std::string mReconstructionPass;
307+
std::string mReconstructionPassDefault;
251308
bool mLoadResponseFromCCDB;
252309
bool mFatalOnPassNotAvailable;
253310
bool mEnableTimeDependentResponse;
@@ -289,6 +346,7 @@ struct tofSignal {
289346
Configurable<std::string> cfgParamFileName{"paramFileName", "", "Path to the parametrization object. If empty the parametrization is not taken from file"};
290347
Configurable<std::string> cfgParametrizationPath{"parametrizationPath", "TOF/Calib/Params", "Path of the TOF parametrization on the CCDB or in the file, if the paramFileName is not empty"};
291348
Configurable<std::string> cfgReconstructionPass{"reconstructionPass", "", {"Apass to use when fetching the calibration tables. Empty (default) does not check for any pass. Use `metadata` to fetch it from the AO2D metadata. Otherwise it will override the metadata."}};
349+
Configurable<std::string> cfgReconstructionPassDefault{"reconstructionPassDefault", "unanchored", {"Default pass to get if the standard one is not found"}};
292350
Configurable<bool> cfgLoadResponseFromCCDB{"loadResponseFromCCDB", false, "Flag to load the response from the CCDB"};
293351
Configurable<bool> cfgFatalOnPassNotAvailable{"fatalOnPassNotAvailable", true, "Flag to throw a fatal if the pass is not available in the retrieved CCDB object"};
294352
Configurable<bool> cfgEnableTimeDependentResponse{"enableTimeDependentResponse", false, "Flag to use the collision timestamp to fetch the PID Response"};

0 commit comments

Comments
 (0)