diff --git a/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TrackMCStudyConfig.h b/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TrackMCStudyConfig.h index 1987527d13f2a..ceaa04905756e 100644 --- a/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TrackMCStudyConfig.h +++ b/Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TrackMCStudyConfig.h @@ -36,7 +36,7 @@ struct TrackMCStudyConfig : o2::conf::ConfigurableParamHelper recTracks{}; o2::track::TrackParCov trackITSProp{}; o2::track::TrackParCov trackTPCProp{}; - int8_t entITS = -1; - int8_t entTPC = -1; - int8_t entITSTPC = -1; - int8_t entITSFound = -1; // ITS track for this MC track, regardless if it was matched to TPC of another track + int8_t entITS = -1; // 1st entry of standalone ITS tracks + int8_t entTPC = -1; // 1st entry of standalone TPC tracks + int8_t entITSTPC = -1; // 1st entry of tracks with both ITS and TPC contributions + int8_t entITSFound = -1; // standalone ITS track for this MC track, regardless if it was matched to TPC of another track + int8_t nEntITS = 0; // number of standalone ITS tracks + int8_t nEntTPC = 0; // number of standalone TPC tracks + int8_t nEntITSTPC = 0; // number of tracks with both ITS and TPC contributions int8_t flags = 0; float tpcT0 = -999.; @@ -158,9 +164,9 @@ struct TrackFamily { // set of tracks related to the same MC label } return false; } - const RecTrack& getTrackWithITS() const { return entITS < 0 ? dummyRecTrack : recTracks[entITS]; } - const RecTrack& getTrackWithTPC() const { return entTPC < 0 ? dummyRecTrack : recTracks[entTPC]; } - const RecTrack& getTrackWithITSTPC() const { return entITSTPC < 0 ? dummyRecTrack : recTracks[entITSTPC]; } + const RecTrack& getTrackWithITS(int id = 0) const { return (id >= 0 && id < nEntITS) ? recTracks[entITS + id] : dummyRecTrack; } + const RecTrack& getTrackWithTPC(int id = 0) const { return (id >= 0 && id < nEntTPC) ? recTracks[entTPC + id] : dummyRecTrack; } + const RecTrack& getTrackWithITSTPC(int id = 0) const { return (id >= 0 && id < nEntITSTPC) ? recTracks[entITSTPC + id] : dummyRecTrack; } const RecTrack& getTrackWithITSFound() const { return entITSFound < 0 ? dummyRecTrack : recTracks[entITSFound]; } const RecTrack& getLongestTPCTrack() const { @@ -171,7 +177,7 @@ struct TrackFamily { // set of tracks related to the same MC label int getNTPCClones() const; static RecTrack dummyRecTrack; // - ClassDefNV(TrackFamily, 1); + ClassDefNV(TrackFamily, 2); }; struct ClResTPCCont { diff --git a/Detectors/GlobalTrackingWorkflow/study/src/TrackMCStudy.cxx b/Detectors/GlobalTrackingWorkflow/study/src/TrackMCStudy.cxx index ec70cfc9e2115..b25adfc31db61 100644 --- a/Detectors/GlobalTrackingWorkflow/study/src/TrackMCStudy.cxx +++ b/Detectors/GlobalTrackingWorkflow/study/src/TrackMCStudy.cxx @@ -14,6 +14,7 @@ #include "DataFormatsGlobalTracking/RecoContainer.h" #include "DataFormatsGlobalTracking/RecoContainerCreateTracksVariadic.h" #include "ReconstructionDataFormats/V0.h" +#include "ReconstructionDataFormats/Cascade.h" #include "ReconstructionDataFormats/TrackTPCITS.h" #include "ReconstructionDataFormats/GlobalTrackID.h" #include "TPCCalibration/VDriftHelper.h" @@ -104,10 +105,12 @@ class TrackMCStudy final : public Task void fillMCClusterInfo(const o2::globaltracking::RecoContainer& recoData); void prepareITSData(const o2::globaltracking::RecoContainer& recoData); bool processMCParticle(int src, int ev, int trid); + int registerDecay(int src, int ev, int trid, int decID); bool addMCParticle(const MCTrack& mctr, const o2::MCCompLabel& lb, TParticlePDG* pPDG = nullptr); bool acceptMCCharged(const MCTrack& tr, const o2::MCCompLabel& lb, int followDec = -1); bool propagateToRefX(o2::track::TrackParCov& trcTPC, o2::track::TrackParCov& trcITS); bool refitV0(int i, o2::dataformats::V0& v0, const o2::globaltracking::RecoContainer& recoData); + bool refitCascade(int i, o2::dataformats::Cascade& casc, o2::dataformats::V0& v0, const o2::globaltracking::RecoContainer& recoData); void updateTimeDependentParams(ProcessingContext& pc); float getDCAYCut(float pt) const; @@ -151,12 +154,19 @@ class TrackMCStudy final : public Task int daughterFirst = -1; int daughterLast = -1; int foundSVID = -1; + int subDecID = -1; // decay type of the neutral daughter decay (e.g. Lambda of the cascade), if any + int subDecEntry = -1; // its entry in mDecaysMaps[subDecID] + int motherDecID = -1; // for the decay which is a sub-decay (e.g. Lambda from cascade): decay type of the mother + int motherEntry = -1; // its entry in mDecaysMaps[motherDecID] + int foundCascID = -1; // reconstructed cascade matched to this decay }; std::vector> mDecaysMaps; // for every parent particle to watch, store its label and entries of 1st/last decay product labels in mDecProdLblPool + std::unordered_map> mDecayOfLabel; // decay type and entry in mDecaysMaps of already registered decays std::unordered_map mSelMCTracks; std::unordered_map> mSelTRefIdx; std::vector mSelTRefs; o2::vertexing::DCAFitterN<2> mFitterV0; + o2::vertexing::DCAFitterN<2> mFitterCasc; static constexpr float MaxSnp = 0.9; // max snp of ITS or TPC track at xRef to be matched }; @@ -185,6 +195,7 @@ void TrackMCStudy::run(ProcessingContext& pc) mDecaysMaps[i].clear(); } mDecProdLblPool.clear(); + mDecayOfLabel.clear(); mMCVtVec.clear(); mCurrMCTracks = nullptr; @@ -228,6 +239,23 @@ void TrackMCStudy::updateTimeDependentParams(ProcessingContext& pc) mFitterV0.setMaxStep(svparam.maxStep); mFitterV0.setMaxSnp(svparam.maxSnp); mFitterV0.setMinXSeed(svparam.minXSeed); + + mFitterCasc.setBz(o2::base::Propagator::Instance()->getNominalBz()); + mFitterCasc.setOldMode(svparam.oldDCAFitterMode); + mFitterCasc.setUseAbsDCA(svparam.useAbsDCA); + mFitterCasc.setPropagateToPCA(false); + mFitterCasc.setMaxR(svparam.maxRIniCasc); + mFitterCasc.setMinParamChange(svparam.minParamChange); + mFitterCasc.setMinRelChi2Change(svparam.minRelChi2Change); + mFitterCasc.setMaxDZIni(svparam.maxDZIni); + mFitterCasc.setMaxDXYIni(svparam.maxDXYIni); + mFitterCasc.setMaxChi2(svparam.maxChi2); + mFitterCasc.setMatCorrType(o2::base::Propagator::MatCorrType(svparam.matCorr)); + mFitterCasc.setUsePropagator(svparam.usePropagator); + mFitterCasc.setRefitWithMatCorr(svparam.refitWithMatCorr); + mFitterCasc.setMaxStep(svparam.maxStep); + mFitterCasc.setMaxSnp(svparam.maxSnp); + mFitterCasc.setMinXSeed(svparam.minXSeed); } } } @@ -489,10 +517,24 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData) break; } auto& trackFamilyOfFake = entryOfFake->second; - auto& trfOfFake = trackFamilyOfFake.recTracks.emplace_back(); - trfOfFake.gid = gidSet[GTrackID::ITS]; // account(iv, vid); + if (!trackFamilyOfFake.contains(gidSet[GTrackID::ITS])) { + auto& trfOfFake = trackFamilyOfFake.recTracks.emplace_back(); + trfOfFake.gid = gidSet[GTrackID::ITS]; // account(iv, vid); + } break; } + if (is != GTrackID::ITS && is != GTrackID::TPC) { // global track: store also its standalone ITS and TPC contributors (if any) + auto gidSet = recoData.getSingleDetectorRefs(vid); + for (auto src : {GTrackID::ITS, GTrackID::TPC}) { + const auto& gidC = gidSet[src]; + if (gidC.isSourceSet() && !trackFamily.contains(gidC)) { + auto& trfC = trackFamily.recTracks.emplace_back(); + trfC.gid = gidC; + trfC.pvID = pvID; + trfC.pvLabel = pvLbl; + } + } + } if (mVerbose > 1) { LOGP(info, "Matched rec track {} to MC track {}", vid.asString(), entry->first.asString()); } @@ -519,13 +561,25 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData) if (mVerbose > 1) { LOGP(info, "Processing MC track#{} {} -> {} reconstructed tracks", mcnt - 1, entry.first.asString(), tracks.size()); } - // sort according to the gid complexity (in principle, should be already sorted due to the backwards loop over NSources above - std::sort(tracks.begin(), tracks.end(), [](const RecTrack& lhs, const RecTrack& rhs) { - const auto mskL = lhs.gid.getSourceDetectorsMask(); - const auto mskR = rhs.gid.getSourceDetectorsMask(); - bool itstpcL = mskL[DetID::ITS] && mskL[DetID::TPC], itstpcR = mskR[DetID::ITS] && mskR[DetID::TPC]; - if (itstpcL && !itstpcR) { // to avoid TPC/TRD or TPC/TOF shadowing ITS/TPC - return true; + // sort to have tracks of the same type contiguous: 1st the tracks with ITS and TPC, then standalone ITS, then standalone TPC, then the rest. + // Within each group sort according to the gid complexity + auto trackGroup = [](const RecTrack& t) { + const auto msk = t.gid.getSourceDetectorsMask(); + if (msk[DetID::ITS] && msk[DetID::TPC]) { + return 0; + } + if (t.gid.getSource() == GTrackID::ITS) { + return 1; + } + if (t.gid.getSource() == GTrackID::TPC) { + return 2; + } + return 3; + }; + std::sort(tracks.begin(), tracks.end(), [&trackGroup](const RecTrack& lhs, const RecTrack& rhs) { + int grL = trackGroup(lhs), grR = trackGroup(rhs); + if (grL != grR) { + return grL < grR; } return lhs.gid.getSource() > rhs.gid.getSource(); }); @@ -540,8 +594,26 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData) } // fill track params int tcnt = 0; + bool tpcT0Set = false; for (auto& tref : tracks) { if (tref.gid.isSourceSet()) { + int grp = trackGroup(tref); + if (grp == 0) { + if (trackFam.entITSTPC < 0) { + trackFam.entITSTPC = tcnt; + } + trackFam.nEntITSTPC++; + } else if (grp == 1) { + if (trackFam.entITS < 0) { + trackFam.entITS = tcnt; + } + trackFam.nEntITS++; + } else if (grp == 2) { + if (trackFam.entTPC < 0) { + trackFam.entTPC = tcnt; + } + trackFam.nEntTPC++; + } auto gidSet = recoData.getSingleDetectorRefs(tref.gid); tref.track = recoData.getTrackParam(tref.gid); if (recoData.getTrackMCLabel(tref.gid).isFake()) { @@ -551,14 +623,11 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData) if (msk[DetID::ITS]) { if (gidSet[GTrackID::ITS].isSourceSet()) { // has ITS track rather than AB tracklet tref.pattITS = getITSPatt(gidSet[GTrackID::ITS], tref.nClITS); - if (trackFam.entITS < 0) { - trackFam.entITS = tcnt; - } auto lblITS = recoData.getTrackMCLabel(gidSet[GTrackID::ITS]); if (lblITS.isFake()) { tref.flags |= RecTrack::FakeITS; } - if (lblITS == trackFam.mcTrackInfo.label) { + if (grp == 1 && trackFam.entITSFound < 0 && lblITS == trackFam.mcTrackInfo.label) { trackFam.entITSFound = tcnt; } } else { // AB ITS tracklet @@ -568,9 +637,6 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData) } } if (msk[DetID::TPC]) { - if (trackFam.entITSTPC < 0) { // has both ITS and TPC contribution - trackFam.entITSTPC = tcnt; - } if (recoData.getTrackMCLabel(gidSet[GTrackID::ITSTPC]).isFake()) { tref.flags |= RecTrack::FakeITSTPC; } @@ -601,8 +667,8 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData) } fillTPCClusterInfo(trtpc, tref); flagTPCClusters(trtpc, entry.first); - if (trackFam.entTPC < 0) { - trackFam.entTPC = tcnt; + if (!tpcT0Set) { + tpcT0Set = true; trackFam.tpcT0 = trtpc.getTime0(); } if (recoData.getTrackMCLabel(gidSet[GTrackID::TPC]).isFake()) { @@ -640,9 +706,9 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData) } tcnt++; } - if (trackFam.entITS > -1 && trackFam.entTPC > -1) { // ITS and TPC were found but matching failed - auto vidITS = recoData.getITSContributorGID(tracks[trackFam.entITS].gid); - auto vidTPC = recoData.getTPCContributorGID(tracks[trackFam.entTPC].gid); + if (trackFam.nEntITS > 0 && trackFam.nEntTPC > 0) { // ITS and TPC standalone tracks were found (matched or not) + auto vidITS = trackFam.getTrackWithITS().gid; + auto vidTPC = trackFam.getTrackWithTPC().gid; auto trcTPC = recoData.getTrackParam(vidTPC); auto trcITS = recoData.getTrackParamOut(vidITS); if (propagateToRefX(trcTPC, trcITS)) { @@ -670,7 +736,7 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData) } return s; }; - for (int svID; svID < (int)v0s.size(); svID++) { + for (int svID = 0; svID < (int)v0s.size(); svID++) { const auto& v0idx = v0s[svID]; int nOKProngs = 0, realMCSVID = -1; int8_t decTypeID = -1; @@ -704,6 +770,37 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData) mDecaysMaps[decTypeID][realMCSVID].foundSVID = svID; } } + + // cascades: the bachelor must come from the decay whose neutral sub-decay produced both V0 prongs + auto cascs = recoData.getCascadesIdx(); + for (int cascID = 0; cascID < (int)cascs.size(); cascID++) { + const auto& cascIdx = cascs[cascID]; + auto itb = mSelMCTracks.find(recoData.getTrackMCLabel(cascIdx.getBachelorID())); + if (itb == mSelMCTracks.end()) { + continue; + } + const auto& bachInfo = itb->second.mcTrackInfo; + if (bachInfo.parentEntry < 0) { + continue; + } + auto& motherDec = mDecaysMaps[bachInfo.parentDecID][bachInfo.parentEntry]; + if (motherDec.subDecID < 0 || cascIdx.getV0ID() < 0 || cascIdx.getV0ID() >= (int)v0s.size()) { + continue; + } + const auto& v0idx = v0s[cascIdx.getV0ID()]; + bool ok = true; + for (int ipr = 0; ipr < v0idx.getNProngs(); ipr++) { + auto itl = mSelMCTracks.find(recoData.getTrackMCLabel(v0idx.getProngID(ipr))); + if (itl == mSelMCTracks.end() || itl->second.mcTrackInfo.parentDecID != motherDec.subDecID || itl->second.mcTrackInfo.parentEntry != motherDec.subDecEntry) { + ok = false; + break; + } + } + if (ok) { + LOGP(debug, "Cascade {}/{} was found", bachInfo.parentDecID, bachInfo.parentEntry); + motherDec.foundCascID = cascID; + } + } } // collect ITS/TPC cluster info for selected MC particles @@ -716,29 +813,51 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData) } // decays - std::vector decFam; + std::vector decFam, decFamSub; + auto fillDecProducts = [this, ¶ms](const DecayRef& dec, int id, std::vector& fam) { + fam.clear(); + for (int idd = dec.daughterFirst; idd <= dec.daughterLast; idd++) { + auto dtLbl = mDecProdLblPool[idd]; // daughter MC label + const auto& dtFamily = mSelMCTracks[dtLbl]; + if (dtFamily.mcTrackInfo.pdgParent != dec.pdg) { + LOGP(error, "{}-th decay (pdg={}): {} in {}:{} range refers to MC track with pdgParent = {}", id, params.decayPDG[id], idd, dec.daughterFirst, dec.daughterLast, dtFamily.mcTrackInfo.pdgParent); + return false; + } + fam.push_back(dtFamily); + } + return true; + }; + const DecayRef dummyDec{}; for (int id = 0; id < mNCheckDecays; id++) { std::string decTreeName = fmt::format("dec{}", params.decayPDG[id]); for (const auto& dec : mDecaysMaps[id]) { - decFam.clear(); - bool skip = false; - for (int idd = dec.daughterFirst; idd <= dec.daughterLast; idd++) { - auto dtLbl = mDecProdLblPool[idd]; // daughter MC label - const auto& dtFamily = mSelMCTracks[dtLbl]; - if (dtFamily.mcTrackInfo.pdgParent != dec.pdg) { - LOGP(error, "{}-th decay (pdg={}): {} in {}:{} range refers to MC track with pdgParent = {}", id, params.decayPDG[id], idd, dec.daughterFirst, dec.daughterLast, dtFamily.mcTrackInfo.pdgParent); - skip = true; - break; - } - decFam.push_back(dtFamily); + bool hasSub = dec.subDecID >= 0; + const auto& decSub = hasSub ? mDecaysMaps[dec.subDecID][dec.subDecEntry] : dummyDec; + if (!fillDecProducts(dec, id, decFam) || (hasSub && !fillDecProducts(decSub, dec.subDecID, decFamSub))) { + continue; + } + if (!hasSub) { + decFamSub.clear(); } - if (!skip) { - o2::dataformats::V0 v0; - if (dec.foundSVID >= 0 && !refitV0(dec.foundSVID, v0, recoData)) { - v0.invalidate(); + int pdgMother = dec.motherDecID >= 0 ? mDecaysMaps[dec.motherDecID][dec.motherEntry].pdg : 0; + o2::dataformats::V0 v0, v0Sub; + o2::dataformats::Cascade casc; + if (dec.foundSVID >= 0 && !refitV0(dec.foundSVID, v0, recoData)) { + v0.invalidate(); + } + v0Sub.invalidate(); + casc.invalidate(); + if (dec.foundCascID >= 0) { // the V0 of the cascade will be refitted together with it + if (!refitCascade(dec.foundCascID, casc, v0Sub, recoData)) { + casc.invalidate(); } - (*mDBGOut) << decTreeName.c_str() << "pdgPar=" << dec.pdg << "trPar=" << dec.parent << "prod=" << decFam << "found=" << dec.foundSVID << "sv=" << v0 << "\n"; + } else if (decSub.foundSVID >= 0 && !refitV0(decSub.foundSVID, v0Sub, recoData)) { + v0Sub.invalidate(); } + (*mDBGOut) << decTreeName.c_str() << "pdgPar=" << dec.pdg << "trPar=" << dec.parent << "prod=" << decFam << "found=" << dec.foundSVID << "sv=" << v0 + << "pdgMother=" << pdgMother + << "pdgSub=" << decSub.pdg << "trSub=" << decSub.parent << "prodSub=" << decFamSub << "foundSub=" << decSub.foundSVID << "svSub=" << v0Sub + << "foundCasc=" << dec.foundCascID << "casc=" << casc << "\n"; } } @@ -1102,39 +1221,10 @@ bool TrackMCStudy::processMCParticle(int src, int ev, int trid) } } 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; - if (idd0 < 0) { - break; - } - for (int idd = idd0; idd <= idd1; idd++) { - const auto& product = (*mCurrMCTracks)[idd]; - auto lbld = o2::MCCompLabel(idd, ev, src); - if (!acceptMCCharged(product, lbld, decay)) { - decay = -1; // discard decay - mDecProdLblPool.resize(dtStart); - break; - } - mDecProdLblPool.push_back(lbld); // register prong entry and label - } - if (decay >= 0) { - // account decay - dtEnd = mDecProdLblPool.size(); - for (int dtid = dtStart; dtid < dtEnd; dtid++) { // flag selected decay parent entry in the prongs MCs - mSelMCTracks[mDecProdLblPool[dtid]].mcTrackInfo.parentEntry = decayPool.size(); - mSelMCTracks[mDecProdLblPool[dtid]].mcTrackInfo.parentDecID = int8_t(decay); - } - dtEnd--; - std::array xyz{(float)mcPart.GetStartVertexCoordinatesX(), (float)mcPart.GetStartVertexCoordinatesY(), (float)mcPart.GetStartVertexCoordinatesZ()}; - std::array pxyz{(float)mcPart.GetStartVertexMomentumX(), (float)mcPart.GetStartVertexMomentumY(), (float)mcPart.GetStartVertexMomentumZ()}; - decayPool.emplace_back(DecayRef{lbl, - o2::track::TrackPar(xyz, pxyz, TMath::Nint(O2DatabasePDG::Instance()->GetParticle(mcPart.GetPdgCode())->Charge() / 3), false), - mcPart.GetPdgCode(), dtStart, dtEnd}); - if (mVerbose > 1) { - LOGP(info, "Adding MC parent pdg={} {}, with prongs in {}:{} range", pdg, lbl.asString(), dtStart, dtEnd); - } - res = true; // Accept! + if (mDecayOfLabel.find(lbl) != mDecayOfLabel.end()) { + res = true; // already registered as a sub-decay of another decay + } else { + res = registerDecay(src, ev, trid, decay) >= 0; } break; } @@ -1148,6 +1238,92 @@ bool TrackMCStudy::processMCParticle(int src, int ev, int trid) return res; } +int TrackMCStudy::registerDecay(int src, int ev, int trid, int decID) +{ + // register decay of MC particle trid as decay type decID, return its entry in mDecaysMaps[decID] or -1 if rejected. + // Charged daughters must be accepted as trackable, a neutral daughter is allowed only if its decay is in the list of decays to watch + // (e.g. Lambda of the Xi or Omega cascade), in which case it is registered (recursively) as a sub-decay of this decay. + const auto& params = o2::trackstudy::TrackMCStudyConfig::Instance(); + const auto& mcPart = (*mCurrMCTracks)[trid]; + auto lbl = o2::MCCompLabel(trid, ev, src); + auto known = mDecayOfLabel.find(lbl); + if (known != mDecayOfLabel.end()) { + return known->second.first == decID ? known->second.second : -1; + } + int idd0 = mcPart.getFirstDaughterTrackId(), idd1 = mcPart.getLastDaughterTrackId(); + if (idd0 < 0) { + return -1; + } + int dtStart = mDecProdLblPool.size(), dtEnd = -1; + int subTrID = -1, subDecID = -1; + bool ok = true; + for (int idd = idd0; idd <= idd1; idd++) { + const auto& product = (*mCurrMCTracks)[idd]; + auto lbld = o2::MCCompLabel(idd, ev, src); + TParticlePDG* pPDG = O2DatabasePDG::Instance()->GetParticle(product.GetPdgCode()); + if (pPDG && pPDG->Charge() == 0.) { // neutral daughter: accept only if its decay is to watch + int dauDecID = -1; + for (int id = 0; id < mNCheckDecays; id++) { + if (params.decayPDG[id] == std::abs(product.GetPdgCode())) { + dauDecID = id; + break; + } + } + if (dauDecID < 0 || subTrID >= 0) { // not to watch or more than 1 neutral sub-decay + if (mVerbose > 1) { + LOGP(info, "rejecting decay {} : neutral prong pdg={} {}", decID, product.GetPdgCode(), dauDecID < 0 ? "is not in the list of decays" : "is not the only neutral prong"); + } + ok = false; + break; + } + subTrID = idd; + subDecID = dauDecID; + continue; + } + if (!acceptMCCharged(product, lbld, decID)) { + ok = false; + break; + } + mDecProdLblPool.push_back(lbld); // register prong entry and label + } + dtEnd = mDecProdLblPool.size(); + int subDecEntry = -1; + if (ok && subTrID >= 0 && (subDecEntry = registerDecay(src, ev, subTrID, subDecID)) < 0) { + if (mVerbose > 1) { + LOGP(info, "rejecting decay {} : sub-decay {} of pdg={} is rejected", decID, subDecID, (*mCurrMCTracks)[subTrID].GetPdgCode()); + } + ok = false; + } + if (!ok) { + mDecProdLblPool.resize(dtStart); // the eventual sub-decay was rejected and its prongs were already removed + return -1; + } + // account decay + auto& decayPool = mDecaysMaps[decID]; + int entry = decayPool.size(); + for (int dtid = dtStart; dtid < dtEnd; dtid++) { // flag selected decay parent entry in the prongs MCs + mSelMCTracks[mDecProdLblPool[dtid]].mcTrackInfo.parentEntry = entry; + mSelMCTracks[mDecProdLblPool[dtid]].mcTrackInfo.parentDecID = int8_t(decID); + } + std::array xyz{(float)mcPart.GetStartVertexCoordinatesX(), (float)mcPart.GetStartVertexCoordinatesY(), (float)mcPart.GetStartVertexCoordinatesZ()}; + std::array pxyz{(float)mcPart.GetStartVertexMomentumX(), (float)mcPart.GetStartVertexMomentumY(), (float)mcPart.GetStartVertexMomentumZ()}; + auto& dec = decayPool.emplace_back(DecayRef{lbl, + o2::track::TrackPar(xyz, pxyz, TMath::Nint(O2DatabasePDG::Instance()->GetParticle(mcPart.GetPdgCode())->Charge() / 3), false), + mcPart.GetPdgCode(), dtStart, dtEnd - 1}); + if (subDecEntry >= 0) { + dec.subDecID = subDecID; + dec.subDecEntry = subDecEntry; + auto& sub = mDecaysMaps[subDecID][subDecEntry]; // N.B.: subDecID != decID, otherwise the reference dec would be invalidated + sub.motherDecID = decID; + sub.motherEntry = entry; + } + mDecayOfLabel[lbl] = {decID, entry}; + if (mVerbose > 1) { + LOGP(info, "Adding MC parent pdg={} {}, with prongs in {}:{} range, sub-decay {}/{}", mcPart.GetPdgCode(), lbl.asString(), dtStart, dtEnd - 1, subDecID, subDecEntry); + } + return entry; +} + bool TrackMCStudy::acceptMCCharged(const MCTrack& tr, const o2::MCCompLabel& lb, int followDecay) { const auto& params = o2::trackstudy::TrackMCStudyConfig::Instance(); @@ -1277,6 +1453,40 @@ bool TrackMCStudy::refitV0(int i, o2::dataformats::V0& v0, const o2::globaltrack return true; } +bool TrackMCStudy::refitCascade(int i, o2::dataformats::Cascade& casc, o2::dataformats::V0& v0, const o2::globaltracking::RecoContainer& recoData) +{ + const auto& cascIdx = recoData.getCascadesIdx()[i]; + if (!refitV0(cascIdx.getV0ID(), v0, recoData)) { + v0.invalidate(); + return false; + } + auto bach = recoData.getTrackParam(cascIdx.getBachelorID()); + if (mFitterCasc.process(v0, bach) == 0) { + return false; + } + const int cand = 0; + if (!mFitterCasc.isPropagateTracksToVertexDone(cand) && !mFitterCasc.propagateTracksToVertex(cand)) { + return false; + } + auto& trNeut = mFitterCasc.getTrack(0, cand); + auto& trBach = mFitterCasc.getTrack(1, cand); + trNeut.setPID(o2::track::PID::Lambda); + trBach.setPID(o2::track::PID::Pion); + std::array pNeut{}, pBach{}; + trNeut.getPxPyPzGlo(pNeut); + trBach.getPxPyPzGlo(pBach); + std::array pCasc = {pNeut[0] + pBach[0], pNeut[1] + pBach[1], pNeut[2] + pBach[2]}; + auto p2Casc = pCasc[0] * pCasc[0] + pCasc[1] * pCasc[1] + pCasc[2] * pCasc[2]; + const auto& pv = recoData.getPrimaryVertex(cascIdx.getVertexID()); + const auto cascXYZ = mFitterCasc.getPCACandidatePos(cand); + float dx = cascXYZ[0] - pv.getX(), dy = cascXYZ[1] - pv.getY(), dz = cascXYZ[2] - pv.getZ(), prodXYZ = dx * pCasc[0] + dy * pCasc[1] + dz * pCasc[2]; + float cosPA = prodXYZ / std::sqrt((dx * dx + dy * dy + dz * dz) * p2Casc); + new (&casc) o2::dataformats::Cascade(cascXYZ, pCasc, mFitterCasc.calcPCACovMatrixFlat(cand), trNeut, trBach); + casc.setDCA(mFitterCasc.getChi2AtPCACandidate(cand)); + casc.setCosPA(cosPA); + return true; +} + void TrackMCStudy::loadTPCOccMap(const o2::globaltracking::RecoContainer& recoData) { auto NHBPerTF = o2::base::GRPGeomHelper::instance().getGRPECS()->getNHBFPerTF(); diff --git a/Detectors/GlobalTrackingWorkflow/study/src/TrackMCStudyTypes.cxx b/Detectors/GlobalTrackingWorkflow/study/src/TrackMCStudyTypes.cxx index b6236b7bf0e73..68881287b0e5a 100644 --- a/Detectors/GlobalTrackingWorkflow/study/src/TrackMCStudyTypes.cxx +++ b/Detectors/GlobalTrackingWorkflow/study/src/TrackMCStudyTypes.cxx @@ -130,13 +130,8 @@ int TrackFamily::getLongestTPCTrackEntry() const int TrackFamily::getNTPCClones() const { - int n = 0; - for (auto& t : recTracks) { - if (t.nClTPC > 0) { - n++; - } - } - return n; + // every stored track with TPC contribution has its standalone TPC track stored too, so the number of distinct TPC tracks is the number of standalone ones + return nEntTPC; } } // namespace o2::trackstudy