CbmRoot
CbmLitFitTracks.cxx
Go to the documentation of this file.
1 
7 #include "CbmLitFitTracks.h"
8 #include "CbmStsTrack.h"
9 #include "CbmTrack.h"
10 #include "FairRootManager.h"
11 #include "FairTrackParam.h"
12 #include "base/CbmLitPtrTypes.h"
13 #include "base/CbmLitToolFactory.h"
14 #include "base/CbmLitTypes.h"
17 #include "std/data/CbmLitTrack.h"
19 
20 #include "TClonesArray.h"
21 
22 #include <algorithm>
23 #include <cassert>
24 #include <iostream>
25 #include <vector>
26 
27 using std::cout;
28 using std::endl;
29 using std::for_each;
30 using std::vector;
31 
33  : FairTask()
34  , fGlobalTracks(NULL)
35  , fStsTracks(NULL)
36  , fMuchTracks(NULL)
37  , fTrdTracks(NULL)
38  , fMuchPixelHits(NULL)
39  , fMuchStrawHits(NULL)
40  , fTrdHits(NULL) {}
41 
43 
44 InitStatus CbmLitFitTracks::Init() {
46 
47  fFitWatch.Reset();
48  fFitWithIOWatch.Reset();
49 
50  return kSUCCESS;
51 }
52 
53 void CbmLitFitTracks::Exec(Option_t* opt) {
54  static Int_t eventNo = 0;
55  std::cout << "CbmLitFitTracks::Exec: eventNo=" << eventNo++ << std::endl;
56 
57  DoFit();
58 }
59 
61 
63  FairRootManager* ioman = FairRootManager::Instance();
64  assert(ioman != NULL);
65 
66  fGlobalTracks = (TClonesArray*) ioman->GetObject("GlobalTrack");
67  fStsTracks = (TClonesArray*) ioman->GetObject("StsTrack");
68  fMuchTracks = (TClonesArray*) ioman->GetObject("MuchTrack");
69  fTrdTracks = (TClonesArray*) ioman->GetObject("TrdTrack");
70  fMuchPixelHits = (TClonesArray*) ioman->GetObject("MuchPixelHit");
71  fMuchStrawHits = (TClonesArray*) ioman->GetObject("MuchStrawHit");
72  fTrdHits = (TClonesArray*) ioman->GetObject("TrdHit");
73 }
74 
76  static Bool_t firstTime = true;
77  static TrackFitterPtr fitter;
78  if (firstTime) {
79  fitter = CbmLitToolFactory::CreateTrackFitter("lit_kalman");
80  firstTime = false;
81  }
82 
83  fFitWithIOWatch.Start(kFALSE);
84 
85  // Convert input data
86  TrackPtrVector ltracks;
87  HitPtrVector lhits;
89  0, ECbmDataType::kTrdHit, fTrdHits, lhits);
91 
92  // Replace first track parameter of the converted tracks with the last STS track parameter
93  Int_t nofTracks = ltracks.size();
94  for (Int_t iTrack = 0; iTrack < nofTracks; iTrack++) {
95  CbmLitTrack* track = ltracks[iTrack];
96  Int_t stsTrackId = track->GetPreviousTrackId();
97  CbmStsTrack* stsTrack =
98  static_cast<CbmStsTrack*>(fStsTracks->At(stsTrackId));
99  CbmTrackParam cbmLPar;
100  cbmLPar.Set(
101  *stsTrack->GetParamLast(), stsTrack->GetTime(), stsTrack->GetTimeError());
102  CbmLitTrackParam lpar;
104  &lpar);
105  track->SetParamFirst(&lpar);
106  track->SetPDG(211);
107  }
108 
109  fFitWatch.Start(kFALSE);
110  for (Int_t iTrack = 0; iTrack < nofTracks; iTrack++) {
111  CbmLitTrack* track = ltracks[iTrack];
112  fitter->Fit(track);
113  }
114  fFitWatch.Stop();
115 
116  // Replace first and last track parameters for the fitted track
117  for (Int_t iTrack = 0; iTrack < nofTracks; iTrack++) {
118  CbmLitTrack* track = ltracks[iTrack];
119  CbmTrack* trdTrack = static_cast<CbmTrack*>(fTrdTracks->At(iTrack));
120  FairTrackParam firstParam, lastParam;
122  track->GetParamFirst(), &firstParam);
124  track->GetParamLast(), &lastParam);
125  trdTrack->SetParamFirst(&firstParam);
126  trdTrack->SetParamLast(&lastParam);
127  }
128 
129  // Clear memory
130  for_each(ltracks.begin(), ltracks.end(), DeleteObject());
131  for_each(lhits.begin(), lhits.end(), DeleteObject());
132  ltracks.clear();
133  lhits.clear();
134 
135  fFitWithIOWatch.Stop();
136 }
137 
139  cout << "CbmLitFitTracks::PrintStopwatchStatistics: " << endl;
140  cout << "fit without IO: counts=" << fFitWatch.Counter()
141  << ", real=" << fFitWatch.RealTime() / fFitWatch.Counter() << "/"
142  << fFitWatch.RealTime()
143  << " s, cpu=" << fFitWatch.CpuTime() / fFitWatch.Counter() << "/"
144  << fFitWatch.CpuTime() << endl;
145  cout << "fit with IO: counts=" << fFitWithIOWatch.Counter()
146  << ", real=" << fFitWithIOWatch.RealTime() / fFitWithIOWatch.Counter()
147  << "/" << fFitWithIOWatch.RealTime()
148  << " s, cpu=" << fFitWithIOWatch.CpuTime() / fFitWithIOWatch.Counter()
149  << "/" << fFitWithIOWatch.CpuTime() << endl;
150 }
ECbmDataType::kTrdHit
@ kTrdHit
CbmTrack::GetParamLast
const FairTrackParam * GetParamLast() const
Definition: CbmTrack.h:62
CbmLitMemoryManagment.h
CbmLitFitTracks::Exec
virtual void Exec(Option_t *opt)
Derived from FairTask.
Definition: CbmLitFitTracks.cxx:53
CbmLitFitTracks::fTrdHits
TClonesArray * fTrdHits
Definition: CbmLitFitTracks.h:62
CbmLitFitTracks::fMuchStrawHits
TClonesArray * fMuchStrawHits
Definition: CbmLitFitTracks.h:64
CbmLitTrackParam
Data class for track parameters.
Definition: CbmLitTrackParam.h:29
CbmLitTrack::SetParamFirst
void SetParamFirst(const CbmLitTrackParam *par)
Definition: CbmLitTrack.h:81
CbmLitToolFactory.h
Tool factory for creation of littrack algorithms.
CbmLitFitTracks.h
Task for testing of standard track fit algorithms.
CbmLitConverter::HitArrayToHitVector
static void HitArrayToHitVector(CbmEvent *event, ECbmDataType hitDataType, const TClonesArray *hits, HitPtrVector &litHits)
Definition: CbmLitConverter.h:315
CbmTrack::SetParamLast
void SetParamLast(const FairTrackParam *par)
Definition: CbmTrack.h:76
CbmTrackParam::Set
void Set(const FairTrackParam &ftp, Double_t time=0., Double_t timeError=0.)
Definition: CbmTrackParam.cxx:12
CbmLitConverterFairTrackParam::CbmLitTrackParamToFairTrackParam
static void CbmLitTrackParamToFairTrackParam(const CbmLitTrackParam *litPar, FairTrackParam *par)
Definition: CbmLitConverterFairTrackParam.h:110
DeleteObject
Definition: CbmLitMemoryManagment.h:5
CbmLitTrack::SetPDG
void SetPDG(Int_t pdg)
Definition: CbmLitTrack.h:80
CbmLitFitTracks::Finish
virtual void Finish()
Derived from FairTask.
Definition: CbmLitFitTracks.cxx:60
CbmLitToolFactory::CreateTrackFitter
static TrackFitterPtr CreateTrackFitter(const string &name)
Create track fit tool by name.
Definition: CbmLitToolFactory.cxx:79
CbmTrack
Definition: CbmTrack.h:32
CbmStsTrack.h
Data class for STS tracks.
CbmLitFitTracks::CbmLitFitTracks
CbmLitFitTracks()
Constructor.
Definition: CbmLitFitTracks.cxx:32
CbmLitTrack::GetPreviousTrackId
Int_t GetPreviousTrackId() const
Definition: CbmLitTrack.h:60
TrackPtrVector
std::vector< CbmTofTrack * > TrackPtrVector
Definition: CbmTofTypes.h:22
CbmLitFitTracks
Definition: CbmLitFitTracks.h:14
CbmTrack.h
CbmLitConverterFairTrackParam.h
CbmLitFitTracks::ReadDataBranches
void ReadDataBranches()
Read data branches.
Definition: CbmLitFitTracks.cxx:62
CbmLitTrack
Base data class for track.
Definition: CbmLitTrack.h:30
TrackFitterPtr
boost::shared_ptr< CbmLitTrackFitter > TrackFitterPtr
Definition: CbmTofPtrTypes.h:24
CbmLitFitTracks::fFitWithIOWatch
TStopwatch fFitWithIOWatch
Definition: CbmLitFitTracks.h:68
CbmLitTrack::GetParamLast
const CbmLitTrackParam * GetParamLast() const
Definition: CbmLitTrack.h:63
CbmLitFitTracks::fTrdTracks
TClonesArray * fTrdTracks
Definition: CbmLitFitTracks.h:60
CbmLitFitTracks::fMuchPixelHits
TClonesArray * fMuchPixelHits
Definition: CbmLitFitTracks.h:63
CbmLitFitTracks::PrintStopwatchStatistics
void PrintStopwatchStatistics()
Print stopwatch statistics.
Definition: CbmLitFitTracks.cxx:138
CbmLitFitTracks::fFitWatch
TStopwatch fFitWatch
Definition: CbmLitFitTracks.h:67
CbmLitTrack::GetParamFirst
const CbmLitTrackParam * GetParamFirst() const
Definition: CbmLitTrack.h:62
CbmTrackParam
Definition: CbmTrackParam.h:22
CbmLitTypes.h
Typedefs for data structures used in littrack.
CbmLitFitTracks::fGlobalTracks
TClonesArray * fGlobalTracks
Definition: CbmLitFitTracks.h:58
CbmLitConverter.h
CbmLitTrack.h
Base data class for track.
CbmTrack::SetParamFirst
void SetParamFirst(const FairTrackParam *par)
Definition: CbmTrack.h:75
CbmTrack::GetTime
Double_t GetTime() const
Definition: CbmTrack.h:64
CbmLitFitTracks::DoFit
void DoFit()
Performs track fit.
Definition: CbmLitFitTracks.cxx:75
CbmLitFitTracks::~CbmLitFitTracks
virtual ~CbmLitFitTracks()
Destructor.
Definition: CbmLitFitTracks.cxx:42
CbmLitPtrTypes.h
Typedefs for algorithm interfaces.
CbmStsTrack
Definition: CbmStsTrack.h:37
CbmTrack::GetTimeError
Double_t GetTimeError() const
Definition: CbmTrack.h:65
CbmLitFitTracks::fStsTracks
TClonesArray * fStsTracks
Definition: CbmLitFitTracks.h:59
ClassImp
ClassImp(CbmLitFitTracks)
CbmLitFitTracks::fMuchTracks
TClonesArray * fMuchTracks
Definition: CbmLitFitTracks.h:61
CbmLitFitTracks::Init
virtual InitStatus Init()
Derived from FairTask.
Definition: CbmLitFitTracks.cxx:44
CbmLitConverterFairTrackParam::FairTrackParamToCbmLitTrackParam
static void FairTrackParamToCbmLitTrackParam(const FairTrackParam *par, CbmLitTrackParam *litPar)
Definition: CbmLitConverterFairTrackParam.h:40
HitPtrVector
std::vector< CbmTofHit * > HitPtrVector
Definition: CbmTofTypes.h:14
CbmLitConverter::CbmTrackArrayToCbmLitTrackArray
static void CbmTrackArrayToCbmLitTrackArray(const TClonesArray *tracks, const HitPtrVector &lhits, TrackPtrVector &ltracks)
Definition: CbmLitConverter.h:163