From eb398f40c6b77e224a0e45eee9d075ef25525de1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Fri, 27 Jun 2025 15:50:57 +0200 Subject: [PATCH 1/2] Use TOF Response parameters as a service --- Common/TableProducer/PID/pidTOFMerge.cxx | 502 +++++------------------ 1 file changed, 104 insertions(+), 398 deletions(-) diff --git a/Common/TableProducer/PID/pidTOFMerge.cxx b/Common/TableProducer/PID/pidTOFMerge.cxx index 3627c349b6f..e8a29b28368 100644 --- a/Common/TableProducer/PID/pidTOFMerge.cxx +++ b/Common/TableProducer/PID/pidTOFMerge.cxx @@ -19,6 +19,7 @@ #include "Common/Core/CollisionTypeHelper.h" #include "Common/Core/MetadataHelper.h" +#include "Common/Core/PID/PIDTOFParamService.h" #include "Common/Core/TableHelper.h" #include "Common/DataModel/EventSelection.h" #include "Common/DataModel/FT0Corrected.h" @@ -63,306 +64,17 @@ using namespace o2::pid; using namespace o2::framework::expressions; using namespace o2::track; -o2::common::core::MetadataHelper metadataInfo; - // Input data types using Run3Trks = o2::soa::Join; -using Run3Cols = aod::Collisions; using Run3TrksWtof = soa::Join; using Run3TrksWtofWevTime = soa::Join; -using EvTimeCollisions = soa::Join; +using EvTimeCollisions = soa::Join; using EvTimeCollisionsFT0 = soa::Join; using Run2Trks = o2::soa::Join; using Run2TrksWtofWevTime = soa::Join; -// Configuration common to all tasks -struct TOFCalibConfig { - template - void init(const CfgType& opt) - { - mUrl = opt.cfgUrl.value; - mPathGrpLhcIf = opt.cfgPathGrpLhcIf.value; - mTimestamp = opt.cfgTimestamp.value; - mTimeShiftCCDBPathPos = opt.cfgTimeShiftCCDBPathPos.value; - mTimeShiftCCDBPathNeg = opt.cfgTimeShiftCCDBPathNeg.value; - mTimeShiftCCDBPathPosMC = opt.cfgTimeShiftCCDBPathPosMC.value; - mTimeShiftCCDBPathNegMC = opt.cfgTimeShiftCCDBPathNegMC.value; - mParamFileName = opt.cfgParamFileName.value; - mParametrizationPath = opt.cfgParametrizationPath.value; - mReconstructionPass = opt.cfgReconstructionPass.value; - mReconstructionPassDefault = opt.cfgReconstructionPassDefault.value; - mFatalOnPassNotAvailable = opt.cfgFatalOnPassNotAvailable.value; - mEnableTimeDependentResponse = opt.cfgEnableTimeDependentResponse.value; - mCollisionSystem = opt.cfgCollisionSystem.value; - mAutoSetProcessFunctions = opt.cfgAutoSetProcessFunctions.value; - } - - template - void getCfg(o2::framework::InitContext& initContext, const std::string& name, VType& v, const std::string& task) - { - if (!getTaskOptionValue(initContext, task, name, v, false)) { - LOG(fatal) << "Could not get " << name << " from " << task << " task"; - } - } - - void inheritFromBaseTask(o2::framework::InitContext& initContext, const std::string& task = "tof-signal") - { - mInitMode = 2; - getCfg(initContext, "ccdb-url", mUrl, task); - getCfg(initContext, "ccdb-path-grplhcif", mPathGrpLhcIf, task); - getCfg(initContext, "ccdb-timestamp", mTimestamp, task); - getCfg(initContext, "timeShiftCCDBPathPos", mTimeShiftCCDBPathPos, task); - getCfg(initContext, "timeShiftCCDBPathNeg", mTimeShiftCCDBPathNeg, task); - getCfg(initContext, "timeShiftCCDBPathPosMC", mTimeShiftCCDBPathPosMC, task); - getCfg(initContext, "timeShiftCCDBPathNegMC", mTimeShiftCCDBPathNegMC, task); - getCfg(initContext, "paramFileName", mParamFileName, task); - getCfg(initContext, "parametrizationPath", mParametrizationPath, task); - getCfg(initContext, "reconstructionPass", mReconstructionPass, task); - getCfg(initContext, "reconstructionPassDefault", mReconstructionPassDefault, task); - getCfg(initContext, "fatalOnPassNotAvailable", mFatalOnPassNotAvailable, task); - getCfg(initContext, "enableTimeDependentResponse", mEnableTimeDependentResponse, task); - getCfg(initContext, "collisionSystem", mCollisionSystem, task); - getCfg(initContext, "autoSetProcessFunctions", mAutoSetProcessFunctions, task); - } - // @brief Set up the configuration from the calibration object from the init function of the task - template - void initSetup(o2::pid::tof::TOFResoParamsV3& mRespParamsV3, - CCDBObject ccdb) - { - mInitMode = 1; - // First we set the CCDB manager - ccdb->setURL(mUrl); - ccdb->setTimestamp(mTimestamp); - ccdb->setCaching(true); - ccdb->setLocalObjectValidityChecking(); - // Not later than now objects - ccdb->setCreatedNotAfter(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()); - - // Then the information about the metadata - if (mReconstructionPass == "metadata") { - LOG(info) << "Getting pass from metadata"; - if (metadataInfo.isMC()) { - mReconstructionPass = metadataInfo.get("AnchorPassName"); - } else { - mReconstructionPass = metadataInfo.get("RecoPassName"); - } - LOG(info) << "Passed autodetect mode for pass. Taking '" << mReconstructionPass << "'"; - } - LOG(info) << "Using parameter collection, starting from pass '" << mReconstructionPass << "'"; - - if (!mParamFileName.empty()) { // Loading the parametrization from file - LOG(info) << "Loading exp. sigma parametrization from file " << mParamFileName << ", using param: " << mParametrizationPath << " and pass " << mReconstructionPass; - o2::tof::ParameterCollection paramCollection; - paramCollection.loadParamFromFile(mParamFileName, mParametrizationPath); - LOG(info) << "+++ Loaded parameter collection from file +++"; - if (!paramCollection.retrieveParameters(mRespParamsV3, mReconstructionPass)) { - if (mFatalOnPassNotAvailable) { - LOG(fatal) << "Pass '" << mReconstructionPass << "' not available in the retrieved object from file"; - } else { - LOG(warning) << "Pass '" << mReconstructionPass << "' not available in the retrieved object from file, fetching '" << mReconstructionPassDefault << "'"; - if (!paramCollection.retrieveParameters(mRespParamsV3, mReconstructionPassDefault)) { - paramCollection.print(); - LOG(fatal) << "Cannot get default pass for calibration " << mReconstructionPassDefault; - } else { - if (metadataInfo.isRun3()) { - mRespParamsV3.setResolutionParametrization(paramCollection.getPars(mReconstructionPassDefault)); - } else { - mRespParamsV3.setResolutionParametrizationRun2(paramCollection.getPars(mReconstructionPassDefault)); - } - mRespParamsV3.setMomentumChargeShiftParameters(paramCollection.getPars(mReconstructionPassDefault)); - } - } - } else { // Pass is available, load non standard parameters - if (metadataInfo.isRun3()) { - mRespParamsV3.setResolutionParametrization(paramCollection.getPars(mReconstructionPass)); - } else { - mRespParamsV3.setResolutionParametrizationRun2(paramCollection.getPars(mReconstructionPass)); - } - mRespParamsV3.setMomentumChargeShiftParameters(paramCollection.getPars(mReconstructionPass)); - } - } else if (!mEnableTimeDependentResponse) { // Loading it from CCDB - LOG(info) << "Loading initial exp. sigma parametrization from CCDB, using path: " << mParametrizationPath << " for timestamp " << mTimestamp; - o2::tof::ParameterCollection* paramCollection = ccdb->template getSpecific(mParametrizationPath, mTimestamp); - if (!paramCollection->retrieveParameters(mRespParamsV3, mReconstructionPass)) { // Attempt at loading the parameters with the pass defined - if (mFatalOnPassNotAvailable) { - LOG(fatal) << "Pass '" << mReconstructionPass << "' not available in the retrieved CCDB object"; - } else { - LOG(warning) << "Pass '" << mReconstructionPass << "' not available in the retrieved CCDB object, fetching '" << mReconstructionPassDefault << "'"; - if (!paramCollection->retrieveParameters(mRespParamsV3, mReconstructionPassDefault)) { - paramCollection->print(); - LOG(fatal) << "Cannot get default pass for calibration " << mReconstructionPassDefault; - } else { - if (metadataInfo.isRun3()) { - mRespParamsV3.setResolutionParametrization(paramCollection->getPars(mReconstructionPassDefault)); - } else { - mRespParamsV3.setResolutionParametrizationRun2(paramCollection->getPars(mReconstructionPassDefault)); - } - mRespParamsV3.setMomentumChargeShiftParameters(paramCollection->getPars(mReconstructionPassDefault)); - } - } - } else { // Pass is available, load non standard parameters - if (metadataInfo.isRun3()) { - mRespParamsV3.setResolutionParametrization(paramCollection->getPars(mReconstructionPass)); - } else { - mRespParamsV3.setResolutionParametrizationRun2(paramCollection->getPars(mReconstructionPass)); - } - mRespParamsV3.setMomentumChargeShiftParameters(paramCollection->getPars(mReconstructionPass)); - } - } - - // Loading additional calibration objects - std::map metadata; - if (!mReconstructionPass.empty()) { - metadata["RecoPassName"] = mReconstructionPass; - } - - auto updateTimeShift = [&](const std::string& nameShift, bool isPositive) { - if (nameShift.empty()) { - return; - } - const bool isFromFile = nameShift.find(".root") != std::string::npos; - if (isFromFile) { - LOG(info) << "Initializing the time shift for " << (isPositive ? "positive" : "negative") << " from file '" << nameShift << "'"; - mRespParamsV3.setTimeShiftParameters(nameShift, "ccdb_object", isPositive); - } else if (!mEnableTimeDependentResponse) { // If the response is fixed fetch it at the init time - LOG(info) << "Initializing the time shift for " << (isPositive ? "positive" : "negative") - << " from ccdb '" << nameShift << "' and timestamp " << mTimestamp - << " and pass '" << mReconstructionPass << "'"; - ccdb->setFatalWhenNull(false); - mRespParamsV3.setTimeShiftParameters(ccdb->template getSpecific(nameShift, mTimestamp, metadata), isPositive); - ccdb->setFatalWhenNull(true); - } - LOG(info) << " test getTimeShift at 0 " << (isPositive ? "pos" : "neg") << ": " - << mRespParamsV3.getTimeShift(0, isPositive); - }; - - const std::string nameShiftPos = metadataInfo.isMC() ? mTimeShiftCCDBPathPosMC : mTimeShiftCCDBPathPos; - updateTimeShift(nameShiftPos, true); - const std::string nameShiftNeg = metadataInfo.isMC() ? mTimeShiftCCDBPathNegMC : mTimeShiftCCDBPathNeg; - updateTimeShift(nameShiftNeg, false); - - // Calibration object is defined - LOG(info) << "Parametrization at init time:"; - mRespParamsV3.printFullConfig(); - } - - template - void processSetup(o2::pid::tof::TOFResoParamsV3& mRespParamsV3, - CCDBObject ccdb, - const BcType& bc) - { - LOG(debug) << "Processing setup for run number " << bc.runNumber() << " from run " << mLastRunNumber; - // First we check if this run number was already processed - if (mLastRunNumber == bc.runNumber()) { - return; - } - LOG(info) << "Updating the parametrization from last run " << mLastRunNumber << " to " << bc.runNumber() << " and timestamp from " << mTimestamp << " " << bc.timestamp(); - mLastRunNumber = bc.runNumber(); - mTimestamp = bc.timestamp(); - - // Check the beam type - if (mCollisionSystem == -1) { - o2::parameters::GRPLHCIFData* grpo = ccdb->template getSpecific(mPathGrpLhcIf, - mTimestamp); - mCollisionSystem = CollisionSystemType::getCollisionTypeFromGrp(grpo); - } else { - LOG(debug) << "Not setting collisions system as already set to " << mCollisionSystem << " " << CollisionSystemType::getCollisionSystemName(mCollisionSystem); - } - - if (!mEnableTimeDependentResponse) { - return; - } - LOG(info) << "Updating parametrization from path '" << mParametrizationPath << "' and timestamp " << mTimestamp << " and reconstruction pass '" << mReconstructionPass << "' for run number " << bc.runNumber(); - if (mParamFileName.empty()) { // Not loading if parametrization was taken from file - LOG(info) << "Updating parametrization from ccdb"; - const o2::tof::ParameterCollection* paramCollection = ccdb->template getSpecific(mParametrizationPath, mTimestamp); - if (!paramCollection->retrieveParameters(mRespParamsV3, mReconstructionPass)) { - if (mFatalOnPassNotAvailable) { - LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", mReconstructionPass.data()); - } else { - LOGF(warning, "Pass '%s' not available in the retrieved CCDB object, fetching '%s'", mReconstructionPass.data(), mReconstructionPassDefault.data()); - if (!paramCollection->retrieveParameters(mRespParamsV3, mReconstructionPassDefault)) { - paramCollection->print(); - LOG(fatal) << "Cannot get default pass for calibration " << mReconstructionPassDefault; - } else { // Found the default case - if (metadataInfo.isRun3()) { - mRespParamsV3.setResolutionParametrization(paramCollection->getPars(mReconstructionPassDefault)); - } else { - mRespParamsV3.setResolutionParametrizationRun2(paramCollection->getPars(mReconstructionPassDefault)); - } - mRespParamsV3.setMomentumChargeShiftParameters(paramCollection->getPars(mReconstructionPassDefault)); - } - } - } else { // Found the non default case - if (metadataInfo.isRun3()) { - mRespParamsV3.setResolutionParametrization(paramCollection->getPars(mReconstructionPass)); - } else { - mRespParamsV3.setResolutionParametrizationRun2(paramCollection->getPars(mReconstructionPass)); - } - mRespParamsV3.setMomentumChargeShiftParameters(paramCollection->getPars(mReconstructionPass)); - } - } - - // Loading additional calibration objects - std::map metadata; - if (!mReconstructionPass.empty()) { - metadata["RecoPassName"] = mReconstructionPass; - } - - auto updateTimeShift = [&](const std::string& nameShift, bool isPositive) { - if (nameShift.empty()) { - return; - } - const bool isFromFile = nameShift.find(".root") != std::string::npos; - if (isFromFile) { - return; - } - LOG(info) << "Updating the time shift for " << (isPositive ? "positive" : "negative") - << " from ccdb '" << nameShift << "' and timestamp " << mTimestamp - << " and pass '" << mReconstructionPass << "'"; - ccdb->setFatalWhenNull(false); - mRespParamsV3.setTimeShiftParameters(ccdb->template getSpecific(nameShift, mTimestamp, metadata), isPositive); - ccdb->setFatalWhenNull(true); - LOG(info) << " test getTimeShift at 0 " << (isPositive ? "pos" : "neg") << ": " - << mRespParamsV3.getTimeShift(0, isPositive); - }; - - updateTimeShift(metadataInfo.isMC() ? mTimeShiftCCDBPathPosMC : mTimeShiftCCDBPathPos, true); - updateTimeShift(metadataInfo.isMC() ? mTimeShiftCCDBPathNegMC : mTimeShiftCCDBPathNeg, false); - - LOG(info) << "Parametrization at setup time:"; - mRespParamsV3.printFullConfig(); - } - - bool autoSetProcessFunctions() const { return mAutoSetProcessFunctions; } - int collisionSystem() const { return mCollisionSystem; } - - private: - int mLastRunNumber = -1; // Last run number for which the calibration was loaded - int mInitMode = 0; // 0: no init, 1: init, 2: inherit - - // Configurable options - std::string mUrl; - std::string mPathGrpLhcIf; - int64_t mTimestamp{0}; - std::string mTimeShiftCCDBPathPos; - std::string mTimeShiftCCDBPathNeg; - std::string mTimeShiftCCDBPathPosMC; - std::string mTimeShiftCCDBPathNegMC; - std::string mParamFileName; - std::string mParametrizationPath; - std::string mReconstructionPass; - std::string mReconstructionPassDefault; - bool mFatalOnPassNotAvailable{false}; - bool mEnableTimeDependentResponse{false}; - int mCollisionSystem{-1}; - bool mAutoSetProcessFunctions{false}; -}; - -// Part 1 TOF signal definition - /// Selection criteria for tracks used for TOF event time bool isTrackGoodMatchForTOFPID(const Run3Trks::iterator& tr) { @@ -374,6 +86,9 @@ bool isTrackGoodMatchForTOFPID(const Run3Trks::iterator& tr) /// Task to produce the TOF signal from the trackTime information struct tofSignal { + // Detector response and input parameters + Service ccdb; + Service tofResponse; // Tables to produce o2::framework::Produces table; o2::framework::Produces tableFlags; @@ -383,9 +98,6 @@ struct tofSignal { // Output histograms Configurable enableQaHistograms{"enableQaHistograms", false, "Flag to enable the QA histograms"}; HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; - // Detector response and input parameters - o2::pid::tof::TOFResoParamsV3 mRespParamsV3; - Service ccdb; struct : ConfigurableGroup { Configurable cfgUrl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; Configurable cfgPathGrpLhcIf{"ccdb-path-grplhcif", "GLO/Config/GRPLHCIF", "Path on the CCDB for the GRPLHCIF object"}; @@ -404,11 +116,10 @@ struct tofSignal { Configurable cfgAutoSetProcessFunctions{"autoSetProcessFunctions", true, "Flag to autodetect the process functions to use"}; } cfg; // Configurables (only defined here and inherited from other tasks) - TOFCalibConfig mTOFCalibConfig; // TOF Calib configuration - void init(o2::framework::InitContext& initContext) { - mTOFCalibConfig.init(cfg); + LOG(debug) << "Initializing the tofSignal task"; + tofResponse->initSetup(ccdb, initContext); // Checking that the table is requested in the workflow and enabling it enableTableTOFSignal = isTableRequiredInWorkflow(initContext, "TOFSignal"); if (enableTableTOFSignal) { @@ -424,10 +135,10 @@ struct tofSignal { LOG(info) << "No table or process is enabled. Disabling task"; return; } - if (mTOFCalibConfig.autoSetProcessFunctions()) { + if (tofResponse->cfgAutoSetProcessFunctions()) { LOG(info) << "Autodetecting process functions"; - if (metadataInfo.isFullyDefined() && !doprocessRun2 && !doprocessRun3) { // Check if the metadata is initialized (only if not forced from the workflow configuration) - if (metadataInfo.isRun3()) { + if (tofResponse->metadataInfo.isFullyDefined() && !doprocessRun2 && !doprocessRun3) { // Check if the metadata is initialized (only if not forced from the workflow configuration) + if (tofResponse->metadataInfo.isRun3()) { doprocessRun3.value = true; } else { doprocessRun2.value = false; @@ -442,7 +153,6 @@ struct tofSignal { if (!doprocessRun2 && !doprocessRun3) { LOG(fatal) << "Neither processRun2 nor processRun3 are enabled. Pick one of the two"; } - mTOFCalibConfig.initSetup(mRespParamsV3, ccdb); // Getting the parametrization parameters if (!enableQaHistograms) { return; } @@ -532,6 +242,9 @@ o2::tof::eventTimeContainer evTimeMakerForTracks(const trackTypeContainer& track /// Task to produce the TOF event time table struct tofEventTime { + // Detector response and input parameters + Service ccdb; + Service tofResponse; // Tables to produce Produces tableEvTime; Produces tableEvTimeTOFOnly; @@ -543,10 +256,6 @@ struct tofEventTime { bool enableTableTOFEvTime = false; bool enableTableEvTimeTOFOnly = false; - // Detector response and input parameters - o2::pid::tof::TOFResoParamsV3 mRespParamsV3; - Service ccdb; - TOFCalibConfig mTOFCalibConfig; // TOF Calib configuration // Event time configurations Configurable minMomentum{"minMomentum", 0.5f, "Minimum momentum to select track sample for TOF event time"}; @@ -559,7 +268,8 @@ struct tofEventTime { void init(o2::framework::InitContext& initContext) { - mTOFCalibConfig.inheritFromBaseTask(initContext); + LOG(debug) << "Initializing the tofEventTime task"; + tofResponse->initSetup(ccdb, initContext); // Checking that the table is requested in the workflow and enabling it enableTableTOFEvTime = isTableRequiredInWorkflow(initContext, "TOFEvTime"); @@ -578,10 +288,10 @@ struct tofEventTime { return; } - if (mTOFCalibConfig.autoSetProcessFunctions()) { + if (tofResponse->cfgAutoSetProcessFunctions()) { LOG(info) << "Autodetecting process functions"; - if (metadataInfo.isFullyDefined()) { - if (metadataInfo.isRun3()) { + if (tofResponse->metadataInfo.isFullyDefined()) { + if (tofResponse->metadataInfo.isRun3()) { doprocessRun3.value = true; } else { doprocessRun2.value = true; @@ -589,11 +299,11 @@ struct tofEventTime { } } - if (metadataInfo.isFullyDefined()) { - if (metadataInfo.isRun3() && doprocessRun2) { + if (tofResponse->metadataInfo.isFullyDefined()) { + if (tofResponse->metadataInfo.isRun3() && doprocessRun2) { LOG(fatal) << "Run2 process function is enabled but the metadata says it is Run3"; } - if (!metadataInfo.isRun3() && doprocessRun3) { + if (!tofResponse->metadataInfo.isRun3() && doprocessRun3) { LOG(fatal) << "Run3 process function is enabled but the metadata says it is Run2"; } } @@ -618,8 +328,6 @@ struct tofEventTime { if (sel8TOFEvTime.value == true) { LOG(info) << "TOF event time will be computed for collisions that pass the event selection only!"; } - mTOFCalibConfig.initSetup(mRespParamsV3, ccdb); // Getting the parametrization parameters - o2::tof::eventTimeContainer::setMaxNtracksInSet(maxNtracksInSet.value); o2::tof::eventTimeContainer::printConfig(); } @@ -629,11 +337,13 @@ struct tofEventTime { /// /// Process function to prepare the event for each track on Run 2 data void processRun2(aod::Tracks const& tracks, - aod::Collisions const&) + aod::Collisions const&, + aod::BCsWithTimestamps const& bcs) { if (!enableTableTOFEvTime) { return; } + tofResponse->processSetup(bcs.iteratorAt(0)); // Update the response parameters tableEvTime.reserve(tracks.size()); tableFlags.reserve(tracks.size()); @@ -671,12 +381,11 @@ struct tofEventTime { if (enableTableEvTimeTOFOnly) { tableEvTimeTOFOnly.reserve(tracks.size()); } - - mTOFCalibConfig.processSetup(mRespParamsV3, ccdb, bcs.iteratorAt(0)); // Update the calibration parameters + tofResponse->processSetup(bcs.iteratorAt(0)); // Update the response parameters // Autoset the processing mode for the event time computation if (mComputeEvTimeWithTOF == -1 || mComputeEvTimeWithFT0 == -1) { - switch (mTOFCalibConfig.collisionSystem()) { + switch (tofResponse->cfgCollisionType()) { case CollisionSystemType::kCollSyspp: // pp mComputeEvTimeWithTOF.value = ((mComputeEvTimeWithTOF == -1) ? 0 : mComputeEvTimeWithTOF.value); mComputeEvTimeWithFT0.value = ((mComputeEvTimeWithFT0 == -1) ? 1 : mComputeEvTimeWithFT0.value); @@ -686,11 +395,11 @@ struct tofEventTime { mComputeEvTimeWithFT0.value = ((mComputeEvTimeWithFT0 == -1) ? 0 : mComputeEvTimeWithFT0.value); break; default: - LOG(fatal) << "Collision system " << mTOFCalibConfig.collisionSystem() << " " << CollisionSystemType::getCollisionSystemName(mTOFCalibConfig.collisionSystem()) << " not supported for TOF event time computation"; + LOG(fatal) << "Collision system " << tofResponse->cfgCollisionType() << " " << CollisionSystemType::getCollisionSystemName(tofResponse->cfgCollisionType()) << " not supported for TOF event time computation"; break; } } - LOG(debug) << "Running on " << CollisionSystemType::getCollisionSystemName(mTOFCalibConfig.collisionSystem()) << " mComputeEvTimeWithTOF " << mComputeEvTimeWithTOF.value << " mComputeEvTimeWithFT0 " << mComputeEvTimeWithFT0.value; + LOG(debug) << "Running on " << CollisionSystemType::getCollisionSystemName(tofResponse->cfgCollisionType()) << " mComputeEvTimeWithTOF " << mComputeEvTimeWithTOF.value << " mComputeEvTimeWithFT0 " << mComputeEvTimeWithFT0.value; if (mComputeEvTimeWithTOF == 1 && mComputeEvTimeWithFT0 == 1) { int lastCollisionId = -1; // Last collision ID analysed @@ -713,8 +422,7 @@ struct tofEventTime { const auto& collision = t.collision_as(); // Compute the TOF event time - const auto evTimeMakerTOF = evTimeMakerForTracks(tracksInCollision, mRespParamsV3, kDiamond); - + const auto evTimeMakerTOF = evTimeMakerForTracks(tracksInCollision, tofResponse->parameters, kDiamond); float t0AC[2] = {.0f, 999.f}; // Value and error of T0A or T0C or T0AC float t0TOF[2] = {static_cast(evTimeMakerTOF.mEventTime), static_cast(evTimeMakerTOF.mEventTimeError)}; // Value and error of TOF @@ -789,7 +497,7 @@ struct tofEventTime { const auto& tracksInCollision = tracks.sliceBy(perCollision, lastCollisionId); // First make table for event time - const auto evTimeMakerTOF = evTimeMakerForTracks(tracksInCollision, mRespParamsV3, kDiamond); + const auto evTimeMakerTOF = evTimeMakerForTracks(tracksInCollision, tofResponse->parameters, kDiamond); int nGoodTracksForTOF = 0; float et = evTimeMakerTOF.mEventTime; float erret = evTimeMakerTOF.mEventTimeError; @@ -868,6 +576,10 @@ static constexpr int kDefaultParEnabled[nSpecies][kParEnabledN]{{-1, -1}, /// Task to produce the response table struct tofPidMerge { + // Detector response and input parameters + Service tofResponse; + Service ccdb; + // Tables to produce Produces tablePIDEl; Produces tablePIDMu; @@ -896,10 +608,6 @@ struct tofPidMerge { bool enableTableBeta = false; bool enableTableMass = false; - // Detector response parameters - o2::pid::tof::TOFResoParamsV3 mRespParamsV3; - Service ccdb; - TOFCalibConfig mTOFCalibConfig; // TOF Calib configuration Configurable enableQaHistograms{"enableQaHistograms", false, "Flag to enable the QA histograms"}; Configurable enableTOFParamsForBetaMass{"enableTOFParamsForBetaMass", false, "Flag to use TOF parameters for TOF Beta and Mass"}; @@ -919,7 +627,8 @@ struct tofPidMerge { std::vector mEnabledParticlesFull; // Vector of enabled PID hypotheses to loop on when making full tables void init(o2::framework::InitContext& initContext) { - mTOFCalibConfig.inheritFromBaseTask(initContext); + LOG(debug) << "Initializing the TOF PID Merge task"; + tofResponse->initSetup(ccdb, initContext); // Checking the tables are requested in the workflow and enabling them for (int i = 0; i < nSpecies; i++) { // First checking tiny @@ -941,10 +650,10 @@ struct tofPidMerge { doprocessRun3.value = false; doprocessRun2.value = false; } else { - if (mTOFCalibConfig.autoSetProcessFunctions()) { - LOG(info) << "Autodetecting process functions"; - if (metadataInfo.isFullyDefined()) { - if (metadataInfo.isRun3()) { + if (tofResponse->cfgAutoSetProcessFunctions()) { + LOG(info) << "Autodetecting process functions for mass and beta"; + if (tofResponse->metadataInfo.isFullyDefined()) { + if (tofResponse->metadataInfo.isRun3()) { doprocessRun3.value = true; doprocessRun2.value = false; } else { @@ -960,7 +669,6 @@ struct tofPidMerge { LOG(fatal) << "Neither processRun2 nor processRun3 are enabled. Pick one of the two"; } } - mTOFCalibConfig.initSetup(mRespParamsV3, ccdb); // Getting the parametrization parameters // Printing enabled tables and enabling QA histograms if needed LOG(info) << "++ Enabled tables:"; @@ -990,12 +698,10 @@ struct tofPidMerge { doprocessRun2BetaM.value = false; doprocessRun3BetaM.value = false; } else { - LOG(info) << "Table for TOF beta is " << (enableTableBeta ? "enabled" : "disabled"); - LOG(info) << "Table for TOF mass is " << (enableTableMass ? "enabled" : "disabled"); - if (mTOFCalibConfig.autoSetProcessFunctions()) { + if (tofResponse->cfgAutoSetProcessFunctions()) { LOG(info) << "Autodetecting process functions for mass and beta"; - if (metadataInfo.isInitialized()) { - if (metadataInfo.isRun3()) { + if (tofResponse->metadataInfo.isFullyDefined()) { + if (tofResponse->metadataInfo.isRun3()) { doprocessRun3BetaM.value = true; doprocessRun2BetaM.value = false; } else { @@ -1178,7 +884,7 @@ struct tofPidMerge { template using ResponseImplementation = o2::pid::tof::ExpTimes; void processRun3(Run3TrksWtofWevTime const& tracks, - Run3Cols const&, + aod::Collisions const&, aod::BCsWithTimestamps const& bcs) { constexpr auto responseEl = ResponseImplementation(); @@ -1191,7 +897,7 @@ struct tofPidMerge { constexpr auto responseHe = ResponseImplementation(); constexpr auto responseAl = ResponseImplementation(); - mTOFCalibConfig.processSetup(mRespParamsV3, ccdb, bcs.iteratorAt(0)); // Update the calibration parameters + tofResponse->processSetup(bcs.iteratorAt(0)); // Update the calibration parameters for (auto const& pidId : mEnabledParticles) { reserveTable(pidId, tracks.size(), false); @@ -1217,47 +923,47 @@ struct tofPidMerge { for (auto const& pidId : mEnabledParticles) { // Loop on enabled particle hypotheses switch (pidId) { case kIdxEl: { - nsigma = responseEl.GetSeparation(mRespParamsV3, trk); + nsigma = responseEl.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDEl); break; } case kIdxMu: { - nsigma = responseMu.GetSeparation(mRespParamsV3, trk); + nsigma = responseMu.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDMu); break; } case kIdxPi: { - nsigma = responsePi.GetSeparation(mRespParamsV3, trk); + nsigma = responsePi.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDPi); break; } case kIdxKa: { - nsigma = responseKa.GetSeparation(mRespParamsV3, trk); + nsigma = responseKa.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDKa); break; } case kIdxPr: { - nsigma = responsePr.GetSeparation(mRespParamsV3, trk); + nsigma = responsePr.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDPr); break; } case kIdxDe: { - nsigma = responseDe.GetSeparation(mRespParamsV3, trk); + nsigma = responseDe.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDDe); break; } case kIdxTr: { - nsigma = responseTr.GetSeparation(mRespParamsV3, trk); + nsigma = responseTr.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDTr); break; } case kIdxHe: { - nsigma = responseHe.GetSeparation(mRespParamsV3, trk); + nsigma = responseHe.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDHe); break; } case kIdxAl: { - nsigma = responseAl.GetSeparation(mRespParamsV3, trk); + nsigma = responseAl.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDAl); break; } @@ -1272,56 +978,56 @@ struct tofPidMerge { for (auto const& pidId : mEnabledParticlesFull) { // Loop on enabled particle hypotheses with full tables switch (pidId) { case kIdxEl: { - resolution = responseEl.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responseEl.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responseEl.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responseEl.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullEl(resolution, nsigma); break; } case kIdxMu: { - resolution = responseMu.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responseMu.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responseMu.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responseMu.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullMu(resolution, nsigma); break; } case kIdxPi: { - resolution = responsePi.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responsePi.GetSeparation(mRespParamsV3, trk); + resolution = responsePi.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responsePi.GetSeparation(tofResponse->parameters, trk); tablePIDFullPi(resolution, nsigma); break; } case kIdxKa: { - resolution = responseKa.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responseKa.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responseKa.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responseKa.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullKa(resolution, nsigma); break; } case kIdxPr: { - resolution = responsePr.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responsePr.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responsePr.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responsePr.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullPr(resolution, nsigma); break; } case kIdxDe: { - resolution = responseDe.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responseDe.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responseDe.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responseDe.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullDe(resolution, nsigma); break; } case kIdxTr: { - resolution = responseTr.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responseTr.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responseTr.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responseTr.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullTr(resolution, nsigma); break; } case kIdxHe: { - resolution = responseHe.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responseHe.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responseHe.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responseHe.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullHe(resolution, nsigma); break; } case kIdxAl: { - resolution = responseAl.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responseAl.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responseAl.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responseAl.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullAl(resolution, nsigma); break; } @@ -1340,7 +1046,7 @@ struct tofPidMerge { template using ResponseImplementationRun2 = o2::pid::tof::ExpTimes; void processRun2(Run2TrksWtofWevTime const& tracks, - Run3Cols const&, + aod::Collisions const&, aod::BCsWithTimestamps const& bcs) { constexpr auto responseEl = ResponseImplementationRun2(); @@ -1353,7 +1059,7 @@ struct tofPidMerge { constexpr auto responseHe = ResponseImplementationRun2(); constexpr auto responseAl = ResponseImplementationRun2(); - mTOFCalibConfig.processSetup(mRespParamsV3, ccdb, bcs.iteratorAt(0)); // Update the calibration parameters + tofResponse->processSetup(bcs.iteratorAt(0)); // Update the calibration parameters for (auto const& pidId : mEnabledParticles) { reserveTable(pidId, tracks.size(), false); @@ -1379,47 +1085,47 @@ struct tofPidMerge { for (auto const& pidId : mEnabledParticles) { // Loop on enabled particle hypotheses switch (pidId) { case kIdxEl: { - nsigma = responseEl.GetSeparation(mRespParamsV3, trk); + nsigma = responseEl.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDEl); break; } case kIdxMu: { - nsigma = responseMu.GetSeparation(mRespParamsV3, trk); + nsigma = responseMu.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDMu); break; } case kIdxPi: { - nsigma = responsePi.GetSeparation(mRespParamsV3, trk); + nsigma = responsePi.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDPi); break; } case kIdxKa: { - nsigma = responseKa.GetSeparation(mRespParamsV3, trk); + nsigma = responseKa.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDKa); break; } case kIdxPr: { - nsigma = responsePr.GetSeparation(mRespParamsV3, trk); + nsigma = responsePr.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDPr); break; } case kIdxDe: { - nsigma = responseDe.GetSeparation(mRespParamsV3, trk); + nsigma = responseDe.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDDe); break; } case kIdxTr: { - nsigma = responseTr.GetSeparation(mRespParamsV3, trk); + nsigma = responseTr.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDTr); break; } case kIdxHe: { - nsigma = responseHe.GetSeparation(mRespParamsV3, trk); + nsigma = responseHe.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDHe); break; } case kIdxAl: { - nsigma = responseAl.GetSeparation(mRespParamsV3, trk); + nsigma = responseAl.GetSeparation(tofResponse->parameters, trk); aod::pidtof_tiny::binning::packInTable(nsigma, tablePIDAl); break; } @@ -1434,56 +1140,56 @@ struct tofPidMerge { for (auto const& pidId : mEnabledParticlesFull) { // Loop on enabled particle hypotheses with full tables switch (pidId) { case kIdxEl: { - resolution = responseEl.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responseEl.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responseEl.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responseEl.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullEl(resolution, nsigma); break; } case kIdxMu: { - resolution = responseMu.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responseMu.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responseMu.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responseMu.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullMu(resolution, nsigma); break; } case kIdxPi: { - resolution = responsePi.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responsePi.GetSeparation(mRespParamsV3, trk); + resolution = responsePi.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responsePi.GetSeparation(tofResponse->parameters, trk); tablePIDFullPi(resolution, nsigma); break; } case kIdxKa: { - resolution = responseKa.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responseKa.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responseKa.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responseKa.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullKa(resolution, nsigma); break; } case kIdxPr: { - resolution = responsePr.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responsePr.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responsePr.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responsePr.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullPr(resolution, nsigma); break; } case kIdxDe: { - resolution = responseDe.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responseDe.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responseDe.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responseDe.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullDe(resolution, nsigma); break; } case kIdxTr: { - resolution = responseTr.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responseTr.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responseTr.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responseTr.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullTr(resolution, nsigma); break; } case kIdxHe: { - resolution = responseHe.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responseHe.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responseHe.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responseHe.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullHe(resolution, nsigma); break; } case kIdxAl: { - resolution = responseAl.GetExpectedSigma(mRespParamsV3, trk); - nsigma = responseAl.GetSeparation(mRespParamsV3, trk, resolution); + resolution = responseAl.GetExpectedSigma(tofResponse->parameters, trk); + nsigma = responseAl.GetSeparation(tofResponse->parameters, trk, resolution); tablePIDFullAl(resolution, nsigma); break; } @@ -1514,7 +1220,7 @@ struct tofPidMerge { } if (enableTableMass) { if (enableTOFParamsForBetaMass) { - tablePIDTOFMass(o2::pid::tof::TOFMass::GetTOFMass(trk.tofExpMom() / (1.f + trk.sign() * mRespParamsV3.getMomentumChargeShift(trk.eta())), beta)); + tablePIDTOFMass(o2::pid::tof::TOFMass::GetTOFMass(trk.tofExpMom() / (1.f + trk.sign() * tofResponse->parameters.getMomentumChargeShift(trk.eta())), beta)); } else { tablePIDTOFMass(o2::pid::tof::TOFMass::GetTOFMass(trk, beta)); } @@ -1539,7 +1245,7 @@ struct tofPidMerge { } if (enableTableMass) { if (enableTOFParamsForBetaMass) { - tablePIDTOFMass(o2::pid::tof::TOFMass::GetTOFMass(trk.tofExpMom() / (1.f + trk.sign() * mRespParamsV3.getMomentumChargeShift(trk.eta())), beta)); + tablePIDTOFMass(o2::pid::tof::TOFMass::GetTOFMass(trk.tofExpMom() / (1.f + trk.sign() * tofResponse->parameters.getMomentumChargeShift(trk.eta())), beta)); } else { tablePIDTOFMass(o2::pid::tof::TOFMass::GetTOFMass(trk, beta)); } @@ -1552,7 +1258,7 @@ struct tofPidMerge { WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { // Parse the metadata - metadataInfo.initMetadata(cfgc); + o2::pid::tof::TOFResponseImpl::metadataInfo.initMetadata(cfgc); auto workflow = WorkflowSpec{adaptAnalysisTask(cfgc)}; workflow.push_back(adaptAnalysisTask(cfgc)); workflow.push_back(adaptAnalysisTask(cfgc)); From de6d0d205868da57cded6cc1e4b183efb9a058e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Sun, 2 Nov 2025 11:49:03 +0100 Subject: [PATCH 2/2] Update --- Common/TableProducer/PID/pidTOFMerge.cxx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Common/TableProducer/PID/pidTOFMerge.cxx b/Common/TableProducer/PID/pidTOFMerge.cxx index e8a29b28368..79a2c02d655 100644 --- a/Common/TableProducer/PID/pidTOFMerge.cxx +++ b/Common/TableProducer/PID/pidTOFMerge.cxx @@ -9,9 +9,11 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. /// -/// \file pidTOFMerge.cxx -/// \brief Task to produce PID tables for TOF split for each particle. -/// Only the tables for the mass hypotheses requested are filled, the others are sent empty. +/// \file pidTOFMerge.cxx +/// +/// \brief Task to produce PID tables for TOF split for each particle. +/// Only the tables for the mass hypotheses requested are filled, the others are sent empty. +/// /// \author Nicolò Jacazio nicolo.jacazio@cern.ch /// @@ -709,7 +711,7 @@ struct tofPidMerge { doprocessRun3BetaM.value = false; } } else { - metadataInfo.print(); + tofResponse->metadataInfo.print(); LOG(warning) << "Metadata is not defined, cannot autodetect process functions for mass and beta"; } } else {