29 #include <FairLogger.h>
30 #include <FairMCPoint.h>
31 #include <FairRootManager.h>
34 #include <TClonesArray.h>
37 #include <boost/exception/exception.hpp>
38 #include <boost/type_index/type_index_facade.hpp>
108 Bool_t includeMvdHitsInStsTrack) {
188 LOG(info) <<
"CbmMatchRecoToMC::Exec eventNo=" <<
fEventNumber++;
194 FairRootManager* ioman = FairRootManager::Instance();
195 if (
nullptr == ioman) {
197 <<
"CbmMatchRecoToMC::ReadAndCreateDataBranches() NULL FairRootManager.";
203 if (
nullptr == mcManager)
205 <<
"CbmMatchRecoToMC::ReadAndCreateDataBranches() NULL MCDataManager.";
223 fStsClusters =
static_cast<TClonesArray*
>(ioman->GetObject(
"StsCluster"));
226 static_cast<TClonesArray*
>(ioman->GetObject(
"StsClusterMatch"));
229 ioman->Register(
"StsClusterMatch",
232 IsOutputBranchPersistent(
"StsClusterMatch"));
236 fStsHits =
static_cast<TClonesArray*
>(ioman->GetObject(
"StsHit"));
239 static_cast<TClonesArray*
>(ioman->GetObject(
"StsHitMatch"));
242 ioman->Register(
"StsHitMatch",
245 IsOutputBranchPersistent(
"StsHitMatch"));
249 fStsTracks =
static_cast<TClonesArray*
>(ioman->GetObject(
"StsTrack"));
252 static_cast<TClonesArray*
>(ioman->GetObject(
"StsTrackMatch"));
255 ioman->Register(
"StsTrackMatch",
258 IsOutputBranchPersistent(
"StsTrackMatch"));
264 fRichHits =
static_cast<TClonesArray*
>(ioman->GetObject(
"RichHit"));
266 fRichRings =
static_cast<TClonesArray*
>(ioman->GetObject(
"RichRing"));
269 static_cast<TClonesArray*
>(ioman->GetObject(
"RichRingMatch"));
272 ioman->Register(
"RichRingMatch",
275 IsOutputBranchPersistent(
"RichRingMatch"));
281 fTrdClusters =
static_cast<TClonesArray*
>(ioman->GetObject(
"TrdCluster"));
284 static_cast<TClonesArray*
>(ioman->GetObject(
"TrdClusterMatch"));
287 ioman->Register(
"TrdClusterMatch",
290 IsOutputBranchPersistent(
"TrdClusterMatch"));
294 fTrdHits =
static_cast<TClonesArray*
>(ioman->GetObject(
"TrdHit"));
297 static_cast<TClonesArray*
>(ioman->GetObject(
"TrdHitMatch"));
300 ioman->Register(
"TrdHitMatch",
303 IsOutputBranchPersistent(
"TrdHitMatch"));
308 fTrdTracks =
static_cast<TClonesArray*
>(ioman->GetObject(
"TrdTrack"));
311 static_cast<TClonesArray*
>(ioman->GetObject(
"TrdTrackMatch"));
314 ioman->Register(
"TrdTrackMatch",
317 IsOutputBranchPersistent(
"TrdTrackMatch"));
324 fMuchTracks = (TClonesArray*) ioman->GetObject(
"MuchTrack");
325 fMuchClusters =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchCluster"));
328 static_cast<TClonesArray*
>(ioman->GetObject(
"MuchClusterMatch"));
331 ioman->Register(
"MuchClusterMatch",
334 IsOutputBranchPersistent(
"MuchClusterMatch"));
338 fMuchPixelHits =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchPixelHit"));
341 static_cast<TClonesArray*
>(ioman->GetObject(
"MuchPixelHitMatch"));
344 ioman->Register(
"MuchPixelHitMatch",
347 IsOutputBranchPersistent(
"MuchPixelHitMatch"));
351 fMuchTracks =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchTrack"));
354 static_cast<TClonesArray*
>(ioman->GetObject(
"MuchTrackMatch"));
357 ioman->Register(
"MuchTrackMatch",
360 IsOutputBranchPersistent(
"MuchTrackMatch"));
367 fMvdCluster =
static_cast<TClonesArray*
>(ioman->GetObject(
"MvdCluster"));
370 static_cast<TClonesArray*
>(ioman->GetObject(
"MvdClusterMatch"));
373 ioman->Register(
"MvdClusterMatch",
376 IsOutputBranchPersistent(
"MvdClusterMatch"));
380 fMvdHits =
static_cast<TClonesArray*
>(ioman->GetObject(
"MvdHit"));
383 static_cast<TClonesArray*
>(ioman->GetObject(
"MvdHitMatch"));
386 ioman->Register(
"MvdHitMatch",
389 IsOutputBranchPersistent(
"MvdHitMatch"));
397 fTofHits =
static_cast<TClonesArray*
>(ioman->GetObject(
"TofHit"));
400 static_cast<TClonesArray*
>(ioman->GetObject(
"TofHitMatch"));
403 ioman->Register(
"TofHitMatch",
406 IsOutputBranchPersistent(
"TofHitMatch"));
413 const TClonesArray* clusters,
414 TClonesArray* clusterMatches) {
415 if (!(digiMatches && clusters && clusterMatches))
return;
416 Int_t nofClusters = clusters->GetEntriesFast();
417 for (Int_t iCluster = 0; iCluster < nofClusters; iCluster++) {
421 for (Int_t iDigi = 0; iDigi < nofDigis; iDigi++) {
423 static_cast<const CbmMatch*
>(digiMatches->At(cluster->
GetDigi(iDigi)));
430 const TClonesArray* clusters,
431 TClonesArray* clusterMatches) {
433 if (!(clusters && clusterMatches))
return;
434 Int_t nofClusters = clusters->GetEntriesFast();
435 for (Int_t iCluster = 0; iCluster < nofClusters; iCluster++) {
439 for (Int_t iDigi = 0; iDigi < nofDigis; iDigi++) {
440 Int_t digiIndex = cluster->
GetDigi(iDigi);
448 const TClonesArray*
hits,
449 TClonesArray* hitMatches) {
450 if (!(matches &&
hits && hitMatches))
return;
451 Int_t nofHits =
hits->GetEntriesFast();
452 for (Int_t iHit = 0; iHit < nofHits; iHit++) {
462 const TClonesArray*
hits,
463 TClonesArray* hitMatches) {
464 if (!(cluMatches &&
hits && hitMatches))
return;
465 Int_t nofHits =
hits->GetEntriesFast();
466 for (Int_t iHit = 0; iHit < nofHits; iHit++) {
473 hitMatch->
AddLinks(*frontClusterMatch);
474 hitMatch->
AddLinks(*backClusterMatch);
479 TClonesArray* hitMatches) {
480 if (!(
hits && hitMatches))
return;
481 Int_t nofHits =
hits->GetEntriesFast();
482 for (Int_t iHit = 0; iHit < nofHits; iHit++) {
492 const TClonesArray*
hits,
493 TClonesArray* hitMatches) {
494 if (!(HitDigiMatches &&
hits && hitMatches))
return;
497 Int_t nofHits =
hits->GetEntriesFast();
501 for (Int_t iHit = 0; iHit < nofHits; iHit++) {
506 for (Int_t iDigi = 0; iDigi < iNbDigisHit; iDigi++) {
510 if (iNbTofDigis <= iDigiIdx) {
512 <<
"CbmTofHitFinderQa::FillHistos => Digi index from Hit #" << iHit
513 <<
" is bigger than nb entries in Digis arrays => ignore it!!!";
519 Int_t iNbPointsDigi = pMatchDigiPnt->GetNofLinks();
521 pMatchDigiPnt->GetMatchedLink();
522 Int_t iTruePointIdx = lTruePoint.
GetIndex();
523 for (Int_t iPoint = 0; iPoint < iNbPointsDigi; iPoint++) {
524 CbmLink lPoint = pMatchDigiPnt->GetLink(iPoint);
525 Int_t iPointIdx = lPoint.
GetIndex();
527 if (iPointIdx == iTruePointIdx)
545 const TClonesArray*
hits,
546 TClonesArray* hitMatches) {
547 if (!(
hits && hitMatches))
return;
548 Int_t nofHits =
hits->GetEntriesFast();
549 for (Int_t iHit = 0; iHit < nofHits; iHit++) {
552 const FairMCPoint* point =
static_cast<const FairMCPoint*
>(
561 const TClonesArray*
tracks,
562 TClonesArray* trackMatches) {
563 if (!(hitMatches &&
points &&
tracks && trackMatches))
return;
565 Bool_t editMode = (trackMatches->GetEntriesFast() != 0);
567 Int_t nofTracks =
tracks->GetEntriesFast();
568 for (Int_t iTrack = 0; iTrack < nofTracks; iTrack++) {
574 for (Int_t iHit = 0; iHit < nofHits; iHit++) {
582 for (Int_t iLink = 0; iLink < nofLinks; iLink++) {
583 const FairMCPoint* point =
static_cast<const FairMCPoint*
>(
585 if (
nullptr == point)
continue;
589 Int_t mcTrackId = point->GetTrackID();
605 for (Int_t iHit = 0; iHit < nofHits; iHit++) {
613 Bool_t hasTrue =
false;
614 for (Int_t iLink = 0; iLink < nofLinks; iLink++) {
615 const FairMCPoint* point =
static_cast<const FairMCPoint*
>(
617 if (
nullptr == point)
continue;
638 const TClonesArray* stsHitMatches,
641 const TClonesArray*
tracks,
642 TClonesArray* trackMatches) {
643 if (!((stsHitMatches && stsPoints &&
tracks && trackMatches)
647 Bool_t editMode = (trackMatches->GetEntriesFast() != 0);
649 Int_t nofTracks =
tracks->GetEntriesFast();
650 for (Int_t iTrack = 0; iTrack < nofTracks; iTrack++) {
657 for (Int_t iHit = 0; iHit < nofStsHits; iHit++) {
661 for (Int_t iLink = 0; iLink < nofLinks; iLink++) {
663 const FairMCPoint* point =
664 static_cast<const FairMCPoint*
>(stsPoints->
Get(link));
665 if (
nullptr == point)
continue;
669 Int_t mcTrackId = point->GetTrackID();
672 if (!mcTrack)
continue;
684 for (Int_t iHit = 0; iHit < nofMvdHits; iHit++) {
688 for (Int_t iLink = 0; iLink < nofLinks; iLink++) {
690 const FairMCPoint* point =
691 static_cast<const FairMCPoint*
>(mvdPoints->
Get(link));
692 if (
nullptr == point)
continue;
703 for (Int_t iHit = 0; iHit < nofStsHits; iHit++) {
707 Bool_t hasTrue =
false;
708 for (Int_t iLink = 0; iLink < nofLinks; iLink++) {
709 const FairMCPoint* point =
static_cast<const FairMCPoint*
>(
711 if (
nullptr == point)
continue;
726 for (Int_t iHit = 0; iHit < nofMvdHits; iHit++) {
730 Bool_t hasTrue =
false;
731 for (Int_t iLink = 0; iLink < nofLinks; iLink++) {
732 const FairMCPoint* point =
static_cast<const FairMCPoint*
>(
734 if (
nullptr == point)
continue;
757 const TClonesArray* richHits,
762 TClonesArray* ringMatches) {
764 Int_t nRings = richRings->GetEntriesFast();
765 for (Int_t iRing = 0; iRing < nRings; iRing++) {
767 static_cast<const CbmRichRing*
>(richRings->At(iRing));
768 if (
nullptr == ring)
continue;
774 for (Int_t iHit = 0; iHit < nofHits; iHit++) {
777 if (
nullptr == hit)
continue;
781 for (UInt_t
i = 0;
i < motherIds.size();
i++) {
791 Int_t trueCounter = 0;
792 Int_t wrongCounter = 0;
793 for (Int_t iHit = 0; iHit < nofHits; iHit++) {
796 if (
nullptr == hit)
continue;
799 if (std::find(motherIds.begin(),
801 std::make_pair(bestTrackEventId, bestTrackId))
802 != motherIds.end()) {
820 vector<pair<Int_t, Int_t>>
826 vector<pair<Int_t, Int_t>> result;
827 if (
nullptr == hit)
return result;
829 if (digiIndex < 0)
return result;
831 if (
nullptr == digi)
return result;
833 if (digiMatch ==
nullptr)
return result;
835 vector<CbmLink> links = digiMatch->
GetLinks();
836 for (UInt_t
i = 0;
i < links.size();
i++) {
837 Int_t pointId = links[
i].GetIndex();
838 Int_t eventId = links[
i].GetEntry();
839 if (pointId < 0)
continue;
841 static_cast<const CbmRichPoint*
>(richPoints->
Get(0, eventId, pointId));
843 if (
nullptr == pMCpt)
continue;
844 Int_t mcTrackIndex = pMCpt->GetTrackID();
845 if (mcTrackIndex < 0)
continue;
850 if (
nullptr == mcTrack)
continue;
856 pair<Int_t, Int_t> val = std::make_pair(eventId, motherId);
857 if (std::find(result.begin(), result.end(), val) == result.end()) {
858 result.push_back(val);
868 const TClonesArray* richPoints,
870 vector<Int_t> result;
871 if (
nullptr == hit)
return result;
873 if (digiIndex < 0)
return result;
875 if (
nullptr == digi)
return result;
877 if (digiMatch ==
nullptr)
return result;
879 vector<CbmLink> links = digiMatch->
GetLinks();
880 for (UInt_t
i = 0;
i < links.size();
i++) {
881 Int_t pointId = links[
i].GetIndex();
882 if (pointId < 0)
continue;
885 static_cast<const CbmRichPoint*
>(richPoints->At(pointId));
886 if (
nullptr == pMCpt)
continue;
887 Int_t mcTrackIndex = pMCpt->GetTrackID();
888 if (mcTrackIndex < 0)
continue;
893 if (
nullptr == mcTrack)
continue;
899 if (std::find(result.begin(), result.end(), motherId) == result.end()) {
900 result.push_back(motherId);