FairRoot/PandaRoot
PndTrackCand.cxx
Go to the documentation of this file.
1 //-----------------------------------------------------------
2 // File and Version Information:
3 // $Id$
4 //
5 // Description:
6 // Implementation of class PndTrackCand
7 // see PndTrackCand.hh for details
8 //
9 // Environment:
10 // Software developed for the PANDA Detector at FAIR.
11 //
12 // Author List:
13 // Tobias Stockmanns (IKP - Juelich) during the Panda Meeting 03/09
14 //
15 //
16 //-----------------------------------------------------------
17 
18 // Panda Headers ----------------------
19 
20 // This Class' Header ------------------
21 #include "PndTrackCand.h"
22 #include "FairRootManager.h"
23 #include "FairEventHeader.h"
24 #include "TClonesArray.h"
25 
26 #include <algorithm>
27 #include "math.h"
28 
30 
31 PndTrackCand::PndTrackCand() : fHitId(), sorted(false), fMcTrackId(-1),fVerbose(0){}
32 
34 
35 void
36 PndTrackCand::AddHit(UInt_t detId, UInt_t hitId, Double_t rho)
37 {
38  fHitId.push_back(PndTrackCandHit(detId, hitId, rho));
39  sorted = false;
40  AddLink(FairLink(detId, hitId));
41 // CalcTimeStamp();
42 }
43 
44 void PndTrackCand::AddHit(TString branchName, UInt_t hitId, Double_t rho)
45 {
46  FairRootManager* ioman = FairRootManager::Instance();
47  UInt_t detId = ioman->GetBranchId(branchName);
48  AddHit(detId, hitId, rho);
49 }
50 
51 void PndTrackCand::AddHit(FairLink link, Double_t rho)
52 {
53  fHitId.push_back(PndTrackCandHit(link, rho));
54  sorted = false;
55  AddLink(link);
56 }
57 
58 
60 {
61  fHitId.clear();
62  ResetLinks();
63 }
64 
65 int PndTrackCand::HitInTrack(UInt_t detId, UInt_t hitId) const
66 {
67  PndTrackCandHit test(detId, hitId, 0.);
68  for (UInt_t i = 0; i < fHitId.size(); i++){
69  if(fHitId[i] == test)
70  return i;
71  }
72  return -1;
73 }
74 
75 void PndTrackCand::DeleteHit(UInt_t detId, UInt_t hitId)
76 {
77  int ind = HitInTrack(detId, hitId);
78  fHitId.erase(fHitId.begin()+ind);
79 
80  //Int_t det = detId;
81  //Int_t hit = hitId;
82  //DeleteLink(det, hit);
83 }
84 
85 UInt_t PndTrackCand::GetNHitsDet(Int_t detId)
86 {
87  // Function to count the number of hits from the same detId
88  UInt_t detCounts = 0;
89 
90  for (UInt_t ihit = 0; ihit<fHitId.size(); ihit++)
91  {
92  PndTrackCandHit candhit = GetSortedHit(ihit);
93  if (candhit.GetDetId() == detId) detCounts++;
94  }
95 
96  return detCounts;
97 }
98 
100 {
101  std::sort(fHitId.begin(), fHitId.end());
102  sorted = true;
103 }
104 
105 std::vector<PndTrackCandHit> PndTrackCand::GetSortedHits()
106 {
107  if (sorted == false)
108  Sort();
109  return fHitId;
110 }
111 
113 {
114  Double_t timestamp = 0;
115  Double_t timestamperror = 0;
116  Int_t counts = 0;
117  for (int i = 0; i < GetNLinks(); i++){
118  FairLink myLink = GetLink(i);
119  Int_t type = myLink.GetType();
120 
121  if (fVerbose > 1){
122  std::cout << "Links: " << myLink << std::endl;
123  }
124 
125  if (type > -1){
126  TString branchName = FairRootManager::Instance()->GetBranchName(type);
127  if (branchName.Contains("Hit") == kFALSE) continue;
128 
129  TClonesArray* myArray = (TClonesArray*)FairRootManager::Instance()->GetObject(branchName);
130  if (myArray != NULL){
131  FairTimeStamp* myData = (FairTimeStamp*)(FairRootManager::Instance()->GetCloneOfLinkData(myLink));
132  if (myData != NULL){
133  Double_t var = myData->GetTimeStampError() * myData->GetTimeStampError();
134  timestamp += myData->GetTimeStamp()/var;
135  timestamperror += 1/var;
136  counts++;
137  delete myData;
138  }
139  else {
140  std::cout << "Data not found: " << FairRootManager::Instance()->GetBranchName(myLink.GetType()) << "/" << myLink << std::endl;
141  }
142  }
143  else {
144  // std::cout << "Array not found: " << ioman->GetBranchName(myLink.GetType()) << std::endl;
145  }
146  }
147  }
148  if (timestamperror > 0){
149  //std::cout << "TrackTimeStamp: " << timestamp/timestamperror << " +/- " << sqrt(timestamperror/counts) << " counts " << counts << std::endl;
150  SetTimeStamp(timestamp/timestamperror);
151  SetTimeStampError(sqrt(timestamperror/counts));
152  }
153 }
154 
156  if(rhs.fHitId.size()!=fHitId.size()) return false;
157  for(unsigned int i=0;i<fHitId.size();++i){
158  if(fHitId.at(i) != rhs.fHitId.at(i) ) return false;
159  }
160  return true;
161 }
162 
163 
164 void PndTrackCand::Print() const {
165  std::cout << "=========== PndTrackCand::Print() ==========" << std::endl;
166  if(fMcTrackId>=0) std::cout << "McTrackId=" << fMcTrackId << std::endl;
167  for(unsigned int i=0;i<fHitId.size();++i){
168  fHitId.at(i).Print();
169  }
170 }
UInt_t GetNHitsDet(Int_t detId)
int fVerbose
Definition: poormantracks.C:24
void Print() const
Int_t i
Definition: run_full.C:25
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
std::vector< PndTrackCandHit > GetSortedHits()
PndTrackCandHit GetSortedHit(UInt_t i)
Definition: PndTrackCand.h:54
std::vector< PndTrackCandHit > fHitId
first index is detId, second index is hit Id
Definition: PndTrackCand.h:93
bool operator==(const PndTrackCand &rhs)
Int_t fVerbose
Definition: PndTrackCand.h:96
void AddHit(UInt_t detId, UInt_t hitId, Double_t rho)
Double_t
void DeleteHit(UInt_t detId, UInt_t hitId)
void CalcTimeStamp()
void ResetLinks()
ClassImp(PndAnaContFact)
Int_t GetDetId() const
Int_t HitInTrack(UInt_t detId, UInt_t hitId) const