forked from eutelescope/eutelescope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEUTelTrackImpl.cc
310 lines (238 loc) · 10.6 KB
/
EUTelTrackImpl.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#include "EUTelTrackImpl.h"
#include "EUTelTrackStateImpl.h"
#include "lcio.h"
#include <cmath>
#include <sstream>
namespace eutelescope {
EUTelTrackImpl::EUTelTrackImpl() :
_chi2(0),
_ndf(0),
_dEdx(0),
_dEdxError(0),
_tracks(),
_hits(),
_trackStates() {
}
// copy constructor
EUTelTrackImpl::EUTelTrackImpl(const EUTelTrackImpl& o) : EVENT::LCObject(), AccessChecked(),
_chi2(o.getChi2()),
_ndf(o.getNdf()),
_dEdx(o.getdEdx()),
_dEdxError(o.getdEdxError()),
_tracks(o.getTracks()),
_hits(o.getTrackerHits()),
_trackStates(o.getTrackStates())
{
*this = o ; // call operator =
}
const EUTelTrackImpl & EUTelTrackImpl::operator = ( const EUTelTrackImpl &o )
{
_chi2 = o._chi2 ;
_ndf = o._ndf ;
_dEdx = o._dEdx ;
_dEdxError = o._dEdxError ;
std::copy( o._hits.begin() , o._hits.end() , std::back_inserter( _hits ) ) ;
std::copy( o._tracks.begin() , o._tracks.end() , std::back_inserter( _tracks ) ) ;
for( unsigned int i=0; i< o._trackStates.size() ; i++ ){
_trackStates.push_back( new EUTelTrackStateImpl( *o._trackStates[i] ) ) ;
}
return *this ;
}
EUTelTrackImpl::~EUTelTrackImpl() {
// delete track states in here ?
for( unsigned int i=0; i<_trackStates.size() ; i++ ){
delete _trackStates[i] ;
}
}
float EUTelTrackImpl::getTx(unsigned int i) const { return ( _trackStates.size()>i ? _trackStates[i]->getTx() : 0 ) ; }
float EUTelTrackImpl::getTy(unsigned int i) const { return ( _trackStates.size()>i ? _trackStates[i]->getTy() : 0 ) ; }
float EUTelTrackImpl::getX(unsigned int i) const { return ( _trackStates.size()>i ? _trackStates[i]->getX() : 0 ) ; }
float EUTelTrackImpl::getY(unsigned int i) const { return ( _trackStates.size()>i ? _trackStates[i]->getY() : 0 ) ; }
float EUTelTrackImpl::getInvP(unsigned int i) const { return ( _trackStates.size()>i ? _trackStates[i]->getInvP() : 0 ) ; }
const EVENT::FloatVec& EUTelTrackImpl::getCovMatrix() const {
static const EUTelTrackStateImpl dummy ;
return ( _trackStates.size()>0 ? _trackStates[0]->getCovMatrix() : dummy.getCovMatrix() ) ;
}
const float* EUTelTrackImpl::getReferencePoint() const {
static const EUTelTrackStateImpl dummy ;
return ( _trackStates.size()>0 ? _trackStates[0]->getReferencePoint() : dummy.getReferencePoint() ) ;
}
float EUTelTrackImpl::getChi2() const { return _chi2 ;}
int EUTelTrackImpl::getNdf() const { return _ndf ;}
float EUTelTrackImpl::getdEdx() const { return _dEdx ; }
float EUTelTrackImpl::getdEdxError() const { return _dEdxError ; }
const EVENT::TrackerHitVec & EUTelTrackImpl::getTrackerHits() const {
return _hits ;
}
const EUTelTrackVec & EUTelTrackImpl::getTracks() const {
return _tracks ;
}
const EUTelTrackStateVec & EUTelTrackImpl::getTrackStates() const {
return _trackStates ;
}
const EUTelTrackStateImpl* EUTelTrackImpl::getClosestTrackState( float x, float y, float z ) const {
EUTelTrackStateImpl* closest = _trackStates[0] ;
const float * refP = _trackStates[0]->getReferencePoint() ;
float shortest_distance_square = pow( ( x - refP[0] ) , 2 ) + pow( ( y - refP[1] ) , 2 ) + pow( ( z - refP[2] ) , 2 ) ;
float current_distance_square = 0 ;
for( unsigned int i=1 ; i < _trackStates.size() ; i++ ){
refP = _trackStates[i]->getReferencePoint() ;
current_distance_square = pow( ( x - refP[0] ) , 2 ) + pow( ( y - refP[1] ) , 2 ) + pow( ( z - refP[2] ) , 2 ) ;
if( current_distance_square < shortest_distance_square ){
closest = _trackStates[i] ;
shortest_distance_square = current_distance_square ;
}
}
return closest ;
}
const EUTelTrackStateImpl* EUTelTrackImpl::getFirstTrackState( ) const {
if( _trackStates.size() > 0 ) {
int firstElement = 0;
return _trackStates[ firstElement ] ;
}
return NULL ;
}
const EUTelTrackStateImpl* EUTelTrackImpl::getTrackState( int location ) const {
for( unsigned int i=0 ; i < _trackStates.size() ; i++ ){
if( _trackStates[i]->getLocation() == location ){
return _trackStates[i] ;
}
}
return NULL ;
}
void EUTelTrackImpl::setTypeBit( int index, bool val){
checkAccess("TrackImpl::setTypeBit") ;
_type.set( index, val ) ;
}
void EUTelTrackImpl::setTx( float tx ){
if( _trackStates.size() == 0 ){
// create a first TrackState for backwards compatibility
EUTelTrackStateImpl* ts = new EUTelTrackStateImpl() ;
_trackStates.push_back( ts ) ;
}
if( _trackStates.size() != 1 ){
throw( lcio::Exception( " trying to use setTx within Track object containing more than one TrackState." )) ;
}
(static_cast< EUTelTrackStateImpl* >(_trackStates[0]) )->setTx( tx ) ;
}
void EUTelTrackImpl::setTy( float ty ){
if( _trackStates.size() == 0 ){
// create a first TrackState for backwards compatibility
EUTelTrackStateImpl* ts = new EUTelTrackStateImpl() ;
_trackStates.push_back( ts ) ;
}
if( _trackStates.size() != 1 ){
throw( lcio::Exception( " trying to use setTy within Track object containing more than one TrackState." )) ;
}
(static_cast< EUTelTrackStateImpl* >(_trackStates[0]) )->setTy( ty ) ;
}
void EUTelTrackImpl::setX( float x ) {
if( _trackStates.size() == 0 ){
// create a first TrackState for backwards compatibility
EUTelTrackStateImpl* ts = new EUTelTrackStateImpl() ;
_trackStates.push_back( ts ) ;
}
if( _trackStates.size() != 1 ){
throw( lcio::Exception( " trying to use setX within Track object containing more than one TrackState." )) ;
}
(static_cast< EUTelTrackStateImpl* >(_trackStates[0]) )->setX( x ) ;
}
void EUTelTrackImpl::setY( float y ){
if( _trackStates.size() == 0 ){
// create a first TrackState for backwards compatibility
EUTelTrackStateImpl* ts = new EUTelTrackStateImpl() ;
_trackStates.push_back( ts ) ;
}
if( _trackStates.size() != 1 ){
throw( lcio::Exception( " trying to use setY within Track object containing more than one TrackState." )) ;
}
(static_cast< EUTelTrackStateImpl* >(_trackStates[0]) )->setY( y ) ;
}
void EUTelTrackImpl::setInvP( float invp ){
if( _trackStates.size() == 0 ){
// create a first TrackState for backwards compatibility
EUTelTrackStateImpl* ts = new EUTelTrackStateImpl() ;
_trackStates.push_back( ts ) ;
}
if( _trackStates.size() != 1 ){
throw( lcio::Exception( " trying to use setInvP within Track object containing more than one TrackState." )) ;
}
(static_cast< EUTelTrackStateImpl* >(_trackStates[0]) )->setInvP( invp ) ;
}
void EUTelTrackImpl::setCovMatrix( const float* cov ){
if( _trackStates.size() == 0 ){
// create a first TrackState for backwards compatibility
EUTelTrackStateImpl* ts = new EUTelTrackStateImpl() ;
_trackStates.push_back( ts ) ;
}
if( _trackStates.size() != 1 ){
throw( lcio::Exception( " trying to use setCovMatrix within Track object containing more than one TrackState." )) ;
}
(static_cast< EUTelTrackStateImpl* >(_trackStates[0]) )->setCovMatrix( cov ) ;
}
void EUTelTrackImpl::setCovMatrix( const EVENT::FloatVec& cov ){
if( _trackStates.size() == 0 ){
// create a first TrackState for backwards compatibility
EUTelTrackStateImpl* ts = new EUTelTrackStateImpl() ;
_trackStates.push_back( ts ) ;
}
if( _trackStates.size() != 1 ){
throw( lcio::Exception( " trying to use setCovMatrix within Track object containing more than one TrackState." )) ;
}
(static_cast< EUTelTrackStateImpl* >(_trackStates[0]) )->setCovMatrix( cov ) ;
}
void EUTelTrackImpl::setReferencePoint( const float* rPnt){
if( _trackStates.size() == 0 ){
// create a first TrackState for backwards compatibility
EUTelTrackStateImpl* ts = new EUTelTrackStateImpl() ;
_trackStates.push_back( ts ) ;
}
if( _trackStates.size() != 1 ){
throw( lcio::Exception( " trying to use setReferencePoint within Track object containing more than one TrackState." )) ;
}
(static_cast< EUTelTrackStateImpl* >(_trackStates[0]) )->setReferencePoint( rPnt ) ;
}
void EUTelTrackImpl::setChi2( float chi2 ){
checkAccess("EUTelTrackImpl::setChi2") ;
_chi2 = chi2 ;
}
void EUTelTrackImpl::setNdf( int ndf ){
checkAccess("EUTelTrackImpl::setNdf") ;
_ndf = ndf ;
}
void EUTelTrackImpl::setdEdx( float dEdx ){
checkAccess("EUTelTrackImpl::setdEdx") ;
_dEdx = dEdx ;
}
void EUTelTrackImpl::setdEdxError( float dEdxError ){
checkAccess("EUTelTrackImpl::setdEdxError") ;
_dEdxError = dEdxError ;
}
void EUTelTrackImpl::addHit( EVENT::TrackerHit* hit) {
_hits.push_back( hit ) ;
}
void EUTelTrackImpl::addTrack( EUTelTrackImpl* trk ) {
checkAccess("EUTelTrackImpl::addTrack") ;
_tracks.push_back( trk ) ;
}
void EUTelTrackImpl::addTrackState( EUTelTrackStateImpl* trkstate ) {
checkAccess("EUTelTrackImpl::addTrackState") ;
Print();
// std::cout << " addTrackState " << trkstate << " of " << _trackStates.size() << std::endl;
/* if( trkstate->getLocation() != EUTelTrackStateImpl::AtOther &&
getTrackState( trkstate->getLocation() ) != NULL )
{
std::stringstream ss;
ss << "another TrackState already exists with Location set to: " << trkstate->getLocation() ;
throw( lcio::Exception( ss.str() )) ;
}*/
_trackStates.push_back( trkstate ) ;
}
EUTelTrackStateVec & EUTelTrackImpl::trackStates() {
checkAccess("EUTelTrackImpl::trackStates") ;
return _trackStates ;
}
//int EUTelTrackImpl::getType(){
// return _type;
// }
} // namespace eutelescope