FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairGeoTrackHandler.cxx
Go to the documentation of this file.
1 /*
2  * FairGeoTrackHandler.cxx
3  *
4  * Created on: 26.11.2020
5  * \author Tobias Stockmanns <t.stockmanns@fz-juelich.de>
6  */
7 
8 #include "FairGeoTrackHandler.h"
9 
10 #include "TClonesArray.h"
11 
12 #include <algorithm>
13 #include <fairlogger/Logger.h>
14 #include <iostream>
15 #include <utility>
16 
17 void FairGeoTrackHandler::FillTClonesArray(TClonesArray* geoArray, int evtIndex, double t0Event, double t0Current)
18 {
19  RemoveOldTracks(t0Current);
20  int evtPresent = std::count(fEventsFilledInBuffer.begin(), fEventsFilledInBuffer.end(), evtIndex);
21  LOG(debug) << "Fill TClonesArray: CurrentTime " << t0Current << " Event " << evtIndex << " time: " << t0Event
22  << " is already present " << evtPresent;
23  if (evtPresent == 0) {
24  fEventsFilledInBuffer.push_back(evtIndex);
25  for (int i = 0; i < geoArray->GetEntriesFast(); i++) {
26  TGeoTrack* track = (TGeoTrack*)geoArray->At(i)->Clone();
27  fTrackVector.push_back(std::make_pair(track, t0Event)); //< not clear if a pointer or an object is better
28  }
29  }
30 }
31 
33 {
34  std::for_each(fTrackVector.begin(), fTrackVector.end(), [](std::pair<TGeoTrack*, double> const& track) {
35  delete (track.first);
36  });
37  fTrackVector.clear();
38  fEventsFilledInBuffer.clear();
39 }
40 
42 {
43  if (fTrackVector.size() > 0) {
44  fTrackVector.erase(std::remove_if(fTrackVector.begin(),
45  fTrackVector.end(),
46  [&](std::pair<TGeoTrack*, double> const& track) {
47  Double_t x, y, z, t;
48  track.first->GetLastPoint(x, y, z, t);
49  if (((t * 1e9) + track.second) < (newT0Time - fHoldTime)) {
50  delete (track.first);
51  return true;
52  } else
53  return false;
54  }),
55  fTrackVector.end());
56  }
57 }
void FillTClonesArray(TClonesArray *geoArray, int evtIndex, double t0Event, double t0Current)
void RemoveOldTracks(double newT0Time)