CbmRoot
Loading...
Searching...
No Matches
CbmRichRingTrackAssignClosestD.cxx
Go to the documentation of this file.
1/* Copyright (C) 2006-2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Claudia Hoehne [committer], Semen Lebedev, Martin Beyer */
4
13
14#include "CbmEvent.h"
15#include "CbmGlobalTrack.h"
16#include "CbmMCTrack.h"
17#include "CbmRichRing.h"
18#include "CbmTrdTrack.h"
19#include "FairRootManager.h"
20#include "FairTrackParam.h"
21#include "TClonesArray.h"
22
23#include <Logger.h>
24
25#include <algorithm>
26#include <iostream>
27#include <vector>
28
29using std::cout;
30using std::endl;
31using std::vector;
32
34
36
38{
39 FairRootManager* manager = FairRootManager::Instance();
40 if (nullptr == manager) LOG(fatal) << "CbmRichRingTrackAssignClosestD::Init(): FairRootManager is nullptr.";
41
42 fGlobalTracks = (TClonesArray*) manager->GetObject("GlobalTrack");
43 if (fGlobalTracks == nullptr) LOG(fatal) << "CbmRichRingTrackAssignClosestD::Init(): No GlobalTrack.";
44
45 fTrdTracks = (TClonesArray*) manager->GetObject("TrdTrack");
46 //if (NULL == fTrdTracks) { LOG(fatal) << GetName() << "::Init: No TrdTrack array"; }
47}
48
49void CbmRichRingTrackAssignClosestD::DoAssign(CbmEvent* event, TClonesArray* rings, TClonesArray* richProj)
50{
51 fEventNum++;
54 } // RingTrack algorithm
55
56 else if (fAlgorithmType == TrackRing) {
58 } // TrackRing
59
60 else if (fAlgorithmType == Combined) {
63 } // Combined
64
65 Int_t nofTracks = event ? event->GetNofData(ECbmDataType::kRichTrackProjection) : richProj->GetEntriesFast();
66 Int_t nofRings = event ? event->GetNofData(ECbmDataType::kRichRing) : rings->GetEntriesFast();
67 LOG(debug) << "CbmRichRingTrackAssignClosestD::DoAssign(): Event:" << fEventNum << " rings:" << nofRings
68 << " ringsInTS:" << rings->GetEntriesFast() << " tracks:" << nofTracks
69 << " tracksInTS:" << richProj->GetEntriesFast();
70}
71
73{
74
75 const Int_t nofTracks = event ? event->GetNofData(ECbmDataType::kRichTrackProjection) : richProj->GetEntriesFast();
76 const Int_t nofRings = event ? event->GetNofData(ECbmDataType::kRichRing) : rings->GetEntriesFast();
77 if (nofTracks <= 0 || nofRings <= 0) return;
78
79 vector<Int_t> trackIndex;
80 vector<Double_t> trackDist;
81 trackIndex.resize(nofRings);
82 trackDist.resize(nofRings);
83 for (UInt_t i = 0; i < trackIndex.size(); i++) {
84 trackIndex[i] = -1;
85 trackDist[i] = 999.;
86 }
87
88 for (Int_t iIter = 0; iIter < 4; iIter++) {
89 for (Int_t iR0 = 0; iR0 < nofRings; iR0++) {
90 Int_t iR = event ? event->GetIndex(ECbmDataType::kRichRing, iR0) : iR0;
91
92 if (trackIndex[iR0] != -1) continue;
93 CbmRichRing* ring = static_cast<CbmRichRing*>(rings->At(iR));
94 if (ring == nullptr) continue;
95 if (ring->GetNofHits() < fMinNofHitsInRing) continue;
96
97 Double_t xRing = ring->GetCenterX();
98 Double_t yRing = ring->GetCenterY();
99 Double_t rMin = 999.;
100 Int_t iTrackMin = -1;
101
102 for (Int_t iT0 = 0; iT0 < nofTracks; iT0++) {
103 Int_t iT = event ? event->GetIndex(ECbmDataType::kRichTrackProjection, iT0) : iT0;
104
105 vector<Int_t>::iterator it = find(trackIndex.begin(), trackIndex.end(), iT);
106 if (it != trackIndex.end()) continue;
107
108 FairTrackParam* track = static_cast<FairTrackParam*>(richProj->At(iT));
109 Double_t xTrack = track->GetX();
110 Double_t yTrack = track->GetY();
111 // no projection onto the photodetector plane
112 if (xTrack == 0 && yTrack == 0) continue;
113
114 if (fUseTrd && fTrdTracks != nullptr && !IsTrdElectron(iT)) continue;
115
116 Double_t dist = TMath::Sqrt((xRing - xTrack) * (xRing - xTrack) + (yRing - yTrack) * (yRing - yTrack));
117
118 if (dist < rMin) {
119 rMin = dist;
120 iTrackMin = iT;
121 }
122 } // loop tracks
123 trackIndex[iR0] = iTrackMin;
124 trackDist[iR0] = rMin;
125 } //loop rings
126
127 for (UInt_t i1 = 0; i1 < trackIndex.size(); i1++) {
128 for (UInt_t i2 = 0; i2 < trackIndex.size(); i2++) {
129 if (i1 == i2) continue;
130 if (trackIndex[i1] == trackIndex[i2] && trackIndex[i1] != -1) {
131 if (trackDist[i1] >= trackDist[i2]) {
132 trackDist[i1] = 999.;
133 trackIndex[i1] = -1;
134 }
135 else {
136 trackDist[i2] = 999.;
137 trackIndex[i2] = -1;
138 }
139 }
140 }
141 }
142 } //iIter
143
144 // fill global tracks
145 for (UInt_t i = 0; i < trackIndex.size(); i++) {
146 // CbmRichRing* pRing = (CbmRichRing*)rings->At(i);
147 // cout << "trackIndex[i]:" << trackIndex[i] << " trackDist[i]:" << trackDist[i] << " r:" << pRing->GetRadius() << " x:" << pRing->GetCenterX() << " y:" << pRing->GetCenterY()<< endl;
148 if (trackIndex[i] == -1) continue;
149 CbmGlobalTrack* gTrack = (CbmGlobalTrack*) fGlobalTracks->At(trackIndex[i]);
150 Int_t ringIndex = event ? event->GetIndex(ECbmDataType::kRichRing, i) : i;
151 gTrack->SetRichRingIndex(ringIndex);
152 }
153}
154
156{
157 const Int_t nofTracks = event ? event->GetNofData(ECbmDataType::kRichTrackProjection) : richProj->GetEntriesFast();
158 const Int_t nofRings = event ? event->GetNofData(ECbmDataType::kRichRing) : rings->GetEntriesFast();
159 if (nofTracks <= 0 || nofRings <= 0) return;
160 for (Int_t iT0 = 0; iT0 < nofTracks; iT0++) {
161 Int_t iT = event ? event->GetIndex(ECbmDataType::kRichTrackProjection, iT0) : iT0;
162 CbmGlobalTrack* gTrack = static_cast<CbmGlobalTrack*>(fGlobalTracks->At(iT));
163 // track already has rich segment
164 if (gTrack == nullptr || gTrack->GetRichRingIndex() >= 0) continue;
165
166 FairTrackParam* track = static_cast<FairTrackParam*>(richProj->At(iT));
167 Double_t xTrack = track->GetX();
168 Double_t yTrack = track->GetY();
169 if (xTrack == 0 && yTrack == 0) continue;
170 if (fUseTrd && fTrdTracks != nullptr && !IsTrdElectron(iT)) continue;
171 Double_t rMin = 999.;
172 Int_t iRingMin = -1;
173 for (Int_t iR0 = 0; iR0 < nofRings; iR0++) {
174 Int_t iR = event ? event->GetIndex(ECbmDataType::kRichRing, iR0) : iR0;
175 CbmRichRing* ring = static_cast<CbmRichRing*>(rings->At(iR));
176 if (ring == nullptr) continue;
177 if (ring->GetNofHits() < fMinNofHitsInRing) continue;
178
179 Double_t xRing = ring->GetCenterX();
180 Double_t yRing = ring->GetCenterY();
181 Double_t dist = TMath::Sqrt((xRing - xTrack) * (xRing - xTrack) + (yRing - yTrack) * (yRing - yTrack));
182 if (dist < rMin) {
183 rMin = dist;
184 iRingMin = iR;
185 }
186 } // loop rings
187 if (iRingMin < 0) continue;
188 // CbmRichRing* pRing = (CbmRichRing*)rings->At(iRingMin);
189 gTrack->SetRichRingIndex(iRingMin);
190 } //loop tracks
191}
192
194{
195 CbmGlobalTrack* gTrack = static_cast<CbmGlobalTrack*>(fGlobalTracks->At(iTrack));
196 Int_t trdIndex = gTrack->GetTrdTrackIndex();
197 if (trdIndex == -1) return false;
198 CbmTrdTrack* trdTrack = static_cast<CbmTrdTrack*>(fTrdTracks->At(trdIndex));
199 if (NULL == trdTrack) return false;
200
201 if (trdTrack->GetPidANN() > fTrdAnnCut) {
202 return true;
203 }
204
205 return false;
206}
TClonesArray * rings
Ring-Track Assignment according to the closest distance criterion.
TClonesArray * richProj
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
int32_t GetRichRingIndex() const
void SetRichRingIndex(int32_t iRing)
int32_t GetTrdTrackIndex() const
bool IsTrdElectron(int iTrack)
Check if global track was identified as electron in the TRD detector.
void DoAssign(CbmEvent *event, TClonesArray *rings, TClonesArray *richProj)
Inherited from CbmRichRingTrackAssignBase.
void DoAssignRingTrack(CbmEvent *event, TClonesArray *rings, TClonesArray *richProj)
Implementation of the ring-track version of the algorithm.
CbmRichRingTrackAssignClosestDAlgorithmEnum fAlgorithmType
void DoAssignTrackRing(CbmEvent *event, TClonesArray *rings, TClonesArray *richProj)
Implementation of the track-ring version of the algorithm.
void Init()
Inherited from CbmRichRingTrackAssignBase.
int32_t GetNofHits() const
Definition CbmRichRing.h:37
float GetCenterX() const
Definition CbmRichRing.h:77
float GetCenterY() const
Definition CbmRichRing.h:78
double GetPidANN() const
Definition CbmTrdTrack.h:41