EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CbmRichRingTrackAssignClosestD.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CbmRichRingTrackAssignClosestD.cxx
1 
8 #include <assert.h>
9 
11 
12 #include "CbmRichRing.h"
13 
14 #include "CbmMCTrack.h"
15 #include "FairRootManager.h"
16 #include "FairTrackParam.h"
17 #include "CbmGlobalTrack.h"
18 //#include "CbmTrdTrack.h"
19 
20 #include "TClonesArray.h"
21 
22 #include <iostream>
23 #include <algorithm>
24 #include <vector>
25 
26 using std::cout;
27 using std::endl;
28 using std::vector;
29 
31  //fGlobalTracks(NULL),
32  fTrdTracks(NULL),
33 
34  fTrdAnnCut(-0.5),
35  fUseTrd(false)
36 {
37 
38 }
39 
41 {
42 }
43 
45 {
47  if (NULL == ioman) {Fatal("CbmRichRingTrackAssignClosestD::Init", "RootManager not instantised!");}
48 
49  //assert(0);
50  //#if _NOW_
51  //fGlobalTracks = (TClonesArray*) ioman->GetObject("GlobalTrack");
52  //if (NULL == fGlobalTracks) {Fatal("CbmRichRingTrackAssignClosestD::Init", "No GlobalTrack array!");}
53  //#endif
54 
55  fTrdTracks = (TClonesArray*) ioman->GetObject("TrdTrack");
56  //if (NULL == fTrdTracks) {Fatal("CbmRichRingTrackAssignClosestD::Init", "No TrdTrack array!");}
57 }
58 
60  TClonesArray* rings,
61  TClonesArray* richProj)
62 {
63  Int_t nofTracks = richProj->GetEntriesFast();
64  Int_t nofRings = rings->GetEntriesFast();
65 
66  vector<Int_t> trackIndex;
67  vector<Double_t> trackDist;
68  trackIndex.resize(nofRings);
69  trackDist.resize(nofRings);
70  for (UInt_t i = 0; i < trackIndex.size(); i++){
71  trackIndex[i] = -1;
72  trackDist[i] = 999.;
73  }
74 
75  for (Int_t iIter = 0; iIter < 4; iIter++){
76  for (Int_t iRing=0; iRing < nofRings; iRing++) {
77  if (trackIndex[iRing] != -1) continue;
78  CbmRichRing* pRing = (CbmRichRing*)rings->At(iRing);
79  if (NULL == pRing) continue;
80  if (pRing->GetNofHits() < fMinNofHitsInRing) continue;
81 
82  Double_t xRing = pRing->GetCenterX();
83  Double_t yRing = pRing->GetCenterY();
84  cout << "xR:" << xRing << " yR:" << yRing << endl;
85  Double_t rMin = 999.;
86  Int_t iTrackMin = -1;
87 
88  for (Int_t iTrack=0; iTrack < nofTracks; iTrack++) {
89  vector<Int_t>::iterator it = find(trackIndex.begin(), trackIndex.end(), iTrack);
90  if (it != trackIndex.end()) continue;
91 
92  FairTrackParam* pTrack = (FairTrackParam*)richProj->At(iTrack);
93  Double_t xTrack = pTrack->GetX();
94  Double_t yTrack = pTrack->GetY();
95  cout << "xT:" << xTrack << " yT:" << yTrack << endl;
96  // no projection onto the photodetector plane
97  if (xTrack == 0 && yTrack == 0) continue;
98 
99  if (fUseTrd && fTrdTracks != NULL && !IsTrdElectron(iTrack)) continue;
100 
101  Double_t dist = TMath::Sqrt( (xRing-xTrack)*(xRing-xTrack) +
102  (yRing-yTrack)*(yRing-yTrack) );
103 
104  if (dist < rMin) {
105  rMin = dist;
106  iTrackMin = iTrack;
107  }
108  } // loop tracks
109  trackIndex[iRing] = iTrackMin;
110  trackDist[iRing] = rMin;
111  }//loop rings
112 
113  for (UInt_t i1 = 0; i1 < trackIndex.size(); i1++){
114  for (UInt_t i2 = 0; i2 < trackIndex.size(); i2++){
115  if (i1 == i2) continue;
116  if (trackIndex[i1] == trackIndex[i2] && trackIndex[i1] != -1){
117  if (trackDist[i1] >= trackDist[i2]){
118  trackDist[i1] = 999.;
119  trackIndex[i1] = -1;
120  }else{
121  trackDist[i2] = 999.;
122  trackIndex[i2] = -1;
123  }
124  }
125  }
126  }
127  }//iIter
128 
129  // fill global tracks
130 #if _LATER_
131  for (UInt_t i = 0; i < trackIndex.size(); i++){
132  CbmRichRing* pRing = (CbmRichRing*)rings->At(i);
133  pRing->SetTrackID(trackIndex[i]);
134  pRing->SetDistance(trackDist[i]);
135  if (trackIndex[i] == -1) continue;
136  CbmGlobalTrack* gTrack = (CbmGlobalTrack*) fGlobalTracks->At(trackIndex[i]);
137  gTrack->SetRichRingIndex(i);
138  }
139 #endif
140 }
141 
143  Int_t iTrack)
144 {
145 #if _LATER_
146  CbmGlobalTrack* gTrack = (CbmGlobalTrack*) fGlobalTracks->At(iTrack);
147  Int_t trdIndex = gTrack->GetTrdTrackIndex();
148  if (trdIndex == -1) return false;
149  CbmTrdTrack* trdTrack = (CbmTrdTrack*)fTrdTracks->At(trdIndex);
150  if (NULL == trdTrack)return false;
151 
152  if (trdTrack->GetPidANN() > fTrdAnnCut) {
153  return true;
154  }
155 #endif
156  return false;
157 }