CbmRoot
Loading...
Searching...
No Matches
CbmMuchMatchTracks.cxx
Go to the documentation of this file.
1/* Copyright (C) 2007-2020 St. Petersburg Polytechnic University, St. Petersburg
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev, Mikhail Ryzhinskiy [committer], Florian Uhlig, Evgeny Kryshen */
4
6
7#include "CbmMuchCluster.h"
8#include "CbmMuchDigiMatch.h"
9#include "CbmMuchPixelHit.h"
10#include "CbmMuchTrack.h"
11#include "CbmTrackMatch.h"
12#include "FairMCPoint.h"
13#include "FairRootManager.h"
14#include "TClonesArray.h"
15
16#include <iomanip>
17#include <iostream>
18#include <map>
19
21 : FairTask("CbmMuchMatchTracks")
22 , fTracks(NULL)
23 , fPoints(NULL)
24 , fPixelHits(NULL)
25 , fMatches(NULL)
26 , fPixelDigiMatches(NULL)
27 , fClusters(NULL)
28 , fNofHits(0)
29 , fNofTrueHits(0)
30 , fNofWrongHits(0)
31 , fNofFakeHits(0)
32 , fNEvents(0)
33{
34}
35
37
39{
40 FairRootManager* ioman = FairRootManager::Instance();
41 if (ioman == NULL) LOG(fatal) << GetName() << "::Init: RootManager not instantised!";
42
43 fPixelHits = (TClonesArray*) ioman->GetObject("MuchPixelHit");
44 if (fPixelHits == NULL) LOG(fatal) << GetName() << "::Init: No MuchPixelHit array!";
45
46 fTracks = (TClonesArray*) ioman->GetObject("MuchTrack");
47 if (fTracks == NULL) LOG(fatal) << GetName() << "::Init: No MuchTrack array!";
48
49 fPoints = (TClonesArray*) ioman->GetObject("MuchPoint");
50 if (fPoints == NULL) LOG(fatal) << GetName() << "::Init: No MuchPoint array!";
51
52 fPixelDigiMatches = (TClonesArray*) ioman->GetObject("MuchDigiMatch");
53 if (fPixelDigiMatches == NULL) LOG(fatal) << GetName() << "::Init: No MuchDigiMatch array!";
54
55 fClusters = (TClonesArray*) ioman->GetObject("MuchCluster");
56 if (fClusters == NULL)
57 Info("CbmMuchMatchTracks::Init", "No cluster array -- simple hit to digi matching will be used");
58
59 fMatches = new TClonesArray("CbmTrackMatch", 100);
60 ioman->Register("MuchTrackMatch", "MUCH", fMatches, IsOutputBranchPersistent("MuchTrackMatch"));
61
62 return kSUCCESS;
63}
64
66{
67
68 fMatches->Clear();
69
70 Int_t nofTracks = fTracks->GetEntriesFast();
71 for (Int_t iTrack = 0; iTrack < nofTracks; iTrack++) { // Loop over tracks
72 // std::map stores MC track id to number of contributions of this MC track
73 std::map<Int_t, Int_t> matchMap;
74
75 CbmMuchTrack* pTrack = static_cast<CbmMuchTrack*>(fTracks->At(iTrack));
76 if (pTrack == NULL) continue;
77
78 Int_t nofHits = pTrack->GetNofHits();
79 for (Int_t iHit = 0; iHit < nofHits; iHit++) { // Loop over hits
80 HitType hitType = pTrack->GetHitType(iHit);
81 if (hitType == kMUCHPIXELHIT) {
82 ExecPixel(matchMap, pTrack->GetHitIndex(iHit));
83 }
84 else {
85 LOG(fatal) << GetName() << ": Hit type not supported!";
86 }
87 } // Loop over hits
88
89 Int_t nofTrue = 0;
90 Int_t bestMcTrackId = -1;
91 Int_t nPoints = 0;
92 for (std::map<Int_t, Int_t>::iterator it = matchMap.begin(); it != matchMap.end(); it++) {
93 if (it->first != -1 && it->second >= nofTrue) {
94 bestMcTrackId = it->first;
95 nofTrue = it->second;
96 }
97 nPoints += it->second;
98 }
99
100 Int_t nofFake = 0;
101 Int_t nofWrong = nofHits - nofTrue - nofFake;
102 Int_t nofMcTracks = matchMap.size() - 1;
103
104 new ((*fMatches)[iTrack]) CbmTrackMatch(bestMcTrackId, nofTrue, nofWrong, nofFake, nofMcTracks);
105
106 fNofHits += nofHits;
107 fNofTrueHits += nofTrue;
108 fNofWrongHits += nofWrong;
109 fNofFakeHits += nofFake;
110
111 if (fVerbose > 1)
112 std::cout << "iTrack=" << iTrack << " mcTrack=" << bestMcTrackId << " nPoints=" << nPoints
113 << " nofTrue=" << nofTrue << " nofWrong=" << nofWrong << " nofFake=" << nofFake
114 << " nofMcTracks=" << nofMcTracks << std::endl;
115 } // Loop over tracks
116
117 fNEvents++;
118}
119
121{
122 Double_t trueHits = 100. * Double_t(fNofTrueHits) / Double_t(fNofHits);
123 Double_t wrongHits = 100. * Double_t(fNofWrongHits) / Double_t(fNofHits);
124 Double_t fakeHits = 100. * Double_t(fNofFakeHits) / Double_t(fNofHits);
125 std::cout << "=================================================" << std::endl;
126 std::cout << "===== " << GetName() << ": Run summary " << std::endl;
127 std::cout << "True hits: " << trueHits << "%" << std::endl;
128 std::cout << "Wrong hits: " << wrongHits << "%" << std::endl;
129 std::cout << "Fake hits: " << fakeHits << "%" << std::endl;
130 std::cout << "=================================================" << std::endl;
131}
132
133void CbmMuchMatchTracks::ExecPixel(std::map<Int_t, Int_t>& matchMap, Int_t index)
134{
135 // std::set stores MC track indices contributed to a certain hit
136 std::set<Int_t> mcIdHit;
137 CbmMuchPixelHit* hit = static_cast<CbmMuchPixelHit*>(fPixelHits->At(index));
138 if (hit == NULL) return;
139
140 Int_t clusterId = hit->GetRefId();
141 CbmMuchCluster* cluster = static_cast<CbmMuchCluster*>(fClusters->At(clusterId));
142 if (cluster == NULL) return;
143
144 for (Int_t iDigi = 0; iDigi < cluster->GetNofDigis(); iDigi++) {
145 Int_t digiId = cluster->GetDigi(iDigi);
146 CbmMuchDigiMatch* digiMatch = static_cast<CbmMuchDigiMatch*>(fPixelDigiMatches->At(digiId));
147 if (digiMatch == NULL) continue;
148 for (Int_t iPoint = 0; iPoint < digiMatch->GetNofLinks(); iPoint++) {
149 Int_t pointIndex = digiMatch->GetLink(iPoint).GetIndex();
150 if (pointIndex < 0) { // Fake or background hit
151 mcIdHit.insert(-1);
152 continue;
153 }
154 FairMCPoint* point = static_cast<FairMCPoint*>(fPoints->At(pointIndex));
155 if (point == NULL) continue;
156 mcIdHit.insert(point->GetTrackID());
157 }
158 } // loop over digis
159
160 for (std::set<Int_t>::iterator it = mcIdHit.begin(); it != mcIdHit.end(); it++) {
161 matchMap[*it]++;
162 }
163}
164
HitType
Definition CbmHit.h:21
@ kMUCHPIXELHIT
Definition CbmHit.h:28
Data container for MUCH clusters.
ClassImp(CbmMuchMatchTracks)
Class for pixel hits in MUCH detector.
int32_t GetDigi(int32_t index) const
Get digi at position index.
Definition CbmCluster.h:76
int32_t GetNofDigis() const
Number of digis in cluster.
Definition CbmCluster.h:69
int32_t GetRefId() const
Definition CbmHit.h:73
const CbmLink & GetLink(int32_t i) const
Definition CbmMatch.h:39
int32_t GetNofLinks() const
Definition CbmMatch.h:42
Data container for MUCH clusters.
TClonesArray * fMatches
virtual InitStatus Init()
TClonesArray * fPixelDigiMatches
TClonesArray * fPixelHits
virtual void Exec(Option_t *opt)
TClonesArray * fClusters
void ExecPixel(std::map< Int_t, Int_t > &matchMap, Int_t index)
virtual int32_t GetNofHits() const
Definition CbmTrack.h:58
int32_t GetHitIndex(int32_t iHit) const
Definition CbmTrack.h:59
HitType GetHitType(int32_t iHit) const
Definition CbmTrack.h:60