// AddFitter.cpp #include "AddFitter.h" #include #include #include "trfutil/trfstream.h" #include "trfbase/Surface.h" #include "trfbase/ETrack.h" #include "HTrack.h" using std::cout; using std::endl; using trf::HitPtr; using trf::ETrack; using trf::HTrack; using trf::AddFitter; //********************************************************************** // Free functions. //********************************************************************** namespace { ObjPtr create(const ObjData& data) { return ObjPtr(0); } } //********************************************************************** // Member functions. //********************************************************************** // constructor AddFitter::AddFitter() : _base_add_hit(false), _base_add_hit_fit(false) { } //********************************************************************** // destructor AddFitter::~AddFitter() { } //********************************************************************** // Return the creator. ObjCreator AddFitter::get_creator() { return create; } //********************************************************************** // Add a hit to an ETrack. // Default is call add_hit_fit_with_record(tre,chsq,phit,0); // If neither method is overriden, the fit fails. int AddFitter:: add_hit_fit(ETrack& tre, double& chsq, const HitPtr& phit) const { // Check that we are not stuck in a loop because subclass has failed // to implement either ETrack method. if ( _base_add_hit_fit ) { cout << *this << endl; assert(false); return 1; } _base_add_hit_fit = true; int stat = add_hit_fit_with_record(tre,chsq,phit,0); _base_add_hit_fit = false; return stat; } //********************************************************************** // Add a hit to an ETrack with a cut record. // Default is call add_hit_fit(tre,chsq,phit); int AddFitter:: add_hit_fit_with_record(ETrack& tre, double& chsq, const HitPtr& phit, CutRecord* prec) const { return add_hit_fit(tre,chsq,phit); } //********************************************************************** // add hit to an HTrack int AddFitter::add_hit(HTrack& trh, const HitPtr& phit) const { _base_add_hit = true; int stat = add_hit_with_record(trh,phit,0); _base_add_hit = false; return stat; } //********************************************************************** // Default method to add a hit to an HTrack. // // If subclass has implemented add_hit(trh,phit) const, then we use it. // If not, call add_hit_fit_with_record(tre,chsq,phit,prec). int AddFitter::add_hit_with_record( HTrack& trh, const HitPtr& phit, CutRecord* prec) const { // Define the return status. int stat = 0; // If we have not already done so, try add_hit(trh,phit). if ( ! _base_add_hit ) { stat = add_hit(trh,phit); // Otherwise try add_hit_fit_with_record(tre,chsq,phit,prec). } else { // Fetch the starting fit and chi-square. ETrack tre = trh.get_track(); double chsq = trh.get_chi_square(); // check the track and hit are at the same surface const Surface& tsrf = *tre.get_surface(); const Surface& hsrf = phit->get_surface(); assert ( tsrf.pure_equal(hsrf) ); if ( ! tsrf.pure_equal(hsrf) ) return -1; // Check the track is fully fit before adding hit. // Unless this is the first hit. if ( trh.get_hits().size() ) { assert( trh.is_fit() ); if ( ! trh.is_fit() ) return -2; } // Fit with the new point; exit if error occurs. int stat = this->add_hit_fit_with_record(tre,chsq,phit,prec); if ( stat ) return stat; // Update the track with the new fit and hit. trh.add_hit(phit); trh.set_fit(tre,chsq); } return stat; } //**********************************************************************