Skip to content
Snippets Groups Projects

Rich: implementation of matching rings to mcTracks for multiple MC input files

Merged Martin Beyer requested to merge ma.beyer/cbmroot:rich_matchreco into master

Files

+ 49
29
@@ -849,51 +849,39 @@ void CbmMatchRecoToMC::MatchStsTracks(const TClonesArray* mvdHitMatches, const T
void CbmMatchRecoToMC::MatchRichRings(const TClonesArray* richRings, const TClonesArray* richHits,
// const TClonesArray* richDigis,
// const TClonesArray* richDigiMatches,
CbmMCDataArray* richMcPoints, CbmMCDataArray* mcTracks, TClonesArray* ringMatches)
{
// Loop over RichRings
Int_t nRings = richRings->GetEntriesFast();
for (Int_t iRing = 0; iRing < nRings; iRing++) {
const CbmRichRing* ring = static_cast<const CbmRichRing*>(richRings->At(iRing));
if (nullptr == ring) continue;
if (!ring) continue;
CbmTrackMatchNew* ringMatch = new ((*ringMatches)[iRing]) CbmTrackMatchNew();
Int_t nofHits = ring->GetNofHits();
for (Int_t iHit = 0; iHit < nofHits; iHit++) {
const CbmRichHit* hit = static_cast<const CbmRichHit*>(richHits->At(ring->GetHit(iHit)));
if (nullptr == hit) continue;
vector<pair<Int_t, Int_t>> motherIds =
GetMcTrackMotherIdsForRichHit(fDigiManager, hit, richMcPoints, mcTracks, fEventNumber);
for (UInt_t i = 0; i < motherIds.size(); i++) {
ringMatch->AddLink(1., motherIds[i].second, motherIds[i].first);
Int_t nHits = ring->GetNofHits();
for (Int_t iHit = 0; iHit < nHits; iHit++) {
const CbmRichHit* hit = static_cast<const CbmRichHit*>(richHits->At(static_cast<Int_t>(ring->GetHit(iHit))));
if (!hit) continue;
vector<CbmLink> motherIds = GetMcTrackMotherIdsForRichHit(fDigiManager, hit, richMcPoints, mcTracks);
for (const auto& motherId : motherIds) {
ringMatch->AddLink(motherId);
}
}
if (ringMatch->GetNofLinks() != 0) {
Int_t bestTrackId = ringMatch->GetMatchedLink().GetIndex();
Int_t bestTrackEventId = ringMatch->GetMatchedLink().GetEntry();
Int_t trueCounter = 0;
Int_t wrongCounter = 0;
for (Int_t iHit = 0; iHit < nofHits; iHit++) {
const CbmRichHit* hit = static_cast<const CbmRichHit*>(richHits->At(ring->GetHit(iHit)));
if (nullptr == hit) continue;
vector<pair<Int_t, Int_t>> motherIds =
GetMcTrackMotherIdsForRichHit(fDigiManager, hit, richMcPoints, mcTracks, fEventNumber);
if (std::find(motherIds.begin(), motherIds.end(), std::make_pair(bestTrackEventId, bestTrackId))
!= motherIds.end()) {
CbmLink bestTrackLink = ringMatch->GetMatchedLink();
Int_t trueCounter = 0;
Int_t wrongCounter = 0;
for (Int_t iHit = 0; iHit < nHits; iHit++) {
const CbmRichHit* hit = static_cast<const CbmRichHit*>(richHits->At(static_cast<Int_t>(ring->GetHit(iHit))));
if (!hit) continue;
vector<CbmLink> motherIds = GetMcTrackMotherIdsForRichHit(fDigiManager, hit, richMcPoints, mcTracks);
if (std::find(motherIds.begin(), motherIds.end(), bestTrackLink) != motherIds.end()) {
trueCounter++;
}
else {
wrongCounter++;
}
}
ringMatch->SetNofTrueHits(trueCounter);
ringMatch->SetNofWrongHits(wrongCounter);
}
@@ -901,10 +889,42 @@ void CbmMatchRecoToMC::MatchRichRings(const TClonesArray* richRings, const TClon
ringMatch->SetNofTrueHits(0);
ringMatch->SetNofWrongHits(0);
}
} // Ring loop
}
vector<CbmLink> CbmMatchRecoToMC::GetMcTrackMotherIdsForRichHit(CbmDigiManager* digiMan, const CbmRichHit* hit,
CbmMCDataArray* richPoints, CbmMCDataArray* mcTracks)
{
vector<CbmLink> result;
if (!hit) return result;
Int_t digiIndex = hit->GetRefId();
if (digiIndex < 0) return result;
const CbmRichDigi* digi = digiMan->Get<CbmRichDigi>(digiIndex);
if (!digi) return result;
const CbmMatch* digiMatch = digiMan->GetMatch(ECbmModuleId::kRich, digiIndex);
if (!digiMatch) return result;
vector<CbmLink> links = digiMatch->GetLinks();
for (const auto& link : links) {
Int_t pointId = link.GetIndex();
if (pointId < 0) continue; // noise signal from digitizer
const CbmRichPoint* point = static_cast<const CbmRichPoint*>(richPoints->Get(link));
if (!point) continue;
Int_t mcTrackId = point->GetTrackID();
if (mcTrackId < 0) continue;
const CbmMCTrack* mcTrack =
static_cast<const CbmMCTrack*>(mcTracks->Get(link.GetFile(), link.GetEntry(), mcTrackId));
if (!mcTrack) continue;
if (mcTrack->GetPdgCode() != 50000050) continue; // select only Cherenkov photons
Int_t motherId = mcTrack->GetMotherId();
// several photons can have same mother track
// count only unique motherIds
CbmLink val(1., motherId, link.GetEntry(), link.GetFile());
if (std::find(result.begin(), result.end(), val) == result.end()) result.push_back(val);
}
return result;
}
vector<pair<Int_t, Int_t>> CbmMatchRecoToMC::GetMcTrackMotherIdsForRichHit(CbmDigiManager* digiMan,
const CbmRichHit* hit,
Loading