diff --git a/core/base/CbmMatchRecoToMC.cxx b/core/base/CbmMatchRecoToMC.cxx index 79624a362dbc28b11955c64fbfabaa929c38135b..77308a5c9c6a741c65485da2895ba97aec981715 100644 --- a/core/base/CbmMatchRecoToMC.cxx +++ b/core/base/CbmMatchRecoToMC.cxx @@ -45,6 +45,7 @@ Int_t CbmMatchRecoToMC::fEventNumber = 0; CbmMatchRecoToMC::CbmMatchRecoToMC() : FairTask("MatchRecoToMC") {} CbmMatchRecoToMC::~CbmMatchRecoToMC() { + if (fStsClusterMatches != nullptr) { fStsClusterMatches->Delete(); delete fStsClusterMatches; @@ -104,11 +105,6 @@ CbmMatchRecoToMC::~CbmMatchRecoToMC() { } } -void CbmMatchRecoToMC::SetIncludeMvdHitsInStsTrack( - Bool_t includeMvdHitsInStsTrack) { - fIncludeMvdHitsInStsTrack = includeMvdHitsInStsTrack; -} - InitStatus CbmMatchRecoToMC::Init() { ReadAndCreateDataBranches(); @@ -200,9 +196,7 @@ void CbmMatchRecoToMC::ReadAndCreateDataBranches() { CbmMCDataManager* mcManager = (CbmMCDataManager*) ioman->GetObject("MCDataManager"); - if (nullptr == mcManager) - LOG(fatal) - << "CbmMatchRecoToMC::ReadAndCreateDataBranches() NULL MCDataManager."; + if (nullptr == mcManager) { LOG(fatal) << "CbmMatchRecoToMC::ReadAndCreateDataBranches() NULL MCDataManager."; } fMCTracks = mcManager->InitBranch("MCTrack"); @@ -390,6 +384,17 @@ void CbmMatchRecoToMC::ReadAndCreateDataBranches() { } } + fIsMvdActive = (fMvdPoints || fMvdCluster || fMvdHits); + + // Currently in the time-based mode MVD is present but not reconstructed + // TODO: remove the check once the reconstruction works + if (fIsMvdActive && !fMvdHits) { + LOG(warning) << "CbmMatchRecoToMC: MVD hits are missing, MVD will not be " + "included to the STS track match"; + fIsMvdActive = false; + } + + // TOF fTofPoints = mcManager->InitBranch("TofPoint"); fTofHitDigiMatches = (TClonesArray*) ioman->GetObject("TofHitDigiMatch"); @@ -617,8 +622,7 @@ void CbmMatchRecoToMC::MatchTracks(const TClonesArray* hitMatches, if (nullptr == point) continue; if ( /*point->GetEventID() == trackMatch->GetMatchedLink().GetEntry() && */ - point->GetTrackID() - == trackMatch->GetMatchedLink().GetIndex()) { + point->GetTrackID() == trackMatch->GetMatchedLink().GetIndex()) { hasTrue = true; break; } @@ -640,19 +644,44 @@ void CbmMatchRecoToMC::MatchStsTracks(const TClonesArray* mvdHitMatches, CbmMCDataArray* stsPoints, const TClonesArray* tracks, TClonesArray* trackMatches) { - if (!((stsHitMatches && stsPoints && tracks && trackMatches) - && ((fIncludeMvdHitsInStsTrack) ? mvdHitMatches && mvdPoints : true))) + if (!tracks) { return; } + + if (!(stsHitMatches && stsPoints && tracks && trackMatches)) { + LOG(error) << "CbmMatchRecoToMC: missing the necessary STS info for the " + "STS track match"; + return; + } + + if (fIsMvdActive && !(mvdHitMatches && mvdPoints)) { + LOG(error) << "CbmMatchRecoToMC: missing the necessary MVD info for the " + "STS track match"; return; + } + + // make sure that the Mvd hits are not present in the reconstruced tracks + // when we assume that the Mvd reconstruction was disabled + if (!fIsMvdActive) { + for (Int_t iTrack = 0; iTrack < trackMatches->GetEntriesFast(); iTrack++) { + const CbmStsTrack* track = static_cast<const CbmStsTrack*>(tracks->At(iTrack)); + if (track->GetNofMvdHits() > 0) { + LOG(error) << "CbmMatchRecoToMC: Sts track contains Mvd hits, but " + "there is no MVD data available"; + return; + } + } + } Bool_t editMode = (trackMatches->GetEntriesFast() != 0); Int_t nofTracks = tracks->GetEntriesFast(); + for (Int_t iTrack = 0; iTrack < nofTracks; iTrack++) { const CbmStsTrack* track = static_cast<const CbmStsTrack*>(tracks->At(iTrack)); CbmTrackMatchNew* trackMatch = (editMode) ? static_cast<CbmTrackMatchNew*>(trackMatches->At(iTrack)) : new ((*trackMatches)[iTrack]) CbmTrackMatchNew(); + Int_t nofStsHits = track->GetNofStsHits(); for (Int_t iHit = 0; iHit < nofStsHits; iHit++) { const CbmMatch* hitMatch = @@ -662,41 +691,37 @@ void CbmMatchRecoToMC::MatchStsTracks(const TClonesArray* mvdHitMatches, const CbmLink& link = hitMatch->GetLink(iLink); const FairMCPoint* point = static_cast<const FairMCPoint*>(stsPoints->Get(link)); - if (nullptr == point) continue; - ////fix low energy cut case on STS + assert(point); + /// fix low energy cut case on STS if (CbmStsAddress::GetSystemId(point->GetDetectorID()) == ECbmModuleId::kSts) { Int_t mcTrackId = point->GetTrackID(); CbmMCTrack* mcTrack = (CbmMCTrack*) fMCTracks->Get( link.GetFile(), link.GetEntry(), mcTrackId); - if (!mcTrack) continue; - if (mcTrack->GetNPoints(ECbmModuleId::kSts) < 2) continue; + assert(mcTrack); + if (mcTrack->GetNPoints(ECbmModuleId::kSts) < 2) { continue; } } - //// + /// trackMatch->AddLink( CbmLink(1., point->GetTrackID(), link.GetEntry(), link.GetFile())); } } - // Include MVD hits in STS matching if needed. - if (fIncludeMvdHitsInStsTrack) { - Int_t nofMvdHits = track->GetNofMvdHits(); - for (Int_t iHit = 0; iHit < nofMvdHits; iHit++) { - const CbmMatch* hitMatch = static_cast<CbmMatch*>( - mvdHitMatches->At(track->GetMvdHitIndex(iHit))); - Int_t nofLinks = hitMatch->GetNofLinks(); - for (Int_t iLink = 0; iLink < nofLinks; iLink++) { - const CbmLink& link = hitMatch->GetLink(iLink); - const FairMCPoint* point = - static_cast<const FairMCPoint*>(mvdPoints->Get(link)); - if (nullptr == point) continue; - trackMatch->AddLink( - CbmLink(1., point->GetTrackID(), link.GetEntry(), link.GetFile())); - } + // Include MVD hits in STS matching if MVD is active + Int_t nofMvdHits = track->GetNofMvdHits(); + for (Int_t iHit = 0; iHit < nofMvdHits; iHit++) { + const CbmMatch* hitMatch = static_cast<CbmMatch*>(mvdHitMatches->At(track->GetMvdHitIndex(iHit))); + Int_t nofLinks = hitMatch->GetNofLinks(); + for (Int_t iLink = 0; iLink < nofLinks; iLink++) { + const CbmLink& link = hitMatch->GetLink(iLink); + const FairMCPoint* point = static_cast<const FairMCPoint*>(mvdPoints->Get(link)); + assert(point); + trackMatch->AddLink(CbmLink(1., point->GetTrackID(), link.GetEntry(), link.GetFile())); } } - if (!trackMatch->GetNofLinks()) continue; + if (!trackMatch->GetNofLinks()) { continue; } + // Calculate number of true and wrong hits Int_t trueCounter = trackMatch->GetNofTrueHits(); Int_t wrongCounter = trackMatch->GetNofWrongHits(); @@ -708,44 +733,39 @@ void CbmMatchRecoToMC::MatchStsTracks(const TClonesArray* mvdHitMatches, for (Int_t iLink = 0; iLink < nofLinks; iLink++) { const FairMCPoint* point = static_cast<const FairMCPoint*>( stsPoints->Get(hitMatch->GetLink(iLink))); - if (nullptr == point) continue; + if (nullptr == point) { continue; } if (point->GetTrackID() == trackMatch->GetMatchedLink().GetIndex()) { hasTrue = true; break; } } - if (hasTrue) - trueCounter++; - else + if (hasTrue) { trueCounter++; } + else { wrongCounter++; + } } - // Include MVD hits in STS track matching if needed - if (fIncludeMvdHitsInStsTrack) { - Int_t nofMvdHits = track->GetNofMvdHits(); - for (Int_t iHit = 0; iHit < nofMvdHits; iHit++) { - const CbmMatch* hitMatch = static_cast<CbmMatch*>( - mvdHitMatches->At(track->GetMvdHitIndex(iHit))); - Int_t nofLinks = hitMatch->GetNofLinks(); - Bool_t hasTrue = false; - for (Int_t iLink = 0; iLink < nofLinks; iLink++) { - const FairMCPoint* point = static_cast<const FairMCPoint*>( - mvdPoints->Get(hitMatch->GetLink(iLink))); - if (nullptr == point) continue; - if ( - /*point->GetEventID() == trackMatch->GetMatchedLink().GetEntry() && */ - point->GetTrackID() - == trackMatch->GetMatchedLink().GetIndex()) { - hasTrue = true; - break; - } + // Include MVD hits in STS matching if MVD is active + for (Int_t iHit = 0; iHit < nofMvdHits; iHit++) { + const CbmMatch* hitMatch = static_cast<CbmMatch*>(mvdHitMatches->At(track->GetMvdHitIndex(iHit))); + Int_t nofLinks = hitMatch->GetNofLinks(); + Bool_t hasTrue = false; + for (Int_t iLink = 0; iLink < nofLinks; iLink++) { + const FairMCPoint* point = static_cast<const FairMCPoint*>(mvdPoints->Get(hitMatch->GetLink(iLink))); + if (nullptr == point) { continue; } + if ( + /*point->GetEventID() == trackMatch->GetMatchedLink().GetEntry() && */ + point->GetTrackID() == trackMatch->GetMatchedLink().GetIndex()) { + hasTrue = true; + break; } - if (hasTrue) - trueCounter++; - else - wrongCounter++; + } + if (hasTrue) { trueCounter++; } + else { + wrongCounter++; } } + trackMatch->SetNofTrueHits(trueCounter); trackMatch->SetNofWrongHits(wrongCounter); // LOG(debug) << iTrack << " "; track->Print(); LOG(debug) << " " << trackMatch->ToString(); diff --git a/core/base/CbmMatchRecoToMC.h b/core/base/CbmMatchRecoToMC.h index 9a8fe6efb23d30212c375ed1ec9f075576e19c69..46246efafc813944702e878638254bf6f24f7b0d 100644 --- a/core/base/CbmMatchRecoToMC.h +++ b/core/base/CbmMatchRecoToMC.h @@ -50,8 +50,6 @@ public: */ virtual void Finish(); - void SetIncludeMvdHitsInStsTrack(Bool_t includeMvdHitsInStsTrack); - private: /** * \brief Read and create data branches. @@ -153,7 +151,7 @@ public: private: static Int_t fEventNumber; - Bool_t fIncludeMvdHitsInStsTrack = kFALSE; + Bool_t fIsMvdActive = kTRUE; // is the Mvd module active Bool_t fbDigiExpUsed = kTRUE; // Usage of CbmTofDigiExp instead of CbmTofDigi CbmMCDataArray* fMCTracks = nullptr; //! Monte-Carlo tracks diff --git a/macro/KF/KFParticleFinderSignalTest/Signal/recoSignal.C b/macro/KF/KFParticleFinderSignalTest/Signal/recoSignal.C index 44b690b3953028ffc2b845fabbea73cef2c25c0e..3747923eed8f6cd2100d88552678ccdaf87b633a 100644 --- a/macro/KF/KFParticleFinderSignalTest/Signal/recoSignal.C +++ b/macro/KF/KFParticleFinderSignalTest/Signal/recoSignal.C @@ -294,7 +294,6 @@ void recoSignal(Int_t nEvents = 1000, // --- STS track matching ---------------------------------------------- CbmMatchRecoToMC* matchTask2 = new CbmMatchRecoToMC(); - if (setup->IsActive(kMvd)) matchTask2->SetIncludeMvdHitsInStsTrack(1); run->AddTask(matchTask2); // ------------------------------------------------------------------------- diff --git a/macro/analysis/opencharm/opencharm_reco.C b/macro/analysis/opencharm/opencharm_reco.C index 87fa9ea11c1c68b205d17a332e3db8ac40603281..78e081039079dfcb4e7c569fc2dae5039dcf2064 100644 --- a/macro/analysis/opencharm/opencharm_reco.C +++ b/macro/analysis/opencharm/opencharm_reco.C @@ -329,7 +329,6 @@ void opencharm_reco(Int_t nEvents = 10, Int_t ProcID = 1, bool PileUp = false) { //------ Match Monte Carlo Data to Reco Data ------------------------- CbmMatchRecoToMC* matcher = new CbmMatchRecoToMC(); - matcher->SetIncludeMvdHitsInStsTrack(kTRUE); run->AddTask(matcher); // ------------------------------------------------------------------------ /* diff --git a/macro/kronos/macro/run_reco.C b/macro/kronos/macro/run_reco.C index 512108dc3110a524906355fe8fc614cc4544be45..53c7100bd6daef53e4aa537b166bd33347929075 100644 --- a/macro/kronos/macro/run_reco.C +++ b/macro/kronos/macro/run_reco.C @@ -274,7 +274,6 @@ void run_reco(TString setupName, Int_t nEvents = 10) { // --- STS track matching ---------------------------------------------- CbmMatchRecoToMC* matchTask2 = new CbmMatchRecoToMC(); - if (setup->IsActive(kMvd)) matchTask2->SetIncludeMvdHitsInStsTrack(1); run->AddTask(matchTask2); // ------------------------------------------------------------------------- diff --git a/macro/run/modules/reconstruct.C b/macro/run/modules/reconstruct.C index cd77a189efcc370c42df9e8d605adb09d03f4c68..c4a010fdca9e1f664760816fdedc136568e72e33 100644 --- a/macro/run/modules/reconstruct.C +++ b/macro/run/modules/reconstruct.C @@ -248,8 +248,6 @@ Bool_t reconstruct(Bool_t useMC = kFALSE, Bool_t searchPV = kTRUE) { // ----- Track matching ----------------------------------------------- if (useMC) { CbmMatchRecoToMC* match2 = new CbmMatchRecoToMC(); - if (setup->IsActive(ECbmModuleId::kMvd)) - match2->SetIncludeMvdHitsInStsTrack(1); run->AddTask(match2); } // ------------------------------------------------------------------------- diff --git a/macro/run/run_reco_tb_track.C b/macro/run/run_reco_tb_track.C index b288146cee64923a9b80f93aa3581a862fc4a365..141a20b1bb075c89018a2115952ec3881570b827 100644 --- a/macro/run/run_reco_tb_track.C +++ b/macro/run/run_reco_tb_track.C @@ -182,7 +182,6 @@ void run_reco_tb_track(TString dataSet = "test", if (useMC) { // --- STS MC matching ---------------------------------------------- CbmMatchRecoToMC* matchTask = new CbmMatchRecoToMC(); - matchTask->SetIncludeMvdHitsInStsTrack(0); run->AddTask(matchTask); }