diff --git a/ALICE3/Core/FlatTrackSmearer.cxx b/ALICE3/Core/FlatTrackSmearer.cxx index c8c5a4555a5..d279365a719 100644 --- a/ALICE3/Core/FlatTrackSmearer.cxx +++ b/ALICE3/Core/FlatTrackSmearer.cxx @@ -317,6 +317,9 @@ bool TrackSmearer::smearTrack(O2Track& o2track, const lutEntry_t* lutEntry, cons return false; } + // Keep the MC parameters in case smearing fails + const O2Track mcTrack = o2track; + // Transform params vector and smear EigenArrayDouble params; for (int i = 0; i < kNumEigenModes; ++i) { @@ -349,6 +352,20 @@ bool TrackSmearer::smearTrack(O2Track& o2track, const lutEntry_t* lutEntry, cons o2track.setCov(lutEntry->covm[i], i); } + // If requested, fall back to the MC parameters (keeping the LUT covariance) when smearing gives NaN + if (mAllowSmearingFailures) { + bool hasNaN = false; + for (int i = 0; i < kNumEigenModes; ++i) { + hasNaN = hasNaN || std::isnan(o2track.getParam(i)); + } + if (hasNaN) { + LOG(debug) << "smearTrack gave NaN parameters, keeping MC parameters"; + for (int i = 0; i < kNumEigenModes; ++i) { + o2track.setParam(mcTrack.getParam(i), i); + } + } + } + return isReconstructed; } @@ -367,7 +384,7 @@ bool TrackSmearer::smearTrack(O2Track& o2track, const int pdg, const float nch) const lutEntry_t* lutEntry = getLUTEntry(pdg, nch, 0.f, eta, pt, interpolatedEff); if (!lutEntry || !lutEntry->valid) { - return false; + return mAllowSmearingFailures; // if allowed, keep the track with MC parameters } return smearTrack(o2track, lutEntry, interpolatedEff); diff --git a/ALICE3/Core/FlatTrackSmearer.h b/ALICE3/Core/FlatTrackSmearer.h index 6008a560e9b..368b952e85a 100644 --- a/ALICE3/Core/FlatTrackSmearer.h +++ b/ALICE3/Core/FlatTrackSmearer.h @@ -43,6 +43,7 @@ class TrackSmearer void useEfficiency(bool val) { mUseEfficiency = val; } void interpolateEfficiency(bool val) { mInterpolateEfficiency = val; } void skipUnreconstructed(bool val) { mSkipUnreconstructed = val; } + void allowSmearingFailures(bool val) { mAllowSmearingFailures = val; } enum EfficiencyType : uint8_t { kWhatEfficiencyReco = 0, kWhatEfficiencyRecoAndTOF = 1 @@ -73,6 +74,7 @@ class TrackSmearer bool mUseEfficiency = true; bool mInterpolateEfficiency = false; bool mSkipUnreconstructed = true; // don't smear tracks that are not reco'ed + bool mAllowSmearingFailures = false; // keep MC parameters if there is no valid LUT entry or smearing gives NaN EfficiencyType mWhatEfficiency = kWhatEfficiencyReco; private: diff --git a/ALICE3/Core/SecondaryTrackSmearer.cxx b/ALICE3/Core/SecondaryTrackSmearer.cxx index 05a81158b56..ca35fa9b6bc 100644 --- a/ALICE3/Core/SecondaryTrackSmearer.cxx +++ b/ALICE3/Core/SecondaryTrackSmearer.cxx @@ -192,7 +192,10 @@ bool SecondaryTrackSmearer::smearTrack(O2Track& track, const SecondaryLutEntry* } if (!entry || !entry->valid) { LOG(debug) << "Cannot smear a track with a missing or invalid secondary LUT entry"; - return false; + if (mAllowSmearingFailures && wasSmeared) { + *wasSmeared = true; // track is kept with MC parameters + } + return mAllowSmearingFailures; } const float selectedEfficiency = mInterpolateEfficiency ? interpolatedEff : efficiency(*entry); if (mUseEfficiency && (!std::isfinite(selectedEfficiency) || selectedEfficiency < 0.f || selectedEfficiency > 1.f)) { @@ -205,7 +208,10 @@ bool SecondaryTrackSmearer::smearTrack(O2Track& track, const SecondaryLutEntry* !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; + if (mAllowSmearingFailures && wasSmeared) { + *wasSmeared = true; // track is kept with MC parameters + } + return mAllowSmearingFailures; } lutEntry_t flatEntry; flatEntry.valid = entry->valid; diff --git a/ALICE3/Core/SecondaryTrackSmearer.h b/ALICE3/Core/SecondaryTrackSmearer.h index b0425fed0e5..ecdee41e4ed 100644 --- a/ALICE3/Core/SecondaryTrackSmearer.h +++ b/ALICE3/Core/SecondaryTrackSmearer.h @@ -51,6 +51,11 @@ class SecondaryTrackSmearer mSkipUnreconstructed = value; mSmearer.skipUnreconstructed(value); } + void allowSmearingFailures(bool value) + { + mAllowSmearingFailures = value; + mSmearer.allowSmearingFailures(value); + } void setWhatEfficiency(EfficiencyType value); void setCcdbManager(o2::ccdb::BasicCCDBManager* manager) { mCcdbManager = manager; } @@ -79,6 +84,7 @@ class SecondaryTrackSmearer bool mUseEfficiency = true; bool mInterpolateEfficiency = false; bool mSkipUnreconstructed = true; + bool mAllowSmearingFailures = false; // keep MC parameters if there is no valid LUT entry or smearing gives NaN EfficiencyType mWhatEfficiency = kWhatEfficiencyReco; }; diff --git a/ALICE3/TableProducer/OTF/onTheFlyTracker.cxx b/ALICE3/TableProducer/OTF/onTheFlyTracker.cxx index 2ab0dc6265d..7a1f5164bbe 100644 --- a/ALICE3/TableProducer/OTF/onTheFlyTracker.cxx +++ b/ALICE3/TableProducer/OTF/onTheFlyTracker.cxx @@ -160,6 +160,7 @@ struct OnTheFlyTracker { Configurable populateTrackSelection{"populateTrackSelection", false, "populate TrackSelection table (legacy)"}; Configurable processUnreconstructedTracks{"processUnreconstructedTracks", false, "process (smear) unreco-ed tracks"}; + Configurable allowSmearingFailures{"allowSmearingFailures", false, "keep tracks with MC parameters if LUT smearing fails (no valid LUT entry or NaN); only the efficiency rejects tracks"}; Configurable doExtraQA{"doExtraQA", false, "do extra 2D QA plots"}; Configurable extraQAwithoutDecayDaughters{"extraQAwithoutDecayDaughters", false, "remove decay daughters from qa plots (yes/no)"}; @@ -487,6 +488,7 @@ struct OnTheFlyTracker { smearer.setCcdbManager(ccdb.operator->()); smearer.interpolateEfficiency(interpolateLutEfficiencyVsNch.value); smearer.skipUnreconstructed(!processUnreconstructedTracks.value); + smearer.allowSmearingFailures(allowSmearingFailures.value); const std::map species = {{"secondaryLutEl", kElectron}, {"secondaryLutMu", kMuonMinus}, {"secondaryLutPi", kPiPlus}, @@ -588,6 +590,9 @@ struct OnTheFlyTracker { // smear un-reco'ed tracks if asked to do so mSmearer[igeo]->skipUnreconstructed(!processUnreconstructedTracks.value); + // keep tracks with MC parameters if smearing fails, if asked to do so + mSmearer[igeo]->allowSmearingFailures(allowSmearingFailures.value); + insertHist(histPath + "hPtGenerated", "hPtGenerated;#it{p}_{T} (GeV/c);Counts", kTH1D, {{axes.axisMomentum}}); insertHist(histPath + "hPhiGenerated", "hPhiGenerated;#phi (rad);Counts", kTH1D, {{100, 0.0f, o2::constants::math::TwoPI, "#phi (rad)"}});