LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 <ostream>
24 #include <vector>
25 
26 //ClassImp(GFTrackCand)
27 
28 genf::GFTrackCand::GFTrackCand() : fCurv(0), fDip(0), fInv(false), fQoverpSeed(0.), fMcTrackId(-1)
29 {}
30 
32 
34  double dip,
35  double inv,
36  std::vector<unsigned int> detIDs,
37  std::vector<unsigned int> hitIDs)
38  : fDetId(detIDs)
39  , fHitId(hitIDs)
40  , fCurv(curv)
41  , fDip(dip)
42  , fInv(inv)
43  , fQoverpSeed(0.)
44  , fMcTrackId(-1)
45 {
46  if (fDetId.size() != fHitId.size())
47  throw GFException("genf::GFTrackCand::GFTrackCand(): hit/det size mismatch", __LINE__, __FILE__)
48  .setFatal();
49  fRho.resize(fDetId.size(), 0.);
50 }
52  double dip,
53  double inv,
54  std::vector<unsigned int> detIDs,
55  std::vector<unsigned int> hitIDs,
56  std::vector<double> rhos)
57  : fDetId(detIDs)
58  , fHitId(hitIDs)
59  , fRho(rhos)
60  , fCurv(curv)
61  , fDip(dip)
62  , fInv(inv)
63  , fQoverpSeed(0.)
64  , fMcTrackId(-1)
65 {
66  if (fDetId.size() != fHitId.size())
67  throw GFException("genf::GFTrackCand::GFTrackCand(): hit/det size mismatch", __LINE__, __FILE__)
68  .setFatal();
69  if (fDetId.size() != fHitId.size())
70  throw GFException("genf::GFTrackCand::GFTrackCand(): rho/det size mismatch", __LINE__, __FILE__)
71  .setFatal();
72 }
73 
74 void genf::GFTrackCand::addHit(unsigned int detId,
75  unsigned int hitId,
76  double rho,
77  unsigned int planeId)
78 {
79  fDetId.push_back(detId);
80  fHitId.push_back(hitId);
81  fPlaneId.push_back(planeId);
82  fRho.push_back(rho);
83 }
84 
85 std::vector<unsigned int> genf::GFTrackCand::GetHitIDs(int detId)
86 {
87  if (detId < 0) { // return hits from all detectors
88  return fHitId;
89  }
90  else {
91  std::vector<unsigned int> result;
92  unsigned int n = fHitId.size();
93  for (unsigned int i = 0; i < n; ++i) {
94  if (fDetId[i] == (unsigned int)detId) result.push_back(fHitId[i]);
95  }
96  return result;
97  }
98 }
99 
101 {
102  fDetId.clear();
103  fHitId.clear();
104 }
105 
106 bool genf::GFTrackCand::HitInTrack(unsigned int detId, unsigned int hitId)
107 {
108  for (unsigned int i = 0; i < fDetId.size(); i++) {
109  if (detId == fDetId[i])
110  if (hitId == fHitId[i]) return true;
111  }
112  return false;
113 }
114 
115 bool genf::operator==(const GFTrackCand& lhs, const GFTrackCand& rhs)
116 {
117  if (lhs.getNHits() != rhs.getNHits()) return false;
118  bool result = std::equal(lhs.fDetId.begin(), lhs.fDetId.end(), rhs.fDetId.begin());
119  result &= std::equal(lhs.fHitId.begin(), lhs.fHitId.end(), rhs.fHitId.begin());
120  return result;
121 }
122 
123 void genf::GFTrackCand::Print(std::ostream& out /* = std::cout */) const
124 {
125  out << "======== GFTrackCand::print ========";
126  if (fMcTrackId >= 0) out << "\nmcTrackId=" << fMcTrackId;
127  out << "\nseed values for pos,direction, and q/p: " << std::endl;
130  out << "q/p=" << fQoverpSeed << std::endl;
131  if (fDetId.size() != fHitId.size())
132  throw std::runtime_error("genf::GFTrackCand::GFTrackCand(): hit/det size mismatch");
133  out << "detId|hitId|rho ";
134  for (unsigned int i = 0; i < fDetId.size(); ++i)
135  out << fDetId.at(i) << "|" << fHitId.at(i) << "|" << fRho.at(i) << " ";
136  out << std::endl;
137 }
138 
140 {
141  unsigned int detId, hitId;
142  double rho;
143  for (unsigned int i = 0; i < rhs.getNHits(); ++i) {
144  rhs.getHit(i, detId, hitId, rho);
145  addHit(detId, hitId, rho);
146  }
147 }
void Print(std::ostream &out=std::cout) const
void append(const GFTrackCand &)
bool HitInTrack(unsigned int detId, unsigned int hitId)
Test if hit already is part of this track candidate.
bool operator==(const genf::GFDetPlane &, const genf::GFDetPlane &)
Definition: GFDetPlane.cxx:249
std::vector< unsigned int > fPlaneId
Definition: GFTrackCand.h:203
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:93
unsigned int getNHits() const
Definition: GFTrackCand.h:134
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
Definition: GFException.h:47
std::vector< unsigned int > GetHitIDs(int detId=-1)
Definition: GFTrackCand.cxx:85
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:75
void addHit(unsigned int detId, unsigned int hitId, double rho=0., unsigned int planeId=0)
Definition: GFTrackCand.cxx:74
Char_t n[5]
std::vector< unsigned int > fDetId
Definition: GFTrackCand.h:201
std::vector< unsigned int > fHitId
Definition: GFTrackCand.h:202
std::vector< double > fRho
Definition: GFTrackCand.h:204