CbmRoot
CbmRichMatchRings.cxx
Go to the documentation of this file.
1 
8 #include "CbmRichMatchRings.h"
9 
10 #include "CbmRichHit.h"
11 #include "CbmRichRing.h"
12 #include "CbmTrackMatchNew.h"
13 
14 #include "CbmMCTrack.h"
15 #include "FairMCPoint.h"
16 #include "FairRootManager.h"
17 
18 #include "TClonesArray.h"
19 
20 #include <iostream>
21 #include <map>
22 
23 using std::cout;
24 using std::endl;
25 using std::map;
26 
28  : FairTask("CbmRichMatchRings")
29  , fRings(NULL)
30  , fPoints(NULL)
31  , fTracks(NULL)
32  , fHits(NULL)
33  , fMatches(NULL)
34  ,
35 
36  fMatchMap() //,
37 // fMatchMCMap()
38 {}
39 
41 
42 
44  FairRootManager* ioman = FairRootManager::Instance();
45  if (NULL == ioman) {
46  Fatal("CbmRichMatchRings::Init", "RootManager not instantiated!");
47  }
48 
49  fHits = (TClonesArray*) ioman->GetObject("RichHit");
50  if (NULL == fHits) { Fatal("CbmRichMatchRings::Init", "No RichHit array!"); }
51 
52  fRings = (TClonesArray*) ioman->GetObject("RichRing");
53  if (NULL == fRings) {
54  Fatal("CbmRichMatchRings::Init", "No RichRing array!");
55  }
56 
57  fPoints = (TClonesArray*) ioman->GetObject("RichPoint");
58  if (NULL == fPoints) {
59  Fatal("CbmRichMatchRings::Init", "No RichPoint array!");
60  }
61 
62  fTracks = (TClonesArray*) ioman->GetObject("MCTrack");
63  if (NULL == fTracks) {
64  Fatal("CbmRichMatchRings::Init", "No MCTrack array!");
65  }
66 
67  // Create and register RichRingMatch array
68  fMatches = new TClonesArray("CbmTrackMatchNew", 100);
69  ioman->Register("RichRingMatch",
70  "RICH",
71  fMatches,
72  IsOutputBranchPersistent("RichRingMatch"));
73 
74  return kSUCCESS;
75 }
76 
77 void CbmRichMatchRings::Exec(Option_t* opt) {
78  // Clear output array
79  if (fMatches != NULL) fMatches->Delete();
80  map<Int_t, Int_t>::iterator it;
81  // fMatchMCMap.clear();
82 
83  // // Loop over Rich hits
84  // Int_t nRichHits = fHits->GetEntriesFast();
85  // for (Int_t iHit=0; iHit < nRichHits; iHit++) {
86  // CbmRichHit* hit = (CbmRichHit*) fHits->At(iHit);
87  // if ( NULL == hit ) continue;
88  //
89  // Int_t iPoint = hit->GetRefId();
90  // if ( iPoint < 0 ) { // Fake or background hit
91  // continue;
92  // }
93  // //Get the MC Point corresponding to the hit
94  // FairMCPoint* point = (FairMCPoint*) fPoints->At(iPoint);
95  // if ( NULL == point ) continue;
96  // //Get the MC Track ID corresponding to the MC Point
97  // Int_t iMCTrack = point->GetTrackID();
98  // // Get the MC Track corresponding to the ID
99  // CbmMCTrack* track = (CbmMCTrack*)fTracks->At(iMCTrack);
100  // if (NULL == track) continue;
101  // Int_t iMother = track->GetMotherId();
102  // fMatchMCMap[iMother]++;
103  // }
104 
105  // Loop over RichRings
106  Int_t nRings = fRings->GetEntriesFast();
107  for (Int_t iRing = 0; iRing < nRings; iRing++) {
108  CbmRichRing* ring = (CbmRichRing*) fRings->At(iRing);
109  if (NULL == ring) continue;
110 
111  CbmTrackMatchNew* ringMatch = new ((*fMatches)[iRing])
112  CbmTrackMatchNew(); //(iMCTrack, nTrue, nWrong, nFake, nMCTracks);
113 
114  Int_t nHits = ring->GetNofHits();
115  Int_t nAll = 0;
116  Int_t nTrue = 0; //number of true hits in ring
117  Int_t nFake = 0; // number of fake hits in ring
118  Int_t nWrong = 0; // number of wrong hits in ring
119  Int_t nMCTracks = 0; //number of MC tracks from which hits ring was formed.
120 
121  fMatchMap.clear();
122 
123  // Loop over Hits of ring
124  for (Int_t iHit = 0; iHit < nHits; iHit++) {
125  CbmRichHit* hit = (CbmRichHit*) fHits->At(ring->GetHit(iHit));
126  if (NULL == hit) continue;
127  Int_t iPoint = hit->GetRefId();
128  if (iPoint < 0) { // Fake or background hit
129  nFake++;
130  continue;
131  }
132 
133  //Get the MC Point corresponding to the hit
134  FairMCPoint* point = (FairMCPoint*) fPoints->At(iPoint);
135  if (NULL == point) continue;
136  //Get the MC Track ID corresponding to the MC Point
137  Int_t iMCTrack = point->GetTrackID();
138 
139  // Get the MC Track corresponding to the ID
140  CbmMCTrack* track = (CbmMCTrack*) fTracks->At(iMCTrack);
141  Int_t iMother = track->GetMotherId();
142  fMatchMap[iMother]++;
143 
144  ringMatch->AddLink(1., iMother);
145  } // Hit loop
146 
147  // Search for best matching MCTrack
148  Int_t iMCTrack = -1;
149  for (it = fMatchMap.begin(); it != fMatchMap.end(); it++) {
150  nMCTracks++;
151  nAll += it->second;
152  if (it->second > nTrue) {
153  iMCTrack = it->first;
154  nTrue = it->second;
155  }
156  }
157 
158  // Int_t nMCHits = fMatchMCMap[iMCTrack]; //number of hits in MC ring
159  nWrong = nAll - nTrue;
160 
161  ringMatch->SetNofTrueHits(nTrue);
162  ringMatch->SetNofWrongHits(nWrong);
163 
164  // Create RichRingMatch
165  // new ((*fMatches)[iRing]) CbmTrackMatchNew(iMCTrack, nTrue, nWrong, nFake, nMCTracks);
166  } // Ring loop
167 }
168 
170 
CbmMCTrack::GetMotherId
Int_t GetMotherId() const
Definition: CbmMCTrack.h:71
CbmRichMatchRings::CbmRichMatchRings
CbmRichMatchRings()
Default constructor.
Definition: CbmRichMatchRings.cxx:27
CbmRichMatchRings::Exec
virtual void Exec(Option_t *opt)
Inherited from FairTask.
Definition: CbmRichMatchRings.cxx:77
CbmRichMatchRings::Init
virtual InitStatus Init()
Inherited from FairTask.
Definition: CbmRichMatchRings.cxx:43
CbmRichRing::GetNofHits
Int_t GetNofHits() const
Definition: CbmRichRing.h:40
CbmRichRing
Definition: CbmRichRing.h:17
CbmHit::GetRefId
Int_t GetRefId() const
Definition: CbmHit.h:72
CbmRichRing.h
CbmTrackMatchNew::SetNofTrueHits
void SetNofTrueHits(Int_t nofTrueHits)
Definition: CbmTrackMatchNew.h:45
CbmRichMatchRings::fMatchMap
std::map< Int_t, Int_t > fMatchMap
Definition: CbmRichMatchRings.h:71
CbmRichRing::GetHit
UInt_t GetHit(Int_t i) const
Definition: CbmRichRing.h:42
CbmTrackMatchNew.h
CbmMatch::AddLink
void AddLink(const CbmLink &newLink)
Definition: CbmMatch.cxx:42
CbmRichMatchRings::fHits
TClonesArray * fHits
Definition: CbmRichMatchRings.h:67
CbmRichMatchRings::~CbmRichMatchRings
virtual ~CbmRichMatchRings()
Destructor.
Definition: CbmRichMatchRings.cxx:40
CbmTrackMatchNew::SetNofWrongHits
void SetNofWrongHits(Int_t nofWrongHits)
Definition: CbmTrackMatchNew.h:46
nMCTracks
Int_t nMCTracks
Definition: CbmHadronAnalysis.cxx:63
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmRichMatchRings
Task class for matching a reconstructed CbmRichRings with a simulated CbmMCTrack. The matching criter...
Definition: CbmRichMatchRings.h:34
CbmMCTrack.h
CbmRichMatchRings::fPoints
TClonesArray * fPoints
Definition: CbmRichMatchRings.h:65
CbmMCTrack
Definition: CbmMCTrack.h:34
CbmRichMatchRings.h
Task class for matching a reconstructed CbmRichRings with a simulated CbmMCTrack. The matching criter...
CbmRichMatchRings::fMatches
TClonesArray * fMatches
Definition: CbmRichMatchRings.h:68
CbmTrackMatchNew
Definition: CbmTrackMatchNew.h:19
CbmRichMatchRings::Finish
virtual void Finish()
Inherited from FairTask.
Definition: CbmRichMatchRings.cxx:169
CbmRichHit.h
CbmRichHit
Definition: CbmRichHit.h:19
CbmRichMatchRings::fTracks
TClonesArray * fTracks
Definition: CbmRichMatchRings.h:66
CbmRichMatchRings::fRings
TClonesArray * fRings
Definition: CbmRichMatchRings.h:64