All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GFTrackCand.cxx
Go to the documentation of this file.
1 /* Copyright 2008-2010, Technische Universitaet Muenchen,
2  Authors: Christian Hoeppner & Sebastian Neubert
3 
4  This file is part of GENFIT.
5 
6  GENFIT is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  GENFIT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
18 */
21 
22 #include <algorithm>
23 #include <ostream>
24 #include <vector>
25 
26 //ClassImp(GFTrackCand)
27 
28 genf::GFTrackCand::GFTrackCand():fCurv(0),fDip(0),fInv(false), fQoverpSeed(0.),fMcTrackId(-1){}
29 
31 
32 genf::GFTrackCand::GFTrackCand(double curv, double dip, double inv, std::vector<unsigned int> detIDs, std::vector<unsigned int> hitIDs)
33  : fDetId(detIDs),fHitId(hitIDs),fCurv(curv), fDip(dip), fInv(inv),fQoverpSeed(0.), fMcTrackId(-1)
34 {
35  if (fDetId.size() != fHitId.size())
36  throw GFException("genf::GFTrackCand::GFTrackCand(): hit/det size mismatch", __LINE__, __FILE__).setFatal();
37  fRho.resize(fDetId.size(),0.);
38 }
39 genf::GFTrackCand::GFTrackCand(double curv, double dip, double inv, std::vector<unsigned int> detIDs, std::vector<unsigned int> hitIDs,std::vector<double> rhos)
40  : fDetId(detIDs),fHitId(hitIDs),fRho(rhos),fCurv(curv), fDip(dip), fInv(inv),fQoverpSeed(0.), fMcTrackId(-1)
41 {
42  if (fDetId.size() != fHitId.size())
43  throw GFException("genf::GFTrackCand::GFTrackCand(): hit/det size mismatch", __LINE__, __FILE__).setFatal();
44  if (fDetId.size() != fHitId.size())
45  throw GFException("genf::GFTrackCand::GFTrackCand(): rho/det size mismatch", __LINE__, __FILE__).setFatal();
46 }
47 
48 void
49 genf::GFTrackCand::addHit(unsigned int detId, unsigned int hitId, double rho, unsigned int planeId)
50 {
51  fDetId.push_back(detId);
52  fHitId.push_back(hitId);
53  fPlaneId.push_back(planeId);
54  fRho.push_back(rho);
55 }
56 
57 std::vector<unsigned int>
59  if(detId<0){ // return hits from all detectors
60  return fHitId;
61  }
62  else {
63  std::vector<unsigned int> result;
64  unsigned int n=fHitId.size();
65  for(unsigned int i=0;i<n;++i){
66  if(fDetId[i]==(unsigned int)detId)result.push_back(fHitId[i]);
67  }
68  return result;
69  }
70 }
71 
72 void
74 {
75  fDetId.clear();fHitId.clear();
76 }
77 
78 bool genf::GFTrackCand::HitInTrack(unsigned int detId, unsigned int hitId)
79 {
80  for (unsigned int i = 0; i < fDetId.size(); i++){
81  if (detId == fDetId[i])
82  if (hitId == fHitId[i])
83  return true;
84  }
85  return false;
86 }
87 
88 bool genf::operator== (const GFTrackCand& lhs, const GFTrackCand& rhs){
89  if(lhs.getNHits()!=rhs.getNHits()) return false;
90  bool result=std::equal(lhs.fDetId.begin(),lhs.fDetId.end(),rhs.fDetId.begin());
91  result &=std::equal(lhs.fHitId.begin(),lhs.fHitId.end(),rhs.fHitId.begin());
92  return result;
93 }
94 
95 void genf::GFTrackCand::Print(std::ostream& out /* = std::cout */) const {
96  out << "======== GFTrackCand::print ========";
97  if(fMcTrackId>=0) out << "\nmcTrackId=" << fMcTrackId;
98  out << "\nseed values for pos,direction, and q/p: " << std::endl;
99  PrintROOTobject(out, fPosSeed);
100  PrintROOTobject(out, fDirSeed);
101  out << "q/p=" << fQoverpSeed << std::endl;
102  if (fDetId.size() !=fHitId.size())
103  throw std::runtime_error("genf::GFTrackCand::GFTrackCand(): hit/det size mismatch");
104  out << "detId|hitId|rho ";
105  for(unsigned int i=0;i<fDetId.size();++i)
106  out << fDetId.at(i) << "|" << fHitId.at(i) << "|" << fRho.at(i) << " ";
107  out << std::endl;
108 }
109 
111  unsigned int detId,hitId;
112  double rho;
113  for(unsigned int i=0;i<rhs.getNHits();++i){
114  rhs.getHit(i,detId,hitId,rho);
115  addHit(detId,hitId,rho);
116  }
117 
118 
119 }
void Print(std::ostream &out=std::cout) const
Definition: GFTrackCand.cxx:95
void append(const GFTrackCand &)
bool HitInTrack(unsigned int detId, unsigned int hitId)
Test if hit already is part of this track candidate.
Definition: GFTrackCand.cxx:78
bool operator==(const genf::GFDetPlane &, const genf::GFDetPlane &)
Definition: GFDetPlane.cxx:270
bool equal(double a, double b)
Comparison tolerance, in centimeters.
void getHit(unsigned int i, unsigned int &detId, unsigned int &hitId) const
Get detector ID and cluster index (hitId) for hit number i.
Definition: GFTrackCand.h:85
unsigned int getNHits() const
Definition: GFTrackCand.h:117
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
Definition: GFException.h:48
std::vector< unsigned int > GetHitIDs(int detId=-1)
Definition: GFTrackCand.cxx:58
void PrintROOTobject(std::ostream &, const ROOTOBJ &)
Small utility functions which print some ROOT objects into an output stream.
Definition: GFException.h:127
GFException & setFatal(bool b=true)
set fatal flag. if this is true, the fit stops for this current track repr.
Definition: GFException.h:78
void addHit(unsigned int detId, unsigned int hitId, double rho=0., unsigned int planeId=0)
Definition: GFTrackCand.cxx:49
std::vector< unsigned int > fDetId
Definition: GFTrackCand.h:177
std::vector< unsigned int > fHitId
Definition: GFTrackCand.h:178
std::vector< double > fRho
Definition: GFTrackCand.h:180