diff --git a/EventFiltering/PWGLF/nucleiFilter.cxx b/EventFiltering/PWGLF/nucleiFilter.cxx index 54f3ed507ad..443df675533 100644 --- a/EventFiltering/PWGLF/nucleiFilter.cxx +++ b/EventFiltering/PWGLF/nucleiFilter.cxx @@ -10,42 +10,48 @@ // or submit itself to any jurisdiction. // O2 includes -#include -#include +#include "../filterTables.h" -#include "Math/Vector4D.h" -#include "Math/GenVector/Boost.h" +#include "PWGLF/DataModel/LFPIDTOFGenericTables.h" +#include "PWGLF/DataModel/LFStrangenessTables.h" +#include "PWGLF/DataModel/Vtx3BodyTables.h" +#include "PWGLF/Utils/pidTOFGeneric.h" + +#include "Common/Core/PID/PIDTOF.h" +#include "Common/Core/trackUtilities.h" #include "Common/DataModel/EventSelection.h" #include "Common/DataModel/PIDResponse.h" #include "Common/DataModel/TrackSelectionTables.h" + +#include "CCDB/BasicCCDBManager.h" +#include "DCAFitter/DCAFitterN.h" +#include "DataFormatsParameters/GRPMagField.h" +#include "DataFormatsParameters/GRPObject.h" +#include "DataFormatsTOF/ParameterContainers.h" #include "DataFormatsTPC/BetheBlochAleph.h" +#include "DetectorsBase/GeometryManager.h" +#include "DetectorsBase/Propagator.h" +#include "Framework/ASoAHelpers.h" #include "Framework/AnalysisDataModel.h" #include "Framework/AnalysisTask.h" -#include "Framework/ASoAHelpers.h" #include "Framework/HistogramRegistry.h" #include "Framework/runDataProcessing.h" #include "ReconstructionDataFormats/Track.h" -#include "PWGLF/DataModel/Vtx3BodyTables.h" -#include "../filterTables.h" +#include "Math/GenVector/Boost.h" +#include "Math/Vector4D.h" -#include "ReconstructionDataFormats/Track.h" -#include "Common/Core/trackUtilities.h" -#include "DetectorsBase/Propagator.h" -#include "DetectorsBase/GeometryManager.h" -#include "DataFormatsParameters/GRPObject.h" -#include "DataFormatsParameters/GRPMagField.h" -#include "DataFormatsTOF/ParameterContainers.h" -#include "CCDB/BasicCCDBManager.h" -#include "DCAFitter/DCAFitterN.h" -#include "PWGLF/DataModel/pidTOFGeneric.h" -#include "PWGLF/DataModel/LFStrangenessTables.h" -#include "Common/Core/PID/PIDTOF.h" +#include +#include +#include +#include using namespace o2; using namespace o2::framework; using namespace o2::framework::expressions; +o2::common::core::MetadataHelper metadataInfo; + namespace { @@ -120,7 +126,9 @@ struct nucleiFilter { o2::base::MatLayerCylSet* lut = nullptr; o2::vertexing::DCAFitterN<2> fitter2body; o2::vertexing::DCAFitterN<3> fitter3body; - o2::pid::tof::TOFResoParamsV2 mRespParamsV2; + // TOF response and input parameters + o2::pid::tof::TOFResoParamsV3 mRespParamsV3; + o2::aod::pidtofgeneric::TOFCalibConfig mTOFCalibConfig; // TOF Calib configuration // configurable for hypertriton 3body decay struct : ConfigurableGroup { Configurable bFieldInput{"trgH3L3Body.mBz", -999, "bz field, -999 is automatic"}; @@ -153,20 +161,12 @@ struct nucleiFilter { Configurable grpmagPath{"trgH3L3Body.grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"}; Configurable lutPath{"trgH3L3Body.lutPath", "GLO/Param/MatLUT", "Path of the Lut parametrization"}; Configurable geoPath{"trgH3L3Body.geoPath", "GLO/Config/GeometryAligned", "Path of the geometry file"}; - // CCDB TOF PID paras - Configurable timestamp{"trgH3L3Body.ccdb-timestamp", -1, "timestamp of the object"}; - Configurable paramFileName{"trgH3L3Body.paramFileName", "", "Path to the parametrization object. If empty the parametrization is not taken from file"}; - Configurable parametrizationPath{"trgH3L3Body.parametrizationPath", "TOF/Calib/Params", "Path of the TOF parametrization on the CCDB or in the file, if the paramFileName is not empty"}; - Configurable passName{"trgH3L3Body.passName", "", "Name of the pass inside of the CCDB parameter collection. If empty, the automatically deceted from metadata (to be implemented!!!)"}; - Configurable timeShiftCCDBPath{"trgH3L3Body.timeShiftCCDBPath", "", "Path of the TOF time shift vs eta. If empty none is taken"}; - Configurable loadResponseFromCCDB{"trgH3L3Body.loadResponseFromCCDB", false, "Flag to load the response from the CCDB"}; - Configurable fatalOnPassNotAvailable{"trgH3L3Body.fatalOnPassNotAvailable", false, "Flag to throw a fatal if the pass is not available in the retrieved CCDB object"}; } trgH3L3Body; HistogramRegistry qaHists{"qaHists", {}, OutputObjHandlingPolicy::AnalysisObject, true, true}; OutputObj hProcessedEvents{TH1D("hProcessedEvents", ";;Number of filtered events", kNtriggers + 1, -0.5, static_cast(kNtriggers) + 0.5)}; - void init(InitContext&) + void init(InitContext& initContext) { std::vector ptBinning = {0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.8, 3.2, 3.6, 4., 5.}; @@ -214,6 +214,11 @@ struct nucleiFilter { ccdb->setCaching(true); ccdb->setLocalObjectValidityChecking(); ccdb->setFatalWhenNull(false); + + // Initialization of TOF PID parameters for fH3L3Body + mTOFCalibConfig.metadataInfo = metadataInfo; + mTOFCalibConfig.inheritFromBaseTask(initContext); + mTOFCalibConfig.initSetup(mRespParamsV3, ccdb); // Getting the parametrization parameters } void initCCDB(aod::BCsWithTimestamps::iterator const& bc) @@ -264,65 +269,7 @@ struct nucleiFilter { o2::base::Propagator::Instance()->setMatLUT(lut); } - // Initial TOF PID Paras, copied from pidTOF.cxx - trgH3L3Body.timestamp.value = bc.timestamp(); - ccdb->setTimestamp(trgH3L3Body.timestamp.value); - // Not later than now objects - ccdb->setCreatedNotAfter(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()); - // TODO: implement the automatic pass name detection from metadata - if (trgH3L3Body.passName.value == "") { - trgH3L3Body.passName.value = "unanchored"; // temporary default - LOG(warning) << "Passed autodetect mode for pass, not implemented yet, waiting for metadata. Taking '" << trgH3L3Body.passName.value << "'"; - } - LOG(info) << "Using parameter collection, starting from pass '" << trgH3L3Body.passName.value << "'"; - - const std::string fname = trgH3L3Body.paramFileName.value; - if (!fname.empty()) { // Loading the parametrization from file - LOG(info) << "Loading exp. sigma parametrization from file " << fname << ", using param: " << trgH3L3Body.parametrizationPath.value; - if (1) { - o2::tof::ParameterCollection paramCollection; - paramCollection.loadParamFromFile(fname, trgH3L3Body.parametrizationPath.value); - LOG(info) << "+++ Loaded parameter collection from file +++"; - if (!paramCollection.retrieveParameters(mRespParamsV2, trgH3L3Body.passName.value)) { - if (trgH3L3Body.fatalOnPassNotAvailable) { - LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", trgH3L3Body.passName.value.data()); - } else { - LOGF(warning, "Pass '%s' not available in the retrieved CCDB object", trgH3L3Body.passName.value.data()); - } - } else { - mRespParamsV2.setShiftParameters(paramCollection.getPars(trgH3L3Body.passName.value)); - mRespParamsV2.printShiftParameters(); - } - } else { - mRespParamsV2.loadParamFromFile(fname.data(), trgH3L3Body.parametrizationPath.value); - } - } else if (trgH3L3Body.loadResponseFromCCDB) { // Loading it from CCDB - LOG(info) << "Loading exp. sigma parametrization from CCDB, using path: " << trgH3L3Body.parametrizationPath.value << " for timestamp " << trgH3L3Body.timestamp.value; - o2::tof::ParameterCollection* paramCollection = ccdb->getForTimeStamp(trgH3L3Body.parametrizationPath.value, trgH3L3Body.timestamp.value); - paramCollection->print(); - if (!paramCollection->retrieveParameters(mRespParamsV2, trgH3L3Body.passName.value)) { // Attempt at loading the parameters with the pass defined - if (trgH3L3Body.fatalOnPassNotAvailable) { - LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", trgH3L3Body.passName.value.data()); - } else { - LOGF(warning, "Pass '%s' not available in the retrieved CCDB object", trgH3L3Body.passName.value.data()); - } - } else { // Pass is available, load non standard parameters - mRespParamsV2.setShiftParameters(paramCollection->getPars(trgH3L3Body.passName.value)); - mRespParamsV2.printShiftParameters(); - } - } - mRespParamsV2.print(); - if (trgH3L3Body.timeShiftCCDBPath.value != "") { - if (trgH3L3Body.timeShiftCCDBPath.value.find(".root") != std::string::npos) { - mRespParamsV2.setTimeShiftParameters(trgH3L3Body.timeShiftCCDBPath.value, "gmean_Pos", true); - mRespParamsV2.setTimeShiftParameters(trgH3L3Body.timeShiftCCDBPath.value, "gmean_Neg", false); - } else { - mRespParamsV2.setTimeShiftParameters(ccdb->getForTimeStamp(Form("%s/pos", trgH3L3Body.timeShiftCCDBPath.value.c_str()), trgH3L3Body.timestamp.value), true); - mRespParamsV2.setTimeShiftParameters(ccdb->getForTimeStamp(Form("%s/neg", trgH3L3Body.timeShiftCCDBPath.value.c_str()), trgH3L3Body.timestamp.value), false); - } - } - - bachelorTOFPID.SetParams(mRespParamsV2); + mTOFCalibConfig.processSetup(mRespParamsV3, ccdb, bc); } enum { @@ -568,7 +515,7 @@ struct nucleiFilter { float tofNSigmaDeuteron = -999; if (track2.has_collision() && track2.hasTOF()) { auto originalcol = track2.collision_as(); - tofNSigmaDeuteron = bachelorTOFPID.GetTOFNSigma(track2, originalcol, collision); + tofNSigmaDeuteron = bachelorTOFPID.GetTOFNSigma(mRespParamsV3, track2, originalcol, collision); } if (track2.p() > trgH3L3Body.minDeuteronPUseTOF && (tofNSigmaDeuteron < trgH3L3Body.tofPIDNSigmaMin || tofNSigmaDeuteron > trgH3L3Body.tofPIDNSigmaMax)) { continue; @@ -671,6 +618,7 @@ struct nucleiFilter { WorkflowSpec defineDataProcessing(ConfigContext const& cfg) { + metadataInfo.initMetadata(cfg); return WorkflowSpec{ adaptAnalysisTask(cfg)}; } diff --git a/PWGLF/DataModel/LFHyperNucleiKinkTables.h b/PWGLF/DataModel/LFHyperNucleiKinkTables.h index 4ffd6f4ec46..3f064f5225f 100644 --- a/PWGLF/DataModel/LFHyperNucleiKinkTables.h +++ b/PWGLF/DataModel/LFHyperNucleiKinkTables.h @@ -55,6 +55,7 @@ DECLARE_SOA_COLUMN(ItsClusterSizesMoth, itsClusterSizesMoth, uint32_t); //! ITS DECLARE_SOA_COLUMN(ItsClusterSizesDaug, itsClusterSizesDaug, uint32_t); //! ITS cluster size of the daughter track DECLARE_SOA_COLUMN(NSigmaTPCDaug, nSigmaTPCDaug, float); //! Number of tpc sigmas of the daughter track DECLARE_SOA_COLUMN(NSigmaITSDaug, nSigmaITSDaug, float); //! Number of ITS sigmas of the daughter track +DECLARE_SOA_COLUMN(NSigmaTOFDaug, nSigmaTOFDaug, float); //! Number of TOF sigmas of the daughter track DECLARE_SOA_COLUMN(IsSignal, isSignal, bool); //! bool: true for hyperhelium4signal DECLARE_SOA_COLUMN(IsSignalReco, isSignalReco, bool); //! bool: true if the signal is reconstructed @@ -94,7 +95,7 @@ DECLARE_SOA_TABLE(HypKinkCand, "AOD", "HYPKINKCANDS", hyperkink::PxDaugSV, hyperkink::PyDaugSV, hyperkink::PzDaugSV, hyperkink::DcaMothPv, hyperkink::DcaDaugPv, hyperkink::DcaKinkTopo, hyperkink::ItsChi2Moth, hyperkink::ItsClusterSizesMoth, hyperkink::ItsClusterSizesDaug, - hyperkink::NSigmaTPCDaug, hyperkink::NSigmaITSDaug); + hyperkink::NSigmaTPCDaug, hyperkink::NSigmaITSDaug, hyperkink::NSigmaTOFDaug); DECLARE_SOA_TABLE(MCHypKinkCand, "AOD", "MCHYPKINKCANDS", o2::soa::Index<>, @@ -109,7 +110,7 @@ DECLARE_SOA_TABLE(MCHypKinkCand, "AOD", "MCHYPKINKCANDS", hyperkink::PxDaugSV, hyperkink::PyDaugSV, hyperkink::PzDaugSV, hyperkink::DcaMothPv, hyperkink::DcaDaugPv, hyperkink::DcaKinkTopo, hyperkink::ItsChi2Moth, hyperkink::ItsClusterSizesMoth, hyperkink::ItsClusterSizesDaug, - hyperkink::NSigmaTPCDaug, hyperkink::NSigmaITSDaug, + hyperkink::NSigmaTPCDaug, hyperkink::NSigmaITSDaug, hyperkink::NSigmaTOFDaug, hyperkink::IsSignal, hyperkink::IsSignalReco, hyperkink::IsCollReco, hyperkink::IsSurvEvSelection, hyperkink::TrueXSV, hyperkink::TrueYSV, hyperkink::TrueZSV, hyperkink::TruePxMothPV, hyperkink::TruePyMothPV, hyperkink::TruePzMothPV, diff --git a/PWGLF/DataModel/LFPIDTOFGenericTables.h b/PWGLF/DataModel/LFPIDTOFGenericTables.h new file mode 100644 index 00000000000..3a52a8a8ca5 --- /dev/null +++ b/PWGLF/DataModel/LFPIDTOFGenericTables.h @@ -0,0 +1,59 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +// +/// \file LFPIDTOFGenericTables.h +/// \brief Table for event time without remving track bias +/// \author Yuanzhe Wang + +#include "Framework/ASoAHelpers.h" +#include "Framework/AnalysisDataModel.h" + +#ifndef PWGLF_DATAMODEL_LFPIDTOFGENERICTABLES_H_ +#define PWGLF_DATAMODEL_LFPIDTOFGENERICTABLES_H_ +#include "Common/Core/PID/PIDTOF.h" + +#include "CommonDataFormat/InteractionRecord.h" + +namespace o2::aod +{ +namespace evtime +{ + +DECLARE_SOA_COLUMN(EvTime, evTime, float); //! Event time. Can be obtained via a combination of detectors e.g. TOF, FT0A, FT0C +DECLARE_SOA_COLUMN(EvTimeErr, evTimeErr, float); //! Error of event time. Can be obtained via a combination of detectors e.g. TOF, FT0A, FT0C +DECLARE_SOA_COLUMN(EvTimeTOF, evTimeTOF, float); //! Event time computed with the TOF detector +DECLARE_SOA_COLUMN(EvTimeTOFErr, evTimeTOFErr, float); //! Error of the event time computed with the TOF detector +DECLARE_SOA_COLUMN(EvTimeFT0, evTimeFT0, float); //! Event time computed with the FT0 detector +DECLARE_SOA_COLUMN(EvTimeFT0Err, evTimeFT0Err, float); //! Error of the event time computed with the FT0 detector +} // namespace evtime + +DECLARE_SOA_TABLE(EvTimeTOFFT0, "AOD", "EvTimeTOFFT0", //! Table of the event time. One entry per collision. + evtime::EvTime, + evtime::EvTimeErr, + evtime::EvTimeTOF, + evtime::EvTimeTOFErr, + evtime::EvTimeFT0, + evtime::EvTimeFT0Err); + +namespace tracktime +{ + +DECLARE_SOA_COLUMN(EvTimeForTrack, evTimeForTrack, float); //! Event time. Removed the bias for the specific track +DECLARE_SOA_COLUMN(EvTimeErrForTrack, evTimeErrForTrack, float); //! Error of event time. Removed the bias for the specific track +} // namespace tracktime + +DECLARE_SOA_TABLE(EvTimeTOFFT0ForTrack, "AOD", "EvTimeForTrack", //! Table of the event time. One entry per track. + tracktime::EvTimeForTrack, + tracktime::EvTimeErrForTrack); + +} // namespace o2::aod + +#endif // PWGLF_DATAMODEL_LFPIDTOFGENERICTABLES_H_ diff --git a/PWGLF/DataModel/pidTOFGeneric.h b/PWGLF/DataModel/pidTOFGeneric.h deleted file mode 100644 index a0d287a7643..00000000000 --- a/PWGLF/DataModel/pidTOFGeneric.h +++ /dev/null @@ -1,220 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#ifndef PWGLF_DATAMODEL_PIDTOFGENERIC_H_ -#define PWGLF_DATAMODEL_PIDTOFGENERIC_H_ -#include "CommonDataFormat/InteractionRecord.h" -#include "Common/Core/PID/PIDTOF.h" - -namespace o2::aod -{ -namespace evtime -{ - -DECLARE_SOA_COLUMN(EvTime, evTime, float); //! Event time. Can be obtained via a combination of detectors e.g. TOF, FT0A, FT0C -DECLARE_SOA_COLUMN(EvTimeErr, evTimeErr, float); //! Error of event time. Can be obtained via a combination of detectors e.g. TOF, FT0A, FT0C -DECLARE_SOA_COLUMN(EvTimeTOF, evTimeTOF, float); //! Event time computed with the TOF detector -DECLARE_SOA_COLUMN(EvTimeTOFErr, evTimeTOFErr, float); //! Error of the event time computed with the TOF detector -DECLARE_SOA_COLUMN(EvTimeFT0, evTimeFT0, float); //! Event time computed with the FT0 detector -DECLARE_SOA_COLUMN(EvTimeFT0Err, evTimeFT0Err, float); //! Error of the event time computed with the FT0 detector -} // namespace evtime - -DECLARE_SOA_TABLE(EvTimeTOFFT0, "AOD", "EvTimeTOFFT0", //! Table of the event time. One entry per collision. - evtime::EvTime, - evtime::EvTimeErr, - evtime::EvTimeTOF, - evtime::EvTimeTOFErr, - evtime::EvTimeFT0, - evtime::EvTimeFT0Err); - -namespace tracktime -{ - -DECLARE_SOA_COLUMN(EvTimeForTrack, evTimeForTrack, float); //! Event time. Removed the bias for the specific track -DECLARE_SOA_COLUMN(EvTimeErrForTrack, evTimeErrForTrack, float); //! Error of event time. Removed the bias for the specific track -} // namespace tracktime - -DECLARE_SOA_TABLE(EvTimeTOFFT0ForTrack, "AOD", "EvTimeForTrack", //! Table of the event time. One entry per track. - tracktime::EvTimeForTrack, - tracktime::EvTimeErrForTrack); - -namespace pidtofgeneric -{ - -static constexpr float kCSPEED = TMath::C() * 1.0e2f * 1.0e-12f; // c in cm/ps - -template -class TofPidNewCollision -{ - public: - TofPidNewCollision() = default; - ~TofPidNewCollision() = default; - - o2::pid::tof::TOFResoParamsV2 mRespParamsV2; - o2::track::PID::ID pidType; - - template - using ResponseImplementation = o2::pid::tof::ExpTimes; - static constexpr auto responseEl = ResponseImplementation(); - static constexpr auto responseMu = ResponseImplementation(); - static constexpr auto responsePi = ResponseImplementation(); - static constexpr auto responseKa = ResponseImplementation(); - static constexpr auto responsePr = ResponseImplementation(); - static constexpr auto responseDe = ResponseImplementation(); - static constexpr auto responseTr = ResponseImplementation(); - static constexpr auto responseHe = ResponseImplementation(); - static constexpr auto responseAl = ResponseImplementation(); - - void SetParams(o2::pid::tof::TOFResoParamsV2 const& para) - { - mRespParamsV2.setParameters(para); - } - - void SetPidType(o2::track::PID::ID pidId) - { - pidType = pidId; - } - - template - float GetTOFNSigma(o2::track::PID::ID pidId, TTrack const& track, TCollision const& originalcol, TCollision const& correctedcol, bool EnableBCAO2D = true); - - template - float GetTOFNSigma(TTrack const& track, TCollision const& originalcol, TCollision const& correctedcol, bool EnableBCAO2D = true); - - float GetTOFNSigma(TTrack const& track); - float GetTOFNSigma(o2::track::PID::ID pidId, TTrack const& track); - - float CalculateTOFNSigma(o2::track::PID::ID pidId, TTrack const& track, double tofsignal, double evTime, double evTimeErr) - { - - float expSigma, tofNsigma = -999; - - switch (pidId) { - case 0: - expSigma = responseEl.GetExpectedSigma(mRespParamsV2, track, tofsignal, evTimeErr); - tofNsigma = (tofsignal - evTime - responseEl.GetCorrectedExpectedSignal(mRespParamsV2, track)) / expSigma; - break; - case 1: - expSigma = responseMu.GetExpectedSigma(mRespParamsV2, track, tofsignal, evTimeErr); - tofNsigma = (tofsignal - evTime - responseMu.GetCorrectedExpectedSignal(mRespParamsV2, track)) / expSigma; - break; - case 2: - expSigma = responsePi.GetExpectedSigma(mRespParamsV2, track, tofsignal, evTimeErr); - tofNsigma = (tofsignal - evTime - responsePi.GetCorrectedExpectedSignal(mRespParamsV2, track)) / expSigma; - break; - case 3: - expSigma = responseKa.GetExpectedSigma(mRespParamsV2, track, tofsignal, evTimeErr); - tofNsigma = (tofsignal - evTime - responseKa.GetCorrectedExpectedSignal(mRespParamsV2, track)) / expSigma; - break; - case 4: - expSigma = responsePr.GetExpectedSigma(mRespParamsV2, track, tofsignal, evTimeErr); - tofNsigma = (tofsignal - evTime - responsePr.GetCorrectedExpectedSignal(mRespParamsV2, track)) / expSigma; - break; - case 5: - expSigma = responseDe.GetExpectedSigma(mRespParamsV2, track, tofsignal, evTimeErr); - tofNsigma = (tofsignal - evTime - responseDe.GetCorrectedExpectedSignal(mRespParamsV2, track)) / expSigma; - break; - case 6: - expSigma = responseTr.GetExpectedSigma(mRespParamsV2, track, tofsignal, evTimeErr); - tofNsigma = (tofsignal - evTime - responseTr.GetCorrectedExpectedSignal(mRespParamsV2, track)) / expSigma; - break; - case 7: - expSigma = responseHe.GetExpectedSigma(mRespParamsV2, track, tofsignal, evTimeErr); - tofNsigma = (tofsignal - evTime - responseHe.GetCorrectedExpectedSignal(mRespParamsV2, track)) / expSigma; - break; - case 8: - expSigma = responseAl.GetExpectedSigma(mRespParamsV2, track, tofsignal, evTimeErr); - tofNsigma = (tofsignal - evTime - responseAl.GetCorrectedExpectedSignal(mRespParamsV2, track)) / expSigma; - break; - default: - LOG(fatal) << "Wrong particle ID in TofPidSecondary class"; - return -999; - } - - return tofNsigma; - } -}; - -template -template -float TofPidNewCollision::GetTOFNSigma(o2::track::PID::ID pidId, TTrack const& track, TCollision const& originalcol, TCollision const& correctedcol, bool EnableBCAO2D) -{ - - if (!track.has_collision() || !track.hasTOF()) { - return -999; - } - - float mMassHyp = o2::track::pid_constants::sMasses2Z[track.pidForTracking()]; - float expTime = track.length() * sqrt((mMassHyp * mMassHyp) + (track.tofExpMom() * track.tofExpMom())) / (kCSPEED * track.tofExpMom()); // L*E/(p*c) = L/v - - float evTime = correctedcol.evTime(); - float evTimeErr = correctedcol.evTimeErr(); - float tofsignal = track.trackTime() * 1000 + expTime; // in ps - - if (originalcol.globalIndex() == correctedcol.globalIndex()) { - evTime = track.evTimeForTrack(); - evTimeErr = track.evTimeErrForTrack(); - } else { - if (EnableBCAO2D) { - auto originalbc = originalcol.template bc_as(); - auto correctedbc = correctedcol.template bc_as(); - o2::InteractionRecord originalIR = o2::InteractionRecord::long2IR(originalbc.globalBC()); - o2::InteractionRecord correctedIR = o2::InteractionRecord::long2IR(correctedbc.globalBC()); - tofsignal += originalIR.differenceInBCNS(correctedIR) * 1000; - } else { - auto originalbc = originalcol.template foundBC_as(); - auto correctedbc = correctedcol.template foundBC_as(); - o2::InteractionRecord originalIR = o2::InteractionRecord::long2IR(originalbc.globalBC()); - o2::InteractionRecord correctedIR = o2::InteractionRecord::long2IR(correctedbc.globalBC()); - tofsignal += originalIR.differenceInBCNS(correctedIR) * 1000; - } - } - - float tofNsigma = CalculateTOFNSigma(pidId, track, tofsignal, evTime, evTimeErr); - return tofNsigma; -} - -template -template -float TofPidNewCollision::GetTOFNSigma(TTrack const& track, TCollision const& originalcol, TCollision const& correctedcol, bool EnableBCAO2D) -{ - return GetTOFNSigma(pidType, track, originalcol, correctedcol, EnableBCAO2D); -} - -template -float TofPidNewCollision::GetTOFNSigma(o2::track::PID::ID pidId, TTrack const& track) -{ - - if (!track.has_collision() || !track.hasTOF()) { - return -999; - } - - float mMassHyp = o2::track::pid_constants::sMasses2Z[track.pidForTracking()]; - float expTime = track.length() * sqrt((mMassHyp * mMassHyp) + (track.tofExpMom() * track.tofExpMom())) / (kCSPEED * track.tofExpMom()); // L*E/(p*c) = L/v - - float evTime = track.evTimeForTrack(); - float evTimeErr = track.evTimeErrForTrack(); - float tofsignal = track.trackTime() * 1000 + expTime; // in ps - - float tofNsigma = CalculateTOFNSigma(pidId, track, tofsignal, evTime, evTimeErr); - return tofNsigma; -} - -template -float TofPidNewCollision::GetTOFNSigma(TTrack const& track) -{ - return GetTOFNSigma(pidType, track); -} - -} // namespace pidtofgeneric -} // namespace o2::aod - -#endif // PWGLF_DATAMODEL_PIDTOFGENERIC_H_ diff --git a/PWGLF/TableProducer/Nuspex/CMakeLists.txt b/PWGLF/TableProducer/Nuspex/CMakeLists.txt index 2f1295a8f4f..98dac784da5 100644 --- a/PWGLF/TableProducer/Nuspex/CMakeLists.txt +++ b/PWGLF/TableProducer/Nuspex/CMakeLists.txt @@ -96,7 +96,7 @@ o2physics_add_dpl_workflow(nuclei-flow-trees o2physics_add_dpl_workflow(hyperkink-reco-task SOURCES hyperkinkRecoTask.cxx - PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore + PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2::TOFBase COMPONENT_NAME Analysis) o2physics_add_dpl_workflow(he3-lambda-analysis diff --git a/PWGLF/TableProducer/Nuspex/decay3bodybuilder.cxx b/PWGLF/TableProducer/Nuspex/decay3bodybuilder.cxx index bee3f8f9eaf..7757cbc72a1 100644 --- a/PWGLF/TableProducer/Nuspex/decay3bodybuilder.cxx +++ b/PWGLF/TableProducer/Nuspex/decay3bodybuilder.cxx @@ -17,10 +17,11 @@ #include "TableHelper.h" +#include "PWGLF/DataModel/LFPIDTOFGenericTables.h" #include "PWGLF/DataModel/Reduced3BodyTables.h" #include "PWGLF/DataModel/Vtx3BodyTables.h" -#include "PWGLF/DataModel/pidTOFGeneric.h" #include "PWGLF/Utils/decay3bodyBuilderHelper.h" +#include "PWGLF/Utils/pidTOFGeneric.h" #include "Common/Core/PID/PIDTOF.h" #include "Common/Core/RecoDecay.h" @@ -66,6 +67,8 @@ using namespace o2; using namespace o2::framework; using namespace o2::framework::expressions; +o2::common::core::MetadataHelper metadataInfo; + static constexpr int nParameters = 1; static const std::vector tableNames{ "Decay3BodyIndices", @@ -204,17 +207,6 @@ struct decay3bodyBuilder { Configurable maxDCAZ3Body{"maxDCAZ3Body", 1.0, "Max DCA Z of 3body"}; } mixingOpts; - struct : ConfigurableGroup { - std::string prefix = "tofPIDOpts"; - Configurable timestamp{"ccdb-timestamp", -1, "timestamp of the object"}; - Configurable paramFileName{"paramFileName", "", "Path to the parametrization object. If empty the parametrization is not taken from file"}; - Configurable parametrizationPath{"parametrizationPath", "TOF/Calib/Params", "Path of the TOF parametrization on the CCDB or in the file, if the paramFileName is not empty"}; - Configurable passName{"passName", "", "Name of the pass inside of the CCDB parameter collection. If empty, the automatically deceted from metadata (to be implemented!!!)"}; - Configurable timeShiftCCDBPath{"timeShiftCCDBPath", "", "Path of the TOF time shift vs eta. If empty none is taken"}; - Configurable loadResponseFromCCDB{"loadResponseFromCCDB", false, "Flag to load the response from the CCDB"}; - Configurable fatalOnPassNotAvailable{"fatalOnPassNotAvailable", true, "Flag to throw a fatal if the pass is not available in the retrieved CCDB object"}; - } tofPIDOpts; - // Helper struct to contain MC information prior to filling struct mc3Bodyinfo { int label; @@ -256,7 +248,9 @@ struct decay3bodyBuilder { // bachelor TOF PID o2::aod::pidtofgeneric::TofPidNewCollision bachelorTOFPID; // to be updated in Init based on the hypothesis o2::aod::pidtofgeneric::TofPidNewCollision bachelorTOFPIDLabeled; // to be updated in Init based on the hypothesis - o2::pid::tof::TOFResoParamsV2 mRespParamsV2; + // TOF response and input parameters + o2::pid::tof::TOFResoParamsV3 mRespParamsV3; + o2::aod::pidtofgeneric::TOFCalibConfig mTOFCalibConfig; // TOF Calib configuration // 3body mixing using Binning3BodyKF = ColumnBinningPolicy; @@ -274,7 +268,7 @@ struct decay3bodyBuilder { // MC info std::vector isGoodCollision; - void init(InitContext&) + void init(InitContext& initContext) { zorroSummary.setObject(zorro.getZorroSummary()); @@ -289,6 +283,11 @@ struct decay3bodyBuilder { ccdb->setLocalObjectValidityChecking(); ccdb->setFatalWhenNull(false); + // TOF PID parameters initialization + mTOFCalibConfig.metadataInfo = metadataInfo; + mTOFCalibConfig.inheritFromBaseTask(initContext); + mTOFCalibConfig.initSetup(mRespParamsV3, ccdb); + // Set material correction if (useMatCorrType == 1) { LOGF(info, "TGeo correction requested, loading geometry"); @@ -528,66 +527,7 @@ struct decay3bodyBuilder { // mark run as configured mRunNumber = bc.runNumber(); - // Initial TOF PID Paras, copied from PIDTOF.h - tofPIDOpts.timestamp.value = bc.timestamp(); - ccdb->setTimestamp(tofPIDOpts.timestamp.value); - // Not later than now objects - ccdb->setCreatedNotAfter(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()); - // TODO: implement the automatic pass name detection from metadata - if (tofPIDOpts.passName.value == "") { - tofPIDOpts.passName.value = "unanchored"; // temporary default - LOG(warning) << "Passed autodetect mode for pass, not implemented yet, waiting for metadata. Taking '" << tofPIDOpts.passName.value << "'"; - } - LOG(info) << "Using parameter collection, starting from pass '" << tofPIDOpts.passName.value << "'"; - - const std::string fname = tofPIDOpts.paramFileName.value; - if (!fname.empty()) { // Loading the parametrization from file - LOG(info) << "Loading exp. sigma parametrization from file " << fname << ", using param: " << tofPIDOpts.parametrizationPath.value; - if (1) { - o2::tof::ParameterCollection paramCollection; - paramCollection.loadParamFromFile(fname, tofPIDOpts.parametrizationPath.value); - LOG(info) << "+++ Loaded parameter collection from file +++"; - if (!paramCollection.retrieveParameters(mRespParamsV2, tofPIDOpts.passName.value)) { - if (tofPIDOpts.fatalOnPassNotAvailable) { - LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", tofPIDOpts.passName.value.data()); - } else { - LOGF(warning, "Pass '%s' not available in the retrieved CCDB object", tofPIDOpts.passName.value.data()); - } - } else { - mRespParamsV2.setShiftParameters(paramCollection.getPars(tofPIDOpts.passName.value)); - mRespParamsV2.printShiftParameters(); - } - } else { - mRespParamsV2.loadParamFromFile(fname.data(), tofPIDOpts.parametrizationPath.value); - } - } else if (tofPIDOpts.loadResponseFromCCDB) { // Loading it from CCDB - LOG(info) << "Loading exp. sigma parametrization from CCDB, using path: " << tofPIDOpts.parametrizationPath.value << " for timestamp " << tofPIDOpts.timestamp.value; - o2::tof::ParameterCollection* paramCollection = ccdb->getForTimeStamp(tofPIDOpts.parametrizationPath.value, tofPIDOpts.timestamp.value); - paramCollection->print(); - if (!paramCollection->retrieveParameters(mRespParamsV2, tofPIDOpts.passName.value)) { // Attempt at loading the parameters with the pass defined - if (tofPIDOpts.fatalOnPassNotAvailable) { - LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", tofPIDOpts.passName.value.data()); - } else { - LOGF(warning, "Pass '%s' not available in the retrieved CCDB object", tofPIDOpts.passName.value.data()); - } - } else { // Pass is available, load non standard parameters - mRespParamsV2.setShiftParameters(paramCollection->getPars(tofPIDOpts.passName.value)); - mRespParamsV2.printShiftParameters(); - } - } - mRespParamsV2.print(); - if (tofPIDOpts.timeShiftCCDBPath.value != "") { - if (tofPIDOpts.timeShiftCCDBPath.value.find(".root") != std::string::npos) { - mRespParamsV2.setTimeShiftParameters(tofPIDOpts.timeShiftCCDBPath.value, "gmean_Pos", true); - mRespParamsV2.setTimeShiftParameters(tofPIDOpts.timeShiftCCDBPath.value, "gmean_Neg", false); - } else { - mRespParamsV2.setTimeShiftParameters(ccdb->getForTimeStamp(Form("%s/pos", tofPIDOpts.timeShiftCCDBPath.value.c_str()), tofPIDOpts.timestamp.value), true); - mRespParamsV2.setTimeShiftParameters(ccdb->getForTimeStamp(Form("%s/neg", tofPIDOpts.timeShiftCCDBPath.value.c_str()), tofPIDOpts.timestamp.value), false); - } - } - - bachelorTOFPID.SetParams(mRespParamsV2); - bachelorTOFPIDLabeled.SetParams(mRespParamsV2); + mTOFCalibConfig.processSetup(mRespParamsV3, ccdb, bc); return true; } @@ -772,9 +712,9 @@ struct decay3bodyBuilder { tofNSigmaDeuteron = trackDeuteron.tofNSigmaDe(); } else if constexpr (soa::is_table) { // running over AO2Ds if constexpr (soa::is_table) { // running over MC (track table with labels) - tofNSigmaDeuteron = getTOFnSigma(collision, trackDeuteron); + tofNSigmaDeuteron = getTOFnSigma(mRespParamsV3, collision, trackDeuteron); } else { // running over real data - tofNSigmaDeuteron = getTOFnSigma(collision, trackDeuteron); + tofNSigmaDeuteron = getTOFnSigma(mRespParamsV3, collision, trackDeuteron); } } @@ -1087,15 +1027,15 @@ struct decay3bodyBuilder { // ______________________________________________________________ // function to calculate correct TOF nSigma for deuteron track template - double getTOFnSigma(TCollision const& collision, TTrack const& track) + double getTOFnSigma(o2::pid::tof::TOFResoParamsV3 const& parameters, TCollision const& collision, TTrack const& track) { // TOF PID of deuteron if (track.has_collision() && track.hasTOF()) { auto originalcol = track.template collision_as(); if constexpr (isMC) { - return bachelorTOFPIDLabeled.GetTOFNSigma(track, originalcol, collision); + return bachelorTOFPIDLabeled.GetTOFNSigma(parameters, track, originalcol, collision); } else { - return bachelorTOFPID.GetTOFNSigma(track, originalcol, collision); + return bachelorTOFPID.GetTOFNSigma(parameters, track, originalcol, collision); } } return -999; @@ -1385,6 +1325,7 @@ struct decay3bodyBuilder { WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { + metadataInfo.initMetadata(cfgc); return WorkflowSpec{ adaptAnalysisTask(cfgc)}; } diff --git a/PWGLF/TableProducer/Nuspex/hyperkinkRecoTask.cxx b/PWGLF/TableProducer/Nuspex/hyperkinkRecoTask.cxx index e465cee83fc..7d2d3fe82e6 100644 --- a/PWGLF/TableProducer/Nuspex/hyperkinkRecoTask.cxx +++ b/PWGLF/TableProducer/Nuspex/hyperkinkRecoTask.cxx @@ -15,6 +15,8 @@ #include "PWGLF/DataModel/LFHyperNucleiKinkTables.h" #include "PWGLF/DataModel/LFKinkDecayTables.h" +#include "PWGLF/DataModel/LFPIDTOFGenericTables.h" +#include "PWGLF/Utils/pidTOFGeneric.h" #include "Common/Core/RecoDecay.h" #include "Common/Core/trackUtilities.h" @@ -43,10 +45,12 @@ using namespace o2; using namespace o2::framework; using namespace o2::framework::expressions; -using CollisionsFull = soa::Join; +o2::common::core::MetadataHelper metadataInfo; + +using CollisionsFull = soa::Join; using MCLabeledCollisionsFull = soa::Join; -using FullTracksExtIU = soa::Join; -using MCLabeledTracksIU = soa::Join; +using FullTracksExtIU = soa::Join; +using MCLabeledTracksIU = soa::Join; enum PartType { kHypertriton = 0, @@ -278,6 +282,25 @@ float getITSNSigma(const TTrack& track, o2::aod::ITSResponse& itsResponse, o2::t return nSigma; } +//-------------------------------------------------------------- +// get default TOFNSigma for daughter track +template +float getDefaultTOFNSigma(const TTrack& track, o2::track::PID partType) +{ + float nSigma = -999.f; + switch (partType) { + case o2::track::PID::Alpha: + nSigma = track.tofNSigmaAl(); + break; + case o2::track::PID::Triton: + nSigma = track.tofNSigmaTr(); + break; + default: + break; + } + return nSigma; +} + //-------------------------------------------------------------- // get TPCNSigma for daughter track template @@ -346,6 +369,7 @@ struct HypKinkCandidate { uint32_t itsClusterSizeDaug = 0u; float nSigmaTPCDaug = -999.f; float nSigmaITSDaug = -999.f; + float nSigmaTOFDaug = -999.f; // recalculated TOF NSigma // mc information bool isSignal = false; @@ -382,7 +406,8 @@ struct HyperkinkRecoTask { // Configurable for event selection Configurable doEventCut{"doEventCut", true, "Apply event selection"}; Configurable maxZVertex{"maxZVertex", 10.0f, "Accepted z-vertex range (cm)"}; - Configurable cutNSigmaDaug{"cutNSigmaDaug", 5, "TPC NSigmaTPC cut for daughter tracks"}; + Configurable cutTPCNSigmaDaug{"cutTPCNSigmaDaug", 5, "TPC NSigma cut for daughter tracks"}; + Configurable cutTOFNSigmaDaug{"cutTOFNSigmaDaug", 1000, "TOF NSigma cut for daughter tracks"}; // CCDB options Configurable inputBz{"inputBz", -999, "bz field, -999 is automatic"}; @@ -402,7 +427,14 @@ struct HyperkinkRecoTask { std::array pdgDaug = {o2::constants::physics::Pdg::kTriton, PDG_t::kPi0}; // pdgcode of charged (0) and neutral (1) daughter particles o2::track::PID pidTypeDaug = o2::track::PID::Triton; - void init(InitContext&) + // secondary TOF PID + o2::aod::pidtofgeneric::TofPidNewCollision secondaryTOFPID; // to be updated in Init based on the hypothesis + o2::aod::pidtofgeneric::TofPidNewCollision secondaryTOFPIDLabeled; // to be updated in Init based on the hypothesis + // TOF response and input parameters + o2::pid::tof::TOFResoParamsV3 mRespParamsV3; + o2::aod::pidtofgeneric::TOFCalibConfig mTOFCalibConfig; // TOF Calib configuration + + void init(InitContext& initContext) { if (hypoMoth == kHypertriton) { massChargedDaug = o2::constants::physics::MassTriton; @@ -453,6 +485,11 @@ struct HyperkinkRecoTask { registry.add("hDCAXYMothToRecSV", "hDCAXYMothToRecSV", HistType::kTH1F, {{200, -10, 10}}); registry.add("hDCAZMothToRecSV", "hDCAZMothToRecSV", HistType::kTH1F, {{200, -10, 10}}); + + registry.add("hDaugOldTOFNSigma_CorrectCol", "hDaugOldTOFNSigma_CorrectCol", HistType::kTH1F, {{600, -300, 300}}); + registry.add("hDaugOldTOFNSigma_WrongCol", "hDaugOldTOFNSigma_WrongCol", HistType::kTH1F, {{600, -300, 300}}); + registry.add("hDaugNewTOFNSigma_CorrectCol", "hDaugNewTOFNSigma_CorrectCol", HistType::kTH1F, {{600, -300, 300}}); + registry.add("hDaugNewTOFNSigma_WrongCol", "hDaugNewTOFNSigma_WrongCol", HistType::kTH1F, {{600, -300, 300}}); } registry.add("h2MothMassPt", "h2MothMassPt", HistType::kTH2F, {{ptAxis, massAxis}}); @@ -462,9 +499,15 @@ struct HyperkinkRecoTask { ccdb->setCaching(true); ccdb->setLocalObjectValidityChecking(); ccdb->setFatalWhenNull(false); + + mTOFCalibConfig.metadataInfo = metadataInfo; + mTOFCalibConfig.inheritFromBaseTask(initContext); + mTOFCalibConfig.initSetup(mRespParamsV3, ccdb); + secondaryTOFPID.SetPidType(pidTypeDaug); + secondaryTOFPIDLabeled.SetPidType(pidTypeDaug); } - void initCCDB(aod::BCs::iterator const& bc) + void initCCDB(aod::BCsWithTimestamps::iterator const& bc) { if (mRunNumber == bc.runNumber()) { return; @@ -481,6 +524,24 @@ struct HyperkinkRecoTask { } o2::base::Propagator::Instance()->setMatLUT(lut); LOG(info) << "Task initialized for run " << mRunNumber << " with magnetic field " << mBz << " kZG"; + + mTOFCalibConfig.processSetup(mRespParamsV3, ccdb, bc); + } + + // ______________________________________________________________ + // get recalulate TOFNSigma for daughter track + template + double getTOFNSigma(o2::pid::tof::TOFResoParamsV3 const& parameters, TTrack const& track, TCollision const& collision, TCollision const& originalcol) + { + // TOF PID of deuteron + if (track.has_collision() && track.hasTOF()) { + if constexpr (isMC) { + return secondaryTOFPIDLabeled.GetTOFNSigma(parameters, track, originalcol, collision); + } else { + return secondaryTOFPID.GetTOFNSigma(parameters, track, originalcol, collision); + } + } + return -999; } template @@ -554,7 +615,7 @@ struct HyperkinkRecoTask { } template - void fillCandidateMCInfo(HypKinkCandidate& hypkinkCand, TMCParticle const& mcMothTrack, TMCParticle const& mcDaugTrack, TMCParticle const& mcNeutDauTrack) + void fillCandidateMCInfo(HypKinkCandidate& hypkinkCand, TMCParticle const& mcMothTrack, TMCParticle const& mcDaugTrack, TMCParticle const& mcNeutDaugTrack) { hypkinkCand.truePosSV[0] = mcDaugTrack.vx(); hypkinkCand.truePosSV[1] = mcDaugTrack.vy(); @@ -562,15 +623,15 @@ struct HyperkinkRecoTask { hypkinkCand.trueMomMothPV[0] = mcMothTrack.px(); hypkinkCand.trueMomMothPV[1] = mcMothTrack.py(); hypkinkCand.trueMomMothPV[2] = mcMothTrack.pz(); - hypkinkCand.trueMomMothSV[0] = mcDaugTrack.px() + mcNeutDauTrack.px(); - hypkinkCand.trueMomMothSV[1] = mcDaugTrack.py() + mcNeutDauTrack.py(); - hypkinkCand.trueMomMothSV[2] = mcDaugTrack.pz() + mcNeutDauTrack.pz(); + hypkinkCand.trueMomMothSV[0] = mcDaugTrack.px() + mcNeutDaugTrack.px(); + hypkinkCand.trueMomMothSV[1] = mcDaugTrack.py() + mcNeutDaugTrack.py(); + hypkinkCand.trueMomMothSV[2] = mcDaugTrack.pz() + mcNeutDaugTrack.pz(); hypkinkCand.trueMomDaugSV[0] = mcDaugTrack.px(); hypkinkCand.trueMomDaugSV[1] = mcDaugTrack.py(); hypkinkCand.trueMomDaugSV[2] = mcDaugTrack.pz(); } - void processData(CollisionsFull const& collisions, aod::KinkCands const& KinkCands, FullTracksExtIU const&, aod::BCs const&) + void processData(CollisionsFull const& collisions, aod::KinkCands const& KinkCands, FullTracksExtIU const&, aod::BCsWithTimestamps const&) { for (const auto& collision : collisions) { registry.fill(HIST("hEventCounter"), 0); @@ -589,9 +650,9 @@ struct HyperkinkRecoTask { } registry.fill(HIST("hCandidateCounter"), 1); - auto dauTrack = kinkCand.trackDaug_as(); - float tpcNSigmaDaug = getTPCNSigma(dauTrack, pidTypeDaug); - if (std::abs(tpcNSigmaDaug) > cutNSigmaDaug) { + auto daugTrack = kinkCand.trackDaug_as(); + float tpcNSigmaDaug = getTPCNSigma(daugTrack, pidTypeDaug); + if (std::abs(tpcNSigmaDaug) > cutTPCNSigmaDaug) { continue; } float invMass = RecoDecay::m(std::array{std::array{kinkCand.pxDaug(), kinkCand.pyDaug(), kinkCand.pzDaug()}, std::array{kinkCand.pxDaugNeut(), kinkCand.pyDaugNeut(), kinkCand.pzDaugNeut()}}, std::array{massChargedDaug, massNeutralDaug}); @@ -599,11 +660,20 @@ struct HyperkinkRecoTask { registry.fill(HIST("h2MothMassPt"), kinkCand.mothSign() * kinkCand.ptMoth(), invMass); registry.fill(HIST("h2DaugTPCNSigmaPt"), kinkCand.mothSign() * kinkCand.ptDaug(), tpcNSigmaDaug); - auto bc = collision.bc_as(); + auto bc = collision.bc_as(); initCCDB(bc); auto motherTrack = kinkCand.trackMoth_as(); HypKinkCandidate hypkinkCand; - fillCandidate(hypkinkCand, collision, kinkCand, motherTrack, dauTrack); + fillCandidate(hypkinkCand, collision, kinkCand, motherTrack, daugTrack); + float nSigmaTOF = -999.f; + if (daugTrack.hasTOF() && daugTrack.has_collision()) { + auto originalDaugCol = daugTrack.collision_as(); + nSigmaTOF = getTOFNSigma(mRespParamsV3, daugTrack, collision, originalDaugCol); + } + if (std::abs(nSigmaTOF) > cutTOFNSigmaDaug) { + continue; + } + hypkinkCand.nSigmaTOFDaug = nSigmaTOF; o2::dataformats::VertexBase primaryVtx = {{collision.posX(), collision.posY(), collision.posZ()}, {collision.covXX(), collision.covXY(), collision.covYY(), collision.covXZ(), collision.covYZ(), collision.covZZ()}}; o2::dataformats::VertexBase secondaryVtx = {{kinkCand.xDecVtx() + collision.posX(), kinkCand.yDecVtx() + collision.posY(), kinkCand.zDecVtx() + collision.posZ()}, {covPosSV[0], covPosSV[1], covPosSV[2], covPosSV[3], covPosSV[4], covPosSV[5]}}; @@ -628,12 +698,12 @@ struct HyperkinkRecoTask { hypkinkCand.momDaugSV[0], hypkinkCand.momDaugSV[1], hypkinkCand.momDaugSV[2], hypkinkCand.dcaXYMothPv, hypkinkCand.dcaXYDaugPv, hypkinkCand.dcaKinkTopo, hypkinkCand.chi2ITSMoth, hypkinkCand.itsClusterSizeMoth, hypkinkCand.itsClusterSizeDaug, - hypkinkCand.nSigmaTPCDaug, hypkinkCand.nSigmaITSDaug); + hypkinkCand.nSigmaTPCDaug, hypkinkCand.nSigmaITSDaug, hypkinkCand.nSigmaTOFDaug); } } PROCESS_SWITCH(HyperkinkRecoTask, processData, "process data", true); - void processMC(MCLabeledCollisionsFull const& collisions, aod::KinkCands const& KinkCands, MCLabeledTracksIU const& tracks, aod::McParticles const& particlesMC, aod::McCollisions const& mcCollisions, aod::BCs const&) + void processMC(MCLabeledCollisionsFull const& collisions, aod::KinkCands const& KinkCands, MCLabeledTracksIU const& tracks, aod::McParticles const& particlesMC, aod::McCollisions const& mcCollisions, aod::BCsWithTimestamps const&) { mcPartIndices.clear(); std::vector mcPartIndices; @@ -657,12 +727,12 @@ struct HyperkinkRecoTask { for (const auto& kinkCand : KinkCands) { auto motherTrack = kinkCand.trackMoth_as(); - auto dauTrack = kinkCand.trackDaug_as(); + auto daugTrack = kinkCand.trackDaug_as(); bool isKinkSignal = false; - if (motherTrack.has_mcParticle() && dauTrack.has_mcParticle()) { + if (motherTrack.has_mcParticle() && daugTrack.has_mcParticle()) { auto mcMothTrack = motherTrack.mcParticle_as(); - auto mcDaugTrack = dauTrack.mcParticle_as(); + auto mcDaugTrack = daugTrack.mcParticle_as(); if (hypoMoth == kHypertriton) { auto dChannel = H3LDecay::getDecayChannel(mcMothTrack, dauIDList); if (dChannel == H3LDecay::k2bodyNeutral && dauIDList[0] == mcDaugTrack.globalIndex()) { @@ -689,8 +759,8 @@ struct HyperkinkRecoTask { registry.fill(HIST("hTrueCandidateCounter"), 1); } - float tpcNSigmaDaug = getTPCNSigma(dauTrack, pidTypeDaug); - if (std::abs(tpcNSigmaDaug) > cutNSigmaDaug) { + float tpcNSigmaDaug = getTPCNSigma(daugTrack, pidTypeDaug); + if (std::abs(tpcNSigmaDaug) > cutTPCNSigmaDaug) { continue; } float invMass = RecoDecay::m(std::array{std::array{kinkCand.pxDaug(), kinkCand.pyDaug(), kinkCand.pzDaug()}, std::array{kinkCand.pxDaugNeut(), kinkCand.pyDaugNeut(), kinkCand.pzDaugNeut()}}, std::array{massChargedDaug, massNeutralDaug}); @@ -701,10 +771,27 @@ struct HyperkinkRecoTask { registry.fill(HIST("h2MothMassPt"), kinkCand.mothSign() * kinkCand.ptMoth(), invMass); registry.fill(HIST("h2DaugTPCNSigmaPt"), kinkCand.mothSign() * kinkCand.ptDaug(), tpcNSigmaDaug); - auto bc = collision.bc_as(); + auto bc = collision.bc_as(); initCCDB(bc); HypKinkCandidate hypkinkCand; - fillCandidate(hypkinkCand, collision, kinkCand, motherTrack, dauTrack); + fillCandidate(hypkinkCand, collision, kinkCand, motherTrack, daugTrack); + float nSigmaTOF = -999.f; + if (daugTrack.hasTOF() && daugTrack.has_collision()) { + auto originalDaugCol = daugTrack.collision_as(); + float defaultNSigmaTOF = getDefaultTOFNSigma(daugTrack, pidTypeDaug); + nSigmaTOF = getTOFNSigma(mRespParamsV3, daugTrack, collision, originalDaugCol); + if (originalDaugCol.globalIndex() == collision.globalIndex()) { + registry.fill(HIST("hDaugOldTOFNSigma_CorrectCol"), defaultNSigmaTOF); + registry.fill(HIST("hDaugNewTOFNSigma_CorrectCol"), nSigmaTOF); + } else { + registry.fill(HIST("hDaugOldTOFNSigma_WrongCol"), defaultNSigmaTOF); + registry.fill(HIST("hDaugNewTOFNSigma_WrongCol"), nSigmaTOF); + } + } + if (std::abs(nSigmaTOF) > cutTOFNSigmaDaug) { + continue; + } + hypkinkCand.nSigmaTOFDaug = nSigmaTOF; std::array posDecVtx = {kinkCand.xDecVtx() + collision.posX(), kinkCand.yDecVtx() + collision.posY(), kinkCand.zDecVtx() + collision.posZ()}; @@ -722,7 +809,7 @@ struct HyperkinkRecoTask { // QA, store mcInfo for true signals if (isKinkSignal) { auto mcMothTrack = motherTrack.mcParticle_as(); - auto mcDaugTrack = dauTrack.mcParticle_as(); + auto mcDaugTrack = daugTrack.mcParticle_as(); auto mcNeutTrack = particlesMC.rawIteratorAt(dauIDList[1]); float recSVR = std::sqrt(posDecVtx[0] * posDecVtx[0] + posDecVtx[1] * posDecVtx[1]); registry.fill(HIST("hDiffSVx"), posDecVtx[0] - mcDaugTrack.vx()); @@ -763,7 +850,7 @@ struct HyperkinkRecoTask { hypkinkCand.momDaugSV[0], hypkinkCand.momDaugSV[1], hypkinkCand.momDaugSV[2], hypkinkCand.dcaXYMothPv, hypkinkCand.dcaXYDaugPv, hypkinkCand.dcaKinkTopo, hypkinkCand.chi2ITSMoth, hypkinkCand.itsClusterSizeMoth, hypkinkCand.itsClusterSizeDaug, - hypkinkCand.nSigmaTPCDaug, hypkinkCand.nSigmaITSDaug, + hypkinkCand.nSigmaTPCDaug, hypkinkCand.nSigmaITSDaug, hypkinkCand.nSigmaTOFDaug, hypkinkCand.isSignal, hypkinkCand.isSignalReco, hypkinkCand.isCollReco, hypkinkCand.isSurvEvSelection, hypkinkCand.truePosSV[0], hypkinkCand.truePosSV[1], hypkinkCand.truePosSV[2], hypkinkCand.trueMomMothPV[0], hypkinkCand.trueMomMothPV[1], hypkinkCand.trueMomMothPV[2], @@ -792,7 +879,7 @@ struct HyperkinkRecoTask { auto mothTrack = tracks.rawIteratorAt(mcPartIndices[mcparticle.globalIndex()]); if (mothTrack.has_collision()) { auto collision = mothTrack.collision_as(); - auto bc = collision.template bc_as(); + auto bc = collision.template bc_as(); initCCDB(bc); fillCandidateRecoMoth(hypkinkCand, collision, mothTrack); } @@ -810,7 +897,7 @@ struct HyperkinkRecoTask { -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, + -1, -1, -1, true, false, isReconstructedMCCollisions[mcparticle.mcCollisionId()], isSelectedMCCollisions[mcparticle.mcCollisionId()], hypkinkCand.truePosSV[0], hypkinkCand.truePosSV[1], hypkinkCand.truePosSV[2], hypkinkCand.trueMomMothPV[0], hypkinkCand.trueMomMothPV[1], hypkinkCand.trueMomMothPV[2], @@ -1076,7 +1163,7 @@ struct HyperkinkQa { } PROCESS_SWITCH(HyperkinkQa, processData, "process data", true); - void processMC(aod::McCollisions const& mcCollisions, aod::McParticles const& particlesMC, MCLabeledCollisionsFull const& collisions, MCLabeledTracksIU const& tracks, aod::BCs const&) + void processMC(aod::McCollisions const& mcCollisions, aod::McParticles const& particlesMC, MCLabeledCollisionsFull const& collisions, MCLabeledTracksIU const& tracks, aod::BCsWithTimestamps const&) { std::vector mcPartIndices; setTrackIDForMC(mcPartIndices, particlesMC, tracks); @@ -1241,7 +1328,9 @@ struct HyperkinkQa { WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { + metadataInfo.initMetadata(cfgc); return WorkflowSpec{ + // Parse the metadata adaptAnalysisTask(cfgc), adaptAnalysisTask(cfgc), }; diff --git a/PWGLF/TableProducer/Nuspex/pidTOFGeneric.cxx b/PWGLF/TableProducer/Nuspex/pidTOFGeneric.cxx index 9997d4d27c8..7a3afb2b71d 100644 --- a/PWGLF/TableProducer/Nuspex/pidTOFGeneric.cxx +++ b/PWGLF/TableProducer/Nuspex/pidTOFGeneric.cxx @@ -11,33 +11,37 @@ /// /// \file pidTOFGeneric.cxx -/// \origin Based on pidTOFBase.cxx +/// \origin Based on pidTOFMerged.cxx /// \brief Task to produce event Time obtained from TOF and FT0. -/// In order to redo TOF PID for tracks which are linked to wrong collisions +/// In order to redo TOF PID for secondary tracks which are linked to wrong collisions +/// \author Yuanzhe Wang /// +#include #include #include -#include // O2 includes #include "CCDB/BasicCCDBManager.h" -#include "TOFBase/EventTimeMaker.h" #include "Framework/AnalysisTask.h" #include "ReconstructionDataFormats/Track.h" +#include "TOFBase/EventTimeMaker.h" // O2Physics includes +#include "PWGLF/DataModel/LFPIDTOFGenericTables.h" +#include "PWGLF/Utils/pidTOFGeneric.h" + #include "Common/Core/TableHelper.h" -#include "Common/DataModel/TrackSelectionTables.h" #include "Common/DataModel/EventSelection.h" #include "Common/DataModel/FT0Corrected.h" #include "Common/DataModel/Multiplicity.h" #include "Common/DataModel/PIDResponse.h" +#include "Common/DataModel/TrackSelectionTables.h" + #include "Framework/HistogramRegistry.h" #include "Framework/runDataProcessing.h" -#include "PID/ParamBase.h" #include "PID/PIDTOF.h" -#include "PWGLF/DataModel/pidTOFGeneric.h" +#include "PID/ParamBase.h" using namespace o2; using namespace o2::framework; @@ -45,13 +49,19 @@ using namespace o2::pid; using namespace o2::framework::expressions; using namespace o2::track; +o2::common::core::MetadataHelper metadataInfo; + /// Selection criteria for tracks used for TOF event time float trackSampleMinMomentum = 0.5f; float trackSampleMaxMomentum = 2.f; template bool filterForTOFEventTime(const trackType& tr) { - return (tr.hasTOF() && tr.p() > trackSampleMinMomentum && tr.p() < trackSampleMaxMomentum && (tr.trackType() == o2::aod::track::TrackTypeEnum::Track || tr.trackType() == o2::aod::track::TrackTypeEnum::TrackIU)); + return (tr.hasTOF() && + tr.p() > trackSampleMinMomentum && tr.p() < trackSampleMaxMomentum && + tr.hasITS() && + tr.hasTPC() && + (tr.trackType() == o2::aod::track::TrackTypeEnum::Track || tr.trackType() == o2::aod::track::TrackTypeEnum::TrackIU)); } // accept all /// Specialization of TOF event time maker @@ -69,342 +79,275 @@ o2::tof::eventTimeContainer evTimeMakerForTracks(const trackTypeContainer& track } /// Task to produce the event time tables for generic TOF PID +/// Modified based on pidTOFMerge.cxx struct pidTOFGeneric { // Tables to produce Produces tableEvTime; // Table for global event time Produces tableEvTimeForTrack; // Table for event time after removing bias from the track - static constexpr float diamond = 6.0; // Collision diamond used in the estimation of the TOF event time - static constexpr float errDiamond = diamond * 33.356409f; - static constexpr float weightDiamond = 1.f / (errDiamond * errDiamond); + static constexpr bool kRemoveTOFEvTimeBias = true; // Flag to subtract the Ev. Time bias for low multiplicity events with TOF + static constexpr float kDiamond = 6.0; // Collision diamond used in the estimation of the TOF event time + static constexpr float kErrDiamond = kDiamond * 33.356409f; + static constexpr float kWeightDiamond = 1.f / (kErrDiamond * kErrDiamond); bool enableTable = false; - // Detector response and input parameters - o2::pid::tof::TOFResoParamsV2 mRespParamsV2; - Service ccdb; - Configurable inheritFromBaseTask{"inheritFromBaseTask", true, "Flag to iherit all common configurables from the TOF base task"}; + Configurable fastTOFPID{"fastTOFPID", false, "Flag to enable computeEvTimeFast for evTimeMaker"}; - // CCDB configuration (inherited from TOF signal task) - Configurable url{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; - Configurable timestamp{"ccdb-timestamp", -1, "timestamp of the object"}; // Event time configurations Configurable minMomentum{"minMomentum", 0.5f, "Minimum momentum to select track sample for TOF event time"}; Configurable maxMomentum{"maxMomentum", 2.0f, "Maximum momentum to select track sample for TOF event time"}; Configurable maxEvTimeTOF{"maxEvTimeTOF", 100000.0f, "Maximum value of the TOF event time"}; Configurable sel8TOFEvTime{"sel8TOFEvTime", false, "Flag to compute the ev. time only for events that pass the sel8 ev. selection"}; + Configurable mComputeEvTimeWithTOF{"computeEvTimeWithTOF", -1, "Compute ev. time with TOF. -1 (autoset), 0 no, 1 yes"}; + Configurable mComputeEvTimeWithFT0{"computeEvTimeWithFT0", -1, "Compute ev. time with FT0. -1 (autoset), 0 no, 1 yes"}; Configurable maxNtracksInSet{"maxNtracksInSet", 10, "Size of the set to consider for the TOF ev. time computation"}; - // TOF Calib configuration - Configurable paramFileName{"paramFileName", "", "Path to the parametrization object. If empty the parametrization is not taken from file"}; - Configurable parametrizationPath{"parametrizationPath", "TOF/Calib/Params", "Path of the TOF parametrization on the CCDB or in the file, if the paramFileName is not empty"}; - Configurable passName{"passName", "", "Name of the pass inside of the CCDB parameter collection. If empty, the automatically deceted from metadata (to be implemented!!!)"}; - Configurable loadResponseFromCCDB{"loadResponseFromCCDB", false, "Flag to load the response from the CCDB"}; - Configurable enableTimeDependentResponse{"enableTimeDependentResponse", false, "Flag to use the collision timestamp to fetch the PID Response"}; - Configurable fatalOnPassNotAvailable{"fatalOnPassNotAvailable", true, "Flag to throw a fatal if the pass is not available in the retrieved CCDB object"}; + + // TOF response and input parameters + o2::pid::tof::TOFResoParamsV3 mRespParamsV3; + Service ccdb; + o2::aod::pidtofgeneric::TOFCalibConfig mTOFCalibConfig; // TOF Calib configuration void init(o2::framework::InitContext& initContext) { - if (inheritFromBaseTask.value) { - if (!getTaskOptionValue(initContext, "tof-signal", "ccdb-url", url.value, true)) { - LOG(fatal) << "Could not get ccdb-url from tof-signal task"; - } - if (!getTaskOptionValue(initContext, "tof-signal", "ccdb-timestamp", timestamp.value, true)) { - LOG(fatal) << "Could not get ccdb-timestamp from tof-signal task"; - } - } - - trackSampleMinMomentum = minMomentum; - trackSampleMaxMomentum = maxMomentum; - LOG(info) << "Configuring track sample for TOF ev. time: " << trackSampleMinMomentum << " < p < " << trackSampleMaxMomentum; - // Check that both processes are not enabled - int nEnabled = 0; - if (doprocessNoFT0 == true) { - LOGF(info, "Enabling process function: processNoFT0"); - nEnabled++; - } - if (doprocessFT0 == true) { - LOGF(info, "Enabling process function: processFT0"); - nEnabled++; - } - if (doprocessOnlyFT0 == true) { - LOGF(info, "Enabling process function: processOnlyFT0"); - nEnabled++; - } - if (nEnabled > 1) { - LOGF(fatal, "Cannot enable more process functions at the same time. Please choose one."); - } + mTOFCalibConfig.metadataInfo = metadataInfo; + mTOFCalibConfig.inheritFromBaseTask(initContext); // Checking that the table is requested in the workflow and enabling it enableTable = isTableRequiredInWorkflow(initContext, "EvTimeTOFFT0") || isTableRequiredInWorkflow(initContext, "EvTimeTOFFT0ForTrack"); if (!enableTable) { LOG(info) << "Table for global Event time is not required, disabling it"; - return; + // return; //TODO: uncomment this line } + enableTable = true; // Force enabling the table for now LOG(info) << "Table EvTimeTOFFT0 enabled!"; - if (sel8TOFEvTime.value == true) { - LOG(info) << "TOF event time will be computed for collisions that pass the event selection only!"; - } - // Getting the parametrization parameters - ccdb->setURL(url.value); - ccdb->setTimestamp(timestamp.value); - 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()); - // - - // TODO: implement the automatic pass name detection from metadata - if (passName.value == "") { - passName.value = "unanchored"; // temporary default - LOG(warning) << "Passed autodetect mode for pass, not implemented yet, waiting for metadata. Taking '" << passName.value << "'"; - } - LOG(info) << "Using parameter collection, starting from pass '" << passName.value << "'"; - - const std::string fname = paramFileName.value; - if (!fname.empty()) { // Loading the parametrization from file - LOG(info) << "Loading exp. sigma parametrization from file " << fname << ", using param: " << parametrizationPath.value; - if (1) { - o2::tof::ParameterCollection paramCollection; - paramCollection.loadParamFromFile(fname, parametrizationPath.value); - LOG(info) << "+++ Loaded parameter collection from file +++"; - if (!paramCollection.retrieveParameters(mRespParamsV2, passName.value)) { - if (fatalOnPassNotAvailable) { - LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", passName.value.data()); - } else { - LOGF(warning, "Pass '%s' not available in the retrieved CCDB object", passName.value.data()); - } - } else { - mRespParamsV2.setShiftParameters(paramCollection.getPars(passName.value)); - mRespParamsV2.printShiftParameters(); - } - } else { - mRespParamsV2.loadParamFromFile(fname.data(), parametrizationPath.value); - } - } else if (loadResponseFromCCDB) { // Loading it from CCDB - LOG(info) << "Loading exp. sigma parametrization from CCDB, using path: " << parametrizationPath.value << " for timestamp " << timestamp.value; - - o2::tof::ParameterCollection* paramCollection = ccdb->getForTimeStamp(parametrizationPath.value, timestamp.value); - paramCollection->print(); - if (!paramCollection->retrieveParameters(mRespParamsV2, passName.value)) { - if (fatalOnPassNotAvailable) { - LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", passName.value.data()); - } else { - LOGF(warning, "Pass '%s' not available in the retrieved CCDB object", passName.value.data()); + if (mTOFCalibConfig.autoSetProcessFunctions()) { + LOG(info) << "Autodetecting process functions"; + if (metadataInfo.isFullyDefined()) { + if (metadataInfo.isRun3()) { + doprocessRun3.value = true; } - } else { - mRespParamsV2.setShiftParameters(paramCollection->getPars(passName.value)); - mRespParamsV2.printShiftParameters(); } } - mRespParamsV2.print(); - o2::tof::eventTimeContainer::setMaxNtracksInSet(maxNtracksInSet.value); - o2::tof::eventTimeContainer::printConfig(); - } - /// - /// Process function to prepare the event time on Run 3 data without the FT0 - using TrksEvTime = soa::Join; - // Define slice per collision - Preslice perCollision = aod::track::collisionId; - template - using ResponseImplementationEvTime = o2::pid::tof::ExpTimes; - using EvTimeCollisions = soa::Join; - void processNoFT0(TrksEvTime& tracks, - EvTimeCollisions const& collisions) - { - if (!enableTable) { - return; - } - tableEvTime.reserve(collisions.size()); - tableEvTimeForTrack.reserve(tracks.size()); - - // for tracks not assigned to a collision - for (auto track : tracks) { - if (!track.has_collision()) { - tableEvTimeForTrack(0.f, 999.f); + if (metadataInfo.isFullyDefined()) { + if (!metadataInfo.isRun3()) { + LOG(fatal) << "Run3 process not supported in pidTOFGeneric task"; } } - for (auto const& collision : collisions) { // Loop on collisions - const auto& tracksInCollision = tracks.sliceBy(perCollision, collision.globalIndex()); - if ((sel8TOFEvTime.value == true) && !collision.sel8()) { - tableEvTime(0.f, 999.f, 0.f, 999.f, 0.f, 999.f); - for (int i = 0; i < tracksInCollision.size(); i++) { - tableEvTimeForTrack(0.f, 999.f); - } - continue; - } - - // First make table for event time - const auto evTimeTOF = evTimeMakerForTracks(tracksInCollision, mRespParamsV2, diamond, fastTOFPID); - int nGoodTracksForTOF = 0; // count for ntrackIndex for removeBias() - float et = evTimeTOF.mEventTime; - float erret = evTimeTOF.mEventTimeError; + trackSampleMinMomentum = minMomentum; + trackSampleMaxMomentum = maxMomentum; + LOG(info) << "Configuring track sample for TOF ev. time: " << trackSampleMinMomentum << " < p < " << trackSampleMaxMomentum; - if (erret < errDiamond && (maxEvTimeTOF <= 0.f || abs(et) < maxEvTimeTOF)) { - } else { - et = 0.f; - erret = errDiamond; - } - tableEvTime(et, erret, et, erret, 0.f, 999.f); - for (auto const& track : tracksInCollision) { - evTimeTOF.removeBias(track, nGoodTracksForTOF, et, erret, 2); - if (erret < errDiamond && (maxEvTimeTOF <= 0.f || abs(et) < maxEvTimeTOF)) { - } else { - et = 0.f; - erret = errDiamond; - } - tableEvTimeForTrack(et, erret); - } + 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(); } - PROCESS_SWITCH(pidTOFGeneric, processNoFT0, "Process without FT0", false); + + void process(aod::BCs const&) {} /// - /// Process function to prepare the event for each track on Run 3 data with the FT0 + /// Process function to prepare the event for each track on Run 3 data without the FT0 + // Define slice per collision + using Run3Cols = aod::Collisions; + using EvTimeCollisions = soa::Join; using EvTimeCollisionsFT0 = soa::Join; - void processFT0(TrksEvTime& tracks, - aod::FT0s const&, - EvTimeCollisionsFT0 const& collisions) + using Run3Trks = o2::soa::Join; + using Run3TrksWtof = soa::Join; + Preslice perCollision = aod::track::collisionId; + template + using ResponseImplementationEvTime = o2::pid::tof::ExpTimes; + + void processRun3(Run3TrksWtof const& tracks, + aod::FT0s const&, + EvTimeCollisionsFT0 const& collisions, + aod::BCsWithTimestamps const& bcs) { if (!enableTable) { return; } + LOG(debug) << "Processing Run3 data for TOF event time"; + tableEvTime.reserve(collisions.size()); tableEvTimeForTrack.reserve(tracks.size()); - std::vector tEvTimeForTrack; - std::vector tEvTimeErrForTrack; - tEvTimeForTrack.resize(tracks.size()); - tEvTimeErrForTrack.resize(tracks.size()); - - // for tracks not assigned to a collision - for (auto track : tracks) { - if (!track.has_collision()) { - tEvTimeForTrack[track.globalIndex()] = 0.f; - tEvTimeErrForTrack[track.globalIndex()] = 999.f; + mTOFCalibConfig.processSetup(mRespParamsV3, ccdb, bcs.iteratorAt(0)); // Update the calibration parameters + + // Autoset the processing mode for the event time computation + if (mComputeEvTimeWithTOF == -1 || mComputeEvTimeWithFT0 == -1) { + switch (mTOFCalibConfig.collisionSystem()) { + case CollisionSystemType::kCollSyspp: // pp + mComputeEvTimeWithTOF.value = ((mComputeEvTimeWithTOF == -1) ? 0 : mComputeEvTimeWithTOF.value); + mComputeEvTimeWithFT0.value = ((mComputeEvTimeWithFT0 == -1) ? 1 : mComputeEvTimeWithFT0.value); + break; + case CollisionSystemType::kCollSysPbPb: // PbPb + mComputeEvTimeWithTOF.value = ((mComputeEvTimeWithTOF == -1) ? 1 : mComputeEvTimeWithTOF.value); + 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"; + break; } } + LOG(debug) << "Running on " << CollisionSystemType::getCollisionSystemName(mTOFCalibConfig.collisionSystem()) << " mComputeEvTimeWithTOF " << mComputeEvTimeWithTOF.value << " mComputeEvTimeWithFT0 " << mComputeEvTimeWithFT0.value; - for (auto const& collision : collisions) { // Loop on collisions - const auto& tracksInCollision = tracks.sliceBy(perCollision, collision.globalIndex()); - if ((sel8TOFEvTime.value == true) && !collision.sel8()) { - tableEvTime(0.f, 999.f, 0.f, 999.f, 0.f, 999.f); - for (auto track : tracksInCollision) { - tEvTimeForTrack[track.globalIndex()] = 0.f; - tEvTimeErrForTrack[track.globalIndex()] = 999.f; + if (mComputeEvTimeWithTOF == 1 && mComputeEvTimeWithFT0 == 1) { + int lastCollisionId = -1; // Last collision ID analysed + for (auto const& t : tracks) { // Loop on collisions + if (!t.has_collision() || ((sel8TOFEvTime.value == true) && !t.collision_as().sel8())) { // Track was not assigned, cannot compute event time or event did not pass the event selection + tableEvTimeForTrack(0.f, 999.f); + continue; } - continue; - } - - // Compute the TOF event time - const auto evTimeTOF = evTimeMakerForTracks(tracksInCollision, mRespParamsV2, diamond, fastTOFPID); - - float t0TOF[2] = {static_cast(evTimeTOF.mEventTime), static_cast(evTimeTOF.mEventTimeError)}; // Value and error of TOF - float t0AC[2] = {.0f, 999.f}; // Value and error of T0A or T0C or T0AC + if (t.collisionId() == lastCollisionId) { // Event time from this collision is already in the table + continue; + } + /// Create new table for the tracks in a collision + lastCollisionId = t.collisionId(); /// Cache last collision ID - float eventTime = 0.f; - float sumOfWeights = 0.f; - float weight = 0.f; + const auto& tracksInCollision = tracks.sliceBy(perCollision, lastCollisionId); + const auto& collision = t.collision_as(); - if (t0TOF[1] < errDiamond && (maxEvTimeTOF <= 0 || abs(t0TOF[0]) < maxEvTimeTOF)) { - weight = 1.f / (t0TOF[1] * t0TOF[1]); - eventTime += t0TOF[0] * weight; - sumOfWeights += weight; - } + // Compute the TOF event time + const auto evTimeMakerTOF = evTimeMakerForTracks(tracksInCollision, mRespParamsV3, kDiamond, fastTOFPID); - if (collision.has_foundFT0()) { // T0 measurement is available - // const auto& ft0 = collision.foundFT0(); - if (collision.t0ACValid()) { - t0AC[0] = collision.t0AC() * 1000.f; - t0AC[1] = collision.t0resolution() * 1000.f; - } + 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 - weight = 1.f / (t0AC[1] * t0AC[1]); - eventTime += t0AC[0] * weight; - sumOfWeights += weight; - } + int nGoodTracksForTOF = 0; + float eventTime = 0.f; + float sumOfWeights = 0.f; + float weight = 0.f; - if (sumOfWeights < weightDiamond) { // avoiding sumOfWeights = 0 or worse that diamond - eventTime = 0; - sumOfWeights = weightDiamond; - } - tableEvTime(eventTime / sumOfWeights, sqrt(1. / sumOfWeights), t0TOF[0], t0TOF[1], t0AC[0], t0AC[1]); - - int nGoodTracksForTOF = 0; // count for ntrackIndex for removeBias() - for (auto const& track : tracksInCollision) { - // Reset the event time - eventTime = 0.f; - sumOfWeights = 0.f; - weight = 0.f; - // Remove the bias on TOF ev. time - evTimeTOF.removeBias(track, nGoodTracksForTOF, t0TOF[0], t0TOF[1], 2); - if (t0TOF[1] < errDiamond && (maxEvTimeTOF <= 0 || abs(t0TOF[0]) < maxEvTimeTOF)) { + if (t0TOF[1] < kErrDiamond && (maxEvTimeTOF <= 0 || std::abs(t0TOF[0]) < maxEvTimeTOF)) { weight = 1.f / (t0TOF[1] * t0TOF[1]); eventTime += t0TOF[0] * weight; sumOfWeights += weight; } - // Add the contribution from FT0 if it is available, t0AC is already calculated - if (collision.has_foundFT0()) { + if (collision.has_foundFT0()) { // T0 measurement is available + // const auto& ft0 = collision.foundFT0(); + if (collision.t0ACValid()) { + t0AC[0] = collision.t0AC() * 1000.f; + t0AC[1] = collision.t0resolution() * 1000.f; + } + weight = 1.f / (t0AC[1] * t0AC[1]); eventTime += t0AC[0] * weight; sumOfWeights += weight; } - if (sumOfWeights < weightDiamond) { // avoiding sumOfWeights = 0 or worse that diamond - eventTime = 0; - sumOfWeights = weightDiamond; + tableEvTime(eventTime / sumOfWeights, std::sqrt(1. / sumOfWeights), t0TOF[0], t0TOF[1], t0AC[0], t0AC[1]); + + for (auto const& trk : tracksInCollision) { // Loop on Tracks + // Reset the event time + eventTime = 0.f; + sumOfWeights = 0.f; + weight = 0.f; + // Remove the bias on TOF ev. time + if constexpr (kRemoveTOFEvTimeBias) { + evTimeMakerTOF.removeBias(trk, nGoodTracksForTOF, t0TOF[0], t0TOF[1], 2); + } + if (t0TOF[1] < kErrDiamond && (maxEvTimeTOF <= 0 || std::abs(t0TOF[0]) < maxEvTimeTOF)) { + weight = 1.f / (t0TOF[1] * t0TOF[1]); + eventTime += t0TOF[0] * weight; + sumOfWeights += weight; + } + + if (collision.has_foundFT0()) { // T0 measurement is available + // const auto& ft0 = collision.foundFT0(); + if (collision.t0ACValid()) { + t0AC[0] = collision.t0AC() * 1000.f; + t0AC[1] = collision.t0resolution() * 1000.f; + } + + weight = 1.f / (t0AC[1] * t0AC[1]); + eventTime += t0AC[0] * weight; + sumOfWeights += weight; + } + + if (sumOfWeights < kWeightDiamond) { // avoiding sumOfWeights = 0 or worse that kDiamond + eventTime = 0; + sumOfWeights = kWeightDiamond; + } + tableEvTimeForTrack(eventTime / sumOfWeights, std::sqrt(1. / sumOfWeights)); } - tEvTimeForTrack[track.globalIndex()] = eventTime / sumOfWeights; - tEvTimeErrForTrack[track.globalIndex()] = sqrt(1. / sumOfWeights); } - } - for (int i = 0; i < tracks.size(); i++) { - tableEvTimeForTrack(tEvTimeForTrack[i], tEvTimeErrForTrack[i]); - } - } - PROCESS_SWITCH(pidTOFGeneric, processFT0, "Process with FT0", true); + } else if (mComputeEvTimeWithTOF == 1 && mComputeEvTimeWithFT0 == 0) { + int lastCollisionId = -1; // Last collision ID analysed + for (auto const& t : tracks) { // Loop on collisions + if (!t.has_collision() || ((sel8TOFEvTime.value == true) && !t.collision_as().sel8())) { // Track was not assigned, cannot compute event time or event did not pass the event selection + tableEvTimeForTrack(0.f, 999.f); + continue; + } + if (t.collisionId() == lastCollisionId) { // Event time from this collision is already in the table + continue; + } + /// Create new table for the tracks in a collision + lastCollisionId = t.collisionId(); /// Cache last collision ID - /// - /// Process function to prepare the event time on Run 3 data with only the FT0 - void processOnlyFT0(EvTimeCollisionsFT0 const& collisions, - TrksEvTime& tracks, - aod::FT0s const&) - { - if (!enableTable) { - return; - } - tableEvTime.reserve(collisions.size()); - tableEvTimeForTrack.reserve(tracks.size()); + const auto& tracksInCollision = tracks.sliceBy(perCollision, lastCollisionId); - // for tracks not assigned to a collision - for (auto track : tracks) { - if (!track.has_collision()) { - tableEvTimeForTrack(0.f, 999.f); - } - } + // First make table for event time + const auto evTimeMakerTOF = evTimeMakerForTracks(tracksInCollision, mRespParamsV3, kDiamond, fastTOFPID); + int nGoodTracksForTOF = 0; + float et = evTimeMakerTOF.mEventTime; + float erret = evTimeMakerTOF.mEventTimeError; - for (auto const& collision : collisions) { - const auto& tracksInCollision = tracks.sliceBy(perCollision, collision.globalIndex()); - if (collision.has_foundFT0()) { // T0 measurement is available - // const auto& ft0 = collision.foundFT0(); - if (collision.t0ACValid()) { - tableEvTime(collision.t0AC() * 1000.f, collision.t0resolution() * 1000.f, 0.f, 999.f, collision.t0AC() * 1000.f, collision.t0resolution() * 1000.f); - for (int i = 0; i < tracks.size(); i++) { - tableEvTimeForTrack(collision.t0AC() * 1000.f, collision.t0resolution() * 1000.f); + if (erret < kErrDiamond && (maxEvTimeTOF <= 0.f || std::abs(et) < maxEvTimeTOF)) { + } else { + et = 0.f; + erret = kErrDiamond; + } + tableEvTime(et, erret, et, erret, 0.f, 999.f); + + for (auto const& trk : tracksInCollision) { // Loop on Tracks + if constexpr (kRemoveTOFEvTimeBias) { + evTimeMakerTOF.removeBias(trk, nGoodTracksForTOF, et, erret, 2); + } + if (erret < kErrDiamond && (maxEvTimeTOF <= 0.f || std::abs(et) < maxEvTimeTOF)) { + } else { + et = 0.f; + erret = kErrDiamond; } - return; + tableEvTimeForTrack(et, erret); + } + } + } else if (mComputeEvTimeWithTOF == 0 && mComputeEvTimeWithFT0 == 1) { + for (const auto& track : tracks) { + if (!track.has_collision()) { + tableEvTimeForTrack(0.f, 999.f); } } - tableEvTime(0.f, 999.f, 0.f, 999.f, 0.f, 999.f); - for (int i = 0; i < tracksInCollision.size(); i++) { - tableEvTimeForTrack(0.f, 999.f); + + for (auto const& collision : collisions) { + const auto& tracksInCollision = tracks.sliceBy(perCollision, collision.globalIndex()); + if (collision.has_foundFT0()) { // T0 measurement is available + // const auto& ft0 = collision.foundFT0(); + if (collision.t0ACValid()) { + tableEvTime(collision.t0AC() * 1000.f, collision.t0resolution() * 1000.f, 0.f, 999.f, collision.t0AC() * 1000.f, collision.t0resolution() * 1000.f); + for (int i = 0; i < tracksInCollision.size(); i++) { + tableEvTimeForTrack(collision.t0AC() * 1000.f, collision.t0resolution() * 1000.f); + } + continue; + } + } + tableEvTime(0.f, 999.f, 0.f, 999.f, 0.f, 999.f); + for (int i = 0; i < tracksInCollision.size(); i++) { + tableEvTimeForTrack(0.f, 999.f); + } } + } else { + LOG(fatal) << "Invalid configuration for TOF event time computation"; } } - PROCESS_SWITCH(pidTOFGeneric, processOnlyFT0, "Process only with FT0", false); + PROCESS_SWITCH(pidTOFGeneric, processRun3, "Process the Run3 data", true); }; WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { + metadataInfo.initMetadata(cfgc); return WorkflowSpec{ adaptAnalysisTask(cfgc)}; } diff --git a/PWGLF/TableProducer/Nuspex/reduced3bodyCreator.cxx b/PWGLF/TableProducer/Nuspex/reduced3bodyCreator.cxx index 091f0b03580..e164dc2794c 100644 --- a/PWGLF/TableProducer/Nuspex/reduced3bodyCreator.cxx +++ b/PWGLF/TableProducer/Nuspex/reduced3bodyCreator.cxx @@ -16,8 +16,9 @@ #include "TableHelper.h" +#include "PWGLF/DataModel/LFPIDTOFGenericTables.h" #include "PWGLF/DataModel/Reduced3BodyTables.h" -#include "PWGLF/DataModel/pidTOFGeneric.h" +#include "PWGLF/Utils/pidTOFGeneric.h" #include "Common/Core/PID/PIDTOF.h" #include "Common/Core/RecoDecay.h" @@ -64,6 +65,8 @@ using namespace o2; using namespace o2::framework; using namespace o2::framework::expressions; +o2::common::core::MetadataHelper metadataInfo; + using FullTracksExtIU = soa::Join; using FullTracksExtPIDIU = soa::Join; @@ -112,14 +115,16 @@ struct reduced3bodyCreator { int mRunNumber; float mBz; - o2::pid::tof::TOFResoParamsV2 mRespParamsV2; + // TOF response and input parameters + o2::pid::tof::TOFResoParamsV3 mRespParamsV3; + o2::aod::pidtofgeneric::TOFCalibConfig mTOFCalibConfig; // TOF Calib configuration // tracked cluster size std::vector fTrackedClSizeVector; HistogramRegistry registry{"registry", {}}; - void init(InitContext&) + void init(InitContext& initContext) { mRunNumber = 0; zorroSummary.setObject(zorro.getZorroSummary()); @@ -130,6 +135,11 @@ struct reduced3bodyCreator { ccdb->setLocalObjectValidityChecking(); ccdb->setFatalWhenNull(false); + // TOF PID parameters initialization + mTOFCalibConfig.metadataInfo = metadataInfo; + mTOFCalibConfig.inheritFromBaseTask(initContext); + mTOFCalibConfig.initSetup(mRespParamsV3, ccdb); + fitter3body.setPropagateToPCA(true); fitter3body.setMaxR(200.); //->maxRIni3body fitter3body.setMinParamChange(1e-3); @@ -186,66 +196,8 @@ struct reduced3bodyCreator { KFParticle::SetField(mBz); #endif - // Initial TOF PID Paras, copied from PIDTOF.h - timestamp.value = bc.timestamp(); - ccdb->setTimestamp(timestamp.value); - // Not later than now objects - ccdb->setCreatedNotAfter(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()); - // TODO: implement the automatic pass name detection from metadata - if (passName.value == "") { - passName.value = "unanchored"; // temporary default - LOG(warning) << "Passed autodetect mode for pass, not implemented yet, waiting for metadata. Taking '" << passName.value << "'"; - } - LOG(info) << "Using parameter collection, starting from pass '" << passName.value << "'"; - - const std::string fname = paramFileName.value; - if (!fname.empty()) { // Loading the parametrization from file - LOG(info) << "Loading exp. sigma parametrization from file " << fname << ", using param: " << parametrizationPath.value; - if (1) { - o2::tof::ParameterCollection paramCollection; - paramCollection.loadParamFromFile(fname, parametrizationPath.value); - LOG(info) << "+++ Loaded parameter collection from file +++"; - if (!paramCollection.retrieveParameters(mRespParamsV2, passName.value)) { - if (fatalOnPassNotAvailable) { - LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", passName.value.data()); - } else { - LOGF(warning, "Pass '%s' not available in the retrieved CCDB object", passName.value.data()); - } - } else { - mRespParamsV2.setShiftParameters(paramCollection.getPars(passName.value)); - mRespParamsV2.printShiftParameters(); - } - } else { - mRespParamsV2.loadParamFromFile(fname.data(), parametrizationPath.value); - } - } else if (loadResponseFromCCDB) { // Loading it from CCDB - LOG(info) << "Loading exp. sigma parametrization from CCDB, using path: " << parametrizationPath.value << " for timestamp " << timestamp.value; - o2::tof::ParameterCollection* paramCollection = ccdb->getForTimeStamp(parametrizationPath.value, timestamp.value); - paramCollection->print(); - if (!paramCollection->retrieveParameters(mRespParamsV2, passName.value)) { // Attempt at loading the parameters with the pass defined - if (fatalOnPassNotAvailable) { - LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", passName.value.data()); - } else { - LOGF(warning, "Pass '%s' not available in the retrieved CCDB object", passName.value.data()); - } - } else { // Pass is available, load non standard parameters - mRespParamsV2.setShiftParameters(paramCollection->getPars(passName.value)); - mRespParamsV2.printShiftParameters(); - } - } - mRespParamsV2.print(); - if (timeShiftCCDBPath.value != "") { - if (timeShiftCCDBPath.value.find(".root") != std::string::npos) { - mRespParamsV2.setTimeShiftParameters(timeShiftCCDBPath.value, "gmean_Pos", true); - mRespParamsV2.setTimeShiftParameters(timeShiftCCDBPath.value, "gmean_Neg", false); - } else { - mRespParamsV2.setTimeShiftParameters(ccdb->getForTimeStamp(Form("%s/pos", timeShiftCCDBPath.value.c_str()), timestamp.value), true); - mRespParamsV2.setTimeShiftParameters(ccdb->getForTimeStamp(Form("%s/neg", timeShiftCCDBPath.value.c_str()), timestamp.value), false); - } - } - fitter3body.setBz(mBz); - bachelorTOFPID.SetParams(mRespParamsV2); + mTOFCalibConfig.processSetup(mRespParamsV3, ccdb, bc); } //------------------------------------------------------------------ @@ -388,7 +340,7 @@ struct reduced3bodyCreator { // TOF PID of bachelor must be calcualted here // ---------------------------------------------- auto originalcol = daughter2.template collision_as(); - double tofNSigmaBach = bachelorTOFPID.GetTOFNSigma(daughter2, originalcol, collision); + double tofNSigmaBach = bachelorTOFPID.GetTOFNSigma(mRespParamsV3, daughter2, originalcol, collision); // ---------------------------------------------- // -------- save reduced track table with decay3body daughters ---------- @@ -469,6 +421,7 @@ struct reduced3bodyInitializer { WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { + metadataInfo.initMetadata(cfgc); return WorkflowSpec{ adaptAnalysisTask(cfgc), adaptAnalysisTask(cfgc), diff --git a/PWGLF/TableProducer/Nuspex/trHeAnalysis.cxx b/PWGLF/TableProducer/Nuspex/trHeAnalysis.cxx index 3d3e2b61d2c..7fe17c42d4a 100644 --- a/PWGLF/TableProducer/Nuspex/trHeAnalysis.cxx +++ b/PWGLF/TableProducer/Nuspex/trHeAnalysis.cxx @@ -16,8 +16,11 @@ /// /// \author Matthias Herzer , Goethe University Frankfurt /// -#include -#include +#include "PWGLF/DataModel/LFNucleiTables.h" +#include "PWGLF/DataModel/LFPIDTOFGenericTables.h" +#include "PWGLF/DataModel/LFParticleIdentification.h" +#include "PWGLF/Utils/pidTOFGeneric.h" + #include "Common/CCDB/EventSelectionParams.h" #include "Common/Core/PID/TPCPIDResponse.h" #include "Common/Core/trackUtilities.h" @@ -26,18 +29,20 @@ #include "Common/DataModel/Multiplicity.h" #include "Common/DataModel/PIDResponse.h" #include "Common/DataModel/TrackSelectionTables.h" + #include "Framework/ASoAHelpers.h" #include "Framework/AnalysisDataModel.h" #include "Framework/AnalysisTask.h" #include "Framework/HistogramRegistry.h" #include "Framework/runDataProcessing.h" -#include "PWGLF/DataModel/LFNucleiTables.h" -#include "PWGLF/DataModel/LFParticleIdentification.h" #include "ReconstructionDataFormats/PID.h" #include "ReconstructionDataFormats/Track.h" -#include "PWGLF/DataModel/pidTOFGeneric.h" + #include +#include +#include + namespace o2::aod { namespace h3_data diff --git a/PWGLF/Utils/pidTOFGeneric.h b/PWGLF/Utils/pidTOFGeneric.h new file mode 100644 index 00000000000..3e7dfd58c23 --- /dev/null +++ b/PWGLF/Utils/pidTOFGeneric.h @@ -0,0 +1,496 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// +/// \file pidTOFGeneric.h +/// \brief Utilities to recalculate secondary tracks TOF PID +/// \author Yuanzhe Wang +/// + +#ifndef PWGLF_UTILS_PIDTOFGENERIC_H_ +#define PWGLF_UTILS_PIDTOFGENERIC_H_ +#include "CollisionTypeHelper.h" +#include "MetadataHelper.h" +#include "TableHelper.h" + +#include "Common/Core/PID/PIDTOF.h" + +#include "CommonDataFormat/InteractionRecord.h" + +#include +#include + +namespace o2::aod +{ + +namespace pidtofgeneric +{ + +// Configuration common to all tasks, copied from pidTOFMerge.cxx but add metadataInfo as a member variable +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; } + + o2::common::core::MetadataHelper metadataInfo; // additional member variable to store metadata information compared to pidTOFMerge.cxx + + 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; + 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; + bool mEnableTimeDependentResponse; + int mCollisionSystem; + bool mAutoSetProcessFunctions; +}; + +static constexpr float kCSPEED = TMath::C() * 1.0e2f * 1.0e-12f; // c in cm/ps + +template +class TofPidNewCollision +{ + public: + TofPidNewCollision() = default; + ~TofPidNewCollision() = default; + + o2::pid::tof::TOFResoParamsV3 mRespParamsV3; + o2::track::PID::ID pidType; + + template + using ResponseImplementation = o2::pid::tof::ExpTimes; + static constexpr auto responseEl = ResponseImplementation(); + static constexpr auto responseMu = ResponseImplementation(); + static constexpr auto responsePi = ResponseImplementation(); + static constexpr auto responseKa = ResponseImplementation(); + static constexpr auto responsePr = ResponseImplementation(); + static constexpr auto responseDe = ResponseImplementation(); + static constexpr auto responseTr = ResponseImplementation(); + static constexpr auto responseHe = ResponseImplementation(); + static constexpr auto responseAl = ResponseImplementation(); + + void SetParams(o2::pid::tof::TOFResoParamsV3 const& para) + { + mRespParamsV3.setParameters(para); + } + + void SetPidType(o2::track::PID::ID pidId) + { + pidType = pidId; + } + + template + float GetTOFNSigma(o2::track::PID::ID pidId, const ParamType& parameters, TTrack const& track, TCollision const& originalcol, TCollision const& correctedcol, bool EnableBCAO2D = true); + + template + float GetTOFNSigma(const ParamType& parameters, TTrack const& track, TCollision const& originalcol, TCollision const& correctedcol, bool EnableBCAO2D = true); + + template + float GetTOFNSigma(const ParamType& parameters, TTrack const& track); + template + float GetTOFNSigma(o2::track::PID::ID pidId, const ParamType& parameters, TTrack const& track); + + template + float CalculateTOFNSigma(o2::track::PID::ID pidId, const ParamType& parameters, TTrack const& track, double tofsignal, double evTime, double evTimeErr) + { + + float expSigma, tofNsigma = -999; + + switch (pidId) { + case 0: + expSigma = responseEl.GetExpectedSigma(parameters, track, tofsignal, evTimeErr); + tofNsigma = (tofsignal - evTime - responseEl.GetCorrectedExpectedSignal(parameters, track)) / expSigma; + break; + case 1: + expSigma = responseMu.GetExpectedSigma(parameters, track, tofsignal, evTimeErr); + tofNsigma = (tofsignal - evTime - responseMu.GetCorrectedExpectedSignal(parameters, track)) / expSigma; + break; + case 2: + expSigma = responsePi.GetExpectedSigma(parameters, track, tofsignal, evTimeErr); + tofNsigma = (tofsignal - evTime - responsePi.GetCorrectedExpectedSignal(parameters, track)) / expSigma; + break; + case 3: + expSigma = responseKa.GetExpectedSigma(parameters, track, tofsignal, evTimeErr); + tofNsigma = (tofsignal - evTime - responseKa.GetCorrectedExpectedSignal(parameters, track)) / expSigma; + break; + case 4: + expSigma = responsePr.GetExpectedSigma(parameters, track, tofsignal, evTimeErr); + tofNsigma = (tofsignal - evTime - responsePr.GetCorrectedExpectedSignal(parameters, track)) / expSigma; + break; + case 5: + expSigma = responseDe.GetExpectedSigma(parameters, track, tofsignal, evTimeErr); + tofNsigma = (tofsignal - evTime - responseDe.GetCorrectedExpectedSignal(parameters, track)) / expSigma; + break; + case 6: + expSigma = responseTr.GetExpectedSigma(parameters, track, tofsignal, evTimeErr); + tofNsigma = (tofsignal - evTime - responseTr.GetCorrectedExpectedSignal(parameters, track)) / expSigma; + break; + case 7: + expSigma = responseHe.GetExpectedSigma(parameters, track, tofsignal, evTimeErr); + tofNsigma = (tofsignal - evTime - responseHe.GetCorrectedExpectedSignal(parameters, track)) / expSigma; + break; + case 8: + expSigma = responseAl.GetExpectedSigma(parameters, track, tofsignal, evTimeErr); + tofNsigma = (tofsignal - evTime - responseAl.GetCorrectedExpectedSignal(parameters, track)) / expSigma; + break; + default: + LOG(fatal) << "Wrong particle ID in TofPidSecondary class"; + return -999; + } + + return tofNsigma; + } +}; + +template +template +float TofPidNewCollision::GetTOFNSigma(o2::track::PID::ID pidId, const ParamType& parameters, TTrack const& track, TCollision const& originalcol, TCollision const& correctedcol, bool EnableBCAO2D) +{ + + if (!track.has_collision() || !track.hasTOF()) { + return -999; + } + + float mMassHyp = o2::track::pid_constants::sMasses2Z[track.pidForTracking()]; + float expTime = track.length() * std::sqrt((mMassHyp * mMassHyp) + (track.tofExpMom() * track.tofExpMom())) / (kCSPEED * track.tofExpMom()); // L*E/(p*c) = L/v + + float evTime = correctedcol.evTime(); + float evTimeErr = correctedcol.evTimeErr(); + float tofsignal = track.trackTime() * 1000 + expTime; // in ps + + if (originalcol.globalIndex() == correctedcol.globalIndex()) { + evTime = track.evTimeForTrack(); + evTimeErr = track.evTimeErrForTrack(); + } else { + if (EnableBCAO2D) { + auto originalbc = originalcol.template bc_as(); + auto correctedbc = correctedcol.template bc_as(); + o2::InteractionRecord originalIR = o2::InteractionRecord::long2IR(originalbc.globalBC()); + o2::InteractionRecord correctedIR = o2::InteractionRecord::long2IR(correctedbc.globalBC()); + tofsignal += originalIR.differenceInBCNS(correctedIR) * 1000; + } else { + auto originalbc = originalcol.template foundBC_as(); + auto correctedbc = correctedcol.template foundBC_as(); + o2::InteractionRecord originalIR = o2::InteractionRecord::long2IR(originalbc.globalBC()); + o2::InteractionRecord correctedIR = o2::InteractionRecord::long2IR(correctedbc.globalBC()); + tofsignal += originalIR.differenceInBCNS(correctedIR) * 1000; + } + } + + float tofNsigma = CalculateTOFNSigma(pidId, parameters, track, tofsignal, evTime, evTimeErr); + return tofNsigma; +} + +template +template +float TofPidNewCollision::GetTOFNSigma(const ParamType& parameters, TTrack const& track, TCollision const& originalcol, TCollision const& correctedcol, bool EnableBCAO2D) +{ + return GetTOFNSigma(pidType, parameters, track, originalcol, correctedcol, EnableBCAO2D); +} + +template +template +float TofPidNewCollision::GetTOFNSigma(o2::track::PID::ID pidId, const ParamType& parameters, TTrack const& track) +{ + + if (!track.has_collision() || !track.hasTOF()) { + return -999; + } + + float mMassHyp = o2::track::pid_constants::sMasses2Z[track.pidForTracking()]; + float expTime = track.length() * std::sqrt((mMassHyp * mMassHyp) + (track.tofExpMom() * track.tofExpMom())) / (kCSPEED * track.tofExpMom()); // L*E/(p*c) = L/v + + float evTime = track.evTimeForTrack(); + float evTimeErr = track.evTimeErrForTrack(); + float tofsignal = track.trackTime() * 1000 + expTime; // in ps + + float tofNsigma = CalculateTOFNSigma(pidId, parameters, track, tofsignal, evTime, evTimeErr); + return tofNsigma; +} + +template +template +float TofPidNewCollision::GetTOFNSigma(const ParamType& parameters, TTrack const& track) +{ + return GetTOFNSigma(pidType, parameters, track); +} + +} // namespace pidtofgeneric +} // namespace o2::aod + +#endif // PWGLF_UTILS_PIDTOFGENERIC_H_