diff --git a/Common/Field/src/MagFieldFast.cxx b/Common/Field/src/MagFieldFast.cxx index 02ef9c153d189..9735d0c711fa3 100644 --- a/Common/Field/src/MagFieldFast.cxx +++ b/Common/Field/src/MagFieldFast.cxx @@ -16,12 +16,10 @@ #include "Field/MagFieldFast.h" #include -#ifndef GPUCA_GPUCODE_DEVICE #include #include #include using namespace std; -#endif using namespace o2::field; diff --git a/Common/MathUtils/include/MathUtils/detail/Bracket.h b/Common/MathUtils/include/MathUtils/detail/Bracket.h index 25d0dbd1d0a6e..2da6949c4a6f8 100644 --- a/Common/MathUtils/include/MathUtils/detail/Bracket.h +++ b/Common/MathUtils/include/MathUtils/detail/Bracket.h @@ -17,7 +17,7 @@ #define ALICEO2_BRACKET_H #include -#ifndef GPUCA_ALIGPUCODE +#ifndef GPUCA_GPUCODE_DEVICE #include #include #endif @@ -76,7 +76,7 @@ class Bracket Relation isOutside(T t, T tErr) const; Relation isOutside(T t) const; -#ifndef GPUCA_ALIGPUCODE +#ifndef GPUCA_GPUCODE_DEVICE std::string asString() const; #endif @@ -247,7 +247,7 @@ inline typename Bracket::Relation Bracket::isOutside(T t) const return t < mMin ? Below : (t > mMax ? Above : Inside); } -#ifndef GPUCA_ALIGPUCODE +#ifndef GPUCA_GPUCODE_DEVICE template std::string Bracket::asString() const { diff --git a/Common/Utils/src/DebugStreamer.cxx b/Common/Utils/src/DebugStreamer.cxx index 46ff9be83d415..3a5401ca9b382 100644 --- a/Common/Utils/src/DebugStreamer.cxx +++ b/Common/Utils/src/DebugStreamer.cxx @@ -10,18 +10,16 @@ // or submit itself to any jurisdiction. #include "CommonUtils/DebugStreamer.h" -#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) #include #include #include "TROOT.h" #include "TKey.h" #include #include "Framework/Logger.h" -#endif O2ParamImpl(o2::utils::ParameterDebugStreamer); -#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) && defined(DEBUG_STREAMER) +#if defined(DEBUG_STREAMER) o2::utils::DebugStreamer::DebugStreamer() { diff --git a/DataFormats/Detectors/TPC/include/DataFormatsTPC/CalibdEdxCorrection.h b/DataFormats/Detectors/TPC/include/DataFormatsTPC/CalibdEdxCorrection.h index 024d6189593e9..f5088959edcf8 100644 --- a/DataFormats/Detectors/TPC/include/DataFormatsTPC/CalibdEdxCorrection.h +++ b/DataFormats/Detectors/TPC/include/DataFormatsTPC/CalibdEdxCorrection.h @@ -42,14 +42,12 @@ class CalibdEdxCorrection static constexpr int FitSize = 288; ///< Number of fitted corrections static constexpr int ParamSize = 8; ///< Number of params per fit -#if !defined(GPUCA_ALIGPUCODE) +#if !defined(GPUCA_GPUCODE) CalibdEdxCorrection() { clear(); } CalibdEdxCorrection(std::string_view fileName) { loadFromFile(fileName); } -#else - CalibdEdxCorrection() = default; #endif ~CalibdEdxCorrection() = default; diff --git a/DataFormats/Detectors/TPC/include/DataFormatsTPC/Constants.h b/DataFormats/Detectors/TPC/include/DataFormatsTPC/Constants.h index 6f6201b7de8df..0ddf7281be866 100644 --- a/DataFormats/Detectors/TPC/include/DataFormatsTPC/Constants.h +++ b/DataFormats/Detectors/TPC/include/DataFormatsTPC/Constants.h @@ -28,7 +28,7 @@ namespace constants constexpr int MAXSECTOR = 36; // the number of global pad rows -#if defined(GPUCA_STANDALONE) && !defined(GPUCA_O2_LIB) && !defined(GPUCA_TPC_GEOMETRY_O2) +#if defined(GPUCA_STANDALONE) && defined(GPUCA_RUN2) constexpr int MAXGLOBALPADROW = 159; // Number of pad rows in Run 2, used for GPU TPC tests with Run 2 data #else constexpr int MAXGLOBALPADROW = 152; // Correct number of pad rows in Run 3 diff --git a/DataFormats/Detectors/TPC/src/CalibdEdxCorrection.cxx b/DataFormats/Detectors/TPC/src/CalibdEdxCorrection.cxx index 152feacb41937..635b0e0817d6e 100644 --- a/DataFormats/Detectors/TPC/src/CalibdEdxCorrection.cxx +++ b/DataFormats/Detectors/TPC/src/CalibdEdxCorrection.cxx @@ -14,6 +14,7 @@ #include #include +#ifndef GPUCA_STANDALONE // o2 includes #include "Framework/Logger.h" #include "DataFormatsTPC/Defs.h" @@ -21,6 +22,7 @@ // root includes #include "TFile.h" +#endif using namespace o2::tpc; @@ -37,6 +39,8 @@ void CalibdEdxCorrection::clear() mDims = -1; } +#ifndef GPUCA_STANDALONE + void CalibdEdxCorrection::writeToFile(std::string_view fileName, std::string_view objName) const { std::unique_ptr file(TFile::Open(fileName.data(), "recreate")); @@ -181,3 +185,5 @@ void CalibdEdxCorrection::setUnity() } mDims = 0; } + +#endif // GPUCA_STANDALONE diff --git a/DataFormats/Detectors/TRD/src/Tracklet64.cxx b/DataFormats/Detectors/TRD/src/Tracklet64.cxx index d7b63cae45354..0458dad92e678 100644 --- a/DataFormats/Detectors/TRD/src/Tracklet64.cxx +++ b/DataFormats/Detectors/TRD/src/Tracklet64.cxx @@ -25,7 +25,6 @@ void Tracklet64::print() const HelperMethods::getSector(getDetector()), HelperMethods::getStack(getDetector()), HelperMethods::getLayer(getDetector()), getROB(), getMCM(), getPadRow(), getPadCol(), getPosition(), getSlope(), getPID(), getQ0(), getQ1(), getQ2(), getFormat()); } -#ifndef GPUCA_GPUCODE_DEVICE void Tracklet64::printStream(std::ostream& stream) const { stream << "Tracklet64 : 0x" << std::hex << getTrackletWord(); @@ -50,7 +49,5 @@ bool operator<(const Tracklet64& lhs, const Tracklet64& rhs) (lhs.getDetector() == rhs.getDetector() && lhs.getROB() == rhs.getROB() && lhs.getMCM() == rhs.getMCM() && lhs.getPadRow() == rhs.getPadRow() && lhs.getPadCol() < rhs.getPadCol()); } -#endif // GPUCA_GPUCODE_DEVICE - } // namespace trd } // namespace o2 diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/PrimaryVertex.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/PrimaryVertex.h index 5343d26ec5ce5..62de31d335e80 100644 --- a/DataFormats/Reconstruction/include/ReconstructionDataFormats/PrimaryVertex.h +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/PrimaryVertex.h @@ -42,7 +42,7 @@ class PrimaryVertex : public Vertex> float getZMAD() const { return mZMAD; } void setZMAD(float v) { mZMAD = v; } -#ifndef GPUCA_ALIGPUCODE +#ifndef GPUCA_GPUCODE_DEVICE void print() const; std::string asString() const; #endif @@ -56,7 +56,7 @@ class PrimaryVertex : public Vertex> ClassDefNV(PrimaryVertex, 2); }; -#ifndef GPUCA_ALIGPUCODE +#ifndef GPUCA_GPUCODE_DEVICE std::ostream& operator<<(std::ostream& os, const o2::dataformats::PrimaryVertex& v); #endif diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/PrimaryVertexExt.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/PrimaryVertexExt.h index bf47ed03f3b39..a228984f2ae5d 100644 --- a/DataFormats/Reconstruction/include/ReconstructionDataFormats/PrimaryVertexExt.h +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/PrimaryVertexExt.h @@ -36,7 +36,7 @@ struct PrimaryVertexExt : public PrimaryVertex { int getNSrcA(int i) const { return nSrcA[i]; } int getNSrcAU(int i) const { return nSrcAU[i]; } -#ifndef GPUCA_ALIGPUCODE +#ifndef GPUCA_GPUCODE_DEVICE void print() const; std::string asString() const; #endif @@ -44,7 +44,7 @@ struct PrimaryVertexExt : public PrimaryVertex { ClassDefNV(PrimaryVertexExt, 6); }; -#ifndef GPUCA_ALIGPUCODE +#ifndef GPUCA_GPUCODE_DEVICE std::ostream& operator<<(std::ostream& os, const o2::dataformats::PrimaryVertexExt& v); #endif diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h index 7f7e1e33144b1..436dc42cff749 100644 --- a/DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h @@ -83,7 +83,7 @@ class TrackParametrizationWithError : public TrackParametrization GPUd() void print() const; GPUd() void printHexadecimal(); -#ifndef GPUCA_ALIGPUCODE +#ifndef GPUCA_GPUCODE_DEVICE bool toFwdTrackParCov(TrackParCovFwd& t) const; std::string asString() const; std::string asStringHexadecimal(); diff --git a/DataFormats/Reconstruction/src/DCA.cxx b/DataFormats/Reconstruction/src/DCA.cxx index 9bb324c8df3a9..dd7c959add253 100644 --- a/DataFormats/Reconstruction/src/DCA.cxx +++ b/DataFormats/Reconstruction/src/DCA.cxx @@ -20,20 +20,16 @@ namespace o2 namespace dataformats { -#ifndef GPUCA_GPUCODE_DEVICE std::ostream& operator<<(std::ostream& os, const o2::dataformats::DCA& d) { // stream itself os << "DCA YZ {" << d.getY() << ", " << d.getZ() << "} Cov {" << d.getSigmaY2() << ", " << d.getSigmaYZ() << ", " << d.getSigmaZ2() << "}"; return os; } -#endif void DCA::print() const { -#ifndef GPUCA_GPUCODE_DEVICE std::cout << *this << '\n'; -#endif } } // namespace dataformats diff --git a/DataFormats/Reconstruction/src/PrimaryVertex.cxx b/DataFormats/Reconstruction/src/PrimaryVertex.cxx index f1b1a8ff01181..f6f589fcb038a 100644 --- a/DataFormats/Reconstruction/src/PrimaryVertex.cxx +++ b/DataFormats/Reconstruction/src/PrimaryVertex.cxx @@ -19,8 +19,6 @@ namespace o2 namespace dataformats { -#ifndef GPUCA_ALIGPUCODE - std::string PrimaryVertex::asString() const { auto str = o2::utils::Str::concat_string(VertexBase::asString(), @@ -44,7 +42,5 @@ void PrimaryVertex::print() const std::cout << *this << std::endl; } -#endif - } // namespace dataformats } // namespace o2 diff --git a/DataFormats/Reconstruction/src/PrimaryVertexExt.cxx b/DataFormats/Reconstruction/src/PrimaryVertexExt.cxx index 6065f04a3bc1a..31f0eff191591 100644 --- a/DataFormats/Reconstruction/src/PrimaryVertexExt.cxx +++ b/DataFormats/Reconstruction/src/PrimaryVertexExt.cxx @@ -18,8 +18,6 @@ namespace o2 { namespace dataformats { - -#ifndef GPUCA_ALIGPUCODE using GTrackID = o2::dataformats::GlobalTrackID; std::string PrimaryVertexExt::asString() const @@ -45,7 +43,5 @@ void PrimaryVertexExt::print() const std::cout << *this << std::endl; } -#endif - } // namespace dataformats } // namespace o2 diff --git a/DataFormats/Reconstruction/src/Vertex.cxx b/DataFormats/Reconstruction/src/Vertex.cxx index 85145683ddd97..9294aeb655803 100644 --- a/DataFormats/Reconstruction/src/Vertex.cxx +++ b/DataFormats/Reconstruction/src/Vertex.cxx @@ -20,8 +20,6 @@ namespace o2 namespace dataformats { -#ifndef GPUCA_GPUCODE_DEVICE -#ifndef GPUCA_NO_FMT std::string VertexBase::asString() const { return fmt::format("Vtx {{{:+.4e},{:+.4e},{:+.4e}}} Cov.:{{{{{:.3e}..}},{{{:.3e},{:.3e}..}},{{{:.3e},{:.3e},{:.3e}}}}}", @@ -39,7 +37,6 @@ void VertexBase::print() const { std::cout << *this << std::endl; } -#endif bool VertexBase::operator==(const VertexBase& other) const { @@ -54,8 +51,6 @@ bool VertexBase::operator==(const VertexBase& other) const return true; } -#endif - template class o2::dataformats::Vertex>; template class o2::dataformats::Vertex>; diff --git a/DataFormats/common/include/CommonDataFormat/InteractionRecord.h b/DataFormats/common/include/CommonDataFormat/InteractionRecord.h index e99f338a16343..c22b24ad03aac 100644 --- a/DataFormats/common/include/CommonDataFormat/InteractionRecord.h +++ b/DataFormats/common/include/CommonDataFormat/InteractionRecord.h @@ -15,7 +15,7 @@ #define ALICEO2_INTERACTIONRECORD_H #include "GPUCommonRtypes.h" -#ifndef GPUCA_ALIGPUCODE +#ifndef GPUCA_GPUCODE_DEVICE #include #include #endif diff --git a/DataFormats/common/src/InteractionRecord.cxx b/DataFormats/common/src/InteractionRecord.cxx index f15c8c8e85328..213ed600e1c57 100644 --- a/DataFormats/common/src/InteractionRecord.cxx +++ b/DataFormats/common/src/InteractionRecord.cxx @@ -15,8 +15,6 @@ namespace o2 { -#ifndef GPUCA_ALIGPUCODE - std::string InteractionRecord::asString() const { return isDummy() ? std::string{"NotSet"} : fmt::format("BCid: {:4d} Orbit: {:6d}", bc, orbit); @@ -49,6 +47,4 @@ void InteractionTimeRecord::print() const std::cout << (*this) << std::endl; } -#endif - } // namespace o2 diff --git a/Detectors/Align/Workflow/include/AlignmentWorkflow/BarrelAlignmentSpec.h b/Detectors/Align/Workflow/include/AlignmentWorkflow/BarrelAlignmentSpec.h index 197ace2bd9d20..9793b8609874f 100644 --- a/Detectors/Align/Workflow/include/AlignmentWorkflow/BarrelAlignmentSpec.h +++ b/Detectors/Align/Workflow/include/AlignmentWorkflow/BarrelAlignmentSpec.h @@ -21,17 +21,13 @@ using namespace o2::framework; namespace o2 { -namespace tpc -{ -struct CorrectionMapsLoaderGloOpts; -} namespace align { /// create a processor spec framework::DataProcessorSpec getBarrelAlignmentSpec(o2::dataformats::GlobalTrackID::mask_t srcMP, o2::dataformats::GlobalTrackID::mask_t src, - o2::detectors::DetID::mask_t dets, o2::detectors::DetID::mask_t skipDetClusters, bool enableCosmic, int postproc, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts); + o2::detectors::DetID::mask_t dets, o2::detectors::DetID::mask_t skipDetClusters, bool enableCosmic, int postproc, bool useMC); } // namespace align } // namespace o2 diff --git a/Detectors/Align/Workflow/src/BarrelAlignmentSpec.cxx b/Detectors/Align/Workflow/src/BarrelAlignmentSpec.cxx index d4ab53c8181ce..84674e69529fb 100644 --- a/Detectors/Align/Workflow/src/BarrelAlignmentSpec.cxx +++ b/Detectors/Align/Workflow/src/BarrelAlignmentSpec.cxx @@ -36,7 +36,7 @@ #include "TRDBase/TrackletTransformer.h" #include "CommonUtils/TreeStreamRedirector.h" #include "TPCCalibration/VDriftHelper.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCFastTransformPOD.h" #include "GPUO2ExternalUser.h" #include "GPUO2InterfaceUtils.h" #include "GPUParam.h" @@ -86,14 +86,9 @@ class BarrelAlignmentSpec : public Task CheckConstaints = 0x1 << 1, GenPedeFiles = 0x1 << 2, LabelPedeResults = 0x1 << 3 }; - BarrelAlignmentSpec(GTrackID::mask_t srcMP, std::shared_ptr dr, std::shared_ptr ggrec, const o2::tpc::CorrectionMapsLoaderGloOpts& tpcOpt, + BarrelAlignmentSpec(GTrackID::mask_t srcMP, std::shared_ptr dr, std::shared_ptr ggrec, DetID::mask_t detmask, bool cosmic, int postprocess, bool useMC, bool loadTPCCalib) - : mDataRequest(dr), mGRPGeomRequest(ggrec), mMPsrc{srcMP}, mDetMask{detmask}, mCosmic(cosmic), mPostProcessing(postprocess), mUseMC(useMC), mLoadTPCCalib(loadTPCCalib) - { - mTPCCorrMapsLoader.setLumiScaleType(tpcOpt.lumiType); - mTPCCorrMapsLoader.setLumiScaleMode(tpcOpt.lumiMode); - mTPCCorrMapsLoader.setCheckCTPIDCConsistency(tpcOpt.checkCTPIDCconsistency); - } + : mDataRequest(dr), mGRPGeomRequest(ggrec), mMPsrc{srcMP}, mDetMask{detmask}, mCosmic(cosmic), mPostProcessing(postprocess), mUseMC(useMC), mLoadTPCCalib(loadTPCCalib) {} ~BarrelAlignmentSpec() override = default; void init(InitContext& ic) final; void run(ProcessingContext& pc) final; @@ -122,7 +117,9 @@ class BarrelAlignmentSpec : public Task std::unique_ptr mTPCParam; o2::tpc::VDriftHelper mTPCVDriftHelper{}; - o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{}; + + o2::gpu::aligned_unique_buffer_ptr mCorrMapBuffer; // buffer to hold the raw map data from CCDB, needed to keep the pointer valid in the CorrectionMapsHelper + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps{}; // TStopwatch mTimer; @@ -184,9 +181,6 @@ void BarrelAlignmentSpec::init(InitContext& ic) } mIgnoreCCDBAlignment = ic.options().get("ignore-ccdb-alignment"); if (!mPostProcessing) { - if (mLoadTPCCalib) { - mTPCCorrMapsLoader.init(ic); - } if (GTrackID::includesDet(DetID::TRD, mMPsrc)) { mTRDTransformer.reset(new o2::trd::TrackletTransformer); if (ic.options().get("apply-xor")) { @@ -272,13 +266,10 @@ void BarrelAlignmentSpec::updateTimeDependentParams(ProcessingContext& pc) } mTPCVDriftHelper.extractCCDBInputs(pc); - mTPCCorrMapsLoader.extractCCDBInputs(pc); - bool updateMaps = false; - if (mTPCCorrMapsLoader.isUpdated()) { - mTPCCorrMapsLoader.acknowledgeUpdate(); - updateMaps = true; - } - mController->setTPCCorrMaps(&mTPCCorrMapsLoader); + + auto const& raw = pc.inputs().get("corrMap"); + mTPCCorrMaps = &o2::gpu::TPCFastTransformPOD::get(raw); + mController->setTPCCorrMaps(mTPCCorrMaps); if (mTPCVDriftHelper.isUpdated()) { LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}", mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, @@ -286,10 +277,6 @@ void BarrelAlignmentSpec::updateTimeDependentParams(ProcessingContext& pc) mTPCVDriftHelper.getSourceName()); mController->setTPCVDrift(mTPCVDriftHelper.getVDriftObject()); mTPCVDriftHelper.acknowledgeUpdate(); - updateMaps = true; - } - if (updateMaps) { - mTPCCorrMapsLoader.updateVDrift(mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().getTimeOffset()); } } } @@ -314,9 +301,6 @@ void BarrelAlignmentSpec::finaliseCCDB(o2::framework::ConcreteDataMatcher& match return; } - if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) { - return; - } } void BarrelAlignmentSpec::run(ProcessingContext& pc) @@ -374,7 +358,7 @@ void BarrelAlignmentSpec::endOfStream(EndOfStreamContext& ec) mDBGOut.reset(); } -DataProcessorSpec getBarrelAlignmentSpec(GTrackID::mask_t srcMP, GTrackID::mask_t src, DetID::mask_t dets, DetID::mask_t skipDetClusters, bool enableCosmic, int postprocess, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts) +DataProcessorSpec getBarrelAlignmentSpec(GTrackID::mask_t srcMP, GTrackID::mask_t src, DetID::mask_t dets, DetID::mask_t skipDetClusters, bool enableCosmic, int postprocess, bool useMC) { std::vector outputs; auto dataRequest = std::make_shared(); @@ -399,7 +383,7 @@ DataProcessorSpec getBarrelAlignmentSpec(GTrackID::mask_t srcMP, GTrackID::mask_ } if (src[DetID::TPC] && !skipDetClusters[DetID::TPC]) { o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs); - o2::tpc::CorrectionMapsLoader::requestCCDBInputs(dataRequest->inputs, opts, sclOpts); + dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe); loadTPCCalib = true; } } @@ -417,7 +401,7 @@ DataProcessorSpec getBarrelAlignmentSpec(GTrackID::mask_t srcMP, GTrackID::mask_ "barrel-alignment", dataRequest->inputs, outputs, - AlgorithmSpec{adaptFromTask(srcMP, dataRequest, ccdbRequest, sclOpts, dets, enableCosmic, postprocess, useMC, loadTPCCalib)}, + AlgorithmSpec{adaptFromTask(srcMP, dataRequest, ccdbRequest, dets, enableCosmic, postprocess, useMC, loadTPCCalib)}, opts}; } diff --git a/Detectors/Align/Workflow/src/barrel-alignment-workflow.cxx b/Detectors/Align/Workflow/src/barrel-alignment-workflow.cxx index 8df479ba39260..4d4bd33ff6b1f 100644 --- a/Detectors/Align/Workflow/src/barrel-alignment-workflow.cxx +++ b/Detectors/Align/Workflow/src/barrel-alignment-workflow.cxx @@ -20,13 +20,13 @@ #include "TPCReaderWorkflow/ClusterReaderSpec.h" #include "TPCWorkflow/ClusterSharingMapSpec.h" #include "TPCWorkflow/TPCScalerSpec.h" -#include "TPCCalibration/CorrectionMapsLoader.h" #include "TOFWorkflowIO/ClusterReaderSpec.h" #include "TOFWorkflowIO/TOFMatchedReaderSpec.h" #include "TOFWorkflowIO/ClusterReaderSpec.h" #include "ReconstructionDataFormats/GlobalTrackID.h" #include "DetectorsCommonDataFormats/DetID.h" #include "GlobalTrackingWorkflowReaders/TrackTPCITSReaderSpec.h" +#include "TPCCalibration/CorrectionMapsOptions.h" #include "Algorithm/RangeTokenizer.h" #include "DetectorsRaw/HBFUtilsInitializer.h" @@ -59,7 +59,7 @@ void customize(std::vector& workflowOptions) {"enable-cosmic", VariantType::Bool, false, {"enable cosmic tracks)"}}, {"postprocessing", VariantType::Int, 0, {"postprocessing bits: 1 - extract alignment objects, 2 - check constraints, 4 - print mpParams/Constraints, 8 - relabel pede results"}}, {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}}}; - o2::tpc::CorrectionMapsLoader::addGlobalOptions(options); + o2::tpc::CorrectionMapsOptions::addGlobalOptions(options); o2::raw::HBFUtilsInitializer::addConfigOption(options); std::swap(workflowOptions, options); } @@ -102,7 +102,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) if (dets[DetID::TPC]) { loadTPCClusters = loadTPCTracks = true; } - auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(configcontext.options()); + auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(configcontext.options()); if (!postprocess) { // this part is needed only if the data should be read if (GID::includesDet(DetID::ITS, src)) { src |= GID::getSourceMask(GID::ITS); @@ -148,11 +148,11 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) o2::conf::ConfigurableParam::writeINI("o2_barrel_alignment_configuration.ini"); } - if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get("disable-root-input")) { - specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection)); + if (!configcontext.options().get("disable-root-input")) { + specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == o2::tpc::LumiScaleType::TPCScaler, sclOpt.enableMShapeCorrection, sclOpt)); } - specs.emplace_back(o2::align::getBarrelAlignmentSpec(srcMP, src, dets, skipDetClusters, enableCosmic, postprocess, useMC, sclOpt)); + specs.emplace_back(o2::align::getBarrelAlignmentSpec(srcMP, src, dets, skipDetClusters, enableCosmic, postprocess, useMC)); // RS FIXME: check which clusters are really needed if (!postprocess) { GID::mask_t dummy; diff --git a/Detectors/Align/include/Align/Controller.h b/Detectors/Align/include/Align/Controller.h index 90abf2025d1c3..a9c4eac734535 100644 --- a/Detectors/Align/include/Align/Controller.h +++ b/Detectors/Align/include/Align/Controller.h @@ -30,7 +30,7 @@ #include "ReconstructionDataFormats/PrimaryVertex.h" #include "ReconstructionDataFormats/TrackCosmics.h" #include "DataFormatsTPC/VDriftCorrFact.h" -#include "CorrectionMapsHelper.h" +#include "TPCFastTransformPOD.h" #include "Align/Millepede2Record.h" #include "Align/ResidualsController.h" @@ -272,8 +272,8 @@ class Controller final : public TObject bool getAllowAfterburnerTracks() const { return mAllowAfterburnerTracks; } void setTPCVDrift(const o2::tpc::VDriftCorrFact& v); - void setTPCCorrMaps(o2::gpu::CorrectionMapsHelper* maph); - o2::gpu::CorrectionMapsHelper* getTPCCorrMaps() { return mTPCCorrMapsHelper; } + void setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD* maph); + const o2::gpu::TPCFastTransformPOD* getTPCCorrMaps() { return mTPCCorrMaps; } const o2::tpc::VDriftCorrFact& getTPCVDrift() const { return mTPCDrift; } int getInstanceID() const { return mInstanceID; } @@ -359,7 +359,7 @@ class Controller final : public TObject bool mUseRecoOCDB = true; // flag to preload reco-time calib objects o2::tpc::VDriftCorrFact mTPCDrift{}; - o2::gpu::CorrectionMapsHelper* mTPCCorrMapsHelper = nullptr; + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps = nullptr; // static const int sSkipLayers[kNLrSkip]; // detector layers for which we don't need module matrices diff --git a/Detectors/Align/src/Controller.cxx b/Detectors/Align/src/Controller.cxx index 5cfbbf9f3a4ae..5f55d07893d33 100644 --- a/Detectors/Align/src/Controller.cxx +++ b/Detectors/Align/src/Controller.cxx @@ -1882,9 +1882,9 @@ void Controller::setTPCVDrift(const o2::tpc::VDriftCorrFact& v) } //______________________________________________ -void Controller::setTPCCorrMaps(o2::gpu::CorrectionMapsHelper* maph) +void Controller::setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD* maph) { - mTPCCorrMapsHelper = maph; + mTPCCorrMaps = maph; } } // namespace align diff --git a/Detectors/Base/test/buildMatBudLUT.C b/Detectors/Base/test/buildMatBudLUT.C index 14f6d078aee90..860fcbd5da940 100644 --- a/Detectors/Base/test/buildMatBudLUT.C +++ b/Detectors/Base/test/buildMatBudLUT.C @@ -23,8 +23,6 @@ #include #endif -#ifndef GPUCA_ALIGPUCODE // this part is invisible on GPU version - o2::base::MatLayerCylSet mbLUT; bool testMBLUT(const std::string& lutFile = "matbud.root"); @@ -399,5 +397,3 @@ void configLayers() lrData.emplace_back(LrData(lrData.back().rMax, lrData.back().rMax + drStep, zSpanH, zBin, rphiBin)); } while (lrData.back().rMax < 500); } - -#endif //!_COMPILED_ON_GPU_ diff --git a/Detectors/Base/test/testMatBudLUT.cxx b/Detectors/Base/test/testMatBudLUT.cxx index 4daa992368dba..33c3498995c90 100644 --- a/Detectors/Base/test/testMatBudLUT.cxx +++ b/Detectors/Base/test/testMatBudLUT.cxx @@ -21,16 +21,12 @@ namespace o2 { BOOST_AUTO_TEST_CASE(MatBudLUT) { -#ifndef GPUCA_ALIGPUCODE // this part is unvisible on GPU version - // using process specific geometry names in order // to avoid race/conditions with other tests accessing geometry std::string geomPrefix("matBudGeom"); std::string matBudFile("matbud"); matBudFile += std::to_string(getpid()) + ".root"; BOOST_CHECK(buildMatBudLUT(2, 20, matBudFile, geomPrefix + std::to_string(getpid()), "align-geom.mDetectors=none")); // generate LUT - BOOST_CHECK(testMBLUT(matBudFile)); // test LUT manipulations - -#endif //!GPUCA_ALIGPUCODE + BOOST_CHECK(testMBLUT(matBudFile)); // test LUT manipulations } } // namespace o2 diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchCosmics.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchCosmics.h index 7720d75590475..9aad1a820d08b 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchCosmics.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchCosmics.h @@ -26,7 +26,6 @@ #include "SimulationDataFormat/MCCompLabel.h" #include "GlobalTracking/MatchCosmicsParams.h" #include "CommonUtils/TreeStreamRedirector.h" -#include "TPCFastTransform.h" #define _ALLOW_DEBUG_TREES_COSM // to allow debug and control tree output @@ -38,7 +37,7 @@ class VDriftCorrFact; } namespace gpu { -class CorrectionMapsHelper; +class TPCFastTransformPOD; } namespace globaltracking { @@ -85,7 +84,7 @@ class MatchCosmics GTrackID origID; ///< track origin id int matchID = MinusOne; ///< entry (none if MinusOne) of its match in the vector of matches }; - void setTPCCorrMaps(o2::gpu::CorrectionMapsHelper* maph); + void setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD* maph); void setTPCVDrift(const o2::tpc::VDriftCorrFact& v); void setITSROFrameLengthMUS(float fums) { mITSROFrameLengthMUS = fums; } void setITSDict(const o2::itsmft::TopologyDictionary* dict) { mITSDict = dict; } @@ -138,14 +137,14 @@ class MatchCosmics std::vector mRecords; std::vector mWinners; const o2::itsmft::TopologyDictionary* mITSDict = nullptr; // cluster patterns dictionary - o2::gpu::CorrectionMapsHelper* mTPCCorrMapsHelper = nullptr; + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps = nullptr; int mTFCount = 0; - float mTPCVDriftRef = -1.; ///< TPC nominal drift speed in cm/microseconds - float mTPCVDriftCorrFact = 1.; ///< TPC nominal correction factort (wrt ref) - float mTPCVDrift = -1.; ///< TPC drift speed in cm/microseconds + float mTPCVDriftRef = -1.; ///< TPC nominal drift speed in cm/microseconds + float mTPCVDriftCorrFact = 1.; ///< TPC nominal correction factort (wrt ref) + float mTPCVDrift = -1.; ///< TPC drift speed in cm/microseconds float mTPCDriftTimeOffset = 0.; ///< drift time offset in mus - float mTPCTBinMUS = 0.; ///< TPC time bin duration in microseconds - float mBz = 0; ///< nominal Bz + float mTPCTBinMUS = 0.; ///< TPC time bin duration in microseconds + float mBz = 0; ///< nominal Bz bool mFieldON = true; bool mUseMC = true; float mITSROFrameLengthMUS = 0.; diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchHMP.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchHMP.h index fbbadc1820ee8..308ba9e61f794 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchHMP.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchHMP.h @@ -41,7 +41,6 @@ #include "DataFormatsTPC/TrackTPC.h" #include "DataFormatsTRD/TrackTRD.h" #include "ReconstructionDataFormats/PID.h" -#include "TPCFastTransform.h" #include "CommonDataFormat/InteractionRecord.h" #include "ReconstructionDataFormats/MatchInfoHMP.h" #include "ReconstructionDataFormats/TrackHMP.h" diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index b66e5b143a898..8447fbc42cdce 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -37,9 +37,7 @@ #include "DataFormatsTPC/TrackTPC.h" #include "DataFormatsTRD/TrackTRD.h" #include "ReconstructionDataFormats/PID.h" -#include "TPCFastTransform.h" #include "CommonDataFormat/InteractionRecord.h" -#include "CorrectionMapsHelper.h" #include "GlobalTracking/MatchTOFParams.h" // from FIT @@ -152,7 +150,7 @@ class MatchTOF std::vector& getMatchedTOFLabelsVector(trkType index) { return mOutTOFLabels[index]; } ///< get vector of TOF labels of matched tracks void setTPCVDrift(const o2::tpc::VDriftCorrFact& v); - void setTPCCorrMaps(o2::gpu::CorrectionMapsHelper* maph); + void setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD* maph, float lumi); void setFIT(bool value = true) { mIsFIT = value; } static int findFITIndex(int bc, const gsl::span& FITRecPoints, unsigned long firstOrbit); @@ -292,7 +290,8 @@ class MatchTOF gsl::span mTPCRefitterOccMap; ///< externally set TPC clusters occupancy map const o2::tpc::ClusterNativeAccess* mTPCClusterIdxStruct = nullptr; ///< struct holding the TPC cluster indices - o2::gpu::CorrectionMapsHelper* mTPCCorrMapsHelper = nullptr; ///< TPC cluster transformation + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps = nullptr; ///< TPC cluster transformation + float mCTPLumi = {-1}; std::unique_ptr mTPCRefitter; ///< TPC refitter used for TPC tracks refit during the reconstruction const o2::dataformats::MCTruthContainer* mTOFClusLabels; ///< input TOF clusters MC labels (pointer to read from tree) diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTPCITS.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTPCITS.h index 00f2fc157a5ec..e736f0c9c8a42 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTPCITS.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTPCITS.h @@ -48,14 +48,13 @@ #include "DataFormatsTPC/ClusterNativeHelper.h" #include "DataFormatsTPC/VDriftCorrFact.h" #include "ITSReconstruction/RecoGeomHelper.h" -#include "TPCFastTransform.h" #include "GPUO2InterfaceRefit.h" #include "GPUTPCGeometry.h" #include "GlobalTracking/MatchTPCITSParams.h" #include "DataFormatsITSMFT/TopologyDictionary.h" #include "DataFormatsITSMFT/TrkClusRef.h" #include "ITSMFTReconstruction/ChipMappingITS.h" -#include "CorrectionMapsHelper.h" +#include "TPCFastTransformPOD.h" #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__ROOTCLING__) && !defined(__CLING__) #include "MemoryResources/MemoryResources.h" #endif @@ -434,7 +433,7 @@ class MatchTPCITS mVDriftCalibOn = v; } void setTPCVDrift(const o2::tpc::VDriftCorrFact& v); - void setTPCCorrMaps(o2::gpu::CorrectionMapsHelper* maph); + void setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD* maph, float lumi); ///< print settings void print() const; @@ -641,7 +640,8 @@ class MatchTPCITS float mMinITSTrackPtInv = 999.; ///< cutoff on ITS track inverse pT bool mVDriftCalibOn = false; ///< flag to produce VDrift calibration data o2::tpc::VDriftCorrFact mTPCDrift{}; - o2::gpu::CorrectionMapsHelper* mTPCCorrMapsHelper = nullptr; + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps = nullptr; + float mLumiCTP{-1}; std::unique_ptr mTPCRefitter; ///< TPC refitter used for TPC tracks refit during the reconstruction diff --git a/Detectors/GlobalTracking/src/MatchCosmics.cxx b/Detectors/GlobalTracking/src/MatchCosmics.cxx index 3c20ecad2f36c..615cfcb84819b 100644 --- a/Detectors/GlobalTracking/src/MatchCosmics.cxx +++ b/Detectors/GlobalTracking/src/MatchCosmics.cxx @@ -32,7 +32,7 @@ #include "CommonConstants/GeomConstants.h" #include "DataFormatsTPC/WorkflowHelper.h" #include "DataFormatsTPC/VDriftCorrFact.h" -#include "CorrectionMapsHelper.h" +#include "TPCFastTransformPOD.h" #include #include @@ -93,7 +93,7 @@ void MatchCosmics::refitWinners(const o2::globaltracking::RecoContainer& data) std::unique_ptr tpcRefitter; if (data.inputsTPCclusters) { tpcRefitter = std::make_unique(&data.inputsTPCclusters->clusterIndex, - mTPCCorrMapsHelper, mBz, + mTPCCorrMaps, mBz, tpcClusRefs.data(), 0, tpcClusShMap.data(), tpcClusOccMap.data(), tpcClusOccMap.size(), nullptr, o2::base::Propagator::Instance()); } @@ -597,9 +597,9 @@ void MatchCosmics::setTPCVDrift(const o2::tpc::VDriftCorrFact& v) } //______________________________________________ -void MatchCosmics::setTPCCorrMaps(o2::gpu::CorrectionMapsHelper* maph) +void MatchCosmics::setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD* maph) { - mTPCCorrMapsHelper = maph; + mTPCCorrMaps = maph; } #endif diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index 6a3486dd12044..5416a612ad1f3 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -255,9 +255,10 @@ void MatchTOF::setTPCVDrift(const o2::tpc::VDriftCorrFact& v) } //______________________________________________ -void MatchTOF::setTPCCorrMaps(o2::gpu::CorrectionMapsHelper* maph) +void MatchTOF::setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD* maph, float lumi) { - mTPCCorrMapsHelper = maph; + mTPCCorrMaps = maph; + mCTPLumi = lumi; } //______________________________________________ @@ -2085,8 +2086,9 @@ void MatchTOF::updateTimeDependentParams() mMaxInvPt = std::abs(mBz) > 0.1 ? 1. / (std::abs(mBz) * 0.05) : 999.; const auto& trackTune = TrackTuneParams::Instance(); - float scale = mTPCCorrMapsHelper->getInstLumiCTP(); + float scale = mCTPLumi; if (scale < 0.f) { + LOGP(warning, "Negative scale factor for TPC covariance correction, setting it to zero"); scale = 0.f; } mCovDiagInner = trackTune.getCovInnerTotal(scale); @@ -2166,7 +2168,7 @@ bool MatchTOF::makeConstrainedTPCTrack(int matchedID, o2::dataformats::TrackTPCT void MatchTOF::checkRefitter() { if (mTPCClusterIdxStruct) { - mTPCRefitter = std::make_unique(mTPCClusterIdxStruct, mTPCCorrMapsHelper, mBz, + mTPCRefitter = std::make_unique(mTPCClusterIdxStruct, mTPCCorrMaps, mBz, mTPCTrackClusIdx.data(), 0, mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), mTPCRefitterOccMap.size(), nullptr, o2::base::Propagator::Instance()); } diff --git a/Detectors/GlobalTracking/src/MatchTPCITS.cxx b/Detectors/GlobalTracking/src/MatchTPCITS.cxx index 73216c8ce1eac..29c45edd6eb96 100644 --- a/Detectors/GlobalTracking/src/MatchTPCITS.cxx +++ b/Detectors/GlobalTracking/src/MatchTPCITS.cxx @@ -205,9 +205,10 @@ void MatchTPCITS::setTPCVDrift(const o2::tpc::VDriftCorrFact& v) } //______________________________________________ -void MatchTPCITS::setTPCCorrMaps(o2::gpu::CorrectionMapsHelper* maph) +void MatchTPCITS::setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD* maph, float lumi) { - mTPCCorrMapsHelper = maph; + mTPCCorrMaps = maph; + mLumiCTP = lumi; } //______________________________________________ @@ -286,8 +287,9 @@ void MatchTPCITS::updateTimeDependentParams() mTPCmeanX0Inv = matbd.meanX2X0 / matbd.length; const auto& trackTune = TrackTuneParams::Instance(); - float scale = mTPCCorrMapsHelper->getInstLumiCTP(); + float scale = mLumiCTP; if (scale < 0.f) { + LOGP(warning, "Negative scale factor for TPC covariance correction, setting it to zero"); scale = 0.f; } mCovDiagInner = trackTune.getCovInnerTotal(scale); @@ -504,7 +506,7 @@ bool MatchTPCITS::prepareTPCData() mTPCSectIndexCache[sec].reserve(100 + 1.2 * ntrW / o2::constants::math::NSectors); } - mTPCRefitter = std::make_unique(mTPCClusterIdxStruct, mTPCCorrMapsHelper, mBz, mTPCTrackClusIdx.data(), 0, mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), mTPCRefitterOccMap.size(), nullptr, o2::base::Propagator::Instance()); + mTPCRefitter = std::make_unique(mTPCClusterIdxStruct, mTPCCorrMaps, mBz, mTPCTrackClusIdx.data(), 0, mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), mTPCRefitterOccMap.size(), nullptr, o2::base::Propagator::Instance()); mNTPCOccBinLength = mTPCRefitter->getParam()->rec.tpc.occupancyMapTimeBins; mTBinClOcc.clear(); if (mNTPCOccBinLength > 1 && mTPCRefitterOccMap.size()) { diff --git a/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/CosmicsMatchingSpec.h b/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/CosmicsMatchingSpec.h index e0e74c3058086..25553c5d56d33 100644 --- a/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/CosmicsMatchingSpec.h +++ b/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/CosmicsMatchingSpec.h @@ -20,16 +20,11 @@ using namespace o2::framework; namespace o2 { -namespace tpc -{ -struct CorrectionMapsLoaderGloOpts; -} - namespace globaltracking { /// create a processor spec -framework::DataProcessorSpec getCosmicsMatchingSpec(o2::dataformats::GlobalTrackID::mask_t src, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts); +framework::DataProcessorSpec getCosmicsMatchingSpec(o2::dataformats::GlobalTrackID::mask_t src, bool useMC); } // namespace globaltracking } // namespace o2 diff --git a/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/SecondaryVertexingSpec.h b/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/SecondaryVertexingSpec.h index b8071ae83d347..9211a9cb0c264 100644 --- a/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/SecondaryVertexingSpec.h +++ b/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/SecondaryVertexingSpec.h @@ -20,16 +20,12 @@ namespace o2 { -namespace tpc -{ -struct CorrectionMapsLoaderGloOpts; -} namespace vertexing { /// create a processor spec -o2::framework::DataProcessorSpec getSecondaryVertexingSpec(o2::dataformats::GlobalTrackID::mask_t src, bool enableCasc, bool enable3body, bool enableStrangenesTracking, bool enableCCDBParams, bool useMC, bool useGeom, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts); +o2::framework::DataProcessorSpec getSecondaryVertexingSpec(o2::dataformats::GlobalTrackID::mask_t src, bool enableCasc, bool enable3body, bool enableStrangenesTracking, bool enableCCDBParams, bool useMC, bool useGeom); } // namespace vertexing } // namespace o2 diff --git a/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/TOFMatcherSpec.h b/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/TOFMatcherSpec.h index 79a4ee0ce0360..a1102af6a1f75 100644 --- a/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/TOFMatcherSpec.h +++ b/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/TOFMatcherSpec.h @@ -21,15 +21,11 @@ using namespace o2::framework; namespace o2 { -namespace tpc -{ -struct CorrectionMapsLoaderGloOpts; -} namespace globaltracking { /// create a processor spec -framework::DataProcessorSpec getTOFMatcherSpec(o2::dataformats::GlobalTrackID::mask_t src, bool useMC, bool useFIT, bool tpcRefit, bool strict, float extratolerancetrd, bool pushMatchable, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, int nlanes = 1); +framework::DataProcessorSpec getTOFMatcherSpec(o2::dataformats::GlobalTrackID::mask_t src, bool useMC, bool useFIT, bool tpcRefit, bool strict, float extratolerancetrd, bool pushMatchable, bool requestCTPLumi, int nlanes = 1); } // namespace globaltracking } // namespace o2 diff --git a/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/TPCITSMatchingSpec.h b/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/TPCITSMatchingSpec.h index 4aaed7d64eec5..56240fd2c8f98 100644 --- a/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/TPCITSMatchingSpec.h +++ b/Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/TPCITSMatchingSpec.h @@ -20,14 +20,10 @@ using namespace o2::framework; namespace o2 { -namespace tpc -{ -struct CorrectionMapsLoaderGloOpts; -} namespace globaltracking { /// create a processor spec -framework::DataProcessorSpec getTPCITSMatchingSpec(o2::dataformats::GlobalTrackID::mask_t src, bool useFT0, bool calib, bool skipTPCOnly, bool useGeom, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts); +framework::DataProcessorSpec getTPCITSMatchingSpec(o2::dataformats::GlobalTrackID::mask_t src, bool useFT0, bool calib, bool skipTPCOnly, bool useGeom, bool useMC, bool requestCTPLumi); } // namespace globaltracking } // namespace o2 diff --git a/Detectors/GlobalTrackingWorkflow/src/CosmicsMatchingSpec.cxx b/Detectors/GlobalTrackingWorkflow/src/CosmicsMatchingSpec.cxx index 34c41ec234dc5..d99ab19be0bc3 100644 --- a/Detectors/GlobalTrackingWorkflow/src/CosmicsMatchingSpec.cxx +++ b/Detectors/GlobalTrackingWorkflow/src/CosmicsMatchingSpec.cxx @@ -47,7 +47,7 @@ #include "ITSMFTReconstruction/ClustererParam.h" #include "DetectorsBase/GRPGeomHelper.h" #include "TPCCalibration/VDriftHelper.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCFastTransformPOD.h" using namespace o2::framework; using MCLabelsTr = gsl::span; @@ -62,12 +62,7 @@ namespace globaltracking class CosmicsMatchingSpec : public Task { public: - CosmicsMatchingSpec(std::shared_ptr dr, std::shared_ptr gr, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, bool useMC) : mDataRequest(dr), mGGCCDBRequest(gr), mUseMC(useMC) - { - mTPCCorrMapsLoader.setLumiScaleType(sclOpts.lumiType); - mTPCCorrMapsLoader.setLumiScaleMode(sclOpts.lumiMode); - mTPCCorrMapsLoader.setCheckCTPIDCConsistency(sclOpts.checkCTPIDCconsistency); - } + CosmicsMatchingSpec(std::shared_ptr dr, std::shared_ptr gr, bool useMC) : mDataRequest(dr), mGGCCDBRequest(gr), mUseMC(useMC) {} ~CosmicsMatchingSpec() override = default; void init(InitContext& ic) final; void run(ProcessingContext& pc) final; @@ -79,7 +74,7 @@ class CosmicsMatchingSpec : public Task std::shared_ptr mDataRequest; std::shared_ptr mGGCCDBRequest; o2::tpc::VDriftHelper mTPCVDriftHelper{}; - o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{}; + const o2::gpu::TPCFastTransformPOD* mCorrMap{nullptr}; o2::globaltracking::MatchCosmics mMatching; // matching engine bool mUseMC = true; TStopwatch mTimer; @@ -92,7 +87,6 @@ void CosmicsMatchingSpec::init(InitContext& ic) o2::base::GRPGeomHelper::instance().setRequest(mGGCCDBRequest); mMatching.setDebugFlag(ic.options().get("debug-tree-flags")); mMatching.setUseMC(mUseMC); - mTPCCorrMapsLoader.init(ic); // } @@ -115,7 +109,8 @@ void CosmicsMatchingSpec::updateTimeDependentParams(ProcessingContext& pc) { o2::base::GRPGeomHelper::instance().checkUpdates(pc); mTPCVDriftHelper.extractCCDBInputs(pc); - mTPCCorrMapsLoader.extractCCDBInputs(pc); + auto const& raw = pc.inputs().get("corrMap"); + mCorrMap = &gpu::TPCFastTransformPOD::get(raw); static bool initOnceDone = false; if (!initOnceDone) { // this params need to be queried only once initOnceDone = true; @@ -132,12 +127,7 @@ void CosmicsMatchingSpec::updateTimeDependentParams(ProcessingContext& pc) } mMatching.init(); } - bool updateMaps = false; - if (mTPCCorrMapsLoader.isUpdated()) { - mTPCCorrMapsLoader.acknowledgeUpdate(); - updateMaps = true; - } - mMatching.setTPCCorrMaps(&mTPCCorrMapsLoader); + mMatching.setTPCCorrMaps(mCorrMap); if (mTPCVDriftHelper.isUpdated()) { LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}", mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, @@ -145,10 +135,6 @@ void CosmicsMatchingSpec::updateTimeDependentParams(ProcessingContext& pc) mTPCVDriftHelper.getSourceName()); mMatching.setTPCVDrift(mTPCVDriftHelper.getVDriftObject()); mTPCVDriftHelper.acknowledgeUpdate(); - updateMaps = true; - } - if (updateMaps) { - mTPCCorrMapsLoader.updateVDrift(mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().getTimeOffset()); } } @@ -160,9 +146,6 @@ void CosmicsMatchingSpec::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) { return; } - if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) { - return; - } if (matcher == ConcreteDataMatcher("ITS", "CLUSDICT", 0)) { LOG(info) << "cluster dictionary updated"; mMatching.setITSDict((const o2::itsmft::TopologyDictionary*)obj); @@ -177,7 +160,7 @@ void CosmicsMatchingSpec::endOfStream(EndOfStreamContext& ec) mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1); } -DataProcessorSpec getCosmicsMatchingSpec(GTrackID::mask_t src, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts) +DataProcessorSpec getCosmicsMatchingSpec(GTrackID::mask_t src, bool useMC) { std::vector outputs; Options opts{ @@ -203,13 +186,13 @@ DataProcessorSpec getCosmicsMatchingSpec(GTrackID::mask_t src, bool useMC, const dataRequest->inputs, true); o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs); - o2::tpc::CorrectionMapsLoader::requestCCDBInputs(dataRequest->inputs, opts, sclOpts); + dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe); return DataProcessorSpec{ "cosmics-matcher", dataRequest->inputs, outputs, - AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, sclOpts, useMC)}, + AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, useMC)}, opts}; } diff --git a/Detectors/GlobalTrackingWorkflow/src/SecondaryVertexingSpec.cxx b/Detectors/GlobalTrackingWorkflow/src/SecondaryVertexingSpec.cxx index 6dfd1cb770d7f..afce2861be2fb 100644 --- a/Detectors/GlobalTrackingWorkflow/src/SecondaryVertexingSpec.cxx +++ b/Detectors/GlobalTrackingWorkflow/src/SecondaryVertexingSpec.cxx @@ -31,10 +31,9 @@ #include "DetectorsBase/GlobalParams.h" #include "TStopwatch.h" #include "TPCCalibration/VDriftHelper.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCFastTransformPOD.h" #include "Framework/ConfigParamRegistry.h" #include "Framework/DeviceSpec.h" -#include "TPCCalibration/CorrectionMapsLoader.h" using namespace o2::framework; @@ -58,14 +57,7 @@ namespace o2d = o2::dataformats; class SecondaryVertexingSpec : public Task { public: - SecondaryVertexingSpec(std::shared_ptr dr, std::shared_ptr gr, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, GTrackID::mask_t src, bool enabCasc, bool enable3body, bool enableStrangenessTracking, bool enableCCDBParams, bool useMC) : mDataRequest(dr), mGGCCDBRequest(gr), mSrc(src), mEnableCascades(enabCasc), mEnable3BodyVertices(enable3body), mEnableStrangenessTracking(enableStrangenessTracking), mEnableCCDBParams(enableCCDBParams), mUseMC(useMC) - { - if (mSrc[GTrackID::TPC]) { - mTPCCorrMapsLoader.setLumiScaleType(sclOpts.lumiType); - mTPCCorrMapsLoader.setLumiScaleMode(sclOpts.lumiMode); - mTPCCorrMapsLoader.setCheckCTPIDCConsistency(sclOpts.checkCTPIDCconsistency); - } - } + SecondaryVertexingSpec(std::shared_ptr dr, std::shared_ptr gr, GTrackID::mask_t src, bool enabCasc, bool enable3body, bool enableStrangenessTracking, bool enableCCDBParams, bool useMC) : mDataRequest(dr), mGGCCDBRequest(gr), mSrc(src), mEnableCascades(enabCasc), mEnable3BodyVertices(enable3body), mEnableStrangenessTracking(enableStrangenessTracking), mEnableCCDBParams(enableCCDBParams), mUseMC(useMC) {} ~SecondaryVertexingSpec() override = default; void init(InitContext& ic) final; void run(ProcessingContext& pc) final; @@ -77,7 +69,7 @@ class SecondaryVertexingSpec : public Task std::shared_ptr mDataRequest; std::shared_ptr mGGCCDBRequest; o2::tpc::VDriftHelper mTPCVDriftHelper{}; - o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{}; + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps{nullptr}; GTrackID::mask_t mSrc{}; bool mEnableCCDBParams = false; bool mEnableCascades = false; @@ -107,9 +99,6 @@ void SecondaryVertexingSpec::init(InitContext& ic) mStrTracker.setMCTruthOn(mUseMC); mVertexer.setStrangenessTracker(&mStrTracker); } - if (mSrc[GTrackID::TPC]) { - mTPCCorrMapsLoader.init(ic); - } } void SecondaryVertexingSpec::run(ProcessingContext& pc) @@ -157,9 +146,6 @@ void SecondaryVertexingSpec::finaliseCCDB(ConcreteDataMatcher& matcher, void* ob if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) { return; } - if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) { - return; - } if (matcher == ConcreteDataMatcher("ITS", "CLUSDICT", 0)) { LOG(info) << "cluster dictionary updated"; mStrTracker.setClusterDictionaryITS((const o2::itsmft::TopologyDictionary*)obj); @@ -193,7 +179,8 @@ void SecondaryVertexingSpec::updateTimeDependentParams(ProcessingContext& pc) o2::base::GRPGeomHelper::instance().checkUpdates(pc); if (mSrc[GTrackID::TPC]) { mTPCVDriftHelper.extractCCDBInputs(pc); - mTPCCorrMapsLoader.extractCCDBInputs(pc); + auto const& raw = pc.inputs().get("corrMap"); + mTPCCorrMaps = &gpu::TPCFastTransformPOD::get(raw); } static bool initOnceDone = false; if (!initOnceDone) { // this params need to be queried only once @@ -223,12 +210,8 @@ void SecondaryVertexingSpec::updateTimeDependentParams(ProcessingContext& pc) } // we may have other params which need to be queried regularly if (mSrc[GTrackID::TPC]) { - bool updateMaps = false; - if (mTPCCorrMapsLoader.isUpdated()) { - mTPCCorrMapsLoader.acknowledgeUpdate(); - updateMaps = true; - } - mVertexer.setTPCCorrMaps(&mTPCCorrMapsLoader); + mVertexer.setTPCCorrMaps(mTPCCorrMaps); + if (mTPCVDriftHelper.isUpdated()) { LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}", mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, @@ -236,10 +219,6 @@ void SecondaryVertexingSpec::updateTimeDependentParams(ProcessingContext& pc) mTPCVDriftHelper.getSourceName()); mVertexer.setTPCVDrift(mTPCVDriftHelper.getVDriftObject()); mTPCVDriftHelper.acknowledgeUpdate(); - updateMaps = true; - } - if (updateMaps) { - mTPCCorrMapsLoader.updateVDrift(mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().getTimeOffset()); } } if (mEnableStrangenessTracking) { @@ -253,7 +232,7 @@ void SecondaryVertexingSpec::updateTimeDependentParams(ProcessingContext& pc) } DataProcessorSpec getSecondaryVertexingSpec(GTrackID::mask_t src, bool enableCasc, bool enable3body, bool enableStrangenesTracking, bool enableCCDBParams, - bool useMC, bool useGeom, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts) + bool useMC, bool useGeom) { std::vector outputs; Options opts{ @@ -297,7 +276,7 @@ DataProcessorSpec getSecondaryVertexingSpec(GTrackID::mask_t src, bool enableCas } if (src[GTrackID::TPC]) { o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs); - o2::tpc::CorrectionMapsLoader::requestCCDBInputs(dataRequest->inputs, opts, sclOpts); + dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe); } outputs.emplace_back("GLO", "V0S_IDX", 0, Lifetime::Timeframe); // found V0s indices outputs.emplace_back("GLO", "V0S", 0, Lifetime::Timeframe); // found V0s @@ -324,7 +303,7 @@ DataProcessorSpec getSecondaryVertexingSpec(GTrackID::mask_t src, bool enableCas "secondary-vertexing", dataRequest->inputs, outputs, - AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, sclOpts, src, enableCasc, enable3body, enableStrangenesTracking, enableCCDBParams, useMC)}, + AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, src, enableCasc, enable3body, enableStrangenesTracking, enableCCDBParams, useMC)}, opts}; } diff --git a/Detectors/GlobalTrackingWorkflow/src/TOFMatcherSpec.cxx b/Detectors/GlobalTrackingWorkflow/src/TOFMatcherSpec.cxx index 8081c48e390d3..746e572c506b8 100644 --- a/Detectors/GlobalTrackingWorkflow/src/TOFMatcherSpec.cxx +++ b/Detectors/GlobalTrackingWorkflow/src/TOFMatcherSpec.cxx @@ -24,7 +24,7 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/DeviceSpec.h" #include "TPCCalibration/VDriftHelper.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCFastTransformPOD.h" // from Tracks #include "ReconstructionDataFormats/GlobalTrackID.h" @@ -59,12 +59,7 @@ namespace globaltracking class TOFMatcherSpec : public Task { public: - TOFMatcherSpec(std::shared_ptr dr, std::shared_ptr gr, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, bool useMC, bool useFIT, bool tpcRefit, bool strict, bool pushMatchable, int lanes = 1) : mDataRequest(dr), mGGCCDBRequest(gr), mUseMC(useMC), mUseFIT(useFIT), mDoTPCRefit(tpcRefit), mStrict(strict), mPushMatchable(pushMatchable), mNlanes(lanes) - { - mTPCCorrMapsLoader.setLumiScaleType(sclOpts.lumiType); - mTPCCorrMapsLoader.setLumiScaleMode(sclOpts.lumiMode); - mTPCCorrMapsLoader.setCheckCTPIDCConsistency(sclOpts.checkCTPIDCconsistency); - } + TOFMatcherSpec(std::shared_ptr dr, std::shared_ptr gr, bool useMC, bool useFIT, bool tpcRefit, bool strict, bool pushMatchable, int lanes = 1, bool requestCTPLumi = false) : mDataRequest(dr), mGGCCDBRequest(gr), mUseMC(useMC), mUseFIT(useFIT), mDoTPCRefit(tpcRefit), mStrict(strict), mPushMatchable(pushMatchable), mNlanes(lanes), mRequestCTPLumi(requestCTPLumi) {} ~TOFMatcherSpec() override = default; void init(InitContext& ic) final; void run(ProcessingContext& pc) final; @@ -76,7 +71,7 @@ class TOFMatcherSpec : public Task std::shared_ptr mDataRequest; std::shared_ptr mGGCCDBRequest; o2::tpc::VDriftHelper mTPCVDriftHelper{}; - o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{}; + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps = nullptr; bool mUseMC = true; bool mUseFIT = false; bool mDoTPCRefit = false; @@ -84,6 +79,7 @@ class TOFMatcherSpec : public Task bool mPushMatchable = false; float mExtraTolTRD = 0.; int mNlanes = 1; + bool mRequestCTPLumi = false; MatchTOF mMatcher; ///< Cluster finder TStopwatch mTimer; }; @@ -96,7 +92,6 @@ void TOFMatcherSpec::init(InitContext& ic) if (mStrict) { mMatcher.setHighPurity(); } - mTPCCorrMapsLoader.init(ic); mMatcher.storeMatchable(mPushMatchable); mMatcher.setExtraTimeToleranceTRD(mExtraTolTRD); mMatcher.setNlanes(mNlanes); @@ -106,7 +101,9 @@ void TOFMatcherSpec::updateTimeDependentParams(ProcessingContext& pc) { o2::base::GRPGeomHelper::instance().checkUpdates(pc); mTPCVDriftHelper.extractCCDBInputs(pc); - mTPCCorrMapsLoader.extractCCDBInputs(pc); + auto const& raw = pc.inputs().get("corrMap"); + mTPCCorrMaps = &o2::gpu::TPCFastTransformPOD::get(raw); + float lumiCTP = mRequestCTPLumi ? pc.inputs().get("lumiCTP") : 0; static bool initOnceDone = false; if (!initOnceDone) { // this params need to be queried only once const auto bcs = o2::base::GRPGeomHelper::instance().getGRPLHCIF()->getBunchFilling().getFilledBCs(); @@ -116,13 +113,7 @@ void TOFMatcherSpec::updateTimeDependentParams(ProcessingContext& pc) initOnceDone = true; // put here init-once stuff } - // we may have other params which need to be queried regularly - bool updateMaps = false; - if (mTPCCorrMapsLoader.isUpdated()) { - mTPCCorrMapsLoader.acknowledgeUpdate(); - updateMaps = true; - } - mMatcher.setTPCCorrMaps(&mTPCCorrMapsLoader); + mMatcher.setTPCCorrMaps(mTPCCorrMaps, lumiCTP); if (mTPCVDriftHelper.isUpdated()) { LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}", mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, @@ -130,10 +121,6 @@ void TOFMatcherSpec::updateTimeDependentParams(ProcessingContext& pc) mTPCVDriftHelper.getSourceName()); mMatcher.setTPCVDrift(mTPCVDriftHelper.getVDriftObject()); mTPCVDriftHelper.acknowledgeUpdate(); - updateMaps = true; - } - if (updateMaps) { - mTPCCorrMapsLoader.updateVDrift(mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().getTimeOffset()); } } @@ -145,9 +132,6 @@ void TOFMatcherSpec::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) { return; } - if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) { - return; - } } void TOFMatcherSpec::run(ProcessingContext& pc) @@ -247,7 +231,7 @@ void TOFMatcherSpec::endOfStream(EndOfStreamContext& ec) mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1); } -DataProcessorSpec getTOFMatcherSpec(GID::mask_t src, bool useMC, bool useFIT, bool tpcRefit, bool strict, float extratolerancetrd, bool pushMatchable, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, int nlanes) +DataProcessorSpec getTOFMatcherSpec(GID::mask_t src, bool useMC, bool useFIT, bool tpcRefit, bool strict, float extratolerancetrd, bool pushMatchable, bool requestCTPLumi, int nlanes) { uint32_t ss = o2::globaltracking::getSubSpec(strict ? o2::globaltracking::MatchingType::Strict : o2::globaltracking::MatchingType::Standard); Options opts; @@ -273,7 +257,10 @@ DataProcessorSpec getTOFMatcherSpec(GID::mask_t src, bool useMC, bool useFIT, bo dataRequest->inputs, true); o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs); - o2::tpc::CorrectionMapsLoader::requestCCDBInputs(dataRequest->inputs, opts, sclOpts); + dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe); + if (requestCTPLumi) { + dataRequest->inputs.emplace_back("lumiCTP", o2::header::gDataOriginCTP, "LUMICTP", 0, Lifetime::Timeframe); + } std::vector outputs; if (GID::includesSource(GID::TPC, src)) { outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_TPC", ss, Lifetime::Timeframe); @@ -327,7 +314,7 @@ DataProcessorSpec getTOFMatcherSpec(GID::mask_t src, bool useMC, bool useFIT, bo "tof-matcher", dataRequest->inputs, outputs, - AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, sclOpts, useMC, useFIT, tpcRefit, strict, pushMatchable, nlanes)}, + AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, useMC, useFIT, tpcRefit, strict, pushMatchable, nlanes, requestCTPLumi)}, opts}; } diff --git a/Detectors/GlobalTrackingWorkflow/src/TPCITSMatchingSpec.cxx b/Detectors/GlobalTrackingWorkflow/src/TPCITSMatchingSpec.cxx index c333c37ff245b..50697ee79c0e7 100644 --- a/Detectors/GlobalTrackingWorkflow/src/TPCITSMatchingSpec.cxx +++ b/Detectors/GlobalTrackingWorkflow/src/TPCITSMatchingSpec.cxx @@ -50,7 +50,7 @@ #include "ITSMFTReconstruction/ClustererParam.h" #include "DetectorsBase/GRPGeomHelper.h" #include "TPCCalibration/VDriftHelper.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCFastTransformPOD.h" #ifdef ENABLE_UPGRADES #include "ITS3Reconstruction/TopologyDictionary.h" @@ -69,14 +69,9 @@ namespace globaltracking class TPCITSMatchingDPL : public Task { public: - TPCITSMatchingDPL(std::shared_ptr dr, std::shared_ptr gr, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, - bool useFT0, bool calib, bool skipTPCOnly, bool useMC) - : mDataRequest(dr), mGGCCDBRequest(gr), mUseFT0(useFT0), mCalibMode(calib), mSkipTPCOnly(skipTPCOnly), mUseMC(useMC) - { - mTPCCorrMapsLoader.setLumiScaleType(sclOpts.lumiType); - mTPCCorrMapsLoader.setLumiScaleMode(sclOpts.lumiMode); - mTPCCorrMapsLoader.setCheckCTPIDCConsistency(sclOpts.checkCTPIDCconsistency); - } + TPCITSMatchingDPL(std::shared_ptr dr, std::shared_ptr gr, + bool useFT0, bool calib, bool skipTPCOnly, bool useMC, bool requestCTPLumi) + : mDataRequest(dr), mGGCCDBRequest(gr), mUseFT0(useFT0), mCalibMode(calib), mSkipTPCOnly(skipTPCOnly), mUseMC(useMC), mRequestCTPLumi(requestCTPLumi) {} ~TPCITSMatchingDPL() override = default; void init(InitContext& ic) final; void run(ProcessingContext& pc) final; @@ -88,12 +83,13 @@ class TPCITSMatchingDPL : public Task std::shared_ptr mDataRequest; std::shared_ptr mGGCCDBRequest; o2::tpc::VDriftHelper mTPCVDriftHelper{}; - o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{}; + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps{}; o2::globaltracking::MatchTPCITS mMatching; // matching engine bool mUseFT0 = false; bool mCalibMode = false; bool mSkipTPCOnly = false; // to use only externally constrained tracks (for test only) bool mUseMC = true; + bool mRequestCTPLumi = false; TStopwatch mTimer; }; @@ -108,7 +104,6 @@ void TPCITSMatchingDPL::init(InitContext& ic) mMatching.setNThreads(std::max(1, ic.options().get("nthreads"))); mMatching.setUseBCFilling(!ic.options().get("ignore-bc-check")); mMatching.setDebugFlag(ic.options().get("debug-tree-flags")); - mTPCCorrMapsLoader.init(ic); } void TPCITSMatchingDPL::run(ProcessingContext& pc) @@ -157,9 +152,6 @@ void TPCITSMatchingDPL::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) { return; } - if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) { - return; - } if (matcher == ConcreteDataMatcher("GLO", "ITSTPCPARAM", 0)) { LOG(info) << "ITS-TPC Matching params updated from ccdb"; return; @@ -193,7 +185,10 @@ void TPCITSMatchingDPL::updateTimeDependentParams(ProcessingContext& pc) { o2::base::GRPGeomHelper::instance().checkUpdates(pc); mTPCVDriftHelper.extractCCDBInputs(pc); - mTPCCorrMapsLoader.extractCCDBInputs(pc); + auto const& raw = pc.inputs().get("corrMap"); + mTPCCorrMaps = &o2::gpu::TPCFastTransformPOD::get(raw); + float lumiCTP = mRequestCTPLumi ? pc.inputs().get("lumiCTP") : 0; + static bool initOnceDone = false; if (!initOnceDone) { // this params need to be queried only once initOnceDone = true; @@ -227,29 +222,20 @@ void TPCITSMatchingDPL::updateTimeDependentParams(ProcessingContext& pc) LOGP(fatal, "USEMatCorrTGeo cannot work w/o full geometry request in the GRPGeomHelper"); } } - // we may have other params which need to be queried regularly - bool updateMaps = false; - if (mTPCCorrMapsLoader.isUpdated()) { - mTPCCorrMapsLoader.acknowledgeUpdate(); - updateMaps = true; - } - mMatching.setTPCCorrMaps(&mTPCCorrMapsLoader); + + mMatching.setTPCCorrMaps(mTPCCorrMaps, lumiCTP); if (mTPCVDriftHelper.isUpdated()) { - LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}", + LOGP(info, "Updating TPC VDrift: corrFact {} wrt refVDrift {} and DriftTimeOffset correction {} wrt {} from source {}", mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset, mTPCVDriftHelper.getSourceName()); mMatching.setTPCVDrift(mTPCVDriftHelper.getVDriftObject()); mTPCVDriftHelper.acknowledgeUpdate(); - updateMaps = true; - } - if (updateMaps) { - mTPCCorrMapsLoader.updateVDrift(mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().getTimeOffset()); } } -DataProcessorSpec getTPCITSMatchingSpec(GTrackID::mask_t src, bool useFT0, bool calib, bool skipTPCOnly, bool useGeom, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts) +DataProcessorSpec getTPCITSMatchingSpec(GTrackID::mask_t src, bool useFT0, bool calib, bool skipTPCOnly, bool useGeom, bool useMC, bool requestCTPLumi) { std::vector outputs; auto dataRequest = std::make_shared(); @@ -305,13 +291,15 @@ DataProcessorSpec getTPCITSMatchingSpec(GTrackID::mask_t src, bool useFT0, bool {"debug-tree-flags", VariantType::Int, 0, {"DebugFlagTypes bit-pattern for debug tree"}}}; o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs); - o2::tpc::CorrectionMapsLoader::requestCCDBInputs(dataRequest->inputs, opts, sclOpts); - + dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe); + if (requestCTPLumi) { + dataRequest->inputs.emplace_back("lumiCTP", o2::header::gDataOriginCTP, "LUMICTP", 0, Lifetime::Timeframe); + } return DataProcessorSpec{ "itstpc-track-matcher", dataRequest->inputs, outputs, - AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, sclOpts, useFT0, calib, skipTPCOnly, useMC)}, + AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, useFT0, calib, skipTPCOnly, useMC, requestCTPLumi)}, opts}; } diff --git a/Detectors/GlobalTrackingWorkflow/src/cosmics-match-workflow.cxx b/Detectors/GlobalTrackingWorkflow/src/cosmics-match-workflow.cxx index e4082bdd14d86..8e0ed7b80c8b7 100644 --- a/Detectors/GlobalTrackingWorkflow/src/cosmics-match-workflow.cxx +++ b/Detectors/GlobalTrackingWorkflow/src/cosmics-match-workflow.cxx @@ -31,7 +31,7 @@ #include "DetectorsRaw/HBFUtilsInitializer.h" #include "Framework/CallbacksPolicy.h" #include "GlobalTrackingWorkflowHelpers/InputHelper.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCCalibration/CorrectionMapsOptions.h" using namespace o2::framework; using DetID = o2::detectors::DetID; @@ -52,7 +52,7 @@ void customize(std::vector& workflowOptions) {"disable-root-output", o2::framework::VariantType::Bool, false, {"disable root-files output writer"}}, {"track-sources", VariantType::String, std::string{GID::ALL}, {"comma-separated list of sources to use"}}, {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}}}; - o2::tpc::CorrectionMapsLoader::addGlobalOptions(options); + o2::tpc::CorrectionMapsOptions::addGlobalOptions(options); o2::raw::HBFUtilsInitializer::addConfigOption(options); std::swap(workflowOptions, options); } @@ -83,7 +83,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) o2::conf::ConfigurableParam::updateFromString(configcontext.options().get("configKeyValues")); // write the configuration used for the workflow o2::conf::ConfigurableParam::writeINI("o2match-cosmics-workflow_configuration.ini"); - auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(configcontext.options()); + auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(configcontext.options()); auto useMC = !configcontext.options().get("disable-mc"); auto disableRootOut = configcontext.options().get("disable-root-output"); @@ -102,10 +102,10 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) } GID::mask_t srcCl = src; GID::mask_t dummy; - if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get("disable-root-input")) { - specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection)); + if (!configcontext.options().get("disable-root-input")) { + specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == o2::tpc::LumiScaleType::TPCScaler, sclOpt.enableMShapeCorrection, sclOpt)); } - specs.emplace_back(o2::globaltracking::getCosmicsMatchingSpec(src, useMC, sclOpt)); + specs.emplace_back(o2::globaltracking::getCosmicsMatchingSpec(src, useMC)); o2::globaltracking::InputHelper::addInputSpecs(configcontext, specs, src, src, src, useMC, dummy); // clusters MC is not needed diff --git a/Detectors/GlobalTrackingWorkflow/src/secondary-vertexing-workflow.cxx b/Detectors/GlobalTrackingWorkflow/src/secondary-vertexing-workflow.cxx index 0ac640cbad9fd..fda749de333ff 100644 --- a/Detectors/GlobalTrackingWorkflow/src/secondary-vertexing-workflow.cxx +++ b/Detectors/GlobalTrackingWorkflow/src/secondary-vertexing-workflow.cxx @@ -29,7 +29,7 @@ #include "Framework/ConfigParamSpec.h" #include "Framework/CompletionPolicyHelpers.h" #include "DetectorsBase/DPLWorkflowUtils.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCCalibration/CorrectionMapsOptions.h" using namespace o2::framework; using GID = o2::dataformats::GlobalTrackID; @@ -62,7 +62,7 @@ void customize(std::vector& workflowOptions) {"use-full-geometry", o2::framework::VariantType::Bool, false, {"use full geometry instead of the light-weight ITS part"}}, {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}}, {"combine-source-devices", o2::framework::VariantType::Bool, false, {"merge DPL source devices"}}}; - o2::tpc::CorrectionMapsLoader::addGlobalOptions(options); + o2::tpc::CorrectionMapsOptions::addGlobalOptions(options); o2::raw::HBFUtilsInitializer::addConfigOption(options); std::swap(workflowOptions, options); } @@ -86,7 +86,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) auto enable3body = !configcontext.options().get("disable-3body-finder"); auto enableStrTr = !configcontext.options().get("disable-strangeness-tracker"); auto useGeom = configcontext.options().get("use-full-geometry"); - auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(configcontext.options()); + auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(configcontext.options()); GID::mask_t src = allowedSources & GID::getSourcesMask(configcontext.options().get("vertexing-sources")); GID::mask_t dummy, srcClus = GID::includesDet(DetID::TOF, src) ? GID::getSourceMask(GID::TOF) : dummy; // eventually, TPC clusters will be needed for refit if (enableStrTr) { @@ -99,10 +99,10 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) src = src | GID::getSourcesMask("CTP"); } WorkflowSpec specs; - if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get("disable-root-input")) { - specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection)); + if (!configcontext.options().get("disable-root-input")) { + specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == o2::tpc::LumiScaleType::TPCScaler, sclOpt.enableMShapeCorrection, sclOpt)); } - specs.emplace_back(o2::vertexing::getSecondaryVertexingSpec(src, enableCasc, enable3body, enableStrTr, enableCCDBParams, useMC, useGeom, sclOpt)); + specs.emplace_back(o2::vertexing::getSecondaryVertexingSpec(src, enableCasc, enable3body, enableStrTr, enableCCDBParams, useMC, useGeom)); // only TOF clusters are needed if TOF is involved, no clusters MC needed WorkflowSpec inputspecs; diff --git a/Detectors/GlobalTrackingWorkflow/src/tof-matcher-workflow.cxx b/Detectors/GlobalTrackingWorkflow/src/tof-matcher-workflow.cxx index 9a95c83617210..96d7c783022c3 100644 --- a/Detectors/GlobalTrackingWorkflow/src/tof-matcher-workflow.cxx +++ b/Detectors/GlobalTrackingWorkflow/src/tof-matcher-workflow.cxx @@ -32,7 +32,7 @@ #include "Steer/MCKinematicsReader.h" #include "TSystem.h" #include "DetectorsBase/DPLWorkflowUtils.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCCalibration/CorrectionMapsOptions.h" #include "TPCWorkflow/TPCScalerSpec.h" using namespace o2::framework; @@ -70,7 +70,7 @@ void customize(std::vector& workflowOptions) {"write-matchable", o2::framework::VariantType::Bool, false, {"write all matchable pairs in a file (o2matchable_tof.root)"}}, {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}}, {"combine-devices", o2::framework::VariantType::Bool, false, {"merge DPL source/writer devices"}}}; - o2::tpc::CorrectionMapsLoader::addGlobalOptions(options); + o2::tpc::CorrectionMapsOptions::addGlobalOptions(options); o2::raw::HBFUtilsInitializer::addConfigOption(options); std::swap(workflowOptions, options); } @@ -97,7 +97,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) auto diagnostic = configcontext.options().get("enable-dia"); auto extratolerancetrd = configcontext.options().get("trd-extra-tolerance"); auto writeMatchable = configcontext.options().get("write-matchable"); - auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(configcontext.options()); + auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(configcontext.options()); bool writematching = 0; bool writecalib = 0; bool refitTPCTOF = configcontext.options().get("refit-tpc-tof"); @@ -168,10 +168,10 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) specs.push_back(s); } } - if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get("disable-root-input")) { - specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection)); + if (!configcontext.options().get("disable-root-input")) { + specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == o2::tpc::LumiScaleType::TPCScaler, sclOpt.enableMShapeCorrection, sclOpt)); } - specs.emplace_back(o2::globaltracking::getTOFMatcherSpec(src, useMC, useFIT, refitTPCTOF, strict, extratolerancetrd, writeMatchable, sclOpt, nLanes)); // doTPCrefit not yet supported (need to load TPC clusters?) + specs.emplace_back(o2::globaltracking::getTOFMatcherSpec(src, useMC, useFIT, refitTPCTOF, strict, extratolerancetrd, writeMatchable, sclOpt.requestCTPLumi, nLanes)); // doTPCrefit not yet supported (need to load TPC clusters?) if (!disableRootOut) { std::vector writers; diff --git a/Detectors/GlobalTrackingWorkflow/src/tpcits-match-workflow.cxx b/Detectors/GlobalTrackingWorkflow/src/tpcits-match-workflow.cxx index 810c7c564b4a8..d3c43c8bc9c91 100644 --- a/Detectors/GlobalTrackingWorkflow/src/tpcits-match-workflow.cxx +++ b/Detectors/GlobalTrackingWorkflow/src/tpcits-match-workflow.cxx @@ -24,7 +24,7 @@ #include "Framework/CallbacksPolicy.h" #include "Framework/ConfigContext.h" #include "Framework/CompletionPolicyHelpers.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCCalibration/CorrectionMapsOptions.h" using namespace o2::framework; using GID = o2::dataformats::GlobalTrackID; @@ -46,7 +46,7 @@ void customize(std::vector& workflowOptions) {"produce-calibration-data", o2::framework::VariantType::Bool, false, {"produce output for TPC vdrift calibration"}}, {"use-full-geometry", o2::framework::VariantType::Bool, false, {"use full geometry instead of the light-weight ITS part"}}, {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}}}; - o2::tpc::CorrectionMapsLoader::addGlobalOptions(options); + o2::tpc::CorrectionMapsOptions::addGlobalOptions(options); o2::raw::HBFUtilsInitializer::addConfigOption(options); std::swap(workflowOptions, options); } @@ -76,7 +76,7 @@ WorkflowSpec defineDataProcessing(o2::framework::ConfigContext const& configcont GID::mask_t alowedSources = GID::getSourcesMask("ITS,TPC,TPC-TOF"); GID::mask_t src = alowedSources & GID::getSourcesMask(configcontext.options().get("track-sources")); bool needStrictTRDTOF = (src & GID::getSourcesMask("TPC-TRD,TPC-TOF,TPC-TRD-TOF")).any(); - auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(configcontext.options()); + auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(configcontext.options()); auto useGeom = configcontext.options().get("use-full-geometry"); auto useFT0 = configcontext.options().get("use-ft0"); if (useFT0) { @@ -90,10 +90,10 @@ WorkflowSpec defineDataProcessing(o2::framework::ConfigContext const& configcont } o2::framework::WorkflowSpec specs; - if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get("disable-root-input")) { - specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection)); + if (!configcontext.options().get("disable-root-input")) { + specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == o2::tpc::LumiScaleType::TPCScaler, sclOpt.enableMShapeCorrection, sclOpt)); } - specs.emplace_back(o2::globaltracking::getTPCITSMatchingSpec(srcL, useFT0, calib, !GID::includesSource(GID::TPC, src), useGeom, useMC, sclOpt)); + specs.emplace_back(o2::globaltracking::getTPCITSMatchingSpec(srcL, useFT0, calib, !GID::includesSource(GID::TPC, src), useGeom, useMC, sclOpt.requestCTPLumi)); if (!configcontext.options().get("disable-root-output")) { specs.emplace_back(o2::globaltracking::getTrackWriterTPCITSSpec(useMC)); diff --git a/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/CheckResid.h b/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/CheckResid.h index a78fa5e8d41da..baba1a1d4d765 100644 --- a/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/CheckResid.h +++ b/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/CheckResid.h @@ -15,7 +15,6 @@ #include "ReconstructionDataFormats/GlobalTrackID.h" #include "Framework/Task.h" #include "Framework/DataProcessorSpec.h" -// #include "TPCCalibration/CorrectionMapsLoader.h" namespace o2::checkresid { diff --git a/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TPCTrackStudy.h b/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TPCTrackStudy.h index 47385f400ec01..f6396f682ac3b 100644 --- a/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TPCTrackStudy.h +++ b/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TPCTrackStudy.h @@ -19,15 +19,10 @@ #include "MathUtils/detail/Bracket.h" #include "DataFormatsTPC/ClusterNative.h" -namespace o2::tpc -{ -struct CorrectionMapsLoaderGloOpts; -} - namespace o2::trackstudy { /// create a processor spec -o2::framework::DataProcessorSpec getTPCTrackStudySpec(o2::dataformats::GlobalTrackID::mask_t srcTracks, o2::dataformats::GlobalTrackID::mask_t srcClus, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts); +o2::framework::DataProcessorSpec getTPCTrackStudySpec(o2::dataformats::GlobalTrackID::mask_t srcTracks, o2::dataformats::GlobalTrackID::mask_t srcClus, bool useMC); } // namespace o2::trackstudy diff --git a/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TrackMCStudy.h b/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TrackMCStudy.h index d1326a47ac909..18ce3dbf8ab87 100644 --- a/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TrackMCStudy.h +++ b/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TrackMCStudy.h @@ -15,13 +15,12 @@ #include "Framework/DataProcessorSpec.h" #include "Framework/Task.h" #include "ReconstructionDataFormats/GlobalTrackID.h" -#include "TPCCalibration/CorrectionMapsLoader.h" namespace o2::trackstudy { /// create a processor spec -o2::framework::DataProcessorSpec getTrackMCStudySpec(o2::dataformats::GlobalTrackID::mask_t srcTracks, o2::dataformats::GlobalTrackID::mask_t srcClus, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, bool checkSV); +o2::framework::DataProcessorSpec getTrackMCStudySpec(o2::dataformats::GlobalTrackID::mask_t srcTracks, o2::dataformats::GlobalTrackID::mask_t srcClus, bool checkSV); } // namespace o2::trackstudy diff --git a/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TrackingStudy.h b/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TrackingStudy.h index 7a15c191cbeed..b3a55416f4818 100644 --- a/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TrackingStudy.h +++ b/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TrackingStudy.h @@ -18,12 +18,11 @@ #include "ReconstructionDataFormats/Track.h" #include "MathUtils/detail/Bracket.h" #include "DataFormatsTPC/ClusterNative.h" -#include "TPCCalibration/CorrectionMapsLoader.h" namespace o2::trackstudy { /// create a processor spec -o2::framework::DataProcessorSpec getTrackingStudySpec(o2::dataformats::GlobalTrackID::mask_t srcTracks, o2::dataformats::GlobalTrackID::mask_t srcClus, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts); +o2::framework::DataProcessorSpec getTrackingStudySpec(o2::dataformats::GlobalTrackID::mask_t srcTracks, o2::dataformats::GlobalTrackID::mask_t srcClus, bool useMC); } // namespace o2::trackstudy diff --git a/Detectors/GlobalTrackingWorkflow/study/src/TPCTrackStudy.cxx b/Detectors/GlobalTrackingWorkflow/study/src/TPCTrackStudy.cxx index ee475acbbcf70..f9ba67319e18a 100644 --- a/Detectors/GlobalTrackingWorkflow/study/src/TPCTrackStudy.cxx +++ b/Detectors/GlobalTrackingWorkflow/study/src/TPCTrackStudy.cxx @@ -14,7 +14,7 @@ #include "DataFormatsGlobalTracking/RecoContainer.h" #include "DataFormatsGlobalTracking/RecoContainerCreateTracksVariadic.h" #include "TPCCalibration/VDriftHelper.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCFastTransformPOD.h" #include "ReconstructionDataFormats/GlobalTrackID.h" #include "DetectorsBase/Propagator.h" #include "DetectorsBase/GeometryManager.h" @@ -50,13 +50,8 @@ using timeEst = o2::dataformats::TimeStampWithError; class TPCTrackStudySpec final : public Task { public: - TPCTrackStudySpec(std::shared_ptr dr, std::shared_ptr gr, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, GTrackID::mask_t src, bool useMC) - : mDataRequest(dr), mGGCCDBRequest(gr), mTracksSrc(src), mUseMC(useMC) - { - mTPCCorrMapsLoader.setLumiScaleType(sclOpts.lumiType); - mTPCCorrMapsLoader.setLumiScaleMode(sclOpts.lumiMode); - mTPCCorrMapsLoader.setCheckCTPIDCConsistency(sclOpts.checkCTPIDCconsistency); - } + TPCTrackStudySpec(std::shared_ptr dr, std::shared_ptr gr, GTrackID::mask_t src, bool useMC) + : mDataRequest(dr), mGGCCDBRequest(gr), mTracksSrc(src), mUseMC(useMC) {} ~TPCTrackStudySpec() final = default; void init(InitContext& ic) final; void run(ProcessingContext& pc) final; @@ -69,7 +64,7 @@ class TPCTrackStudySpec final : public Task std::shared_ptr mDataRequest; std::shared_ptr mGGCCDBRequest; o2::tpc::VDriftHelper mTPCVDriftHelper{}; - o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{}; + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps{nullptr}; bool mUseMC{false}; ///< MC flag bool mUseGPUModel{false}; float mXRef = 0.; @@ -108,7 +103,6 @@ void TPCTrackStudySpec::init(InitContext& ic) if (mXRef < 0.) { mXRef = 0.; } - mTPCCorrMapsLoader.init(ic); mDBGOut = std::make_unique("tpc-trackStudy.root", "recreate"); if (ic.options().get("dump-clusters")) { mDBGOutCl = std::make_unique("tpc-trackStudy-cl.root", "recreate"); @@ -139,29 +133,13 @@ void TPCTrackStudySpec::updateTimeDependentParams(ProcessingContext& pc) { o2::base::GRPGeomHelper::instance().checkUpdates(pc); mTPCVDriftHelper.extractCCDBInputs(pc); - mTPCCorrMapsLoader.extractCCDBInputs(pc); + auto const& raw = pc.inputs().get("corrMap"); + mTPCCorrMaps = &o2::gpu::TPCFastTransformPOD::get(raw); static bool initOnceDone = false; if (!initOnceDone) { // this params need to be queried only once initOnceDone = true; // none at the moment } - // we may have other params which need to be queried regularly - bool updateMaps = false; - if (mTPCCorrMapsLoader.isUpdated()) { - mTPCCorrMapsLoader.acknowledgeUpdate(); - updateMaps = true; - } - if (mTPCVDriftHelper.isUpdated()) { - LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}", - mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, - mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset, - mTPCVDriftHelper.getSourceName()); - mTPCVDriftHelper.acknowledgeUpdate(); - updateMaps = true; - } - if (updateMaps) { - mTPCCorrMapsLoader.updateVDrift(mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().getTimeOffset()); - } } void TPCTrackStudySpec::process(o2::globaltracking::RecoContainer& recoData) @@ -187,7 +165,7 @@ void TPCTrackStudySpec::process(o2::globaltracking::RecoContainer& recoData) } if (mTPCTracksArray.size()) { LOGP(info, "Found {} TPC tracks", mTPCTracksArray.size()); - mTPCRefitter = std::make_unique(mTPCClusterIdxStruct, &mTPCCorrMapsLoader, prop->getNominalBz(), mTPCTrackClusIdx.data(), 0, mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), mTPCRefitterOccMap.size(), nullptr, o2::base::Propagator::Instance()); + mTPCRefitter = std::make_unique(mTPCClusterIdxStruct, mTPCCorrMaps, prop->getNominalBz(), mTPCTrackClusIdx.data(), 0, mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), mTPCRefitterOccMap.size(), nullptr, o2::base::Propagator::Instance()); } float vdriftTB = mTPCVDriftHelper.getVDriftObject().getVDrift() * o2::tpc::ParameterElectronics::Instance().ZbinWidth; // VDrift expressed in cm/TimeBin float tpcTBBias = mTPCVDriftHelper.getVDriftObject().getTimeOffset() / (8 * o2::constants::lhc::LHCBunchSpacingMUS); @@ -196,7 +174,7 @@ void TPCTrackStudySpec::process(o2::globaltracking::RecoContainer& recoData) auto dumpClusters = [this] { static int tf = 0; - const auto* corrMap = this->mTPCCorrMapsLoader.getCorrMap(); + const auto* corrMap = this->mTPCCorrMaps; for (int sector = 0; sector < 36; sector++) { float alp = ((sector % 18) * 20 + 10) * TMath::DegToRad(); float sn = TMath::Sin(alp), cs = TMath::Cos(alp); @@ -273,7 +251,7 @@ void TPCTrackStudySpec::process(o2::globaltracking::RecoContainer& recoData) clSector.push_back(sector); clRow.push_back(row); float x, y, z; - mTPCCorrMapsLoader.Transform(sector, row, cl->getPad(), cl->getTime(), x, y, z, t); // nominal time of the track + mTPCCorrMaps->Transform(sector, row, cl->getPad(), cl->getTime(), x, y, z, t); // nominal time of the track clX.push_back(x); clY.push_back(y); clZ.push_back(z); @@ -415,12 +393,9 @@ void TPCTrackStudySpec::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) { return; } - if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) { - return; - } } -DataProcessorSpec getTPCTrackStudySpec(GTrackID::mask_t srcTracks, GTrackID::mask_t srcClusters, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts) +DataProcessorSpec getTPCTrackStudySpec(GTrackID::mask_t srcTracks, GTrackID::mask_t srcClusters, bool useMC) { std::vector outputs; Options opts{ @@ -445,13 +420,13 @@ DataProcessorSpec getTPCTrackStudySpec(GTrackID::mask_t srcTracks, GTrackID::mas dataRequest->inputs, true); o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs); - o2::tpc::CorrectionMapsLoader::requestCCDBInputs(dataRequest->inputs, opts, sclOpts); + dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe); return DataProcessorSpec{ "tpc-track-study", dataRequest->inputs, outputs, - AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, sclOpts, srcTracks, useMC)}, + AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, srcTracks, useMC)}, opts}; } diff --git a/Detectors/GlobalTrackingWorkflow/study/src/TrackMCStudy.cxx b/Detectors/GlobalTrackingWorkflow/study/src/TrackMCStudy.cxx index 8f6604b029605..ddce606127bcb 100644 --- a/Detectors/GlobalTrackingWorkflow/study/src/TrackMCStudy.cxx +++ b/Detectors/GlobalTrackingWorkflow/study/src/TrackMCStudy.cxx @@ -17,7 +17,6 @@ #include "ReconstructionDataFormats/TrackTPCITS.h" #include "ReconstructionDataFormats/GlobalTrackID.h" #include "TPCCalibration/VDriftHelper.h" -#include "TPCCalibration/CorrectionMapsLoader.h" #include "ITSMFTReconstruction/ChipMappingITS.h" #include "ITStracking/IOUtils.h" #include "DetectorsBase/Propagator.h" @@ -57,6 +56,7 @@ #include "GPUParam.h" #include "GPUParam.inc" #include "MathUtils/fit.h" +#include "TPCFastTransformPOD.h" #include #include #include @@ -86,13 +86,8 @@ using timeEst = o2::dataformats::TimeStampWithError; class TrackMCStudy final : public Task { public: - TrackMCStudy(std::shared_ptr dr, std::shared_ptr gr, GTrackID::mask_t src, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, bool checkSV) - : mDataRequest(dr), mGGCCDBRequest(gr), mTracksSrc(src), mCheckSV(checkSV) - { - mTPCCorrMapsLoader.setLumiScaleType(sclOpts.lumiType); - mTPCCorrMapsLoader.setLumiScaleMode(sclOpts.lumiMode); - mTPCCorrMapsLoader.setCheckCTPIDCConsistency(sclOpts.checkCTPIDCconsistency); - } + TrackMCStudy(std::shared_ptr dr, std::shared_ptr gr, GTrackID::mask_t src, bool checkSV) + : mDataRequest(dr), mGGCCDBRequest(gr), mTracksSrc(src), mCheckSV(checkSV) {} ~TrackMCStudy() final = default; void init(InitContext& ic) final; void run(ProcessingContext& pc) final; @@ -117,21 +112,21 @@ class TrackMCStudy final : public Task const std::vector* mCurrMCTracks = nullptr; TVector3 mCurrMCVertex; o2::tpc::VDriftHelper mTPCVDriftHelper{}; - o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{}; + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps{nullptr}; std::shared_ptr mDataRequest; std::shared_ptr mGGCCDBRequest; std::unique_ptr mDBGOut; - std::vector mTBinClOcc; ///< TPC occupancy histo: i-th entry is the integrated occupancy for ~1 orbit starting from the TB = i*mNTPCOccBinLength - std::vector mTBinClOccHist; //< original occupancy - std::vector mIntBC; ///< interaction global BC wrt TF start - std::vector mTPCOcc; ///< TPC occupancy for this interaction time - std::vector mITSOcc; //< N ITS clusters in the ROF containing collision + std::vector mTBinClOcc; ///< TPC occupancy histo: i-th entry is the integrated occupancy for ~1 orbit starting from the TB = i*mNTPCOccBinLength + std::vector mTBinClOccHist; //< original occupancy + std::vector mIntBC; ///< interaction global BC wrt TF start + std::vector mTPCOcc; ///< TPC occupancy for this interaction time + std::vector mITSOcc; //< N ITS clusters in the ROF containing collision std::vector> mITSClustersArray; ///< ITS clusters created in run() method from compact clusters const o2::itsmft::TopologyDictionary* mITSDict = nullptr; ///< cluster patterns dictionary - bool mCheckSV = false; //< check SV binding (apart from prongs availability) - bool mRecProcStage = false; //< flag that the MC particle was added only at the stage of reco tracks processing - int mNTPCOccBinLength = 0; ///< TPC occ. histo bin length in TBs + bool mCheckSV = false; //< check SV binding (apart from prongs availability) + bool mRecProcStage = false; //< flag that the MC particle was added only at the stage of reco tracks processing + int mNTPCOccBinLength = 0; ///< TPC occ. histo bin length in TBs float mNTPCOccBinLengthInv = -1.f; int mVerbose = 0; float mITSTimeBiasMUS = 0.f; @@ -179,7 +174,6 @@ void TrackMCStudy::init(InitContext& ic) mNCheckDecays++; } mDecaysMaps.resize(mNCheckDecays); - mTPCCorrMapsLoader.init(ic); } void TrackMCStudy::run(ProcessingContext& pc) @@ -202,23 +196,8 @@ void TrackMCStudy::updateTimeDependentParams(ProcessingContext& pc) { o2::base::GRPGeomHelper::instance().checkUpdates(pc); mTPCVDriftHelper.extractCCDBInputs(pc); - mTPCCorrMapsLoader.extractCCDBInputs(pc); - bool updateMaps = false; - if (mTPCCorrMapsLoader.isUpdated()) { - mTPCCorrMapsLoader.acknowledgeUpdate(); - updateMaps = true; - } - if (mTPCVDriftHelper.isUpdated()) { - LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}", - mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, - mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset, - mTPCVDriftHelper.getSourceName()); - mTPCVDriftHelper.acknowledgeUpdate(); - updateMaps = true; - } - if (updateMaps) { - mTPCCorrMapsLoader.updateVDrift(mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().getTimeOffset()); - } + auto const& raw = pc.inputs().get("corrMap"); + mTPCCorrMaps = &o2::gpu::TPCFastTransformPOD::get(raw); static bool initOnceDone = false; if (!initOnceDone) { // this params need to be queried only once initOnceDone = true; @@ -260,8 +239,8 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData) auto vtxRefs = recoData.getPrimaryVertexMatchedTrackRefs(); // references from vertex to these track IDs auto prop = o2::base::Propagator::Instance(); int nv = vtxRefs.size(); - float vdriftTB = mTPCVDriftHelper.getVDriftObject().getVDrift() * o2::tpc::ParameterElectronics::Instance().ZbinWidth; // VDrift expressed in cm/TimeBin - float itsBias = 0.5 * mITSROFrameLengthMUS + o2::itsmft::DPLAlpideParam::Instance().roFrameBiasInBC * o2::constants::lhc::LHCBunchSpacingMUS; // ITS time is supplied in \mus as beginning of ROF + float vdriftTB = mTPCVDriftHelper.getVDriftObject().getVDrift() * o2::tpc::ParameterElectronics::Instance().ZbinWidth; // VDrift expressed in cm/TimeBin + float itsBias = 0.5 * mITSROFrameLengthMUS + o2::itsmft::DPLAlpideParam::Instance().roFrameBiasInBC * o2::constants::lhc::LHCBunchSpacingMUS; // ITS time is supplied in \mus as beginning of ROF prepareITSData(recoData); loadTPCOccMap(recoData); @@ -871,7 +850,7 @@ void TrackMCStudy::fillMCClusterInfo(const o2::globaltracking::RecoContainer& re continue; } float xc, yc, zc; - mTPCCorrMapsLoader.Transform(sector, row, clus.getPad(), clus.getTime(), xc, yc, zc, mctr.bcInTF / 8.); // nominal time of the track + mTPCCorrMaps->Transform(sector, row, clus.getPad(), clus.getTime(), xc, yc, zc, mctr.bcInTF / 8.); // nominal time of the track const auto& entTRefIDs = entTRefIDsIt->second; // find bracketing TRef params @@ -1023,9 +1002,6 @@ void TrackMCStudy::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) { return; } - if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) { - return; - } if (matcher == ConcreteDataMatcher("ITS", "ALPIDEPARAM", 0)) { LOG(info) << "ITS Alpide param updated"; const auto& par = o2::itsmft::DPLAlpideParam::Instance(); @@ -1086,7 +1062,7 @@ bool TrackMCStudy::processMCParticle(int src, int ev, int trid) break; } } - if (decay >= 0) { // check if decay and kinematics is acceptable + if (decay >= 0) { // check if decay and kinematics is acceptable auto& decayPool = mDecaysMaps[decay]; int idd0 = mcPart.getFirstDaughterTrackId(), idd1 = mcPart.getLastDaughterTrackId(); // we want only charged and trackable daughters int dtStart = mDecProdLblPool.size(), dtEnd = -1; @@ -1264,7 +1240,7 @@ void TrackMCStudy::loadTPCOccMap(const o2::globaltracking::RecoContainer& recoDa auto NHBPerTF = o2::base::GRPGeomHelper::instance().getGRPECS()->getNHBFPerTF(); const auto& TPCOccMap = recoData.occupancyMapTPC; auto prop = o2::base::Propagator::Instance(); - auto TPCRefitter = std::make_unique(&recoData.inputsTPCclusters->clusterIndex, &mTPCCorrMapsLoader, prop->getNominalBz(), + auto TPCRefitter = std::make_unique(&recoData.inputsTPCclusters->clusterIndex, mTPCCorrMaps, prop->getNominalBz(), recoData.getTPCTracksClusterRefs().data(), 0, recoData.clusterShMapTPC.data(), TPCOccMap.data(), TPCOccMap.size(), nullptr, prop); mNTPCOccBinLength = TPCRefitter->getParam()->rec.tpc.occupancyMapTimeBins; mTBinClOcc.clear(); @@ -1371,7 +1347,7 @@ void TrackMCStudy::processITSTracks(const o2::globaltracking::RecoContainer& rec } } -DataProcessorSpec getTrackMCStudySpec(GTrackID::mask_t srcTracks, GTrackID::mask_t srcClusters, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, bool checkSV) +DataProcessorSpec getTrackMCStudySpec(GTrackID::mask_t srcTracks, GTrackID::mask_t srcClusters, bool checkSV) { std::vector outputs; Options opts{ @@ -1390,7 +1366,7 @@ DataProcessorSpec getTrackMCStudySpec(GTrackID::mask_t srcTracks, GTrackID::mask dataRequest->requestSecondaryVertices(useMC); } o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs); - o2::tpc::CorrectionMapsLoader::requestCCDBInputs(dataRequest->inputs, opts, sclOpts); + dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe); auto ggRequest = std::make_shared(false, // orbitResetTime true, // GRPECS=true true, // GRPLHCIF @@ -1404,7 +1380,7 @@ DataProcessorSpec getTrackMCStudySpec(GTrackID::mask_t srcTracks, GTrackID::mask "track-mc-study", dataRequest->inputs, outputs, - AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, srcTracks, sclOpts, checkSV)}, + AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, srcTracks, checkSV)}, opts}; } diff --git a/Detectors/GlobalTrackingWorkflow/study/src/TrackingStudy.cxx b/Detectors/GlobalTrackingWorkflow/study/src/TrackingStudy.cxx index c68e60059cd3f..74562b45b19de 100644 --- a/Detectors/GlobalTrackingWorkflow/study/src/TrackingStudy.cxx +++ b/Detectors/GlobalTrackingWorkflow/study/src/TrackingStudy.cxx @@ -42,7 +42,6 @@ #include "ReconstructionDataFormats/VtxTrackRef.h" #include "ReconstructionDataFormats/DCA.h" #include "TPCCalibration/VDriftHelper.h" -#include "TPCCalibration/CorrectionMapsLoader.h" #include "GPUO2InterfaceRefit.h" #include "GPUO2ExternalUser.h" // Needed for propper settings in GPUParam.h #include "GPUParam.h" @@ -50,6 +49,7 @@ #include "GPUTPCGeometry.h" #include "Steer/MCKinematicsReader.h" #include "MathUtils/fit.h" +#include "TPCFastTransformPOD.h" #include namespace o2::trackstudy @@ -70,13 +70,8 @@ using timeEst = o2::dataformats::TimeStampWithError; class TrackingStudySpec final : public Task { public: - TrackingStudySpec(std::shared_ptr dr, std::shared_ptr gr, GTrackID::mask_t src, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts) - : mDataRequest(dr), mGGCCDBRequest(gr), mTracksSrc(src), mUseMC(useMC) - { - mTPCCorrMapsLoader.setLumiScaleType(sclOpts.lumiType); - mTPCCorrMapsLoader.setLumiScaleMode(sclOpts.lumiMode); - mTPCCorrMapsLoader.setCheckCTPIDCConsistency(sclOpts.checkCTPIDCconsistency); - } + TrackingStudySpec(std::shared_ptr dr, std::shared_ptr gr, GTrackID::mask_t src, bool useMC) + : mDataRequest(dr), mGGCCDBRequest(gr), mTracksSrc(src), mUseMC(useMC) {} ~TrackingStudySpec() final = default; void init(InitContext& ic) final; void run(ProcessingContext& pc) final; @@ -91,11 +86,11 @@ class TrackingStudySpec final : public Task std::shared_ptr mDataRequest; std::shared_ptr mGGCCDBRequest; o2::tpc::VDriftHelper mTPCVDriftHelper{}; - o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{}; + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps{nullptr}; bool mUseMC{false}; ///< MC flag std::unique_ptr mDBGOut; std::unique_ptr mDBGOutVtx; - std::unique_ptr mTPCRefitter; ///< TPC refitter used for TPC tracks refit during the reconstruction + std::unique_ptr mTPCRefitter; ///< TPC refitter used for TPC tracks refit during the reconstruction std::vector mMltHistTB, mTBinClOccAft, mTBinClOccBef, mTBinClOccWgh; ///< TPC occupancy histo: i-th entry is the integrated occupancy for ~1 orbit starting/preceding from the TB = i*mNTPCOccBinLength std::unique_ptr mOccWghFun; float mITSROFrameLengthMUS = 0.f; @@ -125,7 +120,6 @@ class TrackingStudySpec final : public Task void TrackingStudySpec::init(InitContext& ic) { o2::base::GRPGeomHelper::instance().setRequest(mGGCCDBRequest); - mTPCCorrMapsLoader.init(ic); int lane = ic.services().get().inputTimesliceId; int maxLanes = ic.services().get().maxInputTimeslices; std::string dbgnm = maxLanes == 1 ? "trackStudy.root" : fmt::format("trackStudy_{}.root", lane); @@ -160,7 +154,7 @@ void TrackingStudySpec::run(ProcessingContext& pc) recoData.collectData(pc, *mDataRequest.get()); // select tracks of needed type, with minimal cuts, the real selected will be done in the vertexer updateTimeDependentParams(pc); // Make sure this is called after recoData.collectData, which may load some conditions if (recoData.inputsTPCclusters) { - mTPCRefitter = std::make_unique(&recoData.inputsTPCclusters->clusterIndex, &mTPCCorrMapsLoader, o2::base::Propagator::Instance()->getNominalBz(), + mTPCRefitter = std::make_unique(&recoData.inputsTPCclusters->clusterIndex, mTPCCorrMaps, o2::base::Propagator::Instance()->getNominalBz(), recoData.getTPCTracksClusterRefs().data(), 0, recoData.clusterShMapTPC.data(), recoData.occupancyMapTPC.data(), recoData.occupancyMapTPC.size(), nullptr, o2::base::Propagator::Instance()); mNTPCOccBinLength = mTPCRefitter->getParam()->rec.tpc.occupancyMapTimeBins; @@ -209,7 +203,8 @@ void TrackingStudySpec::updateTimeDependentParams(ProcessingContext& pc) { o2::base::GRPGeomHelper::instance().checkUpdates(pc); mTPCVDriftHelper.extractCCDBInputs(pc); - mTPCCorrMapsLoader.extractCCDBInputs(pc); + auto const& raw = pc.inputs().get("corrMap"); + mTPCCorrMaps = &o2::gpu::TPCFastTransformPOD::get(raw); static bool initOnceDone = false; if (!initOnceDone) { // this params need to be queried only once initOnceDone = true; @@ -227,22 +222,6 @@ void TrackingStudySpec::updateTimeDependentParams(ProcessingContext& pc) mTPCTBinMUS = elParam.ZbinWidth; // TPC bin in microseconds mTPCTBinMUSInv = 1. / mTPCTBinMUS; } - bool updateMaps = false; - if (mTPCCorrMapsLoader.isUpdated()) { - mTPCCorrMapsLoader.acknowledgeUpdate(); - updateMaps = true; - } - if (mTPCVDriftHelper.isUpdated()) { - LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}", - mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, - mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset, - mTPCVDriftHelper.getSourceName()); - mTPCVDriftHelper.acknowledgeUpdate(); - updateMaps = true; - } - if (updateMaps) { - mTPCCorrMapsLoader.updateVDrift(mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().getTimeOffset()); - } } void TrackingStudySpec::process(o2::globaltracking::RecoContainer& recoData) @@ -296,9 +275,9 @@ void TrackingStudySpec::process(o2::globaltracking::RecoContainer& recoData) if (trExt.padFromEdge > npads / 2) { trExt.padFromEdge = npads - 1 - trExt.padFromEdge; } - this->mTPCCorrMapsLoader.Transform(clSect, clRow, clus.getPad(), clus.getTime(), trExt.innerTPCPos0[0], trExt.innerTPCPos0[1], trExt.innerTPCPos0[2], trc.getTime0()); // nominal time of the track + this->mTPCCorrMaps->Transform(clSect, clRow, clus.getPad(), clus.getTime(), trExt.innerTPCPos0[0], trExt.innerTPCPos0[1], trExt.innerTPCPos0[2], trc.getTime0()); // nominal time of the track if (timestampTB > -1e8) { - this->mTPCCorrMapsLoader.Transform(clSect, clRow, clus.getPad(), clus.getTime(), trExt.innerTPCPos[0], trExt.innerTPCPos[1], trExt.innerTPCPos[2], timestampTB); // time assigned from the global track track + this->mTPCCorrMaps->Transform(clSect, clRow, clus.getPad(), clus.getTime(), trExt.innerTPCPos[0], trExt.innerTPCPos[1], trExt.innerTPCPos[2], timestampTB); // time assigned from the global track track } else { trExt.innerTPCPos = trExt.innerTPCPos0; } @@ -724,9 +703,6 @@ void TrackingStudySpec::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) { return; } - if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) { - return; - } if (matcher == ConcreteDataMatcher("GLO", "MEANVERTEX", 0)) { LOG(info) << "Imposing new MeanVertex: " << ((const o2::dataformats::MeanVertexObject*)obj)->asString(); mMeanVtx = *(const o2::dataformats::MeanVertexObject*)obj; @@ -746,7 +722,7 @@ float TrackingStudySpec::getDCAZCut(float pt) const return fun.Eval(pt); } -DataProcessorSpec getTrackingStudySpec(GTrackID::mask_t srcTracks, GTrackID::mask_t srcClusters, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts) +DataProcessorSpec getTrackingStudySpec(GTrackID::mask_t srcTracks, GTrackID::mask_t srcClusters, bool useMC) { std::vector outputs; auto dataRequest = std::make_shared(); @@ -781,13 +757,13 @@ DataProcessorSpec getTrackingStudySpec(GTrackID::mask_t srcTracks, GTrackID::mas {"min-x-prop", VariantType::Float, 100.f, {"track should be propagated to this X at least"}}, }; o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs); - o2::tpc::CorrectionMapsLoader::requestCCDBInputs(dataRequest->inputs, opts, sclOpts); + dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe); return DataProcessorSpec{ "track-study", dataRequest->inputs, outputs, - AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, srcTracks, useMC, sclOpts)}, + AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, srcTracks, useMC)}, opts}; } diff --git a/Detectors/GlobalTrackingWorkflow/study/src/check-resid-workflow.cxx b/Detectors/GlobalTrackingWorkflow/study/src/check-resid-workflow.cxx index b8230b59405d8..7981fdf94556c 100644 --- a/Detectors/GlobalTrackingWorkflow/study/src/check-resid-workflow.cxx +++ b/Detectors/GlobalTrackingWorkflow/study/src/check-resid-workflow.cxx @@ -20,7 +20,7 @@ #include "DetectorsBase/DPLWorkflowUtils.h" #include "GlobalTrackingWorkflowHelpers/InputHelper.h" #include "DetectorsRaw/HBFUtilsInitializer.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCCalibration/CorrectionMapsOptions.h" #include "TPCWorkflow/TPCScalerSpec.h" using namespace o2::framework; @@ -43,7 +43,7 @@ void customize(std::vector& workflowOptions) {"cluster-sources", VariantType::String, "ITS", {"comma-separated list of cluster sources to use"}}, {"disable-root-input", VariantType::Bool, false, {"disable root-files input reader"}}, {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}}}; - // o2::tpc::CorrectionMapsLoader::addGlobalOptions(options); + o2::tpc::CorrectionMapsOptions::addGlobalOptions(options); o2::raw::HBFUtilsInitializer::addConfigOption(options); std::swap(workflowOptions, options); } @@ -61,7 +61,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) // Update the (declared) parameters if changed from the command line o2::conf::ConfigurableParam::updateFromString(configcontext.options().get("configKeyValues")); - // auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(configcontext.options()); + auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(configcontext.options()); auto useMC = configcontext.options().get("enable-mc"); GID::mask_t srcTrc = allowedSourcesTrc & GID::getSourcesMask(configcontext.options().get("track-sources")); diff --git a/Detectors/GlobalTrackingWorkflow/study/src/tpc-track-study-workflow.cxx b/Detectors/GlobalTrackingWorkflow/study/src/tpc-track-study-workflow.cxx index 3e92178c81b7d..e255295d7665f 100644 --- a/Detectors/GlobalTrackingWorkflow/study/src/tpc-track-study-workflow.cxx +++ b/Detectors/GlobalTrackingWorkflow/study/src/tpc-track-study-workflow.cxx @@ -20,7 +20,7 @@ #include "DetectorsBase/DPLWorkflowUtils.h" #include "GlobalTrackingWorkflowHelpers/InputHelper.h" #include "DetectorsRaw/HBFUtilsInitializer.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCCalibration/CorrectionMapsOptions.h" #include "TPCWorkflow/TPCScalerSpec.h" using namespace o2::framework; @@ -43,7 +43,7 @@ void customize(std::vector& workflowOptions) {"cluster-sources", VariantType::String, std::string{GID::ALL}, {"comma-separated list of cluster sources to use"}}, {"disable-root-input", VariantType::Bool, false, {"disable root-files input reader"}}, {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}}}; - o2::tpc::CorrectionMapsLoader::addGlobalOptions(options); + o2::tpc::CorrectionMapsOptions::addGlobalOptions(options); o2::raw::HBFUtilsInitializer::addConfigOption(options); std::swap(workflowOptions, options); } @@ -62,7 +62,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) // Update the (declared) parameters if changed from the command line o2::conf::ConfigurableParam::updateFromString(configcontext.options().get("configKeyValues")); auto useMC = !configcontext.options().get("disable-mc"); - auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(configcontext.options()); + auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(configcontext.options()); GID::mask_t srcTrc = allowedSourcesTrc & GID::getSourcesMask(configcontext.options().get("track-sources")); GID::mask_t srcCls = allowedSourcesClus & GID::getSourcesMask(configcontext.options().get("cluster-sources")); if (sclOpt.requestCTPLumi) { @@ -71,10 +71,10 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) } o2::globaltracking::InputHelper::addInputSpecs(configcontext, specs, srcCls, srcTrc, srcTrc, useMC); o2::globaltracking::InputHelper::addInputSpecsPVertex(configcontext, specs, useMC); // P-vertex is always needed - if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get("disable-root-input")) { - specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection)); + if (!configcontext.options().get("disable-root-input")) { + specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == o2::tpc::LumiScaleType::TPCScaler, sclOpt.enableMShapeCorrection, sclOpt)); } - specs.emplace_back(o2::trackstudy::getTPCTrackStudySpec(srcTrc, srcCls, useMC, sclOpt)); + specs.emplace_back(o2::trackstudy::getTPCTrackStudySpec(srcTrc, srcCls, useMC)); // configure dpl timer to inject correct firstTForbit: start from the 1st orbit of TF containing 1st sampled orbit o2::raw::HBFUtilsInitializer hbfIni(configcontext, specs); diff --git a/Detectors/GlobalTrackingWorkflow/study/src/trackMCStudy-workflow.cxx b/Detectors/GlobalTrackingWorkflow/study/src/trackMCStudy-workflow.cxx index 7aa53e2190a9e..d86c0f2f1c82f 100644 --- a/Detectors/GlobalTrackingWorkflow/study/src/trackMCStudy-workflow.cxx +++ b/Detectors/GlobalTrackingWorkflow/study/src/trackMCStudy-workflow.cxx @@ -19,7 +19,7 @@ #include "Framework/CallbacksPolicy.h" #include "DetectorsBase/DPLWorkflowUtils.h" #include "GlobalTrackingWorkflowHelpers/InputHelper.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCCalibration/CorrectionMapsOptions.h" #include "TPCWorkflow/TPCScalerSpec.h" #include "DetectorsRaw/HBFUtilsInitializer.h" @@ -44,7 +44,7 @@ void customize(std::vector& workflowOptions) {"ignore-sv-check", VariantType::Bool, false, {"disable check for SV combinatorics"}}, {"disable-mc", o2::framework::VariantType::Bool, false, {"disable MC propagation, never use it"}}, {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}}}; - o2::tpc::CorrectionMapsLoader::addGlobalOptions(options); + o2::tpc::CorrectionMapsOptions::addGlobalOptions(options); o2::raw::HBFUtilsInitializer::addConfigOption(options); std::swap(workflowOptions, options); } @@ -61,7 +61,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) if (!useMC) { throw std::runtime_error("MC cannot be disabled for this workflow"); } - auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(configcontext.options()); + auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(configcontext.options()); GID::mask_t allowedSourcesTrc = GID::getSourcesMask("ITS,TPC,ITS-TPC,TPC-TOF,TPC-TRD,ITS-TPC-TRD,TPC-TRD-TOF,ITS-TPC-TOF,ITS-TPC-TRD-TOF"); GID::mask_t allowedSourcesClus = GID::getSourcesMask("ITS,TPC"); @@ -80,11 +80,11 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) if (checkSV) { o2::globaltracking::InputHelper::addInputSpecsSVertex(configcontext, specs); } - if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get("disable-root-input")) { - specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection)); + if (!configcontext.options().get("disable-root-input")) { + specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == o2::tpc::LumiScaleType::TPCScaler, sclOpt.enableMShapeCorrection, sclOpt)); } - specs.emplace_back(o2::trackstudy::getTrackMCStudySpec(srcTrc, srcCls, sclOpt, checkSV)); + specs.emplace_back(o2::trackstudy::getTrackMCStudySpec(srcTrc, srcCls, checkSV)); // configure dpl timer to inject correct firstTForbit: start from the 1st orbit of TF containing 1st sampled orbit o2::raw::HBFUtilsInitializer hbfIni(configcontext, specs); diff --git a/Detectors/GlobalTrackingWorkflow/study/src/tracking-study-workflow.cxx b/Detectors/GlobalTrackingWorkflow/study/src/tracking-study-workflow.cxx index 413d2e63653fc..0c5006da85e32 100644 --- a/Detectors/GlobalTrackingWorkflow/study/src/tracking-study-workflow.cxx +++ b/Detectors/GlobalTrackingWorkflow/study/src/tracking-study-workflow.cxx @@ -20,7 +20,7 @@ #include "DetectorsBase/DPLWorkflowUtils.h" #include "GlobalTrackingWorkflowHelpers/InputHelper.h" #include "DetectorsRaw/HBFUtilsInitializer.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCCalibration/CorrectionMapsOptions.h" #include "TPCWorkflow/TPCScalerSpec.h" using namespace o2::framework; @@ -43,7 +43,7 @@ void customize(std::vector& workflowOptions) {"cluster-sources", VariantType::String, "TPC,TOF", {"comma-separated list of cluster sources to use"}}, {"disable-root-input", VariantType::Bool, false, {"disable root-files input reader"}}, {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}}}; - o2::tpc::CorrectionMapsLoader::addGlobalOptions(options); + o2::tpc::CorrectionMapsOptions::addGlobalOptions(options); o2::raw::HBFUtilsInitializer::addConfigOption(options); std::swap(workflowOptions, options); } @@ -61,7 +61,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) // Update the (declared) parameters if changed from the command line o2::conf::ConfigurableParam::updateFromString(configcontext.options().get("configKeyValues")); - auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(configcontext.options()); + auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(configcontext.options()); auto useMC = !configcontext.options().get("disable-mc"); GID::mask_t srcTrc = allowedSourcesTrc & GID::getSourcesMask(configcontext.options().get("track-sources")); @@ -69,13 +69,13 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) if (sclOpt.requestCTPLumi) { srcCls = srcCls | GID::getSourcesMask("CTP"); } - if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get("disable-root-input")) { - specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection)); + if (!configcontext.options().get("disable-root-input")) { + specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == o2::tpc::LumiScaleType::TPCScaler, sclOpt.enableMShapeCorrection, sclOpt)); } o2::globaltracking::InputHelper::addInputSpecs(configcontext, specs, srcCls, srcTrc, srcTrc, useMC); o2::globaltracking::InputHelper::addInputSpecsPVertex(configcontext, specs, useMC); // P-vertex is always needed - specs.emplace_back(o2::trackstudy::getTrackingStudySpec(srcTrc, srcCls, useMC, sclOpt)); + specs.emplace_back(o2::trackstudy::getTrackingStudySpec(srcTrc, srcCls, useMC)); // configure dpl timer to inject correct firstTForbit: start from the 1st orbit of TF containing 1st sampled orbit o2::raw::HBFUtilsInitializer hbfIni(configcontext, specs); diff --git a/Detectors/ITSMFT/ITS/tracking/src/Cluster.cxx b/Detectors/ITSMFT/ITS/tracking/src/Cluster.cxx index c4d288bd61777..8c01fb25c545e 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/Cluster.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/Cluster.cxx @@ -69,9 +69,7 @@ Cluster::Cluster(const int layerIndex, const float3& primaryVertex, const IndexT GPUhd() void Cluster::print() const { -#if !defined(GPUCA_GPUCODE_DEVICE) || (!defined(__OPENCL__) && defined(GPUCA_GPU_DEBUG_PRINT)) printf("Cluster: %f %f %f %f %f %d %d\n", xCoordinate, yCoordinate, zCoordinate, phi, radius, clusterId, indexTableBinIndex); -#endif } TrackingFrameInfo::TrackingFrameInfo(float x, float y, float z, float xTF, float alpha, std::array&& posTF, @@ -83,10 +81,8 @@ TrackingFrameInfo::TrackingFrameInfo(float x, float y, float z, float xTF, float GPUhd() void TrackingFrameInfo::print() const { -#if !defined(GPUCA_GPUCODE_DEVICE) || (!defined(__OPENCL__) && defined(GPUCA_GPU_DEBUG_PRINT)) printf("x: %f y: %f z: %f xTF: %f alphaTF: %f posTF: %f %f covTF: %f %f %f\n", xCoordinate, yCoordinate, zCoordinate, xTrackingFrame, alphaTrackingFrame, positionTrackingFrame[0], positionTrackingFrame[1], covarianceTrackingFrame[0], covarianceTrackingFrame[1], covarianceTrackingFrame[2]); -#endif } diff --git a/Detectors/ITSMFT/MFT/workflow/src/TrackerSpec.cxx b/Detectors/ITSMFT/MFT/workflow/src/TrackerSpec.cxx index 3e726fe37c38c..b4ad874a8a750 100644 --- a/Detectors/ITSMFT/MFT/workflow/src/TrackerSpec.cxx +++ b/Detectors/ITSMFT/MFT/workflow/src/TrackerSpec.cxx @@ -261,7 +261,7 @@ void TrackerDPL::run(ProcessingContext& pc) rof->setFirstEntry(firstROFTrackEntry); rof->setNEntries(ntracksROF); - *rof++; + rof++; roFrameId++; } } @@ -319,7 +319,7 @@ void TrackerDPL::run(ProcessingContext& pc) copyTracks(tracksL, allTracksMFT, allClusIdx); rof->setFirstEntry(firstROFTrackEntry); rof->setNEntries(ntracksROF); - *rof++; + rof++; roFrameId++; } } diff --git a/Detectors/TPC/base/include/TPCBase/Mapper.h b/Detectors/TPC/base/include/TPCBase/Mapper.h index f2ff425675df6..6731637e2a08c 100644 --- a/Detectors/TPC/base/include/TPCBase/Mapper.h +++ b/Detectors/TPC/base/include/TPCBase/Mapper.h @@ -755,4 +755,8 @@ inline bool Mapper::isOutOfSector(GlobalPosition3D posEle, const Sector& sector, } // namespace tpc } // namespace o2 +#ifdef GPUCA_STANDALONE +#error TPC Mapper must not be used for Run2 Data +#endif + #endif diff --git a/Detectors/TPC/base/include/TPCBase/ParameterDetector.h b/Detectors/TPC/base/include/TPCBase/ParameterDetector.h index 2762f6ff67d31..e557a174ec70a 100644 --- a/Detectors/TPC/base/include/TPCBase/ParameterDetector.h +++ b/Detectors/TPC/base/include/TPCBase/ParameterDetector.h @@ -18,8 +18,7 @@ #include #include "DataFormatsTPC/Defs.h" -#include "CommonUtils/ConfigurableParam.h" -#include "CommonUtils/ConfigurableParamHelper.h" +#include "GPUCommonConfigurableParam.h" namespace o2 { diff --git a/Detectors/TPC/base/include/TPCBase/ParameterElectronics.h b/Detectors/TPC/base/include/TPCBase/ParameterElectronics.h index a44410d29ae15..8ada729f36103 100644 --- a/Detectors/TPC/base/include/TPCBase/ParameterElectronics.h +++ b/Detectors/TPC/base/include/TPCBase/ParameterElectronics.h @@ -17,9 +17,8 @@ #define ALICEO2_TPC_ParameterElectronics_H_ #include -#include "CommonUtils/ConfigurableParam.h" -#include "CommonUtils/ConfigurableParamHelper.h" #include "CommonConstants/LHCConstants.h" +#include "GPUCommonConfigurableParam.h" namespace o2::tpc { diff --git a/Detectors/TPC/base/include/TPCBase/ParameterGas.h b/Detectors/TPC/base/include/TPCBase/ParameterGas.h index d9bc65a08173a..210d8dbd14867 100644 --- a/Detectors/TPC/base/include/TPCBase/ParameterGas.h +++ b/Detectors/TPC/base/include/TPCBase/ParameterGas.h @@ -17,8 +17,7 @@ #define ALICEO2_TPC_ParameterGas_H_ #include -#include "CommonUtils/ConfigurableParam.h" -#include "CommonUtils/ConfigurableParamHelper.h" +#include "GPUCommonConfigurableParam.h" namespace o2 { diff --git a/Detectors/TPC/base/src/Mapper.cxx b/Detectors/TPC/base/src/Mapper.cxx index 2796d488f014d..75db269ee85f4 100644 --- a/Detectors/TPC/base/src/Mapper.cxx +++ b/Detectors/TPC/base/src/Mapper.cxx @@ -17,7 +17,7 @@ #include #include "TPCBase/Mapper.h" -#include "Framework/Logger.h" +#include "GPUCommonLogger.h" namespace o2 { diff --git a/Detectors/TPC/calibration/CMakeLists.txt b/Detectors/TPC/calibration/CMakeLists.txt index 27f7f0200bb92..67044c04763ac 100644 --- a/Detectors/TPC/calibration/CMakeLists.txt +++ b/Detectors/TPC/calibration/CMakeLists.txt @@ -48,7 +48,7 @@ o2_add_library(TPCCalibration src/SACParameter.cxx src/SACDrawHelper.cxx src/VDriftHelper.cxx - src/CorrectionMapsLoader.cxx + src/CorrectionMapsOptions.cxx src/SACCCDBHelper.cxx src/TPCFastSpaceChargeCorrectionHelper.cxx src/CalculatedEdx.cxx @@ -58,6 +58,7 @@ o2_add_library(TPCCalibration src/DigitAdd.cxx src/CorrectdEdxDistortions.cxx src/PressureTemperatureHelper.cxx + src/CorrectionMapsLoader.cxx PUBLIC_LINK_LIBRARIES O2::DataFormatsTPC O2::TPCBaseRecSim O2::TPCReconstruction ROOT::Minuit Microsoft.GSL::GSL @@ -115,7 +116,8 @@ o2_target_root_dictionary(TPCCalibration include/TPCCalibration/TPCMShapeCorrection.h include/TPCCalibration/DigitAdd.h include/TPCCalibration/CorrectdEdxDistortions.h - include/TPCCalibration/PressureTemperatureHelper.h) + include/TPCCalibration/PressureTemperatureHelper.h + include/TPCCalibration/CorrectionMapsLoader.h) o2_add_test_root_macro(macro/comparePedestalsAndNoise.C PUBLIC_LINK_LIBRARIES O2::TPCBaseRecSim diff --git a/Detectors/TPC/calibration/SpacePoints/include/SpacePoints/TrackResiduals.h b/Detectors/TPC/calibration/SpacePoints/include/SpacePoints/TrackResiduals.h index 2ade12d951c58..c9226589ec703 100644 --- a/Detectors/TPC/calibration/SpacePoints/include/SpacePoints/TrackResiduals.h +++ b/Detectors/TPC/calibration/SpacePoints/include/SpacePoints/TrackResiduals.h @@ -318,9 +318,14 @@ class TrackResiduals void getVoxelCoordinates(int isec, int ix, int ip, int iz, float& x, float& p, float& z) const; /// Calculates the x-coordinate for given x bin. - /// \param i Bin index + /// \param ix Bin index in x /// \return Coordinate in X - float getX(int i) const; + float getX(int ix) const; + + /// Calculates the max y/x-coordinate for given x bin taking the dead zone into account. + /// \param ix Bin index in x + /// \return Max coordinate in Y/X + float getMaxY2X(int ix) const; /// Calculates the y/x-coordinate. /// \param ix Bin index in X @@ -560,9 +565,15 @@ inline float TrackResiduals::getDXI(int ix) const } //_____________________________________________________ -inline float TrackResiduals::getX(int i) const +inline float TrackResiduals::getX(int ix) const +{ + return mUniformBins[VoxX] ? param::MinX + (ix + 0.5) * mDX : param::RowX[ix]; +} + +//_____________________________________________________ +inline float TrackResiduals::getMaxY2X(int ix) const { - return mUniformBins[VoxX] ? param::MinX + (i + 0.5) * mDX : param::RowX[i]; + return mMaxY2X[ix]; } //_____________________________________________________ diff --git a/Detectors/TPC/calibration/include/TPCCalibration/CalculatedEdx.h b/Detectors/TPC/calibration/include/TPCCalibration/CalculatedEdx.h index 3a744d2b1cfb4..4d8c4e89322a8 100644 --- a/Detectors/TPC/calibration/include/TPCCalibration/CalculatedEdx.h +++ b/Detectors/TPC/calibration/include/TPCCalibration/CalculatedEdx.h @@ -22,10 +22,9 @@ #include "DataFormatsTPC/dEdxInfo.h" #include "GPUO2InterfaceRefit.h" #include "CalibdEdxContainer.h" -#include "CorrectionMapsHelper.h" #include "CommonUtils/TreeStreamRedirector.h" #include "TPCCalibration/CorrectdEdxDistortions.h" - +#include "TPCFastTransformPOD.h" #include namespace o2::tpc @@ -225,10 +224,11 @@ class CalculatedEdx unsigned int getOccupancy(const o2::tpc::ClusterNative& cl) const; private: - std::vector* mTracks{nullptr}; ///< vector containing the tpc tracks which will be processed - std::vector* mTPCTrackClIdxVecInput{nullptr}; ///< input vector with TPC tracks cluster indicies - const o2::tpc::ClusterNativeAccess* mClusterIndex{nullptr}; ///< needed to access clusternative with tpctracks - o2::gpu::CorrectionMapsHelper mTPCCorrMapsHelper; ///< cluster correction maps helper + std::vector* mTracks{nullptr}; ///< vector containing the tpc tracks which will be processed + std::vector* mTPCTrackClIdxVecInput{nullptr}; ///< input vector with TPC tracks cluster indicies + const o2::tpc::ClusterNativeAccess* mClusterIndex{nullptr}; ///< needed to access clusternative with tpctracks + const o2::gpu::TPCFastTransformPOD* mTPCCorrMap{nullptr}; ///< cluster correction maps helper + o2::gpu::aligned_unique_buffer_ptr mTPCCorrMapBuffer; std::vector mTPCRefitterShMap; ///< externally set TPC clusters sharing map std::vector mTPCRefitterOccMap; ///< externally set TPC clusters occupancy map std::unique_ptr mRefit{nullptr}; ///< TPC refitter used for TPC tracks refit during the reconstruction @@ -247,4 +247,4 @@ class CalculatedEdx } // namespace o2::tpc -#endif \ No newline at end of file +#endif diff --git a/Detectors/TPC/calibration/include/TPCCalibration/CalibPadGainTracks.h b/Detectors/TPC/calibration/include/TPCCalibration/CalibPadGainTracks.h index b3fd532c06b8e..f8c7a4e1894b1 100644 --- a/Detectors/TPC/calibration/include/TPCCalibration/CalibPadGainTracks.h +++ b/Detectors/TPC/calibration/include/TPCCalibration/CalibPadGainTracks.h @@ -22,7 +22,6 @@ #include "TPCBase/CalDet.h" #include "TPCCalibration/CalibPadGainTracksBase.h" #include "CalibdEdxTrackTopologyPol.h" -#include "TPCFastTransform.h" #include #include @@ -36,8 +35,8 @@ namespace o2 namespace gpu { class GPUO2InterfaceRefit; -class CorrectionMapsHelper; -} +class TPCFastTransformPOD; +} // namespace gpu namespace tpc { @@ -214,7 +213,7 @@ class CalibPadGainTracks : public CalibPadGainTracksBase void setTPCVDrift(const o2::tpc::VDriftCorrFact& v); /// set cluster correction maps helper - void setTPCCorrMaps(o2::gpu::CorrectionMapsHelper* maph); + void setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD* maph); private: gsl::span* mTracks{nullptr}; ///> mDEdxBuffer{}; ///> mClTrk; /// mDedxTmp{}; /// #include -#endif #include "CorrectionMapsHelper.h" +#include "CorrectionMapsTypes.h" namespace o2 { @@ -30,26 +28,12 @@ class ProcessingContext; class ConcreteDataMatcher; class InputSpec; class ConfigParamSpec; -class ConfigParamRegistry; class InitContext; } // namespace framework namespace tpc { -struct CorrectionMapsLoaderGloOpts { - int lumiType = 0; ///< what estimator to used for corrections scaling: 0: no scaling, 1: CTP, 2: IDC - int lumiMode = 0; ///< what corrections method to use: 0: classical scaling, 1: Using of the derivative map, 2: Using of the derivative map for MC - bool enableMShapeCorrection = false; - bool requestCTPLumi = true; //< request CTP Lumi regardless of what is used for corrections scaling - bool checkCTPIDCconsistency = true; //< check the selected CTP or IDC scaling source being consistent with mean scaler of the map - - bool needTPCScalersWorkflow() const - { - return lumiType == 2 || enableMShapeCorrection; - } -}; - class CorrectionMapsLoader : public o2::gpu::CorrectionMapsHelper { public: @@ -57,30 +41,20 @@ class CorrectionMapsLoader : public o2::gpu::CorrectionMapsHelper ~CorrectionMapsLoader() = default; CorrectionMapsLoader(const CorrectionMapsLoader&) = delete; -#ifndef GPUCA_GPUCODE_DEVICE bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher& matcher, void* obj); - void extractCCDBInputs(o2::framework::ProcessingContext& pc); - void updateVDrift(float vdriftCorr, float vdrifRef, float driftTimeOffset = 0); - void init(o2::framework::InitContext& ic); - void copySettings(const CorrectionMapsLoader& src); - void updateInverse(); /// recalculate inverse correction + void extractCCDBInputs(o2::framework::ProcessingContext& pc, float tpcScaler = -1.f); + void init(o2::framework::InitContext& ic, bool idcsAvailable); void checkMeanScaleConsistency(float meanLumi, float threshold) const; - float getMapMeanRate(const o2::gpu::TPCFastTransform* mp, bool lumiOverridden) const; - static void requestCCDBInputs(std::vector& inputs, std::vector& options, const CorrectionMapsLoaderGloOpts& gloOpts); - static void addGlobalOptions(std::vector& options); - static void addOptions(std::vector& options); - static CorrectionMapsLoaderGloOpts parseGlobalOptions(const o2::framework::ConfigParamRegistry& opts); + static void requestCCDBInputs(std::vector& inputs, const o2::tpc::CorrectionMapsGloOpts& gloOpts); protected: static void addOption(std::vector& options, o2::framework::ConfigParamSpec&& osp); static void addInput(std::vector& inputs, o2::framework::InputSpec&& isp); - float mInstLumiCTPFactor = 1.0; // multiplicative factor for inst. lumi - int mLumiCTPSource = 0; // 0: main, 1: alternative CTP lumi source - std::unique_ptr mCorrMapMShape{nullptr}; + float mInstLumiCTPFactor = 1.0; // multiplicative factor for inst. lumi + int mLumiCTPSource = 0; // 0: main, 1: alternative CTP lumi source bool mIDC2CTPFallbackActive = false; // flag indicating that fallback from IDC to CTP scaling is active -#endif }; } // namespace tpc diff --git a/Detectors/TPC/calibration/include/TPCCalibration/CorrectionMapsOptions.h b/Detectors/TPC/calibration/include/TPCCalibration/CorrectionMapsOptions.h new file mode 100644 index 0000000000000..18bde0174a939 --- /dev/null +++ b/Detectors/TPC/calibration/include/TPCCalibration/CorrectionMapsOptions.h @@ -0,0 +1,56 @@ +// 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 CorrectionMapsOptions.h +/// \brief Helper class to parse options for correction maps +/// \author matthias.kleiner@cern.ch + +#ifndef TPC_CORRECTION_MAPS_OPTIONS_H_ +#define TPC_CORRECTION_MAPS_OPTIONS_H_ + +#ifndef GPUCA_GPUCODE_DEVICE +#include +#include +#endif +#include "CorrectionMapsTypes.h" + +namespace o2 +{ +namespace framework +{ +class ConfigParamRegistry; +class ConfigParamSpec; +} // namespace framework + +namespace tpc +{ + +class CorrectionMapsOptions +{ + public: + CorrectionMapsOptions() = default; + ~CorrectionMapsOptions() = default; + CorrectionMapsOptions(const CorrectionMapsOptions&) = delete; + +#ifndef GPUCA_GPUCODE_DEVICE + static CorrectionMapsGloOpts parseGlobalOptions(const o2::framework::ConfigParamRegistry& opts); + static void addGlobalOptions(std::vector& options); + + protected: + static void addOption(std::vector& options, o2::framework::ConfigParamSpec&& osp); +#endif +}; + +} // namespace tpc + +} // namespace o2 + +#endif diff --git a/Detectors/TPC/calibration/include/TPCCalibration/TPCFastSpaceChargeCorrectionHelper.h b/Detectors/TPC/calibration/include/TPCCalibration/TPCFastSpaceChargeCorrectionHelper.h index eff4972679ed8..40c5634b4f1e8 100644 --- a/Detectors/TPC/calibration/include/TPCCalibration/TPCFastSpaceChargeCorrectionHelper.h +++ b/Detectors/TPC/calibration/include/TPCCalibration/TPCFastSpaceChargeCorrectionHelper.h @@ -85,16 +85,28 @@ class TPCFastSpaceChargeCorrectionHelper const int nKnotsY = 10, const int nKnotsZ = 20); /// Create SpaceCharge correction out of the voxel tree + /// \param trackResiduals TrackResiduals object + /// \param voxResTree TTree with voxel residuals + /// \param voxResTreeInverse TTree with inverse voxel residuals + /// \param useSmoothed if true, use smoothed residuals + /// \param invertSigns if true, invert the signs of the residuals + /// \param fitPointsDirect debug: pointer to the data used for the direct correction + /// \param fitPointsInverse debug: pointer to the data used for the inverse correction + /// \return pointer to the created TPCFastSpaceChargeCorrection object + /// \note voxel trees wont be changed. They are read as non-const because of the ROOT::TTreeProcessorMT interface + /// std::unique_ptr createFromTrackResiduals( - const o2::tpc::TrackResiduals& trackResiduals, TTree* voxResTree, bool useSmoothed = false, bool invertSigns = false); + const o2::tpc::TrackResiduals& trackResiduals, TTree* voxResTree, TTree* voxResTreeInverse, // + bool useSmoothed, bool invertSigns, // + TPCFastSpaceChargeCorrectionMap* fitPointsDirect = nullptr, + TPCFastSpaceChargeCorrectionMap* fitPointsInverse = nullptr); + /// _______________ Utilities ________________________ const TPCFastTransformGeo& getGeometry() { return mGeo; } TPCFastSpaceChargeCorrectionMap& getCorrectionMap() { return mCorrectionMap; } - void fillSpaceChargeCorrectionFromMap(TPCFastSpaceChargeCorrection& correction); - void testGeometry(const TPCFastTransformGeo& geo) const; /// initialise inverse transformation @@ -103,15 +115,39 @@ class TPCFastSpaceChargeCorrectionHelper /// initialise inverse transformation from linear combination of several input corrections void initInverse(std::vector& corrections, const std::vector& scaling, bool prn); + /// merge several corrections + /// \param mainCorrection main correction + /// \param scale scaling factor for the main correction + /// \param additionalCorrections vector of pairs of additional corrections and their scaling factors + /// \param prn printout flag + /// \return main correction merged with additional corrections + void mergeCorrections( + o2::gpu::TPCFastSpaceChargeCorrection& mainCorrection, float scale, + const std::vector>& additionalCorrections, bool prn); + + /// how far the voxel mean is allowed to be outside of the voxel (1.1 means 10%) + void setVoxelMeanValidityRange(double range) + { + mVoxelMeanValidityRange = range; + } + + double getVoxelMeanValidityRange() const { return mVoxelMeanValidityRange; } + + /// debug: if true, use voxel centers instead of the fitted positions for correction + void setDebugUseVoxelCenters(); + + bool isDebugUseVoxelCenters() const { return mDebugUseVoxelCenters; } + + /// debug: if true, mirror the data from the A side to the C side of the TPC + void setDebugMirrorAdata2C(); + + bool isDebugMirrorAdata2C() const { return mDebugMirrorAdata2C; } + private: /// geometry initialization void initGeometry(); - /// get space charge correction in internal TPCFastTransform coordinates u,v->dx,du,dv - void getSpaceChargeCorrection(const TPCFastSpaceChargeCorrection& correction, int slice, int row, o2::gpu::TPCFastSpaceChargeCorrectionMap::CorrectionPoint p, double& su, double& sv, double& dx, double& du, double& dv); - - /// initialise max drift length - void initMaxDriftLength(o2::gpu::TPCFastSpaceChargeCorrection& correction, bool prn); + void fillSpaceChargeCorrectionFromMap(TPCFastSpaceChargeCorrection& correction, bool processingInverseCorrection); static TPCFastSpaceChargeCorrectionHelper* sInstance; ///< singleton instance bool mIsInitialized = 0; ///< initialization flag @@ -120,6 +156,11 @@ class TPCFastSpaceChargeCorrectionHelper TPCFastSpaceChargeCorrectionMap mCorrectionMap{0, 0}; + double mVoxelMeanValidityRange{1.1}; ///< debug: how far the voxel mean is allowed to be outside of the voxel (1.1 means 10%) + + bool mDebugUseVoxelCenters{false}; ///< debug: if true, use voxel centers instead of the fitted positions for correction + bool mDebugMirrorAdata2C{false}; ///< debug: if true, mirror the data from the A side to the C side of the TPC + ClassDefNV(TPCFastSpaceChargeCorrectionHelper, 0); }; diff --git a/Detectors/TPC/calibration/include/TPCCalibration/TrackDump.h b/Detectors/TPC/calibration/include/TPCCalibration/TrackDump.h index 34ad5b85a1eed..adbf3ecf5a299 100644 --- a/Detectors/TPC/calibration/include/TPCCalibration/TrackDump.h +++ b/Detectors/TPC/calibration/include/TPCCalibration/TrackDump.h @@ -24,7 +24,7 @@ #include "SimulationDataFormat/MCCompLabel.h" #include "CommonUtils/TreeStreamRedirector.h" #include "DataFormatsTPC/Constants.h" -#include "CorrectionMapsHelper.h" +#include "TPCFastTransformPOD.h" /// \file TrackDump.h /// \author Jens Wiechula (Jens.Wiechula@ikf.uni-frankfurt.de) @@ -77,14 +77,15 @@ class TrackDump float gyc(float vertexTime = 0) const; float zc(float vertexTime = 0) const; - static gpu::CorrectionMapsHelper sCorrHelper; + inline static o2::gpu::aligned_unique_buffer_ptr corrMapBuffer; // buffer for owning the correction map in case of update during runtime + inline static const o2::gpu::TPCFastTransformPOD* corrMap{nullptr}; // local copy of the correction map for quick access to the transform functions static void loadCorrMaps(std::string_view corrMapFile, std::string_view corrMapFileRef = ""); ClassDefNV(ClusterNativeAdd, 1); }; struct TrackInfo : public TrackTPC { TrackInfo() = default; - TrackInfo(const TrackTPC& track) : TrackTPC(track){}; + TrackInfo(const TrackTPC& track) : TrackTPC(track) {}; TrackInfo(const TrackInfo&) = default; ~TrackInfo() = default; diff --git a/Detectors/TPC/calibration/src/CalculatedEdx.cxx b/Detectors/TPC/calibration/src/CalculatedEdx.cxx index 478acda1189c2..396214775eb76 100644 --- a/Detectors/TPC/calibration/src/CalculatedEdx.cxx +++ b/Detectors/TPC/calibration/src/CalculatedEdx.cxx @@ -32,8 +32,10 @@ using namespace o2::tpc; CalculatedEdx::CalculatedEdx() { - mTPCCorrMapsHelper.setOwner(true); - mTPCCorrMapsHelper.setCorrMap(TPCFastTransformHelperO2::instance()->create(0)); + gpu::aligned_unique_buffer_ptr buffer; + gpu::TPCFastTransformPOD::create(buffer, *TPCFastTransformHelperO2::instance()->create(0)); + mTPCCorrMapBuffer = std::move(buffer); + mTPCCorrMap = mTPCCorrMapBuffer.get(); } void CalculatedEdx::setMembers(std::vector* tpcTrackClIdxVecInput, const o2::tpc::ClusterNativeAccess& clIndex, std::vector* vTPCTracksArrayInp) @@ -50,7 +52,7 @@ void CalculatedEdx::setRefit(const unsigned int nHbfPerTf) mTPCRefitterOccMap.resize(sizeOcc); std::fill(mTPCRefitterOccMap.begin(), mTPCRefitterOccMap.end(), 0); o2::gpu::GPUO2InterfaceRefit::fillSharedClustersAndOccupancyMap(mClusterIndex, *mTracks, mTPCTrackClIdxVecInput->data(), mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), nHbfPerTf); - mRefit = std::make_unique(mClusterIndex, &mTPCCorrMapsHelper, mFieldNominalGPUBz, mTPCTrackClIdxVecInput->data(), nHbfPerTf, mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), mTPCRefitterOccMap.size()); + mRefit = std::make_unique(mClusterIndex, mTPCCorrMap, mFieldNominalGPUBz, mTPCTrackClIdxVecInput->data(), nHbfPerTf, mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), mTPCRefitterOccMap.size()); } void CalculatedEdx::fillMissingClusters(int missingClusters[4], float minChargeTot, float minChargeMax, int method, std::array, 5>& chargeTotROC, std::array, 5>& chargeMaxROC) diff --git a/Detectors/TPC/calibration/src/CalibPadGainTracks.cxx b/Detectors/TPC/calibration/src/CalibPadGainTracks.cxx index 094de6b830272..37400a28e4670 100644 --- a/Detectors/TPC/calibration/src/CalibPadGainTracks.cxx +++ b/Detectors/TPC/calibration/src/CalibPadGainTracks.cxx @@ -19,7 +19,7 @@ #include "TPCBase/ROC.h" #include "TPCBase/Mapper.h" #include "TPCCalibration/IDCDrawHelper.h" -#include "CorrectionMapsHelper.h" +#include "TPCFastTransformPOD.h" #include "TPCReconstruction/TPCFastTransformHelperO2.h" #include "GPUO2InterfaceRefit.h" #include "GPUO2ExternalUser.h" @@ -37,7 +37,7 @@ void CalibPadGainTracks::processTracks(const int nMaxTracks) { std::unique_ptr refit; if (!mPropagateTrack) { - refit = std::make_unique(mClusterIndex, mTPCCorrMapsHelper, mFieldNominalGPUBz, mTPCTrackClIdxVecInput->data(), 0, mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), mTPCRefitterOccMap.size()); + refit = std::make_unique(mClusterIndex, mTPCCorrMaps, mFieldNominalGPUBz, mTPCTrackClIdxVecInput->data(), 0, mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), mTPCRefitterOccMap.size()); } const size_t loopEnd = (nMaxTracks < 0) ? mTracks->size() : ((nMaxTracks > mTracks->size()) ? mTracks->size() : size_t(nMaxTracks)); @@ -407,7 +407,7 @@ void CalibPadGainTracks::setTPCVDrift(const o2::tpc::VDriftCorrFact& v) } //______________________________________________ -void CalibPadGainTracks::setTPCCorrMaps(o2::gpu::CorrectionMapsHelper* maph) +void CalibPadGainTracks::setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD* maph) { - mTPCCorrMapsHelper = maph; + mTPCCorrMaps = maph; } diff --git a/Detectors/TPC/calibration/src/CorrectdEdxDistortions.cxx b/Detectors/TPC/calibration/src/CorrectdEdxDistortions.cxx index 73599e744483c..fc60c422d83f4 100644 --- a/Detectors/TPC/calibration/src/CorrectdEdxDistortions.cxx +++ b/Detectors/TPC/calibration/src/CorrectdEdxDistortions.cxx @@ -87,7 +87,7 @@ float o2::tpc::CorrectdEdxDistortions::getCorrection(const float time, unsigned const float ly = mTPCGeometry.LinearPad2Y(sector, padrow, pad); // get correction at "pad + 0.5*padlength" pos1 and dont extrapolate/interpolate across GEM gaps - const int row1 = ((padrow == mTPCGeometry.EndIROC() - 1) || (padrow == mTPCGeometry.EndOROC1() - 1) || (padrow == mTPCGeometry.EndOROC2() - 1)) ? padrow : std::clamp(padrow + 1, 0, GPUCA_ROW_COUNT - 1); + const int row1 = ((padrow == mTPCGeometry.EndIROC() - 1) || (padrow == mTPCGeometry.EndOROC1() - 1) || (padrow == mTPCGeometry.EndOROC2() - 1)) ? padrow : std::clamp(padrow + 1, 0, o2::tpc::constants::MAXGLOBALPADROW - 1); float lxT_1 = 0; float lyT_1 = 0; @@ -101,7 +101,7 @@ float o2::tpc::CorrectdEdxDistortions::getCorrection(const float time, unsigned const float r_1_f = std::sqrt(lxT_1 * lxT_1 + lyT_1 * lyT_1); // get correction at "pad - 0.5*padlength" pos0 and dont extrapolate/interpolate across GEM gaps - const int row0 = ((padrow == mTPCGeometry.EndIROC()) || (padrow == mTPCGeometry.EndOROC1()) || (padrow == mTPCGeometry.EndOROC2())) ? padrow : std::clamp(padrow - 1, 0, GPUCA_ROW_COUNT - 1); + const int row0 = ((padrow == mTPCGeometry.EndIROC()) || (padrow == mTPCGeometry.EndOROC1()) || (padrow == mTPCGeometry.EndOROC2())) ? padrow : std::clamp(padrow - 1, 0, o2::tpc::constants::MAXGLOBALPADROW - 1); // check if previous pad row has enough pads const unsigned char pad0 = std::clamp(static_cast(pad), 0, mTPCGeometry.NPads(row0) - 1); diff --git a/Detectors/TPC/calibration/src/CorrectionMapsLoader.cxx b/Detectors/TPC/calibration/src/CorrectionMapsLoader.cxx index 038fe3c34e140..9569e0eb8abd2 100644 --- a/Detectors/TPC/calibration/src/CorrectionMapsLoader.cxx +++ b/Detectors/TPC/calibration/src/CorrectionMapsLoader.cxx @@ -11,39 +11,21 @@ #include "TPCCalibration/CorrectionMapsLoader.h" #include "TPCCalibration/CorrMapParam.h" -#include "TPCReconstruction/TPCFastTransformHelperO2.h" -#include "TPCBaseRecSim/CDBInterface.h" +#include "TPCBaseRecSim/CDBTypes.h" #include "Framework/Logger.h" #include "Framework/ProcessingContext.h" #include "Framework/CCDBParamSpec.h" -#include "Framework/InputRecord.h" #include "Framework/ConfigParamSpec.h" #include "Framework/ConcreteDataMatcher.h" #include "Framework/InitContext.h" #include "Framework/DeviceSpec.h" -#include "Framework/ConfigParamRegistry.h" #include "DataFormatsCTP/LumiInfo.h" -#include "TPCCalibration/TPCFastSpaceChargeCorrectionHelper.h" using namespace o2::tpc; using namespace o2::framework; -#ifndef GPUCA_GPUCODE_DEVICE - //________________________________________________________ -void CorrectionMapsLoader::updateVDrift(float vdriftCorr, float vdrifRef, float driftTimeOffset) -{ - o2::tpc::TPCFastTransformHelperO2::instance()->updateCalibration(*mCorrMap, 0, vdriftCorr, vdrifRef, driftTimeOffset); - if (mCorrMapRef) { - o2::tpc::TPCFastTransformHelperO2::instance()->updateCalibration(*mCorrMapRef, 0, vdriftCorr, vdrifRef, driftTimeOffset); - } - if (mCorrMapMShape) { - o2::tpc::TPCFastTransformHelperO2::instance()->updateCalibration(*mCorrMapMShape, 0, vdriftCorr, vdrifRef, driftTimeOffset); - } -} - -//________________________________________________________ -void CorrectionMapsLoader::extractCCDBInputs(ProcessingContext& pc) +void CorrectionMapsLoader::extractCCDBInputs(ProcessingContext& pc, float tpcScaler) { pc.inputs().get("tpcCorrPar"); pc.inputs().get("tpcCorrMap"); @@ -53,8 +35,7 @@ void CorrectionMapsLoader::extractCCDBInputs(ProcessingContext& pc) o2::ctp::LumiInfo lumiObj; static o2::ctp::LumiInfo lumiPrev; - if (getLumiScaleType() == 2 || mIDC2CTPFallbackActive) { - float tpcScaler = pc.inputs().get("tpcscaler"); + if (getLumiScaleType() == LumiScaleType::TPCScaler || mIDC2CTPFallbackActive) { // check if tpcScaler is valid and CTP fallback is allowed if (tpcScaler == -1.f) { const bool canUseCTPScaling = mCorrMap && mCorrMapRef && mCorrMap->isIDCSet() && mCorrMapRef->isIDCSet() && mCorrMap->isLumiSet() && mCorrMapRef->isLumiSet(); @@ -63,7 +44,7 @@ void CorrectionMapsLoader::extractCCDBInputs(ProcessingContext& pc) mIDC2CTPFallbackActive = true; setMeanLumi(mCorrMap->getLumi(), false); setMeanLumiRef(mCorrMapRef->getLumi()); - setLumiScaleType(1); + setLumiScaleType(LumiScaleType::CTPLumi); } else if (mCorrMap) { // CTP scaling is not possible, dont do any scaling to avoid applying wrong corrections const float storedIDC = mCorrMap->getIDC(); @@ -77,7 +58,7 @@ void CorrectionMapsLoader::extractCCDBInputs(ProcessingContext& pc) mIDC2CTPFallbackActive = false; setMeanLumi(mCorrMap->getIDC(), false); setMeanLumiRef(mCorrMapRef->getIDC()); - setLumiScaleType(2); + setLumiScaleType(LumiScaleType::TPCScaler); } // correct IDC received setInstLumi(tpcScaler); @@ -94,38 +75,25 @@ void CorrectionMapsLoader::extractCCDBInputs(ProcessingContext& pc) lumiObj = lumiPrev; } setInstLumiCTP(mInstLumiCTPFactor * (mLumiCTPSource == 0 ? lumiObj.getLumi() : lumiObj.getLumiAlt())); - if (getLumiScaleType() == 1) { + if (getLumiScaleType() == LumiScaleType::CTPLumi) { setInstLumi(getInstLumiCTP()); } } - if (getUseMShapeCorrection()) { - LOGP(info, "Setting M-Shape map"); - const auto mapMShape = pc.inputs().get("mshape"); - const_cast(mapMShape.get())->rectifyAfterReadingFromFile(); - mCorrMapMShape = std::unique_ptr(new TPCFastTransform); - mCorrMapMShape->cloneFromObject(*(mapMShape.get()), nullptr); - setCorrMapMShape(mCorrMapMShape.get()); - setUpdatedMapMShape(); - } - - // update inverse in case it is requested - if (!mScaleInverse) { - updateInverse(); - } reportScaling(); } //________________________________________________________ -void CorrectionMapsLoader::requestCCDBInputs(std::vector& inputs, std::vector& options, const CorrectionMapsLoaderGloOpts& gloOpts) +void CorrectionMapsLoader::requestCCDBInputs(std::vector& inputs, const CorrectionMapsGloOpts& gloOpts) { - if (gloOpts.lumiMode == 0) { + LOGP(info, "Requesting CCDB inputs for TPC correction maps with lumiType={} and lumiMode={}", static_cast(gloOpts.lumiType), static_cast(gloOpts.lumiMode)); + if (gloOpts.lumiMode == LumiScaleMode::Linear) { addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMap), {}, 1)}); // time-dependent addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMapRef), {}, 0)}); // load once - } else if (gloOpts.lumiMode == 1) { + } else if (gloOpts.lumiMode == LumiScaleMode::DerivativeMap) { addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMap), {}, 1)}); // time-dependent addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrDerivMap), {}, 1)}); // time-dependent - } else if (gloOpts.lumiMode == 2) { + } else if (gloOpts.lumiMode == LumiScaleMode::DerivativeMapMC) { // for MC corrections addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMapMC), {}, 1)}); // time-dependent addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrDerivMapMC), {}, 1)}); // time-dependent @@ -137,51 +105,7 @@ void CorrectionMapsLoader::requestCCDBInputs(std::vector& inputs, std addInput(inputs, {"CTPLumi", "CTP", "LUMI", 0, Lifetime::Timeframe}); } - if (gloOpts.lumiType == 2) { - addInput(inputs, {"tpcscaler", o2::header::gDataOriginTPC, "TPCSCALER", 0, Lifetime::Timeframe}); - } - addInput(inputs, {"tpcCorrPar", "TPC", "CorrMapParam", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CorrMapParam), {}, 0)}); // load once - - if (gloOpts.enableMShapeCorrection) { - addInput(inputs, {"mshape", o2::header::gDataOriginTPC, "TPCMSHAPE", 0, Lifetime::Timeframe}); - } - addOptions(options); -} - -//________________________________________________________ -void CorrectionMapsLoader::addOptions(std::vector& options) -{ - // these are options which should be added at the level of device using TPC corrections - // At the moment - nothing, all options are moved to configurable param CorrMapParam - addOption(options, ConfigParamSpec{"recalculate-inverse-correction", o2::framework::VariantType::Bool, false, {"recalculate the inverse correction in case lumi mode 1 or 2 is used"}}); - addOption(options, ConfigParamSpec{"nthreads-inverse-correction", o2::framework::VariantType::Int, 4, {"Number of threads used for calculating the inverse correction (-1=all threads)"}}); -} - -//________________________________________________________ -void CorrectionMapsLoader::addGlobalOptions(std::vector& options) -{ - // these are options which should be added at the workflow level, since they modify the inputs of the devices - addOption(options, ConfigParamSpec{"lumi-type", o2::framework::VariantType::Int, 0, {"1 = use CTP lumi for TPC correction scaling, 2 = use TPC scalers for TPC correction scaling"}}); - addOption(options, ConfigParamSpec{"corrmap-lumi-mode", o2::framework::VariantType::Int, 0, {"scaling mode: (default) 0 = static + scale * full; 1 = full + scale * derivative; 2 = full + scale * derivative (for MC)"}}); - addOption(options, ConfigParamSpec{"enable-M-shape-correction", o2::framework::VariantType::Bool, false, {"Enable M-shape distortion correction"}}); - addOption(options, ConfigParamSpec{"disable-ctp-lumi-request", o2::framework::VariantType::Bool, false, {"do not request CTP lumi (regardless what is used for corrections)"}}); - addOption(options, ConfigParamSpec{"disable-lumi-type-consistency-check", o2::framework::VariantType::Bool, false, {"disable check of selected CTP or IDC scaling source being consistent with the map"}}); -} - -//________________________________________________________ -CorrectionMapsLoaderGloOpts CorrectionMapsLoader::parseGlobalOptions(const o2::framework::ConfigParamRegistry& opts) -{ - CorrectionMapsLoaderGloOpts tpcopt; - tpcopt.lumiType = opts.get("lumi-type"); - tpcopt.lumiMode = opts.get("corrmap-lumi-mode"); - tpcopt.enableMShapeCorrection = opts.get("enable-M-shape-correction"); - tpcopt.requestCTPLumi = !opts.get("disable-ctp-lumi-request"); - tpcopt.checkCTPIDCconsistency = !opts.get("disable-lumi-type-consistency-check"); - if (!tpcopt.requestCTPLumi && tpcopt.lumiType == 1) { - LOGP(fatal, "Scaling with CTP Lumi is requested but this input is disabled"); - } - return tpcopt; } //________________________________________________________ @@ -208,18 +132,18 @@ bool CorrectionMapsLoader::accountCCDBInputs(const ConcreteDataMatcher& matcher, mCorrMap->rectifyAfterReadingFromFile(); mCorrMap->setCTP2IDCFallBackThreshold(o2::tpc::CorrMapParam::Instance().CTP2IDCFallBackThreshold); if (getMeanLumiOverride() != 0) { - if (getLumiScaleType() == 1) { + if (getLumiScaleType() == LumiScaleType::CTPLumi) { mCorrMap->setLumi(getMeanLumiOverride()); LOGP(info, "CorrMap mean lumi rate is overridden to {}", mCorrMap->getLumi()); - } else if (getLumiScaleType() == 2) { + } else if (getLumiScaleType() == LumiScaleType::TPCScaler) { mCorrMap->setIDC(getMeanLumiOverride()); LOGP(info, "CorrMap mean IDC rate is overridden to {}", mCorrMap->getIDC()); } } float mapMeanRate = 0; - if (getLumiScaleType() == 1) { + if (getLumiScaleType() == LumiScaleType::CTPLumi) { mapMeanRate = mCorrMap->getLumi(); - } else if (getLumiScaleType() == 2) { + } else if (getLumiScaleType() == LumiScaleType::TPCScaler) { mapMeanRate = mCorrMap->getIDC(); } if (mCheckCTPIDCConsistency) { @@ -237,18 +161,18 @@ bool CorrectionMapsLoader::accountCCDBInputs(const ConcreteDataMatcher& matcher, mCorrMapRef->rectifyAfterReadingFromFile(); mCorrMapRef->setCTP2IDCFallBackThreshold(o2::tpc::CorrMapParam::Instance().CTP2IDCFallBackThreshold); if (getMeanLumiRefOverride() != 0) { - if (getLumiScaleType() == 1) { + if (getLumiScaleType() == LumiScaleType::CTPLumi) { mCorrMapRef->setLumi(getMeanLumiRefOverride()); LOGP(info, "CorrMapRef mean lumi rate is overridden to {}", mCorrMapRef->getLumi()); - } else if (getLumiScaleType() == 2) { + } else if (getLumiScaleType() == LumiScaleType::TPCScaler) { mCorrMapRef->setIDC(getMeanLumiRefOverride()); LOGP(info, "CorrMapRef mean IDC rate is overridden to {}", mCorrMapRef->getIDC()); } } float mapRefMeanRate = 0; - if (getLumiScaleType() == 1) { + if (getLumiScaleType() == LumiScaleType::CTPLumi) { mapRefMeanRate = mCorrMapRef->getLumi(); - } else if (getLumiScaleType() == 2) { + } else if (getLumiScaleType() == LumiScaleType::TPCScaler) { mapRefMeanRate = mCorrMapRef->getIDC(); } if (mCheckCTPIDCConsistency) { @@ -277,12 +201,12 @@ bool CorrectionMapsLoader::accountCCDBInputs(const ConcreteDataMatcher& matcher, } if (mInstCTPLumiOverride != 0.) { setInstLumiCTP(mInstCTPLumiOverride * mInstLumiCTPFactor); - if (getLumiScaleType() == 1) { + if (getLumiScaleType() == LumiScaleType::CTPLumi) { setInstLumi(getInstLumiCTP(), false); } } setUpdatedLumi(); - int scaleType = getLumiScaleType(); + int scaleType = static_cast(getLumiScaleType()); const std::array lumiS{"OFF", "CTP", "TPC scaler"}; if (scaleType >= lumiS.size()) { LOGP(fatal, "Wrong corrmap-lumi-mode provided!"); @@ -290,92 +214,39 @@ bool CorrectionMapsLoader::accountCCDBInputs(const ConcreteDataMatcher& matcher, LOGP(info, "TPC correction map params updated: SP corrections: {} (corr.map scaling type={}, override values: lumiMean={} lumiRefMean={} lumiScaleMode={}), CTP Lumi: source={} lumiInstOverride={} , LumiInst scale={} ", canUseCorrections() ? "ON" : "OFF", - lumiS[scaleType], mMeanLumiOverride, mMeanLumiRefOverride, mLumiScaleMode, mLumiCTPSource, mInstCTPLumiOverride, mInstLumiCTPFactor); + lumiS[scaleType], mMeanLumiOverride, mMeanLumiRefOverride, static_cast(getLumiScaleMode()), mLumiCTPSource, mInstCTPLumiOverride, mInstLumiCTPFactor); } return false; } //________________________________________________________ -void CorrectionMapsLoader::init(o2::framework::InitContext& ic) +void CorrectionMapsLoader::init(o2::framework::InitContext& ic, bool idcsAvailable) { - if (getLumiScaleMode() < 0) { + if (getLumiScaleMode() == LumiScaleMode::Unset) { LOGP(fatal, "TPC correction lumi scaling mode is not set"); } const auto& inputRouts = ic.services().get().inputs; - bool foundCTP = false, foundTPCScl = false, foundMShape = false; + bool foundCTP = false; for (const auto& route : inputRouts) { if (route.matcher == InputSpec{"CTPLumi", "CTP", "LUMI", 0, Lifetime::Timeframe}) { foundCTP = true; - } else if (route.matcher == InputSpec{"tpcscaler", o2::header::gDataOriginTPC, "TPCSCALER", 0, Lifetime::Timeframe}) { - foundTPCScl = true; - } else if (route.matcher == InputSpec{"mshape", o2::header::gDataOriginTPC, "TPCMSHAPE", 0, Lifetime::Timeframe}) { - foundMShape = true; } } setLumiCTPAvailable(foundCTP); - enableMShapeCorrection(foundMShape); - if ((getLumiScaleType() == 1 && !foundCTP) || (getLumiScaleType() == 2 && !foundTPCScl)) { - LOGP(fatal, "Lumi scaling source {}({}) is not available for TPC correction", getLumiScaleType(), getLumiScaleType() == 1 ? "CTP" : "TPCScaler"); - } - - if ((getLumiScaleMode() == 1) || (getLumiScaleMode() == 2)) { - mScaleInverse = !(ic.options().get("recalculate-inverse-correction")); - } else { - mScaleInverse = true; - } - const int nthreadsInv = (ic.options().get("nthreads-inverse-correction")); - (nthreadsInv < 0) ? TPCFastSpaceChargeCorrectionHelper::instance()->setNthreadsToMaximum() : TPCFastSpaceChargeCorrectionHelper::instance()->setNthreads(nthreadsInv); -} - -//________________________________________________________ -void CorrectionMapsLoader::copySettings(const CorrectionMapsLoader& src) -{ - setInstLumi(src.getInstLumi(), false); - setInstLumiCTP(src.getInstLumiCTP()); - setMeanLumi(src.getMeanLumi(), false); - setLumiCTPAvailable(src.getLumiCTPAvailable()); - setMeanLumiRef(src.getMeanLumiRef()); - setLumiScaleType(src.getLumiScaleType()); - setMeanLumiOverride(src.getMeanLumiOverride()); - setMeanLumiRefOverride(src.getMeanLumiRefOverride()); - setInstCTPLumiOverride(src.getInstCTPLumiOverride()); - setLumiScaleMode(src.getLumiScaleMode()); - enableMShapeCorrection(src.getUseMShapeCorrection()); - mInstLumiCTPFactor = src.mInstLumiCTPFactor; - mLumiCTPSource = src.mLumiCTPSource; - mLumiScaleMode = src.mLumiScaleMode; - mScaleInverse = src.getScaleInverse(); - mIDC2CTPFallbackActive = src.mIDC2CTPFallbackActive; -} - -void CorrectionMapsLoader::updateInverse() -{ - if (mLumiScaleMode == 1 || mLumiScaleMode == 2) { - LOGP(info, "Recalculating the inverse correction"); - setUpdatedMap(); - std::vector scaling{1, mLumiScale}; - std::vector corr{&(mCorrMap->getCorrection()), &(mCorrMapRef->getCorrection())}; - if (mCorrMapMShape) { - scaling.emplace_back(1); - corr.emplace_back(&(mCorrMapMShape->getCorrection())); - } - TPCFastSpaceChargeCorrectionHelper::instance()->initInverse(corr, scaling, false); - } else { - LOGP(info, "Reinitializing inverse correction with lumi scale mode {} not supported for now", mLumiScaleMode); + if ((getLumiScaleType() == LumiScaleType::CTPLumi && !foundCTP) || (getLumiScaleType() == LumiScaleType::TPCScaler && !idcsAvailable)) { + LOGP(fatal, "Lumi scaling source {}({}) is not available for TPC correction", static_cast(getLumiScaleType()), getLumiScaleType() == LumiScaleType::CTPLumi ? "CTP" : "TPCScaler"); } } void CorrectionMapsLoader::checkMeanScaleConsistency(float meanLumi, float threshold) const { - if (getLumiScaleType() == 1) { + if (getLumiScaleType() == LumiScaleType::CTPLumi) { if (meanLumi < threshold) { LOGP(fatal, "CTP Lumi scaling source is requested, but the map mean scale {} is below the threshold {}", meanLumi, threshold); } - } else if (getLumiScaleType() == 2) { + } else if (getLumiScaleType() == LumiScaleType::TPCScaler) { if (meanLumi > threshold) { LOGP(fatal, "IDC scaling source is requested, but the map mean scale {} is above the threshold {}", meanLumi, threshold); } } } - -#endif // #ifndef GPUCA_GPUCODE_DEVICE diff --git a/Detectors/TPC/calibration/src/CorrectionMapsOptions.cxx b/Detectors/TPC/calibration/src/CorrectionMapsOptions.cxx new file mode 100644 index 0000000000000..604b7c680385b --- /dev/null +++ b/Detectors/TPC/calibration/src/CorrectionMapsOptions.cxx @@ -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. + +#include "TPCCalibration/CorrectionMapsOptions.h" +#include "Framework/Logger.h" +#include "Framework/ConfigParamSpec.h" +#include "Framework/ConfigParamRegistry.h" +using namespace o2::tpc; +using namespace o2::framework; + +//________________________________________________________ +CorrectionMapsGloOpts CorrectionMapsOptions::parseGlobalOptions(const o2::framework::ConfigParamRegistry& opts) +{ + CorrectionMapsGloOpts tpcopt; + auto lumiTypeVal = opts.get("lumi-type"); + if (lumiTypeVal < -1 || lumiTypeVal > 2) { + LOGP(fatal, "Invalid lumi-type value: {}", lumiTypeVal); + } + tpcopt.lumiType = static_cast(lumiTypeVal); + + auto lumiModeVal = opts.get("corrmap-lumi-mode"); + if (lumiModeVal < -1 || lumiModeVal > 2) { + LOGP(fatal, "Invalid corrmap-lumi-mode value: {}", lumiModeVal); + } + tpcopt.lumiMode = static_cast(lumiModeVal); + + tpcopt.enableMShapeCorrection = opts.get("enable-M-shape-correction"); + tpcopt.requestCTPLumi = !opts.get("disable-ctp-lumi-request"); + tpcopt.checkCTPIDCconsistency = !opts.get("disable-lumi-type-consistency-check"); + if (!tpcopt.requestCTPLumi && tpcopt.lumiType == LumiScaleType::CTPLumi) { + LOGP(fatal, "Scaling with CTP Lumi is requested but this input is disabled"); + } + return tpcopt; +} + +void CorrectionMapsOptions::addGlobalOptions(std::vector& options) +{ + // these are options which should be added at the workflow level, since they modify the inputs of the devices + addOption(options, ConfigParamSpec{"lumi-type", o2::framework::VariantType::Int, 0, {"1 = use CTP lumi for TPC correction scaling, 2 = use TPC scalers for TPC correction scaling"}}); + addOption(options, ConfigParamSpec{"corrmap-lumi-mode", o2::framework::VariantType::Int, 0, {"scaling mode: (default) 0 = static + scale * full; 1 = full + scale * derivative; 2 = full + scale * derivative (for MC)"}}); + addOption(options, ConfigParamSpec{"enable-M-shape-correction", o2::framework::VariantType::Bool, false, {"Enable M-shape distortion correction"}}); + addOption(options, ConfigParamSpec{"disable-ctp-lumi-request", o2::framework::VariantType::Bool, false, {"do not request CTP lumi (regardless what is used for corrections)"}}); + addOption(options, ConfigParamSpec{"disable-lumi-type-consistency-check", o2::framework::VariantType::Bool, false, {"disable check of selected CTP or IDC scaling source being consistent with the map"}}); +} + +void CorrectionMapsOptions::addOption(std::vector& options, ConfigParamSpec&& osp) +{ + if (std::find(options.begin(), options.end(), osp) == options.end()) { + options.emplace_back(osp); + } +} diff --git a/Detectors/TPC/calibration/src/TPCFastSpaceChargeCorrectionHelper.cxx b/Detectors/TPC/calibration/src/TPCFastSpaceChargeCorrectionHelper.cxx index e2960c73e4d50..783c1837590b9 100644 --- a/Detectors/TPC/calibration/src/TPCFastSpaceChargeCorrectionHelper.cxx +++ b/Detectors/TPC/calibration/src/TPCFastSpaceChargeCorrectionHelper.cxx @@ -29,6 +29,11 @@ #include #include #include "TStopwatch.h" +#include "TTreeReader.h" +#include "TTreeReaderValue.h" +#include "ROOT/TTreeProcessorMT.hxx" +#include +#include using namespace o2::gpu; @@ -60,12 +65,8 @@ void TPCFastSpaceChargeCorrectionHelper::initGeometry() mGeo.startConstruction(nRows); auto& detParam = ParameterDetector::Instance(); - float tpcZlengthSideA = detParam.TPClength; - float tpcZlengthSideC = detParam.TPClength; - mGeo.setTPCzLength(tpcZlengthSideA, tpcZlengthSideC); - - mGeo.setTPCalignmentZ(0.); + mGeo.setTPCzLength(detParam.TPClength); for (int iRow = 0; iRow < mGeo.getNumberOfRows(); iRow++) { Sector sector = 0; @@ -113,11 +114,13 @@ void TPCFastSpaceChargeCorrectionHelper::setNthreadsToMaximum() } } -void TPCFastSpaceChargeCorrectionHelper::fillSpaceChargeCorrectionFromMap(TPCFastSpaceChargeCorrection& correction) +void TPCFastSpaceChargeCorrectionHelper::fillSpaceChargeCorrectionFromMap(TPCFastSpaceChargeCorrection& correction, bool processingInverseCorrection) { // calculate correction map: dx,du,dv = ( origTransform() -> x,u,v) - fastTransformNominal:x,u,v // for the future: switch TOF correction off for a while + TStopwatch watch; + if (!mIsInitialized) { initGeometry(); } @@ -129,36 +132,68 @@ void TPCFastSpaceChargeCorrectionHelper::fillSpaceChargeCorrectionFromMap(TPCFas LOG(info) << "fast space charge correction helper: init from data points"; - for (int slice = 0; slice < correction.getGeometry().getNumberOfSlices(); slice++) { + for (int sector = 0; sector < correction.getGeometry().getNumberOfSectors(); sector++) { auto myThread = [&](int iThread) { for (int row = iThread; row < correction.getGeometry().getNumberOfRows(); row += mNthreads) { - TPCFastSpaceChargeCorrection::SplineType& spline = correction.getSpline(slice, row); + TPCFastSpaceChargeCorrection::SplineType& spline = correction.getSpline(sector, row); Spline2DHelper helper; - float* splineParameters = correction.getSplineData(slice, row); - const std::vector& data = mCorrectionMap.getPoints(slice, row); + std::vector splineParameters; + splineParameters.resize(spline.getNumberOfParameters()); + + const std::vector& data = mCorrectionMap.getPoints(sector, row); int nDataPoints = data.size(); + auto& info = correction.getSectorRowInfo(sector, row); + if (!processingInverseCorrection) { + info.resetMaxValues(); + } + info.updateMaxValues(1., 1., 1.); + info.updateMaxValues(-1., -1., -1.); + if (nDataPoints >= 4) { - std::vector pointSU(nDataPoints); - std::vector pointSV(nDataPoints); + std::vector pointGU(nDataPoints); + std::vector pointGV(nDataPoints); + std::vector pointWeight(nDataPoints); std::vector pointCorr(3 * nDataPoints); // 3 dimensions for (int i = 0; i < nDataPoints; ++i) { - double su, sv, dx, du, dv; - getSpaceChargeCorrection(correction, slice, row, data[i], su, sv, dx, du, dv); - pointSU[i] = su; - pointSV[i] = sv; - pointCorr[3 * i + 0] = dx; - pointCorr[3 * i + 1] = du; - pointCorr[3 * i + 2] = dv; + o2::gpu::TPCFastSpaceChargeCorrectionMap::CorrectionPoint p = data[i]; + // not corrected grid coordinates + float gu, gv, scale; + correction.convLocalToGrid(sector, row, p.mY, p.mZ, gu, gv, scale); + if (scale - 1.f > 1.e-6) { // point is outside the grid + continue; + } + pointGU[i] = gu; + pointGV[i] = gv; + pointWeight[i] = p.mWeight; + pointCorr[3 * i + 0] = p.mDx; + pointCorr[3 * i + 1] = p.mDy; + pointCorr[3 * i + 2] = p.mDz; + info.updateMaxValues(5. * p.mDx, 5. * p.mDy, 5. * p.mDz); } - helper.approximateDataPoints(spline, splineParameters, 0., spline.getGridX1().getNumberOfKnots() - 1, 0., spline.getGridX2().getNumberOfKnots() - 1, &pointSU[0], - &pointSV[0], &pointCorr[0], nDataPoints); + helper.approximateDataPoints(spline, splineParameters.data(), 0., spline.getGridX1().getUmax(), 0., spline.getGridX2().getUmax(), pointGU.data(), + pointGV.data(), pointCorr.data(), pointWeight.data(), nDataPoints); } else { for (int i = 0; i < spline.getNumberOfParameters(); i++) { splineParameters[i] = 0.f; } } + + if (processingInverseCorrection) { + float* splineX = correction.getCorrectionDataInvX(sector, row); + float* splineYZ = correction.getCorrectionDataInvYZ(sector, row); + for (int i = 0; i < spline.getNumberOfParameters() / 3; i++) { + splineX[i] = splineParameters[3 * i + 0]; + splineYZ[2 * i + 0] = splineParameters[3 * i + 1]; + splineYZ[2 * i + 1] = splineParameters[3 * i + 2]; + } + } else { + float* splineXYZ = correction.getCorrectionData(sector, row); + for (int i = 0; i < spline.getNumberOfParameters(); i++) { + splineXYZ[i] = splineParameters[i]; + } + } } // row }; // thread @@ -174,53 +209,30 @@ void TPCFastSpaceChargeCorrectionHelper::fillSpaceChargeCorrectionFromMap(TPCFas th.join(); } - } // slice + } // sector - initInverse(correction, 0); -} + watch.Stop(); -void TPCFastSpaceChargeCorrectionHelper::getSpaceChargeCorrection(const TPCFastSpaceChargeCorrection& correction, int slice, int row, o2::gpu::TPCFastSpaceChargeCorrectionMap::CorrectionPoint p, - double& su, double& sv, double& dx, double& du, double& dv) -{ - // get space charge correction in internal TPCFastTransform coordinates su,sv->dx,du,dv - - if (!mIsInitialized) { - initGeometry(); - } - - // not corrected coordinates in u,v - float u = 0.f, v = 0.f, fsu = 0.f, fsv = 0.f; - mGeo.convLocalToUV(slice, p.mY, p.mZ, u, v); - correction.convUVtoGrid(slice, row, u, v, fsu, fsv); - // mGeo.convUVtoScaledUV(slice, row, u, v, fsu, fsv); - su = fsu; - sv = fsv; - // corrected coordinates in u,v - float u1 = 0.f, v1 = 0.f; - mGeo.convLocalToUV(slice, p.mY + p.mDy, p.mZ + p.mDz, u1, v1); - - dx = p.mDx; - du = u1 - u; - dv = v1 - v; -} + LOGP(info, "Space charge correction tooks: {}s", watch.RealTime()); +} // fillSpaceChargeCorrectionFromMap std::unique_ptr TPCFastSpaceChargeCorrectionHelper::createFromGlobalCorrection( - std::function correctionGlobal, const int nKnotsY, const int nKnotsZ) { /// creates TPCFastSpaceChargeCorrection object from a continious space charge correction in global coordinates - auto correctionLocal = [&](int roc, int irow, double ly, double lz, + auto correctionLocal = [&](int sector, int irow, double ly, double lz, double& dlx, double& dly, double& dlz) { double lx = mGeo.getRowInfo(irow).x; float gx, gy, gz; - mGeo.convLocalToGlobal(roc, lx, ly, lz, gx, gy, gz); + mGeo.convLocalToGlobal(sector, lx, ly, lz, gx, gy, gz); double dgx, dgy, dgz; - correctionGlobal(roc, gx, gy, gz, dgx, dgy, dgz); + correctionGlobal(sector, gx, gy, gz, dgx, dgy, dgz); float lx1, ly1, lz1; - mGeo.convGlobalToLocal(roc, gx + dgx, gy + dgy, gz + dgz, lx1, ly1, lz1); + mGeo.convGlobalToLocal(sector, gx + dgx, gy + dgy, gz + dgz, lx1, ly1, lz1); dlx = lx1 - lx; dly = ly1 - ly; dlz = lz1 - lz; @@ -229,7 +241,7 @@ std::unique_ptr TPCFastSpaceChargeCorrectionHelper } std::unique_ptr TPCFastSpaceChargeCorrectionHelper::createFromLocalCorrection( - std::function correctionLocal, + std::function correctionLocal, const int nKnotsY, const int nKnotsZ) { /// creates TPCFastSpaceChargeCorrection object from a continious space charge correction in local coordinates @@ -251,12 +263,14 @@ std::unique_ptr TPCFastSpaceChargeCorrectionHelper correction.startConstruction(mGeo, nCorrectionScenarios); // assign spline type for TPC rows - for (int row = 0; row < mGeo.getNumberOfRows(); row++) { - int scenario = row / 10; - if (scenario >= nCorrectionScenarios) { - scenario = nCorrectionScenarios - 1; + for (int sector = 0; sector < mGeo.getNumberOfSectors(); sector++) { + for (int row = 0; row < mGeo.getNumberOfRows(); row++) { + int scenario = row / 10; + if (scenario >= nCorrectionScenarios) { + scenario = nCorrectionScenarios - 1; + } + correction.setRowScenarioID(sector, row, scenario); } - correction.setRowScenarioID(row, scenario); } for (int scenario = 0; scenario < nCorrectionScenarios; scenario++) { @@ -274,28 +288,25 @@ std::unique_ptr TPCFastSpaceChargeCorrectionHelper /// set space charge correction in the local coordinates /// as a continious function - int nRocs = mGeo.getNumberOfSlices(); + int nSectors = mGeo.getNumberOfSectors(); int nRows = mGeo.getNumberOfRows(); - mCorrectionMap.init(nRocs, nRows); + mCorrectionMap.init(nSectors, nRows); - for (int iRoc = 0; iRoc < nRocs; iRoc++) { + for (int iSector = 0; iSector < nSectors; iSector++) { auto myThread = [&](int iThread) { for (int iRow = iThread; iRow < nRows; iRow += mNthreads) { const auto& info = mGeo.getRowInfo(iRow); - double vMax = mGeo.getTPCzLength(iRoc); - double dv = vMax / (6. * (nKnotsZ - 1)); - + double dl = mGeo.getTPCzLength() / (6. * (nKnotsZ - 1)); double dpad = info.maxPad / (6. * (nKnotsY - 1)); for (double pad = 0; pad < info.maxPad + .5 * dpad; pad += dpad) { - float u = mGeo.convPadToU(iRow, pad); - for (double v = 0.; v < vMax + .5 * dv; v += dv) { - float ly, lz; - mGeo.convUVtoLocal(iRoc, u, v, ly, lz); + for (double l = 0.; l < mGeo.getTPCzLength() + .5 * dl; l += dl) { + float y, z; + mGeo.convPadDriftLengthToLocal(iSector, iRow, pad, l, y, z); double dx, dy, dz; - correctionLocal(iRoc, iRow, ly, lz, dx, dy, dz); - mCorrectionMap.addCorrectionPoint(iRoc, iRow, - ly, lz, dx, dy, dz); + correctionLocal(iSector, iRow, y, z, dx, dy, dz); + mCorrectionMap.addCorrectionPoint(iSector, iRow, + y, z, dx, dy, dz, 1.); } } } // row @@ -313,20 +324,21 @@ std::unique_ptr TPCFastSpaceChargeCorrectionHelper th.join(); } - } // roc + } // sector - fillSpaceChargeCorrectionFromMap(correction); + fillSpaceChargeCorrectionFromMap(correction, false); + initInverse(correction, false); } return std::move(correctionPtr); -} +} // createFromLocalCorrection void TPCFastSpaceChargeCorrectionHelper::testGeometry(const TPCFastTransformGeo& geo) const { const Mapper& mapper = Mapper::instance(); - if (geo.getNumberOfSlices() != Sector::MAXSECTOR) { - LOG(fatal) << "Wrong number of sectors :" << geo.getNumberOfSlices() << " instead of " << Sector::MAXSECTOR << std::endl; + if (geo.getNumberOfSectors() != Sector::MAXSECTOR) { + LOG(fatal) << "Wrong number of sectors :" << geo.getNumberOfSectors() << " instead of " << Sector::MAXSECTOR << std::endl; } if (geo.getNumberOfRows() != mapper.getNumberOfRows()) { @@ -350,15 +362,15 @@ void TPCFastSpaceChargeCorrectionHelper::testGeometry(const TPCFastTransformGeo& for (int pad = 0; pad < nPads; pad++) { const GlobalPadNumber p = mapper.globalPadNumber(PadPos(row, pad)); const PadCentre& c = mapper.padCentre(p); - double u = geo.convPadToU(row, pad); - + float y, z; + geo.convPadDriftLengthToLocal(0, row, pad, 0., y, z); const double dx = x - c.X(); - const double dy = u - (-c.Y()); // diferent sign convention for Y coordinate in the map + const double dy = y - (-c.Y()); // diferent sign convention for Y coordinate in the map if (fabs(dx) >= 1.e-6 || fabs(dy) >= 1.e-5) { LOG(warning) << "wrong calculated pad position:" << " row " << row << " pad " << pad << " x calc " << x << " x in map " << c.X() << " dx " << (x - c.X()) - << " y calc " << u << " y in map " << -c.Y() << " dy " << dy << std::endl; + << " y calc " << y << " y in map " << -c.Y() << " dy " << dy << std::endl; } if (fabs(maxDx) < fabs(dx)) { maxDx = dx; @@ -376,281 +388,520 @@ void TPCFastSpaceChargeCorrectionHelper::testGeometry(const TPCFastTransformGeo& } std::unique_ptr TPCFastSpaceChargeCorrectionHelper::createFromTrackResiduals( - const o2::tpc::TrackResiduals& trackResiduals, TTree* voxResTree, bool useSmoothed, bool invertSigns) + const o2::tpc::TrackResiduals& trackResiduals, TTree* voxResTree, TTree* voxResTreeInverse, bool useSmoothed, bool invertSigns, + TPCFastSpaceChargeCorrectionMap* fitPointsDirect, + TPCFastSpaceChargeCorrectionMap* fitPointsInverse) { // create o2::gpu::TPCFastSpaceChargeCorrection from o2::tpc::TrackResiduals::VoxRes voxel tree - LOG(info) << "fast space charge correction helper: create correction using " << mNthreads << " threads"; + LOG(info) << "fast space charge correction helper: create correction from track residuals using " << mNthreads << " threads"; + + TStopwatch watch, watch1; std::unique_ptr correctionPtr(new o2::gpu::TPCFastSpaceChargeCorrection); o2::gpu::TPCFastSpaceChargeCorrection& correction = *correctionPtr; - // o2::tpc::TrackResiduals::VoxRes* v = nullptr; - // voxResTree->SetBranchAddress("voxRes", &v); - - o2::tpc::TrackResiduals::VoxRes* v = nullptr; - TBranch* branch = voxResTree->GetBranch("voxRes"); - branch->SetAddress(&v); - branch->SetAutoDelete(kTRUE); - auto* helper = o2::tpc::TPCFastSpaceChargeCorrectionHelper::instance(); const o2::gpu::TPCFastTransformGeo& geo = helper->getGeometry(); - o2::gpu::TPCFastSpaceChargeCorrectionMap& map = helper->getCorrectionMap(); - map.init(geo.getNumberOfSlices(), geo.getNumberOfRows()); - int nY2Xbins = trackResiduals.getNY2XBins(); int nZ2Xbins = trackResiduals.getNZ2XBins(); - int nKnotsY = nY2Xbins / 2; - int nKnotsZ = nZ2Xbins / 2; + std::vector knotsDouble[3]; + + knotsDouble[0].reserve(nY2Xbins); + knotsDouble[1].reserve(nZ2Xbins); + knotsDouble[2].reserve(nZ2Xbins); + + // to get enouth measurements, make a spline knot at every second bin. Boundary bins are always included. + + for (int i = 0, j = nY2Xbins - 1; i <= j; i += 2, j -= 2) { + knotsDouble[0].push_back(trackResiduals.getY2X(0, i)); + if (j >= i + 1) { + knotsDouble[0].push_back(trackResiduals.getY2X(0, j)); + } + } - if (nKnotsY < 2) { - nKnotsY = 2; + for (int i = 0, j = nZ2Xbins - 1; i <= j; i += 2, j -= 2) { + knotsDouble[1].push_back(trackResiduals.getZ2X(i)); + knotsDouble[2].push_back(-trackResiduals.getZ2X(i)); + if (j >= i + 1) { + knotsDouble[1].push_back(trackResiduals.getZ2X(j)); + knotsDouble[2].push_back(-trackResiduals.getZ2X(j)); + } } - if (nKnotsZ < 2) { - nKnotsZ = 2; + std::vector knotsInt[3]; + + for (int dim = 0; dim < 3; dim++) { + auto& knotsD = knotsDouble[dim]; + std::sort(knotsD.begin(), knotsD.end()); + + double pitch = knotsD[1] - knotsD[0]; // min distance between the knots + for (int i = 2; i < knotsD.size(); i++) { + double d = knotsD[i] - knotsD[i - 1]; + if (d < pitch) { + pitch = d; + } + } + // spline knots must be positioned on the grid with an integer internal coordinate + // we set the knot positioning accuracy to 0.1*pitch + pitch = 0.1 * pitch; + auto& knotsI = knotsInt[dim]; + knotsI.reserve(knotsD.size()); + double u0 = knotsD[0]; + double u1 = knotsD[knotsD.size() - 1]; + for (auto& u : knotsD) { + u -= u0; + int iu = int(u / pitch + 0.5); + knotsI.push_back(iu); + // debug printout: corrected vs original knot positions, scaled to [-1,1] interval + double uorig = u / (u1 - u0) * 2 - 1.; + u = (iu * pitch) / (u1 - u0) * 2 - 1.; + LOG(info) << "TPC SC splines: convert " << (dim == 0 ? "y" : (dim == 1 ? "z" : "-z")) << " bin to the knot: " << uorig << " -> " << u << " -> " << iu; + } + + if (knotsI.size() < 2) { // minimum 2 knots + knotsI.clear(); + knotsI.push_back(0); + knotsI.push_back(1); + } } + auto& yKnotsInt = knotsInt[0]; + auto& zKnotsIntA = knotsInt[1]; + auto& zKnotsIntC = knotsInt[2]; + + int nKnotsY = yKnotsInt.size(); + int nKnotsZA = zKnotsIntA.size(); + int nKnotsZC = zKnotsIntC.size(); + // std::cout << "n knots Y: " << nKnotsY << std::endl; - // std::cout << "n knots Z: " << nKnotsZ << std::endl; + // std::cout << "n knots Z: " << nKnotsZA << ", " << nKnotsZC << std::endl; + + const int nRows = geo.getNumberOfRows(); + const int nSectors = geo.getNumberOfSectors(); { // create the correction object - const int nRows = geo.getNumberOfRows(); - const int nCorrectionScenarios = 1; + const int nCorrectionScenarios = 2; // different grids for TPC A and TPC C sides correction.startConstruction(geo, nCorrectionScenarios); // init rows - for (int row = 0; row < geo.getNumberOfRows(); row++) { - correction.setRowScenarioID(row, 0); + for (int iSector = 0; iSector < nSectors; iSector++) { + int id = iSector < geo.getNumberOfSectorsA() ? 0 : 1; + for (int row = 0; row < geo.getNumberOfRows(); row++) { + correction.setRowScenarioID(iSector, row, id); + } } { // init spline scenario TPCFastSpaceChargeCorrection::SplineType spline; - spline.recreate(nKnotsY, nKnotsZ); + spline.recreate(nKnotsY, &yKnotsInt[0], nKnotsZA, &zKnotsIntA[0]); correction.setSplineScenario(0, spline); + spline.recreate(nKnotsY, &yKnotsInt[0], nKnotsZC, &zKnotsIntC[0]); + correction.setSplineScenario(1, spline); } correction.finishConstruction(); } // .. create the correction object - // set the grid borders in Z to Z/X==1 - for (int iRoc = 0; iRoc < geo.getNumberOfSlices(); iRoc++) { + // set the grid borders + for (int iSector = 0; iSector < geo.getNumberOfSectors(); iSector++) { for (int iRow = 0; iRow < geo.getNumberOfRows(); iRow++) { - auto rowInfo = geo.getRowInfo(iRow); - o2::gpu::TPCFastSpaceChargeCorrection::SliceRowInfo& info = correction.getSliceRowInfo(iRoc, iRow); - double len = geo.getTPCzLength(iRoc); - info.gridV0 = len - rowInfo.x; - if (info.gridV0 < 0.) { - info.gridV0 = 0.; + auto& info = correction.getSectorRowInfo(iSector, iRow); + const auto& spline = correction.getSpline(iSector, iRow); + double rowX = geo.getRowInfo(iRow).x; + double yMin = rowX * trackResiduals.getY2X(iRow, 0); + double yMax = rowX * trackResiduals.getY2X(iRow, trackResiduals.getNY2XBins() - 1); + double zMin = rowX * trackResiduals.getZ2X(0); + double zMax = rowX * trackResiduals.getZ2X(trackResiduals.getNZ2XBins() - 1); + double zOut = zMax; + if (iSector >= geo.getNumberOfSectorsA()) { + // TPC C side + zOut = -zOut; + zMax = -zMin; + zMin = zOut; } + info.gridMeasured.set(yMin, spline.getGridX1().getUmax() / (yMax - yMin), // y + zMin, spline.getGridX2().getUmax() / (zMax - zMin), // z + zOut, geo.getZreadout(iSector)); // correction scaling region + + info.gridReal = info.gridMeasured; + + // std::cout << " iSector " << iSector << " iRow " << iRow << " uMin: " << uMin << " uMax: " << uMax << " vMin: " << vMin << " vMax: " << vMax + //<< " grid scale u "<< info.scaleUtoGrid << " grid scale v "<< info.scaleVtoGrid<< std::endl; } } - LOG(info) << "fast space charge correction helper: fill data points from track residuals"; + LOG(info) << "fast space charge correction helper: preparation took " << watch1.RealTime() << "s"; - for (int iVox = 0; iVox < voxResTree->GetEntriesFast(); iVox++) { + for (int processingInverseCorrection = 0; processingInverseCorrection <= 1; processingInverseCorrection++) { - voxResTree->GetEntry(iVox); - auto xBin = - v->bvox[o2::tpc::TrackResiduals::VoxX]; // bin number in x (= pad row) - auto y2xBin = - v->bvox[o2::tpc::TrackResiduals::VoxF]; // bin number in y/x 0..14 - auto z2xBin = - v->bvox[o2::tpc::TrackResiduals::VoxZ]; // bin number in z/x 0..4 + TTree* currentTree = (processingInverseCorrection) ? voxResTreeInverse : voxResTree; - int iRoc = (int)v->bsec; - int iRow = (int)xBin; + if (!currentTree) { + continue; + } + const char* directionName = (processingInverseCorrection) ? "inverse" : "direct"; + LOG(info) << "\n fast space charge correction helper: Process " << directionName + << " correction: fill data points from track residuals.. "; - // x,y,z of the voxel in local TPC coordinates + TStopwatch watch3; + o2::gpu::TPCFastSpaceChargeCorrectionMap& map = helper->getCorrectionMap(); + map.init(geo.getNumberOfSectors(), geo.getNumberOfRows()); - double x = trackResiduals.getX(xBin); // radius of the pad row - double y2x = trackResiduals.getY2X( - xBin, y2xBin); // y/x coordinate of the bin ~-0.15 ... 0.15 - double z2x = - trackResiduals.getZ2X(z2xBin); // z/x coordinate of the bin 0.1 .. 0.9 - double y = x * y2x; - double z = x * z2x; + // read the data Sector by Sector - if (iRoc >= geo.getNumberOfSlicesA()) { - z = -z; - // y = -y; - } + // data in the tree is not sorted by row + // first find which data belong to which row - { - float sx, sy, sz; - trackResiduals.getVoxelCoordinates(iRoc, xBin, y2xBin, z2xBin, sx, sy, sz); - sy *= x; - sz *= x; - if (fabs(sx - x) + fabs(sy - y) + fabs(sz - z) > 1.e-4) { - std::cout << "wrong coordinates: " << x << " " << y << " " << z << " / " << sx << " " << sy << " " << sz << std::endl; - } + struct VoxelData { + int mNentries{0}; // number of entries + float mX, mY, mZ; // mean position in the local coordinates + float mCx, mCy, mCz; // corrections to the local coordinates + }; + + std::vector vSectorData[nRows * nSectors]; + for (int ir = 0; ir < nRows * nSectors; ir++) { + vSectorData[ir].resize(nY2Xbins * nZ2Xbins); } - // skip empty voxels - float voxEntries = v->stat[o2::tpc::TrackResiduals::VoxV]; - if (voxEntries < 1.) { // no statistics - continue; + { // read data from the tree to vSectorData + + ROOT::TTreeProcessorMT processor(*currentTree, mNthreads); + std::string errMsg = std::string("Error reading ") + directionName + " track residuals: "; + auto myThread = [&](TTreeReader& readerSubRange) { + TTreeReaderValue v(readerSubRange, "voxRes"); + while (readerSubRange.Next()) { + int iSector = (int)v->bsec; + if (iSector < 0 || iSector >= nSectors) { + LOG(fatal) << errMsg << "Sector number " << iSector << " is out of range"; + continue; + } + int iRow = (int)v->bvox[o2::tpc::TrackResiduals::VoxX]; // bin number in x (= pad row) + if (iRow < 0 || iRow >= nRows) { + LOG(fatal) << errMsg << "Row number " << iRow << " is out of range"; + } + double rowX = trackResiduals.getX(iRow); // X of the pad row + int iy = v->bvox[o2::tpc::TrackResiduals::VoxF]; // bin number in y/x 0..14 + int iz = v->bvox[o2::tpc::TrackResiduals::VoxZ]; // bin number in z/x 0..4 + auto& data = vSectorData[iSector * nRows + iRow][iy * nZ2Xbins + iz]; + data.mNentries = (int)v->stat[o2::tpc::TrackResiduals::VoxV]; + data.mX = v->stat[o2::tpc::TrackResiduals::VoxX]; + data.mY = v->stat[o2::tpc::TrackResiduals::VoxF] * rowX; + data.mZ = v->stat[o2::tpc::TrackResiduals::VoxZ] * rowX; + data.mCx = useSmoothed ? v->DS[o2::tpc::TrackResiduals::ResX] : v->D[o2::tpc::TrackResiduals::ResX]; + data.mCy = useSmoothed ? v->DS[o2::tpc::TrackResiduals::ResY] : v->D[o2::tpc::TrackResiduals::ResY]; + data.mCz = useSmoothed ? v->DS[o2::tpc::TrackResiduals::ResZ] : v->D[o2::tpc::TrackResiduals::ResZ]; + if (invertSigns) { + data.mCx *= -1.; + data.mCy *= -1.; + data.mCz *= -1.; + } + } + }; + processor.Process(myThread); } - // double statX = v->stat[o2::tpc::TrackResiduals::VoxX]; // weight - // double statY = v->stat[o2::tpc::TrackResiduals::VoxF]; // weight - // double statZ = v->stat[o2::tpc::TrackResiduals::VoxZ]; // weight - - // double dx = 1. / trackResiduals.getDXI(xBin); - double dy = x / trackResiduals.getDY2XI(xBin, y2xBin); - double dz = x * trackResiduals.getDZ2X(z2xBin); - - double correctionX = useSmoothed ? v->DS[o2::tpc::TrackResiduals::ResX] : v->D[o2::tpc::TrackResiduals::ResX]; - double correctionY = useSmoothed ? v->DS[o2::tpc::TrackResiduals::ResY] : v->D[o2::tpc::TrackResiduals::ResY]; - double correctionZ = useSmoothed ? v->DS[o2::tpc::TrackResiduals::ResZ] : v->D[o2::tpc::TrackResiduals::ResZ]; - if (invertSigns) { - correctionX *= -1.; - correctionY *= -1.; - correctionZ *= -1.; + // debug: mirror the data for TPC C side + + if (mDebugMirrorAdata2C) { + for (int iSector = 0; iSector < geo.getNumberOfSectorsA(); iSector++) { + for (int iRow = 0; iRow < nRows; iRow++) { + for (int iy = 0; iy < nY2Xbins; iy++) { + for (int iz = 0; iz < nZ2Xbins; iz++) { + auto& dataA = vSectorData[iSector * nRows + iRow][iy * nZ2Xbins + iz]; + auto& dataC = vSectorData[(iSector + geo.getNumberOfSectorsA()) * nRows + iRow][iy * nZ2Xbins + iz]; + dataC = dataA; // copy the data + dataC.mZ = -dataC.mZ; // mirror the Z coordinate + dataC.mCz = -dataC.mCz; // mirror the Z correction + } + } + } + } } - // add one point per voxel - // map.addCorrectionPoint(iRoc, iRow, y, z, correctionX, correctionY, - // correctionZ); + double maxError[3] = {0., 0., 0.}; + int nErrors = 0; + + for (int iSector = 0; iSector < nSectors; iSector++) { + + // now process the data row-by-row + + auto myThread = [&](int iThread, int nTreads) { + struct Voxel { + float mY, mZ; // non-distorted local coordinates + float mDy, mDz; // voxel size + int mSmoothingStep{100}; // is the voxel data original or smoothed at this step + }; + + std::vector vRowVoxels(nY2Xbins * nZ2Xbins); + + for (int iRow = iThread; iRow < nRows; iRow += nTreads) { + // LOG(info) << "Processing Sector " << iSector << " row " << iRow; + + // complete the voxel data + { + int xBin = iRow; + double x = trackResiduals.getX(xBin); // radius of the pad row + double dx = 1. / trackResiduals.getDXI(xBin); + bool isDataFound = false; + for (int iy = 0; iy < nY2Xbins; iy++) { + for (int iz = 0; iz < nZ2Xbins; iz++) { + auto& data = vSectorData[iSector * nRows + iRow][iy * nZ2Xbins + iz]; + auto& vox = vRowVoxels[iy * nZ2Xbins + iz]; + // y/x coordinate of the bin ~-0.15 ... 0.15 + double y2x = trackResiduals.getY2X(xBin, iy); + // z/x coordinate of the bin 0.1 .. 0.9 + double z2x = trackResiduals.getZ2X(iz); + vox.mY = x * y2x; + vox.mZ = x * z2x; + vox.mDy = x / trackResiduals.getDY2XI(xBin, iy); + vox.mDz = x * trackResiduals.getDZ2X(iz); + if (iSector >= geo.getNumberOfSectorsA()) { + vox.mZ = -vox.mZ; + } + if (data.mNentries > 0) { // voxel contains data + vox.mSmoothingStep = 0; // take original data + isDataFound = true; + + // correct the mean position if it is outside the voxel + std::stringstream msg; + if (fabs(x - data.mX) > mVoxelMeanValidityRange * dx / 2.) { + msg << "\n x: center " << x << " dx " << data.mX - x << " half bin size " << dx / 2; + } + + if (fabs(vox.mY - data.mY) > mVoxelMeanValidityRange * vox.mDy / 2.) { + msg << "\n y: center " << vox.mY << " dy " << data.mY - vox.mY << " half bin size " << vox.mDy / 2; + data.mY = vox.mY; + } + + if (fabs(vox.mZ - data.mZ) > mVoxelMeanValidityRange * vox.mDz / 2.) { + msg << "\n z: center " << vox.mZ << " dz " << data.mZ - vox.mZ << " half bin size " << vox.mDz / 2; + data.mZ = vox.mZ; + } + + if (!msg.str().empty()) { + bool isMaxErrorExceeded = (fabs(data.mX - x) / dx > maxError[0]) || + (fabs(data.mY - vox.mY) / vox.mDy > maxError[1]) || + (fabs(data.mZ - vox.mZ) / vox.mDz > maxError[2]); + static std::mutex mutex; + mutex.lock(); + nErrors++; + if (nErrors < 20 || isMaxErrorExceeded) { + LOG(warning) << directionName << " correction: error N " << nErrors << "fitted voxel position is outside the voxel: " + << " sector " << iSector << " row " << iRow << " bin y " << iy << " bin z " << iz + << msg.str(); + maxError[0] = GPUCommonMath::Max(maxError[0], fabs(data.mX - x) / dx); + maxError[1] = GPUCommonMath::Max(maxError[1], fabs(data.mY - vox.mY) / vox.mDy); + maxError[2] = GPUCommonMath::Max(maxError[2], fabs(data.mZ - vox.mZ) / vox.mDz); + } + mutex.unlock(); + } + + } else { // no data, take voxel center position + data.mCx = 0.; + data.mCy = 0.; + data.mCz = 0.; + data.mX = x; + data.mY = vox.mY; + data.mZ = vox.mZ; + vox.mSmoothingStep = 100; // fill this data point with smoothed values from the neighbours + } + if (mDebugUseVoxelCenters) { // debug: always use voxel center instead of the mean position + data.mY = vox.mY; + data.mZ = vox.mZ; + } + } + } + + if (!isDataFound) { // fill everything with 0 + for (int iy = 0; iy < nY2Xbins; iy++) { + for (int iz = 0; iz < nZ2Xbins; iz++) { + vRowVoxels[iy * nZ2Xbins + iz].mSmoothingStep = 0; + } + } + } + } // complete the voxel data + + // repare the voxel data: fill empty voxels + + int nRepairs = 0; + + for (int ismooth = 1; ismooth <= 2; ismooth++) { + for (int iy = 0; iy < nY2Xbins; iy++) { + for (int iz = 0; iz < nZ2Xbins; iz++) { + auto& data = vSectorData[iSector * nRows + iRow][iy * nZ2Xbins + iz]; + auto& vox = vRowVoxels[iy * nZ2Xbins + iz]; + if (vox.mSmoothingStep <= ismooth) { // already filled + continue; + } + nRepairs++; + data.mCx = 0.; + data.mCy = 0.; + data.mCz = 0.; + double w = 0.; + bool filled = false; + auto update = [&](int iy1, int iz1) { + auto& data1 = vSectorData[iSector * nRows + iRow][iy1 * nZ2Xbins + iz1]; + auto& vox1 = vRowVoxels[iy1 * nZ2Xbins + iz1]; + if (vox1.mSmoothingStep >= ismooth) { + return false; + } + double w1 = 1. / (abs(iy - iy1) + abs(iz - iz1) + 1); + data.mCx += w1 * data1.mCx; + data.mCy += w1 * data1.mCy; + data.mCz += w1 * data1.mCz; + w += w1; + filled = true; + return true; + }; + + for (int iy1 = iy - 1; iy1 >= 0 && !update(iy1, iz); iy1--) { + } + for (int iy1 = iy + 1; iy1 < nY2Xbins && !update(iy1, iz); iy1++) { + } + for (int iz1 = iz - 1; iz1 >= 0 && !update(iy, iz1); iz1--) { + } + for (int iz1 = iz + 1; iz1 < nZ2Xbins && !update(iy, iz1); iz1++) { + } + + if (filled) { + data.mCx /= w; + data.mCy /= w; + data.mCz /= w; + vox.mSmoothingStep = ismooth; + } + } // iz + } // iy + } // ismooth + + if (nRepairs > 0) { + LOG(debug) << "Sector " << iSector << " row " << iRow << ": " << nRepairs << " voxel repairs for " << nY2Xbins * nZ2Xbins << " voxels"; + } - // add several points per voxel, - // extend values of the edge voxels to the edges of the TPC row - // + // feed the row data to the helper - double yFirst = y - dy / 2.; - double yLast = y + dy / 2.; + auto& info = correction.getSectorRowInfo(iSector, iRow); + const auto& spline = correction.getSpline(iSector, iRow); - if (y2xBin == 0) { // extend value of the first Y bin to the row edge - float u, v; - if (iRoc < geo.getNumberOfSlicesA()) { - geo.convScaledUVtoUV(iRoc, iRow, 0., 0., u, v); - } else { - geo.convScaledUVtoUV(iRoc, iRow, 1., 0., u, v); - } - float py, pz; - geo.convUVtoLocal(iRoc, u, v, py, pz); - yFirst = py; - } + auto addVoxel = [&](int iy, int iz, double weight) { + auto& vox = vRowVoxels[iy * nZ2Xbins + iz]; + if (vox.mSmoothingStep > 2) { + LOG(fatal) << "empty voxel is not repared: y " << iy << " z " << iz; + } + auto& data = vSectorData[iSector * nRows + iRow][iy * nZ2Xbins + iz]; + map.addCorrectionPoint(iSector, iRow, data.mY, data.mZ, data.mCx, data.mCy, data.mCz, weight); + }; + + auto addEdge = [&](int iy1, int iz1, int iy2, int iz2, int nPoints) { + // add n points on the edge between two voxels excluding the voxel points + if (nPoints < 1) { + return; + } + if (iy1 < 0 || iy1 >= nY2Xbins || iz1 < 0 || iz1 >= nZ2Xbins) { + return; + } + if (iy2 < 0 || iy2 >= nY2Xbins || iz2 < 0 || iz2 >= nZ2Xbins) { + return; + } + auto& data1 = vSectorData[iSector * nRows + iRow][iy1 * nZ2Xbins + iz1]; + auto& vox1 = vRowVoxels[iy1 * nZ2Xbins + iz1]; + auto& data2 = vSectorData[iSector * nRows + iRow][iy2 * nZ2Xbins + iz2]; + auto& vox2 = vRowVoxels[iy2 * nZ2Xbins + iz2]; + double y1 = data1.mY; + double z1 = data1.mZ; + double cx1 = data1.mCx; + double cy1 = data1.mCy; + double cz1 = data1.mCz; + double y2 = data2.mY; + double z2 = data2.mZ; + double cx2 = data2.mCx; + double cy2 = data2.mCy; + double cz2 = data2.mCz; + + for (int is = 1; is <= nPoints; is++) { + double s2 = is / (double)(nPoints + 1); + double s1 = 1. - s2; + double y = s1 * y1 + s2 * y2; + double z = s1 * z1 + s2 * z2; + double cx = s1 * cx1 + s2 * cx2; + double cy = s1 * cy1 + s2 * cy2; + double cz = s1 * cz1 + s2 * cz2; + map.addCorrectionPoint(iSector, iRow, y, z, cx, cy, cz, 1.); + } + }; + + // original measurements weighted by 8 at each voxel and 8 additional artificial measurements around each voxel + // + // (y+1, z) 8 1 1 8 (y+1, z+1) + // 1 1 1 1 1 + // 1 1 1 1 1 + // (y,z) 8 1 1 8 1 + // 1 1 1 1 1 + + for (int iy = 0; iy < nY2Xbins; iy++) { + for (int iz = 0; iz < nZ2Xbins; iz++) { + addVoxel(iy, iz, 8); + addEdge(iy, iz, iy, iz + 1, 2); + addEdge(iy, iz, iy + 1, iz, 2); + addEdge(iy, iz, iy + 1, iz + 1, 2); + addEdge(iy + 1, iz, iy, iz + 1, 2); + } + } - if (y2xBin == trackResiduals.getNY2XBins() - 1) { // extend value of the last Y bin to the row edge - float u, v; - if (iRoc < geo.getNumberOfSlicesA()) { - geo.convScaledUVtoUV(iRoc, iRow, 1., 0., u, v); - } else { - geo.convScaledUVtoUV(iRoc, iRow, 0., 0., u, v); - } - float py, pz; - geo.convUVtoLocal(iRoc, u, v, py, pz); - yLast = py; - } + } // iRow + }; // myThread - double z0 = 0.; - if (iRoc < geo.getNumberOfSlicesA()) { - z0 = geo.getTPCzLengthA(); - } else { - z0 = -geo.getTPCzLengthC(); - } + // run n threads - double yStep = (yLast - yFirst) / 2; + int nThreads = mNthreads; + // nThreads = 1; - for (double py = yFirst; py <= yLast + yStep / 2.; py += yStep) { + std::vector threads(nThreads); - for (double pz = z - dz / 2.; pz <= z + dz / 2. + 1.e-4; pz += dz / 2.) { - map.addCorrectionPoint(iRoc, iRow, py, pz, correctionX, correctionY, - correctionZ); + for (int i = 0; i < nThreads; i++) { + threads[i] = std::thread(myThread, i, nThreads); } - if (z2xBin == trackResiduals.getNZ2XBins() - 1) { - // extend value of the first Z bin to the readout, linear decrease of all values to 0. - int nZsteps = 3; - for (int is = 0; is < nZsteps; is++) { - double pz = z + (z0 - z) * (is + 1.) / nZsteps; - double s = (nZsteps - 1. - is) / nZsteps; - map.addCorrectionPoint(iRoc, iRow, py, pz, s * correctionX, - s * correctionY, s * correctionZ); - } + // wait for the threads to finish + for (auto& th : threads) { + th.join(); } - } - } - helper->fillSpaceChargeCorrectionFromMap(correction); - return std::move(correctionPtr); -} + } // iSector -void TPCFastSpaceChargeCorrectionHelper::initMaxDriftLength(o2::gpu::TPCFastSpaceChargeCorrection& correction, bool prn) -{ - /// initialise max drift length + LOGP(info, "Reading & reparing of the track residuals tooks: {}s", watch3.RealTime()); - double tpcR2min = mGeo.getRowInfo(0).x - 1.; - tpcR2min = tpcR2min * tpcR2min; - double tpcR2max = mGeo.getRowInfo(mGeo.getNumberOfRows() - 1).x; - tpcR2max = tpcR2max / cos(2 * M_PI / mGeo.getNumberOfSlicesA() / 2) + 1.; - tpcR2max = tpcR2max * tpcR2max; + LOG(info) << "fast space charge correction helper: create space charge from the map of data points.."; - ChebyshevFit1D chebFitter; + TStopwatch watch4; - for (int slice = 0; slice < mGeo.getNumberOfSlices(); slice++) { - if (prn) { - LOG(info) << "init MaxDriftLength for slice " << slice; + if (!processingInverseCorrection && fitPointsDirect) { + *fitPointsDirect = helper->getCorrectionMap(); } - double vLength = (slice < mGeo.getNumberOfSlicesA()) ? mGeo.getTPCzLengthA() : mGeo.getTPCzLengthC(); - TPCFastSpaceChargeCorrection::SliceInfo& sliceInfo = correction.getSliceInfo(slice); - sliceInfo.vMax = 0.f; - - for (int row = 0; row < mGeo.getNumberOfRows(); row++) { - TPCFastSpaceChargeCorrection::RowActiveArea& area = correction.getSliceRowInfo(slice, row).activeArea; - area.cvMax = 0; - area.vMax = 0; - area.cuMin = mGeo.convPadToU(row, 0.f); - area.cuMax = -area.cuMin; - chebFitter.reset(4, 0., mGeo.getRowInfo(row).maxPad); - double x = mGeo.getRowInfo(row).x; - for (int pad = 0; pad < mGeo.getRowInfo(row).maxPad; pad++) { - float u = mGeo.convPadToU(row, (float)pad); - float v0 = 0; - float v1 = 1.1 * vLength; - float vLastValid = -1; - float cvLastValid = -1; - while (v1 - v0 > 0.1) { - float v = 0.5 * (v0 + v1); - float dx, du, dv; - correction.getCorrection(slice, row, u, v, dx, du, dv); - double cx = x + dx; - double cu = u + du; - double cv = v + dv; - double r2 = cx * cx + cu * cu; - if (cv < 0) { - v0 = v; - } else if (cv <= vLength && r2 >= tpcR2min && r2 <= tpcR2max) { - v0 = v; - vLastValid = v; - cvLastValid = cv; - } else { - v1 = v; - } - } - if (vLastValid > 0.) { - chebFitter.addMeasurement(pad, vLastValid); - } - if (area.vMax < vLastValid) { - area.vMax = vLastValid; - } - if (area.cvMax < cvLastValid) { - area.cvMax = cvLastValid; - } - } - chebFitter.fit(); - for (int i = 0; i < 5; i++) { - area.maxDriftLengthCheb[i] = chebFitter.getCoefficients()[i]; - } - if (sliceInfo.vMax < area.vMax) { - sliceInfo.vMax = area.vMax; - } - } // row - } // slice -} + if (processingInverseCorrection && fitPointsInverse) { + *fitPointsInverse = helper->getCorrectionMap(); + } + + helper->fillSpaceChargeCorrectionFromMap(correction, processingInverseCorrection); + + LOG(info) << "fast space charge correction helper: creation from the data map took " << watch4.RealTime() << "s"; + + } // processingInverseCorrection + + if (voxResTree && !voxResTreeInverse) { + LOG(info) << "fast space charge correction helper: init inverse correction from direct correction.."; + TStopwatch watch4; + helper->initInverse(correction, false); + LOG(info) << "fast space charge correction helper: init inverse correction took " << watch4.RealTime() << "s"; + } + + LOGP(info, "Creation from track residuals tooks in total: {}s", watch.RealTime()); + + return std::move(correctionPtr); + +} // createFromTrackResiduals void TPCFastSpaceChargeCorrectionHelper::initInverse(o2::gpu::TPCFastSpaceChargeCorrection& correction, bool prn) { @@ -670,128 +921,95 @@ void TPCFastSpaceChargeCorrectionHelper::initInverse(std::vector helper; std::vector splineParameters; - ChebyshevFit1D chebFitterX, chebFitterU, chebFitterV; for (int row = iThread; row < mGeo.getNumberOfRows(); row += mNthreads) { - TPCFastSpaceChargeCorrection::SplineType spline = correction.getSpline(slice, row); - helper.setSpline(spline, 10, 10); - std::vector dataPointCU, dataPointCV, dataPointF; + auto& sectorRowInfo = correction.getSectorRowInfo(sector, row); + sectorRowInfo.gridReal = sectorRowInfo.gridMeasured; - float u0, u1, v0, v1; - mGeo.convScaledUVtoUV(slice, row, 0., 0., u0, v0); - mGeo.convScaledUVtoUV(slice, row, 1., 1., u1, v1); - - double x = mGeo.getRowInfo(row).x; - int nPointsU = (spline.getGridX1().getNumberOfKnots() - 1) * 10; - int nPointsV = (spline.getGridX2().getNumberOfKnots() - 1) * 10; - - double stepU = (u1 - u0) / (nPointsU - 1); - double stepV = (v1 - v0) / (nPointsV - 1); + TPCFastSpaceChargeCorrection::SplineType spline = correction.getSpline(sector, row); + helper.setSpline(spline, 10, 10); - if (prn) { - LOG(info) << "u0 " << u0 << " u1 " << u1 << " v0 " << v0 << " v1 " << v1; - } - TPCFastSpaceChargeCorrection::RowActiveArea& area = correction.getSliceRowInfo(slice, row).activeArea; - area.cuMin = 1.e10; - area.cuMax = -1.e10; - - /* - v1 = area.vMax; - stepV = (v1 - v0) / (nPointsU - 1); - if (stepV < 1.f) { - stepV = 1.f; - } - */ - - for (double u = u0; u < u1 + stepU; u += stepU) { - for (double v = v0; v < v1 + stepV; v += stepV) { - float dx, du, dv; - correction.getCorrection(slice, row, u, v, dx, du, dv); - dx *= scaling[0]; - du *= scaling[0]; - dv *= scaling[0]; - // add remaining corrections - for (int i = 1; i < corrections.size(); ++i) { - float dxTmp, duTmp, dvTmp; - corrections[i]->getCorrection(slice, row, u, v, dxTmp, duTmp, dvTmp); - dx += dxTmp * scaling[i]; - du += duTmp * scaling[i]; - dv += dvTmp * scaling[i]; + std::vector gridU; + { + const auto& grid = spline.getGridX1(); + for (int i = 0; i < grid.getNumberOfKnots(); i++) { + if (i == grid.getNumberOfKnots() - 1) { + gridU.push_back(grid.getKnot(i).u); + break; } - double cx = x + dx; - double cu = u + du; - double cv = v + dv; - if (cu < area.cuMin) { - area.cuMin = cu; + for (double s = 1.; s > 0.; s -= 0.1) { + gridU.push_back(s * grid.getKnot(i).u + (1. - s) * grid.getKnot(i + 1).u); } - if (cu > area.cuMax) { - area.cuMax = cu; + } + } + std::vector gridV; + { + const auto& grid = spline.getGridX2(); + for (int i = 0; i < grid.getNumberOfKnots(); i++) { + if (i == grid.getNumberOfKnots() - 1) { + gridV.push_back(grid.getKnot(i).u); + break; } - - dataPointCU.push_back(cu); - dataPointCV.push_back(cv); - dataPointF.push_back(dx); - dataPointF.push_back(du); - dataPointF.push_back(dv); - - if (prn) { - LOG(info) << "measurement cu " << cu << " cv " << cv << " dx " << dx << " du " << du << " dv " << dv; + for (double s = 1.; s > 0.; s -= 0.1) { + gridV.push_back(s * grid.getKnot(i).u + (1. - s) * grid.getKnot(i + 1).u); } - } // v - } // u - - if (area.cuMax - area.cuMin < 0.2) { - area.cuMax = .1; - area.cuMin = -.1; - } - if (area.cvMax < 0.1) { - area.cvMax = .1; - } - if (prn) { - LOG(info) << "slice " << slice << " row " << row << " max drift L = " << correction.getMaxDriftLength(slice, row) - << " active area: cuMin " << area.cuMin << " cuMax " << area.cuMax << " vMax " << area.vMax << " cvMax " << area.cvMax; + } } - TPCFastSpaceChargeCorrection::SliceRowInfo& info = correction.getSliceRowInfo(slice, row); - info.gridCorrU0 = area.cuMin; - info.scaleCorrUtoGrid = spline.getGridX1().getUmax() / (area.cuMax - area.cuMin); - info.scaleCorrVtoGrid = spline.getGridX2().getUmax() / area.cvMax; - - info.gridCorrU0 = u0; - info.gridCorrV0 = info.gridV0; - info.scaleCorrUtoGrid = spline.getGridX1().getUmax() / (u1 - info.gridCorrU0); - info.scaleCorrVtoGrid = spline.getGridX2().getUmax() / (v1 - info.gridCorrV0); - - int nDataPoints = dataPointCU.size(); - for (int i = 0; i < nDataPoints; i++) { - dataPointCU[i] = (dataPointCU[i] - info.gridCorrU0) * info.scaleCorrUtoGrid; - dataPointCV[i] = (dataPointCV[i] - info.gridCorrV0) * info.scaleCorrVtoGrid; + std::vector dataPointGridU, dataPointGridV, dataPointF, dataPointWeight; + dataPointGridU.reserve(gridU.size() * gridV.size()); + dataPointGridV.reserve(gridU.size() * gridV.size()); + dataPointF.reserve(3 * gridU.size() * gridV.size()); + dataPointWeight.reserve(gridU.size() * gridV.size()); + + for (int iu = 0; iu < gridU.size(); iu++) { + for (int iv = 0; iv < gridV.size(); iv++) { + float y, z; + correction.convGridToLocal(sector, row, gridU[iu], gridV[iv], y, z); + double dx = 0, dy = 0, dz = 0; + + // add corrections + for (int i = 0; i < corrections.size(); ++i) { + float dxTmp, dyTmp, dzTmp; + corrections[i]->getCorrectionLocal(sector, row, y, z, dxTmp, dyTmp, dzTmp); + dx += dxTmp * scaling[i]; + dy += dyTmp * scaling[i]; + dz += dzTmp * scaling[i]; + } + float gridU, gridV, scale; + correction.convRealLocalToGrid(sector, row, y + dy, z + dz, gridU, gridV, scale); + dataPointGridU.push_back(gridU); + dataPointGridV.push_back(gridV); + dataPointF.push_back(scale * dx); + dataPointF.push_back(scale * dy); + dataPointF.push_back(scale * dz); + dataPointWeight.push_back(1.); + } } + int nDataPoints = dataPointGridU.size(); splineParameters.resize(spline.getNumberOfParameters()); helper.approximateDataPoints(spline, splineParameters.data(), 0., spline.getGridX1().getUmax(), 0., spline.getGridX2().getUmax(), - dataPointCU.data(), dataPointCV.data(), - dataPointF.data(), dataPointCU.size()); + dataPointGridU.data(), dataPointGridV.data(), + dataPointF.data(), dataPointWeight.data(), nDataPoints); - float* splineX = correction.getSplineData(slice, row, 1); - float* splineUV = correction.getSplineData(slice, row, 2); + float* splineX = correction.getCorrectionDataInvX(sector, row); + float* splineUV = correction.getCorrectionDataInvYZ(sector, row); for (int i = 0; i < spline.getNumberOfParameters() / 3; i++) { splineX[i] = splineParameters[3 * i + 0]; splineUV[2 * i + 0] = splineParameters[3 * i + 1]; @@ -812,9 +1030,168 @@ void TPCFastSpaceChargeCorrectionHelper::initInverse(std::vector>& additionalCorrections, bool /*prn*/) +{ + /// merge several corrections + + TStopwatch watch; + LOG(info) << "fast space charge correction helper: Merge corrections"; + + const auto& geo = mainCorrection.getGeometry(); + + for (int sector = 0; sector < geo.getNumberOfSectors(); sector++) { + + auto myThread = [&](int iThread) { + for (int row = iThread; row < geo.getNumberOfRows(); row += mNthreads) { + const auto& spline = mainCorrection.getSpline(sector, row); + + float* splineParameters = mainCorrection.getCorrectionData(sector, row); + float* splineParametersInvX = mainCorrection.getCorrectionDataInvX(sector, row); + float* splineParametersInvYZ = mainCorrection.getCorrectionDataInvYZ(sector, row); + + auto& secRowInfo = mainCorrection.getSectorRowInfo(sector, row); + + constexpr int nKnotPar1d = 4; + constexpr int nKnotPar2d = nKnotPar1d * 2; + constexpr int nKnotPar3d = nKnotPar1d * 3; + + { // scale the main correction + for (int i = 0; i < 3; i++) { + secRowInfo.maxCorr[i] *= mainScale; + secRowInfo.minCorr[i] *= mainScale; + } + double parscale[4] = {mainScale, mainScale, mainScale, mainScale * mainScale}; + for (int iknot = 0, ind = 0; iknot < spline.getNumberOfKnots(); iknot++) { + for (int ipar = 0; ipar < nKnotPar1d; ++ipar) { + for (int idim = 0; idim < 3; idim++, ind++) { + splineParameters[ind] *= parscale[ipar]; + } + } + } + for (int iknot = 0, ind = 0; iknot < spline.getNumberOfKnots(); iknot++) { + for (int ipar = 0; ipar < nKnotPar1d; ++ipar) { + for (int idim = 0; idim < 1; idim++, ind++) { + splineParametersInvX[ind] *= parscale[ipar]; + } + } + } + for (int iknot = 0, ind = 0; iknot < spline.getNumberOfKnots(); iknot++) { + for (int ipar = 0; ipar < nKnotPar1d; ++ipar) { + for (int idim = 0; idim < 2; idim++, ind++) { + splineParametersInvYZ[ind] *= parscale[ipar]; + } + } + } + } + + // add the other corrections + + const auto& gridU = spline.getGridX1(); + const auto& gridV = spline.getGridX2(); + + for (int icorr = 0; icorr < additionalCorrections.size(); ++icorr) { + const auto& corr = *(additionalCorrections[icorr].first); + double scale = additionalCorrections[icorr].second; + auto& linfo = corr.getSectorRowInfo(sector, row); + secRowInfo.updateMaxValues(linfo.getMaxValues(), scale); + secRowInfo.updateMaxValues(linfo.getMinValues(), scale); + + double scaleU = secRowInfo.gridMeasured.getYscale() / linfo.gridMeasured.getYscale(); + double scaleV = secRowInfo.gridMeasured.getZscale() / linfo.gridMeasured.getZscale(); + double scaleRealU = secRowInfo.gridReal.getYscale() / linfo.gridReal.getYscale(); + double scaleRealV = secRowInfo.gridReal.getZscale() / linfo.gridReal.getZscale(); + + for (int iu = 0; iu < gridU.getNumberOfKnots(); iu++) { + double u = gridU.getKnot(iu).u; + for (int iv = 0; iv < gridV.getNumberOfKnots(); iv++) { + double v = gridV.getKnot(iv).u; + int knotIndex = spline.getKnotIndex(iu, iv); + float P[nKnotPar3d]; + + { // direct correction + float y, z; + mainCorrection.convGridToLocal(sector, row, u, v, y, z); + // return values: u, v, scaling factor + float lu, lv, ls; + corr.convLocalToGrid(sector, row, y, z, lu, lv, ls); + ls *= scale; + double parscale[4] = {ls, ls * scaleU, ls * scaleV, ls * ls * scaleU * scaleV}; + const auto& spl = corr.getSpline(sector, row); + spl.interpolateParametersAtU(corr.getCorrectionData(sector, row), lu, lv, P); + for (int ipar = 0, ind = 0; ipar < nKnotPar1d; ++ipar) { + for (int idim = 0; idim < 3; idim++, ind++) { + splineParameters[knotIndex * nKnotPar3d + ind] += parscale[ipar] * P[ind]; + } + } + } + + float y, z; + mainCorrection.convGridToRealLocal(sector, row, u, v, y, z); + // return values: u, v, scaling factor + float lu, lv, ls; + corr.convRealLocalToGrid(sector, row, y, z, lu, lv, ls); + ls *= scale; + double parscale[4] = {ls, ls * scaleRealU, ls * scaleRealV, ls * ls * scaleRealU * scaleRealV}; + + { // inverse X correction + corr.getSplineInvX(sector, row).interpolateParametersAtU(corr.getCorrectionDataInvX(sector, row), lu, lv, P); + for (int ipar = 0, ind = 0; ipar < nKnotPar1d; ++ipar) { + for (int idim = 0; idim < 1; idim++, ind++) { + splineParametersInvX[knotIndex * nKnotPar1d + ind] += parscale[ipar] * P[ind]; + } + } + } + + { // inverse YZ correction + corr.getSplineInvYZ(sector, row).interpolateParametersAtU(corr.getCorrectionDataInvYZ(sector, row), lu, lv, P); + for (int ipar = 0, ind = 0; ipar < nKnotPar1d; ++ipar) { + for (int idim = 0; idim < 2; idim++, ind++) { + splineParametersInvYZ[knotIndex * nKnotPar2d + ind] += parscale[ipar] * P[ind]; + } + } + } + + } // iv + } // iu + } // corrections + + } // row + }; // thread + + std::vector threads(mNthreads); + + // run n threads + for (int i = 0; i < mNthreads; i++) { + threads[i] = std::thread(myThread, i); + } + + // wait for the threads to finish + for (auto& th : threads) { + th.join(); + } + + } // sector + float duration = watch.RealTime(); + LOGP(info, "Merge of corrections tooks: {}s", duration); +} + +void TPCFastSpaceChargeCorrectionHelper::setDebugUseVoxelCenters() +{ + LOG(info) << "fast space charge correction helper: use voxel centers for correction"; + mDebugUseVoxelCenters = true; +} + +void TPCFastSpaceChargeCorrectionHelper::setDebugMirrorAdata2C() +{ + LOG(info) << "fast space charge correction helper: mirror A data to C data"; + mDebugMirrorAdata2C = true; } } // namespace tpc diff --git a/Detectors/TPC/calibration/src/TrackDump.cxx b/Detectors/TPC/calibration/src/TrackDump.cxx index 421750a5cb22b..72042a537dc5f 100644 --- a/Detectors/TPC/calibration/src/TrackDump.cxx +++ b/Detectors/TPC/calibration/src/TrackDump.cxx @@ -24,8 +24,6 @@ using namespace o2::tpc; using namespace o2::tpc::constants; namespace fs = std::filesystem; -o2::gpu::CorrectionMapsHelper o2::tpc::TrackDump::ClusterNativeAdd::sCorrHelper{}; - void TrackDump::filter(const gsl::span tracks, ClusterNativeAccess const& clusterIndex, const gsl::span clRefs, const gsl::span mcLabels) { if (!mTreeDump && outputFileName.size()) { @@ -197,8 +195,8 @@ float TrackDump::ClusterNativeAdd::gy() const float TrackDump::ClusterNativeAdd::lxc(float vertexTime) const { float x{0.f}, y{0.f}, z{0.f}; - if (sCorrHelper.getCorrMap()) { - sCorrHelper.Transform(sector, padrow, getPad(), getTime(), x, y, z, vertexTime); + if (corrMap) { + corrMap->Transform(sector, padrow, getPad(), getTime(), x, y, z, vertexTime); } return x; } @@ -206,8 +204,8 @@ float TrackDump::ClusterNativeAdd::lxc(float vertexTime) const float TrackDump::ClusterNativeAdd::lyc(float vertexTime) const { float x{0.f}, y{0.f}, z{0.f}; - if (sCorrHelper.getCorrMap()) { - sCorrHelper.Transform(sector, padrow, getPad(), getTime(), x, y, z, vertexTime); + if (corrMap) { + corrMap->Transform(sector, padrow, getPad(), getTime(), x, y, z, vertexTime); } return y; } @@ -229,17 +227,17 @@ float TrackDump::ClusterNativeAdd::gyc(float vertexTime) const float TrackDump::ClusterNativeAdd::zc(float vertexTime) const { float x{0.f}, y{0.f}, z{0.f}; - if (sCorrHelper.getCorrMap()) { - sCorrHelper.Transform(sector, padrow, getPad(), getTime(), x, y, z, vertexTime); + if (corrMap) { + corrMap->Transform(sector, padrow, getPad(), getTime(), x, y, z, vertexTime); } return z; } void TrackDump::ClusterNativeAdd::loadCorrMaps(std::string_view corrMapFile, std::string_view corrMapFileRef) { - sCorrHelper.setOwner(true); - sCorrHelper.setCorrMap(gpu::TPCFastTransform::loadFromFile(corrMapFile.data())); - if (!corrMapFileRef.empty()) { - sCorrHelper.setCorrMapRef(gpu::TPCFastTransform::loadFromFile(corrMapFileRef.data())); - } + auto fastTransformTmp = gpu::TPCFastTransform::loadFromFile(corrMapFile.data()); + o2::gpu::aligned_unique_buffer_ptr buffer; + gpu::TPCFastTransformPOD::create(buffer, *fastTransformTmp); + corrMapBuffer = std::move(buffer); + corrMap = corrMapBuffer.get(); } diff --git a/Detectors/TPC/monitor/src/SimpleEventDisplayGUI.cxx b/Detectors/TPC/monitor/src/SimpleEventDisplayGUI.cxx index 5509aa7473fc8..0d032443c9754 100644 --- a/Detectors/TPC/monitor/src/SimpleEventDisplayGUI.cxx +++ b/Detectors/TPC/monitor/src/SimpleEventDisplayGUI.cxx @@ -1227,7 +1227,7 @@ void SimpleEventDisplayGUI::showClusters(int roc, int row) } if (fillSingleTB && std::abs(cl.getTime() - timeBin) < 2) { const auto ly = gpuGeom.LinearPad2Y(sector, irow, cl.getPad() + 0.5); - mClustersRowPad->SetNextPoint(gpuGeom.Row2X(irow), (sector >= GPUCA_NSECTORS / 2) ? -ly : ly); + mClustersRowPad->SetNextPoint(gpuGeom.Row2X(irow), (sector >= gpuGeom.NSECTORS / 2) ? -ly : ly); } } // fmt::print("\n"); diff --git a/Detectors/TPC/reconstruction/CMakeLists.txt b/Detectors/TPC/reconstruction/CMakeLists.txt index 29e6d692968b7..0045aad7aa4c7 100644 --- a/Detectors/TPC/reconstruction/CMakeLists.txt +++ b/Detectors/TPC/reconstruction/CMakeLists.txt @@ -96,6 +96,13 @@ o2_add_test(GPUCATracking SOURCES test/testGPUCATracking.cxx ENVIRONMENT O2_ROOT=${CMAKE_BINARY_DIR}/stage) +o2_add_test(GPUTPCGeometry + COMPONENT_NAME tpc + LABELS tpc + PUBLIC_LINK_LIBRARIES O2::TPCBase O2::GPUDataTypes + SOURCES test/testGPUGeometry.cxx + ENVIRONMENT O2_ROOT=${CMAKE_BINARY_DIR}/stage) + o2_add_test(HwClusterer COMPONENT_NAME tpc LABELS tpc diff --git a/Detectors/TPC/reconstruction/include/TPCReconstruction/TPCFastTransformHelperO2.h b/Detectors/TPC/reconstruction/include/TPCReconstruction/TPCFastTransformHelperO2.h index f94bff0acc076..943521e3b11ec 100644 --- a/Detectors/TPC/reconstruction/include/TPCReconstruction/TPCFastTransformHelperO2.h +++ b/Detectors/TPC/reconstruction/include/TPCReconstruction/TPCFastTransformHelperO2.h @@ -21,9 +21,8 @@ #ifndef ALICEO2_TPC_TPCFASTTRANSFORMHELPERO2_H_ #define ALICEO2_TPC_TPCFASTTRANSFORMHELPERO2_H_ -#include "TPCFastTransform.h" -#include "Rtypes.h" -#include +#include "TPCFastTransformPOD.h" +#include "GPUCommonRtypes.h" namespace o2 { @@ -55,14 +54,21 @@ class TPCFastTransformHelperO2 /// _______________ Main functionality ________________________ /// creates TPCFastTransform object - std::unique_ptr create(Long_t TimeStamp); + std::unique_ptr create(int64_t TimeStamp); /// creates TPCFastTransform object - std::unique_ptr create(Long_t TimeStamp, const TPCFastSpaceChargeCorrection& correction); + std::unique_ptr create(int64_t TimeStamp, const TPCFastSpaceChargeCorrection& correction); /// Updates the transformation with the new time stamp - int updateCalibration(TPCFastTransform& transform, Long_t TimeStamp, float vDriftFactor = 1.f, float vDriftRef = 0.f, float driftTimeOffset = 0.f); - + int updateCalibration(TPCFastTransform& fastTransform, int64_t TimeStamp, float vDriftFactor = 1.f, float vDriftRef = 0.f, float driftTimeOffset = 0.f) + { + return updateCalibrationImpl(fastTransform, TimeStamp, vDriftFactor, vDriftRef, driftTimeOffset); + } + + int updateCalibration(TPCFastTransformPOD& fastTransform, int64_t TimeStamp, float vDriftFactor = 1.f, float vDriftRef = 0.f, float driftTimeOffset = 0.f) + { + return updateCalibrationImpl(fastTransform, TimeStamp, vDriftFactor, vDriftRef, driftTimeOffset); + } /// _______________ Utilities ________________________ const TPCFastTransformGeo& getGeometry() { return mGeo; } @@ -73,6 +79,9 @@ class TPCFastTransformHelperO2 /// initialization void init(); + template + int updateCalibrationImpl(T& transform, int64_t TimeStamp, float vDriftFactor, float vDriftRef, float driftTimeOffset); + static TPCFastTransformHelperO2* sInstance; ///< singleton instance bool mIsInitialized = 0; ///< initialization flag TPCFastTransformGeo mGeo; ///< geometry parameters diff --git a/Detectors/TPC/reconstruction/macro/createTPCSpaceChargeCorrection.C b/Detectors/TPC/reconstruction/macro/createTPCSpaceChargeCorrection.C index 723cf2ee30491..af066598d1317 100644 --- a/Detectors/TPC/reconstruction/macro/createTPCSpaceChargeCorrection.C +++ b/Detectors/TPC/reconstruction/macro/createTPCSpaceChargeCorrection.C @@ -397,10 +397,9 @@ void debugInterpolation(utils::TreeStreamRedirector& pcstream, const o2::gpu::TPCFastTransformGeo& geo, TPCFastTransform* fastTransform) { - for (int slice = 0; slice < geo.getNumberOfSlices(); slice += 1) { - // for (int slice = 21; slice < 22; slice += 1) { - std::cout << "debug slice " << slice << " ... " << std::endl; - const o2::gpu::TPCFastTransformGeo::SliceInfo& sliceInfo = geo.getSliceInfo(slice); + for (int sector = 0; sector < geo.getNumberOfSectors(); sector += 1) { + // for (int sector = 21; sector < 22; sector += 1) { + std::cout << "debug sector " << sector << " ... " << std::endl; for (int row = 0; row < geo.getNumberOfRows(); row++) { int nPads = geo.getRowInfo(row).maxPad + 1; @@ -411,28 +410,28 @@ void debugInterpolation(utils::TreeStreamRedirector& pcstream, // non-corrected point fastTransform->setApplyCorrectionOff(); float lx, ly, lz; - fastTransform->Transform(slice, row, pad, time, lx, ly, lz); + fastTransform->Transform(sector, row, pad, time, lx, ly, lz); float gx, gy, gz, r, phi; - geo.convLocalToGlobal(slice, lx, ly, lz, gx, gy, gz); + geo.convLocalToGlobal(sector, lx, ly, lz, gx, gy, gz); r = std::sqrt(lx * lx + ly * ly); phi = std::atan2(gy, gx); fastTransform->setApplyCorrectionOn(); // fast transformation float lxT, lyT, lzT; - fastTransform->Transform(slice, row, pad, time, lxT, lyT, lzT); + fastTransform->Transform(sector, row, pad, time, lxT, lyT, lzT); float gxT, gyT, gzT, rT; - geo.convLocalToGlobal(slice, lxT, lyT, lzT, gxT, gyT, gzT); + geo.convLocalToGlobal(sector, lxT, lyT, lzT, gxT, gyT, gzT); rT = std::sqrt(lxT * lxT + lyT * lyT); // the original correction double gdC[3] = {0, 0, 0}; - Side side = slice < geo.getNumberOfSlicesA() ? Side::A : Side::C; + Side side = sector < geo.getNumberOfSectorsA() ? Side::A : Side::C; if (spaceCharge) { spaceCharge->getCorrections(gx, gy, gz, side, gdC[0], gdC[1], gdC[2]); } float ldxC, ldyC, ldzC; - geo.convGlobalToLocal(slice, gdC[0], gdC[1], gdC[2], ldxC, ldyC, ldzC); + geo.convGlobalToLocal(sector, gdC[0], gdC[1], gdC[2], ldxC, ldyC, ldzC); double rC = std::sqrt((gx + gdC[0]) * (gx + gdC[0]) + (gy + gdC[1]) * (gy + gdC[1])); @@ -466,7 +465,7 @@ void debugInterpolation(utils::TreeStreamRedirector& pcstream, if (spaceChargeExB) { double gdC_ExB[3] = {0, 0, 0}; spaceChargeExB->getCorrections(gx, gy, gz, side, gdC_ExB[0], gdC_ExB[1], gdC_ExB[2]); - geo.convGlobalToLocal(slice, gdC_ExB[0], gdC_ExB[1], gdC_ExB[2], ldxC_ExB, ldyC_ExB, ldzC_ExB); + geo.convGlobalToLocal(sector, gdC_ExB[0], gdC_ExB[1], gdC_ExB[2], ldxC_ExB, ldyC_ExB, ldzC_ExB); } // static distortions @@ -474,18 +473,18 @@ void debugInterpolation(utils::TreeStreamRedirector& pcstream, if (spaceChargeStack) { double gdC_static[3] = {0, 0, 0}; spaceChargeStack->getCorrections(gx, gy, gz, side, gdC_static[0], gdC_static[1], gdC_static[2]); - geo.convGlobalToLocal(slice, gdC_static[0], gdC_static[1], gdC_static[2], ldxC_static, ldyC_static, ldzC_static); + geo.convGlobalToLocal(sector, gdC_static[0], gdC_static[1], gdC_static[2], ldxC_static, ldyC_static, ldzC_static); } // get combined corrections double dx_comb = 0, dy_comb = 0, dz_comb = 0; - getGlobalSpaceChargeCorrectionLinearCombination(slice, gx, gy, gz, dx_comb, dy_comb, dz_comb); + getGlobalSpaceChargeCorrectionLinearCombination(sector, gx, gy, gz, dx_comb, dy_comb, dz_comb); float ldxC_comb, ldyC_comb, ldzC_comb; - geo.convGlobalToLocal(slice, dx_comb, dy_comb, dz_comb, ldxC_comb, ldyC_comb, ldzC_comb); + geo.convGlobalToLocal(sector, dx_comb, dy_comb, dz_comb, ldxC_comb, ldyC_comb, ldzC_comb); pcstream << "fastTransform" // internal coordinates - << "slice=" << slice + << "sector=" << sector << "row=" << row << "pad=" << pad << "time=" << time @@ -613,10 +612,9 @@ void debugGridpoints(utils::TreeStreamRedirector& pcstream, const o2::gpu::TPCFa break; } } - float u = 0.f, v = 0.f; - geo.convLocalToUV(sector, y0, z0, u, v); + float pad = 0.f, time = 0.f; - fastTransform->convUVtoPadTime(sector, row, u, v, pad, time, 0.f); + fastTransform->convLocalToPadTime(sector, row, y0, z0, pad, time, 0.f); if (pad < 0) { continue; } diff --git a/Detectors/TPC/reconstruction/src/TPCFastTransformHelperO2.cxx b/Detectors/TPC/reconstruction/src/TPCFastTransformHelperO2.cxx index 7db84f0e94968..8ae5cbc5fae4a 100644 --- a/Detectors/TPC/reconstruction/src/TPCFastTransformHelperO2.cxx +++ b/Detectors/TPC/reconstruction/src/TPCFastTransformHelperO2.cxx @@ -14,17 +14,18 @@ #include "TPCReconstruction/TPCFastTransformHelperO2.h" +#ifndef GPUCA_STANDALONE #include "TPCBase/Mapper.h" #include "TPCBase/PadRegionInfo.h" +#endif #include "TPCBase/ParameterDetector.h" #include "TPCBase/ParameterElectronics.h" #include "TPCBase/ParameterGas.h" #include "TPCBase/Sector.h" #include "DataFormatsTPC/Defs.h" #include "TPCFastTransform.h" -#include "Spline2DHelper.h" -#include "Riostream.h" -#include +#include "GPUTPCGeometry.h" +#include using namespace o2::gpu; @@ -49,48 +50,28 @@ void TPCFastTransformHelperO2::init() { // initialize geometry - const Mapper& mapper = Mapper::instance(); + const GPUTPCGeometry geo; - const int nRows = mapper.getNumberOfRows(); + const int nRows = geo.NROWS; mGeo.startConstruction(nRows); + mGeo.setTPCzLength(geo.TPCLength()); - auto& detParam = ParameterDetector::Instance(); - float tpcZlengthSideA = detParam.TPClength; - float tpcZlengthSideC = detParam.TPClength; - - mGeo.setTPCzLength(tpcZlengthSideA, tpcZlengthSideC); - - mGeo.setTPCalignmentZ(0.); - - for (int iRow = 0; iRow < mGeo.getNumberOfRows(); iRow++) { - Sector sector = 0; - int regionNumber = 0; - while (iRow >= mapper.getGlobalRowOffsetRegion(regionNumber) + mapper.getNumberOfRowsRegion(regionNumber)) { - regionNumber++; - } - - const PadRegionInfo& region = mapper.getPadRegionInfo(regionNumber); - - int nPads = mapper.getNumberOfPadsInRowSector(iRow); - float padWidth = region.getPadWidth(); - - const GlobalPadNumber pad = mapper.globalPadNumber(PadPos(iRow, nPads / 2)); - const PadCentre& padCentre = mapper.padCentre(pad); - float xRow = padCentre.X(); - - mGeo.setTPCrow(iRow, xRow, nPads, padWidth); + for (int iRow = 0; iRow < nRows; iRow++) { + mGeo.setTPCrow(iRow, geo.Row2X(iRow), geo.NPads(iRow), geo.PadWidth(iRow)); } mGeo.finishConstruction(); +#ifndef GPUCA_STANDALONE // check if calculated pad geometry is consistent with the map testGeometry(mGeo); +#endif mIsInitialized = 1; } -std::unique_ptr TPCFastTransformHelperO2::create(Long_t TimeStamp, const TPCFastSpaceChargeCorrection& correction) +std::unique_ptr TPCFastTransformHelperO2::create(int64_t TimeStamp, const TPCFastSpaceChargeCorrection& correction) { /// initializes TPCFastTransform object @@ -114,22 +95,18 @@ std::unique_ptr TPCFastTransformHelperO2::create(Long_t TimeSt // set some initial calibration values, will be reinitialised later int updateCalibration() const float t0 = 0.; const float vDrift = 0.f; - const float vdCorrY = 0.; - const float ldCorr = 0.; - const float tofCorr = 0.; - const float primVtxZ = 0.; const long int initTimeStamp = -1; - fastTransform.setCalibration(initTimeStamp, t0, vDrift, vdCorrY, ldCorr, tofCorr, primVtxZ); + fastTransform.setCalibration1(initTimeStamp, t0, vDrift); fastTransform.finishConstruction(); } updateCalibration(fastTransform, TimeStamp); - return std::move(fastTransformPtr); + return fastTransformPtr; } -std::unique_ptr TPCFastTransformHelperO2::create(Long_t TimeStamp) +std::unique_ptr TPCFastTransformHelperO2::create(int64_t TimeStamp) { /// initializes TPCFastTransform object @@ -145,7 +122,8 @@ std::unique_ptr TPCFastTransformHelperO2::create(Long_t TimeSt return create(TimeStamp, correction); } -int TPCFastTransformHelperO2::updateCalibration(TPCFastTransform& fastTransform, Long_t TimeStamp, float vDriftFactor, float vDriftRef, float driftTimeOffset) +template +int TPCFastTransformHelperO2::updateCalibrationImpl(T& fastTransform, int64_t TimeStamp, float vDriftFactor, float vDriftRef, float driftTimeOffset) { // Update the calibration with the new time stamp LOGP(debug, "Updating calibration: timestamp:{} vdriftFactor:{} vdriftRef:{}", TimeStamp, vDriftFactor, vDriftRef); @@ -159,8 +137,6 @@ int TPCFastTransformHelperO2::updateCalibration(TPCFastTransform& fastTransform, // search for the calibration database ... - auto& detParam = ParameterDetector::Instance(); - auto& gasParam = ParameterGas::Instance(); auto& elParam = ParameterElectronics::Instance(); // start the initialization @@ -171,29 +147,24 @@ int TPCFastTransformHelperO2::updateCalibration(TPCFastTransform& fastTransform, const double vDrift = elParam.ZbinWidth * vDriftRef * vDriftFactor; // cm/timebin // fast transform formula: - // L = (t-t0)*(mVdrift + mVdriftCorrY*yLab ) + mLdriftCorr - // Z = Z(L) + tpcAlignmentZ + // L = (t-t0)*mVdrift + // Z = Z(L) // spline corrections for xyz - // Time-of-flight correction: ldrift += dist-to-vtx*tofCorr const double t0 = (driftTimeOffset + elParam.getAverageShapingTime()) / elParam.ZbinWidth; - const double vdCorrY = 0.; - const double ldCorr = 0.; - const double tofCorr = 0.; - const double primVtxZ = 0.; - - fastTransform.setCalibration(TimeStamp, t0, vDrift, vdCorrY, ldCorr, tofCorr, primVtxZ); + fastTransform.setCalibration1(TimeStamp, t0, vDrift); return 0; } +#ifndef GPUCA_STANDALONE void TPCFastTransformHelperO2::testGeometry(const TPCFastTransformGeo& geo) const { const Mapper& mapper = Mapper::instance(); - if (geo.getNumberOfSlices() != Sector::MAXSECTOR) { - LOG(fatal) << "Wrong number of sectors :" << geo.getNumberOfSlices() << " instead of " << Sector::MAXSECTOR << std::endl; + if (geo.getNumberOfSectors() != Sector::MAXSECTOR) { + LOG(fatal) << "Wrong number of sectors :" << geo.getNumberOfSectors() << " instead of " << Sector::MAXSECTOR << std::endl; } if (geo.getNumberOfRows() != mapper.getNumberOfRows()) { @@ -217,15 +188,17 @@ void TPCFastTransformHelperO2::testGeometry(const TPCFastTransformGeo& geo) cons for (int pad = 0; pad < nPads; pad++) { const GlobalPadNumber p = mapper.globalPadNumber(PadPos(row, pad)); const PadCentre& c = mapper.padCentre(p); - double u = geo.convPadToU(row, pad); + + float y, z; + geo.convPadDriftLengthToLocal(0, row, pad, 0., y, z); const double dx = x - c.X(); - const double dy = u - (-c.Y()); // diferent sign convention for Y coordinate in the map + const double dy = y - (-c.Y()); // diferent sign convention for Y coordinate in the map if (fabs(dx) >= 1.e-6 || fabs(dy) >= 1.e-5) { LOG(warning) << "wrong calculated pad position:" << " row " << row << " pad " << pad << " x calc " << x << " x in map " << c.X() << " dx " << (x - c.X()) - << " y calc " << u << " y in map " << -c.Y() << " dy " << dy << std::endl; + << " y calc " << y << " y in map " << -c.Y() << " dy " << dy << std::endl; } if (fabs(maxDx) < fabs(dx)) { maxDx = dx; @@ -241,5 +214,10 @@ void TPCFastTransformHelperO2::testGeometry(const TPCFastTransformGeo& geo) cons << " max Dx " << maxDx << " max Dy " << maxDy << std::endl; } } +#endif + +template int TPCFastTransformHelperO2::updateCalibrationImpl(TPCFastTransform&, int64_t, float, float, float); +template int TPCFastTransformHelperO2::updateCalibrationImpl(TPCFastTransformPOD&, int64_t, float, float, float); + } // namespace tpc } // namespace o2 diff --git a/Detectors/TPC/reconstruction/test/testGPUCATracking.cxx b/Detectors/TPC/reconstruction/test/testGPUCATracking.cxx index 0debfa72dd7fa..20660473f4c37 100644 --- a/Detectors/TPC/reconstruction/test/testGPUCATracking.cxx +++ b/Detectors/TPC/reconstruction/test/testGPUCATracking.cxx @@ -24,8 +24,7 @@ #include "DataFormatsTPC/ClusterNativeHelper.h" #include "TPCReconstruction/TPCFastTransformHelperO2.h" -#include "CorrectionMapsHelper.h" -#include "TPCFastTransform.h" +#include "TPCFastTransformPOD.h" #include "GPUO2Interface.h" #include "GPUO2InterfaceUtils.h" #include "GPUO2InterfaceConfiguration.h" @@ -74,11 +73,11 @@ BOOST_AUTO_TEST_CASE(CATracking_test1) config.configWorkflow.inputs.set(gpudatatypes::InOutType::TPCClusters); config.configWorkflow.outputs.set(gpudatatypes::InOutType::TPCMergedTracks); - std::unique_ptr fastTransform(TPCFastTransformHelperO2::instance()->create(0)); - std::unique_ptr fastTransformHelper(new CorrectionMapsHelper()); - fastTransformHelper->setCorrMap(fastTransform.get()); - config.configCalib.fastTransform = fastTransform.get(); - config.configCalib.fastTransformHelper = fastTransformHelper.get(); + auto fastTransformTmp = TPCFastTransformHelperO2::instance()->create(0); + aligned_unique_buffer_ptr fastTransformBuf; + TPCFastTransformPOD::create(fastTransformBuf, *fastTransformTmp); + config.configCalib.fastTransform = fastTransformBuf.get(); + auto dEdxCalibContainer = GPUO2InterfaceUtils::getCalibdEdxContainerDefault(); config.configCalib.dEdxCalibContainer = dEdxCalibContainer.get(); std::unique_ptr gainCalib = GPUO2InterfaceUtils::getPadGainCalibDefault(); diff --git a/Detectors/TPC/reconstruction/test/testGPUGeometry.cxx b/Detectors/TPC/reconstruction/test/testGPUGeometry.cxx new file mode 100644 index 0000000000000..e7cfb25c56087 --- /dev/null +++ b/Detectors/TPC/reconstruction/test/testGPUGeometry.cxx @@ -0,0 +1,68 @@ +// 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 testGPUGeometry.cxx +/// \brief Compare GPUTPCGeometry.h to o2::tpc::Mapper +/// \author David Rohr + +#define BOOST_TEST_MODULE Test TPC GPUTPCGeometry +#define BOOST_TEST_MAIN +#define BOOST_TEST_DYN_LINK +#include +#include "DataFormatsTPC/Constants.h" +#include "TPCBase/Mapper.h" +#include "TPCBase/PadRegionInfo.h" +#include "TPCBase/ParameterDetector.h" +#include "GPUTPCGeometry.h" + +using namespace o2::gpu; + +namespace o2 +{ +namespace tpc +{ +/// @brief Test 1 basic class IO tests +BOOST_AUTO_TEST_CASE(GPUTPCGeometry_test1) +{ + const Mapper& mapper = Mapper::instance(); + const GPUTPCGeometry geo; + const auto regions = mapper.getMapPadRegionInfo(); + + BOOST_CHECK_EQUAL(mapper.getNumberOfPadRegions(), geo.NRegions()); + BOOST_CHECK_EQUAL(mapper.NSECTORS, geo.NSECTORS); + BOOST_CHECK_EQUAL(mapper.PADROWS, geo.NROWS); + + auto& detParam = ParameterDetector::Instance(); + BOOST_CHECK_EQUAL(detParam.TPClength, geo.TPCLength()); + + /*for (unsigned int i = 0; i < mapper.NPARTITIONS; i++) { + BOOST_CHECK_EQUAL(???, geo.GetSectorFECOffset(i)); // TODO: Get value from mapper and compare! + }*/ + + for (unsigned int i = 0; i < mapper.getNumberOfPadRegions(); i++) { + BOOST_CHECK_EQUAL(mapper.ROWSPERREGION[i], geo.GetRegionRows(i)); + BOOST_CHECK_EQUAL(mapper.ROWOFFSET[i], geo.GetRegionStart(i)); + // BOOST_CHECK_EQUAL(???, geo.GetSampaMapping(i)); // TODO: Get value from mapper and compare! + // BOOST_CHECK_EQUAL(???, geo.GetChannelOffset(i)); // TODO: Get value from mapper and compare! + BOOST_CHECK_EQUAL(regions[i].getPadHeight(), geo.PadHeightByRegion(i)); + BOOST_CHECK_EQUAL(regions[i].getPadWidth(), geo.PadWidthByRegion(i)); + } + + for (unsigned int i = 0; i < mapper.PADROWS; i++) { + BOOST_CHECK_EQUAL(mapper.REGION[i], geo.GetRegion(i)); + unsigned int region = mapper.REGION[i]; + BOOST_CHECK_EQUAL(regions[region].getPadsInRowRegion(mapper.getLocalRowFromGlobalRow(i)), geo.NPads(i)); + const auto& pos = mapper.padCentre(mapper.getGlobalPadNumber(mapper.getLocalRowFromGlobalRow(i), 0, region)); + BOOST_CHECK_EQUAL(pos.x(), geo.Row2X(i)); + } +} +} // namespace tpc +} // namespace o2 diff --git a/Detectors/TPC/reconstruction/test/testTPCFastTransform.cxx b/Detectors/TPC/reconstruction/test/testTPCFastTransform.cxx index 5e37bd608c4a1..fee63e9e38bc2 100644 --- a/Detectors/TPC/reconstruction/test/testTPCFastTransform.cxx +++ b/Detectors/TPC/reconstruction/test/testTPCFastTransform.cxx @@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE(FastTransform_test1) BOOST_CHECK_EQUAL(geo.test(), 0); - BOOST_CHECK_EQUAL(geo.getNumberOfSlices(), Sector::MAXSECTOR); + BOOST_CHECK_EQUAL(geo.getNumberOfSectors(), Sector::MAXSECTOR); BOOST_CHECK_EQUAL(geo.getNumberOfRows(), mapper.getNumberOfRows()); double maxDx = 0, maxDy = 0; @@ -71,15 +71,16 @@ BOOST_AUTO_TEST_CASE(FastTransform_test1) for (int pad = 0; pad < nPads; pad++) { const GlobalPadNumber p = mapper.globalPadNumber(PadPos(row, pad)); const PadCentre& c = mapper.padCentre(p); - float u = 0, v = 0; - fastTransform.convPadTimeToUV(0, row, pad, 0, u, v, 0.); - + float y = 0, z = 0; + int sector = 0; + float time = 0.; + fastTransform.convPadTimeToLocal(sector, row, pad, time, y, z, 0.); double dx = x - c.X(); - double dy = u - (-c.Y()); // diferent sign convention for Y coordinate in the map + double dy = y - (-c.Y()); // diferent sign convention for Y coordinate in the map BOOST_CHECK(fabs(dx) < 1.e-6); BOOST_CHECK(fabs(dy) < 1.e-5); if (fabs(dy) >= 1.e-5) { - std::cout << "row " << row << " pad " << pad << " y calc " << u << " y in map " << -c.Y() << " dy " << dy << std::endl; + std::cout << "row " << row << " pad " << pad << " y calc " << y << " y in map " << -c.Y() << " dy " << dy << std::endl; } if (fabs(maxDx) < fabs(dx)) { maxDx = dx; @@ -104,46 +105,46 @@ BOOST_AUTO_TEST_CASE(FastTransform_test_setSpaceChargeCorrection) std::unique_ptr fastTransform0(TPCFastTransformHelperO2::instance()->create(0)); const TPCFastTransformGeo& geo = fastTransform0->getGeometry(); - auto correctionUV = [&](int roc, int /*row*/, const double u, const double v, double& dX, double& dU, double& dV) { + auto correctionUV = [&](int sector, int /*row*/, const double u, const double v, double& dX, double& dU, double& dV) { // float lx = geo.getRowInfo(row).x; dX = 1. + 1 * u + 0.1 * u * u; dU = 2. + 0.2 * u + 0.002 * u * u; // + 0.001 * u * u * u; dV = 3. + 0.1 * v + 0.01 * v * v; //+ 0.0001 * v * v * v; }; - auto correctionLocal = [&](int roc, int row, double ly, double lz, + auto correctionLocal = [&](int sector, int row, double ly, double lz, double& dx, double& dly, double& dlz) { float u, v; - geo.convLocalToUV(roc, ly, lz, u, v); + geo.convLocalToUV(sector, ly, lz, u, v); double du, dv; - correctionUV(roc, row, u, v, dx, du, dv); + correctionUV(sector, row, u, v, dx, du, dv); float ly1, lz1; - geo.convUVtoLocal(roc, u + du, v + dv, ly1, lz1); + geo.convUVtoLocal(sector, u + du, v + dv, ly1, lz1); dly = ly1 - ly; dlz = lz1 - lz; }; - int nRocs = geo.getNumberOfSlices(); + int nSectors = geo.getNumberOfSectors(); int nRows = geo.getNumberOfRows(); TPCFastSpaceChargeCorrectionMap& scData = TPCFastTransformHelperO2::instance()->getCorrectionMap(); - scData.init(nRocs, nRows); + scData.init(nSectors, nRows); - for (int iRoc = 0; iRoc < nRocs; iRoc++) { + for (int iSector = 0; iSector < nSectors; iSector++) { for (int iRow = 0; iRow < nRows; iRow++) { double dsu = 1. / (3 * 8 - 3); double dsv = 1. / (3 * 20 - 3); for (double su = 0.f; su < 1.f + .5 * dsu; su += dsv) { for (double sv = 0.f; sv < 1.f + .5 * dsv; sv += dsv) { float ly = 0.f, lz = 0.f; - geo.convScaledUVtoLocal(iRoc, iRow, su, sv, ly, lz); + geo.convScaledUVtoLocal(iSector, iRow, su, sv, ly, lz); double dx, dy, dz; - correctionLocal(iRoc, iRow, ly, lz, dx, dy, dz); - scData.addCorrectionPoint(iRoc, iRow, + correctionLocal(iSector, iRow, ly, lz, dx, dy, dz); + scData.addCorrectionPoint(iSector, iRow, ly, lz, dx, dy, dz); } } } // row - } // slice + } // sector std::unique_ptr fastTransform(TPCFastTransformHelperO2::instance()->create(0)); @@ -158,12 +159,12 @@ BOOST_AUTO_TEST_CASE(FastTransform_test_setSpaceChargeCorrection) double statDiff = 0., statN = 0.; double statDiffFile = 0., statNFile = 0.; - for (int slice = 0; slice < geo.getNumberOfSlices(); slice += 1) { - //std::cout << "slice " << slice << " ... " << std::endl; + for (int sector = 0; sector < geo.getNumberOfSectors(); sector += 1) { + // std::cout << "sector " << sector << " ... " << std::endl; - const TPCFastTransformGeo::SliceInfo& sliceInfo = geo.getSliceInfo(slice); + const TPCFastTransformGeo::SectorInfo& sectorInfo = geo.getSectorInfo(sector); - float lastTimeBin = fastTransform->getMaxDriftTime(slice, 0.f); + float lastTimeBin = fastTransform->getMaxDriftTime(sector, 0.f); for (int row = 0; row < geo.getNumberOfRows(); row++) { @@ -172,31 +173,31 @@ BOOST_AUTO_TEST_CASE(FastTransform_test_setSpaceChargeCorrection) for (int pad = 0; pad < nPads; pad += 10) { for (float time = 0; time < lastTimeBin; time += 30) { - //std::cout<<"slice "<setApplyCorrectionOff(); float x0, y0, z0; - fastTransform->Transform(slice, row, pad, time, x0, y0, z0); + fastTransform->Transform(sector, row, pad, time, x0, y0, z0); - BOOST_CHECK_EQUAL(geo.test(slice, row, y0, z0), 0); + BOOST_CHECK_EQUAL(geo.test(sector, row, y0, z0), 0); fastTransform->setApplyCorrectionOn(); float x1, y1, z1; - fastTransform->Transform(slice, row, pad, time, x1, y1, z1); + fastTransform->Transform(sector, row, pad, time, x1, y1, z1); // local to UV float u0, v0, u1, v1; - geo.convLocalToUV(slice, y0, z0, u0, v0); - geo.convLocalToUV(slice, y1, z1, u1, v1); + geo.convLocalToUV(sector, y0, z0, u0, v0); + geo.convLocalToUV(sector, y1, z1, u1, v1); double dx, du, dv; - correctionUV(slice, row, u0, v0, dx, du, dv); + correctionUV(sector, row, u0, v0, dx, du, dv); statDiff += fabs((x1 - x0) - dx) + fabs((u1 - u0) - du) + fabs((v1 - v0) - dv); statN += 3; - //std::cout << (x1 - x0) - dx << " " << (u1 - u0) - du << " " << (v1 - v0) - dv << std::endl; //": v0 " << v0 <<" z0 "<Transform(slice, row, pad, time, x1f, y1f, z1f); + fromFile->Transform(sector, row, pad, time, x1f, y1f, z1f); statDiffFile += fabs(x1f - x1) + fabs(y1f - y1) + fabs(z1f - z1); statNFile += 3; } diff --git a/Detectors/TPC/workflow/include/TPCWorkflow/RecoWorkflow.h b/Detectors/TPC/workflow/include/TPCWorkflow/RecoWorkflow.h index 8e8a6a96eed63..3526e9622b83c 100644 --- a/Detectors/TPC/workflow/include/TPCWorkflow/RecoWorkflow.h +++ b/Detectors/TPC/workflow/include/TPCWorkflow/RecoWorkflow.h @@ -30,7 +30,7 @@ struct InputSpec; } namespace tpc { -struct CorrectionMapsLoaderGloOpts; +struct CorrectionMapsGloOpts; namespace reco_workflow { @@ -73,16 +73,16 @@ enum struct OutputType { Digits, using CompletionPolicyData = std::vector; /// create the workflow for TPC reconstruction -framework::WorkflowSpec getWorkflow(CompletionPolicyData* policyData, // - std::vector const& tpcSectors, // - unsigned long tpcSectorMask, // - std::vector const& laneConfiguration, // - const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, // - bool propagateMC = true, unsigned nLanes = 1, // - std::string const& cfgInput = "digitizer", // - std::string const& cfgOutput = "tracks", // - bool disableRootInput = false, // - int caClusterer = 0, // +framework::WorkflowSpec getWorkflow(CompletionPolicyData* policyData, // + std::vector const& tpcSectors, // + unsigned long tpcSectorMask, // + std::vector const& laneConfiguration, // + const o2::tpc::CorrectionMapsGloOpts& sclOpts, // + bool propagateMC = true, unsigned nLanes = 1, // + std::string const& cfgInput = "digitizer", // + std::string const& cfgOutput = "tracks", // + bool disableRootInput = false, // + int caClusterer = 0, // int zsOnTheFly = 0, bool askDISTSTF = true, const std::string& ctfdictOpt = "none", diff --git a/Detectors/TPC/workflow/include/TPCWorkflow/TPCCalibPadGainTracksSpec.h b/Detectors/TPC/workflow/include/TPCWorkflow/TPCCalibPadGainTracksSpec.h index 516ea128acfe7..34f29f94dff4d 100644 --- a/Detectors/TPC/workflow/include/TPCWorkflow/TPCCalibPadGainTracksSpec.h +++ b/Detectors/TPC/workflow/include/TPCWorkflow/TPCCalibPadGainTracksSpec.h @@ -26,8 +26,7 @@ #include "TPCWorkflow/ProcessingHelpers.h" #include "Framework/CCDBParamSpec.h" #include "TPCBaseRecSim/CDBInterface.h" -#include "TPCCalibration/VDriftHelper.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCFastTransformPOD.h" #include "DetectorsBase/GRPGeomHelper.h" #include "GPUO2InterfaceUtils.h" #include "DataFormatsGlobalTracking/RecoContainer.h" @@ -45,22 +44,18 @@ namespace tpc class TPCCalibPadGainTracksDevice : public o2::framework::Task { public: - TPCCalibPadGainTracksDevice(std::shared_ptr dr, std::shared_ptr req, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, const uint32_t publishAfterTFs, const bool debug, const bool useLastExtractedMapAsReference, const std::string polynomialsFile, const bool disablePolynomialsCCDB) : mDataRequest(dr), mPublishAfter(publishAfterTFs), mDebug(debug), mUseLastExtractedMapAsReference(useLastExtractedMapAsReference), mDisablePolynomialsCCDB(disablePolynomialsCCDB), mCCDBRequest(req) + TPCCalibPadGainTracksDevice(std::shared_ptr dr, std::shared_ptr req, const uint32_t publishAfterTFs, const bool debug, const bool useLastExtractedMapAsReference, const std::string polynomialsFile, const bool disablePolynomialsCCDB) : mDataRequest(dr), mPublishAfter(publishAfterTFs), mDebug(debug), mUseLastExtractedMapAsReference(useLastExtractedMapAsReference), mDisablePolynomialsCCDB(disablePolynomialsCCDB), mCCDBRequest(req) { if (!polynomialsFile.empty()) { LOGP(info, "Loading polynomials from file {}", polynomialsFile); mPadGainTracks.loadPolTopologyCorrectionFromFile(polynomialsFile.data()); mDisablePolynomialsCCDB = true; } - mTPCCorrMapsLoader.setLumiScaleType(sclOpts.lumiType); - mTPCCorrMapsLoader.setLumiScaleMode(sclOpts.lumiMode); - mTPCCorrMapsLoader.setCheckCTPIDCConsistency(sclOpts.checkCTPIDCconsistency); } void init(o2::framework::InitContext& ic) final { o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest); - mTPCCorrMapsLoader.init(ic); // setting up the histogram ranges const auto nBins = ic.options().get("nBins"); auto reldEdxMin = ic.options().get("reldEdxMin"); @@ -151,8 +146,6 @@ class TPCCalibPadGainTracksDevice : public o2::framework::Task LOGP(info, "Updating Q topology correction from CCDB"); const auto* topologyCorr = static_cast(obj); mPadGainTracks.setPolTopologyCorrectionFromContainer(*topologyCorr); - } else if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) { - } else if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) { } else if (o2::base::GRPGeomHelper::instance().finaliseCCDB(matcher, obj)) { const auto field = o2::gpu::GPUO2InterfaceUtils::getNominalGPUBz(*o2::base::GRPGeomHelper::instance().getGRPMagField()); LOGP(info, "Setting magnetic field to {} kG", field); @@ -188,27 +181,10 @@ class TPCCalibPadGainTracksDevice : public o2::framework::Task LOGP(info, "fetching residual gain map"); pc.inputs().get>*>("tpcresidualgainmap"); } - mTPCVDriftHelper.extractCCDBInputs(pc); - mTPCCorrMapsLoader.extractCCDBInputs(pc); - bool updateMaps = false; - if (mTPCCorrMapsLoader.isUpdated()) { - mTPCCorrMapsLoader.acknowledgeUpdate(); - updateMaps = true; - } - mPadGainTracks.setTPCCorrMaps(&mTPCCorrMapsLoader); - if (mTPCVDriftHelper.isUpdated()) { - LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}", - mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, - mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset, - mTPCVDriftHelper.getSourceName()); - mPadGainTracks.setTPCVDrift(mTPCVDriftHelper.getVDriftObject()); - mTPCVDriftHelper.acknowledgeUpdate(); - updateMaps = true; - } - if (updateMaps) { - mTPCCorrMapsLoader.updateVDrift(mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().getTimeOffset()); - } + auto const& raw = pc.inputs().get("corrMap"); + mTPCCorrMaps = &o2::gpu::TPCFastTransformPOD::get(raw); + mPadGainTracks.setTPCCorrMaps(mTPCCorrMaps); mPadGainTracks.setMembers(&tracks, &clRefs, clusters->clusterIndex, recoData.clusterShMapTPC, recoData.occupancyMapTPC); mPadGainTracks.processTracks(mMaxTracksPerTF); ++mProcessedTFs; @@ -224,21 +200,20 @@ class TPCCalibPadGainTracksDevice : public o2::framework::Task } private: - const uint32_t mPublishAfter{0}; ///< number of TFs after which to dump the calibration - const bool mDebug{false}; ///< create debug output - const bool mUseLastExtractedMapAsReference{false}; ///< using the last extracted gain map as the reference map which will be applied - bool mDisablePolynomialsCCDB{false}; ///< do not load the polynomials from the CCDB + const uint32_t mPublishAfter{0}; ///< number of TFs after which to dump the calibration + const bool mDebug{false}; ///< create debug output + const bool mUseLastExtractedMapAsReference{false}; ///< using the last extracted gain map as the reference map which will be applied + bool mDisablePolynomialsCCDB{false}; ///< do not load the polynomials from the CCDB std::shared_ptr mDataRequest; ///< reco container data request - std::shared_ptr mCCDBRequest; ///< for accessing the b-field - uint32_t mProcessedTFs{0}; ///< counter to keep track of the processed TFs - uint32_t mTFCounter{0}; ///< counter to keep track of the TFs - CalibPadGainTracks mPadGainTracks{false}; ///< class for creating the pad-by-pad gain map - bool mUsingDefaultGainMapForFirstIter{true}; ///< using no reference gain map for the first iteration - unsigned int mUseEveryNthTF{1}; ///< process every Nth TF only - unsigned int mFirstTFSend{1}; ///< first TF for which the data will be send (initialized randomly) - int mMaxTracksPerTF{-1}; ///< max number of tracks processed per TF - o2::tpc::VDriftHelper mTPCVDriftHelper{}; - o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{}; + std::shared_ptr mCCDBRequest; ///< for accessing the b-field + uint32_t mProcessedTFs{0}; ///< counter to keep track of the processed TFs + uint32_t mTFCounter{0}; ///< counter to keep track of the TFs + CalibPadGainTracks mPadGainTracks{false}; ///< class for creating the pad-by-pad gain map + bool mUsingDefaultGainMapForFirstIter{true}; ///< using no reference gain map for the first iteration + unsigned int mUseEveryNthTF{1}; ///< process every Nth TF only + unsigned int mFirstTFSend{1}; ///< first TF for which the data will be send (initialized randomly) + int mMaxTracksPerTF{-1}; ///< max number of tracks processed per TF + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps{nullptr}; void sendOutput(DataAllocator& output) { @@ -247,16 +222,16 @@ class TPCCalibPadGainTracksDevice : public o2::framework::Task } }; -DataProcessorSpec getTPCCalibPadGainTracksSpec(const uint32_t publishAfterTFs, const bool debug, const bool useLastExtractedMapAsReference, const std::string polynomialsFile, bool disablePolynomialsCCDB, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts) +DataProcessorSpec getTPCCalibPadGainTracksSpec(const uint32_t publishAfterTFs, const bool debug, const bool useLastExtractedMapAsReference, const std::string polynomialsFile, bool disablePolynomialsCCDB) { std::vector inputs; auto dataRequest = std::make_shared(); dataRequest->requestTracks(o2::dataformats::GlobalTrackID::getSourceMask(o2::dataformats::GlobalTrackID::TPC), false); dataRequest->requestClusters(o2::dataformats::GlobalTrackID::getSourceMask(o2::dataformats::GlobalTrackID::TPC), false); - if (sclOpts.lumiType == 1) { - dataRequest->inputs.emplace_back("CTPLumi", "CTP", "LUMI", 0, Lifetime::Timeframe); - } + // if (sclOpts.lumiType == 1) { + // dataRequest->inputs.emplace_back("CTPLumi", "CTP", "LUMI", 0, Lifetime::Timeframe); + // } if (!polynomialsFile.empty()) { disablePolynomialsCCDB = true; @@ -270,7 +245,6 @@ DataProcessorSpec getTPCCalibPadGainTracksSpec(const uint32_t publishAfterTFs, c dataRequest->inputs.emplace_back("tpcresidualgainmap", gDataOriginTPC, "RESIDUALGAINMAP", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalPadGainResidual))); } - o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs); Options opts{ {"nBins", VariantType::Int, 20, {"Number of bins per histogram"}}, {"reldEdxMin", VariantType::Int, 0, {"Minimum x coordinate of the histogram for Q/(dE/dx)"}}, @@ -293,7 +267,7 @@ DataProcessorSpec getTPCCalibPadGainTracksSpec(const uint32_t publishAfterTFs, c {"useEveryNthTF", VariantType::Int, 10, {"Using only a fraction of the data: 1: Use every TF, 10: Use only every tenth TF."}}, {"maxTracksPerTF", VariantType::Int, 10000, {"Maximum number of processed tracks per TF (-1 for processing all tracks)"}}, }; - o2::tpc::CorrectionMapsLoader::requestCCDBInputs(dataRequest->inputs, opts, sclOpts); + dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe); auto ccdbRequest = std::make_shared(false, // orbitResetTime false, // GRPECS=true @@ -310,7 +284,7 @@ DataProcessorSpec getTPCCalibPadGainTracksSpec(const uint32_t publishAfterTFs, c "calib-tpc-gainmap-tracks", dataRequest->inputs, outputs, - AlgorithmSpec{adaptFromTask(dataRequest, ccdbRequest, sclOpts, publishAfterTFs, debug, useLastExtractedMapAsReference, polynomialsFile, disablePolynomialsCCDB)}, + AlgorithmSpec{adaptFromTask(dataRequest, ccdbRequest, publishAfterTFs, debug, useLastExtractedMapAsReference, polynomialsFile, disablePolynomialsCCDB)}, opts}; // end DataProcessorSpec } diff --git a/Detectors/TPC/workflow/include/TPCWorkflow/TPCRefitter.h b/Detectors/TPC/workflow/include/TPCWorkflow/TPCRefitter.h index 31a5ce756142a..7add8aecbb85a 100644 --- a/Detectors/TPC/workflow/include/TPCWorkflow/TPCRefitter.h +++ b/Detectors/TPC/workflow/include/TPCWorkflow/TPCRefitter.h @@ -15,15 +15,10 @@ #include "ReconstructionDataFormats/GlobalTrackID.h" #include "Framework/DataProcessorSpec.h" -namespace o2::tpc -{ -struct CorrectionMapsLoaderGloOpts; -} - namespace o2::trackstudy { /// create a processor spec -o2::framework::DataProcessorSpec getTPCRefitterSpec(o2::dataformats::GlobalTrackID::mask_t srcTracks, o2::dataformats::GlobalTrackID::mask_t srcClus, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, bool requestCosmics = false); +o2::framework::DataProcessorSpec getTPCRefitterSpec(o2::dataformats::GlobalTrackID::mask_t srcTracks, o2::dataformats::GlobalTrackID::mask_t srcClus, bool useMC, bool requestCosmics = false); } // namespace o2::trackstudy diff --git a/Detectors/TPC/workflow/include/TPCWorkflow/TPCScalerSpec.h b/Detectors/TPC/workflow/include/TPCWorkflow/TPCScalerSpec.h index b85a882870ecb..1208ae4cd2144 100644 --- a/Detectors/TPC/workflow/include/TPCWorkflow/TPCScalerSpec.h +++ b/Detectors/TPC/workflow/include/TPCWorkflow/TPCScalerSpec.h @@ -13,13 +13,14 @@ #define O2_TPC_TPCSCALER_SPEC #include "Framework/DataProcessorSpec.h" +#include "TPCCalibration/CorrectionMapsLoader.h" namespace o2 { namespace tpc { -o2::framework::DataProcessorSpec getTPCScalerSpec(bool enableIDCs, bool enableMShape); +o2::framework::DataProcessorSpec getTPCScalerSpec(bool enableIDCs, bool enableMShape, const o2::tpc::CorrectionMapsGloOpts& sclOpts); } // end namespace tpc } // end namespace o2 diff --git a/Detectors/TPC/workflow/src/EntropyEncoderSpec.cxx b/Detectors/TPC/workflow/src/EntropyEncoderSpec.cxx index 73bdfa1905f3b..4de5665f1b9a0 100644 --- a/Detectors/TPC/workflow/src/EntropyEncoderSpec.cxx +++ b/Detectors/TPC/workflow/src/EntropyEncoderSpec.cxx @@ -158,7 +158,7 @@ void EntropyEncoderSpec::run(ProcessingContext& pc) const auto& tinfo = pc.services().get(); const auto firstIR = o2::InteractionRecord(0, tinfo.firstTForbit); - const float totalT = std::max(mFastTransform->getMaxDriftTime(0), mFastTransform->getMaxDriftTime(GPUCA_NSECTORS / 2)); + const float totalT = std::max(mFastTransform->getMaxDriftTime(0), mFastTransform->getMaxDriftTime(GPUTPCGeometry::NSECTORS / 2)); unsigned int offset = 0, lasti = 0; const unsigned int maxTime = (mParam->continuousMaxTimeBin + 1) * o2::tpc::ClusterNative::scaleTimePacked - 1; @@ -205,23 +205,23 @@ void EntropyEncoderSpec::run(ProcessingContext& pc) } } offset = 0; - unsigned int offsets[GPUCA_NSECTORS][GPUCA_ROW_COUNT]; - for (unsigned int i = 0; i < GPUCA_NSECTORS; i++) { - for (unsigned int j = 0; j < GPUCA_ROW_COUNT; j++) { - if (i * GPUCA_ROW_COUNT + j >= clusters.nSliceRows) { + unsigned int offsets[GPUTPCGeometry::NSECTORS][GPUTPCGeometry::NROWS]; + for (unsigned int i = 0; i < GPUTPCGeometry::NSECTORS; i++) { + for (unsigned int j = 0; j < GPUTPCGeometry::NROWS; j++) { + if (i * GPUTPCGeometry::NROWS + j >= clusters.nSliceRows) { break; } offsets[i][j] = offset; - offset += (i * GPUCA_ROW_COUNT + j >= clusters.nSliceRows) ? 0 : clusters.nSliceRowClusters[i * GPUCA_ROW_COUNT + j]; + offset += (i * GPUTPCGeometry::NROWS + j >= clusters.nSliceRows) ? 0 : clusters.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]; } } #ifdef WITH_OPENMP -#pragma omp parallel for num_threads(mNThreads) schedule(static, (GPUCA_NSECTORS + mNThreads - 1) / mNThreads) // Static round-robin scheduling with one chunk per thread to ensure correct order of the final vector +#pragma omp parallel for num_threads(mNThreads) schedule(static, (GPUTPCGeometry::NSECTORS + mNThreads - 1) / mNThreads) // Static round-robin scheduling with one chunk per thread to ensure correct order of the final vector #endif for (unsigned int ii = 0; ii < clusters.nSliceRows; ii++) { - unsigned int i = ii / GPUCA_ROW_COUNT; - unsigned int j = ii % GPUCA_ROW_COUNT; + unsigned int i = ii / GPUTPCGeometry::NROWS; + unsigned int j = ii % GPUTPCGeometry::NROWS; o2::tpc::ClusterNative preCl; #ifdef WITH_OPENMP int myThread = omp_get_thread_num(); @@ -240,7 +240,7 @@ void EntropyEncoderSpec::run(ProcessingContext& pc) const bool reject = mCTFCoder.getIRFramesSelector().check(o2::dataformats::IRFrame(chkVal, chkVal + 1), chkExt, 0) < 0; if (reject) { rejectHits[k] = true; - clustersFiltered.nSliceRowClusters[i * GPUCA_ROW_COUNT + j]--; + clustersFiltered.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]--; static std::atomic_flag lock = ATOMIC_FLAG_INIT; while (lock.test_and_set(std::memory_order_acquire)) { } @@ -253,7 +253,7 @@ void EntropyEncoderSpec::run(ProcessingContext& pc) preCl = cl; } }; - unsigned int end = offsets[i][j] + clusters.nSliceRowClusters[i * GPUCA_ROW_COUNT + j]; + unsigned int end = offsets[i][j] + clusters.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]; o2::gpu::TPCClusterDecompressionCore::decompressHits(clusters, offsets[i][j], end, checker); } tmpBuffer[0].first.reserve(clustersFiltered.nUnattachedClusters); diff --git a/Detectors/TPC/workflow/src/RecoWorkflow.cxx b/Detectors/TPC/workflow/src/RecoWorkflow.cxx index 3054dd5d61519..355bd0cb290f7 100644 --- a/Detectors/TPC/workflow/src/RecoWorkflow.cxx +++ b/Detectors/TPC/workflow/src/RecoWorkflow.cxx @@ -100,7 +100,7 @@ const std::unordered_map OutputMap{ {"tpc-triggers", OutputType::TPCTriggers}}; framework::WorkflowSpec getWorkflow(CompletionPolicyData* policyData, std::vector const& tpcSectors, unsigned long tpcSectorMask, std::vector const& laneConfiguration, - const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, bool propagateMC, unsigned nLanes, std::string const& cfgInput, std::string const& cfgOutput, bool disableRootInput, + const o2::tpc::CorrectionMapsGloOpts& sclOpts, bool propagateMC, unsigned nLanes, std::string const& cfgInput, std::string const& cfgOutput, bool disableRootInput, int caClusterer, int zsOnTheFly, bool askDISTSTF, const std::string& ctfdictOpt, bool selIR, bool filteredInp, int deadMapSources, bool useMCTimeGain) { InputType inputType; @@ -201,9 +201,7 @@ framework::WorkflowSpec getWorkflow(CompletionPolicyData* policyData, std::vecto laneConfiguration, &hook}, propagateMC)); - if (sclOpts.needTPCScalersWorkflow()) { // for standalone tpc-reco workflow - specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpts.lumiType == 2, sclOpts.enableMShapeCorrection)); - } + specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpts.lumiType == o2::tpc::LumiScaleType::TPCScaler, sclOpts.enableMShapeCorrection, sclOpts)); if (produceTracks && sclOpts.requestCTPLumi) { // need CTP digits (lumi) reader specs.emplace_back(o2::ctp::getDigitsReaderSpec(false)); } @@ -225,9 +223,7 @@ framework::WorkflowSpec getWorkflow(CompletionPolicyData* policyData, std::vecto if (!getenv("DPL_DISABLE_TPC_TRIGGER_READER") || atoi(getenv("DPL_DISABLE_TPC_TRIGGER_READER")) != 1) { specs.emplace_back(o2::tpc::getTPCTriggerReaderSpec()); } - if (sclOpts.needTPCScalersWorkflow()) { // for standalone tpc-reco workflow - specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpts.lumiType == 2, sclOpts.enableMShapeCorrection)); - } + specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpts.lumiType == o2::tpc::LumiScaleType::TPCScaler, sclOpts.enableMShapeCorrection, sclOpts)); if (sclOpts.requestCTPLumi) { // need CTP digits (lumi) reader specs.emplace_back(o2::ctp::getDigitsReaderSpec(false)); } @@ -461,11 +457,6 @@ framework::WorkflowSpec getWorkflow(CompletionPolicyData* policyData, std::vecto if (runGPUReco) { o2::gpu::GPURecoWorkflowSpec::Config cfg; cfg.runTPCTracking = true; - cfg.lumiScaleType = sclOpts.lumiType; - cfg.lumiScaleMode = sclOpts.lumiMode; - cfg.checkCTPIDCconsistency = sclOpts.checkCTPIDCconsistency; - cfg.enableMShape = sclOpts.enableMShapeCorrection; - cfg.enableCTPLumi = sclOpts.requestCTPLumi; cfg.decompressTPC = decompressTPC; cfg.decompressTPCFromROOT = decompressTPC && inputType == InputType::CompClustersRoot; cfg.caClusterer = caClusterer; diff --git a/Detectors/TPC/workflow/src/TPCRefitter.cxx b/Detectors/TPC/workflow/src/TPCRefitter.cxx index 43a55526246fe..fbab4500fde5c 100644 --- a/Detectors/TPC/workflow/src/TPCRefitter.cxx +++ b/Detectors/TPC/workflow/src/TPCRefitter.cxx @@ -17,7 +17,7 @@ #include "DataFormatsGlobalTracking/RecoContainerCreateTracksVariadic.h" #include "SimulationDataFormat/MCCompLabel.h" #include "TPCCalibration/VDriftHelper.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCFastTransformPOD.h" #include "ReconstructionDataFormats/GlobalTrackID.h" #include "DetectorsBase/Propagator.h" #include "Framework/ConfigParamRegistry.h" @@ -63,13 +63,8 @@ class TPCRefitterSpec final : public Task Streamer = 0x1, ///< Write per track streamer information TFVectors = 0x2, ///< Writer vectors per TF }; - TPCRefitterSpec(std::shared_ptr dr, std::shared_ptr gr, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, GTrackID::mask_t src, bool useMC) - : mDataRequest(dr), mGGCCDBRequest(gr), mTracksSrc(src), mUseMC(useMC) - { - mTPCCorrMapsLoader.setLumiScaleType(sclOpts.lumiType); - mTPCCorrMapsLoader.setLumiScaleMode(sclOpts.lumiMode); - mTPCCorrMapsLoader.setCheckCTPIDCConsistency(sclOpts.checkCTPIDCconsistency); - } + TPCRefitterSpec(std::shared_ptr dr, std::shared_ptr gr, GTrackID::mask_t src, bool useMC) + : mDataRequest(dr), mGGCCDBRequest(gr), mTracksSrc(src), mUseMC(useMC) {} ~TPCRefitterSpec() final = default; void init(InitContext& ic) final; void run(ProcessingContext& pc) final; @@ -83,7 +78,7 @@ class TPCRefitterSpec final : public Task std::shared_ptr mDataRequest; std::shared_ptr mGGCCDBRequest; o2::tpc::VDriftHelper mTPCVDriftHelper{}; - o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{}; + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps{nullptr}; bool mUseMC{false}; ///< MC flag bool mUseGPUModel{false}; float mXRef = 83.; @@ -184,7 +179,6 @@ void TPCRefitterSpec::init(InitContext& ic) mXRef = 0.; } mGenerator = std::mt19937(std::random_device{}()); - mTPCCorrMapsLoader.init(ic); } void TPCRefitterSpec::run(ProcessingContext& pc) @@ -212,29 +206,8 @@ void TPCRefitterSpec::updateTimeDependentParams(ProcessingContext& pc) { o2::base::GRPGeomHelper::instance().checkUpdates(pc); mTPCVDriftHelper.extractCCDBInputs(pc); - mTPCCorrMapsLoader.extractCCDBInputs(pc); - static bool initOnceDone = false; - if (!initOnceDone) { // this params need to be queried only once - initOnceDone = true; - // none at the moment - } - // we may have other params which need to be queried regularly - bool updateMaps = false; - if (mTPCCorrMapsLoader.isUpdated()) { - mTPCCorrMapsLoader.acknowledgeUpdate(); - updateMaps = true; - } - if (mTPCVDriftHelper.isUpdated()) { - LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}", - mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, - mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset, - mTPCVDriftHelper.getSourceName()); - mTPCVDriftHelper.acknowledgeUpdate(); - updateMaps = true; - } - if (updateMaps) { - mTPCCorrMapsLoader.updateVDrift(mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().getTimeOffset()); - } + auto const& raw = pc.inputs().get("corrMap"); + mTPCCorrMaps = &o2::gpu::TPCFastTransformPOD::get(raw); } void TPCRefitterSpec::fillOccupancyVectors(o2::globaltracking::RecoContainer& recoData) @@ -335,14 +308,14 @@ void TPCRefitterSpec::process(o2::globaltracking::RecoContainer& recoData) mTPCTrkLabels = recoData.getTPCTracksMCLabels(); } - mTPCRefitter = std::make_unique(mTPCClusterIdxStruct, &mTPCCorrMapsLoader, prop->getNominalBz(), mTPCTrackClusIdx.data(), 0, mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), mTPCRefitterOccMap.size(), nullptr, prop); + mTPCRefitter = std::make_unique(mTPCClusterIdxStruct, mTPCCorrMaps, prop->getNominalBz(), mTPCTrackClusIdx.data(), 0, mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), mTPCRefitterOccMap.size(), nullptr, prop); mVdriftTB = mTPCVDriftHelper.getVDriftObject().getVDrift() * o2::tpc::ParameterElectronics::Instance().ZbinWidth; // VDrift expressed in cm/TimeBin mTPCTBBias = mTPCVDriftHelper.getVDriftObject().getTimeOffset() / (8 * o2::constants::lhc::LHCBunchSpacingMUS); auto dumpClusters = [this] { static int tf = 0; - const auto* corrMap = this->mTPCCorrMapsLoader.getCorrMap(); + const auto* corrMap = this->mTPCCorrMaps; for (int sector = 0; sector < 36; sector++) { float alp = ((sector % 18) * 20 + 10) * TMath::DegToRad(); float sn = TMath::Sin(alp), cs = TMath::Cos(alp); @@ -413,9 +386,6 @@ void TPCRefitterSpec::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) { return; } - if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) { - return; - } } bool TPCRefitterSpec::getDCAs(const o2::track::TrackPar& track, float& dcar, float& dcaz) @@ -500,7 +470,7 @@ bool TPCRefitterSpec::processTPCTrack(o2::tpc::TrackTPC tr, o2::MCCompLabel lbl, // auto prepClus = [this, &tr, &clSector, &clRow, &clX, &clY, &clZ, &clXI, &clYI, &clZI, &clNative](float t) { // extract cluster info auto prepClus = [this, &tr, &clData](float t) { // extract cluster info int count = tr.getNClusters(); - const auto* corrMap = this->mTPCCorrMapsLoader.getCorrMap(); + const auto* corrMap = this->mTPCCorrMaps; const o2::tpc::ClusterNative* cl = nullptr; for (int ic = count; ic--;) { uint8_t sector, row; @@ -525,7 +495,7 @@ bool TPCRefitterSpec::processTPCTrack(o2::tpc::TrackTPC tr, o2::MCCompLabel lbl, clData.clZI.emplace_back(z); // transformation without distortions - mTPCCorrMapsLoader.Transform(sector, row, cl->getPad(), cl->getTime(), x, y, z, t); // nominal time of the track + mTPCCorrMaps->Transform(sector, row, cl->getPad(), cl->getTime(), x, y, z, t); // nominal time of the track clData.clX.emplace_back(x); clData.clY.emplace_back(y); clData.clZ.emplace_back(z); @@ -740,7 +710,7 @@ void TPCRefitterSpec::processCosmics(o2::globaltracking::RecoContainer& recoData } } -DataProcessorSpec getTPCRefitterSpec(GTrackID::mask_t srcTracks, GTrackID::mask_t srcClusters, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, bool requestCosmics) +DataProcessorSpec getTPCRefitterSpec(GTrackID::mask_t srcTracks, GTrackID::mask_t srcClusters, bool useMC, bool requestCosmics) { std::vector outputs; Options opts{ @@ -778,13 +748,12 @@ DataProcessorSpec getTPCRefitterSpec(GTrackID::mask_t srcTracks, GTrackID::mask_ dataRequest->inputs, true); o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs); - o2::tpc::CorrectionMapsLoader::requestCCDBInputs(dataRequest->inputs, opts, sclOpts); - + dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe); return DataProcessorSpec{ "tpc-refitter", dataRequest->inputs, outputs, - AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, sclOpts, srcTracks, useMC)}, + AlgorithmSpec{adaptFromTask(dataRequest, ggRequest, srcTracks, useMC)}, opts}; } diff --git a/Detectors/TPC/workflow/src/TPCScalerSpec.cxx b/Detectors/TPC/workflow/src/TPCScalerSpec.cxx index f185b5e08c7e7..8e2a78d69757b 100644 --- a/Detectors/TPC/workflow/src/TPCScalerSpec.cxx +++ b/Detectors/TPC/workflow/src/TPCScalerSpec.cxx @@ -27,6 +27,8 @@ #include "TPCCalibration/TPCFastSpaceChargeCorrectionHelper.h" #include "TPCSpaceCharge/SpaceCharge.h" #include "CommonUtils/TreeStreamRedirector.h" +#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCCalibration/VDriftHelper.h" using namespace o2::framework; @@ -38,7 +40,12 @@ namespace tpc class TPCScalerSpec : public Task { public: - TPCScalerSpec(std::shared_ptr req, bool enableIDCs, bool enableMShape) : mCCDBRequest(req), mEnableIDCs(enableIDCs), mEnableMShape(enableMShape){}; + TPCScalerSpec(std::shared_ptr req, const o2::tpc::CorrectionMapsGloOpts& sclOpts, bool enableIDCs, bool enableMShape) : mCCDBRequest(req), mEnableIDCs(enableIDCs), mEnableMShape(enableMShape), mGlobOpts(sclOpts) + { + mTPCCorrMapsLoader.setLumiScaleType(sclOpts.lumiType); + mTPCCorrMapsLoader.setLumiScaleMode(sclOpts.lumiMode); + mTPCCorrMapsLoader.setCheckCTPIDCConsistency(sclOpts.checkCTPIDCconsistency); + }; void init(framework::InitContext& ic) final { @@ -57,6 +64,7 @@ class TPCScalerSpec : public Task if (enableStreamer) { mStreamer = std::make_unique("M_Shape.root", "recreate"); } + mTPCCorrMapsLoader.init(ic, mEnableIDCs); } void endOfStream(EndOfStreamContext& eos) final @@ -69,6 +77,11 @@ class TPCScalerSpec : public Task void run(ProcessingContext& pc) final { o2::base::GRPGeomHelper::instance().checkUpdates(pc); + mTPCVDriftHelper.extractCCDBInputs(pc); + if (mTPCVDriftHelper.isUpdated()) { + mTPCVDriftHelper.acknowledgeUpdate(); + } + if (mEnableIDCs && pc.inputs().isValid("tpcscaler")) { pc.inputs().get("tpcscaler"); } @@ -122,12 +135,7 @@ class TPCScalerSpec : public Task std::unique_ptr spCorrection = TPCFastSpaceChargeCorrectionHelper::instance()->createFromGlobalCorrection(getCorrections, mKnotsYMshape, mKnotsZMshape); std::unique_ptr fastTransform(TPCFastTransformHelperO2::instance()->create(0, *spCorrection)); - pc.outputs().snapshot(Output{header::gDataOriginTPC, "TPCMSHAPE"}, *fastTransform); - } else { - // send empty dummy object - LOGP(info, "Sending default (no) M-shape correction"); - auto fastTransform = o2::tpc::TPCFastTransformHelperO2::instance()->create(0); - pc.outputs().snapshot(Output{header::gDataOriginTPC, "TPCMSHAPE"}, *fastTransform); + mTPCCorrMapsLoader.setCorrMapMShape(std::move(fastTransform)); } if (mStreamer) { @@ -140,6 +148,7 @@ class TPCScalerSpec : public Task } } + float tpcScaler = -1.f; if (mEnableIDCs) { static int runWarningIDC = -1; if (pc.services().get().runNumber != mTPCScaler.getRun() && runWarningIDC != currRun) { @@ -149,8 +158,7 @@ class TPCScalerSpec : public Task float scalerA = mTPCScaler.getMeanScaler(timestamp, o2::tpc::Side::A); float scalerC = mTPCScaler.getMeanScaler(timestamp, o2::tpc::Side::C); float meanScaler = (scalerA + scalerC) / 2; - LOGP(info, "Publishing TPC scaler: {} for timestamp: {}, firstTFOrbit: {}", meanScaler, timestamp, firstTFOrbit); - pc.outputs().snapshot(Output{header::gDataOriginTPC, "TPCSCALER"}, meanScaler); + tpcScaler = meanScaler; if (mStreamer) { (*mStreamer) << "treeIDC" << "scalerA=" << scalerA @@ -160,11 +168,70 @@ class TPCScalerSpec : public Task << "\n"; } } + // check for Maps update + mTPCCorrMapsLoader.extractCCDBInputs(pc, tpcScaler); + + if (mGlobOpts.requestCTPLumi) { + const float lumiCTP = mTPCCorrMapsLoader.getInstLumiCTP(); + // if CTP lumi was notrequest - defualt of 0 is published, otherwise the value is scaled with the provided factor + LOGP(info, "Publishing CTP Lumi: {} for timestamp: {}, firstTFOrbit: {}", lumiCTP, timestamp, firstTFOrbit); + pc.outputs().snapshot(Output{header::gDataOriginCTP, "LUMICTP"}, lumiCTP); + } + + buildMap(pc); + } + + void buildMap(ProcessingContext& pc) + { + // reference map + auto* corrMap = mTPCCorrMapsLoader.getCorrMap(); + + // // new correction map + o2::gpu::TPCFastTransform finalMap; + finalMap.cloneFromObject(*corrMap, nullptr); + finalMap.setApplyCorrectionOn(); + + const auto* corrMapRef = mTPCCorrMapsLoader.getCorrMapRef(); + const float lumiScale = mTPCCorrMapsLoader.getLumiScale(); + std::vector> additionalCorrections; + + // if standard scaling is used: map(lumi) = (mean_map - ref_map) * lumiScale + ref_map + if (mTPCCorrMapsLoader.getLumiScaleMode() == LumiScaleMode::Linear) { + const std::vector> step0{{&(corrMapRef->getCorrection()), -1.f}}; + // finalMap = (mean_map - finalMap) + TPCFastSpaceChargeCorrectionHelper::instance()->mergeCorrections(finalMap.getCorrection(), 1, step0, true); + + // finalMap = finalMap * lumiScale + ref_map + const std::vector> step1{{&(corrMapRef->getCorrection()), 1.f}}; + TPCFastSpaceChargeCorrectionHelper::instance()->mergeCorrections(finalMap.getCorrection(), lumiScale, step1, true); + + } else if (mTPCCorrMapsLoader.getLumiScaleMode() == LumiScaleMode::DerivativeMap || mTPCCorrMapsLoader.getLumiScaleMode() == LumiScaleMode::DerivativeMapMC) { + additionalCorrections.emplace_back(&(corrMapRef->getCorrection()), lumiScale); + } + + // if mshape map valid + if (!mTPCCorrMapsLoader.isCorrMapMShapeDummy()) { + LOGP(info, "Adding M-shape correction to the final map with scaling factor {}", mMShapeScalingFac); + additionalCorrections.emplace_back(&(mTPCCorrMapsLoader.getCorrMapMShape()->getCorrection()), 1.f); + } + + if (!additionalCorrections.empty()) { + TPCFastSpaceChargeCorrectionHelper::instance()->mergeCorrections(finalMap.getCorrection(), 1, additionalCorrections, true); + } + + Output corrMapOutput{header::gDataOriginTPC, "TPCCORRMAP", 0}; + auto outputBuffer = o2::pmr::vector(pc.outputs().getMemoryResource(corrMapOutput)); + outputBuffer.resize(TPCFastTransformPOD::estimateSize(finalMap.getCorrection())); + auto* pod = TPCFastTransformPOD::create(outputBuffer.data(), outputBuffer.size(), finalMap); + const auto& vd = mTPCVDriftHelper.getVDriftObject(); + o2::tpc::TPCFastTransformHelperO2::instance()->updateCalibration(*pod, 0, vd.corrFact, vd.refVDrift, vd.getTimeOffset()); + pc.outputs().adoptContainer(corrMapOutput, std::move(outputBuffer)); } void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final { o2::base::GRPGeomHelper::instance().finaliseCCDB(matcher, obj); + mTPCVDriftHelper.accountCCDBInputs(matcher, obj); if (matcher == ConcreteDataMatcher(o2::header::gDataOriginTPC, "TPCSCALERCCDB", 0)) { LOGP(info, "Updating TPC scaler"); mTPCScaler.setFromTree(*((TTree*)obj)); @@ -198,12 +265,16 @@ class TPCScalerSpec : public Task LOGP(info, "Loaded default M-Shape correction object from CCDB"); } } + if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) { + return; + } } private: std::shared_ptr mCCDBRequest; ///< info for CCDB request const bool mEnableIDCs{true}; ///< enable IDCs const bool mEnableMShape{false}; ///< enable v shape scalers + const o2::tpc::CorrectionMapsGloOpts mGlobOpts; ///< global options for the correction map loader, needed to decide which maps to load from CCDB bool mEnableWeights{false}; ///< use weights for TPC scalers TPCScalerWeights mScalerWeights{}; ///< scaler weights float mIonDriftTimeMS{-1}; ///< ion drift time @@ -214,6 +285,8 @@ class TPCScalerSpec : public Task int mKnotsYMshape{4}; ///< number of knots used for the spline object for M-Shape distortions int mKnotsZMshape{4}; ///< number of knots used for the spline object for M-Shape distortions std::unique_ptr mStreamer; ///< streamer + o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{}; + o2::tpc::VDriftHelper mTPCVDriftHelper{}; ///< helper for v-drift void overWriteIntegrationTime() { @@ -229,7 +302,7 @@ class TPCScalerSpec : public Task } }; -o2::framework::DataProcessorSpec getTPCScalerSpec(bool enableIDCs, bool enableMShape) +o2::framework::DataProcessorSpec getTPCScalerSpec(bool enableIDCs, bool enableMShape, const o2::tpc::CorrectionMapsGloOpts& sclOpts) { std::vector inputs; if (enableIDCs) { @@ -251,18 +324,18 @@ o2::framework::DataProcessorSpec getTPCScalerSpec(bool enableIDCs, bool enableMS inputs); std::vector outputs; - if (enableIDCs) { - outputs.emplace_back(o2::header::gDataOriginTPC, "TPCSCALER", 0, Lifetime::Timeframe); - } - if (enableMShape) { - outputs.emplace_back(o2::header::gDataOriginTPC, "TPCMSHAPE", 0, Lifetime::Timeframe); + outputs.emplace_back(o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe); + if (sclOpts.requestCTPLumi) { + outputs.emplace_back(o2::header::gDataOriginCTP, "LUMICTP", 0, Lifetime::Timeframe); } + o2::tpc::VDriftHelper::requestCCDBInputs(inputs); + o2::tpc::CorrectionMapsLoader::requestCCDBInputs(inputs, sclOpts); return DataProcessorSpec{ "tpc-scaler", inputs, outputs, - AlgorithmSpec{adaptFromTask(ccdbRequest, enableIDCs, enableMShape)}, + AlgorithmSpec{adaptFromTask(ccdbRequest, sclOpts, enableIDCs, enableMShape)}, Options{ {"ion-drift-time", VariantType::Float, -1.f, {"Overwrite ion drift time if a value >0 is provided"}}, {"max-time-for-weights", VariantType::Float, 500.f, {"Maximum possible integration time in ms when weights are used"}}, diff --git a/Detectors/TPC/workflow/src/tpc-calib-gainmap-tracks.cxx b/Detectors/TPC/workflow/src/tpc-calib-gainmap-tracks.cxx index 5475995437113..138968cd6b517 100644 --- a/Detectors/TPC/workflow/src/tpc-calib-gainmap-tracks.cxx +++ b/Detectors/TPC/workflow/src/tpc-calib-gainmap-tracks.cxx @@ -20,7 +20,7 @@ #include "CommonUtils/ConfigurableParam.h" #include "TPCWorkflow/TPCCalibPadGainTracksSpec.h" #include "TPCReaderWorkflow/TPCSectorCompletionPolicy.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCCalibration/CorrectionMapsOptions.h" #include "TPCWorkflow/TPCScalerSpec.h" using namespace o2::framework; @@ -44,7 +44,7 @@ void customize(std::vector& workflowOptions) {"polynomialsFile", VariantType::String, "", {"file containing the polynomials for the track topology correction"}}, {"disablePolynomialsCCDB", VariantType::Bool, false, {"Do not load the polynomials from the CCDB"}}, {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings"}}}; - o2::tpc::CorrectionMapsLoader::addGlobalOptions(options); + o2::tpc::CorrectionMapsOptions::addGlobalOptions(options); std::swap(workflowOptions, options); } @@ -63,11 +63,9 @@ WorkflowSpec defineDataProcessing(ConfigContext const& config) const bool useLastExtractedMapAsReference = config.options().get("useLastExtractedMapAsReference"); const std::string polynomialsFile = config.options().get("polynomialsFile"); const auto disablePolynomialsCCDB = config.options().get("disablePolynomialsCCDB"); - const auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(config.options()); + const auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(config.options()); WorkflowSpec workflow; - if (sclOpt.needTPCScalersWorkflow()) { - workflow.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection)); - } - workflow.emplace_back(o2::tpc::getTPCCalibPadGainTracksSpec(publishAfterTFs, debug, useLastExtractedMapAsReference, polynomialsFile, disablePolynomialsCCDB, sclOpt)); + workflow.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == o2::tpc::LumiScaleType::TPCScaler, sclOpt.enableMShapeCorrection, sclOpt)); + workflow.emplace_back(o2::tpc::getTPCCalibPadGainTracksSpec(publishAfterTFs, debug, useLastExtractedMapAsReference, polynomialsFile, disablePolynomialsCCDB)); return workflow; } diff --git a/Detectors/TPC/workflow/src/tpc-reco-workflow.cxx b/Detectors/TPC/workflow/src/tpc-reco-workflow.cxx index f3d4d639ddfd2..318c8372e7ad5 100644 --- a/Detectors/TPC/workflow/src/tpc-reco-workflow.cxx +++ b/Detectors/TPC/workflow/src/tpc-reco-workflow.cxx @@ -23,6 +23,7 @@ #include "Framework/ConcreteDataMatcher.h" #include "TPCWorkflow/RecoWorkflow.h" #include "TPCReaderWorkflow/TPCSectorCompletionPolicy.h" +#include "TPCCalibration/CorrectionMapsOptions.h" #include "TPCCalibration/CorrectionMapsLoader.h" #include "Framework/CustomWorkflowTerminationHook.h" #include "DataFormatsTPC/TPCSectorHeader.h" @@ -75,8 +76,8 @@ void customize(std::vector& workflowOptions) {"tpc-deadMap-sources", VariantType::Int, -1, {"Sources to consider for TPC dead channel map creation; -1=all, 0=deactivated"}}, {"tpc-mc-time-gain", VariantType::Bool, false, {"use time gain calibration for MC (true) or for data (false)"}}, }; - o2::tpc::CorrectionMapsLoader::addGlobalOptions(options); o2::raw::HBFUtilsInitializer::addConfigOption(options); + o2::tpc::CorrectionMapsOptions::addGlobalOptions(options); std::swap(workflowOptions, options); } @@ -169,7 +170,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) gTpcSectorMask |= (1ul << s); } bool doMC = not cfgc.options().get("disable-mc"); - auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(cfgc.options()); + auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(cfgc.options()); auto wf = o2::tpc::reco_workflow::getWorkflow(&gPolicyData, // tpcSectors, // sector configuration gTpcSectorMask, // same as bitmask diff --git a/Detectors/TPC/workflow/src/tpc-refitter-workflow.cxx b/Detectors/TPC/workflow/src/tpc-refitter-workflow.cxx index 78bf63a44d60f..61c589512d1ce 100644 --- a/Detectors/TPC/workflow/src/tpc-refitter-workflow.cxx +++ b/Detectors/TPC/workflow/src/tpc-refitter-workflow.cxx @@ -18,10 +18,10 @@ #include "Framework/ConfigParamSpec.h" #include "GlobalTrackingWorkflowHelpers/InputHelper.h" #include "ReconstructionDataFormats/GlobalTrackID.h" -#include "TPCCalibration/CorrectionMapsLoader.h" #include "TPCWorkflow/TPCRefitter.h" #include "TPCWorkflow/TPCScalerSpec.h" #include "DetectorsBase/DPLWorkflowUtils.h" +#include "TPCCalibration/CorrectionMapsOptions.h" using namespace o2::framework; using GID = o2::dataformats::GlobalTrackID; @@ -47,7 +47,7 @@ void customize(std::vector& workflowOptions) {"enable-M-shape-correction", VariantType::Bool, false, {"Enable M-shape distortion correction"}}, {"disable-IDC-scalers", VariantType::Bool, false, {"Disable TPC scalers for space-charge distortion fluctuation correction"}}, {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}}}; - o2::tpc::CorrectionMapsLoader::addGlobalOptions(options); + o2::tpc::CorrectionMapsOptions::addGlobalOptions(options); o2::raw::HBFUtilsInitializer::addConfigOption(options); std::swap(workflowOptions, options); } @@ -63,7 +63,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) // Update the (declared) parameters if changed from the command line o2::conf::ConfigurableParam::updateFromString(configcontext.options().get("configKeyValues")); auto useMC = configcontext.options().get("use-mc"); - auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(configcontext.options()); + auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(configcontext.options()); const auto enableCosmics = configcontext.options().get("enable-cosmics"); GID::mask_t allowedSourcesTrc = GID::getSourcesMask("ITS,TPC,ITS-TPC,TPC-TOF"); @@ -79,18 +79,16 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) srcCls = srcCls | GID::getSourcesMask("CTP"); } - if (sclOpt.lumiType == 2) { - const auto enableMShape = configcontext.options().get("enable-M-shape-correction"); - const auto enableIDCs = !configcontext.options().get("disable-IDC-scalers"); - specs.emplace_back(o2::tpc::getTPCScalerSpec(enableIDCs, enableMShape)); - } + const auto enableMShape = configcontext.options().get("enable-M-shape-correction"); + const auto enableIDCs = !configcontext.options().get("disable-IDC-scalers"); + specs.emplace_back(o2::tpc::getTPCScalerSpec(enableIDCs, enableMShape, sclOpt)); o2::globaltracking::InputHelper::addInputSpecs(configcontext, specs, srcCls, srcTrc, srcTrc, useMC); o2::globaltracking::InputHelper::addInputSpecsPVertex(configcontext, specs, useMC); // P-vertex is always needed if (enableCosmics) { o2::globaltracking::InputHelper::addInputSpecsCosmics(configcontext, specs, useMC); } - specs.emplace_back(o2::trackstudy::getTPCRefitterSpec(srcTrc, srcCls, useMC, sclOpt, enableCosmics)); + specs.emplace_back(o2::trackstudy::getTPCRefitterSpec(srcTrc, srcCls, useMC, enableCosmics)); // configure dpl timer to inject correct firstTForbit: start from the 1st orbit of TF containing 1st sampled orbit o2::raw::HBFUtilsInitializer hbfIni(configcontext, specs); diff --git a/Detectors/TPC/workflow/src/tpc-scaler.cxx b/Detectors/TPC/workflow/src/tpc-scaler.cxx index 598687c7dff41..d3893c0eafe84 100644 --- a/Detectors/TPC/workflow/src/tpc-scaler.cxx +++ b/Detectors/TPC/workflow/src/tpc-scaler.cxx @@ -15,6 +15,7 @@ #include "TPCWorkflow/TPCScalerSpec.h" #include "CommonUtils/ConfigurableParam.h" #include "Framework/ConfigParamSpec.h" +#include "TPCCalibration/CorrectionMapsOptions.h" using namespace o2::framework; @@ -25,7 +26,7 @@ void customize(std::vector& workflowOptions) ConfigParamSpec{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings"}}, {"enable-M-shape-correction", VariantType::Bool, false, {"Enable M-shape distortion correction"}}, {"disable-IDC-scalers", VariantType::Bool, false, {"Disable TPC scalers for space-charge distortion fluctuation correction"}}}; - + o2::tpc::CorrectionMapsOptions::addGlobalOptions(options); std::swap(workflowOptions, options); } @@ -37,6 +38,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& config) o2::conf::ConfigurableParam::updateFromString(config.options().get("configKeyValues")); const auto enableMShape = config.options().get("enable-M-shape-correction"); const auto enableIDCs = !config.options().get("disable-IDC-scalers"); - workflow.emplace_back(o2::tpc::getTPCScalerSpec(enableIDCs, enableMShape)); + auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(config.options()); + workflow.emplace_back(o2::tpc::getTPCScalerSpec(enableIDCs, enableMShape, sclOpt)); return workflow; } diff --git a/Detectors/TRD/workflow/include/TRDWorkflow/TRDGlobalTrackingSpec.h b/Detectors/TRD/workflow/include/TRDWorkflow/TRDGlobalTrackingSpec.h index 93f07dd58445e..92c33d8c316b5 100644 --- a/Detectors/TRD/workflow/include/TRDWorkflow/TRDGlobalTrackingSpec.h +++ b/Detectors/TRD/workflow/include/TRDWorkflow/TRDGlobalTrackingSpec.h @@ -32,9 +32,8 @@ #include #include "DetectorsBase/GRPGeomHelper.h" #include "TPCCalibration/VDriftHelper.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCFastTransformPOD.h" #include "GPUO2InterfaceRefit.h" -#include "TPCFastTransform.h" #include "DataFormatsTPC/TrackTPC.h" #include "DataFormatsITS/TrackITS.h" #include "DataFormatsITSMFT/TrkClusRef.h" @@ -52,13 +51,8 @@ namespace trd class TRDGlobalTracking : public o2::framework::Task { public: - TRDGlobalTracking(bool useMC, bool withPID, PIDPolicy policy, std::shared_ptr dataRequest, std::shared_ptr gr, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, - o2::dataformats::GlobalTrackID::mask_t src, bool trigRecFilterActive, bool strict) : mUseMC(useMC), mWithPID(withPID), mDataRequest(dataRequest), mGGCCDBRequest(gr), mTrkMask(src), mTrigRecFilter(trigRecFilterActive), mStrict(strict), mPolicy(policy) - { - mTPCCorrMapsLoader.setLumiScaleType(sclOpts.lumiType); - mTPCCorrMapsLoader.setLumiScaleMode(sclOpts.lumiMode); - mTPCCorrMapsLoader.setCheckCTPIDCConsistency(sclOpts.checkCTPIDCconsistency); - } + TRDGlobalTracking(bool useMC, bool withPID, PIDPolicy policy, std::shared_ptr dataRequest, std::shared_ptr gr, + o2::dataformats::GlobalTrackID::mask_t src, bool trigRecFilterActive, bool strict, bool requestCTPLumi) : mUseMC(useMC), mWithPID(withPID), mDataRequest(dataRequest), mGGCCDBRequest(gr), mTrkMask(src), mTrigRecFilter(trigRecFilterActive), mStrict(strict), mPolicy(policy), mRequestCTPLumi(requestCTPLumi) {} ~TRDGlobalTracking() override = default; void init(o2::framework::InitContext& ic) final; void fillMCTruthInfo(const TrackTRD& trk, o2::MCCompLabel lblSeed, std::vector& lblContainerTrd, std::vector& lblContainerMatch, const o2::dataformats::MCTruthContainer* trkltLabels) const; @@ -86,7 +80,7 @@ class TRDGlobalTracking : public o2::framework::Task std::shared_ptr mDataRequest; ///< seeding input (TPC-only, ITS-TPC or both) std::shared_ptr mGGCCDBRequest; o2::tpc::VDriftHelper mTPCVDriftHelper{}; - o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{}; + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps{nullptr}; o2::dataformats::GlobalTrackID::mask_t mTrkMask; ///< seeding track sources (TPC, ITS-TPC) bool mTrigRecFilter{false}; ///< if true, TRD trigger records without matching ITS IR are filtered out bool mStrict{false}; ///< preliminary matching in strict mode @@ -111,11 +105,12 @@ class TRDGlobalTracking : public o2::framework::Task std::array mCovDiagOuter{}; ///< total cov.matrix extra diagonal error from TrackTuneParams // PID PIDPolicy mPolicy{PIDPolicy::DEFAULT}; ///< Model to load an evaluate + bool mRequestCTPLumi{false}; ///< whether to request CTP lumi std::unique_ptr mBase; ///< PID engine }; /// create a processor spec -framework::DataProcessorSpec getTRDGlobalTrackingSpec(bool useMC, o2::dataformats::GlobalTrackID::mask_t src, bool trigRecFilterActive, bool strict /* = false*/, bool withPID /* = false*/, PIDPolicy policy /* = PIDPolicy::DEFAULT*/, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts); +framework::DataProcessorSpec getTRDGlobalTrackingSpec(bool useMC, o2::dataformats::GlobalTrackID::mask_t src, bool trigRecFilterActive, bool strict /* = false*/, bool withPID /* = false*/, PIDPolicy policy /* = PIDPolicy::DEFAULT*/, bool requestCTPLumi); } // namespace trd } // namespace o2 diff --git a/Detectors/TRD/workflow/src/TRDGlobalTrackingSpec.cxx b/Detectors/TRD/workflow/src/TRDGlobalTrackingSpec.cxx index 0f578efd3aa5b..40521c5fd5ee9 100644 --- a/Detectors/TRD/workflow/src/TRDGlobalTrackingSpec.cxx +++ b/Detectors/TRD/workflow/src/TRDGlobalTrackingSpec.cxx @@ -82,7 +82,6 @@ using TrackTunePar = o2::globaltracking::TrackTuneParams; void TRDGlobalTracking::init(InitContext& ic) { o2::base::GRPGeomHelper::instance().setRequest(mGGCCDBRequest); - mTPCCorrMapsLoader.init(ic); mTimer.Stop(); mTimer.Reset(); } @@ -91,7 +90,11 @@ void TRDGlobalTracking::updateTimeDependentParams(ProcessingContext& pc) { o2::base::GRPGeomHelper::instance().checkUpdates(pc); mTPCVDriftHelper.extractCCDBInputs(pc); - mTPCCorrMapsLoader.extractCCDBInputs(pc); + + auto const& raw = pc.inputs().get("corrMap"); + mTPCCorrMaps = &o2::gpu::TPCFastTransformPOD::get(raw); + float lumiCTP = mRequestCTPLumi ? pc.inputs().get("lumiCTP") : 0; + // pc.inputs().get("cldict"); // called by the RecoContainer to trigger finaliseCCDB static bool initOnceDone = false; if (!initOnceDone) { // this params need to be queried only once @@ -148,13 +151,9 @@ void TRDGlobalTracking::updateTimeDependentParams(ProcessingContext& pc) mBase->setLocalGainFactors(pc.inputs().get("localgainfactors").get()); } } - bool updateCalib = false; - if (mTPCCorrMapsLoader.isUpdated()) { - mTPCCorrMapsLoader.acknowledgeUpdate(); - updateCalib = true; - } + const auto& trackTune = TrackTuneParams::Instance(); - float scale = mTPCCorrMapsLoader.getInstLumiCTP(); + float scale = lumiCTP; if (scale < 0.f) { scale = 0.f; } @@ -173,11 +172,6 @@ void TRDGlobalTracking::updateTimeDependentParams(ProcessingContext& pc) mTracker->SetTPCVdrift(mTPCVdrift); mTracker->SetTPCTDriftOffset(mTPCTDriftOffset); mTPCVDriftHelper.acknowledgeUpdate(); - updateCalib = true; - } - if (updateCalib) { - auto& vd = mTPCVDriftHelper.getVDriftObject(); - mTPCCorrMapsLoader.updateVDrift(vd.corrFact, vd.refVDrift, vd.getTimeOffset()); } } @@ -189,9 +183,6 @@ void TRDGlobalTracking::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) { return; } - if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) { - return; - } if (matcher == ConcreteDataMatcher("ITS", "CLUSDICT", 0)) { LOG(info) << "cluster dictionary updated"; mITSDict = (const o2::itsmft::TopologyDictionary*)obj; @@ -293,7 +284,7 @@ void TRDGlobalTracking::run(ProcessingContext& pc) mChainTracking->ClearIOPointers(); mTPCClusterIdxStruct = &inputTracks.inputsTPCclusters->clusterIndex; - mTPCRefitter = std::make_unique(mTPCClusterIdxStruct, &mTPCCorrMapsLoader, o2::base::Propagator::Instance()->getNominalBz(), inputTracks.getTPCTracksClusterRefs().data(), 0, inputTracks.clusterShMapTPC.data(), inputTracks.occupancyMapTPC.data(), inputTracks.occupancyMapTPC.size(), nullptr, o2::base::Propagator::Instance()); + mTPCRefitter = std::make_unique(mTPCClusterIdxStruct, mTPCCorrMaps, o2::base::Propagator::Instance()->getNominalBz(), inputTracks.getTPCTracksClusterRefs().data(), 0, inputTracks.clusterShMapTPC.data(), inputTracks.occupancyMapTPC.data(), inputTracks.occupancyMapTPC.size(), nullptr, o2::base::Propagator::Instance()); auto tmpInputContainer = getRecoInputContainer(pc, &mChainTracking->mIOPtrs, &inputTracks, mUseMC); auto tmpContainer = GPUWorkflowHelper::fillIOPtr(mChainTracking->mIOPtrs, inputTracks, mUseMC, nullptr, GTrackID::getSourcesMask("TRD"), mTrkMask, GTrackID::mask_t{GTrackID::MASK_NONE}); mTrackletsRaw = inputTracks.getTRDTracklets(); @@ -862,7 +853,7 @@ void TRDGlobalTracking::endOfStream(EndOfStreamContext& ec) mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1); } -DataProcessorSpec getTRDGlobalTrackingSpec(bool useMC, GTrackID::mask_t src, bool trigRecFilterActive, bool strict, bool withPID, PIDPolicy policy, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts) +DataProcessorSpec getTRDGlobalTrackingSpec(bool useMC, GTrackID::mask_t src, bool trigRecFilterActive, bool strict, bool withPID, PIDPolicy policy, bool requestCTPLumi) { std::vector outputs; uint32_t ss = o2::globaltracking::getSubSpec(strict ? o2::globaltracking::MatchingType::Strict : o2::globaltracking::MatchingType::Standard); @@ -899,7 +890,12 @@ DataProcessorSpec getTRDGlobalTrackingSpec(bool useMC, GTrackID::mask_t src, boo true); o2::tpc::VDriftHelper::requestCCDBInputs(inputs); Options opts; - o2::tpc::CorrectionMapsLoader::requestCCDBInputs(inputs, opts, sclOpts); + + dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe); + + if (requestCTPLumi) { + dataRequest->inputs.emplace_back("lumiCTP", o2::header::gDataOriginCTP, "LUMICTP", 0, Lifetime::Timeframe); + } // Request PID policy data if (withPID) { @@ -962,7 +958,7 @@ DataProcessorSpec getTRDGlobalTrackingSpec(bool useMC, GTrackID::mask_t src, boo processorName, inputs, outputs, - AlgorithmSpec{adaptFromTask(useMC, withPID, policy, dataRequest, ggRequest, sclOpts, src, trigRecFilterActive, strict)}, + AlgorithmSpec{adaptFromTask(useMC, withPID, policy, dataRequest, ggRequest, src, trigRecFilterActive, strict, requestCTPLumi)}, opts}; } diff --git a/Detectors/TRD/workflow/src/trd-tracking-workflow.cxx b/Detectors/TRD/workflow/src/trd-tracking-workflow.cxx index 1d8243ff8cbc0..6b83f58dfb032 100644 --- a/Detectors/TRD/workflow/src/trd-tracking-workflow.cxx +++ b/Detectors/TRD/workflow/src/trd-tracking-workflow.cxx @@ -24,7 +24,7 @@ #include "TRDWorkflow/TRDGlobalTrackingQCSpec.h" #include "TRDWorkflow/TRDPulseHeightSpec.h" #include "GlobalTrackingWorkflowHelpers/InputHelper.h" -#include "TPCCalibration/CorrectionMapsLoader.h" +#include "TPCCalibration/CorrectionMapsOptions.h" #include "TPCWorkflow/TPCScalerSpec.h" using namespace o2::framework; @@ -62,7 +62,7 @@ void customize(std::vector& workflowOptions) {"disable-ft0-pileup-tagging", VariantType::Bool, false, {"Do not request FT0 for pile-up determination"}}, {"policy", VariantType::String, "default", {"Pick PID policy (=default)"}}, {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings"}}}; - o2::tpc::CorrectionMapsLoader::addGlobalOptions(options); + o2::tpc::CorrectionMapsOptions::addGlobalOptions(options); o2::raw::HBFUtilsInitializer::addConfigOption(options); std::swap(workflowOptions, options); } @@ -86,7 +86,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) auto gain = configcontext.options().get("enable-gain-calib"); auto pulseHeight = configcontext.options().get("enable-ph"); auto digitsSpec = configcontext.options().get("trd-digits-spec"); - auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(configcontext.options()); + auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(configcontext.options()); bool rootInput = !configcontext.options().get("disable-root-input"); GTrackID::mask_t srcTRD = allowedSources & GTrackID::getSourcesMask(configcontext.options().get("track-sources")); if (strict && (srcTRD & ~GTrackID::getSourcesMask("TPC")).any()) { @@ -113,10 +113,10 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) // processing devices o2::framework::WorkflowSpec specs; - if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get("disable-root-input")) { - specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection)); + if (!configcontext.options().get("disable-root-input")) { + specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == o2::tpc::LumiScaleType::TPCScaler, sclOpt.enableMShapeCorrection, sclOpt)); } - specs.emplace_back(o2::trd::getTRDGlobalTrackingSpec(useMC, srcTRD, trigRecFilterActive, strict, pid, policy, sclOpt)); + specs.emplace_back(o2::trd::getTRDGlobalTrackingSpec(useMC, srcTRD, trigRecFilterActive, strict, pid, policy, sclOpt.requestCTPLumi)); if (vdexb || gain) { specs.emplace_back(o2::trd::getTRDTrackBasedCalibSpec(srcTRD, vdexb, gain)); } diff --git a/Detectors/Upgrades/ITS3/macros/test/buildMatBudLUT.C b/Detectors/Upgrades/ITS3/macros/test/buildMatBudLUT.C index fa4f7e3910b99..4af1aa64a8ab2 100644 --- a/Detectors/Upgrades/ITS3/macros/test/buildMatBudLUT.C +++ b/Detectors/Upgrades/ITS3/macros/test/buildMatBudLUT.C @@ -25,8 +25,6 @@ #include #endif -#ifndef GPUCA_ALIGPUCODE // this part is invisible on GPU version - o2::base::MatLayerCylSet mbLUT; bool testMBLUT(const std::string& lutFile = "matbud.root"); @@ -405,5 +403,3 @@ void configLayers() lrData.emplace_back(lrData.back().rMax, lrData.back().rMax + drStep, zSpanH, zBin, rphiBin); } while (lrData.back().rMax < 500); } - -#endif //!_COMPILED_ON_GPU_ diff --git a/Detectors/Vertexing/include/DetectorsVertexing/SVertexer.h b/Detectors/Vertexing/include/DetectorsVertexing/SVertexer.h index b933363bb352d..4d783b0018fc3 100644 --- a/Detectors/Vertexing/include/DetectorsVertexing/SVertexer.h +++ b/Detectors/Vertexing/include/DetectorsVertexing/SVertexer.h @@ -35,7 +35,6 @@ #include #include #include "GPUO2InterfaceRefit.h" -#include "TPCFastTransform.h" #include "DataFormatsTPC/PIDResponse.h" namespace o2 @@ -46,7 +45,7 @@ class VDriftCorrFact; } namespace gpu { -class CorrectionMapsHelper; +class TPCFastTransformPOD; } namespace vertexing @@ -143,7 +142,7 @@ class SVertexer mMUS2TPCBin = 1.f / (nbc * o2::constants::lhc::LHCBunchSpacingMUS); } void setTPCVDrift(const o2::tpc::VDriftCorrFact& v); - void setTPCCorrMaps(o2::gpu::CorrectionMapsHelper* maph); + void setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD* maph); void setStrangenessTracker(o2::strangeness_tracking::StrangenessTracker* tracker) { mStrTracker = tracker; } o2::strangeness_tracking::StrangenessTracker* getStrangenessTracker() { return mStrTracker; } @@ -175,7 +174,7 @@ class SVertexer gsl::span mTPCTrackClusIdx; ///< input TPC track cluster indices span gsl::span mTPCRefitterShMap; ///< externally set TPC clusters sharing map gsl::span mTPCRefitterOccMap; ///< externally set TPC clusters occupancy map - o2::gpu::CorrectionMapsHelper* mTPCCorrMapsHelper = nullptr; + const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps = nullptr; std::unique_ptr mTPCRefitter; ///< TPC refitter used for TPC tracks refit during the reconstruction o2::strangeness_tracking::StrangenessTracker* mStrTracker = nullptr; gsl::span mPVertices; diff --git a/Detectors/Vertexing/src/SVertexer.cxx b/Detectors/Vertexing/src/SVertexer.cxx index 2c625c9cfaf0a..bf7d436ca150c 100644 --- a/Detectors/Vertexing/src/SVertexer.cxx +++ b/Detectors/Vertexing/src/SVertexer.cxx @@ -18,7 +18,7 @@ #include "TPCReconstruction/TPCFastTransformHelperO2.h" #include "DataFormatsTPC/WorkflowHelper.h" #include "DataFormatsTPC/VDriftCorrFact.h" -#include "CorrectionMapsHelper.h" +#include "TPCFastTransformPOD.h" #include "Framework/ProcessingContext.h" #include "Framework/DataProcessorSpec.h" #include "ReconstructionDataFormats/StrangeTrack.h" @@ -331,9 +331,9 @@ void SVertexer::setTPCVDrift(const o2::tpc::VDriftCorrFact& v) mTPCBin2Z = mTPCVDrift / mMUS2TPCBin; } //______________________________________________ -void SVertexer::setTPCCorrMaps(o2::gpu::CorrectionMapsHelper* maph) +void SVertexer::setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD* maph) { - mTPCCorrMapsHelper = maph; + mTPCCorrMaps = maph; } //__________________________________________________________________ @@ -458,7 +458,7 @@ void SVertexer::buildT2V(const o2::globaltracking::RecoContainer& recoData) // a mTPCClusterIdxStruct = &recoData.inputsTPCclusters->clusterIndex; mTPCRefitterShMap = recoData.clusterShMapTPC; mTPCRefitterOccMap = mRecoCont->occupancyMapTPC; - mTPCRefitter = std::make_unique(mTPCClusterIdxStruct, mTPCCorrMapsHelper, o2::base::Propagator::Instance()->getNominalBz(), mTPCTrackClusIdx.data(), 0, mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), mTPCRefitterOccMap.size(), nullptr, o2::base::Propagator::Instance()); + mTPCRefitter = std::make_unique(mTPCClusterIdxStruct, mTPCCorrMaps, o2::base::Propagator::Instance()->getNominalBz(), mTPCTrackClusIdx.data(), 0, mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), mTPCRefitterOccMap.size(), nullptr, o2::base::Propagator::Instance()); } std::unordered_map> tmap; @@ -1360,7 +1360,7 @@ float SVertexer::correctTPCTrack(SVertexer::TrackCand& trc, const o2::tpc::Track uint8_t sector, row; auto cl = &tTPC.getCluster(mTPCTrackClusIdx, tTPC.getNClusters() - 1, *mTPCClusterIdxStruct, sector, row); float x = 0, y = 0, z = 0; - mTPCCorrMapsHelper->Transform(sector, row, cl->getPad(), cl->getTime(), x, y, z, tTB); + mTPCCorrMaps->Transform(sector, row, cl->getPad(), cl->getTime(), x, y, z, tTB); if (x < o2::constants::geom::XTPCInnerRef) { x = o2::constants::geom::XTPCInnerRef; } diff --git a/EventVisualisation/Workflow/src/O2DPLDisplay.cxx b/EventVisualisation/Workflow/src/O2DPLDisplay.cxx index bd8ab5a664d99..0ca94ca812529 100644 --- a/EventVisualisation/Workflow/src/O2DPLDisplay.cxx +++ b/EventVisualisation/Workflow/src/O2DPLDisplay.cxx @@ -25,7 +25,6 @@ #include "CommonUtils/NameConf.h" #include "TRDBase/GeometryFlat.h" #include "TOFBase/Geo.h" -#include "TPCFastTransform.h" #include "TRDBase/Geometry.h" #include "EMCALCalib/CellRecalibrator.h" #include "EMCALWorkflow/CalibLoader.h" diff --git a/GPU/Common/CMakeLists.txt b/GPU/Common/CMakeLists.txt index 8f7a7c2e169ed..45ca83a3033f0 100644 --- a/GPU/Common/CMakeLists.txt +++ b/GPU/Common/CMakeLists.txt @@ -13,6 +13,7 @@ set(MODULE GPUCommon) set(HDRS_INSTALL GPUCommonAlgorithm.h + GPUCommonAlignedAlloc.h GPUCommonDef.h GPUCommonDefAPI.h GPUCommonHelpers.h diff --git a/GPU/Common/GPUCommonAlignedAlloc.h b/GPU/Common/GPUCommonAlignedAlloc.h new file mode 100644 index 0000000000000..8e028399f4910 --- /dev/null +++ b/GPU/Common/GPUCommonAlignedAlloc.h @@ -0,0 +1,61 @@ +// 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 GPUCommonAlignedAlloc.h +/// \author David Rohr + +#ifndef GPUCOMMONAKUGBEDALLOC_H +#define GPUCOMMONAKUGBEDALLOC_H + +#include + +namespace o2::gpu +{ + +template +struct alignedDeleter { + void operator()(void* ptr) { ::operator delete(ptr, std::align_val_t(std::max(MIN_ALIGN, alignof(T)))); }; +}; + +template +struct alignedAllocator { + using value_type = T; + T* allocate(std::size_t n) + { + return (T*)::operator new(n, std::align_val_t(std::max(MIN_ALIGN, alignof(T)))); + } + void deallocate(T* ptr, std::size_t) + { + alignedDeleter()(ptr); + } +}; + +template +struct aligned_unique_buffer_ptr : public std::unique_ptr> { + aligned_unique_buffer_ptr() = default; + aligned_unique_buffer_ptr(size_t n) { alloc(n); } + aligned_unique_buffer_ptr(T* ptr) { std::unique_ptr>::reset((char*)ptr); } + char* getraw() { return std::unique_ptr>::get(); } + const char* getraw() const { return std::unique_ptr>::get(); } + T* get() { return (T*)std::unique_ptr>::get(); } + const T* get() const { return (T*)std::unique_ptr>::get(); } + T* operator->() { return get(); } + const T* operator->() const { return get(); } + T* alloc(std::size_t n) + { + std::unique_ptr>::reset((char*)alignedAllocator().allocate(n)); + return get(); + } +}; + +} // namespace o2::gpu + +#endif // GPUCOMMONAKUGBEDALLOC_H diff --git a/GPU/Common/GPUCommonConfigurableParam.h b/GPU/Common/GPUCommonConfigurableParam.h new file mode 100644 index 0000000000000..475679df270e3 --- /dev/null +++ b/GPU/Common/GPUCommonConfigurableParam.h @@ -0,0 +1,42 @@ +// 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 GPUCommonConfigurableParam.h +/// \author David Rohr + +#ifndef GPUCOMMONCONFIGURABLEPARAM_H +#define GPUCOMMONCONFIGURABLEPARAM_H + +#include "GPUCommonDef.h" + +#if defined(GPUCA_STANDALONE) + +namespace o2::conf +{ +template +struct ConfigurableParamHelper { + static const T& Instance() + { + static T instance; + return instance; + } +}; +#define O2ParamDef(...) +} // namespace o2::conf + +#else + +#include "CommonUtils/ConfigurableParam.h" +#include "CommonUtils/ConfigurableParamHelper.h" + +#endif + +#endif diff --git a/GPU/Common/GPUCommonLogger.h b/GPU/Common/GPUCommonLogger.h index a70710e9ae744..296cf9c562088 100644 --- a/GPU/Common/GPUCommonLogger.h +++ b/GPU/Common/GPUCommonLogger.h @@ -16,10 +16,13 @@ #define GPUCOMMONFAIRLOGGER_H #include "GPUCommonDef.h" +#ifndef GPUCA_GPUCODE_DEVICE +#include +#endif -#if defined(GPUCA_GPUCODE_DEVICE) -namespace o2::gpu::detail +namespace o2::gpu::internal { +#if defined(GPUCA_GPUCODE_DEVICE) struct DummyLogger { template GPUd() DummyLogger& operator<<(Args... args) @@ -27,16 +30,25 @@ struct DummyLogger { return *this; } }; -} // namespace o2::gpu::detail +#else +template +void LOGP_internal(const char* str, Args... args) +{ + printf("%s\n", str); +} #endif +} // namespace o2::gpu::internal -#if defined(__OPENCL__) || (defined(GPUCA_GPUCODE_DEVICE) && !defined(GPUCA_GPU_DEBUG_PRINT)) -#define LOG(...) o2::gpu::detail::DummyLogger() +#ifdef GPUCA_GPUCODE_DEVICE +// ---------- begin GPUCA_GPUCODE_DEVICE ---------- + +#if defined(__OPENCL__) || !defined(GPUCA_GPU_DEBUG_PRINT) +#define LOG(...) o2::gpu::internal::DummyLogger() #define LOGF(...) #define LOGP(...) -#elif defined(GPUCA_GPUCODE_DEVICE) -#define LOG(...) o2::gpu::detail::DummyLogger() +#else +#define LOG(...) o2::gpu::internal::DummyLogger() // #define LOG(...) static_assert(false, "LOG(...) << ... unsupported in GPU code"); #define LOGF(type, string, ...) \ { \ @@ -44,23 +56,39 @@ struct DummyLogger { } #define LOGP(...) // #define LOGP(...) static_assert(false, "LOGP(...) unsupported in GPU code"); +#endif +// ---------- end GPUCA_GPUCODE_DEVICE ---------- #elif defined(GPUCA_STANDALONE) || defined(GPUCA_GPUCODE_COMPILEKERNELS) || defined(GPUCA_COMPILEKERNELS) +// ---------- begin GPUCA_STANDALONE / COMPILEKERNELS ---------- + #include #include #define LOG(type) std::cout -#define LOGF(type, string, ...) \ - { \ - printf(string "\n", ##__VA_ARGS__); \ - } -#define LOGP(type, string, ...) \ - { \ - printf("%s\n", string); \ - } +#define LOGF(type, string, ...) printf(string "\n", ##__VA_ARGS__); +#if !defined(GPUCA_NO_FMT) && !defined(GPUCA_GPUCODE) +#define LOGP(type, string, ...) fmt::print(string, ##__VA_ARGS__) +#else +#define LOGP(type, string, ...) o2::gpu::internal::LOGP_internal(string, ##__VA_ARGS__) +#endif +#if defined(GPUCA_STANDALONE) && !defined(GPUCA_GPUCODE) +#if !defined(GPUCA_NO_FMT) +#include +#else +namespace fmt +{ +template +static const char* format(Args... args) +{ + return ""; +} +} // namespace fmt +#endif +#endif +// ---------- end GPUCA_STANDALONE / COMPILEKERNELS ---------- #else #include - #endif #endif diff --git a/GPU/GPUTracking/Base/GPUConstantMem.h b/GPU/GPUTracking/Base/GPUConstantMem.h index 94ccfa7fa6db9..14c388e450d73 100644 --- a/GPU/GPUTracking/Base/GPUConstantMem.h +++ b/GPU/GPUTracking/Base/GPUConstantMem.h @@ -40,13 +40,13 @@ namespace o2::gpu { struct GPUConstantMem { GPUParam param; - GPUTPCTracker tpcTrackers[GPUCA_NSECTORS]; + GPUTPCTracker tpcTrackers[GPUTPCGeometry::NSECTORS]; GPUTPCCompression tpcCompressor; GPUTPCDecompression tpcDecompressor; GPUTPCGMMerger tpcMerger; GPUTRDTrackerGPU trdTrackerGPU; GPUTRDTracker trdTrackerO2; - GPUTPCClusterFinder tpcClusterer[GPUCA_NSECTORS]; + GPUTPCClusterFinder tpcClusterer[GPUTPCGeometry::NSECTORS]; GPUTrackingRefitProcessor trackingRefit; GPUTrackingInOutPointers ioPtrs; GPUCalibObjectsConst calibObjects; @@ -55,7 +55,7 @@ struct GPUConstantMem { GPUKernelDebugOutput debugOutput; #endif #ifdef GPUCA_HAS_ONNX - GPUTPCNNClusterizer tpcNNClusterer[GPUCA_NSECTORS]; + GPUTPCNNClusterizer tpcNNClusterer[GPUTPCGeometry::NSECTORS]; #endif template GPUd() auto& getTRDTracker(); diff --git a/GPU/GPUTracking/Base/GPUParam.cxx b/GPU/GPUTracking/Base/GPUParam.cxx index aa4c3c7671c93..3f6c08e9f53fe 100644 --- a/GPU/GPUTracking/Base/GPUParam.cxx +++ b/GPU/GPUTracking/Base/GPUParam.cxx @@ -38,7 +38,7 @@ void GPUParam::SetDefaults(float solenoidBz, bool assumeConstantBz) occupancyMapSize = 0; occupancyTotal = 0; -#ifdef GPUCA_TPC_GEOMETRY_O2 +#ifndef GPUCA_RUN2 const float kErrorsY[4] = {0.06, 0.24, 0.12, 0.1}; const float kErrorsZ[4] = {0.06, 0.24, 0.15, 0.1}; @@ -91,16 +91,16 @@ void GPUParam::SetDefaults(float solenoidBz, bool assumeConstantBz) constexpr float plusZmax = 249.778; constexpr float minusZmin = -249.645; constexpr float minusZmax = -0.0799937; - for (int32_t i = 0; i < GPUCA_NSECTORS; i++) { - const bool zPlus = (i < GPUCA_NSECTORS / 2); + for (uint32_t i = 0; i < GPUTPCGeometry::NSECTORS; i++) { + const bool zPlus = (i < GPUTPCGeometry::NSECTORS / 2); SectorParam[i].ZMin = zPlus ? plusZmin : minusZmin; SectorParam[i].ZMax = zPlus ? plusZmax : minusZmax; int32_t tmp = i; - if (tmp >= GPUCA_NSECTORS / 2) { - tmp -= GPUCA_NSECTORS / 2; + if (tmp >= (int32_t)GPUTPCGeometry::NSECTORS / 2) { + tmp -= GPUTPCGeometry::NSECTORS / 2; } - if (tmp >= GPUCA_NSECTORS / 4) { - tmp -= GPUCA_NSECTORS / 2; + if (tmp >= (int32_t)GPUTPCGeometry::NSECTORS / 4) { + tmp -= GPUTPCGeometry::NSECTORS / 2; } SectorParam[i].Alpha = 0.174533f + dAlpha * tmp; SectorParam[i].CosAlpha = CAMath::Cos(SectorParam[i].Alpha); @@ -161,7 +161,7 @@ void GPUParam::SetDefaults(const GPUSettingsGRP* g, const GPUSettingsRec* r, con void GPUParam::UpdateRun3ClusterErrors(const float* yErrorParam, const float* zErrorParam) { -#ifdef GPUCA_TPC_GEOMETRY_O2 +#ifndef GPUCA_RUN2 for (int32_t yz = 0; yz < 2; yz++) { const float* param = yz ? zErrorParam : yErrorParam; for (int32_t rowType = 0; rowType < 4; rowType++) { diff --git a/GPU/GPUTracking/Base/GPUParam.h b/GPU/GPUTracking/Base/GPUParam.h index 0716274c5e198..27d23fd49920a 100644 --- a/GPU/GPUTracking/Base/GPUParam.h +++ b/GPU/GPUTracking/Base/GPUParam.h @@ -20,6 +20,7 @@ #include "GPUDef.h" #include "GPUSettings.h" #include "GPUTPCGMPolynomialField.h" +#include "DataFormatsTPC/Constants.h" #if !defined(GPUCA_GPUCODE) namespace o2::base @@ -65,10 +66,10 @@ struct GPUParam_t { uint32_t occupancyTotal; // Total occupancy in the TPC (nCl / nHbf) uint32_t occupancyMapSize; // Size of occupancy map - GPUParamSector SectorParam[GPUCA_NSECTORS]; + GPUParamSector SectorParam[o2::tpc::constants::MAXSECTOR]; protected: -#ifdef GPUCA_TPC_GEOMETRY_O2 +#ifndef GPUCA_RUN2 float ParamErrors[2][4][4]; // cluster error parameterization used during seeding and fit #else float ParamErrorsSeeding0[2][3][4]; // cluster error parameterization used during seeding @@ -87,13 +88,14 @@ struct GPUParam : public internal::GPUParam_t void UpdateRun3ClusterErrors(const float* yErrorParam, const float* zErrorParam); #endif - GPUd() float Alpha(int32_t iSector) const + GPUd() constexpr uint32_t tpcMinHitsB5(float qPtB5) const { return CAMath::Abs(qPtB5) > 10 ? 10 : (CAMath::Abs(qPtB5) > 5 ? 15 : 29); } // Minimum hits should depend on Pt, low Pt tracks can have few hits. 29 Hits default, 15 for < 200 mev, 10 for < 100 mev + GPUd() constexpr float Alpha(int32_t iSector) const { - if (iSector >= GPUCA_NSECTORS / 2) { - iSector -= GPUCA_NSECTORS / 2; + if (iSector >= (int32_t)o2::tpc::constants::MAXSECTOR / 2) { + iSector -= o2::tpc::constants::MAXSECTOR / 2; } - if (iSector >= GPUCA_NSECTORS / 4) { - iSector -= GPUCA_NSECTORS / 2; + if (iSector >= (int32_t)o2::tpc::constants::MAXSECTOR / 4) { + iSector -= o2::tpc::constants::MAXSECTOR / 2; } return 0.174533f + dAlpha * iSector; } diff --git a/GPU/GPUTracking/Base/GPUParam.inc b/GPU/GPUTracking/Base/GPUParam.inc index dbccca4d7c46b..8ed6160af361d 100644 --- a/GPU/GPUTracking/Base/GPUParam.inc +++ b/GPU/GPUTracking/Base/GPUParam.inc @@ -39,7 +39,7 @@ GPUdi() void GPUParam::Global2Sector(int32_t iSector, float X, float Y, float Z, *z = Z; } -#ifdef GPUCA_TPC_GEOMETRY_O2 +#ifndef GPUCA_RUN2 GPUdi() void GPUParam::GetClusterErrorsSeeding2(uint8_t sector, int32_t iRow, float z, float sinPhi, float DzDs, float time, float& ErrY2, float& ErrZ2) const { @@ -116,12 +116,12 @@ GPUdi() float GPUParam::GetSystematicClusterErrorC122(float x, float y, uint8_t return 0.f; } constexpr float dEdgeInv = 18.f / CAMath::Pi(); - const float dy = (sector == (GPUCA_NSECTORS / 2 + 1) ? 0.5f : -0.5f) * (y / x) * dEdgeInv + 0.5f; + const float dy = (sector == (GPUTPCGeometry::NSECTORS / 2 + 1) ? 0.5f : -0.5f) * (y / x) * dEdgeInv + 0.5f; const float errC12 = rec.tpc.sysClusErrorC12Norm * occupancyTotal * dy; return errC12 * errC12; } -#else // GPUCA_TPC_GEOMETRY_O2 +#else // !GPUCA_RUN2 GPUdi() float GPUParam::GetClusterErrorSeeding(int32_t yz, int32_t type, float zDiff, float angle2, float scaledMult) const { @@ -169,7 +169,7 @@ GPUdi() float GPUParam::GetSystematicClusterErrorC122(float trackX, float trackY return 0; } -#endif // !GPUCA_TPC_GEOMETRY_O2 +#endif // GPUCA_RUN2 GPUdi() void GPUParam::GetClusterErrors2(uint8_t sector, int32_t iRow, float z, float sinPhi, float DzDs, float time, float avgInvCharge, float invCharge, float& ErrY2, float& ErrZ2) const { diff --git a/GPU/GPUTracking/Base/GPUProcessor.h b/GPU/GPUTracking/Base/GPUProcessor.h index df551c9f0330d..337ecfc61f79d 100644 --- a/GPU/GPUTracking/Base/GPUProcessor.h +++ b/GPU/GPUTracking/Base/GPUProcessor.h @@ -62,7 +62,7 @@ class GPUProcessor return *(T*)(mGPUProcessorType == PROCESSOR_TYPE_DEVICE ? mLinkedProcessor : this); } - template + template static constexpr inline size_t getAlignmentMod(size_t addr) { static_assert((alignment & (alignment - 1)) == 0, "Invalid alignment, not power of 2"); @@ -71,7 +71,7 @@ class GPUProcessor } return addr & (alignment - 1); } - template + template static constexpr inline size_t getAlignment(size_t addr) { size_t mod = getAlignmentMod(addr); @@ -80,7 +80,7 @@ class GPUProcessor } return (alignment - mod); } - template + template static constexpr inline size_t nextMultipleOf(size_t size) { return size + getAlignment(size); @@ -97,22 +97,22 @@ class GPUProcessor return (size + alignment - 1) & ~(alignment - 1); } } - template + template static inline void* alignPointer(void* ptr) { return (reinterpret_cast(nextMultipleOf(reinterpret_cast(ptr)))); } - template + template static inline size_t getAlignmentMod(void* addr) { return (getAlignmentMod(reinterpret_cast(addr))); } - template + template static inline size_t getAlignment(void* addr) { return (getAlignment(reinterpret_cast(addr))); } - template + template static inline S* getPointerWithAlignment(size_t& basePtr, size_t nEntries = 1) { if (basePtr == 0) { @@ -125,7 +125,7 @@ class GPUProcessor return retVal; } - template + template static inline S* getPointerWithAlignment(void*& basePtr, size_t nEntries = 1) { size_t tmp = (size_t)basePtr; @@ -134,7 +134,7 @@ class GPUProcessor return retVal; } - template + template static inline void computePointerWithAlignment(T*& basePtr, S*& objPtr, size_t nEntries = 1) { size_t tmp = (size_t)basePtr; @@ -145,8 +145,8 @@ class GPUProcessor template static inline void computePointerWithoutAlignment(T*& basePtr, S*& objPtr, size_t nEntries = 1) { - if ((size_t)basePtr < GPUCA_BUFFER_ALIGNMENT) { - basePtr = (T*)GPUCA_BUFFER_ALIGNMENT; + if ((size_t)basePtr < constants::GPU_BUFFER_ALIGNMENT) { + basePtr = (T*)constants::GPU_BUFFER_ALIGNMENT; } size_t tmp = (size_t)basePtr; objPtr = reinterpret_cast(getPointerWithAlignment<1, char>(tmp, nEntries * sizeof(S))); diff --git a/GPU/GPUTracking/Base/GPUReconstruction.cxx b/GPU/GPUTracking/Base/GPUReconstruction.cxx index f6aa62778a061..555ca39edb3a3 100644 --- a/GPU/GPUTracking/Base/GPUReconstruction.cxx +++ b/GPU/GPUTracking/Base/GPUReconstruction.cxx @@ -42,7 +42,7 @@ #include "utils/strtag.h" #include "utils/stdspinlock.h" -#ifdef GPUCA_O2_LIB +#ifndef GPUCA_STANDALONE #include "GPUO2InterfaceConfiguration.h" #endif @@ -343,14 +343,14 @@ int32_t GPUReconstruction::InitPhaseBeforeDevice() } if (GetProcessingSettings().nTPCClustererLanes == -1) { - mProcessingSettings->nTPCClustererLanes = (GetRecoStepsGPU() & RecoStep::TPCClusterFinding) ? 3 : std::max(1, std::min(GPUCA_NSECTORS, GetProcessingSettings().inKernelParallel ? (mMaxHostThreads >= 4 ? std::min(mMaxHostThreads / 2, mMaxHostThreads >= 32 ? GPUCA_NSECTORS : 4) : 1) : mMaxHostThreads)); + mProcessingSettings->nTPCClustererLanes = (GetRecoStepsGPU() & RecoStep::TPCClusterFinding) ? 3 : std::max(1, std::min(GPUTPCGeometry::NSECTORS, GetProcessingSettings().inKernelParallel ? (mMaxHostThreads >= 4 ? std::min(mMaxHostThreads / 2, mMaxHostThreads >= 32 ? GPUTPCGeometry::NSECTORS : 4) : 1) : mMaxHostThreads)); } if (GetProcessingSettings().overrideClusterizerFragmentLen == -1) { mProcessingSettings->overrideClusterizerFragmentLen = ((GetRecoStepsGPU() & RecoStep::TPCClusterFinding) || (mMaxHostThreads / GetProcessingSettings().nTPCClustererLanes >= 3)) ? TPC_MAX_FRAGMENT_LEN_GPU : TPC_MAX_FRAGMENT_LEN_HOST; } - if (GetProcessingSettings().nTPCClustererLanes > GPUCA_NSECTORS) { + if ((uint32_t)GetProcessingSettings().nTPCClustererLanes > GPUTPCGeometry::NSECTORS) { GPUError("Invalid value for nTPCClustererLanes: %d", GetProcessingSettings().nTPCClustererLanes); - mProcessingSettings->nTPCClustererLanes = GPUCA_NSECTORS; + mProcessingSettings->nTPCClustererLanes = GPUTPCGeometry::NSECTORS; } if (GetProcessingSettings().doublePipeline) { @@ -467,7 +467,7 @@ int32_t GPUReconstruction::Exit() if (mMemoryResources[i].mReuse >= 0) { continue; } - operator delete(mMemoryResources[i].mPtrDevice, std::align_val_t(GPUCA_BUFFER_ALIGNMENT)); + ::operator delete(mMemoryResources[i].mPtrDevice, std::align_val_t(constants::GPU_BUFFER_ALIGNMENT)); mMemoryResources[i].mPtr = mMemoryResources[i].mPtrDevice = nullptr; } } @@ -597,11 +597,11 @@ size_t GPUReconstruction::AllocateRegisteredMemoryHelper(GPUMemoryResource* res, stdspinlock spinlock(mMemoryMutex); if ((res->mType & GPUMemoryResource::MEMORY_STACK) && memorypoolend) { retVal = ptrDiff((res->*setPtr)((char*)1), (char*)(1)); - memorypoolend = (void*)((char*)memorypoolend - GPUProcessor::getAlignmentMod(memorypoolend)); + memorypoolend = (void*)((char*)memorypoolend - GPUProcessor::getAlignmentMod(memorypoolend)); if (retVal < res->mOverrideSize) { retVal = res->mOverrideSize; } - retVal += GPUProcessor::getAlignment(retVal); + retVal += GPUProcessor::getAlignment(retVal); memorypoolend = (char*)memorypoolend - retVal; ptr = memorypoolend; retVal = std::max(ptrDiff((res->*setPtr)(ptr), ptr), res->mOverrideSize); @@ -613,7 +613,7 @@ size_t GPUReconstruction::AllocateRegisteredMemoryHelper(GPUMemoryResource* res, retVal = res->mOverrideSize; memorypool = (char*)ptr + res->mOverrideSize; } - memorypool = (void*)((char*)memorypool + GPUProcessor::getAlignment(memorypool)); + memorypool = (void*)((char*)memorypool + GPUProcessor::getAlignment(memorypool)); } if (memorypoolend ? (memorypool > memorypoolend) : ((size_t)ptrDiff(memorypool, memorybase) > memorysize)) { std::cerr << "Memory pool size exceeded (" << device << ") (" << res->mName << ": " << (memorypoolend ? (memorysize + ptrDiff(memorypool, memorypoolend)) : ptrDiff(memorypool, memorybase)) << " > " << memorysize << "\n"; @@ -630,7 +630,7 @@ void GPUReconstruction::AllocateRegisteredMemoryInternal(GPUMemoryResource* res, if (GetProcessingSettings().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_INDIVIDUAL && (control == nullptr || control->useInternal())) { if (!(res->mType & GPUMemoryResource::MEMORY_EXTERNAL)) { if (res->mPtrDevice && res->mReuse < 0) { - operator delete(res->mPtrDevice, std::align_val_t(GPUCA_BUFFER_ALIGNMENT)); + ::operator delete(res->mPtrDevice, std::align_val_t(constants::GPU_BUFFER_ALIGNMENT)); } res->mSize = std::max((size_t)res->SetPointers((void*)1) - 1, res->mOverrideSize); if (res->mReuse >= 0) { @@ -640,9 +640,9 @@ void GPUReconstruction::AllocateRegisteredMemoryInternal(GPUMemoryResource* res, } res->mPtrDevice = mMemoryResources[res->mReuse].mPtrDevice; } else { - res->mPtrDevice = operator new(res->mSize + GPUCA_BUFFER_ALIGNMENT, std::align_val_t(GPUCA_BUFFER_ALIGNMENT)); + res->mPtrDevice = ::operator new(res->mSize + constants::GPU_BUFFER_ALIGNMENT, std::align_val_t(constants::GPU_BUFFER_ALIGNMENT)); } - res->mPtr = GPUProcessor::alignPointer(res->mPtrDevice); + res->mPtr = GPUProcessor::alignPointer(res->mPtrDevice); res->SetPointers(res->mPtr); if (GetProcessingSettings().allocDebugLevel >= 2) { std::cout << (res->mReuse >= 0 ? "Reused " : "Allocated ") << res->mName << ": " << res->mSize << " (individual" << ((res->mType & GPUMemoryResource::MEMORY_STACK) ? " stack" : "") << ")\n"; @@ -651,7 +651,7 @@ void GPUReconstruction::AllocateRegisteredMemoryInternal(GPUMemoryResource* res, stdspinlock spinlock(mMemoryMutex); mNonPersistentIndividualAllocations.emplace_back(res); } - if ((size_t)res->mPtr % GPUCA_BUFFER_ALIGNMENT) { + if ((size_t)res->mPtr % constants::GPU_BUFFER_ALIGNMENT) { GPUError("Got buffer with insufficient alignment"); throw std::bad_alloc(); } @@ -661,14 +661,14 @@ void GPUReconstruction::AllocateRegisteredMemoryInternal(GPUMemoryResource* res, GPUError("Double allocation! (%s)", res->mName); throw std::bad_alloc(); } - if (IsGPU() && res->mOverrideSize < GPUCA_BUFFER_ALIGNMENT) { - res->mOverrideSize = GPUCA_BUFFER_ALIGNMENT; + if (IsGPU() && res->mOverrideSize < constants::GPU_BUFFER_ALIGNMENT) { + res->mOverrideSize = constants::GPU_BUFFER_ALIGNMENT; } if ((!IsGPU() || (res->mType & GPUMemoryResource::MEMORY_HOST) || GetProcessingSettings().keepDisplayMemory) && !(res->mType & GPUMemoryResource::MEMORY_EXTERNAL)) { // keepAllMemory --> keepDisplayMemory if (control && control->useExternal()) { if (control->allocator) { res->mSize = std::max((size_t)res->SetPointers((void*)1) - 1, res->mOverrideSize); - res->mPtr = control->allocator(CAMath::nextMultipleOf(res->mSize)); + res->mPtr = control->allocator(CAMath::nextMultipleOf(res->mSize)); res->mSize = std::max(ptrDiff(res->SetPointers(res->mPtr), res->mPtr), res->mOverrideSize); if (GetProcessingSettings().allocDebugLevel >= 2) { std::cout << "Allocated (from callback) " << res->mName << ": " << res->mSize << "\n"; @@ -680,7 +680,7 @@ void GPUReconstruction::AllocateRegisteredMemoryInternal(GPUMemoryResource* res, } else { res->mSize = AllocateRegisteredMemoryHelper(res, res->mPtr, recPool->mHostMemoryPool, recPool->mHostMemoryBase, recPool->mHostMemorySize, &GPUMemoryResource::SetPointers, recPool->mHostMemoryPoolEnd, "host"); } - if ((size_t)res->mPtr % GPUCA_BUFFER_ALIGNMENT) { + if ((size_t)res->mPtr % constants::GPU_BUFFER_ALIGNMENT) { GPUError("Got buffer with insufficient alignment"); throw std::bad_alloc(); } @@ -702,7 +702,7 @@ void GPUReconstruction::AllocateRegisteredMemoryInternal(GPUMemoryResource* res, GPUError("Inconsistent device memory allocation (%s: device %lu vs %lu)", res->mName, size, res->mSize); throw std::bad_alloc(); } - if ((size_t)res->mPtrDevice % GPUCA_BUFFER_ALIGNMENT) { + if ((size_t)res->mPtrDevice % constants::GPU_BUFFER_ALIGNMENT) { GPUError("Got buffer with insufficient alignment"); throw std::bad_alloc(); } @@ -731,11 +731,11 @@ void* GPUReconstruction::AllocateDirectMemory(size_t size, int32_t type) { stdspinlock spinlock(mMemoryMutex); if (GetProcessingSettings().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_INDIVIDUAL) { - char* retVal = new (std::align_val_t(GPUCA_BUFFER_ALIGNMENT)) char[size]; + char* retVal = new (std::align_val_t(constants::GPU_BUFFER_ALIGNMENT)) char[size]; if ((type & GPUMemoryResource::MEMORY_STACK)) { - mNonPersistentIndividualDirectAllocations.emplace_back(retVal, alignedDeleter()); + mNonPersistentIndividualDirectAllocations.emplace_back(retVal, alignedDefaultBufferDeleter()); } else { - mDirectMemoryChunks.emplace_back(retVal, alignedDeleter()); + mDirectMemoryChunks.emplace_back(retVal, alignedDefaultBufferDeleter()); } return retVal; } @@ -753,7 +753,7 @@ void* GPUReconstruction::AllocateDirectMemory(size_t size, int32_t type) char* retVal; if ((type & GPUMemoryResource::MEMORY_STACK)) { poolend = (char*)poolend - size; // TODO: Implement overflow check - poolend = (char*)poolend - GPUProcessor::getAlignmentMod(poolend); + poolend = (char*)poolend - GPUProcessor::getAlignmentMod(poolend); retVal = (char*)poolend; } else { GPUProcessor::computePointerWithAlignment(pool, retVal, size); @@ -796,9 +796,9 @@ void* GPUReconstruction::AllocateVolatileMemory(size_t size, bool device) if (device) { return AllocateVolatileDeviceMemory(size); } - char* retVal = new (std::align_val_t(GPUCA_BUFFER_ALIGNMENT)) char[size]; + char* retVal = new (std::align_val_t(constants::GPU_BUFFER_ALIGNMENT)) char[size]; stdspinlock spinlock(mMemoryMutex); - mVolatileChunks.emplace_back(retVal, alignedDeleter()); + mVolatileChunks.emplace_back(retVal, alignedDefaultBufferDeleter()); return retVal; } @@ -876,7 +876,7 @@ void GPUReconstruction::FreeRegisteredMemory(GPUMemoryResource* res) std::cout << "Freeing " << res->mName << ": size " << res->mSize << " (reused " << res->mReuse << ")\n"; } if (GetProcessingSettings().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_INDIVIDUAL && res->mReuse < 0) { - operator delete(res->mPtrDevice, std::align_val_t(GPUCA_BUFFER_ALIGNMENT)); + ::operator delete(res->mPtrDevice, std::align_val_t(constants::GPU_BUFFER_ALIGNMENT)); } res->mPtr = nullptr; res->mPtrDevice = nullptr; @@ -916,7 +916,7 @@ void GPUReconstruction::PopNonPersistentMemory(RecoStep step, uint64_t tag, cons std::cout << "Freeing NonPersistent " << res->mName << ": size " << res->mSize << " (reused " << res->mReuse << ")\n"; } if (res->mReuse < 0) { - operator delete(res->mPtrDevice, std::align_val_t(GPUCA_BUFFER_ALIGNMENT)); + ::operator delete(res->mPtrDevice, std::align_val_t(constants::GPU_BUFFER_ALIGNMENT)); } res->mPtr = nullptr; res->mPtrDevice = nullptr; @@ -970,8 +970,8 @@ void GPUReconstruction::ClearAllocatedMemory(bool clearOutputs) mVolatileChunks.clear(); mVolatileMemoryStart = nullptr; if (GetProcessingSettings().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_GLOBAL) { - mHostMemoryPool = GPUProcessor::alignPointer(mHostMemoryPermanent); - mDeviceMemoryPool = GPUProcessor::alignPointer(mDeviceMemoryPermanent); + mHostMemoryPool = GPUProcessor::alignPointer(mHostMemoryPermanent); + mDeviceMemoryPool = GPUProcessor::alignPointer(mDeviceMemoryPermanent); mHostMemoryPoolEnd = mHostMemoryPoolBlocked ? mHostMemoryPoolBlocked : ((char*)mHostMemoryBase + mHostMemorySize); mDeviceMemoryPoolEnd = mDeviceMemoryPoolBlocked ? mDeviceMemoryPoolBlocked : ((char*)mDeviceMemoryBase + mDeviceMemorySize); } else { @@ -1237,7 +1237,8 @@ int32_t GPUReconstruction::ReadSettings(const char* dir) f = dir; f += "settings.dump"; new (mGRPSettings.get()) GPUSettingsGRP; - if (ReadStructFromFile(f.c_str(), mGRPSettings.get())) { + bool error; + if (ReadStructFromFile(f.c_str(), mGRPSettings.get(), &error) && error) { return 1; } param().UpdateSettings(mGRPSettings.get()); @@ -1249,15 +1250,15 @@ int32_t GPUReconstruction::ReadSettings(const char* dir) void GPUReconstruction::SetSettings(float solenoidBzNominalGPU, const GPURecoStepConfiguration* workflow) { -#ifdef GPUCA_O2_LIB +#ifdef GPUCA_STANDALONE + GPUSettingsGRP grp; + grp.solenoidBzNominalGPU = solenoidBzNominalGPU; + SetSettings(&grp, nullptr, nullptr, workflow); +#else GPUO2InterfaceConfiguration config; config.ReadConfigurableParam(config); config.configGRP.solenoidBzNominalGPU = solenoidBzNominalGPU; SetSettings(&config.configGRP, &config.configReconstruction, &config.configProcessing, workflow); -#else - GPUSettingsGRP grp; - grp.solenoidBzNominalGPU = solenoidBzNominalGPU; - SetSettings(&grp, nullptr, nullptr, workflow); #endif } diff --git a/GPU/GPUTracking/Base/GPUReconstruction.h b/GPU/GPUTracking/Base/GPUReconstruction.h index 9a337c02ad26d..fb07a66a21b9e 100644 --- a/GPU/GPUTracking/Base/GPUReconstruction.h +++ b/GPU/GPUTracking/Base/GPUReconstruction.h @@ -32,6 +32,7 @@ #include "GPUOutputControl.h" #include "GPUParam.h" #include "GPUConstantMem.h" +#include "GPUCommonAlignedAlloc.h" #include "GPUDef.h" namespace o2::its @@ -81,7 +82,7 @@ class GPUReconstruction GPUReconstruction& operator=(const GPUReconstruction&) = delete; // General definitions - constexpr static uint32_t NSECTORS = GPUCA_NSECTORS; + constexpr static uint32_t NSECTORS = GPUTPCGeometry::NSECTORS; using GeometryType = gpudatatypes::GeometryType; using DeviceType = gpudatatypes::DeviceType; @@ -91,10 +92,10 @@ class GPUReconstruction using InOutTypeField = gpudatatypes::InOutTypeField; static constexpr const char* const GEOMETRY_TYPE_NAMES[] = {"INVALID", "ALIROOT", "O2"}; -#ifdef GPUCA_TPC_GEOMETRY_O2 - static constexpr GeometryType geometryType = GeometryType::O2; -#else +#ifdef GPUCA_RUN2 static constexpr GeometryType geometryType = GeometryType::ALIROOT; +#else + static constexpr GeometryType geometryType = GeometryType::O2; #endif static DeviceType GetDeviceType(const char* type); @@ -299,9 +300,11 @@ class GPUReconstruction template void DumpStructToFile(const T* obj, const char* file); template - std::unique_ptr ReadStructFromFile(const char* file); + void DumpDynamicStructToFile(const T* obj, size_t dynamicSize, const char* file); template - int32_t ReadStructFromFile(const char* file, T* obj); + std::unique_ptr ReadStructFromFile(const char* file, T* obj = nullptr, bool* errorOnMissing = nullptr); + template + aligned_unique_buffer_ptr ReadDynamicStructFromFile(const char* file); // Others virtual RecoStepField AvailableGPURecoSteps() { return RecoStep::AllRecoSteps; } @@ -381,15 +384,13 @@ class GPUReconstruction GPUProcessor* proc = nullptr; std::vector res; }; - struct alignedDeleter { - void operator()(void* ptr) { ::operator delete[](ptr, std::align_val_t(GPUCA_BUFFER_ALIGNMENT)); }; - }; std::unordered_map mMemoryReuse1to1; std::vector> mNonPersistentMemoryStack; // hostPoolAddress, devicePoolAddress, individualAllocationCount, directIndividualAllocationCound, tag std::vector mNonPersistentIndividualAllocations; - std::vector> mNonPersistentIndividualDirectAllocations; - std::vector> mDirectMemoryChunks; - std::vector> mVolatileChunks; + using alignedDefaultBufferDeleter = alignedDeleter; + std::vector> mNonPersistentIndividualDirectAllocations; + std::vector> mDirectMemoryChunks; + std::vector> mVolatileChunks; std::atomic_flag mMemoryMutex = ATOMIC_FLAG_INIT; std::unique_ptr mPipelineContext; diff --git a/GPU/GPUTracking/Base/GPUReconstructionCPU.cxx b/GPU/GPUTracking/Base/GPUReconstructionCPU.cxx index 752b5f27ded3f..1aa54ae56b67b 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionCPU.cxx +++ b/GPU/GPUTracking/Base/GPUReconstructionCPU.cxx @@ -189,7 +189,7 @@ int32_t GPUReconstructionCPU::InitDevice() if (mDeviceMemorySize > mHostMemorySize) { mHostMemorySize = mDeviceMemorySize; } - mHostMemoryBase = operator new(mHostMemorySize, std::align_val_t(GPUCA_BUFFER_ALIGNMENT)); + mHostMemoryBase = ::operator new(mHostMemorySize, std::align_val_t(constants::GPU_BUFFER_ALIGNMENT)); } mHostMemoryPermanent = mHostMemoryBase; ClearAllocatedMemory(); @@ -205,7 +205,7 @@ int32_t GPUReconstructionCPU::ExitDevice() { if (GetProcessingSettings().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_GLOBAL) { if (mMaster == nullptr) { - operator delete(mHostMemoryBase, std::align_val_t(GPUCA_BUFFER_ALIGNMENT)); + ::operator delete(mHostMemoryBase, std::align_val_t(constants::GPU_BUFFER_ALIGNMENT)); } mHostMemoryPool = mHostMemoryBase = mHostMemoryPoolEnd = mHostMemoryPermanent = nullptr; mHostMemorySize = 0; diff --git a/GPU/GPUTracking/Base/GPUReconstructionCPUKernels.h b/GPU/GPUTracking/Base/GPUReconstructionCPUKernels.h index 0c19941c40ea4..7970fbe753ec8 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionCPUKernels.h +++ b/GPU/GPUTracking/Base/GPUReconstructionCPUKernels.h @@ -49,8 +49,8 @@ inline void GPUReconstructionCPU::runKernelInterface(krnlSetup&& setup, Args con } else if ((int32_t)nThreads < 0) { nThreads = cpuFallback ? 1 : -nThreads; } - if (nThreads > GPUCA_MAX_THREADS) { - throw std::runtime_error("GPUCA_MAX_THREADS exceeded"); + if (nThreads > constants::GPU_MAX_THREADS) { + throw std::runtime_error("GPU_MAX_THREADS exceeded"); } if (GetProcessingSettings().debugLevel >= 3) { GPUInfo("Running kernel %s (Stream %d, Index %d, Grid %d/%d) on %s", GetKernelName(), stream, setup.y.index, nBlocks, nThreads, cpuFallback == 2 ? "CPU (forced)" : (cpuFallback ? "CPU (fallback)" : mDeviceName.c_str())); diff --git a/GPU/GPUTracking/Base/GPUReconstructionConvert.cxx b/GPU/GPUTracking/Base/GPUReconstructionConvert.cxx index a4b17b81bf5ac..9ec1af55a7a62 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionConvert.cxx +++ b/GPU/GPUTracking/Base/GPUReconstructionConvert.cxx @@ -12,7 +12,7 @@ /// \file GPUReconstructionConvert.cxx /// \author David Rohr -#ifdef GPUCA_O2_LIB +#ifndef GPUCA_STANDALONE #include "DetectorsRaw/RawFileWriter.h" #include "TPCBase/Sector.h" #include "DataFormatsTPC/Digit.h" @@ -20,7 +20,7 @@ #endif #include "GPUReconstructionConvert.h" -#include "TPCFastTransform.h" +#include "TPCFastTransformPOD.h" #include "GPUTPCClusterData.h" #include "GPUO2DataTypes.h" #include "GPUDataTypesIO.h" @@ -48,19 +48,19 @@ using namespace o2::tpc; using namespace o2::tpc::constants; using namespace std::string_literals; -void GPUReconstructionConvert::ConvertNativeToClusterData(o2::tpc::ClusterNativeAccess* native, std::unique_ptr* clusters, uint32_t* nClusters, const TPCFastTransform* transform, int32_t continuousMaxTimeBin) +void GPUReconstructionConvert::ConvertNativeToClusterData(o2::tpc::ClusterNativeAccess* native, std::unique_ptr* clusters, uint32_t* nClusters, const TPCFastTransformPOD* transform, int32_t continuousMaxTimeBin) { memset(nClusters, 0, NSECTORS * sizeof(nClusters[0])); uint32_t offset = 0; for (uint32_t i = 0; i < NSECTORS; i++) { uint32_t nClSector = 0; - for (int32_t j = 0; j < GPUCA_ROW_COUNT; j++) { + for (uint32_t j = 0; j < GPUTPCGeometry::NROWS; j++) { nClSector += native->nClusters[i][j]; } nClusters[i] = nClSector; clusters[i].reset(new GPUTPCClusterData[nClSector]); nClSector = 0; - for (int32_t j = 0; j < GPUCA_ROW_COUNT; j++) { + for (uint32_t j = 0; j < GPUTPCGeometry::NROWS; j++) { for (uint32_t k = 0; k < native->nClusters[i][j]; k++) { const auto& clin = native->clusters[i][j][k]; float x = 0, y = 0, z = 0; @@ -98,7 +98,7 @@ void GPUReconstructionConvert::ConvertRun2RawToNative(o2::tpc::ClusterNativeAcce native.clustersLinear = nativeBuffer.get(); native.setOffsetPtrs(); for (uint32_t i = 0; i < NSECTORS; i++) { - for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) { + for (uint32_t j = 0; j < GPUTPCGeometry::NROWS; j++) { native.nClusters[i][j] = 0; } for (uint32_t j = 0; j < nRawClusters[i]; j++) { @@ -119,7 +119,7 @@ int32_t GPUReconstructionConvert::GetMaxTimeBin(const ClusterNativeAccess& nativ { float retVal = 0; for (uint32_t i = 0; i < NSECTORS; i++) { - for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) { + for (uint32_t j = 0; j < GPUTPCGeometry::NROWS; j++) { for (uint32_t k = 0; k < native.nClusters[i][j]; k++) { if (native.clusters[i][j][k].getTime() > retVal) { retVal = native.clusters[i][j][k].getTime(); @@ -174,7 +174,7 @@ int32_t GPUReconstructionConvert::GetMaxTimeBin(const GPUTrackingInOutZS& zspage // ------------------------------------------------- TPC ZS ------------------------------------------------- -#ifdef GPUCA_TPC_GEOMETRY_O2 +#ifndef GPUCA_RUN2 namespace o2::gpu { namespace // anonymous @@ -193,7 +193,7 @@ struct zsEncoder { const o2::InteractionRecord* ir = nullptr; const GPUParam* param = nullptr; bool padding = false; - int32_t lastEndpoint = -2, lastTime = -1, lastRow = GPUCA_ROW_COUNT; + int32_t lastEndpoint = -2, lastTime = -1, lastRow = GPUTPCGeometry::NROWS; int32_t endpoint = 0, outputEndpoint = 0; int64_t hbf = -1, nexthbf = 0; zsPage* page = nullptr; @@ -244,11 +244,11 @@ inline void zsEncoder::ZSstreamOut(uint16_t* bufIn, uint32_t& lenIn, uint8_t* bu static inline auto ZSEncoderGetDigits(const GPUTrackingInOutDigits& in, int32_t i) { return in.tpcDigits[i]; } static inline auto ZSEncoderGetNDigits(const GPUTrackingInOutDigits& in, int32_t i) { return in.nTPCDigits[i]; } -#ifdef GPUCA_O2_LIB +#ifndef GPUCA_STANDALONE using DigitArray = std::array, o2::tpc::Sector::MAXSECTOR>; static inline auto ZSEncoderGetDigits(const DigitArray& in, int32_t i) { return in[i].data(); } static inline auto ZSEncoderGetNDigits(const DigitArray& in, int32_t i) { return in[i].size(); } -#endif // GPUCA_O2_LIB +#endif // ------------------------------------------------- TPC ZS Original Row-based ZS ------------------------------------------------- @@ -364,7 +364,7 @@ uint32_t zsEncoderRow::encodeSequence(std::vector& tmpBuffer, ui curTBHdr = reinterpret_cast(pagePtr); curTBHdr->rowMask |= (endpoint & 1) << 15; nRowsInTB = 0; - lastRow = GPUCA_ROW_COUNT; + lastRow = GPUTPCGeometry::NROWS; } if (tmpBuffer[k].getRow() != lastRow) { curTBHdr->rowMask |= 1 << (tmpBuffer[k].getRow() - endpointStart); @@ -460,7 +460,7 @@ void zsEncoderRow::decodePage(std::vector& outputBuffer, const z // ------------------------------------------------- TPC ZS Link Based ZS ------------------------------------------------- -#ifdef GPUCA_O2_LIB +#ifndef GPUCA_STANDALONE struct zsEncoderLinkBased : public zsEncoder { TPCZSHDRV2* hdr = nullptr; TPCZSHDRV2 hdrBuffer; @@ -1045,7 +1045,7 @@ void zsEncoderDenseLinkBased::amendPageErrorMessage(std::ostringstream& oss, con oss << "Meta header of page: " << dumpBuffer << "\n"; } -#endif // GPUCA_O2_LIB +#endif // !GPUCA_STANDALONE // ------------------------------------------------- TPC ZS Main Encoder ------------------------------------------------- @@ -1095,7 +1095,7 @@ inline uint32_t zsEncoderRun::run(std::vector* buffer, std::vector::run(std::vector* buffer, std::vector && (padding || lastEndpoint == -1 || hbf == nexthbf) ? TPCZSHDR::TPC_ZS_PAGE_SIZE : (pagePtr - (uint8_t*)page); size = CAMath::nextMultipleOf(size); -#ifdef GPUCA_O2_LIB +#ifndef GPUCA_STANDALONE if (raw) { raw->addData(rawfeeid, rawcru, 0, rawendpoint, *ir + hbf * o2::constants::lhc::LHCMaxBunches, gsl::span((char*)page + sizeof(o2::header::RAWDataHeader), (char*)page + size), true, 0, 2); maxhbf = std::max(maxhbf, hbf); @@ -1257,7 +1257,7 @@ inline uint32_t zsEncoderRun::run(std::vector* buffer, std::vectoraddData(46208, 360, rdh_utils::SACLinkID, 0, *ir + i * o2::constants::lhc::LHCMaxBunches, gsl::span((char*)&singleBuffer, (char*)&singleBuffer), true, 0, 4); @@ -1310,7 +1310,7 @@ size_t zsEncoderRun::compare(std::vector* buffer, std::vector void GPUReconstructionConvert::RunZSEncoder(const S& in, std::unique_ptr* outBuffer, uint32_t* outSizes, o2::raw::RawFileWriter* raw, const o2::InteractionRecord* ir, const GPUParam& param, int32_t version, bool verify, float threshold, bool padding, std::function&)> digitsFilter) @@ -1320,7 +1320,7 @@ void GPUReconstructionConvert::RunZSEncoder(const S& in, std::unique_ptr buffer[NSECTORS][GPUTrackingInOutZS::NENDPOINTS]; struct tmpReductionResult { uint32_t totalPages = 0; @@ -1365,7 +1365,7 @@ void GPUReconstructionConvert::RunZSEncoder(const S& in, std::unique_ptr enc{{{.iSector = i, .raw = raw, .ir = ir, .param = ¶m, .padding = padding}}}; runZS(enc); } else if (version >= ZSVersion::ZSVersionLinkBasedWithMeta && version <= ZSVersion::ZSVersionDenseLinkBasedV2) { -#ifdef GPUCA_O2_LIB +#ifndef GPUCA_STANDALONE if (version == ZSVersion::ZSVersionLinkBasedWithMeta) { zsEncoderRun enc{{{{.iSector = i, .raw = raw, .ir = ir, .param = ¶m, .padding = padding}}}}; runZS(enc); @@ -1410,7 +1410,7 @@ void GPUReconstructionConvert::RunZSEncoder(const S& in, std::unique_ptr(const GPUTrackingInOutDigits&, std::unique_ptr*, uint32_t*, o2::raw::RawFileWriter*, const o2::InteractionRecord*, const GPUParam&, int32_t, bool, float, bool, std::function&)> digitsFilter); -#ifdef GPUCA_O2_LIB +#ifndef GPUCA_STANDALONE template void GPUReconstructionConvert::RunZSEncoder(const DigitArray&, std::unique_ptr*, uint32_t*, o2::raw::RawFileWriter*, const o2::InteractionRecord*, const GPUParam&, int32_t, bool, float, bool, std::function&)> digitsFilter); #endif @@ -1454,7 +1454,7 @@ void GPUReconstructionConvert::RunZSFilter(std::unique_ptr* bu } } -#ifdef GPUCA_O2_LIB +#ifndef GPUCA_STANDALONE namespace o2::gpu::internal { template diff --git a/GPU/GPUTracking/Base/GPUReconstructionConvert.h b/GPU/GPUTracking/Base/GPUReconstructionConvert.h index a24eb52a3a47c..17958303103a0 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionConvert.h +++ b/GPU/GPUTracking/Base/GPUReconstructionConvert.h @@ -19,6 +19,7 @@ #include #include #include "GPUDef.h" +#include "DataFormatsTPC/Constants.h" namespace o2 { @@ -41,15 +42,15 @@ namespace o2::gpu { struct GPUParam; struct GPUTPCClusterData; -class TPCFastTransform; +class TPCFastTransformPOD; struct GPUTrackingInOutDigits; struct GPUTrackingInOutZS; class GPUReconstructionConvert { public: - constexpr static uint32_t NSECTORS = GPUCA_NSECTORS; - static void ConvertNativeToClusterData(o2::tpc::ClusterNativeAccess* native, std::unique_ptr* clusters, uint32_t* nClusters, const TPCFastTransform* transform, int32_t continuousMaxTimeBin = 0); + constexpr static uint32_t NSECTORS = o2::tpc::constants::MAXSECTOR; + static void ConvertNativeToClusterData(o2::tpc::ClusterNativeAccess* native, std::unique_ptr* clusters, uint32_t* nClusters, const TPCFastTransformPOD* transform, int32_t continuousMaxTimeBin = 0); static void ConvertRun2RawToNative(o2::tpc::ClusterNativeAccess& native, std::unique_ptr& nativeBuffer, const AliHLTTPCRawCluster** rawClusters, uint32_t* nRawClusters); template static void RunZSEncoder(const S& in, std::unique_ptr* outBuffer, uint32_t* outSizes, o2::raw::RawFileWriter* raw, const o2::InteractionRecord* ir, const GPUParam& param, int32_t version, bool verify, float threshold = 0.f, bool padding = false, std::function&)> digitsFilter = nullptr); diff --git a/GPU/GPUTracking/Base/GPUReconstructionDeviceBase.cxx b/GPU/GPUTracking/Base/GPUReconstructionDeviceBase.cxx index 9962bdf3922c1..dba1e85aad3d6 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionDeviceBase.cxx +++ b/GPU/GPUTracking/Base/GPUReconstructionDeviceBase.cxx @@ -98,8 +98,8 @@ int32_t GPUReconstructionDeviceBase::InitDevice() GPUError("Individual memory allocation strategy unsupported for device\n"); return (1); } - if (GetProcessingSettings().nStreams > GPUCA_MAX_STREAMS) { - GPUError("Too many straems requested %d > %d\n", GetProcessingSettings().nStreams, GPUCA_MAX_STREAMS); + if ((size_t)GetProcessingSettings().nStreams > constants::GPU_MAX_STREAMS) { + GPUError("Too many straems requested %d > %d\n", GetProcessingSettings().nStreams, constants::GPU_MAX_STREAMS); return (1); } diff --git a/GPU/GPUTracking/Base/GPUReconstructionIO.h b/GPU/GPUTracking/Base/GPUReconstructionIO.h index 810ebfffe1703..90edefc7a9fd4 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionIO.h +++ b/GPU/GPUTracking/Base/GPUReconstructionIO.h @@ -41,7 +41,7 @@ inline T* GPUReconstruction::AllocateIOMemoryHelper(size_t n, const T*& ptr, std retVal = u.get(); if (GetProcessingSettings().registerStandaloneInputMemory) { if (registerMemoryForGPU(u.get(), n * sizeof(T))) { - GPUError("Error registering memory for GPU: %p - %ld bytes\n", (void*)u.get(), (int64_t)(n * sizeof(T))); + GPUError("Error registering memory for GPU: %p - %zu bytes\n", (void*)u.get(), n * sizeof(T)); throw std::bad_alloc(); } } @@ -69,7 +69,7 @@ inline uint32_t GPUReconstruction::DumpData(FILE* fp, const T* const* entries, c } } if (GetProcessingSettings().debugLevel >= 2) { - GPUInfo("Dumped %ld %s", (int64_t)numTotal, IOTYPENAMES[type]); + GPUInfo("Dumped %zu %s", numTotal, IOTYPENAMES[type]); } return numTotal; } @@ -103,7 +103,7 @@ inline size_t GPUReconstruction::ReadData(FILE* fp, const T** entries, S* num, s } (void)r; if (GetProcessingSettings().debugLevel >= 2) { - GPUInfo("Read %ld %s", (int64_t)numTotal, IOTYPENAMES[type]); + GPUInfo("Read %zu %s", numTotal, IOTYPENAMES[type]); } return numTotal; } @@ -133,7 +133,7 @@ inline std::unique_ptr GPUReconstruction::ReadFlatObjectFromFile(const char* r = fread(size, sizeof(size[0]), 2, fp); if (r == 0 || size[0] != sizeof(T)) { fclose(fp); - GPUError("ERROR reading %s, invalid size: %ld (%ld expected)", file, (int64_t)size[0], (int64_t)sizeof(T)); + GPUError("ERROR reading %s, invalid size: %zu (%zu expected)", file, size[0], sizeof(T)); throw std::runtime_error("invalid size"); } std::unique_ptr retVal(new T); @@ -143,7 +143,7 @@ inline std::unique_ptr GPUReconstruction::ReadFlatObjectFromFile(const char* r = fread(buf, 1, size[1], fp); fclose(fp); if (GetProcessingSettings().debugLevel >= 2) { - GPUInfo("Read %ld bytes from %s", (int64_t)r, file); + GPUInfo("Read %zu bytes from %s", r, file); } retVal->clearInternalBufferPtr(); retVal->setActualBufferAddress(buf); @@ -165,47 +165,95 @@ inline void GPUReconstruction::DumpStructToFile(const T* obj, const char* file) } template -inline std::unique_ptr GPUReconstruction::ReadStructFromFile(const char* file) +inline std::unique_ptr GPUReconstruction::ReadStructFromFile(const char* file, T* obj, bool* errorOnMissing) { FILE* fp = fopen(file, "rb"); if (fp == nullptr) { + if (errorOnMissing) { + *errorOnMissing = true; + } return nullptr; } size_t size, r; r = fread(&size, sizeof(size), 1, fp); if (r == 0 || size != sizeof(T)) { fclose(fp); - GPUError("ERROR reading %s, invalid size: %ld (%ld expected)", file, (int64_t)size, (int64_t)sizeof(T)); + GPUError("ERROR reading %s, invalid size: %zu (%zu expected)", file, size, sizeof(T)); throw std::runtime_error("invalid size"); } - std::unique_ptr newObj(new T); - r = fread(newObj.get(), 1, size, fp); + std::unique_ptr retVal(nullptr); + if (obj == nullptr) { + retVal = std::make_unique(); + obj = retVal.get(); + } + r = fread(obj, 1, size, fp); fclose(fp); + if (r != size) { + GPUError("ERROR reading %s, read %zu (%zu expected)", file, r, size); + throw std::runtime_error("invalid size"); + } if (GetProcessingSettings().debugLevel >= 2) { - GPUInfo("Read %ld bytes from %s", (int64_t)r, file); + GPUInfo("Read %zu bytes from %s", r, file); } - return newObj; + if (errorOnMissing) { + *errorOnMissing = false; + } + return retVal; } template -inline int32_t GPUReconstruction::ReadStructFromFile(const char* file, T* obj) +inline void GPUReconstruction::DumpDynamicStructToFile(const T* obj, size_t dynamicSize, const char* file) +{ + FILE* fp = fopen(file, "w+b"); + if (fp == nullptr) { + return; + } + size_t size = sizeof(*obj); + fwrite(&size, sizeof(size), 1, fp); + fwrite(&dynamicSize, sizeof(dynamicSize), 1, fp); + fwrite(obj, 1, dynamicSize, fp); + fclose(fp); +} + +template +inline aligned_unique_buffer_ptr GPUReconstruction::ReadDynamicStructFromFile(const char* file) { FILE* fp = fopen(file, "rb"); if (fp == nullptr) { - return 1; + return nullptr; } - size_t size, r; + size_t size, dynsize, r, r2; r = fread(&size, sizeof(size), 1, fp); + r2 = fread(&dynsize, sizeof(dynsize), 1, fp); + if (r == 0 || r2 == 0 || size != sizeof(T) || dynsize < size) { + fclose(fp); + GPUError("ERROR reading %s, invalid size: %zu (%zu buffer size, %zu object size expected)", file, size, dynsize, sizeof(T)); + throw std::runtime_error("invalid size"); + } + std::unique_ptr tmp = std::make_unique(); + r = fread(tmp.get(), sizeof(T), 1, fp); if (r == 0) { fclose(fp); - return 1; + GPUError("ERROR reading %s %zu (%zu expected)", file, size, sizeof(T)); + throw std::runtime_error("read error"); } - r = fread(obj, 1, size, fp); + if ((tmp.get()->*F)() != dynsize) { + fclose(fp); + GPUError("ERROR in %s: invalid size: %zu (%zu expected)", file, dynsize, (tmp.get()->*F)()); + throw std::runtime_error("invalid size"); + } + aligned_unique_buffer_ptr newObj(dynsize); + memcpy(newObj.get(), tmp.get(), sizeof(T)); + r = fread(newObj.getraw() + sizeof(T), 1, dynsize - sizeof(T), fp); fclose(fp); + if (r != dynsize - sizeof(T)) { + GPUError("ERROR in %s: File Read error in %s: %zu (%zu expected)", file, r, dynsize); + throw std::runtime_error("invalid size"); + } if (GetProcessingSettings().debugLevel >= 2) { - GPUInfo("Read %ld bytes from %s", (int64_t)r, file); + GPUInfo("Read %zu bytes from %s", r + dynsize, file); } - return 0; + return newObj; } } // namespace o2::gpu diff --git a/GPU/GPUTracking/Base/GPUReconstructionProcessing.h b/GPU/GPUTracking/Base/GPUReconstructionProcessing.h index f582610b57973..746ecdf083691 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionProcessing.h +++ b/GPU/GPUTracking/Base/GPUReconstructionProcessing.h @@ -249,7 +249,7 @@ HighResTimer& GPUReconstructionProcessing::getTimer(const char* name, int32_t nu static int32_t id = getNextTimerId(); timerMeta* timer = getTimerById(id); if (timer == nullptr) { - int32_t max = std::max({mMaxHostThreads, GPUCA_MAX_STREAMS}); + int32_t max = std::max({mMaxHostThreads, constants::GPU_MAX_STREAMS}); timer = insertTimer(id, name, J, max, 1, RecoStep::NoRecoStep); } if (num == -1) { diff --git a/GPU/GPUTracking/Base/GPUReconstructionTimeframe.cxx b/GPU/GPUTracking/Base/GPUReconstructionTimeframe.cxx index fefcd0ac925fe..4570d4da5d000 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionTimeframe.cxx +++ b/GPU/GPUTracking/Base/GPUReconstructionTimeframe.cxx @@ -22,8 +22,7 @@ #include "GPUTPCMCInfo.h" #include "GPUTPCClusterData.h" #include "AliHLTTPCRawCluster.h" -#include "TPCFastTransform.h" -#include "CorrectionMapsHelper.h" +#include "TPCFastTransformPOD.h" #include "GPUO2DataTypes.h" #include "GPUSettings.h" @@ -45,7 +44,7 @@ GPUReconstructionTimeframe::GPUReconstructionTimeframe(GPUChainTracking* chain, mMaxBunchesFull = TIME_ORBIT / config.bunchSpacing; mMaxBunches = (TIME_ORBIT - config.abortGapTime) / config.bunchSpacing; - if (config.overlayRaw && chain->GetTPCTransformHelper() == nullptr) { + if (config.overlayRaw && chain->GetTPCTransform() == nullptr) { GPUInfo("Overlay Raw Events requires TPC Fast Transform"); throw std::exception(); } @@ -72,7 +71,7 @@ int32_t GPUReconstructionTimeframe::ReadEventShifted(int32_t iEvent, float shift { mReadEvent(iEvent); if (config.overlayRaw) { - float shiftTTotal = (((double)config.timeFrameLen - DRIFT_TIME) * ((double)TPCZ / (double)DRIFT_TIME) - shiftZ) / mChain->GetTPCTransformHelper()->getCorrMap()->getVDrift(); + float shiftTTotal = (((double)config.timeFrameLen - DRIFT_TIME) * ((double)TPCZ / (double)DRIFT_TIME) - shiftZ) / mChain->GetTPCTransform()->getVDrift(); for (uint32_t iSector = 0; iSector < NSECTORS; iSector++) { for (uint32_t j = 0; j < mChain->mIOPtrs.nRawClusters[iSector]; j++) { auto& tmp = mChain->mIOMem.rawClusters[iSector][j]; diff --git a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu index c919581eefdde..308c9e29be2b7 100644 --- a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu +++ b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu @@ -270,12 +270,12 @@ int32_t GPUReconstructionCUDA::InitDevice_Runtime() #endif #ifndef __HIPCC__ // CUDA - if (GPUChkErrI(cudaDeviceSetLimit(cudaLimitStackSize, GPUCA_GPU_STACK_SIZE))) { + if (GPUChkErrI(cudaDeviceSetLimit(cudaLimitStackSize, constants::GPU_STACK_SIZE))) { GPUError("Error setting CUDA stack size"); GPUChkErrI(cudaDeviceReset()); return (1); } - if (GPUChkErrI(cudaDeviceSetLimit(cudaLimitMallocHeapSize, GetProcessingSettings().deterministicGPUReconstruction ? std::max(1024 * 1024 * 1024, GPUCA_GPU_HEAP_SIZE) : GPUCA_GPU_HEAP_SIZE))) { + if (GPUChkErrI(cudaDeviceSetLimit(cudaLimitMallocHeapSize, GetProcessingSettings().deterministicGPUReconstruction ? std::max(1024 * 1024 * 1024, constants::GPU_HEAP_SIZE) : constants::GPU_HEAP_SIZE))) { GPUError("Error setting CUDA stack size"); GPUChkErrI(cudaDeviceReset()); return (1); @@ -374,7 +374,7 @@ int32_t GPUReconstructionCUDA::InitDevice_Runtime() #endif mDeviceConstantMem = (GPUConstantMem*)devPtrConstantMem; - GPUInfo("CUDA Initialisation successfull (Device %d: %s (Frequency %d, Cores %d), %ld / %ld bytes host / global memory, Stack frame %d, Constant memory %ld)", mDeviceId, deviceProp.name, deviceClockRate, deviceProp.multiProcessorCount, (int64_t)mHostMemorySize, (int64_t)mDeviceMemorySize, (int32_t)GPUCA_GPU_STACK_SIZE, (int64_t)gGPUConstantMemBufferSize); + GPUInfo("CUDA Initialisation successfull (Device %d: %s (Frequency %d, Cores %d), %ld / %ld bytes host / global memory, Stack frame %d, Constant memory %ld)", mDeviceId, deviceProp.name, deviceClockRate, deviceProp.multiProcessorCount, (int64_t)mHostMemorySize, (int64_t)mDeviceMemorySize, (int32_t)constants::GPU_STACK_SIZE, (int64_t)gGPUConstantMemBufferSize); } else { GPUReconstructionCUDA* master = dynamic_cast(mMaster); mDeviceId = master->mDeviceId; diff --git a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAInternals.h b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAInternals.h index 493c09e448e5e..8ce21652247fc 100644 --- a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAInternals.h +++ b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAInternals.h @@ -30,7 +30,7 @@ namespace o2::gpu struct GPUReconstructionCUDAInternals { std::vector> kernelModules; // module for RTC compilation std::vector> kernelFunctions; // vector of ptrs to RTC kernels - cudaStream_t Streams[GPUCA_MAX_STREAMS]; // Pointer to array of CUDA Streams + cudaStream_t Streams[constants::GPU_MAX_STREAMS]; // Pointer to array of CUDA Streams static void getArgPtrs(const void** pArgs) {} template diff --git a/GPU/GPUTracking/Base/opencl/GPUReconstructionOCLIncludesHost.h b/GPU/GPUTracking/Base/opencl/GPUReconstructionOCLIncludesHost.h index 919791948d6c3..ed0234f273338 100644 --- a/GPU/GPUTracking/Base/opencl/GPUReconstructionOCLIncludesHost.h +++ b/GPU/GPUTracking/Base/opencl/GPUReconstructionOCLIncludesHost.h @@ -43,7 +43,7 @@ struct GPUReconstructionOCLInternals { cl_platform_id platform; cl_device_id device; cl_context context; - cl_command_queue command_queue[GPUCA_MAX_STREAMS]; + cl_command_queue command_queue[constants::GPU_MAX_STREAMS]; cl_mem mem_gpu; cl_mem mem_constant; cl_mem mem_host; diff --git a/GPU/GPUTracking/CMakeLists.txt b/GPU/GPUTracking/CMakeLists.txt index c276bf59af40b..47e4bd2cc1b25 100644 --- a/GPU/GPUTracking/CMakeLists.txt +++ b/GPU/GPUTracking/CMakeLists.txt @@ -355,7 +355,7 @@ if(ALIGPU_BUILD_TYPE STREQUAL "O2") O2::TPCFastTransformation PRIVATE_LINK_LIBRARIES O2::DataFormatsTPC SOURCES ${SRCS_DATATYPES}) - target_compile_definitions(${targetName} PRIVATE GPUCA_O2_LIB GPUCA_TPC_GEOMETRY_O2) + target_compile_definitions(${targetName} PRIVATE GPUCA_O2_LIB) o2_target_root_dictionary(GPUDataTypes HEADERS ${HDRS_CINT_DATATYPES} ${HDRS_CINT_O2_ADDITIONAL} @@ -384,7 +384,7 @@ if(ALIGPU_BUILD_TYPE STREQUAL "O2") ${targetName} PRIVATE $) - target_compile_definitions(${targetName} PRIVATE GPUCA_O2_LIB GPUCA_TPC_GEOMETRY_O2) + target_compile_definitions(${targetName} PRIVATE GPUCA_O2_LIB) o2_target_root_dictionary(${MODULE} HEADERS ${HDRS_CINT_O2} ${HDRS_CINT_O2_ADDITIONAL} diff --git a/GPU/GPUTracking/DataCompression/GPUTPCClusterStatistics.cxx b/GPU/GPUTracking/DataCompression/GPUTPCClusterStatistics.cxx index b11a3b13d7132..d51d306acb827 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCClusterStatistics.cxx +++ b/GPU/GPUTracking/DataCompression/GPUTPCClusterStatistics.cxx @@ -117,7 +117,7 @@ void GPUTPCClusterStatistics::RunStatistics(const o2::tpc::ClusterNativeAccess* std::vector tmpClusters; if (param.rec.tpc.rejectionStrategy == GPUSettings::RejectionNone) { // verification does not make sense if we reject clusters during compression for (uint32_t i = 0; i < NSECTORS; i++) { - for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) { + for (uint32_t j = 0; j < GPUTPCGeometry::NROWS; j++) { if (clustersNative->nClusters[i][j] != clustersNativeDecoded.nClusters[i][j]) { GPUError("Number of clusters mismatch sector %u row %u: expected %d v.s. decoded %d", i, j, clustersNative->nClusters[i][j], clustersNativeDecoded.nClusters[i][j]); decodingErrors++; @@ -181,7 +181,7 @@ void GPUTPCClusterStatistics::RunStatistics(const o2::tpc::ClusterNativeAccess* FillStatisticCombined(mPsigmaU, clustersCompressed->sigmaPadU, clustersCompressed->sigmaTimeU, clustersCompressed->nUnattachedClusters, P_MAX_SIGMA); FillStatisticCombined(mPQA, clustersCompressed->qMaxA, clustersCompressed->qTotA, clustersCompressed->nAttachedClusters, P_MAX_QMAX); FillStatisticCombined(mPQU, clustersCompressed->qMaxU, clustersCompressed->qTotU, clustersCompressed->nUnattachedClusters, P_MAX_QMAX); - FillStatisticCombined(mProwSectorA, clustersCompressed->rowDiffA, clustersCompressed->sliceLegDiffA, clustersCompressed->nAttachedClustersReduced, GPUCA_ROW_COUNT); + FillStatisticCombined(mProwSectorA, clustersCompressed->rowDiffA, clustersCompressed->sliceLegDiffA, clustersCompressed->nAttachedClustersReduced, GPUTPCGeometry::NROWS); mNTotalClusters += clustersCompressed->nAttachedClusters + clustersCompressed->nUnattachedClusters; } diff --git a/GPU/GPUTracking/DataCompression/GPUTPCClusterStatistics.h b/GPU/GPUTracking/DataCompression/GPUTPCClusterStatistics.h index 1dfb958750bef..4efaa7f33257c 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCClusterStatistics.h +++ b/GPU/GPUTracking/DataCompression/GPUTPCClusterStatistics.h @@ -29,7 +29,7 @@ namespace o2::gpu class GPUTPCClusterStatistics { public: - static constexpr uint32_t NSECTORS = GPUCA_NSECTORS; + static constexpr uint32_t NSECTORS = GPUTPCGeometry::NSECTORS; void RunStatistics(const o2::tpc::ClusterNativeAccess* clustersNative, const o2::tpc::CompressedClusters* clustersCompressed, const GPUParam& param); void Finish(); @@ -54,15 +54,15 @@ class GPUTPCClusterStatistics std::vector mPqTotA = std::vector(P_MAX_QTOT, 0); std::vector mPqMaxA = std::vector(P_MAX_QMAX, 0); std::vector mPflagsA = std::vector(P_MAX_FLAGS, 0); - std::vector mProwDiffA = std::vector(GPUCA_ROW_COUNT, 0); - std::vector mPsectorLegDiffA = std::vector(GPUCA_NSECTORS * 2, 0); + std::vector mProwDiffA = std::vector(GPUTPCGeometry::NROWS, 0); + std::vector mPsectorLegDiffA = std::vector(GPUTPCGeometry::NSECTORS * 2, 0); std::vector mPpadResA = std::vector(P_MAX_PAD, 0); std::vector mPtimeResA = std::vector(P_MAX_TIME, 0); std::vector mPsigmaPadA = std::vector(P_MAX_SIGMA, 0); std::vector mPsigmaTimeA = std::vector(P_MAX_SIGMA, 0); std::vector mPqPtA = std::vector(P_MAX_QPT, 0); - std::vector mProwA = std::vector(GPUCA_ROW_COUNT, 0); - std::vector mPsectorA = std::vector(GPUCA_NSECTORS, 0); + std::vector mProwA = std::vector(GPUTPCGeometry::NROWS, 0); + std::vector mPsectorA = std::vector(GPUTPCGeometry::NSECTORS, 0); std::vector mPtimeA = std::vector(P_MAX_TIME, 0); std::vector mPpadA = std::vector(P_MAX_PAD, 0); std::vector mPqTotU = std::vector(P_MAX_QTOT, 0); @@ -78,7 +78,7 @@ class GPUTPCClusterStatistics std::vector mPsigmaA = std::vector(P_MAX_SIGMA * P_MAX_SIGMA, 0); std::vector mPQU = std::vector(P_MAX_QMAX * P_MAX_QTOT, 0); std::vector mPQA = std::vector(P_MAX_QMAX * P_MAX_QTOT, 0); - std::vector mProwSectorA = std::vector(GPUCA_ROW_COUNT * GPUCA_NSECTORS * 2, 0); + std::vector mProwSectorA = std::vector(GPUTPCGeometry::NROWS * GPUTPCGeometry::NSECTORS * 2, 0); double mEntropy = 0; double mHuffman = 0; diff --git a/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx b/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx index efb7a4af3f323..00f1f6500e9f0 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx +++ b/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx @@ -69,7 +69,7 @@ void GPUTPCCompression::SetPointersCompressedClusters(void*& mem, T& c, uint32_t computePointerWithAlignment(mem, c.timeDiffU, nClU); computePointerWithAlignment(mem, c.sigmaPadU, nClU); computePointerWithAlignment(mem, c.sigmaTimeU, nClU); - computePointerWithAlignment(mem, c.nSliceRowClusters, GPUCA_ROW_COUNT * NSECTORS); + computePointerWithAlignment(mem, c.nSliceRowClusters, GPUTPCGeometry::NROWS * NSECTORS); uint32_t nClAreduced = reducedClA ? nClA - nTr : nClA; @@ -139,8 +139,8 @@ void GPUTPCCompression::DumpCompressedClusters(std::ostream& out) out << "Slice Row Clusters:\n"; for (uint32_t i = 0; i < NSECTORS; i++) { out << "Sector " << i << ": "; - for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) { - out << (O.nSliceRowClusters ? O.nSliceRowClusters[i * GPUCA_ROW_COUNT + j] : 0) << ", "; + for (uint32_t j = 0; j < GPUTPCGeometry::NROWS; j++) { + out << (O.nSliceRowClusters ? O.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j] : 0) << ", "; } out << "\n"; } @@ -155,16 +155,16 @@ void GPUTPCCompression::DumpCompressedClusters(std::ostream& out) uint32_t offset = 0; if (O.nSliceRowClusters) { for (uint32_t i = 0; i < NSECTORS; i++) { - for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) { + for (uint32_t j = 0; j < GPUTPCGeometry::NROWS; j++) { out << "Sector " << i << " Row " << j << ": "; - for (uint32_t k = 0; k < O.nSliceRowClusters[i * GPUCA_ROW_COUNT + j]; k++) { + for (uint32_t k = 0; k < O.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]; k++) { if (k && k % 10 == 0) { out << "\n "; } const uint32_t l = k + offset; out << "[" << (uint32_t)O.qTotU[l] << ", " << (uint32_t)O.qMaxU[l] << ", " << (uint32_t)O.flagsU[l] << ", " << (int32_t)O.padDiffU[l] << ", " << (int32_t)O.timeDiffU[l] << ", " << (uint32_t)O.sigmaPadU[l] << ", " << (uint32_t)O.sigmaTimeU[l] << "] "; } - offset += O.nSliceRowClusters[i * GPUCA_ROW_COUNT + j]; + offset += O.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]; out << "\n"; } } diff --git a/GPU/GPUTracking/DataCompression/GPUTPCCompression.h b/GPU/GPUTracking/DataCompression/GPUTPCCompression.h index 95173dad7257f..82e44eda6f3cc 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCCompression.h +++ b/GPU/GPUTracking/DataCompression/GPUTPCCompression.h @@ -20,6 +20,7 @@ #include "GPUCommonMath.h" #include "GPUParam.h" #include "DataFormatsTPC/CompressedClusters.h" +#include "GPUTPCGeometry.h" namespace o2::gpu { @@ -69,7 +70,7 @@ class GPUTPCCompression : public GPUProcessor uint32_t nStoredUnattachedClusters = 0; }; - constexpr static uint32_t NSECTORS = GPUCA_NSECTORS; + constexpr static uint32_t NSECTORS = GPUTPCGeometry::NSECTORS; o2::tpc::CompressedClustersPtrs mPtrs; o2::tpc::CompressedClusters* mOutput = nullptr; diff --git a/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.cxx b/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.cxx index 1cd44e221f203..abf94746f5a72 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.cxx +++ b/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.cxx @@ -73,7 +73,7 @@ GPUdii() void GPUTPCCompressionKernels::Thread row) { - row += GPUCA_ROW_COUNT; + row += GPUTPCGeometry::NROWS; } row -= lastRow; if (lastSector > sector) { @@ -112,7 +112,7 @@ GPUdii() void GPUTPCCompressionKernels::ThreadclusterOffset[iSector][iRow]; const uint32_t idOffsetOut = clusters->clusterOffset[iSector][iRow] * compressor.mMaxClusterFactorBase1024 / 1024; // 32 bit enough for number of clusters per row * 1024 const uint32_t idOffsetOutMax = ((const uint32_t*)clusters->clusterOffset[iSector])[iRow + 1] * compressor.mMaxClusterFactorBase1024 / 1024; // Array out of bounds access is ok, since it goes to the correct nClustersTotal @@ -244,10 +244,10 @@ GPUdii() void GPUTPCCompressionKernels::Thread idOffsetOutMax) { if (iThread == nThreads - 1) { compressor.raiseError(GPUErrors::ERROR_COMPRESSION_ROW_HIT_OVERFLOW, iSector * 1000 + iRow, idOffsetOut + totalCount + count, idOffsetOutMax); @@ -269,7 +269,7 @@ GPUdii() void GPUTPCCompressionKernels::Thread(clusters->clusters[iSector][iRow])); @@ -321,7 +321,7 @@ GPUdii() void GPUTPCCompressionKernels::ThreadnStoredUnattachedClusters, totalCount); } GPUbarrier(); @@ -547,7 +547,7 @@ GPUdii() void GPUTPCCompressionGatherKernels::ThreadnSliceRowClusters, compressor.mPtrs.nSliceRowClusters, compressor.NSECTORS * GPUCA_ROW_COUNT, nThreads, iThread); + compressorMemcpy(compressor.mOutput->nSliceRowClusters, compressor.mPtrs.nSliceRowClusters, compressor.NSECTORS * GPUTPCGeometry::NROWS, nThreads, iThread); compressorMemcpy(compressor.mOutput->nTrackClusters, compressor.mPtrs.nTrackClusters, compressor.mMemory->nStoredTracks, nThreads, iThread); compressorMemcpy(compressor.mOutput->qPtA, compressor.mPtrs.qPtA, compressor.mMemory->nStoredTracks, nThreads, iThread); compressorMemcpy(compressor.mOutput->rowA, compressor.mPtrs.rowA, compressor.mMemory->nStoredTracks, nThreads, iThread); @@ -566,15 +566,15 @@ GPUdii() void GPUTPCCompressionGatherKernels::ThreadtimeA, compressor.mPtrs.timeA, compressor.mMemory->nStoredTracks, nThreads, iThread); compressorMemcpy(compressor.mOutput->padA, compressor.mPtrs.padA, compressor.mMemory->nStoredTracks, nThreads, iThread); - uint32_t sectorStart = rowStart / GPUCA_ROW_COUNT; - uint32_t sectorEnd = rowEnd / GPUCA_ROW_COUNT; + uint32_t sectorStart = rowStart / GPUTPCGeometry::NROWS; + uint32_t sectorEnd = rowEnd / GPUTPCGeometry::NROWS; - uint32_t sectorRowStart = rowStart % GPUCA_ROW_COUNT; - uint32_t sectorRowEnd = rowEnd % GPUCA_ROW_COUNT; + uint32_t sectorRowStart = rowStart % GPUTPCGeometry::NROWS; + uint32_t sectorRowEnd = rowEnd % GPUTPCGeometry::NROWS; for (uint32_t i = sectorStart; i <= sectorEnd && i < compressor.NSECTORS; i++) { - for (uint32_t j = ((i == sectorStart) ? sectorRowStart : 0); j < ((i == sectorEnd) ? sectorRowEnd : GPUCA_ROW_COUNT); j++) { - uint32_t nClusters = compressor.mPtrs.nSliceRowClusters[i * GPUCA_ROW_COUNT + j]; + for (uint32_t j = ((i == sectorStart) ? sectorRowStart : 0); j < ((i == sectorEnd) ? sectorRowEnd : GPUTPCGeometry::NROWS); j++) { + uint32_t nClusters = compressor.mPtrs.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]; uint32_t clusterOffsetInCache = clusters->clusterOffset[i][j] * compressor.mMaxClusterFactorBase1024 / 1024; compressorMemcpy(compressor.mOutput->qTotU + rowsOffset, compressor.mPtrs.qTotU + clusterOffsetInCache, nClusters, nLanes, iLane); compressorMemcpy(compressor.mOutput->qMaxU + rowsOffset, compressor.mPtrs.qMaxU + clusterOffsetInCache, nClusters, nLanes, iLane); @@ -653,7 +653,7 @@ GPUdii() void GPUTPCCompressionGatherKernels::gatherBuffered(int32_t nBlocks, in auto& input = compressor.mPtrs; auto* output = compressor.mOutput; - uint32_t nRows = compressor.NSECTORS * GPUCA_ROW_COUNT; + uint32_t nRows = compressor.NSECTORS * GPUTPCGeometry::NROWS; uint32_t rowsPerWarp = (nRows + nGlobalWarps - 1) / nGlobalWarps; uint32_t rowStart = rowsPerWarp * iGlobalWarp; uint32_t rowEnd = CAMath::Min(nRows, rowStart + rowsPerWarp); @@ -678,7 +678,7 @@ GPUdii() void GPUTPCCompressionGatherKernels::gatherBuffered(int32_t nBlocks, in uint32_t tracksOffset = calculateWarpOffsets(smem, input.nTrackClusters, trackStart, trackEnd, nWarps, iWarp, nLanes, iLane); if (iBlock == 0) { - compressorMemcpyBasic(output->nSliceRowClusters, input.nSliceRowClusters, compressor.NSECTORS * GPUCA_ROW_COUNT, nThreads, iThread); + compressorMemcpyBasic(output->nSliceRowClusters, input.nSliceRowClusters, compressor.NSECTORS * GPUTPCGeometry::NROWS, nThreads, iThread); compressorMemcpyBasic(output->nTrackClusters, input.nTrackClusters, compressor.mMemory->nStoredTracks, nThreads, iThread); compressorMemcpyBasic(output->qPtA, input.qPtA, compressor.mMemory->nStoredTracks, nThreads, iThread); compressorMemcpyBasic(output->rowA, input.rowA, compressor.mMemory->nStoredTracks, nThreads, iThread); @@ -731,7 +731,7 @@ GPUdii() void GPUTPCCompressionGatherKernels::gatherMulti(int32_t nBlocks, int32 auto* buf = smem.getBuffer(iWarp); if (iBlock == 0) { - compressorMemcpyBasic(output->nSliceRowClusters, input.nSliceRowClusters, compressor.NSECTORS * GPUCA_ROW_COUNT, nThreads, iThread); + compressorMemcpyBasic(output->nSliceRowClusters, input.nSliceRowClusters, compressor.NSECTORS * GPUTPCGeometry::NROWS, nThreads, iThread); compressorMemcpyBasic(output->nTrackClusters, input.nTrackClusters, compressor.mMemory->nStoredTracks, nThreads, iThread); compressorMemcpyBasic(output->qPtA, input.qPtA, compressor.mMemory->nStoredTracks, nThreads, iThread); compressorMemcpyBasic(output->rowA, input.rowA, compressor.mMemory->nStoredTracks, nThreads, iThread); @@ -742,7 +742,7 @@ GPUdii() void GPUTPCCompressionGatherKernels::gatherMulti(int32_t nBlocks, int32 const uint32_t nGlobalWarps = nWarps * (nBlocks - 1) / 2; const uint32_t iGlobalWarp = nWarps * (iBlock - 1) / 2 + iWarp; - const uint32_t nRows = compressor.NSECTORS * GPUCA_ROW_COUNT; + const uint32_t nRows = compressor.NSECTORS * GPUTPCGeometry::NROWS; uint32_t rowsPerWarp = (nRows + nGlobalWarps - 1) / nGlobalWarps; uint32_t rowStart = rowsPerWarp * iGlobalWarp; uint32_t rowEnd = CAMath::Min(nRows, rowStart + rowsPerWarp); diff --git a/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.h b/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.h index 2236f15af9725..1edf718de8128 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.h +++ b/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.h @@ -37,7 +37,7 @@ class GPUTPCCompressionKernels : public GPUKernelTemplate struct GPUSharedMemory : public GPUKernelTemplate::GPUSharedMemoryScan64 { GPUAtomic(uint32_t) nCount; uint32_t lastIndex; - uint32_t sortBuffer[GPUCA_TPC_COMP_CHUNK_SIZE]; + uint32_t sortBuffer[constants::TPC_COMP_CHUNK_SIZE]; }; template diff --git a/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.cxx b/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.cxx index ab7b0c99e09df..1fe22e0e88137 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.cxx +++ b/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.cxx @@ -26,7 +26,7 @@ using namespace o2::gpu; GPUd() void GPUTPCCompressionTrackModel::Init(float x, float y, float z, float alpha, uint8_t qPt, const GPUParam& GPUrestrict() param) { mProp.SetMaterialTPC(); - mProp.SetMaxSinPhi(GPUCA_MAX_SIN_PHI); + mProp.SetMaxSinPhi(constants::MAX_SIN_PHI); mProp.SetSeedingErrors(true); // Larger errors for seeds, better since we don't start with good hypothesis mProp.SetFitInProjections(true); mProp.SetPropagateBzOnly(true); @@ -87,10 +87,10 @@ GPUd() void GPUTPCCompressionTrackModel::Init(float x, float y, float z, float a GPUd() int32_t GPUTPCCompressionTrackModel::Propagate(float x, float alpha) { GPUTPCTrackLinearisation t0(mTrk); - if (alpha != mAlpha && !mTrk.Rotate(alpha, t0, GPUCA_MAX_SIN_PHI)) { + if (alpha != mAlpha && !mTrk.Rotate(alpha, t0, constants::MAX_SIN_PHI)) { return 2; } - int32_t retVal = !mTrk.TransportToX(x, t0, mParam->bzCLight, GPUCA_MAX_SIN_PHI); + int32_t retVal = !mTrk.TransportToX(x, t0, mParam->bzCLight, constants::MAX_SIN_PHI); // GPUInfo("Propagated to: x %f y %f z %f alpha %f qPt %f", x, mTrk.Y(), mTrk.Z(), alpha, mTrk.QPt()); return retVal; } @@ -100,7 +100,7 @@ GPUd() int32_t GPUTPCCompressionTrackModel::Filter(float y, float z, int32_t iRo mTrk.ConstrainSinPhi(); float err2Y, err2Z; GPUTPCTracker::GetErrors2Seeding(*mParam, iRow, mTrk, -1.f, err2Y, err2Z); - int32_t retVal = !mTrk.Filter(y, z, err2Y, err2Z, GPUCA_MAX_SIN_PHI, false); + int32_t retVal = !mTrk.Filter(y, z, err2Y, err2Z, constants::MAX_SIN_PHI, false); // GPUInfo("Filtered with %f %f: y %f z %f qPt %f", y, z, mTrk.Y(), mTrk.Z(), mTrk.QPt()); return retVal; } diff --git a/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.h b/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.h index b3b4da27e625b..0021f3331cb2e 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.h +++ b/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.h @@ -20,6 +20,7 @@ // #define GPUCA_COMPRESSION_TRACK_MODEL_SECTORTRACKER #include "GPUDef.h" +#include "DataFormatsTPC/Constants.h" #ifdef GPUCA_COMPRESSION_TRACK_MODEL_MERGER #include "GPUTPCGMPropagator.h" @@ -100,15 +101,15 @@ class GPUTPCCompressionTrackModel GPUd() void getClusterErrors2(int32_t iRow, float z, float sinPhi, float DzDs, float& ErrY2, float& ErrZ2) const; GPUd() void resetCovariance(); - GPUd() float LinearPad2Y(int32_t sector, float pad, float padWidth, uint8_t npads) const + GPUd() float LinearPad2Y(uint32_t sector, float pad, float padWidth, uint8_t npads) const { const float u = (pad - 0.5f * npads) * padWidth; - return (sector >= GPUCA_NSECTORS / 2) ? -u : u; + return (sector >= o2::tpc::constants::MAXSECTOR / 2) ? -u : u; } - GPUd() float LinearY2Pad(int32_t sector, float y, float padWidth, uint8_t npads) const + GPUd() float LinearY2Pad(uint32_t sector, float y, float padWidth, uint8_t npads) const { - const float u = (sector >= GPUCA_NSECTORS / 2) ? -y : y; + const float u = (sector >= o2::tpc::constants::MAXSECTOR / 2) ? -y : y; return u / padWidth + 0.5f * npads; } diff --git a/GPU/GPUTracking/DataCompression/GPUTPCDecompression.cxx b/GPU/GPUTracking/DataCompression/GPUTPCDecompression.cxx index b2949b5a98fd2..e28718e6b6755 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCDecompression.cxx +++ b/GPU/GPUTracking/DataCompression/GPUTPCDecompression.cxx @@ -40,7 +40,7 @@ void GPUTPCDecompression::SetPointersCompressedClusters(void*& mem, T& c, uint32 computePointerWithAlignment(mem, c.timeDiffU, nClU); computePointerWithAlignment(mem, c.sigmaPadU, nClU); computePointerWithAlignment(mem, c.sigmaTimeU, nClU); - computePointerWithAlignment(mem, c.nSliceRowClusters, GPUCA_ROW_COUNT * NSECTORS); + computePointerWithAlignment(mem, c.nSliceRowClusters, GPUTPCGeometry::NROWS * NSECTORS); uint32_t nClAreduced = reducedClA ? nClA - nTr : nClA; @@ -68,19 +68,19 @@ void GPUTPCDecompression::SetPointersCompressedClusters(void*& mem, T& c, uint32 void* GPUTPCDecompression::SetPointersTmpNativeBuffersGPU(void* mem) { - computePointerWithAlignment(mem, mTmpNativeClusters, NSECTORS * GPUCA_ROW_COUNT * mMaxNativeClustersPerBuffer); + computePointerWithAlignment(mem, mTmpNativeClusters, NSECTORS * GPUTPCGeometry::NROWS * mMaxNativeClustersPerBuffer); return mem; } void* GPUTPCDecompression::SetPointersTmpNativeBuffersOutput(void* mem) { - computePointerWithAlignment(mem, mNativeClustersIndex, NSECTORS * GPUCA_ROW_COUNT); + computePointerWithAlignment(mem, mNativeClustersIndex, NSECTORS * GPUTPCGeometry::NROWS); return mem; } void* GPUTPCDecompression::SetPointersTmpNativeBuffersInput(void* mem) { - computePointerWithAlignment(mem, mUnattachedClustersOffsets, NSECTORS * GPUCA_ROW_COUNT); + computePointerWithAlignment(mem, mUnattachedClustersOffsets, NSECTORS * GPUTPCGeometry::NROWS); computePointerWithAlignment(mem, mAttachedClustersOffsets, mInputGPU.nTracks); return mem; } @@ -99,7 +99,7 @@ void* GPUTPCDecompression::SetPointersInputClusterNativeAccess(void* mem) void* GPUTPCDecompression::SetPointersNClusterPerSectorRow(void* mem) { - computePointerWithAlignment(mem, mNClusterPerSectorRow, NSECTORS * GPUCA_ROW_COUNT); + computePointerWithAlignment(mem, mNClusterPerSectorRow, NSECTORS * GPUTPCGeometry::NROWS); return mem; } diff --git a/GPU/GPUTracking/DataCompression/GPUTPCDecompression.h b/GPU/GPUTracking/DataCompression/GPUTPCDecompression.h index e6f8377a246e2..59b1c564bff02 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCDecompression.h +++ b/GPU/GPUTracking/DataCompression/GPUTPCDecompression.h @@ -21,6 +21,7 @@ #include "GPUParam.h" #include "GPUO2DataTypes.h" #include "DataFormatsTPC/CompressedClusters.h" +#include "GPUTPCGeometry.h" namespace o2::gpu { @@ -49,7 +50,7 @@ class GPUTPCDecompression : public GPUProcessor #endif protected: - constexpr static uint32_t NSECTORS = GPUCA_NSECTORS; + constexpr static uint32_t NSECTORS = GPUTPCGeometry::NSECTORS; o2::tpc::CompressedClusters mInputGPU; uint32_t mMaxNativeClustersPerBuffer; diff --git a/GPU/GPUTracking/DataCompression/GPUTPCDecompressionKernels.cxx b/GPU/GPUTracking/DataCompression/GPUTPCDecompressionKernels.cxx index 68e45f0c08c32..0d2140c32e4a9 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCDecompressionKernels.cxx +++ b/GPU/GPUTracking/DataCompression/GPUTPCDecompressionKernels.cxx @@ -45,10 +45,10 @@ GPUdii() void GPUTPCDecompressionKernels::ThreadclusterOffset[iSector][iRow]; if (decompressor.mNativeClustersIndex[linearIndex] != 0) { @@ -105,9 +105,9 @@ GPUdii() void GPUTPCDecompressionUtilKernels::ThreadnClusters[sector][row]; k++) { ClusterNative cl = clusterAccess->clusters[sector][row][k]; if (isClusterKept(cl, param)) { @@ -125,9 +125,9 @@ GPUdii() void GPUTPCDecompressionUtilKernels::ThreadnClusters[sector][row]; k++) { const ClusterNative cl = clusterAccess->clusters[sector][row][k]; @@ -144,9 +144,9 @@ GPUdii() void GPUTPCDecompressionUtilKernels::ThreadclusterOffset[sector][row]; GPUCommonAlgorithm::sort(buffer, buffer + outputAccess->nClusters[sector][row]); } diff --git a/GPU/GPUTracking/DataCompression/GPUTPCDecompressionKernels.h b/GPU/GPUTracking/DataCompression/GPUTPCDecompressionKernels.h index 2140cfbe5166d..03fcfebacdaa9 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCDecompressionKernels.h +++ b/GPU/GPUTracking/DataCompression/GPUTPCDecompressionKernels.h @@ -39,7 +39,7 @@ class GPUTPCDecompressionKernels : public GPUKernelTemplate GPUd() static uint32_t computeLinearTmpBufferIndex(uint32_t sector, uint32_t row, uint32_t maxClustersPerBuffer) { - return sector * (GPUCA_ROW_COUNT * maxClustersPerBuffer) + row * maxClustersPerBuffer; + return sector * (GPUTPCGeometry::NROWS * maxClustersPerBuffer) + row * maxClustersPerBuffer; } template diff --git a/GPU/GPUTracking/DataCompression/TPCClusterDecompressionCore.inc b/GPU/GPUTracking/DataCompression/TPCClusterDecompressionCore.inc index e4de5a503e52d..3089a454c048b 100644 --- a/GPU/GPUTracking/DataCompression/TPCClusterDecompressionCore.inc +++ b/GPU/GPUTracking/DataCompression/TPCClusterDecompressionCore.inc @@ -48,7 +48,7 @@ class TPCClusterDecompressionCore return clusterVector.back(); } - GPUhi() static auto decompressTrackStore(const CompressedClusters& clustersCompressed, const uint32_t offset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, std::vector (&clusters)[GPUCA_NSECTORS][GPUCA_ROW_COUNT], std::atomic_flag (&locks)[GPUCA_NSECTORS][GPUCA_ROW_COUNT]) + GPUhi() static auto decompressTrackStore(const CompressedClusters& clustersCompressed, const uint32_t offset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, std::vector (&clusters)[GPUTPCGeometry::NSECTORS][GPUTPCGeometry::NROWS], std::atomic_flag (&locks)[GPUTPCGeometry::NSECTORS][GPUTPCGeometry::NROWS]) { std::vector& clusterVector = clusters[slice][row]; auto& lock = locks[slice][row]; @@ -62,14 +62,14 @@ class TPCClusterDecompressionCore GPUdi() static ClusterNative decompressTrackStore(const CompressedClusters& cmprClusters, const uint32_t clusterOffset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, GPUTPCDecompression& decompressor) { - uint32_t tmpBufferIndex = slice * (GPUCA_ROW_COUNT * decompressor.mMaxNativeClustersPerBuffer) + row * decompressor.mMaxNativeClustersPerBuffer; - uint32_t currentClusterIndex = CAMath::AtomicAdd(decompressor.mNativeClustersIndex + (slice * GPUCA_ROW_COUNT + row), 1u); + uint32_t tmpBufferIndex = slice * (GPUTPCGeometry::NROWS * decompressor.mMaxNativeClustersPerBuffer) + row * decompressor.mMaxNativeClustersPerBuffer; + uint32_t currentClusterIndex = CAMath::AtomicAdd(decompressor.mNativeClustersIndex + (slice * GPUTPCGeometry::NROWS + row), 1u); const ClusterNative c(time, cmprClusters.flagsA[clusterOffset], pad, cmprClusters.sigmaTimeA[clusterOffset], cmprClusters.sigmaPadA[clusterOffset], cmprClusters.qMaxA[clusterOffset], cmprClusters.qTotA[clusterOffset]); if (currentClusterIndex < decompressor.mMaxNativeClustersPerBuffer) { decompressor.mTmpNativeClusters[tmpBufferIndex + currentClusterIndex] = c; } else { decompressor.raiseError(GPUErrors::ERROR_DECOMPRESSION_ATTACHED_CLUSTER_OVERFLOW, slice * 1000 + row, currentClusterIndex, decompressor.mMaxNativeClustersPerBuffer); - CAMath::AtomicExch(decompressor.mNativeClustersIndex + (slice * GPUCA_ROW_COUNT + row), decompressor.mMaxNativeClustersPerBuffer); + CAMath::AtomicExch(decompressor.mNativeClustersIndex + (slice * GPUTPCGeometry::NROWS + row), decompressor.mMaxNativeClustersPerBuffer); } return c; } @@ -87,18 +87,18 @@ class TPCClusterDecompressionCore uint32_t pad = 0, time = 0; if (clusterIndex != 0) { uint8_t tmpSlice = cmprClusters.sliceLegDiffA[clusterOffset - trackIndex - 1]; - bool changeLeg = (tmpSlice >= GPUCA_NSECTORS); + bool changeLeg = (tmpSlice >= GPUTPCGeometry::NSECTORS); if (changeLeg) { - tmpSlice -= GPUCA_NSECTORS; + tmpSlice -= GPUTPCGeometry::NSECTORS; } if (cmprClusters.nComppressionModes & GPUSettings::CompressionDifferences) { slice += tmpSlice; - if (slice >= GPUCA_NSECTORS) { - slice -= GPUCA_NSECTORS; + if (slice >= GPUTPCGeometry::NSECTORS) { + slice -= GPUTPCGeometry::NSECTORS; } row += cmprClusters.rowDiffA[clusterOffset - trackIndex - 1]; - if (row >= GPUCA_ROW_COUNT) { - row -= GPUCA_ROW_COUNT; + if (row >= GPUTPCGeometry::NROWS) { + row -= GPUTPCGeometry::NROWS; } } else { slice = tmpSlice; @@ -115,7 +115,7 @@ class TPCClusterDecompressionCore timeTmp |= 0xFF000000; } time = timeTmp + ClusterNative::packTime(CAMath::Max(0.f, geo.LinearZ2Time(slice, track.Z() + zOffset))); - float tmpPad = CAMath::Max(0.f, CAMath::Min((float)geo.NPads(GPUCA_ROW_COUNT - 1), track.LinearY2Pad(slice, track.Y(), geo.PadWidth(row), geo.NPads(row)))); + float tmpPad = CAMath::Max(0.f, CAMath::Min((float)geo.NPads(GPUTPCGeometry::NROWS - 1), track.LinearY2Pad(slice, track.Y(), geo.PadWidth(row), geo.NPads(row)))); pad = cmprClusters.padResA[clusterOffset - trackIndex - 1] + ClusterNative::packPad(tmpPad); time = time & 0xFFFFFF; pad = (uint16_t)pad; diff --git a/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.cxx b/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.cxx index 51a896c2baf6a..e28b4c476f815 100644 --- a/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.cxx +++ b/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.cxx @@ -48,12 +48,12 @@ int32_t TPCClusterDecompressor::decompress(const CompressedClusters* clustersCom if (clustersCompressed->nTracks && clustersCompressed->maxTimeBin != -1e6 && clustersCompressed->maxTimeBin != param.continuousMaxTimeBin) { throw std::runtime_error("Configured max time bin " + std::to_string(param.continuousMaxTimeBin) + " does not match value used for track model encoding " + std::to_string(clustersCompressed->maxTimeBin)); } - std::vector clusters[NSECTORS][GPUCA_ROW_COUNT]; - std::atomic_flag locks[NSECTORS][GPUCA_ROW_COUNT]; - for (uint32_t i = 0; i < NSECTORS * GPUCA_ROW_COUNT; i++) { + std::vector clusters[NSECTORS][GPUTPCGeometry::NROWS]; + std::atomic_flag locks[NSECTORS][GPUTPCGeometry::NROWS]; + for (uint32_t i = 0; i < NSECTORS * GPUTPCGeometry::NROWS; i++) { (&locks[0][0])[i].clear(); } - const uint32_t maxTime = param.continuousMaxTimeBin > 0 ? ((param.continuousMaxTimeBin + 1) * ClusterNative::scaleTimePacked - 1) : TPC_MAX_TIME_BIN_TRIGGERED; + const uint32_t maxTime = param.continuousMaxTimeBin > 0 ? ((param.continuousMaxTimeBin + 1) * ClusterNative::scaleTimePacked - 1) : constants::TPC_MAX_TIME_BIN_TRIGGERED; tbb::parallel_for(tbb::blocked_range(0, clustersCompressed->nTracks), [&](const tbb::blocked_range& range) { uint32_t offset = 0, lasti = 0; for (uint32_t i = range.begin(); i < range.end(); i++) { @@ -69,14 +69,14 @@ int32_t TPCClusterDecompressor::decompress(const CompressedClusters* clustersCom }); size_t nTotalClusters = clustersCompressed->nAttachedClusters + clustersCompressed->nUnattachedClusters; ClusterNative* clusterBuffer = allocator(nTotalClusters); - uint32_t offsets[NSECTORS][GPUCA_ROW_COUNT]; + uint32_t offsets[NSECTORS][GPUTPCGeometry::NROWS]; uint32_t offset = 0; uint32_t decodedAttachedClusters = 0; for (uint32_t i = 0; i < NSECTORS; i++) { - for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) { - clustersNative.nClusters[i][j] = clusters[i][j].size() + ((i * GPUCA_ROW_COUNT + j >= clustersCompressed->nSliceRows) ? 0 : clustersCompressed->nSliceRowClusters[i * GPUCA_ROW_COUNT + j]); + for (uint32_t j = 0; j < GPUTPCGeometry::NROWS; j++) { + clustersNative.nClusters[i][j] = clusters[i][j].size() + ((i * GPUTPCGeometry::NROWS + j >= clustersCompressed->nSliceRows) ? 0 : clustersCompressed->nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]); offsets[i][j] = offset; - offset += (i * GPUCA_ROW_COUNT + j >= clustersCompressed->nSliceRows) ? 0 : clustersCompressed->nSliceRowClusters[i * GPUCA_ROW_COUNT + j]; + offset += (i * GPUTPCGeometry::NROWS + j >= clustersCompressed->nSliceRows) ? 0 : clustersCompressed->nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]; decodedAttachedClusters += clusters[i][j].size(); } } @@ -86,13 +86,13 @@ int32_t TPCClusterDecompressor::decompress(const CompressedClusters* clustersCom clustersNative.clustersLinear = clusterBuffer; clustersNative.setOffsetPtrs(); tbb::parallel_for(0, NSECTORS, [&](auto i) { - for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) { + for (uint32_t j = 0; j < GPUTPCGeometry::NROWS; j++) { ClusterNative* buffer = &clusterBuffer[clustersNative.clusterOffset[i][j]]; if (clusters[i][j].size()) { memcpy((void*)buffer, (const void*)clusters[i][j].data(), clusters[i][j].size() * sizeof(clusterBuffer[0])); } ClusterNative* clout = buffer + clusters[i][j].size(); - uint32_t end = offsets[i][j] + ((i * GPUCA_ROW_COUNT + j >= clustersCompressed->nSliceRows) ? 0 : clustersCompressed->nSliceRowClusters[i * GPUCA_ROW_COUNT + j]); + uint32_t end = offsets[i][j] + ((i * GPUTPCGeometry::NROWS + j >= clustersCompressed->nSliceRows) ? 0 : clustersCompressed->nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]); TPCClusterDecompressionCore::decompressHits(*clustersCompressed, offsets[i][j], end, clout); if (param.rec.tpc.clustersEdgeFixDistance > 0.f) { constexpr GPUTPCGeometry geo; diff --git a/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.h b/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.h index 0c54f34c0237a..723a97341a53b 100644 --- a/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.h +++ b/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.h @@ -32,7 +32,7 @@ struct GPUParam; class TPCClusterDecompressor { public: - static constexpr uint32_t NSECTORS = GPUCA_NSECTORS; + static constexpr uint32_t NSECTORS = GPUTPCGeometry::NSECTORS; static int32_t decompress(const o2::tpc::CompressedClustersFlat* clustersCompressed, o2::tpc::ClusterNativeAccess& clustersNative, std::function allocator, const GPUParam& param, bool deterministicRec); static int32_t decompress(const o2::tpc::CompressedClusters* clustersCompressed, o2::tpc::ClusterNativeAccess& clustersNative, std::function allocator, const GPUParam& param, bool deterministicRec); }; diff --git a/GPU/GPUTracking/DataCompression/standalone-cluster-dump-entropy-analysed.cxx b/GPU/GPUTracking/DataCompression/standalone-cluster-dump-entropy-analysed.cxx deleted file mode 100644 index b23d19c3c9cd4..0000000000000 --- a/GPU/GPUTracking/DataCompression/standalone-cluster-dump-entropy-analysed.cxx +++ /dev/null @@ -1,709 +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. - -/// \file standalone-cluster-dump-entropy-analysed.cxx -/// \author David Rohr - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -const int32_t sort_method = 1; // 0 No sorting, 1 sort after pad, 2 sort after time, 3/4 mixed methods favoring pad / time -const int32_t sector_diff = 1; -const int32_t row_diff = 1; -const int32_t pad_diff = 1; -const int32_t time_diff = 1; -const int32_t res_diff = 0; -const int32_t approximate_qtot = 0; -const int32_t combine_maxtot = 1; -const int32_t combine_sigmapadtime = 1; -const int32_t track_based = 1; -const int32_t track_avgtot = track_based && 0; -const int32_t track_avgmax = track_based && 0; -const int32_t track_diffqtot = track_based && 0; -const int32_t track_diffqmax = track_based && 0; -const int32_t track_separate_q = track_based && 1; -const int32_t track_diffsigma = track_based && 0; -const int32_t track_separate_sigma = track_based && 1; -const int32_t truncate_bits = 1; -const int32_t separate_sectors = 0; -const int32_t separate_patches = 0; -const int32_t separate_sides = 0; -const int32_t full_row_numbers = 1; -const int32_t distinguish_rows = 0; -const int32_t optimized_negative_values = 1; - -const int32_t print_clusters = 0; - -const char* file = "clusters-pbpb.dump"; -const int32_t max_clusters = 2000000; - -const int32_t truncate_sigma = 3; -const int32_t truncate_charge = 4; - -const int32_t sort_pad_mixed_bins = 100; -const int32_t sort_time_mixed_bins = 400; - -#define EVENT 0 -#define SECTOR 1 -#define PATCH 2 -#define ROW 3 -#define PAD 4 -#define TIME 5 -#define SIGMA_PAD 6 -#define SIGMA_TIME 7 -#define QMAX 8 -#define QTOT 9 -#define FLAG_PADTIME 10 -#define CLUSTER_ID 11 -#define RES_PAD 12 -#define RES_TIME 13 -#define AVG_TOT 14 -#define AVG_MAX 15 -#define QMAX_QTOT 16 -#define SIGMA_PAD_TIME 17 -#define DIFF_SIGMA_PAD 18 -#define DIFF_SIGMA_TIME 19 -#define DIFF_SIGMA_PAD_TIME 20 -#define AVG_TOT_MAX 21 -#define ROW_TRACK_FIRST 22 -#define ROW_TRACK 23 - -#define PAD_80 24 -#define PAD_92 25 -#define PAD_104 26 -#define PAD_116 27 -#define PAD_128 28 -#define PAD_140 29 - -const int32_t rr = optimized_negative_values && 0 ? 13 : 14; // We can make them all 14 for convenience, the encoding will handle it - -const uint32_t field_bits[] = {0, 6, 0, 8, 14, 15, 8, 8, 10, 16, 2, 0, 14, 15, 16, 10, 26, 16, 8, 8, 16, 26, 8, 8, rr, rr, rr, rr, rr, 14}; -const uint32_t significant_bits[] = {0, 6, 0, 8, 14, 15, truncate_sigma, truncate_sigma, truncate_charge, truncate_charge, 2, 0, 14, 15, truncate_charge, truncate_charge, 26, 16, truncate_sigma, truncate_sigma, 16, 26, 8, 8, rr, rr, rr, rr, rr, 14}; -const int32_t nFields = sizeof(field_bits) / sizeof(field_bits[0]); -const char* field_names[] = {"event", "sector", "patch", "row", "pad", "time", "sigmaPad", "sigmaTime", "qmax", "qtot", "flagPadTime", "trackID", "resTrackPad", - "resTrackTime", "trackQTot", "trackQMax", "qmaxtot", "sigmapadtime", "diffsigmapad", "diffsigmatime", "diffsigmapadtime", "tracktotmax", "trackfirstrow", "trackrow", "pad_80", "pad_92", - "pad_104", "pad_116", "pad_128", "pad_140"}; - -union cluster_struct { - struct - { - uint32_t event, sector, patch, row, pad, time, sigmaPad, sigmaTime, qmax, qtot, splitPadTime; - int32_t trackID; - uint32_t resPad, resTime, avgtot, avgmax; - }; - uint32_t vals[16]; -}; - -int32_t fgRows[6][2] = {{0, 30}, {30, 62}, {63, 90}, {90, 116}, {117, 139}, {139, 158}}; -int32_t fgNRows[6] = {31, 33, 28, 27, 23, 20}; - -int32_t fgNPads[159] = {68, 68, 68, 68, 70, 70, 70, 72, 72, 72, 74, 74, 74, 76, 76, 76, 78, 78, 78, 80, 80, 80, 82, 82, 82, 84, 84, 84, 86, 86, 86, 88, 88, 88, 90, 90, 90, 92, 92, 92, 94, 94, 94, 96, 96, 96, 98, 98, 98, 100, 100, 100, 102, - 102, 102, 104, 104, 104, 106, 106, 106, 108, 108, 74, 76, 76, 76, 76, 78, 78, 78, 80, 80, 80, 80, 82, 82, 82, 84, 84, 84, 86, 86, 86, 86, 88, 88, 88, 90, 90, 90, 90, 92, 92, 92, 94, 94, 94, 96, 96, 96, 96, 98, 98, 98, 100, - 100, 100, 100, 102, 102, 102, 104, 104, 104, 106, 106, 106, 106, 108, 108, 108, 110, 110, 110, 110, 112, 112, 114, 114, 114, 116, 116, 118, 118, 120, 120, 122, 122, 122, 124, 124, 126, 126, 128, 128, 130, 130, 130, 132, 132, 134, 134, 136, 136, 138, 138, 138, 140}; - -int32_t fgNPadsMod[159] = {80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 116, 116, 116, 116, 116, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 128, 128, 128, 128, 128, 128, 128, 128, 128, 126, 126, 128, 128, 140, 140, 140, 140, 140, 134, 134, 140, 140, 140, 140, 140, 140}; - -// ---------------------------------- HUFFMAN TREE - -typedef std::vector HuffCode; -typedef std::map HuffCodeMap; - -class INode -{ - public: - const double f; - - virtual ~INode() {} - - protected: - INode(double f) : f(f) {} -}; - -class InternalNode : public INode -{ - public: - INode* const left; - INode* const right; - - InternalNode(INode* c0, INode* c1) : INode(c0->f + c1->f), left(c0), right(c1) {} - ~InternalNode() - { - delete left; - delete right; - } -}; - -class LeafNode : public INode -{ - public: - const uint32_t c; - - LeafNode(double f, uint32_t c) : INode(f), c(c) {} -}; - -struct NodeCmp { - bool operator()(const INode* lhs, const INode* rhs) const { return lhs->f > rhs->f; } -}; - -INode* BuildTree(const double* frequencies, uint32_t UniqueSymbols) -{ - std::priority_queue, NodeCmp> trees; - - for (int32_t i = 0; i < UniqueSymbols; i++) { - if (frequencies[i] != 0) { - trees.push(new LeafNode(frequencies[i], i)); - } - } - while (trees.size() > 1) { - INode* childR = trees.top(); - trees.pop(); - - INode* childL = trees.top(); - trees.pop(); - - INode* parent = new InternalNode(childR, childL); - trees.push(parent); - } - return trees.top(); -} - -void GenerateCodes(const INode* node, const HuffCode& prefix, HuffCodeMap& outCodes) -{ - if (const LeafNode* lf = dynamic_cast(node)) { - outCodes[lf->c] = prefix; - } else if (const InternalNode* in = dynamic_cast(node)) { - HuffCode leftPrefix = prefix; - leftPrefix.push_back(false); - GenerateCodes(in->left, leftPrefix, outCodes); - - HuffCode rightPrefix = prefix; - rightPrefix.push_back(true); - GenerateCodes(in->right, rightPrefix, outCodes); - } -} - -//--------------------------------------------- END HUFFMAN - -bool clustercompare_padtime(cluster_struct a, cluster_struct b) { return (a.pad < b.pad || (a.pad == b.pad && a.time < b.time)); } - -bool clustercompare_timepad(cluster_struct a, cluster_struct b) { return (a.time < b.time || (a.time == b.time && a.pad < b.pad)); } - -bool clustercompare_padtime_mixed(cluster_struct a, cluster_struct b) { return (a.pad / sort_pad_mixed_bins < b.pad / sort_pad_mixed_bins || (a.pad / sort_pad_mixed_bins == b.pad / sort_pad_mixed_bins && a.time < b.time)); } - -bool clustercompare_timepad_mixed(cluster_struct a, cluster_struct b) { return (a.time / sort_time_mixed_bins < b.time / sort_time_mixed_bins || (a.time / sort_time_mixed_bins == b.time / sort_time_mixed_bins && a.pad < b.pad)); } - -bool clustercompare_inevent(cluster_struct a, cluster_struct b) { return (a.sector < b.sector || (a.sector == b.sector && a.patch < b.patch) || (a.sector == b.sector && a.patch == b.patch && a.row < b.row)); } - -void do_diff(uint32_t& val, int32_t& last, uint32_t bits, uint32_t maxval = 0) -{ - int32_t tmp = val; - val -= last; - if (maxval && optimized_negative_values) { - while ((signed)val < 0) { - val += maxval; - } - } else { - val &= (1 << bits) - 1; - } - last = tmp; -} - -uint32_t truncate(int32_t j, uint32_t val) -{ - if (truncate_bits && field_bits[j] != significant_bits[j] && val) { - int32_t ldz = sizeof(uint32_t) * 8 - __builtin_clz(val); - if (ldz > significant_bits[j]) { - val &= ((1 << ldz) - 1) ^ ((1 << (ldz - significant_bits[j])) - 1); - } - } - return (val); -} - -int32_t main(int argc, char** argv) -{ - FILE* fp; - - if (truncate_bits && (track_avgmax || track_diffqmax || track_diffqtot)) { - printf("Cannot use truncate bits with differential qmax / qtot"); - return (1); - } - if (truncate_bits && (track_diffsigma)) { - printf("Cannot use truncate bits with differential sigma"); - return (1); - } - - if (!(fp = fopen(file, "rb"))) { - printf("Error opening file\n"); - return (1); - } - - fseek(fp, 0, SEEK_END); - size_t nFileSize = ftell(fp); - fseek(fp, 0, SEEK_SET); - - size_t nClusters = nFileSize / sizeof(cluster_struct); - if (max_clusters && nClusters > max_clusters) { - nClusters = max_clusters; - } - - cluster_struct* clusters = new cluster_struct[nClusters]; - if (clusters == NULL) { - printf("Memory allocation error\n"); - return (1); - } - - fprintf(stderr, "Reading %d clusters...", (int32_t)nClusters); - fread(clusters, sizeof(cluster_struct), nClusters, fp); - - fprintf(stderr, "Done\nSorting clusters..."); - - if (sort_method) { - int32_t starti = 0; - if (!track_based) { - fprintf(stderr, " (removing track ordering)..."); - int32_t last_event = 0; - for (int32_t i = 0; i <= nClusters; i++) { - int32_t event = (i == nClusters ? -1 : clusters[i].event); - if (last_event != event) { - if (i - 1 > starti) { - std::sort(clusters + starti, clusters + i - 1, clustercompare_inevent); - } - starti = i; - } - last_event = event; - } - } - - starti = 0; - int32_t startrow = -1; - for (int32_t i = 0; i <= nClusters; i++) { - int32_t currow; - if (i == nClusters) { - currow = -1; - } else if (track_based && clusters[i].trackID != -1) { - currow = -2; - } else { - currow = clusters[i].row; - } - if (currow != startrow && startrow != -2) { - if (i - 1 > starti) { - if (sort_method == 1) { - std::sort(clusters + starti, clusters + i - 1, clustercompare_padtime); - } else if (sort_method == 2) { - std::sort(clusters + starti, clusters + i - 1, clustercompare_timepad); - } else if (sort_method == 3) { - std::sort(clusters + starti, clusters + i - 1, clustercompare_padtime_mixed); - } else if (sort_method == 4) { - std::sort(clusters + starti, clusters + i - 1, clustercompare_timepad_mixed); - } - } - starti = i; - startrow = currow; - } - } - } - fprintf(stderr, "Done\n"); - - fclose(fp); - - int64_t* histograms[nFields]; - double* probabilities[nFields]; - int64_t counts[nFields]; - int32_t used[nFields]; - for (int32_t i = SECTOR; i < nFields; i++) { - if (i == CLUSTER_ID) { - continue; - } - histograms[i] = new int64_t[1 << field_bits[i]]; - probabilities[i] = new double[1 << field_bits[i]]; - } - - double rawtotalbytes = 0; - double entrototalbytes = 0; - for (int32_t isector = 0; isector < 36; isector++) { - for (int32_t ipatch = 0; ipatch < 6; ipatch++) { - if (separate_sectors) { - printf("SECTOR %d ", isector); - } - if (separate_patches) { - printf("PATCH %d", ipatch); - } - if (separate_sectors || separate_patches) { - printf("\n"); - } - for (int32_t i = SECTOR; i < nFields; i++) { - if (i == CLUSTER_ID || i == PATCH) { - continue; - } - memset(histograms[i], 0, sizeof(int64_t) * (1 << field_bits[i])); - counts[i] = 0; - used[i] = 0; - } - - size_t nClustersUsed = 0; - - int32_t lastRow = 0, lastPad = 0, lastTime = 0, lastSector = 0, lastResPad = 0, lastResTime = 0, lastQTot = 0, lastQMax = 0, lastSigmaPad = 0, lastSigmaTime = 0, lastTrack = -1, lastEvent = 0; - - for (size_t i = 0; i < nClusters; i++) { - const cluster_struct& cluster_org = clusters[i]; - cluster_struct cluster = clusters[i]; - if (cluster.pad >= 32768) { - printf("%d\n", cluster.pad); - } - - if ((separate_sectors && cluster.sector != isector) || (separate_patches && cluster.patch != ipatch)) { - continue; - } - if (separate_sides && !(cluster.sector < 18 ^ isector < 18)) { - continue; - } - - bool newTrack = lastTrack != cluster.trackID; - uint32_t dSigmaPad, dSigmaTime; - - if (cluster.event != lastEvent) { - lastRow = lastPad = lastTime = lastSector = 0; - lastTrack = -1; - } - - if (full_row_numbers) { - cluster.row += fgRows[cluster.patch][0]; - } - - if ((sector_diff || res_diff || track_diffqtot || track_diffqmax) && cluster.trackID != -1 && track_based) { - if (lastTrack != cluster.trackID) { - lastSector = lastResPad = lastResTime = lastQTot = lastQMax = lastSigmaPad = lastSigmaTime = 0; - } - - if (sector_diff) { - do_diff(cluster.sector, lastSector, field_bits[SECTOR]); - } - - if (res_diff) { - do_diff(cluster.resPad, lastResPad, field_bits[RES_PAD]); - do_diff(cluster.resTime, lastResTime, field_bits[RES_TIME]); - } - - if (track_diffqtot) { - cluster.avgtot = cluster.qtot; - do_diff(cluster.avgtot, lastQTot, field_bits[QTOT]); - } - if (track_diffqmax) { - cluster.avgmax = cluster.qmax; - do_diff(cluster.avgmax, lastQMax, field_bits[QMAX]); - } - if (track_diffsigma) { - dSigmaPad = cluster.sigmaPad; - dSigmaTime = cluster.sigmaTime; - do_diff(dSigmaPad, lastSigmaPad, field_bits[SIGMA_PAD]); - do_diff(dSigmaTime, lastSigmaTime, field_bits[SIGMA_TIME]); - } else if (track_separate_sigma) { - dSigmaPad = truncate(SIGMA_PAD, cluster.sigmaPad); - dSigmaTime = truncate(SIGMA_TIME, cluster.sigmaTime); - } - } - - if (cluster.row != lastRow) { - lastPad = lastTime = 0; - } - if (row_diff) { - do_diff(cluster.row, lastRow, field_bits[ROW]); - } else { - lastRow = cluster.row; - } - - if (pad_diff && (cluster.trackID == -1 || !track_based)) { - do_diff(cluster.pad, lastPad, field_bits[PAD], (distinguish_rows ? fgNPadsMod[cluster_org.row + fgRows[cluster.patch][0]] : 140) * 60); - } - if (time_diff && (cluster.trackID == -1 || !track_based)) { - do_diff(cluster.time, lastTime, field_bits[TIME], 1024 * 25); - } - - if (approximate_qtot && (!track_based || cluster.trackID == -1 || (track_avgtot == 0 && track_diffqtot == 0))) { - cluster.qtot -= cluster.sigmaPad * cluster.qmax / 3; - if (cluster.qtot < 0) { - cluster.qtot = -truncate(QTOT, -cluster.qtot); - } else { - cluster.qtot = truncate(QTOT, cluster.qtot); - } - cluster.qtot &= (1 << field_bits[QTOT]) - 1; - } - - if (track_avgtot && cluster.trackID != -1) { - int32_t tmp = truncate(QTOT, cluster.qtot) - truncate(QTOT, cluster.avgtot); - if (newTrack) { - cluster.qtot = truncate(QTOT, cluster.avgtot); - } - cluster.avgtot = tmp & ((1 << field_bits[QTOT]) - 1); - } - if (track_avgmax && cluster.trackID != -1) { - int32_t tmp = cluster.qmax - cluster.avgmax; - if (newTrack) { - cluster.qmax = cluster.avgmax; - } - cluster.avgmax = tmp & ((1 << field_bits[QMAX]) - 1); - } - - // Copy qmax / qtot to combined track avg... slot, to use for combine_maxtot - if ((((combine_maxtot && (track_avgtot || track_diffqtot)) || track_separate_q) && track_avgmax == 0 && track_diffqmax == 0) && cluster.trackID != -1) { - cluster.avgmax = cluster.qmax; - } - if ((((combine_maxtot && (track_avgmax || track_diffqmax)) || track_separate_q) && track_avgtot == 0 && track_diffqtot == 0) && cluster.trackID != -1) { - cluster.avgtot = cluster.qtot; - } - - for (int32_t j = 0; j < sizeof(cluster_struct) / sizeof(uint32_t); j++) { - if (approximate_qtot && (j == QTOT || j == AVG_TOT)) { - continue; - } - if (track_avgtot && (j == QTOT || j == AVG_TOT)) { - continue; - } - cluster.vals[j] = truncate(j, cluster.vals[j]); - } - - lastEvent = cluster.event; - lastTrack = cluster.trackID; - - if (print_clusters > 0 || (print_clusters < 0 && i < -print_clusters)) { - printf("Event %u Track %d Sector %u Patch %u Row %u Pad %u Time %u sigmaPad %u sigmaTime %u qTot %u qMax %u Flag %u resPad %u resTime %u avgTot %u avgMax %u\n", cluster.event, cluster.trackID, cluster.sector, cluster.patch, cluster.row, cluster.pad, cluster.time, cluster.sigmaPad, - cluster.sigmaTime, cluster.qtot, cluster.qmax, cluster.splitPadTime, cluster.resPad, cluster.resTime, cluster.avgtot, cluster.avgmax); - } - - for (int32_t j = SECTOR; j < nFields; j++) { - bool forceStore = false; - if (j == CLUSTER_ID || j == PATCH) { - continue; - } - - if (j == SECTOR && (track_based == 0 || cluster.trackID == -1)) { - continue; - } - - if (track_based && cluster.trackID != -1 && !newTrack) { - if (j == PAD || j == TIME || (j >= PAD_80 && j <= PAD_140)) { - continue; - } - if (j == RES_PAD || j == RES_TIME) { - cluster.vals[j] &= (1 << field_bits[j]) - 1; - forceStore = true; - } - } - - if ((track_avgtot || track_diffqtot || track_separate_q) && cluster.trackID != -1) { - if (j == QTOT && (!newTrack || (track_avgtot == 0 && track_diffqtot == 0))) { - continue; - } - if (j == AVG_TOT && (track_diffqtot == 0 || !newTrack)) { - forceStore = true; - } - } - if ((track_avgmax || track_diffqmax || track_separate_q) && cluster.trackID != -1) { - if (j == QMAX && (!newTrack || (track_avgmax == 0 && track_diffqmax == 0))) { - continue; - } - if (j == AVG_MAX && (track_diffqmax == 0 || !newTrack)) { - forceStore = true; - } - } - - if ((track_diffsigma || track_separate_sigma) && cluster.trackID != -1) { - if (j == SIGMA_PAD || j == SIGMA_TIME) { - continue; - } - if (j == DIFF_SIGMA_PAD) { - histograms[j][dSigmaPad]++; - counts[j]++; - } - if (j == DIFF_SIGMA_TIME) { - histograms[j][dSigmaTime]++; - counts[j]++; - } - } - - if (track_based && row_diff && cluster.trackID != -1) { - if (j == ROW) { - continue; - } - int32_t myj = newTrack ? ROW_TRACK_FIRST : ROW_TRACK; - if (j == myj) { - histograms[myj][cluster.vals[ROW]]++; - counts[myj]++; - } - } - - if (j <= FLAG_PADTIME || forceStore) { - if (cluster.vals[j] >= (1 << field_bits[j])) { - printf("Cluster value %d/%s out of bit range %d > %d\n", j, field_names[j], cluster.vals[j], (1 << field_bits[j])); - } else { - histograms[j][cluster.vals[j]]++; - counts[j]++; - } - } else if (j == QMAX_QTOT && (!track_based || cluster.trackID == -1 || (((track_avgmax == 0 && track_avgtot == 0 && track_diffqmax == 0 && track_diffqtot == 0) || newTrack) && track_separate_q == 0))) { - int32_t val = (cluster.qtot << field_bits[QMAX]) | cluster.qmax; - histograms[j][val]++; - counts[j]++; - } else if (((track_avgmax || track_avgtot || track_diffqmax || track_diffqtot) && !newTrack || track_separate_q) && cluster.trackID != -1 && j == AVG_TOT_MAX) { - int32_t val = (cluster.avgtot << field_bits[QMAX]) | cluster.avgmax; - histograms[j][val]++; - counts[j]++; - } else if (j == SIGMA_PAD_TIME && (!track_based || cluster.trackID == -1 || (track_diffsigma == 0 && track_separate_sigma == 0))) { - int32_t val = (cluster.sigmaTime << field_bits[SIGMA_PAD]) | cluster.sigmaPad; - histograms[j][val]++; - counts[j]++; - } else if ((track_diffsigma || track_separate_sigma) && cluster.trackID != -1 && j == DIFF_SIGMA_PAD_TIME) { - int32_t val = (dSigmaPad << field_bits[SIGMA_PAD]) | dSigmaTime; - histograms[j][val]++; - counts[j]++; - } else if (distinguish_rows && j >= PAD_80 && j <= PAD_140) { - int32_t myj = fgNPads[cluster_org.row + fgRows[cluster.patch][0]]; - myj = (myj - (80 - 11)) / 12; - myj += PAD_80; - if (myj == j) { - if (cluster.pad >= (1 << field_bits[j])) { - printf("Cluster value %d/%s out of bit range %d > %d\n", j, field_names[j], cluster.vals[j], (1 << field_bits[j])); - } else { - histograms[j][cluster.pad]++; - counts[j]++; - } - } - } - } - nClustersUsed++; - } - - printf("Clusters in block: %ld / %ld\n", nClustersUsed, nClusters); - - double log2 = log(2.); - double entropies[nFields]; - double huffmanSizes[nFields]; - for (int32_t i = SECTOR; i < nFields; i++) { - if (i == CLUSTER_ID || i == PATCH) { - continue; - } - double entropy = 0.; - double huffmanSize = 0; - - if (counts[i]) { - for (int32_t j = 0; j < (1 << field_bits[i]); j++) { - // printf("Field %d/%s Value %d Entries %ld\n", i, field_names[i], j, histograms[i][j]); - - probabilities[i][j] = (double)histograms[i][j] / (double)counts[i]; - if (probabilities[i][j]) { - double I = -log(probabilities[i][j]) / log2; - double H = I * probabilities[i][j]; - // printf("Field %d/%s Value %d I prob %f I %f H %f\n", i, field_names[i], probabilities[i][j], I, H); - - entropy += H; - } - } - - INode* root = BuildTree(probabilities[i], 1 << field_bits[i]); - - HuffCodeMap codes; - GenerateCodes(root, HuffCode(), codes); - delete root; - - for (HuffCodeMap::const_iterator it = codes.begin(); it != codes.end(); it++) { - huffmanSize += it->second.size() * probabilities[i][it->first]; - } - } - entropies[i] = entropy; - huffmanSizes[i] = huffmanSize; - } - - int32_t rawBits = 0; - double entroTotal = 0., huffmanTotal = 0.; - for (int32_t i = SECTOR; i < nFields; i++) { - if (i == CLUSTER_ID || i == PATCH) { - continue; - } - - if (i <= FLAG_PADTIME) { - rawBits += field_bits[i]; - } - - if (combine_maxtot && (i == QMAX || i == QTOT)) { - continue; - } - if (combine_sigmapadtime && (i == SIGMA_PAD || i == SIGMA_TIME)) { - continue; - } - if ((track_diffsigma || track_separate_sigma) && combine_sigmapadtime && (i == DIFF_SIGMA_PAD || i == DIFF_SIGMA_TIME)) { - continue; - } - - if (distinguish_rows && i == PAD) { - continue; - } - - if (i <= FLAG_PADTIME || (combine_maxtot && i == QMAX_QTOT) || (combine_maxtot && (track_avgmax || track_avgtot || track_diffqmax || track_diffqtot || track_separate_q) && combine_maxtot && i == AVG_TOT_MAX) || (combine_sigmapadtime && i == SIGMA_PAD_TIME) || - (combine_sigmapadtime && (track_diffsigma || track_separate_sigma) && i == DIFF_SIGMA_PAD_TIME) || (track_based && (i == RES_PAD || i == RES_TIME)) || ((track_avgtot || track_diffqtot || track_separate_q) && !combine_maxtot && i == AVG_TOT) || - ((track_avgmax || track_diffqmax || track_separate_q) && !combine_maxtot && i == AVG_MAX) || ((track_diffsigma || track_separate_sigma) && (i == DIFF_SIGMA_PAD || i == DIFF_SIGMA_TIME)) || (track_based && row_diff && (i == ROW_TRACK || i == ROW_TRACK_FIRST)) || - (distinguish_rows && i >= PAD_80 && i <= PAD_140)) { - entroTotal += entropies[i] * counts[i]; - huffmanTotal += huffmanSizes[i] * counts[i]; - used[i] = 1; - } - } - for (int32_t i = SECTOR; i < nFields; i++) { - if (field_bits[i] == 0) { - continue; - } - if (counts[i] == 0) { - continue; - } - printf("Field %2d/%16s (count %10ld / used %1d) rawBits %2d huffman %9.6f entropy %9.6f\n", i, field_names[i], counts[i], used[i], field_bits[i], huffmanSizes[i], entropies[i]); - } - rawBits = 79; // Override incorrect calculation: Row is only 6 bit in raw format, and sector is not needed! - printf("Raw Bits: %d - Total Size %f MB Clusters %d\n", rawBits, (double)rawBits * (double)nClustersUsed / 8. / 1.e6, nClustersUsed); - printf("Huffman Bits: %f - Total Size %f MB\n", huffmanTotal / (double)nClustersUsed, huffmanTotal / 8. / 1.e6); - printf("Entropy Bits: %f - Total Size %f MB\n", entroTotal / (double)nClustersUsed, entroTotal / 8. / 1.e6); - printf("Maximum Compression Ratio: %f (Huffman %f)\n", (double)rawBits * (double)nClustersUsed / entroTotal, (double)rawBits * (double)nClustersUsed / huffmanTotal); - entrototalbytes += entroTotal; - rawtotalbytes += (double)rawBits * (double)nClustersUsed; - - if (separate_sides && !separate_sectors && isector == 0) { - isector = 17; - } else if (!separate_sectors) { - isector = 9999999; - } - - if (!separate_patches) { - ipatch = 9999999; - } - } - } - - if (separate_sectors || separate_patches || separate_sides) { - printf("Total Compression: %f\n", rawtotalbytes / entrototalbytes); - } - - printf("Exiting\n"); - for (int32_t i = SECTOR; i < nFields; i++) { - if (i == CLUSTER_ID || i == PATCH) { - continue; - } - delete[] histograms[i]; - delete[] probabilities[i]; - } - delete[] clusters; - return (0); -} diff --git a/GPU/GPUTracking/DataTypes/CalibdEdxContainer.cxx b/GPU/GPUTracking/DataTypes/CalibdEdxContainer.cxx index 0b3ee65ef7578..7a3931d0920c4 100644 --- a/GPU/GPUTracking/DataTypes/CalibdEdxContainer.cxx +++ b/GPU/GPUTracking/DataTypes/CalibdEdxContainer.cxx @@ -12,18 +12,18 @@ /// \file CalibdEdxContainer.cxx /// \author Matthias Kleiner -#if !defined(GPUCA_STANDALONE) +#ifndef GPUCA_STANDALONE #include "TFile.h" #include "TPCBase/CalDet.h" -#include "Framework/Logger.h" -#include "clusterFinderDefs.h" #endif + +#include "GPUCommonLogger.h" +#include "clusterFinderDefs.h" #include "CalibdEdxContainer.h" using namespace o2::gpu; using namespace o2::tpc; -#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) void CalibdEdxContainer::cloneFromObject(const CalibdEdxContainer& obj, char* newFlatBufferPtr) { FlatObject::cloneFromObject(obj, newFlatBufferPtr); @@ -49,7 +49,6 @@ void CalibdEdxContainer::subobjectCloneFromObject(Type*& obj, const Type* objOld memset((void*)obj, 0, sizeof(*obj)); obj->cloneFromObject(*objOld, mFlatBufferPtr + sizeOfCalibdEdxTrackTopologyObj()); } -#endif void CalibdEdxContainer::moveBufferTo(char* newFlatBufferPtr) { @@ -120,8 +119,6 @@ void CalibdEdxContainer::setFutureBufferAddress(Type*& obj, char* futureFlatBuff obj = FlatObject::relocatePointer(mFlatBufferPtr, futureFlatBufferPtr, obj); } -#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) - float CalibdEdxContainer::getMinZeroSupresssionThreshold() const { if (mCalibTrackTopologyPol) { @@ -144,16 +141,6 @@ float CalibdEdxContainer::getMaxZeroSupresssionThreshold() const } } -void CalibdEdxContainer::loadPolTopologyCorrectionFromFile(std::string_view fileName) -{ - loadTopologyCorrectionFromFile(fileName, mCalibTrackTopologyPol); -} - -void CalibdEdxContainer::loadSplineTopologyCorrectionFromFile(std::string_view fileName) -{ - loadTopologyCorrectionFromFile(fileName, mCalibTrackTopologySpline); -} - void CalibdEdxContainer::setPolTopologyCorrection(const CalibdEdxTrackTopologyPol& calibTrackTopology) { setTopologyCorrection(calibTrackTopology, mCalibTrackTopologyPol); @@ -174,6 +161,45 @@ void CalibdEdxContainer::setSplineTopologyCorrection(const CalibdEdxTrackTopolog mCalibTrackTopologyPol = nullptr; } +void CalibdEdxContainer::setDefaultZeroSupresssionThreshold() +{ + const float defaultVal = getMinZeroSupresssionThreshold() + (getMaxZeroSupresssionThreshold() - getMinZeroSupresssionThreshold()) / 2; + mThresholdMap.setMinCorrectionFactor(defaultVal - 0.1f); + mThresholdMap.setMaxCorrectionFactor(defaultVal + 0.1f); + for (int32_t sector = 0; sector < o2::tpc::constants::MAXSECTOR; ++sector) { + for (uint16_t globPad = 0; globPad < TPC_PADS_IN_SECTOR; ++globPad) { + mThresholdMap.setGainCorrection(sector, globPad, defaultVal); + } + } +} + +template +void CalibdEdxContainer::setTopologyCorrection(const Type& calibTrackTopologyTmp, Type*& obj) +{ + FlatObject::startConstruction(); + + // get size of the flat buffer of the splines + const std::size_t flatbufferSize = calibTrackTopologyTmp.getFlatBufferSize(); + + // size of the dEdx container without taking flat buffer into account + const std::size_t objSize = sizeOfCalibdEdxTrackTopologyObj(); + + // create mFlatBuffer with correct size + const std::size_t totalSize = flatbufferSize + objSize; + FlatObject::finishConstruction(totalSize); + + // setting member of CalibdEdxTrackTopologyPol to correct buffer address + obj = reinterpret_cast(mFlatBufferPtr); + + // deep copy of CalibdEdxTrackTopologyPol to buffer without moving the flat buffer to correct address + obj->cloneFromObject(calibTrackTopologyTmp, nullptr); + + // seting the buffer of the splines to current buffer + obj->moveBufferTo(objSize + mFlatBufferPtr); +} + +#ifndef GPUCA_STANDALONE + void CalibdEdxContainer::loadZeroSupresssionThresholdFromFile(std::string_view fileName, std::string_view objName, const float minCorrectionFactor, const float maxCorrectionFactor) { TFile fInp(fileName.data(), "READ"); @@ -219,7 +245,7 @@ CalDet CalibdEdxContainer::processThresholdMap(const CalDet& thres for (int32_t padCl = padStart; padCl <= padEnd; ++padCl) { const int32_t globalPad = Mapper::getGlobalPadNumber(rowCl, padCl, region); // skip for current cluster position as the charge there is not effected from the thresold - if (padCl == pad && rowCl == lrow) { + if (padCl == (int32_t)pad && rowCl == lrow) { continue; } @@ -259,16 +285,14 @@ void CalibdEdxContainer::setGainMapResidual(const CalDet& gainMapResidual mGainMapResidual = gainMapResTmp; } -void CalibdEdxContainer::setDefaultZeroSupresssionThreshold() +void CalibdEdxContainer::loadPolTopologyCorrectionFromFile(std::string_view fileName) { - const float defaultVal = getMinZeroSupresssionThreshold() + (getMaxZeroSupresssionThreshold() - getMinZeroSupresssionThreshold()) / 2; - mThresholdMap.setMinCorrectionFactor(defaultVal - 0.1f); - mThresholdMap.setMaxCorrectionFactor(defaultVal + 0.1f); - for (int32_t sector = 0; sector < o2::tpc::constants::MAXSECTOR; ++sector) { - for (uint16_t globPad = 0; globPad < TPC_PADS_IN_SECTOR; ++globPad) { - mThresholdMap.setGainCorrection(sector, globPad, defaultVal); - } - } + loadTopologyCorrectionFromFile(fileName, mCalibTrackTopologyPol); +} + +void CalibdEdxContainer::loadSplineTopologyCorrectionFromFile(std::string_view fileName) +{ + loadTopologyCorrectionFromFile(fileName, mCalibTrackTopologySpline); } template @@ -279,29 +303,4 @@ void CalibdEdxContainer::loadTopologyCorrectionFromFile(std::string_view fileNam setTopologyCorrection(calibTrackTopologyTmp, obj); } -template -void CalibdEdxContainer::setTopologyCorrection(const Type& calibTrackTopologyTmp, Type*& obj) -{ - FlatObject::startConstruction(); - - // get size of the flat buffer of the splines - const std::size_t flatbufferSize = calibTrackTopologyTmp.getFlatBufferSize(); - - // size of the dEdx container without taking flat buffer into account - const std::size_t objSize = sizeOfCalibdEdxTrackTopologyObj(); - - // create mFlatBuffer with correct size - const std::size_t totalSize = flatbufferSize + objSize; - FlatObject::finishConstruction(totalSize); - - // setting member of CalibdEdxTrackTopologyPol to correct buffer address - obj = reinterpret_cast(mFlatBufferPtr); - - // deep copy of CalibdEdxTrackTopologyPol to buffer without moving the flat buffer to correct address - obj->cloneFromObject(calibTrackTopologyTmp, nullptr); - - // seting the buffer of the splines to current buffer - obj->moveBufferTo(objSize + mFlatBufferPtr); -} - -#endif +#endif // GPUCA_STANDALONE diff --git a/GPU/GPUTracking/DataTypes/CalibdEdxContainer.h b/GPU/GPUTracking/DataTypes/CalibdEdxContainer.h index 33089ff301d06..4e7c47b25d86c 100644 --- a/GPU/GPUTracking/DataTypes/CalibdEdxContainer.h +++ b/GPU/GPUTracking/DataTypes/CalibdEdxContainer.h @@ -26,7 +26,7 @@ #include "TPCPadGainCalib.h" #include "TPCPadBitMap.h" -#ifndef GPUCA_ALIGPUCODE +#ifndef GPUCA_GPUCODE_DEVICE #include #endif @@ -159,7 +159,7 @@ class CalibdEdxContainer : public o2::gpu::FlatObject void setFutureBufferAddress(char* futureFlatBufferPtr); /// ================================================================================================ -#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) +#if !defined(GPUCA_GPUCODE) // loading the polynomial track topology correction from a file /// \param fileName input file containing the correction void loadPolTopologyCorrectionFromFile(std::string_view fileName); diff --git a/GPU/GPUTracking/DataTypes/CalibdEdxTrackTopologyPol.cxx b/GPU/GPUTracking/DataTypes/CalibdEdxTrackTopologyPol.cxx index 1f6d6709e0ab0..dd61598f2de7e 100644 --- a/GPU/GPUTracking/DataTypes/CalibdEdxTrackTopologyPol.cxx +++ b/GPU/GPUTracking/DataTypes/CalibdEdxTrackTopologyPol.cxx @@ -20,7 +20,7 @@ using namespace o2::tpc; -#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) // code invisible on GPU and in the standalone compilation +#if !defined(GPUCA_STANDALONE) // code invisible on GPU and in the standalone compilation #include "NDPiecewisePolynomials.inc" void CalibdEdxTrackTopologyPol::dumpToTree(const uint32_t nSamplingPoints[/* Dim */], const char* outName) const { @@ -104,8 +104,6 @@ void CalibdEdxTrackTopologyPol::setFutureBufferAddress(char* futureFlatBufferPtr FlatObject::setFutureBufferAddress(futureFlatBufferPtr); } -#if !defined(GPUCA_STANDALONE) - void CalibdEdxTrackTopologyPol::construct() { FlatObject::startConstruction(); @@ -155,30 +153,6 @@ void CalibdEdxTrackTopologyPol::setDefaultPolynomials() construct(); } -void CalibdEdxTrackTopologyPol::writeToFile(TFile& outf, const char* name) const -{ - CalibdEdxTrackTopologyPolContainer cont; - cont.mCalibPols.reserve(FFits); - - for (const auto& par : mCalibPolsqTot) { - cont.mCalibPols.emplace_back(par.getContainer()); - } - - for (const auto& par : mCalibPolsqMax) { - cont.mCalibPols.emplace_back(par.getContainer()); - } - - for (const auto par : mScalingFactorsqTot) { - cont.mScalingFactorsqTot.emplace_back(par); - } - - for (const auto par : mScalingFactorsqMax) { - cont.mScalingFactorsqMax.emplace_back(par); - } - - outf.WriteObject(&cont, name); -} - void CalibdEdxTrackTopologyPol::setFromContainer(const CalibdEdxTrackTopologyPolContainer& container) { if (2 * FFits != container.mCalibPols.size()) { @@ -207,6 +181,39 @@ void CalibdEdxTrackTopologyPol::setFromContainer(const CalibdEdxTrackTopologyPol construct(); } +std::string CalibdEdxTrackTopologyPol::getPolyName(const int32_t region, const ChargeType charge) +{ + const std::string typeName[2] = {"qMax", "qTot"}; + const std::string polname = fmt::format("polynomial_{}_region{}", typeName[charge], region).data(); + return polname; +} + +#ifndef GPUCA_STANDALONE + +void CalibdEdxTrackTopologyPol::writeToFile(TFile& outf, const char* name) const +{ + CalibdEdxTrackTopologyPolContainer cont; + cont.mCalibPols.reserve(FFits); + + for (const auto& par : mCalibPolsqTot) { + cont.mCalibPols.emplace_back(par.getContainer()); + } + + for (const auto& par : mCalibPolsqMax) { + cont.mCalibPols.emplace_back(par.getContainer()); + } + + for (const auto par : mScalingFactorsqTot) { + cont.mScalingFactorsqTot.emplace_back(par); + } + + for (const auto par : mScalingFactorsqMax) { + cont.mScalingFactorsqMax.emplace_back(par); + } + + outf.WriteObject(&cont, name); +} + void CalibdEdxTrackTopologyPol::loadFromFile(const char* fileName, const char* name) { TFile inpf(fileName, "READ"); @@ -231,11 +238,4 @@ void CalibdEdxTrackTopologyPol::setPolynomialsFromFile(TFile& inpf) construct(); } -std::string CalibdEdxTrackTopologyPol::getPolyName(const int32_t region, const ChargeType charge) -{ - const std::string typeName[2] = {"qMax", "qTot"}; - const std::string polname = fmt::format("polynomial_{}_region{}", typeName[charge], region).data(); - return polname; -} - -#endif +#endif // GPUCA_STANDALONE diff --git a/GPU/GPUTracking/DataTypes/CalibdEdxTrackTopologyPol.h b/GPU/GPUTracking/DataTypes/CalibdEdxTrackTopologyPol.h index 0a3816f9ddbd2..939d3daf73b24 100644 --- a/GPU/GPUTracking/DataTypes/CalibdEdxTrackTopologyPol.h +++ b/GPU/GPUTracking/DataTypes/CalibdEdxTrackTopologyPol.h @@ -20,7 +20,7 @@ #include "GPUCommonDef.h" #include "FlatObject.h" #include "DataFormatsTPC/Defs.h" -#ifndef GPUCA_ALIGPUCODE +#ifndef GPUCA_GPUCODE_DEVICE #include #endif @@ -127,7 +127,7 @@ class CalibdEdxTrackTopologyPol : public o2::gpu::FlatObject /// \param region region of the scaling factor GPUd() float getScalingFactorqMax(const int32_t region) const { return mScalingFactorsqMax[region]; }; -#if !defined(GPUCA_GPUCODE) +#ifndef GPUCA_GPUCODE /// \return returns polynomial for qTot /// \param region region of the TPC const auto& getPolyqTot(const int32_t region) const { return mCalibPolsqTot[region]; } @@ -136,7 +136,6 @@ class CalibdEdxTrackTopologyPol : public o2::gpu::FlatObject /// \param region region of the TPC const auto& getPolyqMax(const int32_t region) const { return mCalibPolsqMax[region]; } -#ifndef GPUCA_STANDALONE /// set the the scaling factors for the polynomials for qTot /// \param factor scaling factor /// \param region region of the scaling factor @@ -172,16 +171,13 @@ class CalibdEdxTrackTopologyPol : public o2::gpu::FlatObject /// setting a default topology correction which just returns 1 void setDefaultPolynomials(); -#endif /// \return returns the name of the polynomial object which can be read in with the setPolynomialsFromFile() function /// \param region region of the TPC /// \param charge correction for maximum or total charge static std::string getPolyName(const int32_t region, const ChargeType charge); -#endif -/// ========== FlatObject functionality, see FlatObject class for description ================= -#if !defined(GPUCA_GPUCODE) + /// ========== FlatObject functionality, see FlatObject class for description ================= /// cloning a container object (use newFlatBufferPtr=nullptr for simple copy) void cloneFromObject(const CalibdEdxTrackTopologyPol& obj, char* newFlatBufferPtr); diff --git a/GPU/GPUTracking/DataTypes/GPUDataTypesIO.h b/GPU/GPUTracking/DataTypes/GPUDataTypesIO.h index 76fa569a16824..f3172aa18d387 100644 --- a/GPU/GPUTracking/DataTypes/GPUDataTypesIO.h +++ b/GPU/GPUTracking/DataTypes/GPUDataTypesIO.h @@ -23,6 +23,7 @@ #include #endif #include "GPUTRDDef.h" +#include "DataFormatsTPC/Constants.h" struct AliHLTTPCClusterMCLabel; struct AliHLTTPCRawCluster; @@ -91,7 +92,7 @@ class ORTRootSerializer; namespace o2::gpu { class CorrectionMapsHelper; -class TPCFastTransform; +class TPCFastTransformPOD; struct TPCPadGainCalib; struct TPCZSLinkMapping; @@ -109,11 +110,6 @@ struct GPUTRDTrackletLabels; struct GPUTPCDigitsMCInput; struct GPUSettingsTF; -namespace gpudatatypes -{ -static constexpr uint32_t NSECTORS = 36; -} // namespace gpudatatypes - template struct DefaultPtr { typedef T type; @@ -125,10 +121,7 @@ struct ConstPtr { template