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