CbmRoot
CbmBuildEventsFromTracksIdeal.cxx
Go to the documentation of this file.
1 
7 
8 #include "CbmEvent.h"
9 #include "CbmStsDigi.h"
10 #include "CbmStsHit.h"
11 #include "CbmStsTrack.h"
12 #include "FairLogger.h"
13 #include "FairRootManager.h"
14 #include "TClonesArray.h"
15 #include "TStopwatch.h"
16 #include <cassert>
17 #include <iomanip>
18 #include <iostream>
19 #include <map>
20 
21 #include "CbmMCDataArray.h"
22 #include "CbmMCDataManager.h"
23 #include "CbmMCEventList.h"
24 #include "CbmMCTrack.h"
25 #include "CbmTrackMatchNew.h"
26 
27 using namespace std;
28 
29 
30 // ===== Constructor =====================================================
32  : FairTask("CbmBuildEventsFromTracksIdeal")
33  , fStsDigis(nullptr)
34  , fStsTracks(nullptr)
35  , fMCTracks(nullptr)
36  , fStsHits(nullptr)
37  , fMcPoints(nullptr)
38  , fEvents(nullptr)
39  , fStsTrackMatchArray(nullptr)
40  , fEventList(nullptr) {}
41 // ===========================================================================
42 
43 
44 // ===== Destructor ======================================================
46  // fEvents->Delete();
47 }
48 // ===========================================================================
49 
50 // ===== Task initialisation =============================================
52 
53 
54  // --- Get FairRootManager instance
55  FairRootManager* ioman = FairRootManager::Instance();
56  assert(ioman);
57 
58  // --- Get input array (CbmStsDigi)
59  // fStsDigis = (TClonesArray*) ioman->GetObject("StsDigi");
60  // assert ( fStsDigis );
61 
62  CbmMCDataManager* mcManager =
63  (CbmMCDataManager*) ioman->GetObject("MCDataManager");
64  if (mcManager == nullptr) LOG(fatal) << GetName() << ": No CbmMCDataManager!";
65 
66  fMCTracks = (CbmMCDataArray*) mcManager->InitBranch("MCTrack");
67  if (fMCTracks == nullptr) LOG(fatal) << GetName() << ": No MCTrack data!";
68 
69  fEventList = (CbmMCEventList*) ioman->GetObject("MCEventList.");
70  if (fEventList == 0) {
71  Error("CbmKFParticleFinderQA::Init", "MC Event List not found!");
72  return kERROR;
73  }
74 
75  // open MCTrack array
76  fStsTracks = (TClonesArray*) ioman->GetObject("StsTrack");
77  assert(fStsTracks);
78 
79  fStsTrackMatchArray = (TClonesArray*) ioman->GetObject("StsTrackMatch");
80  if (fStsTrackMatchArray == 0) {
81  Error("CbmKFParticleFinderQA::Init", "track match array not found!");
82  return kERROR;
83  }
84 
85  fStsHits = (TClonesArray*) ioman->GetObject("StsHit");
86  assert(fStsHits);
87 
88  fMcPoints = (TClonesArray*) ioman->GetObject("StsPoint");
89  assert(fMcPoints);
90 
91 
92  // Register output array (CbmStsDigi)
93  fEvents = new TClonesArray("CbmEvent", 100);
94  ioman->Register(
95  "Event", "CbmEvent", fEvents, IsOutputBranchPersistent("Event"));
96 
97  return kSUCCESS;
98 }
99 // ===========================================================================
100 
101 // ===== Task execution ==================================================
103 
104  TStopwatch timer;
105  timer.Start();
106  std::map<Int_t, CbmEvent*> eventMap;
107 
108  // Clear output array
109  fEvents->Delete();
110 
111  UInt_t nTracks = fStsTracks->GetEntriesFast();
112 
113 
114  vector<vector<UInt_t>> vKFPTrack1;
115 
116  int nMCEvents = fEventList->GetNofEvents();
117 
118  vKFPTrack1.resize(nMCEvents);
119 
120 
121  for (unsigned int iTrack = 0; iTrack < nTracks; iTrack++) {
122 
123  // CbmStsTrack* track = (CbmStsTrack*) fStsTracks->At(iTrack);
124 
125  CbmTrackMatchNew* stsTrackMatch =
126  (CbmTrackMatchNew*) fStsTrackMatchArray->At(iTrack);
127  if (stsTrackMatch->GetNofLinks() == 0) continue;
128  Float_t bestWeight = 0.f;
129  Float_t totalWeight = 0.f;
130  Int_t mcTrackId = -1;
131  int mcEvent = -1;
132  CbmLink link;
133  for (int iLink = 0; iLink < stsTrackMatch->GetNofLinks(); iLink++) {
134  totalWeight += stsTrackMatch->GetLink(iLink).GetWeight();
135  if (stsTrackMatch->GetLink(iLink).GetWeight() > bestWeight) {
136  bestWeight = stsTrackMatch->GetLink(iLink).GetWeight();
137  int iMCTrack = stsTrackMatch->GetLink(iLink).GetIndex();
138  link = stsTrackMatch->GetLink(iLink);
139 
140 
141  mcEvent = link.GetEntry();
142  mcTrackId = iMCTrack;
143  }
144  }
145  if (bestWeight / totalWeight < 0.7 || mcTrackId < 0) continue;
146 
147  // CbmMCTrack *mcTrack = (CbmMCTrack*)fMCTracks->Get(0, mcEvent, mcTrackId);
148 
149  vKFPTrack1[mcEvent].push_back(iTrack);
150  }
151 
152 
153  for (unsigned int iEvent = 0; iEvent < vKFPTrack1.size(); iEvent++) {
154  CbmEvent* event = nullptr;
155  Int_t nEvents = fEvents->GetEntriesFast();
156 
157  if (vKFPTrack1[iEvent].size() > 1) {
158 
159  event = new ((*fEvents)[nEvents]) CbmEvent(iEvent);
160  event->SetStsTracks(vKFPTrack1[iEvent]);
161  }
162  }
163 
164  timer.Stop();
165 }
166 
167 
170  : fMCFileId(-1)
171  , fMCEventId(-1)
172  , fMCTrackId(-1)
173  , fRecoTrackId()
174  , fRecoEventId() {}
175 
179 
180  vector<int> fRecoTrackId;
181  vector<int> fRecoEventId;
182 };
183 
184 
185 // ===========================================================================
186 
CbmMCDataManager::GetObject
CbmMCDataObject * GetObject(const char *name)
Definition: CbmMCDataManager.cxx:137
CbmMCDataManager.h
CbmMatch::GetLink
const CbmLink & GetLink(Int_t i) const
Definition: CbmMatch.h:35
CbmMatch::GetNofLinks
Int_t GetNofLinks() const
Definition: CbmMatch.h:38
CbmBuildEventMCTrack::fMCFileId
int fMCFileId
Definition: CbmBuildEventsFromTracksIdeal.cxx:176
CbmBuildEventsFromTracksIdeal::fMCTracks
CbmMCDataArray * fMCTracks
Input array (class CbmStsDigi)
Definition: CbmBuildEventsFromTracksIdeal.h:43
CbmBuildEventsFromTracksIdeal
Task class for associating digis to events.
Definition: CbmBuildEventsFromTracksIdeal.h:25
CbmBuildEventsFromTracksIdeal.h
CbmMCDataManager::InitBranch
CbmMCDataArray * InitBranch(const char *name)
Definition: CbmMCDataManager.cxx:106
CbmMCDataArray.h
CbmMCDataArray
Access to a MC data branch for time-based analysis.
Definition: CbmMCDataArray.h:35
CbmBuildEventMCTrack::fMCEventId
int fMCEventId
Definition: CbmBuildEventsFromTracksIdeal.cxx:177
CbmBuildEventsFromTracksIdeal::fStsTrackMatchArray
TClonesArray * fStsTrackMatchArray
Definition: CbmBuildEventsFromTracksIdeal.h:47
CbmBuildEventsFromTracksIdeal::fStsHits
TClonesArray * fStsHits
Input array (class CbmStsDigi)
Definition: CbmBuildEventsFromTracksIdeal.h:44
CbmBuildEventsFromTracksIdeal::fMcPoints
TClonesArray * fMcPoints
Input array (class CbmStsDigi)
Definition: CbmBuildEventsFromTracksIdeal.h:45
CbmBuildEventMCTrack::fRecoEventId
vector< int > fRecoEventId
Definition: CbmBuildEventsFromTracksIdeal.cxx:181
CbmBuildEventsFromTracksIdeal::~CbmBuildEventsFromTracksIdeal
virtual ~CbmBuildEventsFromTracksIdeal()
Definition: CbmBuildEventsFromTracksIdeal.cxx:45
CbmBuildEventMCTrack::fMCTrackId
int fMCTrackId
Definition: CbmBuildEventsFromTracksIdeal.cxx:178
CbmBuildEventMCTrack
Definition: CbmBuildEventsFromTracksIdeal.cxx:168
CbmEvent.h
CbmMCEventList::GetNofEvents
std::size_t GetNofEvents() const
Number of events in the list @value Number of events.
Definition: CbmMCEventList.h:90
CbmStsDigi.h
CbmStsTrack.h
Data class for STS tracks.
CbmBuildEventsFromTracksIdeal::fStsTracks
TClonesArray * fStsTracks
Input array (class CbmStsDigi)
Definition: CbmBuildEventsFromTracksIdeal.h:42
CbmTrackMatchNew.h
CbmBuildEventsFromTracksIdeal::fEventList
CbmMCEventList * fEventList
Definition: CbmBuildEventsFromTracksIdeal.h:49
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMCEventList
Container class for MC events with number, file and start time.
Definition: CbmMCEventList.h:38
CbmMCDataManager
Task class creating and managing CbmMCDataArray objects.
Definition: CbmMCDataManager.h:27
CbmEvent::SetStsTracks
void SetStsTracks(std::vector< UInt_t > &indexVector)
Sets the index array for STS tracks. Old content will be overwritten.
Definition: CbmEvent.h:157
CbmBuildEventsFromTracksIdeal::Exec
virtual void Exec(Option_t *opt)
Definition: CbmBuildEventsFromTracksIdeal.cxx:102
CbmMCEventList.h
CbmMCTrack.h
CbmBuildEventsFromTracksIdeal::Init
virtual InitStatus Init()
Definition: CbmBuildEventsFromTracksIdeal.cxx:51
CbmBuildEventMCTrack::fRecoTrackId
vector< int > fRecoTrackId
Definition: CbmBuildEventsFromTracksIdeal.cxx:180
CbmBuildEventMCTrack::CbmBuildEventMCTrack
CbmBuildEventMCTrack()
Definition: CbmBuildEventsFromTracksIdeal.cxx:169
CbmEvent
Class characterising one event by a collection of links (indices) to data objects,...
Definition: CbmEvent.h:30
CbmTrackMatchNew
Definition: CbmTrackMatchNew.h:19
CbmBuildEventsFromTracksIdeal::fEvents
TClonesArray * fEvents
Output array (class CbmEvent)
Definition: CbmBuildEventsFromTracksIdeal.h:46
CbmBuildEventsFromTracksIdeal::CbmBuildEventsFromTracksIdeal
CbmBuildEventsFromTracksIdeal()
Definition: CbmBuildEventsFromTracksIdeal.cxx:31
CbmStsHit.h
Data class for a reconstructed hit in the STS.