CbmRoot
CbmRichRingFinderIdeal.cxx
Go to the documentation of this file.
1 
11 #include "CbmRichRingFinderIdeal.h"
12 
13 #include "CbmDigiManager.h"
14 #include "CbmMCDataArray.h"
15 #include "CbmMCDataManager.h"
16 #include "CbmMCEventList.h"
17 #include "CbmMCTrack.h"
18 #include "CbmMatch.h"
19 #include "CbmMatchRecoToMC.h"
20 #include "CbmRichDigi.h"
21 #include "CbmRichHit.h"
22 #include "CbmRichPoint.h"
23 #include "CbmRichRing.h"
24 #include "FairLogger.h"
25 #include "FairRootManager.h"
26 
27 #include "TClonesArray.h"
28 
29 #include <iostream>
30 #include <map>
31 #include <vector>
32 
33 using namespace std;
34 
35 
38  , fRichPoints(NULL)
39  , fMcTracks(NULL)
40  , fEventList(NULL)
41  , fDigiMan(nullptr) {}
42 
44 
46  FairRootManager* ioman = FairRootManager::Instance();
47  if (NULL == ioman) {
48  Fatal("CbmRichRingFinderIdeal::Init", "RootManager is NULL!");
49  }
50 
51  CbmMCDataManager* mcManager =
52  (CbmMCDataManager*) ioman->GetObject("MCDataManager");
53  if (mcManager == nullptr)
54  LOG(fatal) << "CbmRichRingFinderIdeal::Init() NULL MCDataManager.";
55 
57  fDigiMan->Init();
59  Fatal("CbmRichHitProducer::Init", "No RichDigi array!");
60  }
62  Fatal("CbmRichHitProducer::Init", "No RichMatchDigi array!");
63  }
64 
65  fMcTracks = mcManager->InitBranch("MCTrack");
66  if (NULL == fMcTracks) {
67  LOG(fatal) << "CbmRichRingFinderIdeal::Init No MCTrack!";
68  }
69 
70  fRichPoints = mcManager->InitBranch("RichPoint");
71  if (NULL == fRichPoints) {
72  LOG(fatal) << "CbmRichRingFinderIdeal::Init No RichPoint!";
73  }
74 
75  fEventList = (CbmMCEventList*) ioman->GetObject("MCEventList.");
76  if (NULL == fEventList) {
77  LOG(fatal) << "CbmRichRingFinderIdeal::Init No MCEventList!";
78  }
79 }
80 
81 Int_t CbmRichRingFinderIdeal::DoFind(TClonesArray* hitArray,
82  TClonesArray* /*projArray*/,
83  TClonesArray* ringArray) {
84  if (NULL == hitArray) {
85  cout << "-E- CbmRichRingFinderIdeal::DoFind, RichHit array missing!"
86  << endl;
87  return -1;
88  }
89 
90  if (NULL == ringArray) {
91  cout << "-E- CbmRichRingFinderIdeal::DoFind, Ring array missing!" << endl;
92  return -1;
93  }
94 
95  // Create STL map from MCtrack index to number of valid RichHits
96  map<pair<Int_t, Int_t>, Int_t> hitMap;
97  Int_t nofRichHits = hitArray->GetEntriesFast();
98  for (Int_t iHit = 0; iHit < nofRichHits; iHit++) {
99  const CbmRichHit* richHit = static_cast<CbmRichHit*>(hitArray->At(iHit));
100  if (NULL == richHit) continue;
101  Int_t eventId = GetEventIdForRichHit(richHit);
102  vector<pair<Int_t, Int_t>> motherIds =
104  fDigiMan, richHit, fRichPoints, fMcTracks, eventId);
105  for (UInt_t i = 0; i < motherIds.size(); i++) {
106  hitMap[motherIds[i]]++;
107  }
108  }
109 
110  // Create STL map from MCTrack index to RichRing index
111  map<pair<Int_t, Int_t>, Int_t> ringMap;
112  Int_t nofRings = 0;
113  Int_t nofEvents = fEventList->GetNofEvents();
114  for (Int_t iE = 0; iE < nofEvents; iE++) {
115  Int_t fileId = fEventList->GetFileIdByIndex(iE);
116  Int_t eventId = fEventList->GetEventIdByIndex(iE);
117 
118  // Create RichRings for McTracks
119  Int_t nofMcTracks = fMcTracks->Size(fileId, eventId);
120  for (Int_t iT = 0; iT < nofMcTracks; iT++) {
121  const CbmMCTrack* mcTrack =
122  static_cast<CbmMCTrack*>(fMcTracks->Get(fileId, eventId, iT));
123  if (NULL == mcTrack) continue;
124  pair<Int_t, Int_t> val = std::make_pair(eventId, iT);
125  if (hitMap[val] <= 0) continue;
126  new ((*ringArray)[nofRings]) CbmRichRing();
127  ringMap[val] = nofRings++;
128  }
129  }
130 
131  // Loop over RichHits. Get corresponding MCPoint and MCTrack index
132  for (Int_t iHit = 0; iHit < nofRichHits; iHit++) {
133  const CbmRichHit* richHit = static_cast<CbmRichHit*>(hitArray->At(iHit));
134  if (NULL == richHit) continue;
135  Int_t eventId = GetEventIdForRichHit(richHit);
136 
137  vector<pair<Int_t, Int_t>> motherIds =
139  fDigiMan, richHit, fRichPoints, fMcTracks, eventId);
140 
141  for (UInt_t i = 0; i < motherIds.size(); i++) {
142  if (ringMap.find(motherIds[i]) == ringMap.end()) continue;
143  Int_t ringIndex = ringMap[motherIds[i]];
144  CbmRichRing* ring = (CbmRichRing*) ringArray->At(ringIndex);
145  if (NULL == ring) continue;
146 
147  ring->AddHit(iHit); // attach the hit to the ring
148  }
149  }
150 
151  LOG(info) << "-I- CbmRichRingFinderIdeal nofRings:" << nofRings;
152 
153  return nofRings;
154 }
155 
156 
158  if (richHit == NULL) return -1;
159  Int_t digiIndex = richHit->GetRefId();
160  if (digiIndex < 0) return -1;
161  const CbmMatch* digiMatch =
163  if (NULL == digiMatch) return -1;
164  return digiMatch->GetMatchedLink().GetEntry();
165 }
CbmRichPoint.h
CbmMatch::GetMatchedLink
const CbmLink & GetMatchedLink() const
Definition: CbmMatch.h:37
CbmMCDataManager::GetObject
CbmMCDataObject * GetObject(const char *name)
Definition: CbmMCDataManager.cxx:137
CbmRichRingFinderIdeal::fDigiMan
CbmDigiManager * fDigiMan
Definition: CbmRichRingFinderIdeal.h:29
CbmMCEventList::GetFileIdByIndex
Int_t GetFileIdByIndex(UInt_t index)
File number by index @value File number for event at given index in list.
Definition: CbmMCEventList.cxx:106
CbmMatch
Definition: CbmMatch.h:22
CbmMCDataManager.h
CbmRichRingFinderIdeal::fMcTracks
CbmMCDataArray * fMcTracks
Definition: CbmRichRingFinderIdeal.h:27
CbmRichRingFinderIdeal::GetEventIdForRichHit
Int_t GetEventIdForRichHit(const CbmRichHit *richHit)
Definition: CbmRichRingFinderIdeal.cxx:157
CbmRichRingFinderIdeal::CbmRichRingFinderIdeal
CbmRichRingFinderIdeal()
Default constructor.
Definition: CbmRichRingFinderIdeal.cxx:36
CbmMCDataArray::Size
Int_t Size(Int_t fileNumber, Int_t eventNumber)
Definition: CbmMCDataArray.cxx:133
CbmDigiManager::Init
InitStatus Init()
Initialisation.
Definition: CbmDigiManager.cxx:71
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmRichRingFinderIdeal::DoFind
virtual int DoFind(TClonesArray *hitArray, TClonesArray *projArray, TClonesArray *ringArray)
Definition: CbmRichRingFinderIdeal.cxx:81
CbmMCDataManager::InitBranch
CbmMCDataArray * InitBranch(const char *name)
Definition: CbmMCDataManager.cxx:106
CbmMCDataArray.h
CbmRichRing
Definition: CbmRichRing.h:17
CbmHit::GetRefId
Int_t GetRefId() const
Definition: CbmHit.h:72
CbmRichRing.h
CbmMatch.h
CbmMatchRecoToMC.h
FairTask for matching RECO data to MC.
CbmDigiManager::IsPresent
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
Definition: CbmDigiManager.cxx:112
CbmDigiManager::Instance
static CbmDigiManager * Instance()
Static instance.
Definition: CbmDigiManager.h:93
CbmDigiManager::IsMatchPresent
static Bool_t IsMatchPresent(ECbmModuleId systemId)
Presence of a digi match branch.
Definition: CbmDigiManager.cxx:104
CbmRichDigi.h
CbmRichRingFinderIdeal::Init
virtual void Init()
Inherited from CbmRichRingFinder.
Definition: CbmRichRingFinderIdeal.cxx:45
CbmMCEventList::GetNofEvents
std::size_t GetNofEvents() const
Number of events in the list @value Number of events.
Definition: CbmMCEventList.h:90
CbmRichRingFinderIdeal::~CbmRichRingFinderIdeal
virtual ~CbmRichRingFinderIdeal()
Destructor.
Definition: CbmRichRingFinderIdeal.cxx:43
CbmMCDataArray::Get
TObject * Get(const CbmLink *lnk)
Definition: CbmMCDataArray.h:47
CbmMatchRecoToMC::GetMcTrackMotherIdsForRichHit
static std::vector< std::pair< Int_t, Int_t > > GetMcTrackMotherIdsForRichHit(CbmDigiManager *digiMan, const CbmRichHit *hit, CbmMCDataArray *richPoints, CbmMCDataArray *mcTracks, Int_t eventNumber)
Return McTrack Ids for RICH hit C++11 efficient way to return vector.
Definition: CbmMatchRecoToMC.cxx:821
CbmDigiManager::GetMatch
const CbmMatch * GetMatch(ECbmModuleId systemId, UInt_t index) const
Get a match object.
Definition: CbmDigiManager.cxx:54
CbmRichRingFinderIdeal::fRichPoints
CbmMCDataArray * fRichPoints
Definition: CbmRichRingFinderIdeal.h:26
ECbmModuleId::kRich
@ kRich
Ring-Imaging Cherenkov Detector.
CbmMCEventList
Container class for MC events with number, file and start time.
Definition: CbmMCEventList.h:38
fDigiMan
CbmDigiManager * fDigiMan
Definition: CbmTofAnaTestbeam.cxx:88
CbmMCDataManager
Task class creating and managing CbmMCDataArray objects.
Definition: CbmMCDataManager.h:27
CbmMCEventList.h
CbmRichRingFinder
Definition: CbmRichRingFinder.h:32
CbmMCTrack.h
CbmMCEventList::GetEventIdByIndex
Int_t GetEventIdByIndex(UInt_t index)
Event number by index @value Event number for event at given index in list.
Definition: CbmMCEventList.cxx:77
CbmDigiManager.h
CbmRichRingFinderIdeal.h
Ideal ring finder in the RICH detector. It uses MC information to attach RICH hits to rings.
CbmMCTrack
Definition: CbmMCTrack.h:34
CbmRichRing::AddHit
void AddHit(UInt_t pHit)
Definition: CbmRichRing.h:34
CbmRichHit.h
CbmRichHit
Definition: CbmRichHit.h:19
CbmRichRingFinderIdeal::fEventList
CbmMCEventList * fEventList
Definition: CbmRichRingFinderIdeal.h:28