CbmRoot
Loading...
Searching...
No Matches
CbmBuildEventsFromTracksReal.cxx
Go to the documentation of this file.
1/* Copyright (C) 2017-2020 IKF-UFra, GSI
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Valentina Akishina , Maksym Zyzak, Valentina Akishina [committer] */
4
11
12#include "CbmEvent.h"
13#include "CbmStsDigi.h"
14#include "CbmStsHit.h"
15#include "FairRootManager.h"
16#include "TClonesArray.h"
17#include "TStopwatch.h"
18
19#include <Logger.h>
20
21#include <cassert>
22#include <iomanip>
23#include <iostream>
24#include <map>
25
26
27using namespace std;
28
29
30// ===== Constructor =====================================================
32 : FairTask("CbmBuildEventsFromTracksReal")
33 , fStsTracks(nullptr)
34 , fEvents(nullptr)
35{
36}
37// ===========================================================================
38
39
40// ===== Destructor ======================================================
45// ===========================================================================
46
47// ===== Task initialisation =============================================
49{
50
51
52 // --- Get FairRootManager instance
53 FairRootManager* ioman = FairRootManager::Instance();
54 assert(ioman);
55
56 fStsTracks = (TClonesArray*) ioman->GetObject("StsTrack");
57 assert(fStsTracks);
58
59
60 // Register output array (CbmStsDigi)
61 fEvents = new TClonesArray("CbmEvent", 100);
62 ioman->Register("CbmEvent", "Cbm_Event", fEvents, IsOutputBranchPersistent("CbmEvent"));
63
64 return kSUCCESS;
65}
66// ===========================================================================
67
68// ===== Task execution ==================================================
70{
71
72 TStopwatch timer;
73 timer.Start();
74 std::map<Int_t, CbmEvent*> eventMap;
75
76 // Clear output array
77 fEvents->Delete();
78
79 UInt_t nTracks = fStsTracks->GetEntriesFast();
80
81 vector<CbmStsTrack> vRTracks_new;
82 vector<int> Index;
83
84
85 vector<SortTracks> Tracks;
86
87 vector<vector<int>> timeClusters;
88 unsigned int nUsedTracks = 0;
89
90
91 for (unsigned int iTrack = 0; iTrack < nTracks; iTrack++) {
92 CbmStsTrack* track = (CbmStsTrack*) fStsTracks->At(iTrack);
93
94 Double_t time = track->GetStartTime();
95 Double_t timeEr = track->GetStartTimeError();
96
97 SortTracks structure;
98
99 structure.Track = *track;
100 structure.index = iTrack;
101 structure.used = 0;
102
103 if (timeEr > 0 && timeEr == timeEr && time == time) Tracks.push_back(structure);
104 }
105
106 // std::sort(Tracks.begin(), Tracks.end(), CompareTrackTime);
107
108
109 nUsedTracks = 0;
110
111 vector<vector<UInt_t>> clusters;
112
113
114 while (nUsedTracks < Tracks.size()) {
115
116 vector<UInt_t> cluster;
117
118 //find first unused track and create a new cluster
119 for (unsigned int iTrack = 0; iTrack < Tracks.size(); iTrack++)
120 if (!Tracks[iTrack].used) {
121 cluster.push_back(Tracks[iTrack].index);
122 Tracks[iTrack].used = true;
123 nUsedTracks++;
124 break;
125 }
126
127 //form a cluster around this track
128 for (unsigned int iTrack = 0; iTrack < Tracks.size(); iTrack++) {
129 if (Tracks[iTrack].used) continue;
130
131 float time1 = Tracks[iTrack].Track.GetStartTime();
132 float timeC1 = Tracks[iTrack].Track.GetStartTimeError();
133
134 for (unsigned int iClusterTrack = 0; iClusterTrack < cluster.size(); iClusterTrack++) {
135 CbmStsTrack* stsTrack = (CbmStsTrack*) fStsTracks->At(cluster[iClusterTrack]);
136
137 float time2 = stsTrack->GetStartTime();
138 float timeC2 = stsTrack->GetStartTimeError();
139
140 float dt = fabs(time1 - time2);
141 float error = sqrt(timeC1 + timeC2);
142
143 if ((dt < 4 * error) && (dt < 8.5)) {
144 cluster.push_back(Tracks[iTrack].index);
145 Tracks[iTrack].used = true;
146 nUsedTracks++;
147 break;
148 }
149 }
150 }
151
152
153 float time_min = 100000000000;
154 float time_max = 0;
155
156 for (unsigned int iClusterTrack = 0; iClusterTrack < cluster.size(); iClusterTrack++) {
157 CbmStsTrack* stsTrack = (CbmStsTrack*) fStsTracks->At(cluster[iClusterTrack]);
158
159 if (time_min > stsTrack->GetStartTime()) time_min = stsTrack->GetStartTime();
160
161 if (time_max < stsTrack->GetStartTime()) time_max = stsTrack->GetStartTime();
162 }
163
164 if (cluster.size() > 1) clusters.push_back(cluster);
165 }
166
167
168 for (unsigned int iEvent = 0; iEvent < clusters.size(); iEvent++) {
169 CbmEvent* event = nullptr;
170 Int_t nEvents = fEvents->GetEntriesFast();
171
172 // if (clusters[iEvent].size()>1)
173 {
174
175 event = new ((*fEvents)[nEvents]) CbmEvent(iEvent);
176 event->SetStsTracks(clusters[iEvent]);
177 }
178 }
179
180 timer.Stop();
181}
182
ClassImp(CbmConverterManager)
Data class for a reconstructed hit in the STS.
friend fvec sqrt(const fvec &a)
TClonesArray * fEvents
Output array (class CbmEvent)
TClonesArray * fStsTracks
Input array (class CbmStsDigi)
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
void SetStsTracks(std::vector< uint32_t > &indexVector)
Sets the index array for STS tracks. Old content will be overwritten.
Definition CbmEvent.h:183
double GetStartTime() const
Definition CbmTrack.h:71
double GetStartTimeError() const
Definition CbmTrack.h:72
Hash for CbmL1LinkKey.