LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
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 <iostream>
24 
25 //ClassImp(GFTrackCand)
26 
27 genf::GFTrackCand::GFTrackCand():fCurv(0),fDip(0),fInv(false), fQoverpSeed(0.),fMcTrackId(-1){}
28 
30 
31 genf::GFTrackCand::GFTrackCand(double curv, double dip, double inv, std::vector<unsigned int> detIDs, std::vector<unsigned int> hitIDs)
32  : fDetId(detIDs),fHitId(hitIDs),fCurv(curv), fDip(dip), fInv(inv),fQoverpSeed(0.), fMcTrackId(-1)
33 {
34  if (fDetId.size() != fHitId.size())
35  throw GFException("genf::GFTrackCand::GFTrackCand(): hit/det size mismatch", __LINE__, __FILE__).setFatal();
36  fRho.resize(fDetId.size(),0.);
37 }
38 genf::GFTrackCand::GFTrackCand(double curv, double dip, double inv, std::vector<unsigned int> detIDs, std::vector<unsigned int> hitIDs,std::vector<double> rhos)
39  : fDetId(detIDs),fHitId(hitIDs),fRho(rhos),fCurv(curv), fDip(dip), fInv(inv),fQoverpSeed(0.), fMcTrackId(-1)
40 {
41  if (fDetId.size() != fHitId.size())
42  throw GFException("genf::GFTrackCand::GFTrackCand(): hit/det size mismatch", __LINE__, __FILE__).setFatal();
43  if (fDetId.size() != fHitId.size())
44  throw GFException("genf::GFTrackCand::GFTrackCand(): rho/det size mismatch", __LINE__, __FILE__).setFatal();
45 }
46 
47 void
48 genf::GFTrackCand::addHit(unsigned int detId, unsigned int hitId, double rho, unsigned int planeId)
49 {
50  fDetId.push_back(detId);
51  fHitId.push_back(hitId);
52  fPlaneId.push_back(planeId);
53  fRho.push_back(rho);
54 }
55 
56 std::vector<unsigned int>
58  if(detId<0){ // return hits from all detectors
59  return fHitId;
60  }
61  else {
62  std::vector<unsigned int> result;
63  unsigned int n=fHitId.size();
64  for(unsigned int i=0;i<n;++i){
65  if(fDetId[i]==(unsigned int)detId)result.push_back(fHitId[i]);
66  }
67  return result;
68  }
69 }
70 
71 void
73 {
74  fDetId.clear();fHitId.clear();
75 }
76 
77 bool genf::GFTrackCand::HitInTrack(unsigned int detId, unsigned int hitId)
78 {
79  for (unsigned int i = 0; i < fDetId.size(); i++){
80  if (detId == fDetId[i])
81  if (hitId == fHitId[i])
82  return true;
83  }
84  return false;
85 }
86 
87 bool genf::operator== (const GFTrackCand& lhs, const GFTrackCand& rhs){
88  if(lhs.getNHits()!=rhs.getNHits()) return false;
89  bool result=std::equal(lhs.fDetId.begin(),lhs.fDetId.end(),rhs.fDetId.begin());
90  result &=std::equal(lhs.fHitId.begin(),lhs.fHitId.end(),rhs.fHitId.begin());
91  return result;
92 }
93 
94 void genf::GFTrackCand::Print(std::ostream& out /* = std::cout */) const {
95  out << "======== GFTrackCand::print ========";
96  if(fMcTrackId>=0) out << "\nmcTrackId=" << fMcTrackId;
97  out << "\nseed values for pos,direction, and q/p: " << std::endl;
100  out << "q/p=" << fQoverpSeed << std::endl;
101  if (fDetId.size() !=fHitId.size())
102  throw std::runtime_error("genf::GFTrackCand::GFTrackCand(): hit/det size mismatch");
103  out << "detId|hitId|rho ";
104  for(unsigned int i=0;i<fDetId.size();++i)
105  out << fDetId.at(i) << "|" << fHitId.at(i) << "|" << fRho.at(i) << " ";
106  out << std::endl;
107 }
108 
110  unsigned int detId,hitId;
111  double rho;
112  for(unsigned int i=0;i<rhs.getNHits();++i){
113  rhs.getHit(i,detId,hitId,rho);
114  addHit(detId,hitId,rho);
115  }
116 
117 
118 }
void Print(std::ostream &out=std::cout) const
Definition: GFTrackCand.cxx:94
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:77
bool operator==(const genf::GFDetPlane &, const genf::GFDetPlane &)
Definition: GFDetPlane.cxx:265
std::vector< unsigned int > fPlaneId
Definition: GFTrackCand.h:178
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:84
unsigned int getNHits() const
Definition: GFTrackCand.h:116
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
Definition: GFException.h:50
std::vector< unsigned int > GetHitIDs(int detId=-1)
Definition: GFTrackCand.cxx:57
void PrintROOTobject(std::ostream &, const ROOTOBJ &)
Small utility functions which print some ROOT objects into an output stream.
Definition: GFException.h:129
GFException & setFatal(bool b=true)
set fatal flag. if this is true, the fit stops for this current track repr.
Definition: GFException.h:80
void addHit(unsigned int detId, unsigned int hitId, double rho=0., unsigned int planeId=0)
Definition: GFTrackCand.cxx:48
Char_t n[5]
std::vector< unsigned int > fDetId
Definition: GFTrackCand.h:176
std::vector< unsigned int > fHitId
Definition: GFTrackCand.h:177
std::vector< double > fRho
Definition: GFTrackCand.h:179