From 27f699f585f72ae9bd5961053f3c784c99cc0d85 Mon Sep 17 00:00:00 2001 From: "se.gorbunov" <se.gorbunov@gsi.de> Date: Mon, 19 Jun 2023 16:20:13 +0000 Subject: [PATCH] L1: cleanup the Fitter for the Particle Finder; remove failing requests to the run manager --- reco/L1/ParticleFinder/CbmL1PFFitter.cxx | 160 +++++++++++++---------- reco/L1/ParticleFinder/CbmL1PFFitter.h | 13 ++ 2 files changed, 106 insertions(+), 67 deletions(-) diff --git a/reco/L1/ParticleFinder/CbmL1PFFitter.cxx b/reco/L1/ParticleFinder/CbmL1PFFitter.cxx index ee121c60d2..559e18e6fb 100644 --- a/reco/L1/ParticleFinder/CbmL1PFFitter.cxx +++ b/reco/L1/ParticleFinder/CbmL1PFFitter.cxx @@ -57,9 +57,6 @@ namespace NS_L1TrackFitter } // namespace NS_L1TrackFitter using namespace NS_L1TrackFitter; -CbmL1PFFitter::CbmL1PFFitter() {} - -CbmL1PFFitter::~CbmL1PFFitter() {} inline void CbmL1PFFitter::PFFieldRegion::setFromL1FieldRegion(const L1FieldRegion& fld, int i) { @@ -98,6 +95,48 @@ inline void CbmL1PFFitter::PFFieldRegion::getL1FieldRegion(L1FieldRegion& fld, i inline CbmL1PFFitter::PFFieldRegion::PFFieldRegion(const L1FieldRegion& fld, int i) { setFromL1FieldRegion(fld, i); } +CbmL1PFFitter::CbmL1PFFitter() {} + +CbmL1PFFitter::~CbmL1PFFitter() {} + +inline void CbmL1PFFitter::Initialize() +{ + if (fIsInitialised) return; + + fNmvdStationsActive = 0; + fNstsStationsActive = 0; + fMvdHitArray = nullptr; + fStsHitArray = nullptr; + + FairRootManager* manager = FairRootManager::Instance(); + + if (!manager) { LOG(fatal) << "CbmL1PFFitter: no FairRootManager"; } + + if (!CbmL1::Instance() || !CbmL1::Instance()->fpAlgo || !CbmL1::Instance()->fpAlgo->GetParameters()) { + LOG(fatal) << "CbmL1PFFitter: no CbmL1 task initialised "; + } + + fNmvdStationsActive = CbmL1::Instance()->fpAlgo->GetParameters()->GetNstationsActive(L1DetectorID::kMvd); + fNstsStationsActive = CbmL1::Instance()->fpAlgo->GetParameters()->GetNstationsActive(L1DetectorID::kSts); + + if (fNmvdStationsActive > 0) { fMvdHitArray = static_cast<TClonesArray*>(manager->GetObject("MvdHit")); } + if (fNstsStationsActive > 0) { fStsHitArray = static_cast<TClonesArray*>(manager->GetObject("StsHit")); } + + fIsInitialised = true; +} + +inline int CbmL1PFFitter::GetMvdStationIndex(const CbmMvdHit* hit) +{ + return CbmL1::Instance()->fpAlgo->GetParameters()->GetStationIndexActive(hit->GetStationNr(), L1DetectorID::kMvd); +} + +inline int CbmL1PFFitter::GetStsStationIndex(const CbmStsHit* hit) +{ + return CbmL1::Instance()->fpAlgo->GetParameters()->GetStationIndexActive( + CbmStsSetup::Instance()->GetStationNumber(hit->GetAddress()), L1DetectorID::kSts); +} + + void FilterFirst(L1Fit& fit, fvec& x, fvec& y, fvec& dxx, fvec& dxy, fvec& dyy) { L1TrackPar& tr = fit.Tr(); @@ -114,6 +153,8 @@ void CbmL1PFFitter::Fit(std::vector<CbmStsTrack>& Tracks, const std::vector<CbmM const std::vector<CbmStsHit>& vStsHits, const std::vector<int>& pidHypo) { + Initialize(); + L1FieldValue b0, b1, b2 _fvecalignment; L1FieldRegion fld _fvecalignment; // fld.SetUseOriginalField(); @@ -223,11 +264,9 @@ void CbmL1PFFitter::Fit(std::vector<CbmStsTrack>& Tracks, const std::vector<CbmM posy = hit->GetY(); posz = hit->GetZ(); time = hit->GetTime(); + ista = GetMvdStationIndex(hit); + if (ista < 0) continue; - // ista = hit->GetStationNr(); - ista = - CbmL1::Instance()->fpAlgo->GetParameters()->GetStationIndexActive(hit->GetStationNr(), L1DetectorID::kMvd); - if (ista == -1) continue; du2[ista][iVec] = hit->GetDx() * hit->GetDx(); dv2[ista][iVec] = hit->GetDy() * hit->GetDy(); dt2[ista][iVec] = hit->GetTimeError() * hit->GetTimeError(); @@ -240,12 +279,9 @@ void CbmL1PFFitter::Fit(std::vector<CbmStsTrack>& Tracks, const std::vector<CbmM posy = hit->GetY(); posz = hit->GetZ(); time = hit->GetTime(); + ista = GetStsStationIndex(hit); + if (ista < 0) continue; - // ista = CbmStsSetup::Instance()->GetStationNumber(hit->GetAddress()) - // + NMvdStations; //hit->GetStationNr() - 1 + NMvdStations; - ista = CbmL1::Instance()->fpAlgo->GetParameters()->GetStationIndexActive( - CbmStsSetup::Instance()->GetStationNumber(hit->GetAddress()), L1DetectorID::kSts); - if (ista == -1) continue; du2[ista][iVec] = hit->GetDu() * hit->GetDu(); dv2[ista][iVec] = hit->GetDv() * hit->GetDv(); dt2[ista][iVec] = hit->GetTimeError() * hit->GetTimeError(); @@ -443,23 +479,20 @@ void CbmL1PFFitter::Fit(std::vector<CbmStsTrack>& Tracks, const std::vector<CbmM void CbmL1PFFitter::Fit(vector<CbmStsTrack>& Tracks, const vector<int>& pidHypo) { - FairRootManager* fManger = FairRootManager::Instance(); - TClonesArray* mvdHitArray = static_cast<TClonesArray*>(fManger->GetObject("MvdHit")); - TClonesArray* stsHitArray = static_cast<TClonesArray*>(fManger->GetObject("StsHit")); + Initialize(); std::vector<CbmMvdHit> vMvdHits; std::vector<CbmStsHit> vStsHits; - if (mvdHitArray) { - for (int ih = 0; ih < mvdHitArray->GetEntriesFast(); ih++) { - CbmMvdHit hit = *dynamic_cast<const CbmMvdHit*>(mvdHitArray->At(ih)); - vMvdHits.push_back(hit); + if (fMvdHitArray) { + for (int ih = 0; ih < fMvdHitArray->GetEntriesFast(); ih++) { + vMvdHits.push_back(*dynamic_cast<const CbmMvdHit*>(fMvdHitArray->At(ih))); } } - if (stsHitArray) { - for (int ih = 0; ih < stsHitArray->GetEntriesFast(); ih++) { - vStsHits.push_back(*dynamic_cast<const CbmStsHit*>(stsHitArray->At(ih))); + if (fStsHitArray) { + for (int ih = 0; ih < fStsHitArray->GetEntriesFast(); ih++) { + vStsHits.push_back(*dynamic_cast<const CbmStsHit*>(fStsHitArray->At(ih))); } } @@ -470,6 +503,8 @@ void CbmL1PFFitter::Fit(vector<CbmStsTrack>& Tracks, const vector<int>& pidHypo) void CbmL1PFFitter::GetChiToVertex(vector<CbmStsTrack>& Tracks, vector<PFFieldRegion>& field, vector<float>& chiToVtx, CbmKFVertex& primVtx, float chiPrim) { + Initialize(); + chiToVtx.reserve(Tracks.size()); int nTracks_SIMD = fvec::size(); @@ -479,8 +514,8 @@ void CbmL1PFFitter::GetChiToVertex(vector<CbmStsTrack>& Tracks, vector<PFFieldRe CbmStsTrack* tr[fvec::size()] {nullptr}; - int nStations = CbmL1::Instance()->fpAlgo->GetParameters()->GetNstationsActive(); - int NMvdStations = CbmL1::Instance()->fpAlgo->GetNstationsBeforePipe(); + int nStations = fNmvdStationsActive + fNstsStationsActive; + const L1Station* sta = CbmL1::Instance()->fpAlgo->GetParameters()->GetStations().begin(); fvec* zSta = new fvec[nStations]; for (int iSta = 0; iSta < nStations; iSta++) { @@ -492,10 +527,6 @@ void CbmL1PFFitter::GetChiToVertex(vector<CbmStsTrack>& Tracks, vector<PFFieldRe L1FieldRegion fld _fvecalignment; L1FieldValue fB[3], fB_temp _fvecalignment; fvec zField[3]; - FairRootManager* fManger = FairRootManager::Instance(); - TClonesArray* listStsHits = static_cast<TClonesArray*>(fManger->GetObject("StsHit")); - TClonesArray* listMvdHits = 0; - if (NMvdStations > 0.) listMvdHits = static_cast<TClonesArray*>(fManger->GetObject("MvdHit")); unsigned short N_vTracks = Tracks.size(); int ista; @@ -535,25 +566,26 @@ void CbmL1PFFitter::GetChiToVertex(vector<CbmStsTrack>& Tracks, vector<PFFieldRe float posx = 0.f, posy = 0.f, posz = 0.f; if (iH < nHitsTrackMvd) { - if (!listMvdHits) continue; - int hitIndex = tr[iVec]->GetMvdHitIndex(iH); - CbmMvdHit* hit = L1_DYNAMIC_CAST<CbmMvdHit*>(listMvdHits->At(hitIndex)); + if (!fMvdHitArray) continue; + int hitIndex = tr[iVec]->GetMvdHitIndex(iH); + const CbmMvdHit* hit = dynamic_cast<const CbmMvdHit*>(fMvdHitArray->At(hitIndex)); posx = hit->GetX(); posy = hit->GetY(); posz = hit->GetZ(); - ista = hit->GetStationNr(); + ista = GetMvdStationIndex(hit); + if (ista < 0) continue; } else { - if (!listStsHits) continue; - int hitIndex = tr[iVec]->GetHitIndex(iH - nHitsTrackMvd); - CbmStsHit* hit = L1_DYNAMIC_CAST<CbmStsHit*>(listStsHits->At(hitIndex)); + if (!fStsHitArray) continue; + int hitIndex = tr[iVec]->GetHitIndex(iH - nHitsTrackMvd); + const CbmStsHit* hit = dynamic_cast<const CbmStsHit*>(fStsHitArray->At(hitIndex)); posx = hit->GetX(); posy = hit->GetY(); posz = hit->GetZ(); - ista = CbmStsSetup::Instance()->GetStationNumber(hit->GetAddress()) - + NMvdStations; //hit->GetStationNr()-1+NMvdStations; + ista = GetStsStationIndex(hit); + if (ista < 0) continue; } sta[ista].fieldSlice.GetFieldValue(posx, posy, fB_temp); @@ -637,16 +669,12 @@ void CbmL1PFFitter::GetChiToVertex(vector<CbmStsTrack>& Tracks, vector<PFFieldRe void CbmL1PFFitter::CalculateFieldRegion(vector<CbmStsTrack>& Tracks, vector<PFFieldRegion>& field) { + Initialize(); + field.reserve(Tracks.size()); L1FieldRegion fld _fvecalignment; - FairRootManager* fManger = FairRootManager::Instance(); - TClonesArray* listStsHits = static_cast<TClonesArray*>(fManger->GetObject("StsHit")); - TClonesArray* listMvdHits = 0; - int NMvdStations = CbmL1::Instance()->fpAlgo->GetNstationsBeforePipe(); - if (NMvdStations > 0.) listMvdHits = static_cast<TClonesArray*>(fManger->GetObject("MvdHit")); - int nTracks_SIMD = fvec::size(); L1TrackPar T; // fitting parametr coresponding to current track @@ -671,25 +699,26 @@ void CbmL1PFFitter::CalculateFieldRegion(vector<CbmStsTrack>& Tracks, vector<PFF float posx = 0.f, posy = 0.f, posz = 0.f; if (iH < nHitsTrackMvd) { - if (!listMvdHits) continue; - int hitIndex = tr[iVec]->GetMvdHitIndex(iH); - CbmMvdHit* hit = L1_DYNAMIC_CAST<CbmMvdHit*>(listMvdHits->At(hitIndex)); + if (!fMvdHitArray) continue; + int hitIndex = tr[iVec]->GetMvdHitIndex(iH); + const CbmMvdHit* hit = dynamic_cast<const CbmMvdHit*>(fMvdHitArray->At(hitIndex)); posx = hit->GetX(); posy = hit->GetY(); posz = hit->GetZ(); - ista = hit->GetStationNr(); + ista = GetMvdStationIndex(hit); + if (ista < 0) continue; } else { - if (!listStsHits) continue; - int hitIndex = tr[iVec]->GetHitIndex(iH - nHitsTrackMvd); - CbmStsHit* hit = L1_DYNAMIC_CAST<CbmStsHit*>(listStsHits->At(hitIndex)); + if (!fStsHitArray) continue; + int hitIndex = tr[iVec]->GetHitIndex(iH - nHitsTrackMvd); + const CbmStsHit* hit = dynamic_cast<const CbmStsHit*>(fStsHitArray->At(hitIndex)); posx = hit->GetX(); posy = hit->GetY(); posz = hit->GetZ(); - ista = CbmStsSetup::Instance()->GetStationNumber(hit->GetAddress()) - + NMvdStations; //hit->GetStationNr()-1+NMvdStations; + ista = GetStsStationIndex(hit); + if (ista < 0) continue; } sta[ista].fieldSlice.GetFieldValue(posx, posy, fB_temp); @@ -711,16 +740,12 @@ void CbmL1PFFitter::CalculateFieldRegion(vector<CbmStsTrack>& Tracks, vector<PFF void CbmL1PFFitter::CalculateFieldRegionAtLastPoint(vector<CbmStsTrack>& Tracks, vector<PFFieldRegion>& field) { + Initialize(); + field.reserve(Tracks.size()); L1FieldRegion fld _fvecalignment; - FairRootManager* fManger = FairRootManager::Instance(); - TClonesArray* listStsHits = static_cast<TClonesArray*>(fManger->GetObject("StsHit")); - TClonesArray* listMvdHits = 0; - int NMvdStations = CbmL1::Instance()->fpAlgo->GetNstationsBeforePipe(); - if (NMvdStations > 0.) listMvdHits = static_cast<TClonesArray*>(fManger->GetObject("MvdHit")); - int nTracks_SIMD = fvec::size(); L1TrackPar T; // fitting parametr coresponding to current track @@ -748,25 +773,26 @@ void CbmL1PFFitter::CalculateFieldRegionAtLastPoint(vector<CbmStsTrack>& Tracks, int hitNumber = nHits - iH - 1; if (hitNumber < nHitsTrackMvd) { - if (!listMvdHits) continue; - int hitIndex = tr[iVec]->GetMvdHitIndex(hitNumber); - CbmMvdHit* hit = L1_DYNAMIC_CAST<CbmMvdHit*>(listMvdHits->At(hitIndex)); + if (!fMvdHitArray) continue; + int hitIndex = tr[iVec]->GetMvdHitIndex(hitNumber); + const CbmMvdHit* hit = dynamic_cast<const CbmMvdHit*>(fMvdHitArray->At(hitIndex)); posx = hit->GetX(); posy = hit->GetY(); posz = hit->GetZ(); - ista = hit->GetStationNr(); + ista = GetMvdStationIndex(hit); + if (ista < 0) continue; } else { - if (!listStsHits) continue; - int hitIndex = tr[iVec]->GetHitIndex(hitNumber - nHitsTrackMvd); - CbmStsHit* hit = L1_DYNAMIC_CAST<CbmStsHit*>(listStsHits->At(hitIndex)); + if (!fStsHitArray) continue; + int hitIndex = tr[iVec]->GetHitIndex(hitNumber - nHitsTrackMvd); + const CbmStsHit* hit = dynamic_cast<const CbmStsHit*>(fStsHitArray->At(hitIndex)); posx = hit->GetX(); posy = hit->GetY(); posz = hit->GetZ(); - ista = CbmStsSetup::Instance()->GetStationNumber(hit->GetAddress()) - + NMvdStations; //hit->GetStationNr()-1+NMvdStations; + ista = GetStsStationIndex(hit); + if (ista < 0) continue; } sta[ista].fieldSlice.GetFieldValue(posx, posy, fB_temp); diff --git a/reco/L1/ParticleFinder/CbmL1PFFitter.h b/reco/L1/ParticleFinder/CbmL1PFFitter.h index 1955f4db34..8fe2bfb3ce 100644 --- a/reco/L1/ParticleFinder/CbmL1PFFitter.h +++ b/reco/L1/ParticleFinder/CbmL1PFFitter.h @@ -27,6 +27,7 @@ class CbmStsHit; class CbmStsTrack; class L1FieldRegion; class CbmKFVertex; +class TClonesArray; class CbmL1PFFitter { public: @@ -51,5 +52,17 @@ public: void CalculateFieldRegionAtLastPoint(std::vector<CbmStsTrack>& Tracks, std::vector<PFFieldRegion>& field); void GetChiToVertex(std::vector<CbmStsTrack>& Tracks, std::vector<PFFieldRegion>& field, std::vector<float>& chiToVtx, CbmKFVertex& primVtx, float chiPrim = -1); + +private: + void Initialize(); + int GetMvdStationIndex(const CbmMvdHit* h); + int GetStsStationIndex(const CbmStsHit* h); + +private: + bool fIsInitialised = {false}; // is the fitter initialised + int fNmvdStationsActive = {0}; // n MVD stations + int fNstsStationsActive = {0}; // n STS stations + TClonesArray* fMvdHitArray {nullptr}; // pointer to MVD hits + TClonesArray* fStsHitArray {nullptr}; // pointer to STS hits }; #endif -- GitLab