11#include "TrkBase/TrkRecoTrk.h"
12#include "CLHEP/Vector/ThreeVector.h"
13#include "MdcGeom/Constants.h"
14#include "MdcRecoUtil/BesPointErr.h"
15#include "MdcRecoUtil/BesVectorErr.h"
16#include "MdcRecoUtil/DifIndepPar.h"
17#include "MdcRecoUtil/DifPoint.h"
18#include "MdcRecoUtil/DifVector.h"
19#include "MdcRecoUtil/Pdt.h"
20#include "MdcRecoUtil/PdtPid.h"
21#include "PatBField/BField.h"
22#include "TrkBase/TrkContext.h"
23#include "TrkBase/TrkDifTraj.h"
24#include "TrkBase/TrkErrCode.h"
25#include "TrkBase/TrkExchangePar.h"
26#include "TrkBase/TrkExtInterface.h"
27#include "TrkBase/TrkFitStatus.h"
28#include "TrkBase/TrkFundHit.h"
29#include "TrkBase/TrkHitOnTrk.h"
30#include "TrkBase/TrkRep.h"
31#include "TrkBase/TrkRepIter.h"
32#include "boost/shared_ptr.hpp"
52 typedef std::vector<boost::shared_ptr<TrkRep>> repList_t;
53 typedef repList_t::const_iterator repConstIter;
54 typedef repList_t::iterator repIter;
56 typedef std::vector<boost::shared_ptr<TrkHitList>> hitList_t;
57 typedef hitList_t::iterator hitListIter;
58 hitList_t _hitInterfaces;
63 , _id( ctext.getId() )
64 , _fitNumber(
PdtPid::nPidType, (int)0 )
65 , _defaultType( defaultPart )
67 , _bField( ctext.
bField() ) {
70 for ( TrkRecoTrkImpl::hitListIter iface = _impl->_hitInterfaces.begin();
71 iface != _impl->_hitInterfaces.end(); ++iface )
73 iface->reset( new TrkHitList( this, (PdtPid::PidType)i++ ) );
81 , _fitNumber(
PdtPid::nPidType, (int)0 )
82 , _defaultType( defaultPart )
87 for ( TrkRecoTrkImpl::hitListIter iface = _impl->_hitInterfaces.begin();
88 iface != _impl->_hitInterfaces.end(); ++iface )
90 iface->reset( new TrkHitList( this, (PdtPid::PidType)i++ ) );
97 , _id( rhs._id.idManager() )
98 , _fitNumber(
PdtPid::nPidType, (int)0 )
99 , _storage( rhs._storage )
100 , _trackT0( rhs._trackT0 )
101 , _bField( rhs._bField ) {
104 for ( TrkRecoTrkImpl::hitListIter iface = _impl->_hitInterfaces.begin();
105 iface != _impl->_hitInterfaces.end(); ++iface )
107 iface->reset( new TrkHitList( this, (PdtPid::PidType)i++ ) );
115 if ( &right ==
this )
return *
this;
116 _trackT0 = right._trackT0;
119 _bField = right._bField;
121 _id.setNewValue( right._id );
122 _storage = right._storage;
131 if ( _impl->_reps[hypo].get() == 0 ) {
return hypo; }
134 return _impl->_reps[hypo]->particleType();
141 return _fitNumber[index];
150 if ( daList != 0 ) { ostr <<
" nhit: " << daList->
nHit(); }
152 { ostr <<
" nactive: " << daFit->
nActive() <<
" chisq: " << daFit->
chisq(); }
153 if ( daStatus != 0 ) { ostr <<
" 3-d: " << ( daStatus->
is2d() == 0 ); }
154 ostr <<
" t0: " << _trackT0 <<
"\n";
157 TrkExchangePar par = daFit->
helix( 0. );
158 ostr <<
"phi0: " << par.
phi0() <<
" om: " << par.
omega() <<
" d0: " << par.
d0()
159 <<
" z0: " << par.
z0() <<
" ct: " << par.
tanDip();
170 const TrkFitStatus* daStatus =
status();
171 if ( daList != 0 ) { ostr <<
" nhit: " << daList->
nHit(); }
173 { ostr <<
" nactive: " << daFit->
nActive() <<
" chisq: " << daFit->
chisq(); }
174 if ( daStatus != 0 ) { ostr <<
" 3-d: " << ( daStatus->
is2d() == 0 ); }
175 ostr <<
" t0: " << _trackT0 <<
"\n";
189 "TrkRecoTrk::addFit(): cannot add a fit to this track." );
194 "TrkRecoTrk::addFit(): requested fit already exists." );
196 _impl->_reps[hypo].reset( _impl->_reps[
defaultType()]->cloneNewHypo( hypo ) );
198 if ( fit && !_impl->_reps[hypo]->fitCurrent() ) { fitErr = _impl->_reps[hypo]->fit(); }
209 std::pair<TrkRepIter, TrkRepIter> x =
uniqueReps();
211 std::transform( _fitNumber.begin(), _fitNumber.end(), _fitNumber.begin(),
212 std::bind2nd( std::plus<int>(), 1 ) );
225 TrkRep* theRep = _impl->_reps[hypo].get();
227 if ( hypo ==
defaultType() ) assert( 0 != theRep );
233 const TrkRep* theRep = _impl->_reps[hypo].get();
234 if ( hypo ==
defaultType() ) assert( 0 != theRep );
243 std::for_each( oldList->
begin(), oldList->
end(),
245 assert(
getRep( newHypo ) != 0 );
247 std::for_each( newList->
begin(), newList->
end(),
249 _defaultType = newHypo;
253 TrkRecoTrkImpl::repIter lhs = _impl->_reps.begin();
254 for ( TrkRecoTrkImpl::repIter i = rhs._impl->_reps.begin(); i != rhs._impl->_reps.end();
257 TrkRecoTrkImpl::repIter j = std::find( rhs._impl->_reps.begin(), i, *i );
260 lhs->reset( ( *i )->clone(
this ) );
261 ( *lhs )->setValid( ( *i )->fitValid() );
262 ( *lhs )->setCurrent( ( *i )->fitCurrent() );
264 else { *lhs = *( _impl->_reps.begin() + ( j - rhs._impl->_reps.begin() ) ); }
266 assert( _fitNumber.size() == rhs._fitNumber.size() );
267 std::copy( rhs._fitNumber.begin(), rhs._fitNumber.end(), _fitNumber.begin() );
273 std::fill( _impl->_reps.begin(), _impl->_reps.end(), boost::shared_ptr<TrkRep>( r ) );
274 std::transform( _fitNumber.begin(), _fitNumber.end(), _fitNumber.begin(),
275 std::bind2nd( std::plus<int>(), 1 ) );
280 if ( fit == hypo ||
getRep( fit ) ==
getRep( hypo ) )
return;
284 std::cout <<
"ErrMsg(error) "
285 <<
"TrkRecoTrk: can't make default hypothesis point at different fit"
289 _impl->_reps[hypo] = _impl->_reps[fit];
294 return rp != 0 ? interface.
attach( rp ) : 0;
299 return rp != 0 ? interface.
attach( rp ) : 0;
304 return rp == 0 ? 0 : _impl->_hitInterfaces[hypo].get();
309 return rp == 0 ? 0 : _impl->_hitInterfaces[hypo].get();
316 return rp == 0 ? 0 : ( rp->
fitValid() ? rp : 0 );
328 _fitNumber[hypo] = newNumber;
332 _impl->_reps[hypo].reset( newRep );
348 if (
getRep( realhypo ) != 0 &&
getRep( realhypo )->fitValid() )
350 _storage[std::string( listname )].insert(
TrkStoreHypo( realhypo, fltlen ) );
353 std::cout <<
"ErrMsg(error) "
354 <<
"Invalid fits cannot be marked for storage" << std::endl;
358 static std::set<TrkStoreHypo> empty;
359 std::map<std::string, std::set<TrkStoreHypo>>::const_iterator foundit =
360 _storage.find( std::string( listname ) );
361 if ( foundit != _storage.end() )
return foundit->second;
366 _storage[std::string( listname )].clear();
373 std::map<std::string, std::set<TrkStoreHypo>>::const_iterator miter = _storage.begin();
374 while ( miter != _storage.end() )
376 storage.insert( miter->first );
383 return rp == 0 ? 0 : rp->
hotList();
388 return rp == 0 ? 0 : rp->
hotList();
392 typedef std::vector<TrkRep*> RPL;
393 boost::shared_ptr<RPL>
x(
new RPL );
396 for ( TrkRecoTrkImpl::repConstIter i = _impl->_reps.begin(); i != _impl->_reps.end(); ++i )
398 x->push_back( i->get() );
409 typedef std::vector<TrkRep*> RPL;
410 boost::shared_ptr<RPL>
x(
new RPL );
411 for ( TrkRecoTrkImpl::repConstIter i = _impl->_reps.begin(); i != _impl->_reps.end(); ++i )
413 if ( std::find( x->begin(), x->end(), i->get() ) == x->end() ) x->push_back( i->get() );
ostream & operator<<(ostream &os, const TrkRecoTrk &tk)
const char * name() const
static PdtEntry * lookup(const std::string &name)
virtual void printAll(std::ostream &ostr) const =0
virtual double chisq() const =0
virtual bool attach(TrkRep *)
virtual int nActive() const =0
virtual TrkExchangePar helix(double fltL) const =0
hot_iterator begin() const
void repointHypo(PdtPid::PidType hypo, PdtPid::PidType fit)
virtual void print(std::ostream &) const
PdtPid::PidType whichFit(PdtPid::PidType hypo) const
void addHypoTo(TrkRep *newRep, PdtPid::PidType hypo)
void clearStorageRequests(const char *listname="Default")
void changeDefault(PdtPid::PidType newHypo)
int fitNumber(PdtPid::PidType hypo) const
void setFitNumber(PdtPid::PidType hypo, int newNumber)
void markForStore(PdtPid::PidType hypo, double fltlen, const char *listname="Default")
const TrkRecoTrk & operator=(const TrkRecoTrk &right)
void resetT0(double time)
PdtPid::PidType defaultType() const
TrkRecoTrk(const TrkRecoTrk &right)
std::pair< TrkRepIter, TrkRepIter > uniqueReps() const
const MdcPatRec::BField & bField() const
bool operator<(const TrkRecoTrk &other) const
bool operator==(const TrkRecoTrk &other) const
void copyReps(const TrkRecoTrk &rhs)
void setIdManager(TrkIdManager *idMan)
TrkRep * getRep(PdtPid::PidType hypo)
std::pair< TrkRepIter, TrkRepIter > allReps() const
void storageLists(std::set< std::string > &storage) const
const TrkFit * fitResult() const
virtual void printAll(std::ostream &) const
const TrkFitStatus * status() const
bool attach(TrkExtInterface &, PdtPid::PidType hypo)
const std::set< TrkStoreHypo > & storageRequests(const char *listname="Default") const
void setBField(const MdcPatRec::BField *field)
TrkErrCode addFit(PdtPid::PidType hypo, bool fit=true)
virtual void updateHots()
virtual TrkHotList * hotList()