diff --git a/core/data/global/CbmVertex.cxx b/core/data/global/CbmVertex.cxx index dc77aaf3ef0248593c8839e78099a1bdea282a11..73f86d6d22f1e889ad785ad8cd864c725ad4a7b0 100644 --- a/core/data/global/CbmVertex.cxx +++ b/core/data/global/CbmVertex.cxx @@ -1,6 +1,6 @@ -/* Copyright (C) 2005-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt +/* Copyright (C) 2005-2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt SPDX-License-Identifier: GPL-3.0-only - Authors: Volker Friese, Florian Uhlig, Denis Bertini [committer] */ + Authors: Volker Friese, Florian Uhlig, Alex Bercuci, Denis Bertini [committer] */ // ------------------------------------------------------------------------- // ----- CbmVertex source file ----- @@ -178,5 +178,45 @@ string CbmVertex::ToString() const } // ------------------------------------------------------------------------- +// ------------------------------------------------------------------------- +int32_t CbmVertex::GetTrackIndex(int32_t iTrack) const +{ + if (iTrack < 0 || iTrack >= fNTracks) { + LOG(warning) << GetName() << "::GetTrackIndex(" << iTrack << ") : outside range."; + return -1; + } + if (!fTrkIdx.size() || size_t(iTrack) >= fTrkIdx.size()) return -1; + return fTrkIdx[iTrack]; +} +// ------------------------------------------------------------------------- + +// ------------------------------------------------------------------------- +bool CbmVertex::FindTrackByIndex(uint32_t iTrack) const +{ + auto idx = find_if(fTrkIdx.begin(), fTrkIdx.end(), [iTrack](uint32_t p) { return p == iTrack; }); + if (idx != fTrkIdx.end()) return true; + return false; +} +// ------------------------------------------------------------------------- + +// ------------------------------------------------------------------------- +bool CbmVertex::SetTracks(std::vector<uint32_t>& indexVector) +{ + fTrkIdx = indexVector; + + if (!fNTracks) + fNTracks = fTrkIdx.size(); + else { + if (size_t(fNTracks) != fTrkIdx.size()) { + LOG(error) << GetName() + << "::SetTracks() : fNTracks does not match fTrkIdx info. This might point to a problem !"; + fNTracks = fTrkIdx.size(); + return false; + } + } + + return true; +} +// ------------------------------------------------------------------------- ClassImp(CbmVertex) diff --git a/core/data/global/CbmVertex.h b/core/data/global/CbmVertex.h index 4c73ffa93987fe36bc782c44e58deff06d4b3160..2e6624607699594f4e2047f4a22c8582351580df 100644 --- a/core/data/global/CbmVertex.h +++ b/core/data/global/CbmVertex.h @@ -1,6 +1,6 @@ -/* Copyright (C) 2006-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt +/* Copyright (C) 2006-2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt SPDX-License-Identifier: GPL-3.0-only - Authors: Volker Friese, Florian Uhlig, Denis Bertini [committer] */ + Authors: Volker Friese, Florian Uhlig, Alex Bercuci, Denis Bertini [committer] */ // ------------------------------------------------------------------------- // ----- CbmVertex header file ----- @@ -27,6 +27,7 @@ #include <cstdint> #include <string> // for string +#include <vector> // for global track indices class CbmVertex : public TNamed { @@ -73,6 +74,11 @@ public: void CovMatrix(TMatrixFSym& covMat) const; double GetCovariance(int32_t i, int32_t j) const; + /** \brief Accessors to the Global track array. Retrieve the tracks being actually used for vertex fit by entry in the indices array*/ + int32_t GetTrackIndex(int32_t iTrack) const; + /** \brief Accessors to the Global track array. Check if track with global index iTrack was actually used for vertex fit*/ + bool FindTrackByIndex(uint32_t iTrack) const; + bool SetTracks(std::vector<uint32_t>& indexVector); /** Reset the member variables **/ void Reset(); @@ -112,8 +118,10 @@ private: **/ Double32_t fCovMatrix[6]; + /** indices of [global] tracks being used for the vertex fit AB 24.07.17 for mCBM 2024*/ + std::vector<uint32_t> fTrkIdx = {}; - ClassDef(CbmVertex, 1); + ClassDef(CbmVertex, 2); }; diff --git a/reco/KF/CbmKFPrimaryVertexFinder.cxx b/reco/KF/CbmKFPrimaryVertexFinder.cxx index b5dc0fb8ff7f5c53717b9d1a2b29444a15ee9458..f5914e4e34c6091bb28175a5cb124263c7936194 100644 --- a/reco/KF/CbmKFPrimaryVertexFinder.cxx +++ b/reco/KF/CbmKFPrimaryVertexFinder.cxx @@ -1,6 +1,6 @@ -/* Copyright (C) 2006-2016 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt +/* Copyright (C) 2006-2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt SPDX-License-Identifier: GPL-3.0-only - Authors: Sergey Gorbunov, Ivan Kisel, Denis Bertini [committer] */ + Authors: Sergey Gorbunov, Alex Bercuci, Ivan Kisel, Denis Bertini [committer] */ /** Implementation of the CbmKFPrimaryVertexFinder class * @@ -25,14 +25,20 @@ ClassImp(CbmKFPrimaryVertexFinder) Tracks.clear(); } -void CbmKFPrimaryVertexFinder::AddTrack(CbmKFTrackInterface* Track) { Tracks.push_back(Track); } +void CbmKFPrimaryVertexFinder::AddTrack(CbmKFTrackInterface* Track, int32_t idx) +{ + Tracks.push_back(std::make_tuple(Track, idx, true)); +} -void CbmKFPrimaryVertexFinder::SetTracks(vector<CbmKFTrackInterface*>& vTr) { Tracks = vTr; } +void CbmKFPrimaryVertexFinder::SetTracks(vector<CbmKFTrackInterface*>& vTr) +{ + for (auto& trk : vTr) + Tracks.push_back(std::make_tuple(trk, -1, true)); +} void CbmKFPrimaryVertexFinder::Fit(CbmKFVertexInterface& vtx) { //* Constants - const Double_t CutChi2 = 3.5 * 3.5; const Int_t MaxIter = 3; @@ -86,12 +92,15 @@ void CbmKFPrimaryVertexFinder::Fit(CbmKFVertexInterface& vtx) vtx.GetRefNDF() = -3; vtx.GetRefChi2() = 0.; vtx.GetRefNTracks() = 0; + for (auto& trk : Tracks) { + // convert track to internal KF representation and reset used flag + auto itr = std::get<0>(trk); + std::get<2>(trk) = true; + CbmKFTrack T(*itr); - for (vector<CbmKFTrackInterface*>::iterator itr = Tracks.begin(); itr != Tracks.end(); ++itr) { - - CbmKFTrack T(**itr); Bool_t err = T.Extrapolate(r0[2]); if (err) { + std::get<2>(trk) = false; continue; } @@ -106,12 +115,17 @@ void CbmKFPrimaryVertexFinder::Fit(CbmKFVertexInterface& vtx) Double_t S[3] = {(C0[2] + V[2]), -(C0[1] + V[1]), (C0[0] + V[0])}; Double_t s = S[2] * S[0] - S[1] * S[1]; Double_t chi2 = zeta[0] * zeta[0] * S[0] + 2 * zeta[0] * zeta[1] * S[1] + zeta[1] * zeta[1] * S[2]; - if (chi2 > s * CutChi2) continue; - + if (chi2 > s * CutChi2) { + std::get<2>(trk) = false; + continue; + } //* Fit of vertex track slopes (a,b) to r0 vertex s = V[0] * V[2] - V[1] * V[1]; - if (s < 1.E-20) continue; + if (s < 1.E-20) { + std::get<2>(trk) = false; + continue; + } s = 1. / s; a = m[2] + s * ((V[3] * V[2] - V[4] * V[1]) * zeta[0] + (-V[3] * V[1] + V[4] * V[0]) * zeta[1]); b = m[3] + s * ((V[6] * V[2] - V[7] * V[1]) * zeta[0] + (-V[6] * V[1] + V[7] * V[0]) * zeta[1]); @@ -139,7 +153,10 @@ void CbmKFPrimaryVertexFinder::Fit(CbmKFVertexInterface& vtx) //* Invert S { Double_t w = S[0] * S[2] - S[1] * S[1]; - if (w < 1.E-200) continue; + if (w < 1.E-200) { + std::get<2>(trk) = false; + continue; + } w = 1. / w; Double_t S0 = S[0]; S[0] = w * S[2]; @@ -177,7 +194,6 @@ void CbmKFPrimaryVertexFinder::Fit(CbmKFVertexInterface& vtx) C[3] -= K[2][0] * CHt[0][0] + K[2][1] * CHt[0][1]; C[4] -= K[2][0] * CHt[1][0] + K[2][1] * CHt[1][1]; C[5] -= K[2][0] * CHt[2][0] + K[2][1] * CHt[2][1]; - } //* itr } //* finished iterations @@ -188,3 +204,14 @@ void CbmKFPrimaryVertexFinder::Fit(CbmKFVertexInterface& vtx) vtx.GetRefY() = r[1]; vtx.GetRefZ() = r[2]; } + +int CbmKFPrimaryVertexFinder::GetUsedTracks(std::vector<uint32_t>& idx) const +{ + idx.clear(); + for (auto& trk : Tracks) { + if (!std::get<2>(trk)) continue; + if (std::get<1>(trk) < 0) continue; + idx.push_back(std::get<1>(trk)); + } + return (int) idx.size(); +} diff --git a/reco/KF/CbmKFPrimaryVertexFinder.h b/reco/KF/CbmKFPrimaryVertexFinder.h index 969c61d4c6e659c8bd17fbfc0973fe45533c6514..ff6f725454465e779a3ce99b510036093fc4ada3 100644 --- a/reco/KF/CbmKFPrimaryVertexFinder.h +++ b/reco/KF/CbmKFPrimaryVertexFinder.h @@ -1,6 +1,6 @@ -/* Copyright (C) 2006-2015 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt +/* Copyright (C) 2006-2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt SPDX-License-Identifier: GPL-3.0-only - Authors: Sergey Gorbunov, Ivan Kisel, Denis Bertini [committer] */ + Authors: Sergey Gorbunov, Alex Bercuci, Ivan Kisel, Denis Bertini [committer] */ /** The CbmKFPrimaryVertexFinder class * @@ -17,21 +17,25 @@ #include "CbmKFTrackInterface.h" #include "CbmKFVertexInterface.h" +#include <tuple> #include <vector> class CbmKFPrimaryVertexFinder : public TObject { - std::vector<CbmKFTrackInterface*> Tracks; + std::vector<std::tuple<CbmKFTrackInterface*, int32_t, bool>> Tracks; public: CbmKFPrimaryVertexFinder() : Tracks() { Clear(); }; ~CbmKFPrimaryVertexFinder(){}; virtual void Clear(Option_t* opt = ""); - void AddTrack(CbmKFTrackInterface* Track); + void AddTrack(CbmKFTrackInterface* Track, int32_t idx = -1); void SetTracks(std::vector<CbmKFTrackInterface*>& vTracks); + + /** Return the list of indices og global tracks used for PV fit, if they were provided by the user */ + int GetUsedTracks(std::vector<uint32_t>& idx) const; void Fit(CbmKFVertexInterface& vtx); - ClassDef(CbmKFPrimaryVertexFinder, 1); + ClassDef(CbmKFPrimaryVertexFinder, 2); }; #endif /* !CBMKFPRIMARYVERTEXFINDER_H */ diff --git a/reco/KF/Interface/CbmPVFinderKFGlobal.cxx b/reco/KF/Interface/CbmPVFinderKFGlobal.cxx index 4db6df4e566e596a2ddd4ec30df449205834f223..3a74a0fc8a6e81a06dd6dd547ef5a491d14c9c11 100644 --- a/reco/KF/Interface/CbmPVFinderKFGlobal.cxx +++ b/reco/KF/Interface/CbmPVFinderKFGlobal.cxx @@ -1,6 +1,6 @@ /* Copyright (C) 2023-2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt SPDX-License-Identifier: GPL-3.0-only - Authors: Sergei Zharko [committer] */ + Authors: Sergei Zharko [committer], Alex Bercuci*/ /// \file CbmPVFinderKFGlobal.h /// \brief Primary vertex finder from the global tracks (implementation) @@ -84,21 +84,21 @@ Int_t CbmPVFinderKFGlobal::FindEventVertex(CbmEvent* event, TClonesArray* tracks auto iTrkEvent = event->GetIndex(ECbmDataType::kGlobalTrack, iT); auto* globalTrack = dynamic_cast<CbmGlobalTrack*>(tracks->At(iTrkEvent)); - if (globalTrack->GetStsTrackIndex() < 0) { - continue; - } - if (globalTrack->GetTrdTrackIndex() < 0) { - continue; - } - if (globalTrack->GetTofTrackIndex() < 0) { - continue; - } + // if (globalTrack->GetStsTrackIndex() < 0) { + // continue; + // } + // if (globalTrack->GetTrdTrackIndex() < 0) { + // continue; + // } + // if (globalTrack->GetTofTrackIndex() < 0) { + // continue; + // } if (globalTrack->GetChi2() < 0.) continue; CbmKFTrack& kfTrack = vKFTracks[iT]; kfTrack.SetGlobalTrack(*globalTrack); if (!std::isfinite(kfTrack.GetTrack()[0]) || !std::isfinite(kfTrack.GetCovMatrix()[0])) continue; - finder.AddTrack(&kfTrack); + finder.AddTrack(&kfTrack, iTrkEvent); } // Do the vertex finding @@ -107,7 +107,9 @@ Int_t CbmPVFinderKFGlobal::FindEventVertex(CbmEvent* event, TClonesArray* tracks // Copy KFVertex into CbmVertex kfVertex.GetVertex(*vertex); - + std::vector<uint32_t> idx; + finder.GetUsedTracks(idx); + vertex->SetTracks(idx); // Re-fit vertices of the global tracks for (int iT = 0; iT < nTracks; ++iT) { auto iTrkEvent = event->GetIndex(ECbmDataType::kGlobalTrack, iT); @@ -119,6 +121,5 @@ Int_t CbmPVFinderKFGlobal::FindEventVertex(CbmEvent* event, TClonesArray* tracks kfTrack.GetTrackParam(par); globalTrack->SetParamPrimaryVertex(&par); } - return vertex->GetNTracks(); }