EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PndTrackCand.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PndTrackCand.cxx
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 
25 #include <algorithm>
26 #include "math.h"
27 
29 
30 PndTrackCand::PndTrackCand():sorted(false), fMcTrackId(-1),/*fQoverPseed(0.)*/fChargeSeed(0.0),fVerbose(0){}
31 
33 
34 void
35 PndTrackCand::AddHit(UInt_t detId, UInt_t hitId, Double_t rho)
36 {
37  fHitId.push_back(PndTrackCandHit(detId, hitId, rho));
38  sorted = false;
39  AddLink(FairLink(detId, hitId));
40 // CalcTimeStamp();
41 }
42 
43 void PndTrackCand::AddHit(TString branchName, UInt_t hitId, Double_t rho)
44 {
46  UInt_t detId = ioman->GetBranchId(branchName);
47  AddHit(detId, hitId, rho);
48 }
49 
50 void PndTrackCand::AddHit(FairLink link, Double_t rho)
51 {
52  fHitId.push_back(PndTrackCandHit(link.GetType(), link.GetIndex(), rho));
53  sorted = false;
54  AddLink(link);
55 }
56 
57 
59 {
60  fHitId.clear();
62 }
63 
64 int PndTrackCand::HitInTrack(UInt_t detId, UInt_t hitId)
65 {
66  PndTrackCandHit test(detId, hitId, 0.);
67  for (UInt_t i = 0; i < fHitId.size(); i++){
68  if(fHitId[i] == test)
69  return i;
70  }
71  return -1;
72 }
73 
74 void PndTrackCand::DeleteHit(UInt_t detId, UInt_t hitId)
75 {
76  int ind = HitInTrack(detId, hitId);
77  fHitId.erase(fHitId.begin()+ind);
78 
79  //Int_t det = detId;
80  //Int_t hit = hitId;
81  //DeleteLink(det, hit);
82 }
83 
84 UInt_t PndTrackCand::GetNHitsDet(UInt_t detId)
85 {
86  // Function to count the number of hits from the same detId
87  Int_t detCounts = 0;
88 
89  for (Int_t ihit = 0; ihit<fHitId.size(); ihit++)
90  {
92  if (candhit.GetDetId() == detId) detCounts++;
93  }
94 
95  return detCounts;
96 }
97 
99 {
100  std::sort(fHitId.begin(), fHitId.end());
101  sorted = true;
102 }
103 
104 std::vector<PndTrackCandHit> &PndTrackCand::_GetSortedHits()
105 {
106  if (sorted == false)
107  Sort();
108  return fHitId;
109 }
110 
112 {
113  Double_t timestamp = 0;
114  Double_t timestamperror = 0;
115  Int_t counts = 0;
116  for (int i = 0; i < GetNLinks(); i++){
117  FairLink myLink = GetLink(i);
118  Int_t type = myLink.GetType();
119 
120  if (fVerbose > 1){
121  std::cout << "Links: " << myLink << std::endl;
122  }
123 
124  if (type > -1){
125  TString branchName = FairRootManager::Instance()->GetBranchName(type);
126  //std::cout << "BranchName: " << branchName.Data() << std::endl;
127 
128  TClonesArray* myArray = (TClonesArray*)FairRootManager::Instance()->GetObject(branchName);
129  if (myArray > 0){
131  if (myData > 0){
132  Double_t var = myData->GetTimeStampError() * myData->GetTimeStampError();
133  timestamp += myData->GetTimeStamp()/var;
134  timestamperror += 1/var;
135  counts++;
136  delete myData;
137  }
138  else {
139  std::cout << "Data not found: " << FairRootManager::Instance()->GetBranchName(myLink.GetType()) << "/" << myLink.GetIndex() << std::endl;
140  }
141  }
142  else {
143  // std::cout << "Array not found: " << ioman->GetBranchName(myLink.GetType()) << std::endl;
144  }
145  }
146  }
147  if (timestamperror > 0){
148  //std::cout << "TrackTimeStamp: " << timestamp/timestamperror << " +/- " << sqrt(timestamperror/counts) << " counts " << counts << std::endl;
149  SetTimeStamp(timestamp/timestamperror);
150  SetTimeStampError(sqrt(timestamperror/counts));
151  }
152 }
153 
155  if(rhs.fHitId.size()!=fHitId.size()) return false;
156  for(unsigned int i=0;i<fHitId.size();++i){
157  if(fHitId.at(i) != rhs.fHitId.at(i) ) return false;
158  }
159  return true;
160 }
161 
162 
164  std::cout << "=========== PndTrackCand::Print() ==========" << std::endl;
165  if(fMcTrackId>=0) std::cout << "McTrackId=" << fMcTrackId << std::endl;
166  std::cout << "seed values for pos,direction, and q/p: " << std::endl;
167  fPosSeed.Print();
168  fMomSeed.Print();
169  //std::cout << "q/p=" << fQoverPseed << std::endl;
170  for(unsigned int i=0;i<fHitId.size();++i){
171  fHitId.at(i).Print();
172  }
173 }