SND@LHC Software
Loading...
Searching...
No Matches
TrackCand.cc
Go to the documentation of this file.
1/* Copyright 2008-2010, Technische Universitaet Muenchen,
2 Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch
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 */
19
20#include "TrackCand.h"
21#include "Exception.h"
22#include "TDatabasePDG.h"
23
24#include <algorithm>
25#include <iostream>
26#include <utility>
27
28namespace genfit {
29
30
32 mcTrackId_(-1),
33 pdg_(0),
34 state6D_(6),
35 cov6D_(6),
36 q_(0)
37{
38 ;
39}
40
42 for (unsigned int i=0; i<hits_.size(); ++i) {
43 delete hits_[i];
44 }
45 hits_.clear();
46}
47
48
50 TObject(other),
51 mcTrackId_(other.mcTrackId_),
52 pdg_(0),
53 state6D_(other.state6D_),
54 cov6D_(other.cov6D_),
55 q_(other.q_)
56{
57 // deep copy
58 hits_.reserve(other.hits_.size());
59 for (unsigned int i=0; i<other.hits_.size(); ++i) {
60 hits_.push_back( (other.hits_[i])->clone() );
61 }
62
63 if (other.pdg_ != 0)
64 setPdgCode(other.pdg_);
65}
66
68 swap(other);
69 return *this;
70}
71
72
74 // by swapping the members of two classes,
75 // the two classes are effectively swapped
76 std::swap(this->hits_, other.hits_);
77 std::swap(this->mcTrackId_, other.mcTrackId_);
78 std::swap(this->pdg_, other.pdg_);
79 std::swap(this->state6D_, other.state6D_);
80 std::swap(this->cov6D_, other.cov6D_);
81 std::swap(this->q_, other.q_);
82}
83
84
86 if (i < 0)
87 i += hits_.size();
88
89 return hits_.at(i);
90}
91
92
93void TrackCand::getHit(int i, int& detId, int& hitId) const {
94 if (i < 0)
95 i += hits_.size();
96
97 detId = hits_.at(i)->getDetId();
98 hitId = hits_[i]->getHitId();
99}
100
101
102void TrackCand::getHit(int i, int& detId, int& hitId, double& sortingParameter) const {
103 if (i < 0)
104 i += hits_.size();
105
106 detId = hits_.at(i)->getDetId();
107 hitId = hits_[i]->getHitId();
108 sortingParameter = hits_[i]->getSortingParameter();
109}
110
111
112void TrackCand::getHitWithPlane(int i, int& detId, int& hitId, int& planeId) const {
113 if (i < 0)
114 i += hits_.size();
115
116 detId = hits_.at(i)->getDetId();
117 hitId = hits_[i]->getHitId();
118 planeId = hits_[i]->getPlaneId();
119}
120
121
122void TrackCand::addHit(int detId, int hitId, int planeId, double sortingParameter)
123{
124 hits_.push_back(new TrackCandHit(detId, hitId, planeId, sortingParameter));
125}
126
127std::vector<int> TrackCand::getHitIDs(int detId) const {
128 std::vector<int> result;
129 for(unsigned int i=0; i<hits_.size(); ++i){
130 if(detId==-2 || hits_[i]->getDetId() == detId) {
131 result.push_back(hits_[i]->getHitId());
132 }
133 }
134 return result;
135}
136
137std::vector<int> TrackCand::getDetIDs() const {
138 std::vector<int> result;
139 for(unsigned int i=0; i<hits_.size(); ++i){
140 result.push_back(hits_[i]->getDetId());
141 }
142 return result;
143}
144
145std::vector<double> TrackCand::getSortingParameters() const {
146 std::vector<double> result;
147 for(unsigned int i=0; i<hits_.size(); ++i){
148 result.push_back(hits_[i]->getSortingParameter());
149 }
150 return result;
151}
152
153std::set<int> TrackCand::getUniqueDetIDs() const {
154 std::set<int> retVal;
155 for (unsigned int i = 0; i < hits_.size(); ++i) {
156 retVal.insert(hits_[i]->getDetId());
157 }
158 return retVal;
159}
160
161
162void TrackCand::setPdgCode(int pdgCode) {
163 pdg_ = pdgCode;
164 TParticlePDG* part = TDatabasePDG::Instance()->GetParticle(pdg_);
165 q_ = part->Charge() / (3.);
166}
167
168
170{
171 for (unsigned int i=0; i<hits_.size(); ++i) {
172 delete hits_[i];
173 }
174 hits_.clear();
175}
176
177
178bool TrackCand::hitInTrack(int detId, int hitId) const
179{
180 for (unsigned int i = 0; i < hits_.size(); ++i){
181 if (detId == hits_[i]->getDetId() && hitId == hits_[i]->getHitId())
182 return true;
183 }
184 return false;
185}
186
187
188bool operator== (const TrackCand& lhs, const TrackCand& rhs){
189 if(lhs.getNHits() != rhs.getNHits()) return false;
190 for (unsigned int i = 0; i < lhs.getNHits(); ++i){
191 if (lhs.getHit(i) != rhs.getHit(i)) return false;
192 }
193 return true;
194}
195
196
197void TrackCand::Print(const Option_t* option) const {
198 std::cout << "======== TrackCand::print ========\n";
199 std::cout << "mcTrackId=" << mcTrackId_ << "\n";
200 std::cout << "seed values for 6D state: \n";
201 state6D_.Print(option);
202 std::cout << "q" << q_ << "\n";
203 std::cout << "PDG code= " << pdg_ << "\n";
204 for(unsigned int i=0; i<hits_.size(); ++i){
205 hits_[i]->Print();
206 }
207}
208
209
211 for(unsigned int i=0; i<rhs.getNHits(); ++i){
212 addHit(rhs.getHit(i)->clone());
213 }
214}
215
216
218 std::stable_sort(hits_.begin(), hits_.end(), compareTrackCandHits);
219}
220
221
222void TrackCand::sortHits(const std::vector<unsigned int>& indices){
223
224 const unsigned int nHits(getNHits());
225 if (indices.size() != nHits){
226 abort();
227 Exception exc("TrackCand::sortHits ==> Size of indices != number of hits!",__LINE__,__FILE__);
228 throw exc;
229 }
230
231 //these containers will hold the sorted results. They are created to avoid probably slower in-place sorting
232 std::vector<TrackCandHit*> sortedHits(nHits);
233 for (unsigned int i=0; i<nHits; ++i){
234 sortedHits[i] = hits_[indices[i]];
235 }
236 //write the changes back to the private data members:
237 hits_ = sortedHits;
238}
239
240
241void TrackCand::set6DSeed(const TVectorD& state6D, const double charge) {
242 if (pdg_ != 0 && q_ != charge)
243 pdg_ = -pdg_;
244 q_ = charge;
245 state6D_ = state6D;
246}
247
248void TrackCand::set6DSeedAndPdgCode(const TVectorD& state6D, const int pdgCode) {
249 setPdgCode(pdgCode);
250 state6D_ = state6D;
251}
252
253void TrackCand::setPosMomSeed(const TVector3& pos, const TVector3& mom, const double charge) {
254 if (pdg_ != 0 && q_ != charge)
255 pdg_ = -pdg_;
256 q_ = charge;
257 state6D_[0] = pos[0]; state6D_[1] = pos[1]; state6D_[2] = pos[2];
258 state6D_[3] = mom[0]; state6D_[4] = mom[1]; state6D_[5] = mom[2];
259}
260
261void TrackCand::setPosMomSeedAndPdgCode(const TVector3& pos, const TVector3& mom, const int pdgCode) {
262 setPdgCode(pdgCode);
263 state6D_[0] = pos[0]; state6D_[1] = pos[1]; state6D_[2] = pos[2];
264 state6D_[3] = mom[0]; state6D_[4] = mom[1]; state6D_[5] = mom[2];
265}
266
267
268} /* End of namespace genfit */
Exception class for error handling in GENFIT (provides storage for diagnostic information)
Definition Exception.h:48
Hit object for use in TrackCand. Provides IDs and sorting parameters.
virtual TrackCandHit * clone() const
Track candidate – seed values and indices.
Definition TrackCand.h:69
void append(const TrackCand &)
Clone the TrackCandHit objects from the other TrackCand and append them to this TrackCand.
Definition TrackCand.cc:210
std::vector< double > getSortingParameters() const
Get sorting parameterts of all hits.
Definition TrackCand.cc:145
bool hitInTrack(int detId, int hitId) const
Is there a hit with detId and hitId in the TrackCand?
Definition TrackCand.cc:178
std::vector< int > getDetIDs() const
Get detector IDs of all hits.
Definition TrackCand.cc:137
void addHit(int detId, int hitId, int planeId=-1, double sortingParameter=0)
Definition TrackCand.cc:122
void setPosMomSeed(const TVector3 &pos, const TVector3 &mom, const double charge)
sets the state to seed the track fitting. State has to be a TVector3 for position and a TVector3 for ...
Definition TrackCand.cc:253
static bool compareTrackCandHits(const TrackCandHit *lhs, const TrackCandHit *rhs)
Definition TrackCand.h:89
void swap(TrackCand &other)
Definition TrackCand.cc:73
void sortHits()
Sort the hits that were already added to the trackCand using the sorting parameters.
Definition TrackCand.cc:217
TMatrixDSym cov6D_
Definition TrackCand.h:199
std::set< int > getUniqueDetIDs() const
Definition TrackCand.cc:153
void set6DSeed(const TVectorD &state6D, const double charge)
sets the state to seed the track fitting. State has to be a TVectorD(6). First 3 elements are the sta...
Definition TrackCand.cc:241
void Print(const Option_t *="") const
Write the content of all private attributes to the terminal.
Definition TrackCand.cc:197
std::vector< int > getHitIDs(int detId=-2) const
Get hit ids of from a specific detector.
Definition TrackCand.cc:127
void getHitWithPlane(int i, int &detId, int &hitId, int &planeId) const
Get detector Id, hit Id and plane id for hit number i.
Definition TrackCand.cc:112
std::vector< TrackCandHit * > hits_
Definition TrackCand.h:193
TVectorD state6D_
Definition TrackCand.h:198
void set6DSeedAndPdgCode(const TVectorD &state6D, const int pdgCode)
This function works the same as set6DSeed but instead of a charge hypothesis you can set a pdg code w...
Definition TrackCand.cc:248
unsigned int getNHits() const
Definition TrackCand.h:103
TrackCand & operator=(TrackCand other)
assignment operator
Definition TrackCand.cc:67
void setPosMomSeedAndPdgCode(const TVector3 &pos, const TVector3 &mom, const int pdgCode)
This function works the same as setPosMomSeed but instead of a charge hypothesis you can set a pdg co...
Definition TrackCand.cc:261
void setPdgCode(int pdgCode)
Set a particle hypothesis in form of a PDG code. This will also set the charge attribute.
Definition TrackCand.cc:162
void reset()
Delete and clear the TrackCandHits.
Definition TrackCand.cc:169
TrackCandHit * getHit(int i) const
Definition TrackCand.cc:85
Matrix inversion tools.
Definition AbsBField.h:29
bool operator==(const DetPlane &lhs, const DetPlane &rhs)
Definition DetPlane.cc:241