EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CbmRichMatchRings.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CbmRichMatchRings.cxx
1 
8 #include <assert.h>
9 
10 #include "CbmRichMatchRings.h"
11 
12 #include "CbmRichHit.h"
13 #include "CbmRichRing.h"
14 #include "CbmTrackMatch.h"
15 
16 #include "FairMCPoint.h"
17 #include "CbmMCTrack.h"
18 #include "FairRootManager.h"
19 
20 #include "TClonesArray.h"
21 
22 #include <iostream>
23 #include <map>
24 
25 using std::cout;
26 using std::endl;
27 using std::map;
28 
30  FairTask("CbmRichMatchRings"),
31  fRings(NULL),
32  fPoints(NULL),
33  fTracks(NULL),
34  fHits(NULL),
35  fMatches(NULL),
36 
37  fMatchMap()//,
38 // fMatchMCMap()
39 {
40 
41 }
42 
44 {
45 }
46 
47 
49 {
51  if (NULL == ioman) {Fatal("CbmRichMatchRings::Init", "RootManager not instantiated!");}
52 
53  fHits = (TClonesArray*) ioman->GetObject("RichHit");
54  if (NULL == fHits) {Fatal("CbmRichMatchRings::Init", "No RichHit array!");}
55 
56  fRings = (TClonesArray*) ioman->GetObject("RichRing");
57  if (NULL == fRings) { Fatal("CbmRichMatchRings::Init", "No RichRing array!");}
58 
59  fPoints = (TClonesArray*) ioman->GetObject("RichPoint");
60  if (NULL == fPoints) {Fatal("CbmRichMatchRings::Init", "No RichPoint array!");}
61 
62  fTracks = (TClonesArray*) ioman->GetObject("MCTrack");
63  if (NULL == fTracks ) {Fatal("CbmRichMatchRings::Init", "No MCTrack array!");}
64 
65  // Create and register RichRingMatch array
66  fMatches = new TClonesArray("CbmTrackMatch",100);
67  ioman->Register("RichRingMatch", "RICH", fMatches, kTRUE);
68 
69  return kSUCCESS;
70 }
71 
73  Option_t* opt)
74 {
75  // Clear output array
76  if (fMatches != NULL) fMatches->Clear();
77  map<Int_t, Int_t>::iterator it ;
78 // fMatchMCMap.clear();
79 
80 // // Loop over Rich hits
81 // Int_t nRichHits = fHits->GetEntriesFast();
82 // for (Int_t iHit=0; iHit < nRichHits; iHit++) {
83 // CbmRichHit* hit = (CbmRichHit*) fHits->At(iHit);
84 // if ( NULL == hit ) continue;
85 //
86 // Int_t iPoint = hit->GetRefId();
87 // if ( iPoint < 0 ) { // Fake or background hit
88 // continue;
89 // }
90 // //Get the MC Point corresponding to the hit
91 // FairMCPoint* point = (FairMCPoint*) fPoints->At(iPoint);
92 // if ( NULL == point ) continue;
93 // //Get the MC Track ID corresponding to the MC Point
94 // Int_t iMCTrack = point->GetTrackID();
95 // // Get the MC Track corresponding to the ID
96 // CbmMCTrack* track = (CbmMCTrack*)fTracks->At(iMCTrack);
97 // if (NULL == track) continue;
98 // Int_t iMother = track->GetMotherId();
99 // fMatchMCMap[iMother]++;
100 // }
101 
102  // Loop over RichRings
103  Int_t nRings = fRings->GetEntriesFast();
104  for (Int_t iRing=0; iRing<nRings; iRing++) {
105  CbmRichRing* ring = (CbmRichRing*) fRings->At(iRing);
106  if (NULL == ring) continue;
107 
108  Int_t nHits = ring->GetNofHits();
109  Int_t nAll = 0;
110  Int_t nTrue = 0; //number of true hits in ring
111  Int_t nFake = 0; // number of fake hits in ring
112  Int_t nWrong = 0; // number of wrong hits in ring
113  Int_t nMCTracks = 0; //number of MC tracks from which hits ring was formed.
114 
115  fMatchMap.clear();
116 
117  // Loop over Hits of ring
118  for (Int_t iHit=0; iHit<nHits; iHit++) {
119  assert(0);
120 #if _NOW_
121  CbmRichHit* hit = (CbmRichHit*) fHits->At(ring->GetHit(iHit));
122  if ( NULL == hit ) continue;
123  Int_t iPoint = hit->GetRefId();
124  if ( iPoint < 0 ) { // Fake or background hit
125  nFake++;
126  continue;
127  }
128 
129  //Get the MC Point corresponding to the hit
130  FairMCPoint* point = (FairMCPoint*) fPoints->At(iPoint);
131  if (NULL == point ) continue;
132  //Get the MC Track ID corresponding to the MC Point
133  Int_t iMCTrack = point->GetTrackID();
134 
135  // Get the MC Track corresponding to the ID
136  CbmMCTrack* track = (CbmMCTrack*)fTracks->At(iMCTrack);
137  Int_t iMother = track->GetMotherId();
138  fMatchMap[iMother]++;
139 #endif
140  }// Hit loop
141 
142  assert(0);
143 #if _NOW_
144  // Search for best matching MCTrack
145  Int_t iMCTrack = -1;
146  for (it=fMatchMap.begin(); it!=fMatchMap.end(); it++) {
147  nMCTracks++;
148  nAll += it->second;
149  if ( it->second > nTrue ) {
150  iMCTrack = it->first;
151  nTrue = it->second;
152  }
153  }
154 
155 // Int_t nMCHits = fMatchMCMap[iMCTrack]; //number of hits in MC ring
156  nWrong = nAll - nTrue;
157 
158  // Create RichRingMatch
159  new ((*fMatches)[iRing]) CbmTrackMatch(iMCTrack, nTrue, nWrong, nFake, nMCTracks);
160 #endif
161  }// Ring loop
162 }
163 
165 {
166 
167 }
168