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