EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CbmRichRingFinderIdeal.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CbmRichRingFinderIdeal.cxx
1 
12 #include "CbmRichRingFinderIdeal.h"
13 
14 #include "CbmRichHit.h"
15 #include "CbmRichRing.h"
16 #include "CbmRichPoint.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 
29 
31  fRichPoints(NULL),
32  fMcTracks(NULL)
33 {
34 
35 }
36 
38 {
39 
40 }
41 
43 {
45  if (NULL == ioman) {Fatal("CbmRichRingFinderIdeal::Init","RootManager is NULL!");}
46 
47  fMcTracks = (TClonesArray*) ioman->GetObject("MCTrack");
48  if (NULL == fMcTracks) {Fatal("CbmRichRingFinderIdeal::Init","No MCTrack array!");}
49 
50  fRichPoints = (TClonesArray*) ioman->GetObject("RichPoint");
51  if (NULL == fRichPoints) {Fatal("CbmRichRingFinderIdeal::Init","No RichPoint array!");}
52 }
53 
55  TClonesArray* hitArray,
56  TClonesArray* projArray,
57  TClonesArray* ringArray)
58 {
59  if ( NULL == hitArray) {
60  cout << "-E- CbmRichRingFinderIdeal::DoFind, RichHit array missing!" << endl;
61  return -1;
62  }
63 
64  if ( NULL == ringArray ) {
65  cout << "-E- CbmRichRingFinderIdeal::DoFind, Ring array missing!" << endl;
66  return -1;
67  }
68 
69  // Create STL map from MCtrack index to number of valid RichHits
70  map<Int_t, Int_t> hitMap;
71  Int_t nRichHits = hitArray->GetEntriesFast();
72  for (Int_t iHit = 0; iHit < nRichHits; iHit++) {
73  CbmRichHit* pRhit = (CbmRichHit*) hitArray->At(iHit);
74  if ( NULL == pRhit ) continue;
75  Int_t ptIndex = pRhit->GetRefId();
76  if (ptIndex < 0) continue; // fake or background hit
77  CbmRichPoint* pMCpt = (CbmRichPoint*) (fRichPoints->At(ptIndex));
78  if ( NULL == pMCpt ) continue;
79  Int_t mcTrackIndex = pMCpt->GetTrackID();
80  if ( mcTrackIndex < 0 ) continue;
81  CbmMCTrack* pMCtr = (CbmMCTrack*) fMcTracks->At(mcTrackIndex);
82  if ( NULL == pMCtr ) continue;
83  if ( pMCtr->GetPdgCode() != 50000050) continue; // select only Cherenkov photons
84  Int_t motherId = pMCtr->GetMotherId();
85  hitMap[motherId]++;
86  }
87 
88  // Create STL map from MCTrack index to RichRing index
89  map<Int_t, Int_t> ringMap;
90 
91  // Create RICHRings for MCTracks
92  Int_t nRings = 0; // number of RichRings
93  Int_t nMCTracks = fMcTracks->GetEntriesFast();
94  for (Int_t iMCTrack = 0; iMCTrack < nMCTracks; iMCTrack++) {
95  CbmMCTrack* pMCtr = (CbmMCTrack*) fMcTracks->At(iMCTrack);
96  if ( NULL == pMCtr ) continue;
97 
98  new((*ringArray)[nRings]) CbmRichRing();
99  ringMap[iMCTrack] = nRings++;
100  }
101 
102  // Loop over RichHits. Get corresponding MCPoint and MCTrack index
103  for (Int_t iHit = 0; iHit < nRichHits; iHit++) {
104  CbmRichHit* pRhit = (CbmRichHit*) hitArray->At(iHit);
105  if ( NULL == pRhit ) continue;
106 
107  Int_t ptIndex = pRhit->GetRefId();
108 
109  if (ptIndex < 0) continue;// fake or background hit
110  CbmRichPoint* pMCpt = (CbmRichPoint*) fRichPoints->At(ptIndex);
111  if ( NULL == pMCpt ) continue;
112 
113  Int_t mcTrackIndex = pMCpt->GetTrackID();
114  if ( mcTrackIndex < 0) continue;
115  CbmMCTrack* pMCtr = (CbmMCTrack*) fMcTracks->At(mcTrackIndex);
116  if ( NULL == pMCtr ) continue;
117  if ( pMCtr->GetPdgCode() != 50000050) continue;
118  Int_t motherId = pMCtr->GetMotherId();
119 
120  if (motherId < 0 || motherId > nMCTracks) continue;
121 
122  if (ringMap.find(motherId) == ringMap.end()) continue;
123 
124  Int_t ringIndex = ringMap[motherId];
125 
126  CbmRichRing* pRing = (CbmRichRing*) ringArray->At(ringIndex);
127  if ( NULL == pRing ) continue;
128 
129  pRing->AddHit(iHit); // attach the hit to the ring
130  }
131 
132  cout << "-I- CbmRichRingFinderIdeal: all " << nMCTracks << ", rec. " << nRings << endl;
133 
134  return nRings;
135 }