From 512565dc942c42d692447004a1a113bc01e3ae92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Mon, 23 Nov 2026 06:57:41 +0100 Subject: [PATCH 1/3] Add secondary particle LUT smearing --- ALICE3/Core/ALICE3CoreLinkDef.h | 4 + ALICE3/Core/CMakeLists.txt | 4 + ALICE3/Core/DetLayer.cxx | 6 +- ALICE3/Core/DetLayer.h | 41 ++- ALICE3/Core/FastTracker.cxx | 132 +++++++- ALICE3/Core/FastTracker.h | 10 + ALICE3/Core/SecondaryLut.cxx | 208 ++++++++++++ ALICE3/Core/SecondaryLut.h | 148 +++++++++ ALICE3/Core/SecondaryTrackSmearer.cxx | 306 ++++++++++++++++++ ALICE3/Core/SecondaryTrackSmearer.h | 87 +++++ ALICE3/Macros/Configuration/a3geometry_v3.ini | 9 + ALICE3/TableProducer/OTF/onTheFlyTracker.cxx | 178 ++++++++-- 12 files changed, 1094 insertions(+), 39 deletions(-) create mode 100644 ALICE3/Core/SecondaryLut.cxx create mode 100644 ALICE3/Core/SecondaryLut.h create mode 100644 ALICE3/Core/SecondaryTrackSmearer.cxx create mode 100644 ALICE3/Core/SecondaryTrackSmearer.h diff --git a/ALICE3/Core/ALICE3CoreLinkDef.h b/ALICE3/Core/ALICE3CoreLinkDef.h index 10706fa14cc..5bfeda3968b 100644 --- a/ALICE3/Core/ALICE3CoreLinkDef.h +++ b/ALICE3/Core/ALICE3CoreLinkDef.h @@ -17,3 +17,7 @@ #pragma link C++ class std::vector < std::vector < unsigned int>> + ; #pragma link C++ class std::vector < std::vector < std::uint32_t>> + ; +#pragma link C++ class o2::fastsim::SecondaryLutAxis + ; +#pragma link C++ class o2::fastsim::SecondaryLutEntry + ; +#pragma link C++ class std::vector < o2::fastsim::SecondaryLutEntry> + ; +#pragma link C++ class o2::fastsim::SecondaryLut + ; diff --git a/ALICE3/Core/CMakeLists.txt b/ALICE3/Core/CMakeLists.txt index de89ec6f1a4..b84efe7723e 100644 --- a/ALICE3/Core/CMakeLists.txt +++ b/ALICE3/Core/CMakeLists.txt @@ -16,10 +16,13 @@ o2physics_add_library(ALICE3Core FlatLutRootWriter.cxx FlatTrackSmearer.cxx GeometryContainer.cxx + SecondaryLut.cxx + SecondaryTrackSmearer.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore PRIVATE_LINK_LIBRARIES ROOT::Core ROOT::RIO + ROOT::Hist ROOT::Tree) o2physics_target_root_dictionary(ALICE3Core @@ -27,6 +30,7 @@ o2physics_target_root_dictionary(ALICE3Core FlatLutEntry.h OTFParticle.h GeometryContainer.h + SecondaryLut.h LINKDEF ALICE3CoreLinkDef.h) o2physics_add_library(FastTracker diff --git a/ALICE3/Core/DetLayer.cxx b/ALICE3/Core/DetLayer.cxx index d93fd77373f..df2d438edf4 100644 --- a/ALICE3/Core/DetLayer.cxx +++ b/ALICE3/Core/DetLayer.cxx @@ -52,7 +52,8 @@ DetLayer::DetLayer(const TString& name, } DetLayer::DetLayer(const DetLayer& other) - : mName(other.mName), mR(other.mR), mZ(other.mZ), mX0(other.mX0), mXrho(other.mXrho), mResRPhi(other.mResRPhi), mResZ(other.mResZ), mEff(other.mEff), mType(other.mType) + : mName(other.mName), mR(other.mR), mZ(other.mZ), mX0(other.mX0), mXrho(other.mXrho), mResRPhi(other.mResRPhi), mResZ(other.mResZ), mEff(other.mEff), mType(other.mType), + mDiskROuter(other.mDiskROuter) { } @@ -141,6 +142,9 @@ std::string DetLayer::toString() const case kLayerSilicon: out.append("Silicon"); break; + case kLayerSiliconDisk: + out.append("SiliconDisk"); + break; case kLayerGas: out.append("Gas/TPC"); break; diff --git a/ALICE3/Core/DetLayer.h b/ALICE3/Core/DetLayer.h index eb5b1cf0550..ca773696c9d 100644 --- a/ALICE3/Core/DetLayer.h +++ b/ALICE3/Core/DetLayer.h @@ -48,6 +48,12 @@ struct DetLayer { void setResolutionZ(float resZ) { mResZ = resZ; } void setEfficiency(float eff) { mEff = eff; } void setType(int type) { mType = type; } + void setSiliconDiskAcceptance(float innerRadius, float outerRadius, float z) + { + mR = innerRadius; + mZ = z; + mDiskROuter = outerRadius; + } // Dead areas @@ -71,6 +77,27 @@ struct DetLayer { int getType() const { return mType; } const TString& getName() const { return mName; } const TGraph* getDeadPhiRegions() const { return mDeadPhiRegions; } + float getDiskInnerRadius() const + { + if (mType != kLayerSiliconDisk) { + LOG(fatal) << "getDiskInnerRadius() called for layer " << mName << " which is not a silicon disk layer (type: " << mType << ")"; + } + return mR; + } + float getDiskOuterRadius() const + { + if (mType != kLayerSiliconDisk) { + LOG(fatal) << "getDiskOuterRadius() called for layer " << mName << " which is not a silicon disk layer (type: " << mType << ")"; + } + return mDiskROuter >= 0.f ? mDiskROuter : mR; + } + float getDiskZ() const + { + if (mType != kLayerSiliconDisk) { + LOG(fatal) << "getDiskZ() called for layer " << mName << " which is not a silicon disk layer (type: " << mType << ")"; + } + return mZ; + } // Check layer mType bool isInert() const { return mType == kLayerInert; } @@ -78,6 +105,7 @@ struct DetLayer { bool isGas() const { return mType == kLayerGas; } bool isTOF() const { return mType == kLayerTOF; } bool isVertex() const { return mType == kLayerVertex; } + bool isSiliconDisk() const { return mType == kLayerSiliconDisk; } bool isActive() const { return mType != kLayerInert; } // active layers are not inert // Utilities @@ -97,11 +125,12 @@ struct DetLayer { return mDeadPhiRegions->Eval(phi) > 1.f; }; - static constexpr int kLayerVertex = -1; // vertex layer type (not used in tracking) - static constexpr int kLayerInert = 0; // inert/undefined layer - static constexpr int kLayerSilicon = 1; // silicon layer - static constexpr int kLayerGas = 2; // gas/tpc layer - static constexpr int kLayerTOF = 3; // TOF layer type (not used in tracking) + static constexpr int kLayerVertex = -1; // vertex layer type (not used in tracking) + static constexpr int kLayerInert = 0; // inert/undefined layer + static constexpr int kLayerSilicon = 1; // silicon layer + static constexpr int kLayerGas = 2; // gas/tpc layer + static constexpr int kLayerTOF = 3; // TOF layer type (not used in tracking) + static constexpr int kLayerSiliconDisk = 4; // silicon disk private: // TString for holding name @@ -127,6 +156,8 @@ struct DetLayer { // layer type int mType{0}; // 0: undefined/inert, 1: silicon, 2: gas/tpc + + float mDiskROuter{-1.f}; // outer radius for silicon disks, if applicable }; } // namespace o2::fastsim diff --git a/ALICE3/Core/FastTracker.cxx b/ALICE3/Core/FastTracker.cxx index 84b018d1540..da87469f4b4 100644 --- a/ALICE3/Core/FastTracker.cxx +++ b/ALICE3/Core/FastTracker.cxx @@ -41,6 +41,7 @@ #include +#include #include #include #include @@ -52,18 +53,143 @@ namespace o2::fastsim { +FastTracker::SiliconLayerHits FastTracker::countSiliconLayerHits(const o2::track::TrackParCov& track) const +{ + SiliconLayerHits result; + std::array position{}; + track.getXYZGlo(position); + const double x = position[0], y = position[1], z = position[2]; + const double phi = track.getPhi(), tgl = track.getTgl(), curvature = track.getCurvature(magneticField); + if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(z) || + !std::isfinite(phi) || !std::isfinite(tgl) || !std::isfinite(curvature)) { + LOG(error) << "Cannot count silicon layer hits for non-finite track parameters"; + result.count = -1; + return result; + } + const double ux = std::cos(phi), uy = std::sin(phi); + constexpr double MinCurvature = 1.e-8; + constexpr double TwoPi = 6.2831853071795864769; + + for (const auto& layer : layers) { + if (!layer.isSilicon() && !layer.isSiliconDisk()) { + continue; + } + if (layer.isSiliconDisk()) { + const double diskZ = layer.getDiskZ(); + const double rMin = layer.getDiskInnerRadius(); + const double rMax = layer.getDiskOuterRadius(); + if (!std::isfinite(diskZ) || !std::isfinite(rMin) || !std::isfinite(rMax) || + rMin < 0. || rMax < rMin) { + LOG(fatal) << "Invalid silicon disk geometry: " << layer; + continue; + } + if (std::abs(tgl) < 1.e-12) { + continue; + } + const double distance = (diskZ - z) / tgl; + if (distance < 0.) { + continue; + } + if (std::abs(curvature) >= MinCurvature) { + if (distance > TwoPi / std::abs(curvature)) { + continue; + } + } + + const double cx = std::abs(curvature) < MinCurvature ? x : x - uy / curvature; + const double cy = std::abs(curvature) < MinCurvature ? y : y + ux / curvature; + const double startTheta = std::atan2(y - cy, x - cx); + const double diskX = std::abs(curvature) < MinCurvature ? x + ux * distance : cx + std::cos(startTheta + curvature * distance) / std::abs(curvature); + const double diskY = std::abs(curvature) < MinCurvature ? y + uy * distance : cy + std::sin(startTheta + curvature * distance) / std::abs(curvature); + const double hitRadius = std::hypot(diskX, diskY); + if (hitRadius >= rMin && hitRadius <= rMax) { + ++result.count; + result.innerRadius = result.innerRadius < 0.f ? static_cast(rMin) : std::min(result.innerRadius, static_cast(rMin)); + result.outerRadius = std::max(result.outerRadius, static_cast(rMax)); + } + continue; + } + const double r = layer.getRadius(); + const double halfLength = layer.getZ(); + if (!std::isfinite(r) || !std::isfinite(halfLength) || r <= 0. || halfLength < 0.) { + LOG(fatal) << "Invalid silicon layer geometry: " << layer; + continue; + } + bool reached = false; + if (std::abs(curvature) < MinCurvature) { + const double projection = x * ux + y * uy; + const double discriminant = projection * projection + r * r - x * x - y * y; + if (discriminant >= 0.) { + const double root = std::sqrt(discriminant); + for (const double distance : {-projection - root, -projection + root}) { + if (distance >= 0. && std::abs(z + distance * tgl) <= halfLength) { + reached = true; + break; + } + } + } + } else { + const double cx = x - uy / curvature, cy = y + ux / curvature; + const double trackRadius = 1. / std::abs(curvature); + const double centerDistance = std::hypot(cx, cy); + if (centerDistance < 1.e-10 && std::abs(trackRadius - r) < 1.e-5) { + const double endZ = z + TwoPi * trackRadius * tgl; + reached = std::min(z, endZ) <= halfLength && std::max(z, endZ) >= -halfLength; + } else if (centerDistance > 0. && centerDistance <= trackRadius + r && + centerDistance >= std::abs(trackRadius - r)) { + const double along = (r * r + centerDistance * centerDistance - trackRadius * trackRadius) / (2. * centerDistance); + const double perpendicular = std::sqrt(std::max(0., r * r - along * along)); + const double nx = cx / centerDistance, ny = cy / centerDistance; + const double startX = x - cx, startY = y - cy; + for (const double sign : {-1., 1.}) { + const double ix = along * nx - sign * perpendicular * ny; + const double iy = along * ny + sign * perpendicular * nx; + const double vx = ix - cx, vy = iy - cy; + double angle = std::atan2(startX * vy - startY * vx, startX * vx + startY * vy); + if (std::hypot(ix - x, iy - y) < 1.e-5) { + angle = 0.; + } + if (curvature < 0.) { + angle = -angle; + } + if (angle < 0.) { + angle += TwoPi; + } + const double distance = angle / std::abs(curvature); + if (std::abs(z + distance * tgl) <= halfLength) { + reached = true; + break; + } + } + } + } + if (reached) { + ++result.count; + if (result.innerRadius < 0.f || r < result.innerRadius) { + result.innerRadius = r; + } + result.outerRadius = std::max(result.outerRadius, static_cast(r)); + } + } + return result; +} + // +-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+ DetLayer* FastTracker::addLayer(const TString& name, float r, float z, float x0, float xrho, float resRPhi, float resZ, float eff, int type) { LOG(debug) << "Adding layer " << name << " r=" << r << " z=" << z << " x0=" << x0 << " xrho=" << xrho << " resRPhi=" << resRPhi << " resZ=" << resZ << " eff=" << eff << " type=" << type; DetLayer newLayer(name, r, z, x0, xrho, resRPhi, resZ, eff, type); + if (newLayer.isSiliconDisk()) { + newLayer.setSiliconDiskAcceptance(r, r, z); + } // Check that efficient layers are not inert layers if (newLayer.getEfficiency() > 0.0f && newLayer.isInert()) { LOG(error) << "Layer " << name << " with efficiency > 0.0 should not be inert"; } // Layers should be ordered by increasing radius, check this - if (!layers.empty() && newLayer.getRadius() < layers.back().getRadius()) { + if (!layers.empty() && !newLayer.isSiliconDisk() && !layers.back().isSiliconDisk() && + newLayer.getRadius() < layers.back().getRadius()) { LOG(fatal) << "Layer " << newLayer << " is not ordered correctly, it should be after layer " << layers.back(); } // Layers should all have different names @@ -180,6 +306,10 @@ void FastTracker::addGenericDetector(const o2::fastsim::GeometryEntry& configMap LOG(info) << " Adding layer " << layer << " r=" << r << " z=" << z << " x0=" << x0 << " xrho=" << xrho << " resRPhi=" << resRPhi << " resZ=" << resZ << " eff=" << eff << " type=" << type << " deadPhiRegions=" << deadPhiRegions; DetLayer* addedLayer = addLayer(layer.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type); + if (type == DetLayer::kLayerSiliconDisk) { + const float rMax = configMap.getFloatValue(layer, "diskOuterRadius"); + addedLayer->setSiliconDiskAcceptance(r, rMax, z); + } if (!deadPhiRegions.empty()) { // Taking it as ccdb path or local file // Check if it begins with ccdb: if (deadPhiRegions.starts_with("ccdb:")) { diff --git a/ALICE3/Core/FastTracker.h b/ALICE3/Core/FastTracker.h index 0366c0cf443..7f3748b8a69 100644 --- a/ALICE3/Core/FastTracker.h +++ b/ALICE3/Core/FastTracker.h @@ -101,6 +101,16 @@ class FastTracker */ int fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackParCov& outputTrack, const float nch, const float maxRadius = 100.f); + struct SiliconLayerHits { + int count = 0; + float innerRadius = -1.f; + float outerRadius = -1.f; + }; + /// Count distinct silicon cylinders and disks crossed in the first turn of + /// the ideal production helix, including their longitudinal/radial acceptance. + /// Material, dead regions and layer efficiencies are not applied. count is -1 on error. + [[nodiscard]] SiliconLayerHits countSiliconLayerHits(const o2::track::TrackParCov& track) const; + // For efficiency calculation float dist(float z, float radius); float oneEventHitDensity(float multiplicity, float radius); diff --git a/ALICE3/Core/SecondaryLut.cxx b/ALICE3/Core/SecondaryLut.cxx new file mode 100644 index 00000000000..c3520567df0 --- /dev/null +++ b/ALICE3/Core/SecondaryLut.cxx @@ -0,0 +1,208 @@ +// 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 SecondaryLut.cxx +/// \brief ROOT-persistent LUT for secondary particles. + +#include "ALICE3/Core/SecondaryLut.h" + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +namespace o2::fastsim +{ + +namespace +{ +constexpr std::array kDimNames = {"nch", "eta", "pt", "nHits"}; +} + +int SecondaryLutAxis::find(float val) const +{ + if (log) { + val = val > 0.f ? std::log10(val) : min; + } + const int bin = static_cast(std::floor((val - min) / (max - min) * nbins)); + return std::clamp(bin, 0, nbins - 1); +} + +float SecondaryLutAxis::lowEdge(int bin) const +{ + const float v = min + bin * (max - min) / nbins; + return log ? std::pow(10.f, v) : v; +} + +float SecondaryLutAxis::upEdge(int bin) const { return lowEdge(bin + 1); } + +float SecondaryLutAxis::center(int bin) const +{ + const float v = min + (bin + 0.5f) * (max - min) / nbins; + return log ? std::pow(10.f, v) : v; +} + +SecondaryLut::SecondaryLut(const char* name, int pdg, float mass, float field) + : TNamed(name, "Secondary particle LUT"), mPdg(pdg), mMass(mass), mField(field) +{ +} + +void SecondaryLut::setAxis(Dim dim, int nbins, float min, float max, bool log) +{ + mAxes[dim] = {.nbins = std::max(nbins, 1), .min = min, .max = max, .log = log}; + mEntries.clear(); +} + +void SecondaryLut::init() +{ + std::size_t n = 1; + for (const auto& a : mAxes) { + n *= static_cast(a.nbins); + } + mEntries.assign(n, SecondaryLutEntry{}); +} + +const SecondaryLutEntry* SecondaryLut::lookup(float nch, float eta, float pt, float nHits) const +{ + if (mEntries.empty()) { + return nullptr; + } + return &mEntries[index(mAxes[kNch].find(nch), mAxes[kEta].find(eta), mAxes[kPt].find(pt), mAxes[kNHits].find(nHits))]; +} + +bool SecondaryLut::writeToFile(const char* fileName, const char* option) const +{ + std::unique_ptr f(TFile::Open(fileName, option)); + if (!f || f->IsZombie()) { + return false; + } + const auto written = f->WriteObject(this, GetName()); + return written > 0 && !f->IsZombie(); +} + +SecondaryLut* SecondaryLut::readFromFile(const char* fileName, const char* objName) +{ + std::unique_ptr f(TFile::Open(fileName, "READ")); + if (!f || f->IsZombie()) { + return nullptr; + } + auto* in = f->Get(objName); + return in ? new SecondaryLut(*in) : nullptr; +} + +void SecondaryLut::unravel(std::size_t idx, std::array& bins) const +{ + // Reverse of index(): pt fastest, then hits, eta, nch + static constexpr std::array order = {kPt, kNHits, kEta, kNch}; + for (const Dim d : order) { + bins[d] = static_cast(idx % mAxes[d].nbins); + idx /= mAxes[d].nbins; + } +} + +TTree* SecondaryLut::toTree(const char* treeName) const +{ + auto* tree = new TTree(treeName, "Secondary LUT flat view"); + tree->SetDirectory(nullptr); + std::array bins{}; + std::array centers{}; + SecondaryLutEntry e; + for (int d = 0; d < kNDims; ++d) { + tree->Branch(Form("%sBin", kDimNames[d]), &bins[d]); + tree->Branch(kDimNames[d], ¢ers[d]); + } + tree->Branch("valid", &e.valid); + tree->Branch("eff", &e.eff); + tree->Branch("eff2", &e.eff2); + tree->Branch("itof", &e.itof); + tree->Branch("otof", &e.otof); + tree->Branch("covm", e.covm.data(), "covm[15]/F"); + tree->Branch("eigval", e.eigval.data(), "eigval[5]/F"); + tree->Branch("eigvec", e.eigvec.data(), "eigvec[25]/F"); + tree->Branch("eiginv", e.eiginv.data(), "eiginv[25]/F"); + for (std::size_t i = 0; i < mEntries.size(); ++i) { + unravel(i, bins); + for (int d = 0; d < kNDims; ++d) { + centers[d] = mAxes[d].center(bins[d]); + } + e = mEntries[i]; + tree->Fill(); + } + tree->ResetBranchAddresses(); + return tree; +} + +TH1D* SecondaryLut::projectEfficiency(Dim dim, const char* histName) const +{ + const auto& ax = mAxes[dim]; + std::vector edges(ax.nbins + 1); + for (int i = 0; i <= ax.nbins; ++i) { + edges[i] = ax.lowEdge(i); + } + auto* h = new TH1D(histName ? histName : Form("%s_eff_vs_%s", GetName(), kDimNames[dim]), + Form("Average efficiency vs %s;%s;", kDimNames[dim], kDimNames[dim]), + ax.nbins, edges.data()); + h->SetDirectory(nullptr); + std::vector sum(ax.nbins, 0.), cnt(ax.nbins, 0.); + std::array bins{}; + for (std::size_t i = 0; i < mEntries.size(); ++i) { + if (!mEntries[i].valid) { + continue; + } + unravel(i, bins); + sum[bins[dim]] += mEntries[i].eff; + cnt[bins[dim]] += 1.; + } + for (int b = 0; b < ax.nbins; ++b) { + h->SetBinContent(b + 1, cnt[b] > 0. ? sum[b] / cnt[b] : 0.); + } + return h; +} + +void SecondaryLut::Print(Option_t*) const +{ + std::printf("SecondaryLut '%s': pdg=%d mass=%g field=%g entries=%zu (%.2f MB)\n", GetName(), mPdg, mMass, mField, + mEntries.size(), mEntries.size() * sizeof(SecondaryLutEntry) / 1.e6); + for (int d = 0; d < kNDims; ++d) { + const auto& a = mAxes[d]; + std::printf(" %-6s nbins=%-4d [%g, %g]%s\n", kDimNames[d], a.nbins, a.min, a.max, a.log ? " (log10)" : ""); + } + std::size_t nvalid = 0; + for (const auto& e : mEntries) { + nvalid += static_cast(e.valid); + } + std::printf(" valid bins: %zu\n", nvalid); +} + +void SecondaryLut::Browse(TBrowser* b) +{ + if (!b || mEntries.empty()) { + return; + } + for (int d = 0; d < kNDims; ++d) { + auto* h = projectEfficiency(static_cast(d)); + b->Add(h, h->GetName()); + } + b->Add(toTree(), "secondaryLut"); +} + +} // namespace o2::fastsim diff --git a/ALICE3/Core/SecondaryLut.h b/ALICE3/Core/SecondaryLut.h new file mode 100644 index 00000000000..e34f8c6cce4 --- /dev/null +++ b/ALICE3/Core/SecondaryLut.h @@ -0,0 +1,148 @@ +// 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 SecondaryLut.h +/// \brief ROOT-persistent LUT for secondary particles (weak decay products), +/// binned in nch, eta, pt and the particle's number of hits. + +#ifndef ALICE3_CORE_SECONDARYLUT_H_ +#define ALICE3_CORE_SECONDARYLUT_H_ + +#include +#include + +#include +#include + +#include +#include +#include + +class TH1D; +class TTree; + +namespace o2::fastsim +{ + +/// Uniform (linear or log10) binning axis. Streamable, trivially copyable. +struct SecondaryLutAxis { + int nbins = 1; + float min = 0.f; + float max = 1.f; + bool log = false; // min/max are expressed in log10 of the variable + + /// Bin index of val, clamped to [0, nbins-1] + [[nodiscard]] int find(float val) const; + /// Bin centre in the variable's natural units + [[nodiscard]] float center(int bin) const; + /// Lower edge in the variable's natural units + [[nodiscard]] float lowEdge(int bin) const; + /// Upper edge in the variable's natural units + [[nodiscard]] float upEdge(int bin) const; + + ClassDefNV(SecondaryLutAxis, 1); +}; + +/// Payload of one bin. Plain floats only for compact and fast I/O. +struct SecondaryLutEntry { + bool valid = false; + float eff = 0.f; + float eff2 = 0.f; + float itof = 0.f; + float otof = 0.f; + std::array covm{}; + std::array eigval{}; + std::array eigvec{}; // row-major 5x5 + std::array eiginv{}; // row-major 5x5 + + ClassDefNV(SecondaryLutEntry, 1); +}; + +/// LUT for secondary particles. Entries are stored in one contiguous vector with +/// layout index = (((nch * nEta + eta) * nHits + hits) * nPt + pt), +/// pt varying fastest. Can be written to / read from a ROOT file and inspected +/// with Print(), Browse(), toTree() and projectEfficiency(). +class SecondaryLut : public TNamed +{ + public: + enum Dim : int { kNch = 0, + kEta, + kPt, + kNHits, + kNDims }; + + SecondaryLut() = default; + SecondaryLut(const char* name, int pdg, float mass, float field); + + /// Set the binning of one dimension. Must be called before init(). + void setAxis(Dim dim, int nbins, float min, float max, bool log = false); + [[nodiscard]] const SecondaryLutAxis& getAxis(Dim dim) const { return mAxes[dim]; } + + /// Allocate (zero-initialised) storage for all bins + void init(); + [[nodiscard]] bool isInitialized() const { return !mEntries.empty(); } + + [[nodiscard]] int getPdg() const { return mPdg; } + [[nodiscard]] float getMass() const { return mMass; } + [[nodiscard]] float getField() const { return mField; } + [[nodiscard]] std::size_t size() const { return mEntries.size(); } + + [[nodiscard]] std::size_t index(int nch, int eta, int pt, int nHits) const + { + const auto& a = mAxes; + return ((static_cast(nch) * a[kEta].nbins + eta) * a[kNHits].nbins + nHits) * a[kPt].nbins + pt; + } + + /// Direct bin access (no bounds clamping) + SecondaryLutEntry& at(int nch, int eta, int pt, int nHits) + { + return mEntries[index(nch, eta, pt, nHits)]; + } + [[nodiscard]] const SecondaryLutEntry& at(int nch, int eta, int pt, int nHits) const + { + return mEntries[index(nch, eta, pt, nHits)]; + } + + /// Lookup by physical values; out-of-range values are clamped to edge bins. + /// Returns nullptr if the LUT is not initialised. + [[nodiscard]] const SecondaryLutEntry* lookup(float nch, float eta, float pt, float nHits) const; + + [[nodiscard]] const std::vector& entries() const { return mEntries; } + + /// Write to a ROOT file (object stored under its own name) + bool writeToFile(const char* fileName, const char* option = "RECREATE") const; + /// Read from a ROOT file; returns nullptr on failure. Caller owns the result. + static SecondaryLut* readFromFile(const char* fileName, const char* objName = "SecondaryLut"); + + /// Flat TTree with one row per bin (bin indices, bin centres and payload) + [[nodiscard]] TTree* toTree(const char* treeName = "secondaryLut") const; + /// Efficiency (average over valid bins) projected on one dimension. Caller owns the result. + [[nodiscard]] TH1D* projectEfficiency(Dim dim, const char* histName = nullptr) const; + + void Print(Option_t* option = "") const override; + void Browse(TBrowser* b) override; + [[nodiscard]] Bool_t IsFolder() const override { return kTRUE; } + + private: + void unravel(std::size_t idx, std::array& bins) const; + + int mPdg = 0; + float mMass = 0.f; + float mField = 0.f; + std::array mAxes; + std::vector mEntries; + + ClassDefOverride(SecondaryLut, 1); +}; + +} // namespace o2::fastsim + +#endif // ALICE3_CORE_SECONDARYLUT_H_ diff --git a/ALICE3/Core/SecondaryTrackSmearer.cxx b/ALICE3/Core/SecondaryTrackSmearer.cxx new file mode 100644 index 00000000000..3af72b7dea5 --- /dev/null +++ b/ALICE3/Core/SecondaryTrackSmearer.cxx @@ -0,0 +1,306 @@ +// 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 "ALICE3/Core/SecondaryTrackSmearer.h" + +#include "ALICE3/Core/ConfigurationParser.h" +#include "ALICE3/Core/GeometryContainer.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace o2::fastsim +{ + +namespace +{ +int particleKey(int pdg) +{ + const auto magnitude = std::abs(static_cast(pdg)); + return magnitude <= std::numeric_limits::max() ? static_cast(magnitude) : 0; +} + +float clampToAxis(const SecondaryLutAxis& axis, float value) +{ + return std::clamp(value, axis.lowEdge(0), axis.upEdge(axis.nbins - 1)); +} +} // namespace + +bool SecondaryTrackSmearer::loadTable(int pdg, const char* filename, bool forceReload, const char* objectName) +{ + if (!filename || !filename[0] || !objectName || !objectName[0]) { + LOGF(error, "A filename and object name are required for secondary LUT PDG %d", pdg); + return false; + } + if (particleKey(pdg) == 0) { + LOGF(error, "Invalid secondary LUT PDG %d", pdg); + return false; + } + if (hasTable(pdg) && !forceReload) { + LOGF(info, "Secondary LUT for PDG %d already loaded", pdg); + return false; + } + const std::string path(filename); + if (path.rfind("ccdb:", 0) == 0 && !mCcdbManager) { + LOGF(error, "A CCDB manager is required to load secondary LUT %s", filename); + return false; + } + const auto localFile = ConfigurationParser::accessFile(path, "./.ALICE3/LUTs/", mCcdbManager, + GeometryContainer::cleanLutWhenLoaded() ? 10 : 0); + std::unique_ptr table(SecondaryLut::readFromFile(localFile.c_str(), objectName)); + if (!table) { + LOGF(error, "Cannot read secondary LUT object '%s' from '%s'", objectName, localFile.c_str()); + return false; + } + return installTable(pdg, std::move(table), forceReload); +} + +bool SecondaryTrackSmearer::adoptTable(int pdg, const SecondaryLut& table, bool forceReload) +{ + if (hasTable(pdg) && !forceReload) { + LOGF(info, "Secondary LUT for PDG %d already loaded", pdg); + return false; + } + return installTable(pdg, std::make_unique(table), forceReload); +} + +bool SecondaryTrackSmearer::installTable(int pdg, std::unique_ptr table, bool forceReload) +{ + const int key = particleKey(pdg); + const int tableKey = particleKey(table->getPdg()); + if (key == 0 || (key != tableKey && !(key == o2::constants::physics::kAlpha && tableKey == o2::constants::physics::kHelium3))) { + LOGF(error, "Secondary LUT PDG mismatch: requested %d, table has %d", pdg, table->getPdg()); + return false; + } + if (hasTable(pdg) && !forceReload) { + LOGF(info, "Secondary LUT for PDG %d already loaded", pdg); + return false; + } + std::size_t expectedSize = 1; + for (int d = 0; d < SecondaryLut::kNDims; ++d) { + const auto& axis = table->getAxis(static_cast(d)); + if (axis.nbins <= 0 || !std::isfinite(axis.min) || !std::isfinite(axis.max) || + !std::isfinite(axis.max - axis.min) || axis.max <= axis.min || + !std::isfinite(axis.lowEdge(0)) || !std::isfinite(axis.upEdge(axis.nbins - 1)) || + (axis.log && axis.lowEdge(0) <= 0.f) || + expectedSize > std::numeric_limits::max() / static_cast(axis.nbins)) { + LOGF(error, "Invalid axis %d in secondary LUT for PDG %d", d, pdg); + return false; + } + expectedSize *= static_cast(axis.nbins); + } + if (!table->isInitialized() || table->size() != expectedSize) { + LOGF(error, "Invalid entry count in secondary LUT for PDG %d", pdg); + return false; + } + mTables[key] = std::move(table); + LOGF(info, "Loaded secondary LUT for PDG %d", pdg); + return true; +} + +bool SecondaryTrackSmearer::hasTable(int pdg) const +{ + return getLUT(pdg) != nullptr; +} + +const SecondaryLut* SecondaryTrackSmearer::getLUT(int pdg) const +{ + const auto it = mTables.find(particleKey(pdg)); + return it == mTables.end() ? nullptr : it->second.get(); +} + +void SecondaryTrackSmearer::setWhatEfficiency(EfficiencyType value) +{ + if (value != kWhatEfficiencyReco && value != kWhatEfficiencyRecoAndTOF) { + throw std::invalid_argument("Unknown secondary LUT efficiency type"); + } + mWhatEfficiency = value; + mSmearer.setWhatEfficiency(value); +} + +float SecondaryTrackSmearer::efficiency(const SecondaryLutEntry& entry) const +{ + return mWhatEfficiency == kWhatEfficiencyReco ? entry.eff : entry.eff2; +} + +const SecondaryLutEntry* SecondaryTrackSmearer::getLUTEntry(int pdg, float nch, float eta, float pt, int nHits, float& interpolatedEff) const +{ + interpolatedEff = std::numeric_limits::quiet_NaN(); + const auto* table = getLUT(pdg); + if (!table) { + LOGF(warn, "No secondary LUT loaded for PDG %d", pdg); + return nullptr; + } + if (nHits < 0 || !std::isfinite(nch) || !std::isfinite(eta) || !std::isfinite(pt)) { + LOGF(error, "Invalid secondary LUT lookup values for PDG %d", pdg); + return nullptr; + } + nch = clampToAxis(table->getAxis(SecondaryLut::kNch), nch); + eta = clampToAxis(table->getAxis(SecondaryLut::kEta), eta); + pt = clampToAxis(table->getAxis(SecondaryLut::kPt), pt); + const float hits = clampToAxis(table->getAxis(SecondaryLut::kNHits), static_cast(nHits)); + const auto* entry = table->lookup(nch, eta, pt, hits); + interpolatedEff = efficiency(*entry); + if (!mInterpolateEfficiency || !entry->valid) { + return entry; + } + + const auto& axis = table->getAxis(SecondaryLut::kNch); + const float value = axis.log ? (nch > 0.f ? std::log10(nch) : axis.min) : nch; + const float position = std::clamp((value - axis.min) / (axis.max - axis.min) * axis.nbins - 0.5f, 0.f, static_cast(axis.nbins - 1)); + const int lower = static_cast(position); + const int upper = std::min(lower + 1, axis.nbins - 1); + const int ieta = table->getAxis(SecondaryLut::kEta).find(eta); + const int ipt = table->getAxis(SecondaryLut::kPt).find(pt); + const int ihits = table->getAxis(SecondaryLut::kNHits).find(hits); + const auto& low = table->at(lower, ieta, ipt, ihits); + const auto& high = table->at(upper, ieta, ipt, ihits); + if (!low.valid || !high.valid) { + LOGF(warn, "Cannot interpolate secondary LUT efficiency across an invalid bin for PDG %d", pdg); + return entry; + } + const float fraction = position - lower; + interpolatedEff = (1.f - fraction) * efficiency(low) + fraction * efficiency(high); + return entry; +} + +bool SecondaryTrackSmearer::smearTrack(O2Track& track, const SecondaryLutEntry* entry, float interpolatedEff, bool* wasSmeared) +{ + if (wasSmeared) { + *wasSmeared = false; + } + if (!entry || !entry->valid) { + LOG(warn) << "Cannot smear a track with a missing or invalid secondary LUT entry"; + return false; + } + const float selectedEfficiency = mInterpolateEfficiency ? interpolatedEff : efficiency(*entry); + if (mUseEfficiency && (!std::isfinite(selectedEfficiency) || selectedEfficiency < 0.f || selectedEfficiency > 1.f)) { + LOG(error) << "Cannot smear a track with an invalid efficiency"; + return false; + } + const auto finite = [](float value) { return std::isfinite(value); }; + if (!std::all_of(entry->covm.begin(), entry->covm.end(), finite) || + !std::all_of(entry->eigval.begin(), entry->eigval.end(), finite) || + !std::all_of(entry->eigvec.begin(), entry->eigvec.end(), finite) || + !std::all_of(entry->eiginv.begin(), entry->eiginv.end(), finite)) { + LOG(error) << "Cannot smear a track with non-finite secondary LUT parameters"; + return false; + } + lutEntry_t flatEntry; + flatEntry.valid = entry->valid; + flatEntry.eff = entry->eff; + flatEntry.eff2 = entry->eff2; + flatEntry.covm = entry->covm; + flatEntry.eigval = entry->eigval; + for (int i = 0; i < kNumEigenModes; ++i) { + for (int j = 0; j < kNumEigenModes; ++j) { + flatEntry.eigvec[i][j] = entry->eigvec[i * kNumEigenModes + j]; + flatEntry.eiginv[i][j] = entry->eiginv[i * kNumEigenModes + j]; + } + } + const bool reconstructed = mSmearer.smearTrack(track, &flatEntry, interpolatedEff); + if (wasSmeared) { + *wasSmeared = reconstructed || !mSkipUnreconstructed; + } + return reconstructed; +} + +bool SecondaryTrackSmearer::smearTrack(O2Track& track, int pdg, float nch, int nHits, bool* wasSmeared) +{ + float pt = track.getPt(); + const auto key = particleKey(pdg); + if (key == o2::constants::physics::kHelium3 || key == o2::constants::physics::kAlpha) { + pt *= 2.f; + } + float interpolatedEff; + const auto* entry = getLUTEntry(pdg, nch, track.getEta(), pt, nHits, interpolatedEff); + return smearTrack(track, entry, interpolatedEff, wasSmeared); +} + +double SecondaryTrackSmearer::getEfficiency(int pdg, float nch, float eta, float pt, int nHits) const +{ + float result; + const auto* entry = getLUTEntry(pdg, nch, eta, pt, nHits, result); + if (!entry || !entry->valid || !std::isfinite(result) || result < 0.f || result > 1.f) { + LOGF(warn, "No valid secondary LUT efficiency for PDG %d", pdg); + return std::numeric_limits::quiet_NaN(); + } + return result; +} + +double SecondaryTrackSmearer::getPtRes(int pdg, float nch, float eta, float pt, int nHits) const +{ + float ignored; + const auto* entry = getLUTEntry(pdg, nch, eta, pt, nHits, ignored); + if (!entry || !entry->valid) { + LOGF(warn, "No valid secondary LUT resolution for PDG %d", pdg); + return std::numeric_limits::quiet_NaN(); + } + if (!std::isfinite(entry->covm[14]) || entry->covm[14] < 0.f) { + LOGF(error, "Invalid inverse-pT variance in secondary LUT for PDG %d", pdg); + return std::numeric_limits::quiet_NaN(); + } + const auto& axis = getLUT(pdg)->getAxis(SecondaryLut::kPt); + return std::sqrt(entry->covm[14]) * axis.center(axis.find(clampToAxis(axis, pt))); +} + +double SecondaryTrackSmearer::getAbsPtRes(int pdg, float nch, float eta, float pt, int nHits) const +{ + const double relative = getPtRes(pdg, nch, eta, pt, nHits); + if (!std::isfinite(relative)) { + return relative; + } + const auto& axis = getLUT(pdg)->getAxis(SecondaryLut::kPt); + return relative * axis.center(axis.find(clampToAxis(axis, pt))); +} + +double SecondaryTrackSmearer::getAbsEtaRes(int pdg, float nch, float eta, float pt, int nHits) const +{ + float ignored; + const auto* entry = getLUTEntry(pdg, nch, eta, pt, nHits, ignored); + if (!entry || !entry->valid) { + LOGF(warn, "No valid secondary LUT resolution for PDG %d", pdg); + return std::numeric_limits::quiet_NaN(); + } + if (!std::isfinite(entry->covm[9]) || entry->covm[9] < 0.f) { + LOGF(error, "Invalid tan(lambda) variance in secondary LUT for PDG %d", pdg); + return std::numeric_limits::quiet_NaN(); + } + return std::fabs(std::sin(2.0 * std::atan(std::exp(-eta)))) * std::sqrt(entry->covm[9]); +} + +double SecondaryTrackSmearer::getEtaRes(int pdg, float nch, float eta, float pt, int nHits) const +{ + const double absolute = getAbsEtaRes(pdg, nch, eta, pt, nHits); + if (!std::isfinite(absolute)) { + return absolute; + } + const auto& axis = getLUT(pdg)->getAxis(SecondaryLut::kEta); + const float binEta = axis.center(axis.find(clampToAxis(axis, eta))); + if (binEta == 0.f) { + LOGF(warn, "Cannot compute relative eta resolution for zero eta bin center (PDG %d)", pdg); + return std::numeric_limits::quiet_NaN(); + } + return absolute / binEta; +} + +} // namespace o2::fastsim diff --git a/ALICE3/Core/SecondaryTrackSmearer.h b/ALICE3/Core/SecondaryTrackSmearer.h new file mode 100644 index 00000000000..8ff04fcc405 --- /dev/null +++ b/ALICE3/Core/SecondaryTrackSmearer.h @@ -0,0 +1,87 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +#ifndef ALICE3_CORE_SECONDARYTRACKSMEARER_H_ +#define ALICE3_CORE_SECONDARYTRACKSMEARER_H_ + +#include "ALICE3/Core/FlatTrackSmearer.h" +#include "ALICE3/Core/SecondaryLut.h" + +#include +#include + +namespace o2::fastsim +{ + +/// Track smearing using ROOT-persistent secondary-particle LUTs. +class SecondaryTrackSmearer +{ + public: + using EfficiencyType = TrackSmearer::EfficiencyType; + static constexpr EfficiencyType kWhatEfficiencyReco = TrackSmearer::kWhatEfficiencyReco; + static constexpr EfficiencyType kWhatEfficiencyRecoAndTOF = TrackSmearer::kWhatEfficiencyRecoAndTOF; + + /// Load an object from a ROOT file (a local path or a ccdb: path). + bool loadTable(int pdg, const char* filename, bool forceReload = false, const char* objectName = "SecondaryLut"); + /// Copy an in-memory table; subsequent changes to the original do not affect the smearer. + bool adoptTable(int pdg, const SecondaryLut& table, bool forceReload = false); + [[nodiscard]] bool hasTable(int pdg) const; + [[nodiscard]] const SecondaryLut* getLUT(int pdg) const; + + void useEfficiency(bool value) + { + mUseEfficiency = value; + mSmearer.useEfficiency(value); + } + void interpolateEfficiency(bool value) + { + mInterpolateEfficiency = value; + mSmearer.interpolateEfficiency(value); + } + void skipUnreconstructed(bool value) + { + mSkipUnreconstructed = value; + mSmearer.skipUnreconstructed(value); + } + void setWhatEfficiency(EfficiencyType value); + void setCcdbManager(o2::ccdb::BasicCCDBManager* manager) { mCcdbManager = manager; } + + /// Lookup clamps each coordinate to the table range; nHits must be nonnegative. + /// The returned pointer is invalidated when its table is reloaded or destroyed. + [[nodiscard]] const SecondaryLutEntry* getLUTEntry(int pdg, float nch, float eta, float pt, int nHits, float& interpolatedEff) const; + /// wasSmeared reports whether the track was modified, including rejected + /// tracks when skipUnreconstructed is false. + bool smearTrack(O2Track& track, const SecondaryLutEntry* entry, float interpolatedEff, bool* wasSmeared = nullptr); + bool smearTrack(O2Track& track, int pdg, float nch, int nHits, bool* wasSmeared = nullptr); + + /// Queries return NaN if no valid entry is available. + [[nodiscard]] double getEfficiency(int pdg, float nch, float eta, float pt, int nHits) const; + [[nodiscard]] double getPtRes(int pdg, float nch, float eta, float pt, int nHits) const; + [[nodiscard]] double getEtaRes(int pdg, float nch, float eta, float pt, int nHits) const; + [[nodiscard]] double getAbsPtRes(int pdg, float nch, float eta, float pt, int nHits) const; + [[nodiscard]] double getAbsEtaRes(int pdg, float nch, float eta, float pt, int nHits) const; + + private: + bool installTable(int pdg, std::unique_ptr table, bool forceReload); + [[nodiscard]] float efficiency(const SecondaryLutEntry& entry) const; + + std::unordered_map> mTables; + TrackSmearer mSmearer; + o2::ccdb::BasicCCDBManager* mCcdbManager = nullptr; + bool mUseEfficiency = true; + bool mInterpolateEfficiency = false; + bool mSkipUnreconstructed = true; + EfficiencyType mWhatEfficiency = kWhatEfficiencyReco; +}; + +} // namespace o2::fastsim + +#endif // ALICE3_CORE_SECONDARYTRACKSMEARER_H_ diff --git a/ALICE3/Macros/Configuration/a3geometry_v3.ini b/ALICE3/Macros/Configuration/a3geometry_v3.ini index 3381df08209..6bbba72a1fe 100644 --- a/ALICE3/Macros/Configuration/a3geometry_v3.ini +++ b/ALICE3/Macros/Configuration/a3geometry_v3.ini @@ -156,6 +156,15 @@ oTOF.eff: 1.00 oTOF.type: 3 # Lookup tables +# For useSecondaryLUT=true and enableSecondarySmearing=true, configure a ROOT +# SecondaryLut object for each secondary species encountered, for example: +# global.secondaryLutPi: /path/to/secondary-pion.root +# global.secondaryLutPr: /path/to/secondary-proton.root +# Other keys: secondaryLutEl, Mu, Ka, De, Tr, He3 and Al (all prefixed by global.). +# The LUT uses nch, eta, pt and nHits. nHits counts distinct silicon cylinders +# and disks reached in the first ideal-helix turn within their acceptance. +# Detector efficiency and dead regions are not applied to that geometric count. +# All configured geometries must use the same global.magneticfield. global.lutEl: ccdb:/Users/j/jekarlss/LUTs/v3/b/el global.lutMu: ccdb:/Users/j/jekarlss/LUTs/v3/b/mu global.lutPi: ccdb:/Users/j/jekarlss/LUTs/v3/b/pi diff --git a/ALICE3/TableProducer/OTF/onTheFlyTracker.cxx b/ALICE3/TableProducer/OTF/onTheFlyTracker.cxx index d958418952d..2d0409ffd53 100644 --- a/ALICE3/TableProducer/OTF/onTheFlyTracker.cxx +++ b/ALICE3/TableProducer/OTF/onTheFlyTracker.cxx @@ -29,6 +29,7 @@ #include "ALICE3/Core/FlatTrackSmearer.h" #include "ALICE3/Core/GeometryContainer.h" #include "ALICE3/Core/OTFParticle.h" +#include "ALICE3/Core/SecondaryTrackSmearer.h" #include "ALICE3/Core/TrackUtilities.h" #include "ALICE3/DataModel/OTFCollision.h" #include "ALICE3/DataModel/OTFStrangeness.h" @@ -147,6 +148,7 @@ struct OnTheFlyTracker { Configurable minPt{"minPt", 0.1, "minimum pt to consider viable"}; Configurable enablePrimarySmearing{"enablePrimarySmearing", false, "Enable smearing of primary particles"}; Configurable enableSecondarySmearing{"enableSecondarySmearing", false, "Enable smearing of weak decay daughters"}; + Configurable useSecondaryLUT{"useSecondaryLUT", false, "Use secondary ROOT LUTs instead of FastTracker for weak decay daughters"}; Configurable enableNucleiSmearing{"enableNucleiSmearing", false, "Enable smearing of nuclei"}; Configurable enablePrimaryVertexing{"enablePrimaryVertexing", true, "Enable primary vertexing"}; Configurable primaryVertexOption{"primaryVertexOption", "pvertexer.maxChi2TZDebris=10;pvertexer.acceptableScale2=9;pvertexer.minScale2=2;pvertexer.timeMarginVertexTime=1.3;;pvertexer.maxChi2TZDebris=40;pvertexer.maxChi2Mean=12;pvertexer.maxMultRatDebris=1.;pvertexer.addTimeSigma2Debris=1e-2;pvertexer.meanVertexExtraErrSelection=0.03;", "Option for the primary vertexer"}; @@ -381,6 +383,7 @@ struct OnTheFlyTracker { // Track smearer array, one per geometry std::vector> mSmearer; + std::vector> mSecondarySmearer; // Configuration defined at init time o2::fastsim::GeometryContainer mGeoContainer; float mMagneticField = 0.0f; @@ -430,6 +433,29 @@ struct OnTheFlyTracker { histPointers[name] = histos.add(name.c_str(), title.c_str(), type, axisSpecs); } + bool smearSecondaryWithLUT(const o2::track::TrackParCov& productionTrack, + o2::track::TrackParCov& track, + int pdg, float dNdEta, int& nHits, + std::array& hitRadii, bool* wasSmeared = nullptr) + { + if (wasSmeared) { + *wasSmeared = false; + } + const auto& smearer = mSecondarySmearer[icfg]; + if (!smearer->hasTable(pdg)) { + LOG(fatal) << "No secondary LUT configured for PDG " << pdg << " in geometry " << icfg; + return false; + } + const auto hits = fastTracker[icfg]->countSiliconLayerHits(productionTrack); + if (hits.count < 0) { + LOG(error) << "Failed to count secondary silicon hits for PDG " << pdg; + return false; + } + nHits = hits.count; + hitRadii = {hits.innerRadius, hits.outerRadius}; + return smearer->smearTrack(track, pdg, dNdEta, nHits, wasSmeared); + } + void init(o2::framework::InitContext& initContext) { LOG(info) << "Initializing OnTheFlyTracker task"; @@ -438,14 +464,54 @@ struct OnTheFlyTracker { mGeoContainer.setCcdbManager(ccdb.operator->()); mGeoContainer.init(initContext); + if (useSecondaryLUT && !enableSecondarySmearing) { + LOG(fatal) << "useSecondaryLUT requires enableSecondarySmearing"; + } const int nGeometries = mGeoContainer.getNumberOfConfigurations(); mMagneticField = mGeoContainer.getFloatValue(0, "global", "magneticfield"); decayer.setBField(mMagneticField); for (int igeo = 0; igeo < nGeometries; ++igeo) { + if (useSecondaryLUT && mGeoContainer.getFloatValue(igeo, "global", "magneticfield") != mMagneticField) { + LOG(fatal) << "Secondary LUT tracking requires the same magnetic field for all geometries"; + } const std::string histPath = "Configuration_" + std::to_string(igeo) + "/"; mSmearer.emplace_back(std::make_unique()); mSmearer[igeo]->setCcdbManager(ccdb.operator->()); std::map globalConfiguration = mGeoContainer.getConfiguration(igeo, "global"); + if (useSecondaryLUT) { + mSecondarySmearer.emplace_back(std::make_unique()); + auto& smearer = *mSecondarySmearer.back(); + smearer.setCcdbManager(ccdb.operator->()); + smearer.interpolateEfficiency(interpolateLutEfficiencyVsNch.value); + smearer.skipUnreconstructed(!processUnreconstructedTracks.value); + const std::map species = { + {"secondaryLutEl", kElectron}, {"secondaryLutMu", kMuonMinus}, {"secondaryLutPi", kPiPlus}, {"secondaryLutKa", kKPlus}, {"secondaryLutPr", kProton}, {"secondaryLutDe", o2::constants::physics::kDeuteron}, {"secondaryLutTr", o2::constants::physics::kTriton}, {"secondaryLutHe3", o2::constants::physics::kHelium3}, {"secondaryLutAl", o2::constants::physics::kAlpha}}; + int loaded = 0; + for (const auto& entry : globalConfiguration) { + if (!entry.first.starts_with("secondaryLut")) { + continue; + } + const auto found = species.find(entry.first); + if (found == species.end()) { + LOG(fatal) << "Unknown secondary LUT entry " << entry.first; + continue; + } + std::string filename = entry.second; + const auto first = filename.find_first_not_of(" \t\r\n"); + if (first == std::string::npos) { + LOG(fatal) << "Empty secondary LUT filename for " << entry.first; + continue; + } + filename = filename.substr(first, filename.find_last_not_of(" \t\r\n") - first + 1); + if (!smearer.loadTable(found->second, filename.c_str())) { + LOG(fatal) << "Failed to load secondary LUT " << entry.first << " from " << filename; + } + ++loaded; + } + if (loaded == 0) { + LOG(fatal) << "No secondary LUTs configured for geometry " << igeo; + } + } if (enablePrimarySmearing) { // load LUTs for primaries for (const auto& entry : globalConfiguration) { @@ -985,6 +1051,7 @@ struct OnTheFlyTracker { std::array nHitsCascadeProngs{}; // total std::array nSiliconHitsCascadeProngs{}; // silicon type std::array nTPCHitsCascadeProngs{}; // TPC type + std::array, NCascProngs> cascadeHitRadii{}; o2::track::TrackParCov xiTrackParCov; o2::upgrade::convertMCParticleToO2Track(mcParticle, xiTrackParCov, pdgDB); @@ -1036,21 +1103,32 @@ struct OnTheFlyTracker { nSiliconHitsCascadeProngs[i] = 0; nTPCHitsCascadeProngs[i] = 0; if (enableSecondarySmearing) { - nHitsCascadeProngs[i] = fastTracker[icfg]->fastTrack(xiDaughterTrackParCovsPerfect[i], xiDaughterTrackParCovsTracked[i], dNdEta); - nSiliconHitsCascadeProngs[i] = fastTracker[icfg]->getNSiliconPoints(); - nTPCHitsCascadeProngs[i] = fastTracker[icfg]->getNGasPoints(); + if (useSecondaryLUT) { + static constexpr std::array daughterPdgs = {kPiMinus, kPiMinus, kProton}; + xiDaughterTrackParCovsTracked[i] = xiDaughterTrackParCovsPerfect[i]; + isReco[i] = smearSecondaryWithLUT(xiDaughterTrackParCovsPerfect[i], xiDaughterTrackParCovsTracked[i], + daughterPdgs[i], dNdEta, nSiliconHitsCascadeProngs[i], cascadeHitRadii[i]); + nHitsCascadeProngs[i] = nSiliconHitsCascadeProngs[i]; + } else { + nHitsCascadeProngs[i] = fastTracker[icfg]->fastTrack(xiDaughterTrackParCovsPerfect[i], xiDaughterTrackParCovsTracked[i], dNdEta); + nSiliconHitsCascadeProngs[i] = fastTracker[icfg]->getNSiliconPoints(); + nTPCHitsCascadeProngs[i] = fastTracker[icfg]->getNGasPoints(); + } if (nHitsCascadeProngs[i] < 0 && cascadeDecaySettings.doXiQA) { // QA getHist(histPath + "hFastTrackerQA")->Fill(o2::math_utils::abs(nHitsCascadeProngs[i])); } - getHist(histPath + "nSiliconHitsCascadeProngs")->Fill(nSiliconHitsCascadeProngs[i]); - getHist(histPath + "nTPCHitsCascadeProngs")->Fill(nTPCHitsCascadeProngs[i]); - if (nSiliconHitsCascadeProngs[i] >= fastTrackerSettings.minSiliconHits || - (nSiliconHitsCascadeProngs[i] >= fastTrackerSettings.minSiliconHitsIfTPCUsed && - nTPCHitsCascadeProngs[i] >= fastTrackerSettings.minTPCClusters)) { - isReco[i] = true; - } else { + if (cascadeDecaySettings.doXiQA) { + getHist(histPath + "nSiliconHitsCascadeProngs")->Fill(nSiliconHitsCascadeProngs[i]); + getHist(histPath + "nTPCHitsCascadeProngs")->Fill(nTPCHitsCascadeProngs[i]); + } + if (!useSecondaryLUT) { + isReco[i] = nSiliconHitsCascadeProngs[i] >= fastTrackerSettings.minSiliconHits || + (nSiliconHitsCascadeProngs[i] >= fastTrackerSettings.minSiliconHitsIfTPCUsed && + nTPCHitsCascadeProngs[i] >= fastTrackerSettings.minTPCClusters); + } + if (!isReco[i]) { continue; // extra sure } if (cascadeDecaySettings.doXiQA) { @@ -1058,7 +1136,7 @@ struct OnTheFlyTracker { } isReco[i] = true; - for (uint32_t ih = 0; ih < fastTracker[icfg]->getNHits() && cascadeDecaySettings.doXiQA; ih++) { + for (uint32_t ih = 0; !useSecondaryLUT && ih < fastTracker[icfg]->getNHits() && cascadeDecaySettings.doXiQA; ih++) { getHist(histPath + "hFastTrackerHits")->Fill(fastTracker[icfg]->getHitZ(ih), std::hypot(fastTracker[icfg]->getHitX(ih), fastTracker[icfg]->getHitY(ih))); } } else { @@ -1073,13 +1151,19 @@ struct OnTheFlyTracker { isReco[i] = false; continue; } - getHist(histPath + "hXiBuilding")->Fill(4.0f); + if (cascadeDecaySettings.doXiQA) { + getHist(histPath + "hXiBuilding")->Fill(4.0f); + } histos.fill(HIST("hNaNBookkeeping"), i + 1, 1.0f); trackTime = (eventCollisionTimeNS + gRandom->Gaus(0., TimeResolutionNs)) * NsToMus; // TODO: add flag for whether it's a ghost track or not, currently assuming all are reconstructed tracks if they pass the fast tracker requirements TrackType trackType = isReco[i] ? TrackType::kRecoCascDaug : TrackType::kGenCascDaug; tracksCascadeProngs[i] = TrackAlice3{xiDaughterTrackParCovsTracked[i], mcParticle.globalIndex(), trackTime, TimeResolutionUs, true, false, true, i + 2, nSiliconHitsCascadeProngs[i], nTPCHitsCascadeProngs[i], trackType}; + if (enableSecondarySmearing && useSecondaryLUT) { + tracksCascadeProngs[i].trackIU = cascadeHitRadii[i][0]; + tracksCascadeProngs[i].trackOU = cascadeHitRadii[i][1]; + } } bool tryKinkReco = false; @@ -1487,19 +1571,24 @@ struct OnTheFlyTracker { std::vector nV0Hits(NV0Prongs); // total std::vector nV0SiliconHits(NV0Prongs); // silicon type std::vector nV0TPCHits(NV0Prongs); // TPC type + std::array v0DaughterPdgs{}; + std::array, NV0Prongs> v0HitRadii{}; if (v0DecaySettings.doV0QA) { fillHist(Form("V0Building_Configuration_%i/hV0Building", icfg), 0.0f); } switch (mcParticle.pdgCode()) { case kK0Short: + v0DaughterPdgs = {kPiMinus, kPiPlus}; o2::upgrade::convertTLorentzVectorToO2Track(kPiMinus, v0DecayProducts[0], v0DecayVertex, v0DaughterTrackParCovsPerfect[0], pdgDB); o2::upgrade::convertTLorentzVectorToO2Track(kPiPlus, v0DecayProducts[1], v0DecayVertex, v0DaughterTrackParCovsPerfect[1], pdgDB); break; case kLambda0: + v0DaughterPdgs = {kPiMinus, kProton}; o2::upgrade::convertTLorentzVectorToO2Track(kPiMinus, v0DecayProducts[0], v0DecayVertex, v0DaughterTrackParCovsPerfect[0], pdgDB); o2::upgrade::convertTLorentzVectorToO2Track(kProton, v0DecayProducts[1], v0DecayVertex, v0DaughterTrackParCovsPerfect[1], pdgDB); break; case kLambda0Bar: + v0DaughterPdgs = {kProtonBar, kPiPlus}; o2::upgrade::convertTLorentzVectorToO2Track(kProtonBar, v0DecayProducts[0], v0DecayVertex, v0DaughterTrackParCovsPerfect[0], pdgDB); o2::upgrade::convertTLorentzVectorToO2Track(kPiPlus, v0DecayProducts[1], v0DecayVertex, v0DaughterTrackParCovsPerfect[1], pdgDB); break; @@ -1524,15 +1613,20 @@ struct OnTheFlyTracker { nV0SiliconHits[i] = 0; nV0TPCHits[i] = 0; if (enableSecondarySmearing) { - nV0Hits[i] = fastTracker[icfg]->fastTrack(v0DaughterTrackParCovsPerfect[i], v0DaughterTrackParCovsTracked[i], dNdEta); - nV0SiliconHits[i] = fastTracker[icfg]->getNSiliconPoints(); - nV0TPCHits[i] = fastTracker[icfg]->getNGasPoints(); - - if (nV0SiliconHits[i] >= fastTrackerSettings.minSiliconHits || - (nV0SiliconHits[i] >= fastTrackerSettings.minSiliconHitsIfTPCUsed && - nV0TPCHits[i] >= fastTrackerSettings.minTPCClusters)) { - isV0Reco[i] = true; + if (useSecondaryLUT) { + v0DaughterTrackParCovsTracked[i] = v0DaughterTrackParCovsPerfect[i]; + isV0Reco[i] = smearSecondaryWithLUT(v0DaughterTrackParCovsPerfect[i], v0DaughterTrackParCovsTracked[i], + v0DaughterPdgs[i], dNdEta, nV0SiliconHits[i], v0HitRadii[i]); + nV0Hits[i] = nV0SiliconHits[i]; } else { + nV0Hits[i] = fastTracker[icfg]->fastTrack(v0DaughterTrackParCovsPerfect[i], v0DaughterTrackParCovsTracked[i], dNdEta); + nV0SiliconHits[i] = fastTracker[icfg]->getNSiliconPoints(); + nV0TPCHits[i] = fastTracker[icfg]->getNGasPoints(); + isV0Reco[i] = nV0SiliconHits[i] >= fastTrackerSettings.minSiliconHits || + (nV0SiliconHits[i] >= fastTrackerSettings.minSiliconHitsIfTPCUsed && + nV0TPCHits[i] >= fastTrackerSettings.minTPCClusters); + } + if (!isV0Reco[i]) { continue; // extra sure } @@ -1540,7 +1634,7 @@ struct OnTheFlyTracker { if (nV0Hits[i] < 0) { fillHist(Form("V0Building_Configuration_%i/hFastTrackerQA", icfg), o2::math_utils::abs(nV0Hits[i])); } - for (uint32_t ih = 0; ih < fastTracker[icfg]->getNHits(); ih++) { + for (uint32_t ih = 0; !useSecondaryLUT && ih < fastTracker[icfg]->getNHits(); ih++) { fillHist(Form("V0Building_Configuration_%i/hFastTrackerHits", icfg), fastTracker[icfg]->getHitZ(ih), std::hypot(fastTracker[icfg]->getHitX(ih), fastTracker[icfg]->getHitY(ih))); } } @@ -1552,7 +1646,13 @@ struct OnTheFlyTracker { trackTime = (eventCollisionTimeNS + gRandom->Gaus(0., TimeResolutionNs)) * NsToMus; // TODO: flag to separate ghost and reco tracks TrackType trackType = isV0Reco[i] ? TrackType::kRecoV0Daug : TrackType::kGhostV0Daug; - tracksV0Daugs[i] = TrackAlice3{v0DaughterTrackParCovsTracked[i], mcParticle.globalIndex(), trackTime, TimeResolutionUs, true, false, true, i + 2, trackType}; + if (enableSecondarySmearing && useSecondaryLUT) { + tracksV0Daugs[i] = TrackAlice3{v0DaughterTrackParCovsTracked[i], mcParticle.globalIndex(), trackTime, TimeResolutionUs, true, false, true, i + 2, nV0SiliconHits[i], nV0TPCHits[i], trackType}; + tracksV0Daugs[i].trackIU = v0HitRadii[i][0]; + tracksV0Daugs[i].trackOU = v0HitRadii[i][1]; + } else { + tracksV0Daugs[i] = TrackAlice3{v0DaughterTrackParCovsTracked[i], mcParticle.globalIndex(), trackTime, TimeResolutionUs, true, false, true, i + 2, trackType}; + } } if (v0DecaySettings.doV0QA) { if (isV0Reco[0] && isV0Reco[1]) { @@ -2092,7 +2192,7 @@ struct OnTheFlyTracker { fillTracksInfo(ghostPrimaries, primaryVertex); // do bookkeeping of fastTracker tracking - if (enableSecondarySmearing) { + if (enableSecondarySmearing && !useSecondaryLUT) { histos.fill(HIST("hCovMatOK"), 0.0f, fastTracker[icfg]->getCovMatNotOK()); histos.fill(HIST("hCovMatOK"), 1.0f, fastTracker[icfg]->getCovMatOK()); } @@ -2190,7 +2290,7 @@ struct OnTheFlyTracker { o2::upgrade::convertMCParticleToO2Track(mcParticle, trackParCov, pdgDB); computeBremsstrahlungLoss(mcParticle, trackParCov); reconstructed = mSmearer[icfg]->smearTrack(trackParCov, mcParticle.pdgCode(), dNdEta); - } else if (shortLivedToBeHandled && fastPrimaryTrackerSettings.fastTrackShortLivedParticles) { + } else if (shortLivedToBeHandled && fastPrimaryTrackerSettings.fastTrackShortLivedParticles && !(useSecondaryLUT && isSecondary)) { o2::track::TrackParCov perfectTrackParCov = o2::upgrade::convertMCParticleToO2Track(mcParticle, pdgDB); perfectTrackParCov.setPID(pdgCodeToPID(mcParticle.pdgCode())); computeBremsstrahlungLoss(mcParticle, perfectTrackParCov); @@ -2210,11 +2310,22 @@ struct OnTheFlyTracker { } else if (enableSecondarySmearing && isSecondary) { o2::track::TrackParCov perfectTrackParCov; o2::upgrade::convertMCParticleToO2Track(mcParticle, perfectTrackParCov, pdgDB); - computeBremsstrahlungLoss(mcParticle, perfectTrackParCov); - perfectTrackParCov.setPID(pdgCodeToPID(mcParticle.pdgCode())); - nTrkHits = fastTracker[icfg]->fastTrack(perfectTrackParCov, trackParCov, dNdEta); - hitRadii = {fastTracker[icfg]->getTrackIU(), fastTracker[icfg]->getTrackOU()}; - reconstructed = nTrkHits >= fastTrackerSettings.minSiliconHits; + if (useSecondaryLUT) { + trackParCov = perfectTrackParCov; + computeBremsstrahlungLoss(mcParticle, trackParCov); + trackParCov.setPID(pdgCodeToPID(mcParticle.pdgCode())); + bool wasSmeared = false; + reconstructed = smearSecondaryWithLUT(perfectTrackParCov, trackParCov, mcParticle.pdgCode(), dNdEta, nTrkHits, hitRadii, &wasSmeared); + if (!wasSmeared) { + continue; + } + } else { + computeBremsstrahlungLoss(mcParticle, perfectTrackParCov); + perfectTrackParCov.setPID(pdgCodeToPID(mcParticle.pdgCode())); + nTrkHits = fastTracker[icfg]->fastTrack(perfectTrackParCov, trackParCov, dNdEta); + hitRadii = {fastTracker[icfg]->getTrackIU(), fastTracker[icfg]->getTrackOU()}; + reconstructed = nTrkHits >= fastTrackerSettings.minSiliconHits; + } } if (!reconstructed && !processUnreconstructedTracks) { @@ -2273,7 +2384,9 @@ struct OnTheFlyTracker { tracksAlice3.push_back(TrackAlice3{trackParCov, mcParticle.globalIndex(), time, TimeResolutionUs, isSecondary, true, false, 0, nTrkHits, kRecoPrimary}); tracksAlice3.back().trackIU = hitRadii[0]; tracksAlice3.back().trackOU = hitRadii[1]; - getHist(histPath + "hPtReconstructedPr")->Fill(trackParCov.getPt()); + if (enablePrimarySmearing) { + getHist(histPath + "hPtReconstructedPr")->Fill(trackParCov.getPt()); + } } else { ghostTracksAlice3.push_back(TrackAlice3{trackParCov, mcParticle.globalIndex(), time, TimeResolutionUs, isSecondary, false, false, false, 0, nTrkHits, kGhostPrimary}); ghostTracksAlice3.back().trackIU = hitRadii[0]; @@ -2283,8 +2396,9 @@ struct OnTheFlyTracker { o2::vertexing::PVertex primaryVertex; static constexpr int MinTracksForReconstructingPV = 2; - if (enablePrimaryVertexing && recoPrimaries.size() <= MinTracksForReconstructingPV) { - LOG(info) << "Not enough primary tracks (" << recoPrimaries.size() << ") to compute vertex, skipping vertexing and collision population."; + const auto vertexTrackCount = useSecondaryLUT ? tracksAlice3.size() : recoPrimaries.size(); + if (enablePrimaryVertexing && vertexTrackCount <= MinTracksForReconstructingPV) { + LOG(info) << "Not enough tracks (" << vertexTrackCount << ") to compute vertex, skipping vertexing and collision population."; return; } computeVertex(mcCollision, tracksAlice3, primaryVertex); From a2f82bf6f15feffff0687048fa26db9e1d150a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Mon, 23 Nov 2026 07:12:18 +0100 Subject: [PATCH 2/3] Avoid tracking with disks --- ALICE3/Core/DetLayer.h | 2 ++ ALICE3/Core/FastTracker.cxx | 19 ++++++++++++++----- ALICE3/Core/FastTracker.h | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ALICE3/Core/DetLayer.h b/ALICE3/Core/DetLayer.h index ca773696c9d..3687e061cf4 100644 --- a/ALICE3/Core/DetLayer.h +++ b/ALICE3/Core/DetLayer.h @@ -19,6 +19,8 @@ #ifndef ALICE3_CORE_DETLAYER_H_ #define ALICE3_CORE_DETLAYER_H_ +#include + #include #include diff --git a/ALICE3/Core/FastTracker.cxx b/ALICE3/Core/FastTracker.cxx index da87469f4b4..b769957f1e7 100644 --- a/ALICE3/Core/FastTracker.cxx +++ b/ALICE3/Core/FastTracker.cxx @@ -451,15 +451,15 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa const float initialAlpha = inputTrack.getAlpha(); // frame of the input track const float kTrackingMargin = 0.1; - int firstActiveLayer = -1; // first layer that is not inert + int firstActiveLayer = -1; // first supported layer that is not inert for (size_t i = 0; i < layers.size(); ++i) { - if (!layers[i].isInert()) { + if (!layers[i].isInert() && !layers[i].isSiliconDisk()) { firstActiveLayer = i; break; } } if (firstActiveLayer < 0) { - LOG(fatal) << "No active layers found in FastTracker, check layer setup"; + LOG(fatal) << "No active non-disk layers found in FastTracker, check layer setup"; return -2; // no active layers } const int xrhosteps = 100; @@ -480,8 +480,14 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa // Outward pass to find intercepts int firstLayerReached = -1; int lastLayerReached = -1; + int previousLayer = -1; new (&outputTrack)(o2::track::TrackParCov)(inputTrack); for (size_t il = 0; il < layers.size(); il++) { + if (layers[il].isSiliconDisk()) { + continue; + } + const int previousNonDiskLayer = previousLayer; + previousLayer = il; // check if layer is doable if (layers[il].getRadius() < initialRadius) { continue; // this layer should not be attempted, but go ahead @@ -528,9 +534,9 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa LOGF(debug, "Propagation was %s up to layer %d", ok ? "successful" : "unsuccessful", il); // was there a problem on this layer? - if (!ok && il > 0) { // may fail to reach target layer due to the eloss + if (!ok && previousNonDiskLayer >= 0) { // may fail to reach target layer due to the eloss const float rad2 = inputTrack.getX() * inputTrack.getX() + inputTrack.getY() * inputTrack.getY(); - const float maxR = layers[il - 1].getRadius() + kTrackingMargin * 2; + const float maxR = layers[previousNonDiskLayer].getRadius() + kTrackingMargin * 2; const float minRad = (fMinRadTrack > 0 && fMinRadTrack < maxR) ? fMinRadTrack : maxR; if (rad2 - minRad * minRad < kTrackingMargin * kTrackingMargin) { // check previously reached layer return -5; // did not reach min requested layer @@ -605,6 +611,9 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa // Inward pass to calculate covariances // As in DetectorK::SolveTrack, the track is rotated to the frame of each layer (X axis normal to the layer) for (int il = lastLayerReached; il >= firstLayerReached; il--) { + if (layers[il].isSiliconDisk()) { + continue; + } float targetX = 1e+3; inputTrack.getXatLabR(layers[il].getRadius(), targetX, magneticField); diff --git a/ALICE3/Core/FastTracker.h b/ALICE3/Core/FastTracker.h index 7f3748b8a69..1640c278e5e 100644 --- a/ALICE3/Core/FastTracker.h +++ b/ALICE3/Core/FastTracker.h @@ -93,6 +93,7 @@ class FastTracker * * Propagates the given input track through the detector layers, applying * relevant corrections and updates, and stores the result in outputTrack. + * Silicon disks are not included in this tracking calculation. * * @param inputTrack The input track parameters and covariance (const, by value). * @param outputTrack Reference to the output track parameters and covariance, to be filled. From 6c1797a90653a9c5b3b336126e2b1796945fe058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Mon, 23 Nov 2026 07:22:50 +0100 Subject: [PATCH 3/3] Fix radius check --- ALICE3/Core/FastTracker.cxx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ALICE3/Core/FastTracker.cxx b/ALICE3/Core/FastTracker.cxx index b769957f1e7..cebbe0290e1 100644 --- a/ALICE3/Core/FastTracker.cxx +++ b/ALICE3/Core/FastTracker.cxx @@ -188,9 +188,15 @@ DetLayer* FastTracker::addLayer(const TString& name, float r, float z, float x0, LOG(error) << "Layer " << name << " with efficiency > 0.0 should not be inert"; } // Layers should be ordered by increasing radius, check this - if (!layers.empty() && !newLayer.isSiliconDisk() && !layers.back().isSiliconDisk() && - newLayer.getRadius() < layers.back().getRadius()) { - LOG(fatal) << "Layer " << newLayer << " is not ordered correctly, it should be after layer " << layers.back(); + if (!newLayer.isSiliconDisk()) { + const auto previous = std::find_if(layers.rbegin(), layers.rend(), + [](const auto& layer) { + return !layer.isSiliconDisk(); + }); + + if (previous != layers.rend() && newLayer.getRadius() < previous->getRadius()) { + LOG(fatal) << "Layer " << newLayer << " is not ordered correctly, it should be after layer " << previous->getName(); + } } // Layers should all have different names for (const auto& layer : layers) {