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