/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/MdcPatRec/TrkBase/TrkBase-00-01-12/src/TrkHitOnTrk.cxx

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: TrkHitOnTrk.cxx,v 1.5 2010/09/26 00:31:59 zhangy Exp $
00004 //
00005 // Description:
00006 //
00007 //
00008 // Environment:
00009 //      Software developed for the BaBar Detector at the SLAC B-Factory.
00010 //
00011 // Author(s): Steve Schaffner
00012 //
00013 //
00014 // Modified 3-july-97 by Leon Rochester to add '<' & '==' operators for
00015 // Roguewave Sorted Vector
00016 //------------------------------------------------------------------------
00017 #include "TrkBase/TrkHitOnTrk.h"
00018 #include <assert.h>
00019 #include "TrkBase/TrkRecoTrk.h"
00020 #include "TrkBase/TrkFundHit.h"
00021 #include "TrkBase/TrkRep.h"
00022 #include "TrkBase/TrkDifTraj.h"
00023 #include "TrkBase/TrkPoca.h"
00024 #include "TrkBase/TrkDifPoca.h"
00025 #include "TrkBase/TrkSimpTraj.h"
00026 //#include "MdcData/MdcHit.h"//yzhang debug
00027 using std::endl;
00028 using std::ostream;
00029 
00030 const MdcHitOnTrack* TrkHitOnTrk::mdcHitOnTrack() const {return 0;}
00031 const SvtHitOnTrack* TrkHitOnTrk::svtHitOnTrack() const {return 0;}
00032 
00033 TrkHitOnTrk::TrkHitOnTrk(const TrkFundHit* hit,double tolerance) :
00034   _parentRep(0),
00035   _theHit(const_cast<TrkFundHit*>(hit)),
00036   _isActive(true),
00037   _isUsable(true),
00038   //make caches invalid
00039   _hitRms(-9.e50),
00040   _trkLen(0.0),
00041   _hitLen(0.0),
00042   _trkTraj(0),
00043   _poca(0),
00044   _tolerance(tolerance)
00045 {  }
00046 
00047 // This is effectively a copy ctor:
00048 TrkHitOnTrk::TrkHitOnTrk(const TrkHitOnTrk &oldHit, TrkRep *newRep,
00049                          const TrkDifTraj *trkTraj)
00050   : _parentRep(newRep),
00051     _theHit(oldHit._theHit),
00052     _isActive(oldHit._isActive),
00053     _isUsable(oldHit._isUsable),
00054     _hitRms(oldHit._hitRms),
00055     _trkLen(oldHit._trkLen),
00056     _hitLen(oldHit._hitLen),
00057     _resid(9999.9),
00058     _trkTraj(0),
00059     _poca(0),
00060     _tolerance(oldHit._tolerance)
00061 {
00062   assert (0 != newRep);
00063   if( oldHit._trkTraj!=0 && trkTraj!=0 && oldHit._trkTraj == trkTraj ) {
00064                               // re-use cache as traj are the same
00065         _resid=oldHit._resid;
00066         _trkTraj=trkTraj;
00067         _poca = (oldHit._poca==0 ? 0 :new TrkPoca(*oldHit._poca));
00068   } else {
00069        double fl = oldHit.fltLen();
00070        double dum;
00071        const TrkSimpTraj *t1= (oldHit._trkTraj==0?0:oldHit._trkTraj->localTrajectory(fl,dum));
00072        const TrkSimpTraj *t2= (trkTraj==0?0:trkTraj->localTrajectory(fl,dum));
00073        if( t1 != 0 && t2 != 0 && t1->parameters()->parameter() == t2->parameters()->parameter() ) {
00074                               // re-use cache as traj are sufficiently equiv
00075            _resid=oldHit._resid;
00076            _trkTraj=trkTraj;
00077            _poca = (oldHit._poca==0 ? 0: new TrkPoca(*oldHit._poca));
00078 
00079        }
00080   }
00081   // Only record hots if on default TrkRep
00082   if (getParentRep()->particleType() == getParentTrack()->defaultType()) {
00083           setUsedHit();
00084   }
00085 }
00086 
00087 TrkHitOnTrk::~TrkHitOnTrk()
00088 {
00089   delete _poca;
00090   if ( hit() != 0 && getParentRep() != 0 ) {      
00091     setUnusedHit();
00092   }
00093 }
00094 
00095 void
00096 TrkHitOnTrk::setActivity(bool turnOn)
00097 {
00098   if (!isUsable() || isActive()==turnOn) return;
00099   if (getParentRep() != 0) {    // needed until Rep-less HoTs go away
00100     turnOn ? parentRep()->activateHot(this)
00101            : parentRep()->deactivateHot(this);
00102   } else {
00103     _isActive = turnOn;
00104   }
00105 }
00106 
00107 void
00108 TrkHitOnTrk::setUsability(int usability)
00109 {
00110   _isUsable = usability;
00111   if (isActive() && !isUsable()) {
00112     _isActive = false;
00113     if(getParentRep() != 0)parentRep()->deactivateHot(this);
00114   }
00115   if (!isActive() && mustUse()) {
00116     _isActive = true;
00117     if(getParentRep() != 0)parentRep()->activateHot(this);
00118   }
00119 }
00120 
00121 double
00122 TrkHitOnTrk::weight() const
00123 {
00124   // could be cached
00125   double rms=hitRms();
00126   assert(rms > 0);
00127   return double(1) / ( rms * rms );
00128 }
00129 
00130 void
00131 TrkHitOnTrk::print(ostream& o) const
00132 {
00133   hit()->printAll(o);
00134   o << " hitlen " << hitLen() 
00135     << " fltlen " << fltLen()
00136     << " act " << (isActive() != 0) << endl;
00137 }
00138 
00139 void
00140 TrkHitOnTrk::printAll(ostream& o) const
00141 {
00142   print(o);
00143 }
00144 
00145 TrkRecoTrk*
00146 TrkHitOnTrk::parentTrack() const
00147 {
00148   return parentRep()->parentTrack();
00149 }
00150 
00151 const TrkRecoTrk*
00152 TrkHitOnTrk::getParentTrack() const
00153 {
00154   return getParentRep()->parentTrack();
00155 }
00156 
00157 PdtPid::PidType
00158 TrkHitOnTrk::particleType() const
00159 {
00160   return getParentRep()->particleType();
00161 }
00162 
00163   void
00164 TrkHitOnTrk::setUsedHit()
00165 {
00166   if (hit() != 0) hit()->setUsedHit(this);
00167 }
00168 
00169   void
00170 TrkHitOnTrk::setUnusedHit()
00171 {
00172   if (hit() != 0) hit()->setUnusedHit(this);
00173 }
00174 
00175 bool TrkHitOnTrk::operator==(const TrkHitOnTrk &rhs) const
00176 {
00177   return this == &rhs;
00178 }
00179 
00180 int
00181 TrkHitOnTrk::ambig() const
00182 {
00183   return 0;// by default no ambiguity
00184 }
00185 
00186   void
00187 TrkHitOnTrk::setAmbig(int newambig)
00188 {} // by default nothing to set
00189 
00190 double
00191 TrkHitOnTrk::resid(bool exclude) const
00192 {
00193   double r(-99999.9),re(-9999.9);
00194   bool s=getParentRep()->resid(this,r,re,exclude);
00195   if (!s && r<-99999.8) {
00196 #ifdef MDCPATREC_ROUTINE
00197     std::cout<<"ErrMsg(routine) "
00198       << "error calling parentRep()->residual()" << std::endl;
00199 #endif
00200   }
00201   return r;
00202 }
00203 
00204 bool
00205 TrkHitOnTrk::resid(double &resid, double &residErr, bool exclude) const
00206 {
00207   assert(getParentRep()!=0);
00208   return getParentRep()->resid(this,resid,residErr,exclude);
00209 }
00210 
00211 double
00212 TrkHitOnTrk::residual() const
00213 {
00214   assert (_trkTraj == &(getParentRep()->traj()));
00215   return _resid;
00216 }
00217 
00218   TrkErrCode
00219 TrkHitOnTrk::updatePoca(const TrkDifTraj* trkTraj, bool maintainAmb)
00220 {
00221   _trkTraj = (trkTraj!=0?trkTraj:&(getParentRep()->traj()));
00222   if (_poca==0) {
00223     _poca = new TrkPoca(*_trkTraj,fltLen(),
00224         *hitTraj(), hitLen(),_tolerance);
00225   } else {
00226     *_poca = TrkPoca(*_trkTraj,fltLen(),
00227         *hitTraj(), hitLen(),_tolerance);
00228   }
00229   if(_poca->status().failure()) {
00230     if(isActive()){
00231 #ifdef MDCPATREC_WARNING
00232       std::cout<<"ErrMsg(warning) "
00233         << " TrkPoca failed in TrkHitOnTrk::updatePoca"
00234         << std::endl;
00235 #endif
00236     }
00237     delete _poca; _poca=0;
00238     return TrkErrCode(TrkErrCode::fail,4);
00239   }
00240   _trkLen = _poca->flt1();
00241   _hitLen = _poca->flt2();
00242   double dca=_poca->doca();
00243   if (!maintainAmb) setAmbig(dca>0?+1:-1);
00244   return TrkErrCode(TrkErrCode::succeed);
00245 }
00246 
00247 TrkErrCode
00248 TrkHitOnTrk::getFitStuff(HepVector &derivs, double &deltaChi ) const
00249 {
00250   if (_poca==0 || _poca->status().failure()) {
00251     return TrkErrCode(TrkErrCode::fail);
00252   }
00253   // FIXME: I wish I could tell poca to NOT iterate
00254   //        and ONLY compute the distance & derivatives...
00255   TrkDifPoca poca(*_trkTraj,fltLen(),*hitTraj(), hitLen(),_tolerance);
00256   if (poca.status().failure()) {
00257     return TrkErrCode(TrkErrCode::fail);
00258   }
00259   if (derivs.num_row() != 0) {
00260     poca.fetchDerivs(derivs);
00261   } else {
00262     derivs = poca.derivs();
00263   }
00264   double sigInv = 1. / hitRms();
00265   deltaChi = _resid * sigInv; // NOTE: use _INTERNAL_ residual
00266   derivs *= sigInv;
00267   return TrkErrCode(TrkErrCode::succeed);
00268 }
00269 
00270 TrkErrCode
00271 TrkHitOnTrk::getFitStuff(double &deltaChi)  const
00272 {
00273   assert (_trkTraj == &(getParentRep()->traj()));
00274   deltaChi=_resid/hitRms(); // NOTE: use _INTERNAL_ residual
00275   return TrkErrCode(TrkErrCode::succeed);
00276 }
00277 
00278 
00279   ostream&
00280 operator<<(ostream& o, const TrkHitOnTrk& x)
00281 {
00282   x.print(o); return o;
00283 }

Generated on Tue Nov 29 23:13:40 2016 for BOSS_7.0.2 by  doxygen 1.4.7