THelixFitter Class Reference

A class to fit a TTrackBase object to a helix. More...

#include <THelixFitter.h>

Inheritance diagram for THelixFitter:

TMFitter List of all members.

Public Member Functions

 THelixFitter (const std::string &name)
 Constructor.
virtual ~THelixFitter ()
 Destructor.
void dump (const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
 dumps debug information.
bool fit2D (void) const
 sets/returns 2D flag.
bool fit2D (bool)
bool freeT0 (void) const
 sets/returns free T0 flag.
bool freeT0 (bool)
unsigned corrections (void) const
 sets/returns correctin flag.
unsigned corrections (unsigned)
bool sag (void) const
 sets/returns sag correction flag.
bool sag (bool)
bool propagation (void) const
 sets/returns propagation-delay correction flag.
bool propagation (bool)
bool tof (void) const
 sets/returns propagation-delay correction flag.
bool tof (bool)
bool tanl (void) const
 sets/returns tanLambda correction flag.
bool tanl (bool)
double preChi2 (void) const
 returns sum of chi2 before fit.
double chi2 (void) const
 returns sum of chi2 aftter fit.
IMagneticFieldSvcgetMagneticFieldPointer (void) const
int fit (TTrackBase &) const
int fit (TTrackBase &, double *pre_chi2, double *fitted_chi2) const
int fit (TTrackBase &, float t0Offset, double *pre_chi2=NULL, double *fitted_chi2=NULL) const
int fit (TTrackBase &, float &tev, float &tev_err, double *pre_chi2=NULL, double *fitted_chi2=NULL) const
const std::stringname (void) const
 returns name.

Protected Member Functions

void fitDone (TTrackBase &) const
 sets the fitted flag. (Bad implementation)

Private Member Functions

int main (TTrackBase &, float t0Offset, double *pre_chi2=NULL, double *fitted_chi2=NULL) const
 main routine for fixed T0.
int main (TTrackBase &, float &tev, float &tev_err, double *pre_chi2=NULL, double *fitted_chi2=NULL) const
 main routine for free T0.
void drift (const TTrack &, TMLink &, float t0Offset, double &distance, double &itsError) const
 calculates drift distance and its error.
void drift (const TTrack &, TMLink &, float t0Offset, double &distance, double &itsError, double &ddda) const
 calculates drift distance and its error for free T0 case.
int dxda (const TMLink &link, const Helix &helix, double dPhi, HepVector &dxda, HepVector &dyda, HepVector &dzda) const
 calculates dXda. 'link' and 'dPhi' are inputs. Others are outputs.

Private Attributes

bool _fit2D
bool _freeT0
unsigned _corrections
bool _sag
int _propagation
bool _tof
bool _tanl
double _driftTime
double _pre_chi2
double _fitted_chi2
IMagneticFieldSvcm_pmgnIMF

Detailed Description

A class to fit a TTrackBase object to a helix.

Definition at line 48 of file THelixFitter.h.


Constructor & Destructor Documentation

THelixFitter::THelixFitter ( const std::string name  ) 

Constructor.

Definition at line 122 of file THelixFitter.cxx.

00123 : TMFitter(name),
00124   _fit2D(false),
00125   _freeT0(false),
00126   _sag(false),
00127   _propagation(false),
00128   _tof(false),
00129   _tanl(false),
00130   _pre_chi2(0.),
00131   _fitted_chi2(0.),
00132   m_pmgnIMF(0) {
00133 
00134     //yzhang delete
00135   //StatusCode scmgn = Gaudi::svcLocator()->service("MagneticFieldSvc",m_pmgnIMF); 
00136   //if(scmgn!=StatusCode::SUCCESS) { 
00137   //  std::cout<< name <<" Unable to open Magnetic field service"<<std::endl;
00138   //}else{
00139   //  std::cout<< name <<" open Magnetic field service"<<std::endl;
00140   //}
00141 
00142 }

THelixFitter::~THelixFitter (  )  [virtual]

Destructor.

Definition at line 144 of file THelixFitter.cxx.

00144                             {
00145 }


Member Function Documentation

double THelixFitter::chi2 ( void   )  const [inline]

returns sum of chi2 aftter fit.

Definition at line 305 of file THelixFitter.h.

References _fitted_chi2.

Referenced by main().

00305                              {
00306     return _fitted_chi2;
00307 }

unsigned THelixFitter::corrections ( unsigned   )  [inline]

Definition at line 293 of file THelixFitter.h.

References _corrections.

00293                                     {
00294     return _corrections = a;
00295 }

unsigned THelixFitter::corrections ( void   )  const [inline]

sets/returns correctin flag.

Definition at line 287 of file THelixFitter.h.

References _corrections.

00287                                     {
00288     return _corrections;
00289 }

void THelixFitter::drift ( const TTrack ,
TMLink ,
float  t0Offset,
double &  distance,
double &  itsError,
double &  ddda 
) const [private]

calculates drift distance and its error for free T0 case.

by wangjk, propagation correction

readout in the west of MDC

readout in the east of MDC

Definition at line 1973 of file THelixFitter.cxx.

References _propagation, _tof, MdcRec_wirhit::adc, TMDCWire::backwardPosition(), TMDCWireHit::dDrift(), check_raw_filter::dist, TMLink::dPhi(), TMDCWireHit::drift(), IMdcCalibFunSvc::driftTimeToDist(), TMDCWire::forwardPosition(), IMdcCalibFunSvc::getSigma(), IMdcCalibFunSvc::getTimeWalk(), TMLink::hit(), TMDCWire::layerId(), TMDCWire::localId(), msgSvc(), TMLink::positionOnTrack(), TMLink::positionOnWire(), TMDCWireHit::reccdc(), s, TMLink::setDriftTime(), t(), MdcRec_wirhit::tdc, tof(), Bes_Common::WARNING, TMDCWireHit::wire(), WireHitLeft, and WireHitRight.

01978                                          {
01979 //=========================================
01980 // be cautious here
01981     const TMDCWireHit & h = * l.hit();
01982     const HepPoint3D & onTrack = l.positionOnTrack();
01983     const HepPoint3D & onWire = l.positionOnWire();
01984     unsigned leftRight = WireHitRight;
01985     if (onWire.cross(onTrack).z() < 0.) leftRight = WireHitLeft;
01986 
01987     //...No correction...
01988     if ((tev == 0.) && (! _propagation) && (! _tof)) {
01989         distance = h.drift(leftRight);
01990         err = h.dDrift(leftRight);
01991         return;
01992     }
01993 
01994     //...TOF correction...
01995     float tof = 0.;
01996     if (_tof) {
01997         int imass = 3;
01998         float tl = t.helix().a()[4];
01999         float f = sqrt(1. + tl * tl);
02000         float s = fabs(t.helix().curv()) * fabs(l.dPhi()) * f;
02001         float p = f / fabs(t.helix().a()[2]);
02002 //zsl   calcdc_tof2_(& imass, & p, & s, & tof);
02003         float Mass[5] = {0.000511,0.105,0.140,0.493677,0.98327};
02004         tof = s/29.98*sqrt(1.0+(Mass[imass-1]/p)*(Mass[imass-1]/p));
02005         //cout<<"tof:"<<tof<<endl;
02006     }
02007 
02008     //...T0 and propagation corrections...
02009     int wire = h.wire()->localId();
02010     int layerId = h.wire()->layerId();
02011 //    int wire = h.wire()->id();
02012     int side = leftRight;
02013 
02014 
02016     const double zhit = onWire.z();
02017     const double vinner = 220.0e8; // unit is cm/s
02018     const double vouter = 240.0e8;
02019     
02020     double tprop = 0.;
02021     const double vprop = (layerId<8) ? vinner : vouter;
02022     if (0 == layerId%2){
02024       tprop = fabs((zhit - h.wire()->backwardPosition()[2]))/vprop; 
02025     }else{ 
02027       tprop = fabs(( zhit - h.wire()->forwardPosition()[2]))/vprop;
02028     }
02029 
02030 
02031 //    if (side==0) side = -1;
02032 //    HepVector3D tp = t.helix().momentum(l.dPhi());
02033 //    float p[3] = {tp.x(),tp.y(),tp.z()};
02034 //    float x[3] = {onWire.x(), onWire.y(), onWire.z()};
02035     float time = h.reccdc()->tdc + tev - tof - 1.0e9*tprop;
02036     //    float dist_p;
02037     //    float dist_m;
02038 //    float dist;
02039 //    float edist;
02040 
02041 //  cout<<"tdc: "<<h.reccdc()->tdc<<"  tev: "<<tev<<"  tof: "<<tof<<endl;
02042 
02043 
02044     double EsT0 = -1.;
02045     IMessageSvc *msgSvc;
02046     Gaudi::svcLocator()->service("MessageSvc", msgSvc);
02047     MsgStream log(msgSvc, "TCosmicFitter");
02048 
02049     IDataProviderSvc* eventSvc = NULL;
02050     Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
02051 
02052     SmartDataPtr<RecEsTimeCol> aevtimeCol (eventSvc,"/Event/Recon/RecEsTimeCol");
02053     if (aevtimeCol) {
02054       RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
02055       EsT0 = (*iter_evt)->getTest();
02056     }else{
02057       log << MSG::WARNING << "Could not find RecEsTimeCol" << endreq;
02058     }
02059 
02060     double rawTime = 0.;
02061     rawTime = h.reccdc()->tdc;
02062     double rawadc = 0.;
02063     rawadc =h.reccdc()->adc;
02064 //    double timewalk = CalibFunSvc_->getTimeWalk(layerid, 0.0);
02065 //    double timeDrift = rawTime - tof - tprop - EsTo - toWalk; 
02066 
02067 
02068 //----cal drift----//
02069     IMdcCalibFunSvc* l_mdcCalFunSvc;
02070     Gaudi::svcLocator() -> service("MdcCalibFunSvc", l_mdcCalFunSvc);
02071 
02072     double timeWalk = l_mdcCalFunSvc->getTimeWalk(layerId, rawadc);
02073     double drifttime = rawTime - tof - 1.0e9*tprop - EsT0 - timeWalk;
02074 
02075     l.setDriftTime(drifttime);
02076 
02077 
02078     double dist;
02079     double edist;
02080     int prop = _propagation;
02081 
02082     //    //calculate derivative w.r.t. time in blute force way; need update 
02083     //    //in future to speed up
02084     //    float time_p = time + 0.1;
02085     //    calcdc_driftdist_(& prop,
02086     //                        & wire,
02087     //                        & side,
02088     //                        p,
02089     //                        x,
02090     //                        & time_p,
02091     //                        & dist_p,
02092     //                        & edist);
02093     //
02094     //        float time_m = time - 0.1;
02095     //        calcdc_driftdist_(& prop,
02096     //                        & wire,                 
02097     //                      & side,
02098     //                        p,
02099     //                        x,
02100     //                        & time_m,
02101     //                        & dist_m,
02102     //                        & edist);
02104     //    dddt = (dist_p - dist_m)*5.;
02105     //               std::cout << "side=" << side << std::endl;
02106     //               std::cout << "dddt=" << dddt << std::endl;
02107 
02108 //    float dist2[2];
02109 //    float sigma_d2[2];
02110 //    float deriv2[2];
02111     float time_tmp = time;
02112 
02113     //----cal drift----//
02114 //    IMdcCalibFunSvc* l_mdcCalFunSvc;
02115     Gaudi::svcLocator() -> service("MdcCalibFunSvc", l_mdcCalFunSvc);
02116   //  dist = l_mdcCalFunSvc->rawTimeNoTOFToDist(time_tmp, layerId, wire, side, 0.0);
02117     dist =  l_mdcCalFunSvc->driftTimeToDist(time_tmp,layerId, wire, side,0.0);//by liucy 2010/05/12
02118     edist = l_mdcCalFunSvc->getSigma(layerId, side, dist, 0.0);
02119     dist = dist/10.0; //mm->cm
02120     edist = edist/10.0;
02121 
02122     distance = dist;
02123     err = edist;
02124 
02125 //    cout<<"dist: "<<dist<<" edist: "<<edist<<endl;
02126 
02127     float time_p = time - 0.1;
02128     float time_m = time + 0.1;
02129 //    float dist_p = l_mdcCalFunSvc->rawTimeNoTOFToDist(time_p, layerId, wire, side, 0.0);
02130 //    float dist_m = l_mdcCalFunSvc->rawTimeNoTOFToDist(time_m, layerId, wire, side, 0.0);
02131 //    dist_p = dist_p/10.;
02132 //    dist_m = dist_m/10.;
02133 //    dddt = (dist_m - dist_p)/0.2;
02134 //    dddt = 0;
02135 //    dddt = 0.004;
02136 
02137 //    float dist2[2] = {dist, dist};
02138 //    float sigma_d2[2] = {edist, edist};
02139 //    float deriv2[2] = {dddt_tmp, dddt_tmp}; // cm/ns
02140 //    float deriv2[2] = {0.00, 0.00};
02141 //    float deriv2[2] = {0.004, 0.004};
02142 //cout<<"dddt_tmp: "<<dddt_tmp<<endl;
02143 
02144 //zsl    calcdc_driftdist3_(& prop,
02145 //                     & wire,                
02146 //                     p,
02147 //                     x,
02148 //                     & time_tmp,
02149 //                     dist2,
02150 //                     sigma_d2, 
02151 //                     deriv2);
02152     //n.b. input and output time are slightly different because of prop. 
02153     //delay corr. in driftdist3.
02154     //    calcdc_driftdist_(& prop,
02155     //                        & wire,
02156     //                        & side,
02157     //                        p,
02158     //                        x,
02159     //                        & time,
02160     //                        & dist,
02161     //                        & edist);
02162 
02163 /*    if (side==-1) {
02164       //            std::cout << " " << std::endl;
02165       //            std::cout << dist << " " << dist2[0] << " " <<dist2[1] << std::endl;
02166       //            std::cout << edist << " " << sigma_d2[0] << " " << sigma_d2[1] << std::endl;
02167       //            std::cout << dddt  << " " << 0.001*deriv2[0] << std::endl;
02168       dist  = dist2[0];
02169       edist = sigma_d2[0];
02170       //dddt = 0.001*deriv2[0];
02171       dddt = deriv2[0];
02172     } else if(side== 1) {
02173       //            std::cout << " " << std::endl;
02174       //            std::cout << dist << " " << dist2[1] << " " <<dist2[0] << std::endl;
02175       //            std::cout << edist << " " << sigma_d2[1] << " " << sigma_d2[0] << std::endl;
02176       //            std::cout << dddt  << " " << 0.001*deriv2[1] << std::endl;
02177       dist  = dist2[1];
02178       edist = sigma_d2[1];
02179       //dddt = 0.001*deriv2[1];
02180       dddt = deriv2[1];
02181     }  
02182 
02183     distance = (double) dist;
02184 //    std::cout << "time,distance,dddt="<<time<<" "<<distance<<"  "<<dddt<<std::endl;
02185     err = (double) edist;
02186 */
02187     return;
02188 }

void THelixFitter::drift ( const TTrack ,
TMLink ,
float  t0Offset,
double &  distance,
double &  itsError 
) const [private]

calculates drift distance and its error.

by wangjk, propagation correction

Definition at line 1253 of file THelixFitter.cxx.

References _propagation, _tof, MdcRec_wirhit::adc, alpha, cos(), TMDCWireHit::dDrift(), check_raw_filter::dist, TMLink::dPhi(), TMDCWireHit::drift(), IMdcCalibFunSvc::driftTimeToDist(), IMagneticFieldSvc::getReferField(), IMdcCalibFunSvc::getSigma(), IMdcCalibFunSvc::getT0(), IMdcCalibFunSvc::getTimeWalk(), IMdcCalibFunSvc::getTprop(), TMLink::hit(), TMDCWire::layerId(), TMDCWire::localId(), m_pmgnIMF, msgSvc(), pi, TMLink::positionOnTrack(), TMLink::positionOnWire(), TMDCWireHit::reccdc(), s, TMLink::setDriftTime(), sin(), t(), tanl(), MdcRec_wirhit::tdc, tof(), Bes_Common::WARNING, TMDCWireHit::wire(), WireHitLeft, and WireHitRight.

Referenced by main().

01257                                         {
01258   //be cautious here
01259     const TMDCWireHit & h = * l.hit();
01260     const HepPoint3D & onTrack = l.positionOnTrack();
01261     const HepPoint3D & onWire = l.positionOnWire();
01262     unsigned leftRight = WireHitRight;
01263     //yzhang delete TEMP
01264     if (onWire.cross(onTrack).z() < 0.) leftRight = WireHitLeft;
01265     int charge = (t.helix().a()[2]>0) ? 1: -1;//track charge//yzhang 2012-05-03 TEMP
01266     //m_pmgnIMF NULL set mutable 2012-05-04 
01267     if(NULL == m_pmgnIMF) {
01268       Gaudi::svcLocator()->service("MagneticFieldSvc",m_pmgnIMF);
01269       if(NULL == m_pmgnIMF) {
01270         std::cout<< __FILE__<<" "<<__LINE__<<" Unable to open Magnetic field service"<<std::endl;
01271       }
01272     }
01273     const double Bz = -1000*m_pmgnIMF->getReferField();
01274 #ifdef TRKRECO_DEBUG
01275     std::cout << " orignal ambig "<<leftRight<<" charge "<< charge <<" Bz "<<Bz<<std::endl;
01276 #endif
01277     //if(charge * Bz <0){
01278     //  leftRight = (onWire.cross(onTrack).z() < 0.)
01279     //    ? WireHitLeft : WireHitRight;
01280     //}else{
01281     //  leftRight = (onWire.cross(onTrack).z() < 0.)
01282     //    ? WireHitRight : WireHitLeft;
01283     //}
01284 #ifdef TRKRECO_DEBUG
01285     std::cout << " new ambig "<<leftRight<<std::endl;
01286 #endif
01287     //zhangy
01288 
01289     //...No correction...
01290     if ((t0Offset == 0.) && (! _propagation) && (! _tof)) {
01291         distance = h.drift(leftRight);
01292         err = h.dDrift(leftRight);
01293         return;
01294     }
01295 
01296 //    float x[3]={ onWire.x(), onWire.y(), onWire.z()};
01297 //    float Tcenter = 0;
01298 
01299     //...TOF correction...
01300     float tof = 0.;
01301     if (_tof) {
01302         int imass = 3;
01303         float tl = t.helix().a()[4];
01304         float f = sqrt(1. + tl * tl);
01305         float s = fabs(t.helix().curv()) * fabs(l.dPhi()) * f;
01306         float p = f / fabs(t.helix().a()[2]);
01307 //zsl   calcdc_tof2_(& imass, & p, & s, & tof);
01308         float Mass[5] = {0.000511,0.105,0.140,0.493677,0.98327};
01309         tof = s/29.98*sqrt(1.0+(Mass[imass-1]/p)*(Mass[imass-1]/p));
01310 
01311 /*      float x[3]={ onWire.x(), onWire.y(), onWire.z()};
01312       float Rad = 81; // cm
01313       float dRho = t.helix().a()[0];
01314       float Phi0 = t.helix().a()[1];
01315       float a2 = (dRho*cos(Phi0))*(dRho*cos(Phi0));
01316       float b2 = (dRho*sin(Phi0))*(dRho*sin(Phi0));
01317       float Lproj = sqrt(Rad*Rad - a2 - b2);
01318       Tcenter = Lproj/29.98; //approxiate... cm/ns
01319       tof = s/29.98;  //cosmic
01320       if (x[1]>0) tof = -tof;
01321       */
01322     }
01323 
01324     //...T0 and propagation corrections...
01325     int wire = h.wire()->localId();
01326     int layerId = h.wire()->layerId();
01327     int side = leftRight;
01328 //    if (side == 0) side = -1;
01329 //    HepVector3D tp = t.helix().momentum(l.dPhi());
01330 //    float p[3] = {tp.x(), tp.y(), tp.z()};
01331 //    float x[3] = {onWire.x(), onWire.y(), onWire.z()};
01332 //    float time = h.reccdc()->tdc + t0Offset - tof;
01333 //    float dist;
01334 //    float edist;
01335     double dist;
01336     double edist;
01337     int prop = _propagation;
01338 
01339     const double x0 = t.helix().pivot().x();
01340     const double y0 = t.helix().pivot().y();
01341     Hep3Vector pivot_helix(x0,y0,0);
01342     const double dr    =  t.helix().a()[0];
01343     const double phi0  =  t.helix().a()[1];
01344     const double kappa =  t.helix().a()[2];
01345     const double dz    =  t.helix().a()[3];
01346     const double tanl  =  t.helix().a()[4];
01347 
01348     //yzhang 2012-05-03 delete
01349     //const double alpha = 333.564095;
01350     //yzhang add
01351     const double alpha= 333.564095/(-1000*(m_pmgnIMF->getReferField()));
01352     //zhangy
01353 
01354     const double cox = x0 + dr*cos(phi0) + alpha*cos(phi0)/kappa;
01355     const double coy = y0 + dr*sin(phi0) + alpha*sin(phi0)/kappa;
01356 
01357 
01358     unsigned nHits = t.links().length();
01359     unsigned nStereos = 0;
01360     unsigned firstLyr = 44;
01361     unsigned lastLyr = 0;
01362 
01363 
01364     HepPoint3D ontrack = l.positionOnTrack();
01365     HepPoint3D onwire = l.positionOnWire();
01366     HepPoint3D dir(ontrack.y()-coy,cox-ontrack.x(),0);           
01367     double pos_phi=onwire.phi();
01368     double dir_phi=dir.phi();
01369     while(pos_phi>pi){pos_phi-=pi;}
01370     while(pos_phi<0){pos_phi+=pi;}
01371     while(dir_phi>pi){dir_phi-=pi;}
01372     while(dir_phi<0){dir_phi+=pi;}
01373     double entrangle=dir_phi-pos_phi;
01374     while(entrangle>pi/2)entrangle-=pi;
01375     while(entrangle<(-1)*pi/2)entrangle+=pi; 
01377     double zhit = onWire.z();
01378     
01379 #ifdef TRKRECO_DEBUG 
01380     std::cout<<" onWire: "<<onWire<<std::endl;
01381     std::cout<<" zhit: "<<zhit<<std::endl;
01382 #endif
01383 
01384     const double vinner = 220.0e8; // unit is cm/s
01385     const double vouter = 240.0e8; 
01386     double vprop = 300.0e9;
01387 //    double tprop = 0.;
01388     
01389     
01390     if(layerId<8) {
01391       vprop = vinner;
01392     }
01393     else {
01394       vprop = vouter;
01395     }
01396   
01397     
01398     double EsT0 = -1.;
01399     IMessageSvc *msgSvc;
01400     Gaudi::svcLocator()->service("MessageSvc", msgSvc);
01401     MsgStream log(msgSvc, "TCosmicFitter");
01402 
01403     IDataProviderSvc* eventSvc = NULL;
01404     Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
01405 
01406     SmartDataPtr<RecEsTimeCol> aevtimeCol (eventSvc,"/Event/Recon/RecEsTimeCol");
01407     if (aevtimeCol) {
01408       RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
01409       EsT0 = (*iter_evt)->getTest();
01410     }else{
01411       log << MSG::WARNING << "Could not find RecEsTimeCol" << endreq;
01412     }
01413    
01414     double rawTime = 0.;
01415     rawTime = h.reccdc()->tdc;
01416     double rawadc = 0.;
01417     rawadc =h.reccdc()->adc;
01418     //    double timewalk = CalibFunSvc_->getTimeWalk(layerid, 0.0);
01419     //    double timeDrift = rawTime - tof - tprop - EsTo - toWalk; 
01420     
01421 
01422     //----cal drift----//
01423     IMdcCalibFunSvc* l_mdcCalFunSvc;
01424     Gaudi::svcLocator() -> service("MdcCalibFunSvc", l_mdcCalFunSvc);
01425 
01426     double tprop = l_mdcCalFunSvc->getTprop(layerId,zhit*10.);
01427 
01428     double timeWalk = l_mdcCalFunSvc->getTimeWalk(layerId, rawadc);
01429 
01430     double T0 = l_mdcCalFunSvc->getT0(layerId,wire);
01431     double drifttime = rawTime - tof - tprop - timeWalk -T0;
01432     l.setDriftTime(drifttime);
01433 
01434 #ifdef TRKRECO_DEBUG
01435     std::cout<<"timewalk is : "<< timeWalk << std::endl ;
01436     std::cout<<"T0 is : "<< T0 << std::endl ;
01437     std::cout<<"EsT0 is : "<< EsT0 << std::endl ;
01438     std::cout<<"tprop is : "<< tprop << std::endl ;
01439     std::cout<<"tof is : "<< tof << std::endl ;
01440     std::cout<<"rawTime is : "<< rawTime << std::endl ;
01441     std::cout<<"driftTime is : "<< drifttime << std::endl ;
01442 #endif
01443 //    dist = l_mdcCalFunSvc->rawTimeNoTOFToDist(h.reccdc()->tdc - tof - tprop-timeWalk, layerId, wire, side, entrangle); //default entranceangle is 0
01444     dist = l_mdcCalFunSvc->driftTimeToDist(drifttime,layerId, wire, side, entrangle);//by liucy 2010/05/12
01445     edist = l_mdcCalFunSvc->getSigma(layerId, side, dist, entrangle,tanl,zhit*10,rawadc);
01446     dist = dist/10.0; //mm->cm
01447     edist = edist/10.0;
01448 
01449 //zsl    calcdc_driftdist_(& prop,
01450 //                    & wire,
01451 //                    & side,
01452 //                    p,
01453 //                    x,
01454 //                    & time,
01455 //                    & dist,
01456 //                    & edist);
01457 
01458 //      dist = (h.reccdc()->tdc-tof) * 40./10000;
01459 
01460 //    distance = (double) dist;
01461 //    err = (double) edist;
01462     distance = dist;
01463     err = edist;
01464 
01465     return;
01466 }

void THelixFitter::dump ( const std::string message = std::string(""),
const std::string prefix = std::string("") 
) const

dumps debug information.

Reimplemented from TMFitter.

int THelixFitter::dxda ( const TMLink link,
const Helix helix,
double  dPhi,
HepVector &  dxda,
HepVector &  dyda,
HepVector &  dzda 
) const [private]

calculates dXda. 'link' and 'dPhi' are inputs. Others are outputs.

Referenced by main().

int THelixFitter::fit ( TTrackBase ,
float &  tev,
float &  tev_err,
double *  pre_chi2 = NULL,
double *  fitted_chi2 = NULL 
) const [inline]

Definition at line 267 of file THelixFitter.h.

References TTrackBase::_fitted, and main().

00268                                                                {
00269     a._fitted = false;
00270     return main(a, tev, tev_err, pre_chi2, fitted_chi2);
00271 }

int THelixFitter::fit ( TTrackBase ,
float  t0Offset,
double *  pre_chi2 = NULL,
double *  fitted_chi2 = NULL 
) const [inline]

Definition at line 254 of file THelixFitter.h.

References TTrackBase::_fitted, _freeT0, and main().

00255                                                                {
00256     a._fitted = false;
00257     if (! _freeT0) return main(a, t0Offset, pre_chi2, fitted_chi2);
00258     else {
00259         float tev = t0Offset;
00260         float tevError;
00261         return main(a, tev, tevError, pre_chi2, fitted_chi2);
00262     }
00263 }

int THelixFitter::fit ( TTrackBase ,
double *  pre_chi2,
double *  fitted_chi2 
) const [inline]

Definition at line 242 of file THelixFitter.h.

References _freeT0, and main().

00243                                                                {
00244     if (! _freeT0) return main(a, 0., pre_chi2, fitted_chi2);
00245     else {
00246         float tev = 0.;
00247         float tevError;
00248         return main(a, tev, tevError, pre_chi2, fitted_chi2);
00249     }
00250 }

int THelixFitter::fit ( TTrackBase  )  const [inline, virtual]

Implements TMFitter.

Definition at line 231 of file THelixFitter.h.

References _freeT0, and main().

Referenced by TBuilder::build(), TBuilder::buildRphi(), TBuilderCurl::buildStereo(), TBuilder::buildStereo(), TBuilderCurl::buildStereoMC(), TPerfectFinder::doit(), TTrackManager::mask(), TTrackManager::maskCurl(), TTrackManager::maskNormal(), TTrackManager::merge(), TTrackManager::refit(), TBuilder::salvage(), TCurlFinder::salvage3DTrack(), TTrackManager::T0(), and TTrackManager::T0Fit().

00231                                       {
00232     if (! _freeT0) return main(a, 0.);
00233     else {
00234         float tev = 0.;
00235         float tevError;
00236         return main(a, tev, tevError);
00237     }
00238 }

bool THelixFitter::fit2D ( bool   )  [inline]

Definition at line 175 of file THelixFitter.h.

References _fit2D.

00175                           {
00176     return _fit2D = a;
00177 }

bool THelixFitter::fit2D ( void   )  const [inline]

sets/returns 2D flag.

Definition at line 169 of file THelixFitter.h.

References _fit2D.

Referenced by TTrackManager::determineT0().

00169                               {
00170     return _fit2D;
00171 }

void TMFitter::fitDone ( TTrackBase  )  const [protected, inherited]

sets the fitted flag. (Bad implementation)

Definition at line 24 of file TMFitter.cxx.

References t().

Referenced by TRobustLineFitter::fit(), TLineFitter::fit(), and TCircleFitter::fit().

00024                                       {
00025     t._fitted = true;
00026 }

bool THelixFitter::freeT0 ( bool   )  [inline]

Definition at line 281 of file THelixFitter.h.

References _freeT0.

00281                            {
00282     return _freeT0 = a;
00283 }

bool THelixFitter::freeT0 ( void   )  const [inline]

sets/returns free T0 flag.

Definition at line 275 of file THelixFitter.h.

References _freeT0.

Referenced by TTrackManager::fittingFlag(), and TBuilder::TBuilder().

00275                                {
00276     return _freeT0;
00277 }

IMagneticFieldSvc* THelixFitter::getMagneticFieldPointer ( void   )  const [inline]

Definition at line 98 of file THelixFitter.h.

References m_pmgnIMF.

Referenced by TBuilder::build().

00098 {return m_pmgnIMF;}

int THelixFitter::main ( TTrackBase ,
float &  tev,
float &  tev_err,
double *  pre_chi2 = NULL,
double *  fitted_chi2 = NULL 
) const [private]

main routine for free T0.

Definition at line 1471 of file THelixFitter.cxx.

References _fit2D, _fitted_chi2, _pre_chi2, _sag, AxialHits(), DBL_MAX, Helix::direction(), drift(), dxda(), ganga-rec::j, NStereoHits(), NTrailMax, TTrackBase::objectType(), t(), TFitAlreadyFitted, TFitErrorFewHits, TFitFailed, TFitUnavailable, Track, WireHitLeft, and WireHitRight.

01472                                                                 {
01473 //=====================================================================
01474     //...Initialize
01475     _pre_chi2 = _fitted_chi2 = 0.;
01476     if(pre_chi2)*pre_chi2 = _pre_chi2;
01477     if(fitted_chi2)*fitted_chi2 = _fitted_chi2;
01478 
01479     //...Type check...
01480     if (b.objectType() != Track) return TFitUnavailable;
01481     TTrack & t = (TTrack &) b;
01482 
01483     //...Already fitted ?...
01484     if (t.fitted()) return TFitAlreadyFitted;
01485 
01486     //...Count # of hits...
01487     AList<TMLink> cores = t.cores();
01488     if (_fit2D) cores = AxialHits(cores);
01489     unsigned nCores = cores.length();
01490     unsigned nStereoCores = NStereoHits(cores);
01491 
01492     //...2D or 3D...
01493     bool fitBy2D = _fit2D;
01494     if (! fitBy2D) fitBy2D = (! nStereoCores);
01495 
01496     //...Check # of hits...
01497     if (! fitBy2D) {
01498         if ((nStereoCores < 2) || (nCores - nStereoCores < 3))
01499             return TFitErrorFewHits;
01500     }
01501     else {
01502         if (nCores < 3) return TFitErrorFewHits;
01503     }
01504 
01505     //...Setup...
01506     Vector a(6), da(6);
01507     Vector a_5dim(5);
01508     for (unsigned j = 0; j < 5; j++) a[j] = t.helix().a()[j];
01509     a[5] = tev;
01510     Vector dxda(5);
01511     Vector dyda(5);
01512     Vector dzda(5);
01513     Vector dDda(6);
01514     Vector dDda_5dim(5);
01515     Vector dchi2da(6);
01516     SymMatrix d2chi2d2a(6, 0);
01517     static const SymMatrix zero6(6, 0);
01518     double chi2;
01519     double chi2Old = DBL_MAX;
01520 //    const double convergence = Convergence;
01521     const double convergence = 1.0e-4;   //Liuqg
01522     bool allAxial = true;
01523     Matrix e(3, 3);
01524     Vector f(3);
01525     int err = 0;
01526     double factor = 1.0;//jtanaka0715
01527 
01528     //...Fitting loop...
01529     unsigned nTrial = 0;
01530     while (nTrial < NTrailMax) {
01531 
01532         //...Set up...
01533         chi2 = 0.;
01534         for (unsigned j = 0; j < 6; j++) dchi2da[j] = 0.;
01535         d2chi2d2a = zero6;
01536 
01537         //...Loop with hits...
01538         unsigned i = 0;
01539         while (TMLink * l = cores[i++]) {
01540             const TMDCWireHit & h = * l->hit();
01541 
01542             //...Cal. closest points...
01543             t.approach(* l, _sag);
01544             double dPhi = l->dPhi();
01545             const HepPoint3D & onTrack = l->positionOnTrack();
01546             const HepPoint3D & onWire = l->positionOnWire();
01547             unsigned leftRight = (onWire.cross(onTrack).z() < 0.) ? WireHitLeft : WireHitRight;
01548 
01549             //...Obtain drift distance and its error...
01550             double distance;
01551             double eDistance;
01552             double dddt;
01553             drift(t, * l, tev, distance, eDistance, dddt);
01554 //          l->drift(distance,0);
01555 //          l->drift(distance,1);
01556 //          l->dDrift(distance,0);
01557 //          l->dDrift(distance,1);
01558            
01559 
01560             double inv_eDistance2 = 1./(eDistance * eDistance);
01561 
01562 
01563             //...Residual...
01564             HepVector3D v = onTrack - onWire;
01565             double vmag = v.mag();
01566             double dDistance = vmag - distance;
01567 
01568             //...dxda...
01569             this->dxda(* l, t.helix(), dPhi, dxda, dyda, dzda);
01570 
01571             //...Chi2 related...
01572             // dDda = (v.x() * dxda + v.y() * dyda + v.z() * dzda) / vmag;
01573             double vw[3] = { h.wire()->direction().x(),
01574                              h.wire()->direction().y(),
01575                              h.wire()->direction().z() };
01576             double vwxy = vw[0]*vw[1];
01577             double vwyz = vw[1]*vw[2];
01578             double vwzx = vw[2]*vw[0];
01579             dDda_5dim = (vmag > 0.)
01580                 ? ((v.x() * (1. - vw[0] * vw[0]) -
01581                     v.y() * vwxy - v.z() * vwzx)
01582                    * dxda + 
01583                    (v.y() * (1. - vw[1] * vw[1]) -
01584                     v.z() * vwyz - v.x() * vwxy)
01585                    * dyda + 
01586                    (v.z() * (1. - vw[2] * vw[2]) -
01587                     v.x() * vwzx - v.y() * vwyz)
01588                    * dzda) / vmag
01589                 : Vector(5,0);
01590             if (vmag <= 0.0) {
01591                 std::cout << "    in fit " << onTrack << ", " << onWire;
01592                 h.dump();
01593             }
01594             //      for (unsigned j = 0; j < 5; j++) dDda[j] = dDda_5dim[j];
01595             dDda[0] = dDda_5dim[0];
01596             dDda[1] = dDda_5dim[1];
01597             dDda[2] = dDda_5dim[2];
01598             dDda[3] = dDda_5dim[3];
01599             dDda[4] = dDda_5dim[4];
01600             dDda[5] = -dddt;
01601 
01602             dchi2da += (dDistance * inv_eDistance2) * dDda;
01603             d2chi2d2a += vT_times_v(dDda) * inv_eDistance2;
01604             double pChi2 = dDistance * dDistance * inv_eDistance2;
01605             chi2 += pChi2;
01606 
01607             //...Store results...
01608             l->update(onTrack, onWire, leftRight, pChi2);
01609         }
01610 
01611         //...Save chi2 information...
01612         if(nTrial == 0){
01613           _pre_chi2 = chi2;
01614           _fitted_chi2 = chi2;
01615         }else _fitted_chi2 = chi2;
01616 
01617         //...Check condition...
01618         double change = chi2Old - chi2;
01619         if (fabs(change) < convergence) break;
01620         //temp
01621                 factor = 1.0;
01622         //temp
01623         if (change < 0.) {
01624 //          a += factor * da;
01625 //          t._helix->a(a);
01626 //          break;
01627             factor = 0.5;
01628         }
01629 
01630         chi2Old = chi2;
01631 
01632         //...Cal. helix parameters for next loop...
01633         if (fitBy2D) {
01634             f = dchi2da.sub(1, 4);
01635             e = d2chi2d2a.sub(1, 4);
01636             f = solve(e, f);
01637             da[0] = f[0];
01638             da[1] = f[1];
01639             da[2] = f[2];
01640             da[3] = f[3];
01641             da[4] = 0.;
01642             da[5] = 0.;
01643         }
01644         else {
01645             da = solve(d2chi2d2a, dchi2da);
01646         }
01647 
01648         a -= factor * da;
01649 
01650         //      for (unsigned j = 0; j < 5; j++) a_5dim[j] = a[j];
01651         a_5dim[0] = a[0];
01652         a_5dim[1] = a[1];
01653         a_5dim[2] = a[2];
01654         a_5dim[3] = a[3];
01655         a_5dim[4] = a[4];
01656         t._helix->a(a_5dim);
01657         tev = a[5];
01658         //temp
01659         //      if(nTrial == 0) std::cout << "initial chi2=" <<chi2 << std::endl;
01660         //temp
01661         ++nTrial;
01662 
01663 #ifdef TRKRECO_DEBUG
01664         std::cout << "fit " << nTrial-1<< " : " << chi2 << " : " << change << std::endl;
01665 #endif
01666     }
01667 
01668     //...Cal. error matrix...
01669     SymMatrix Ea(6, 0);
01670     unsigned dim;
01671     if (fitBy2D) {
01672         dim = 4;
01673         SymMatrix Eb(4, 0), Ec(4, 0);
01674         Eb = d2chi2d2a.sub(1, 4);
01675         Ec = Eb.inverse(err);
01676         Ea[0][0] = Ec[0][0];
01677         Ea[0][1] = Ec[0][1];
01678         Ea[0][2] = Ec[0][2];
01679         Ea[0][3] = Ec[0][3];
01680         Ea[1][1] = Ec[1][1];
01681         Ea[1][2] = Ec[1][2];
01682         Ea[1][3] = Ec[1][3];
01683         Ea[2][2] = Ec[2][2];
01684         Ea[2][3] = Ec[2][3];
01685         Ea[3][3] = Ec[3][3];
01686     }
01687     else {
01688         dim = 6;
01689         Ea = d2chi2d2a.inverse(err);
01690         //        std::cout << "err flg=" << err << std::endl;
01691     }
01692 
01693 
01694     //...Store information...
01695     if (! err) {
01696         for (unsigned j = 0; j < 5; j++) a_5dim[j] = a[j];
01697         SymMatrix Ea_5dim(5, 0);
01698         Ea_5dim = Ea.sub(1, 5);
01699         t._helix->a(a_5dim);
01700         t._helix->Ea(Ea_5dim);
01701         tev = a[5];
01702         tev_err = sqrt(Ea[5][5]);
01703         //temp
01704         //      std::cout << "nTrial=" << nTrial << std::endl;
01705         //      std::cout << "chi2="   << chi2   << std::endl;
01706         //      std::cout << "pt:" << fabs(1./a_5dim[2])<< std::endl;
01707         //      std::cout << "tev,tev_err="<<tev<<" "<<tev_err<<std::endl;
01708         //temp
01709 
01710         t._fitted = true;
01711     }
01712     else {
01713         err = TFitFailed;
01714     }
01715 
01716     t._ndf = nCores - dim;
01717     t._chi2 = chi2;
01718 
01719     if(pre_chi2)*pre_chi2 = _pre_chi2;
01720     if(fitted_chi2)*fitted_chi2 = _fitted_chi2;
01721 
01722     return err;
01723 }

int THelixFitter::main ( TTrackBase ,
float  t0Offset,
double *  pre_chi2 = NULL,
double *  fitted_chi2 = NULL 
) const [private]

main routine for fixed T0.

Definition at line 150 of file THelixFitter.cxx.

References _fit2D, _fitted_chi2, _pre_chi2, _sag, AxialHits(), chi2(), Convergence, DBL_MAX, TMDCWire::direction(), drift(), TMDCWireHit::dump(), dxda(), showlog::err, genRecEmupikp::i, ganga-rec::j, NStereoHits(), NTrailMax, TTrackBase::objectType(), TMDCWireHit::state(), t(), TFitAlreadyFitted, TFitErrorFewHits, TFitFailed, TFitUnavailable, Track, TrkRecoHelixFitterChisqMax, v, TMDCWireHit::wire(), WireHitLeft, WireHitPatternLeft, WireHitPatternRight, and WireHitRight.

Referenced by fit().

00151                                                                 {
00152 #ifdef TRKRECO_DEBUG
00153 /*
00154         if (first) {
00155         first = false;
00156         extern BelleTupleManager * BASF_Histogram;
00157         BelleTupleManager * m = BASF_Histogram;
00158         _nCall[0] = m->histogram("HF nCall all", 1, 0., 1.);
00159         _nCall[1] = m->histogram("HF nCall conf f2d l0", 1, 0., 1.);
00160         _nCall[2] = m->histogram("HF nCall conf f3d l0", 1, 0., 1.);
00161         _nCall[3] = m->histogram("HF nCall conf f2d l1", 1, 0., 1.);
00162         _nCall[4] = m->histogram("HF nCall conf f3d l1", 1, 0., 1.);
00163         _nCall[5] = m->histogram("HF nCall conf s2d", 1, 0., 1.);
00164         _nCall[6] = m->histogram("HF nCall conf s3d", 1, 0., 1.);
00165         _nCall[7] = m->histogram("HF nCall other", 1, 0., 1.);
00166         _nTrial[0] = m->histogram("HF nTrial all", 100, 0., 100.);
00167         _nTrial[1] = m->histogram("HF nTrial conf f2d l0", 100, 0., 100.);
00168         _nTrial[2] = m->histogram("HF nTrial conf f3d l0", 100, 0., 100.);
00169         _nTrial[3] = m->histogram("HF nTrial conf f2d l1", 100, 0., 100.);
00170         _nTrial[4] = m->histogram("HF nTrial conf f3d l1", 100, 0., 100.);
00171         _nTrial[5] = m->histogram("HF nTrial conf s2d", 100, 0., 100.);
00172         _nTrial[6] = m->histogram("HF nTrial conf s3d", 100, 0., 100.);
00173         _nTrial[7] = m->histogram("HF nTrial other", 100, 0., 100.);
00174         _pull[0][0][0] = m->histogram("HF pull ax true all",
00175                                       100, 0., 5000.);
00176         _pull[0][0][2] = m->histogram("HF pull ax true conf f3d l0",
00177                                       100, 0., 5000.);
00178         _pull[0][0][4] = m->histogram("HF pull ax true conf f3d l1",
00179                                       100, 0., 5000.);
00180         _pull[0][0][6] = m->histogram("HF pull ax true conf s3d",
00181                                       100, 0., 5000.);
00182         _pull[0][0][7] = m->histogram("HF pull ax true other",
00183                                       100, 0., 5000.);
00184         _pull[1][0][0] = m->histogram("HF pull st true all",
00185                                       100, 0., 5000.);
00186         _pull[1][0][2] = m->histogram("HF pull st true conf f3d l0", 
00187                                       100, 0., 5000.);
00188         _pull[1][0][4] = m->histogram("HF pull st true conf f3d l1",
00189                                       100, 0., 5000.);
00190         _pull[1][0][6] = m->histogram("HF pull st true conf s3d",
00191                                       100, 0., 5000.);
00192         _pull[1][0][7] = m->histogram("HF pull st true other",
00193                                       100, 0., 5000.);
00194         _pull[0][1][0] = m->histogram("HF pull ax wrong all",
00195                                       100, 0., 5000.);
00196         _pull[0][1][2] = m->histogram("HF pull ax wrong conf f3d l0",
00197                                       100, 0., 5000.);
00198         _pull[0][1][4] = m->histogram("HF pull ax wrong conf f3d l1",
00199                                       100, 0., 5000.);
00200         _pull[0][1][6] = m->histogram("HF pull ax wrong conf s3d",
00201                                       100, 0., 5000.);
00202         _pull[0][1][7] = m->histogram("HF pull ax wrong other",
00203                                       100, 0., 5000.);
00204         _pull[1][1][0] = m->histogram("HF pull st wrong all",
00205                                       100, 0., 5000.);
00206         _pull[1][1][2] = m->histogram("HF pull st wrong conf f3d l0",
00207                                       100, 0., 5000.);
00208         _pull[1][1][4] = m->histogram("HF pull st wrong conf f3d l1",
00209                                       100, 0., 5000.);
00210         _pull[1][1][6] = m->histogram("HF pull st wrong conf s3d",
00211                                       100, 0., 5000.);
00212         _pull[1][1][7] = m->histogram("HF pull st wrong other",
00213                                       100, 0., 5000.);
00214         _nTrialPositive = m->histogram("HF nTrial +", 100, 0., 100.);
00215         _nTrialNegative = m->histogram("HF nTrial -", 100, 0., 100.);
00216     }
00217     _nCall[0]->accumulate(.5);
00218     if (TConformalFinder::_stage == ConformalOutside)
00219         _nCall[7]->accumulate(.5);
00220     else if (TConformalFinder::_stage == ConformalFast2DLevel0)
00221         _nCall[1]->accumulate(.5);
00222     else if (TConformalFinder::_stage == ConformalFast3DLevel0)
00223         _nCall[2]->accumulate(.5);
00224     else if (TConformalFinder::_stage == ConformalFast2DLevel1)
00225         _nCall[3]->accumulate(.5);
00226     else if (TConformalFinder::_stage == ConformalFast3DLevel1)
00227         _nCall[4]->accumulate(.5);
00228     else if (TConformalFinder::_stage == ConformalSlow2D)
00229         _nCall[5]->accumulate(.5);
00230     else if (TConformalFinder::_stage == ConformalSlow3D)
00231         _nCall[6]->accumulate(.5);
00232     bool posi = true;
00233     const TTrackHEP & hep = Links2HEP(b.links());
00234 */
00235 #endif
00236     //...Initialize
00237     _pre_chi2 = _fitted_chi2 = 0.;
00238     if(pre_chi2)*pre_chi2 = _pre_chi2;
00239     if(fitted_chi2)*fitted_chi2 = _fitted_chi2;
00240 
00241     //...Type check...
00242     if (b.objectType() != Track) return TFitUnavailable;
00243     TTrack & t = (TTrack &) b;
00244 
00245     //...Already fitted ?...
00246     if (t.fitted()) return TFitAlreadyFitted;
00247 
00248     //...Count # of hits...
00249     AList<TMLink> cores = t.cores();
00250 #ifdef TRKRECO_DEBUG
00251     cout<<__FILE__<<" cores in helix = "<<cores.length()<<endl;
00252 #endif
00253     if (_fit2D) cores = AxialHits(cores);
00254     unsigned nCores = cores.length();
00255     unsigned nStereoCores = NStereoHits(cores);
00256 
00257     //...2D or 3D...
00258     bool fitBy2D = _fit2D;
00259     if (! fitBy2D) fitBy2D = (! nStereoCores);
00260 
00261     //...Check # of hits...
00262     if (! fitBy2D) {
00263         if ((nStereoCores < 2) || (nCores - nStereoCores < 3))
00264             return TFitErrorFewHits;
00265     }
00266     else {
00267         if (nCores < 3) return TFitErrorFewHits;
00268     }
00269 
00270     //...Setup...
00271     Vector a(5), da(5);
00272     a = t.helix().a();
00273     Vector dxda(5);
00274     Vector dyda(5);
00275     Vector dzda(5);
00276     Vector dDda(5);
00277     Vector dchi2da(5);
00278     SymMatrix d2chi2d2a(5, 0);
00279     static const SymMatrix zero5(5, 0);
00280     double chi2;
00281     double chi2Old = DBL_MAX;
00282     const double convergence = Convergence;
00283     bool allAxial = true;
00284     Matrix e(3, 3);
00285     Vector f(3);
00286     int err = 0;
00287     double factor = 1.0;//jtanaka0715
00288 
00289     //...For bad hit rejection...(by JT, 2001/04/12)...
00290     int flagBad = 0;
00291     if (TrkRecoHelixFitterChisqMax != 0.)
00292         flagBad = 1;
00293     AList<TMLink> initBadWires; 
00294     unsigned nInitBadWires = 0;
00295     Vector initBadDchi2da(5);
00296     SymMatrix initBadD2chi2d2a(5, 0);
00297     for (unsigned j = 0; j < 5; ++j) initBadDchi2da[j] = 0.;
00298     double initBadChi2 = 0.;
00299 
00300     //...Fitting loop...
00301     unsigned nTrial = 0;
00302     while (nTrial < NTrailMax) {
00303 
00304         //...Set up...
00305         chi2 = 0.;
00306         for (unsigned j = 0; j < 5; j++) dchi2da[j] = 0.;
00307         d2chi2d2a = zero5;
00308 
00309     //yuany
00310 #ifdef TRKRECO_DEBUG
00311         cout<<"helix fitter a5 "<<t.helix().a()<< " cores.length "<<cores.length()<<endl;
00312 #endif
00313         //...Loop with hits...
00314         unsigned i = 0;
00315         while (TMLink * l = cores[i++]) {
00316             const TMDCWireHit & h = * l->hit();
00317     //yuany
00318 #ifdef TRKRECO_DEBUG
00319             cout<<"trial "<<nTrial<<" wire name "<<l->wire()->name()<<"    L "<<(h.state()&WireHitPatternLeft)<<" R "<<(h.state()&WireHitPatternRight)<<" link "<<l->leftRight()<<endl;
00320 #endif
00321             //...Cal. closest points...
00322             t.approach(* l, _sag);
00323             double dPhi = l->dPhi();
00324             const HepPoint3D & onTrack = l->positionOnTrack();
00325             const HepPoint3D & onWire = l->positionOnWire();
00326             unsigned leftRight = (onWire.cross(onTrack).z() < 0.)
00327                 ? WireHitLeft : WireHitRight;
00328 
00329             //...Obtain drift distance and its error...
00330             double distance;
00331             double eDistance;
00332             drift(t, * l, t0Offset, distance, eDistance);
00333             l->drift(distance,0);
00334             l->drift(distance,1);
00335             l->dDrift(eDistance,0);
00336             l->dDrift(eDistance,1);
00337 
00338 
00339             double inv_eDistance2 = 1. / (eDistance * eDistance);
00340             
00341             //...Residual...
00342             HepVector3D v = onTrack - onWire;
00343             double vmag = v.mag();
00344 #ifdef TRKRECO_DEBUG
00345             std::cout<<"THelixFitter::eDistance-----"<<eDistance<<endl;
00346             cout<<"  vmag = "<<vmag<<"   distance = "<<distance<<"  eDistance = "<<eDistance<<endl;
00347 #endif
00348             double dDistance = vmag - distance;
00349             
00350             //...dxda...
00351             this->dxda(* l, t.helix(), dPhi, dxda, dyda, dzda);
00352 
00353             //...Chi2 related...
00354             // dDda = (v.x() * dxda + v.y() * dyda + v.z() * dzda) / vmag;
00355             // Vector3 vw = h.wire()->direction();
00356             double vw[3] = { h.wire()->direction().x(),
00357                              h.wire()->direction().y(),
00358                              h.wire()->direction().z() };
00359             double vwxy = vw[0]*vw[1];
00360             double vwyz = vw[1]*vw[2];
00361             double vwzx = vw[2]*vw[0];
00362             dDda = (vmag > 0.)
00363                 ? ((v.x() * (1. - vw[0] * vw[0]) -
00364                     v.y() * vwxy - v.z() * vwzx)
00365                    * dxda + 
00366                    (v.y() * (1. - vw[1] * vw[1]) -
00367                     v.z() * vwyz - v.x() * vwxy)
00368                    * dyda + 
00369                    (v.z() * (1. - vw[2] * vw[2]) -
00370                     v.x() * vwzx - v.y() * vwyz)
00371                    * dzda) / vmag
00372                 : Vector(5,0);
00373             if (vmag <= 0.0) {
00374                 std::cout << "    in fit " << onTrack << ", " << onWire;
00375                 h.dump();
00376             }
00377             double pChi2 = dDistance * dDistance * inv_eDistance2;
00378 #ifdef TRKRECO_DEBUG
00379             std::cout<<"THelixFitter::dDistance"<<dDistance<<" inv_eDistance2 "<<inv_eDistance2<<endl; 
00380             cout<<"Liuqg check ... .. pChi2 = "<<pChi2<<endl;
00381 #endif
00382 
00383             //...Bad hit rejection...
00384             if (flagBad && nTrial == 0) {
00385                 if (pChi2 > TrkRecoHelixFitterChisqMax) {
00386                     initBadWires.append(l);
00387                     initBadDchi2da += (dDistance * inv_eDistance2) * dDda;
00388                     initBadD2chi2d2a += vT_times_v(dDda) * inv_eDistance2;
00389                     initBadChi2 += pChi2;
00390                 }
00391             }
00392             else {
00393                 dchi2da += (dDistance * inv_eDistance2) * dDda;
00394                 d2chi2d2a += vT_times_v(dDda) * inv_eDistance2;
00395                 chi2 += pChi2;      
00396 
00397                 //...Store results...
00398                 l->update(onTrack, onWire, leftRight, pChi2);
00399             }
00400 
00401 #ifdef TRKRECO_DEBUG
00402 //          if ((! fitBy2D) && (nTrial == 0)) {
00403 //              unsigned as = 0;
00404 //              if (l->hit()->wire()->stereo()) as = 1;
00405 //              unsigned mt = 0;
00406 //              if (& hep != l->hit()->mc()->hep()) mt = 1;
00407 
00408 //              _pull[as][mt][0]->accumulate(pChi2);
00409 //              if (TConformalFinder::_stage == ConformalOutside)
00410 //                  _pull[as][mt][7]->accumulate(pChi2);
00411 //              else if (TConformalFinder::_stage == ConformalFast3DLevel0)
00412 //                  _pull[as][mt][2]->accumulate(pChi2);
00413 //              else if (TConformalFinder::_stage == ConformalFast3DLevel1)
00414 //                  _pull[as][mt][4]->accumulate(pChi2);
00415 //              else if (TConformalFinder::_stage == ConformalSlow3D)
00416 //                  _pull[as][mt][6]->accumulate(pChi2);
00417 //          }
00418 #endif
00419         }
00420 
00421         //...Bad hit rejection...
00422         if (flagBad && nTrial == 0) {
00423             if ((initBadWires.length() == 1 || initBadWires.length() == 2) &&
00424                 nCores >= 20 &&
00425                 chi2 / (double)(nCores - initBadWires.length()) < 10.) {
00426                 cores.remove(initBadWires);
00427                 nInitBadWires = initBadWires.length();
00428             }
00429             else if (initBadWires.length() != 0) {
00430                 dchi2da += initBadDchi2da;
00431                 d2chi2d2a += initBadD2chi2d2a;
00432                 chi2 += initBadChi2;
00433             }
00434         }
00435 
00436         //...Save chi2 information...
00437         if (nTrial == 0) {
00438             _pre_chi2 = chi2;
00439             _fitted_chi2 = chi2;
00440         }
00441         else {
00442             _fitted_chi2 = chi2;
00443         }
00444 
00445         //...Check condition...
00446         double change = chi2Old - chi2;
00447 #ifdef TRKRECO_DEBUG_DETAIL
00448         std::cout<<" chi2 change  "<<change <<" convergence  "<<convergence <<" break?  "<<(fabs(change) < convergence == true)<<std::endl;
00449 #endif
00450         if (fabs(change) < convergence) break;
00451         if (change < 0.) {
00452 //          a += factor * da;
00453 //          t._helix->a(a);
00454 //          break;
00455             factor = 0.5;
00456         }
00457         chi2Old = chi2;
00458 
00459         //...Cal. helix parameters for next loop...
00460         if (fitBy2D) {
00461             f = dchi2da.sub(1, 3);
00462             e = d2chi2d2a.sub(1, 3);
00463             f = solve(e, f);
00464             da[0] = f[0];
00465             da[1] = f[1];
00466             da[2] = f[2];
00467             da[3] = 0.;
00468             da[4] = 0.;
00469         }
00470         else {
00471             da = solve(d2chi2d2a, dchi2da);
00472         }
00473 
00474         a -= factor * da;
00475         t._helix->a(a);
00476         ++nTrial;
00477 
00478         // jtanaka 001008
00479         //if( fabs(a[3]) > 200. ){
00480         // yiwasaki 001010
00481         if( fabs(a[3]) > 1000. ){
00482           // stop "fit" and return error.
00483           //std::cout << "Stop Fit... " << a << std::endl;
00484           err = 1;
00485           break;
00486         }
00487 #ifdef TRKRECO_DEBUG_DETAIL
00488         std::cout << "            fit " << nTrial-1<< " : " << chi2 << " : "
00489                   << change << std::endl;
00490 #endif
00491     }
00492 
00493 #ifdef TRKRECO_DEBUG
00494 /*
00495     _nTrial[0]->accumulate(float(nTrial) + .5);
00496     if (TConformalFinder::_stage == ConformalOutside)
00497         _nTrial[7]->accumulate(float(nTrial) + .5);
00498     else if (TConformalFinder::_stage == ConformalFast2DLevel0)
00499         _nTrial[1]->accumulate(float(nTrial) + .5);
00500     else if (TConformalFinder::_stage == ConformalFast3DLevel0)
00501         _nTrial[2]->accumulate(float(nTrial) + .5);
00502     else if (TConformalFinder::_stage == ConformalFast2DLevel1)
00503         _nTrial[3]->accumulate(float(nTrial) + .5);
00504     else if (TConformalFinder::_stage == ConformalFast3DLevel1)
00505         _nTrial[4]->accumulate(float(nTrial) + .5);
00506     else if (TConformalFinder::_stage == ConformalSlow2D)
00507         _nTrial[5]->accumulate(float(nTrial) + .5);
00508     else if (TConformalFinder::_stage == ConformalSlow3D)
00509         _nTrial[6]->accumulate(float(nTrial) + .5);
00510 
00511     if (posi) _nTrialPositive->accumulate((float) nTrial + .5);
00512     else _nTrialNegative->accumulate((float) nTrial + .5);
00513 */
00514 #endif
00515 
00516     //...Cal. error matrix...
00517     SymMatrix Ea(5, 0);
00518     unsigned dim;
00519     if (fitBy2D) {
00520         dim = 3;
00521         SymMatrix Eb(3, 0), Ec(3, 0);
00522         Eb = d2chi2d2a.sub(1, 3);
00523         Ec = Eb.inverse(err);
00524         Ea[0][0] = Ec[0][0];
00525         Ea[0][1] = Ec[0][1];
00526         Ea[0][2] = Ec[0][2];
00527         Ea[1][1] = Ec[1][1];
00528         Ea[1][2] = Ec[1][2];
00529         Ea[2][2] = Ec[2][2];
00530     }
00531     else {
00532         dim = 5;
00533         Ea = d2chi2d2a.inverse(err);
00534     }
00535 
00536     //...Store information...
00537     if (! err) {
00538         t._helix->a(a);
00539         t._helix->Ea(Ea);
00540         t._fitted = true;
00541     }
00542     else {
00543         err = TFitFailed;
00544     }
00545 
00546     t._charge = copysign(1., a[2]);    
00547     t._ndf = nCores - dim -nInitBadWires;
00548     t._chi2 = chi2;
00549 
00550     //...Treatment for bad wires...
00551     if (nInitBadWires) {
00552         for  (unsigned i = 0; i < nInitBadWires; i++) {
00553             TMLink * l = initBadWires[i];
00554             t.approach(* l, _sag);
00555             double dPhi = l->dPhi();
00556             const HepPoint3D & onTrack = l->positionOnTrack();
00557             const HepPoint3D & onWire = l->positionOnWire();
00558             HepVector3D v = onTrack - onWire;
00559             double vmag = v.mag();
00560             unsigned leftRight = (onWire.cross(onTrack).z() < 0.)
00561                 ? WireHitLeft : WireHitRight;
00562             double distance;
00563             double eDistance;
00564             drift(t, * l, t0Offset, distance, eDistance);
00565             l->drift(distance,0);
00566             l->drift(distance,1);
00567             l->dDrift(eDistance,0);
00568             l->dDrift(eDistance,1);
00569 
00570 
00571             double inv_eDistance2 = 1. / (eDistance * eDistance);
00572             double dDistance = vmag - distance;
00573             double pChi2 = dDistance * dDistance * inv_eDistance2;
00574             l->update(onTrack, onWire, leftRight, pChi2);
00575         }
00576 #ifdef TRKRECO_DEBUG_DETAIL
00577         std::cout << "            HelixFitter : # of rejected hits="
00578                   << nInitBadWires << endl;
00579 #endif
00580     }
00581 
00582     if (pre_chi2) * pre_chi2 = _pre_chi2;
00583     if (fitted_chi2) * fitted_chi2 = _fitted_chi2;
00584 
00585     return err;
00586 }

const std::string & TMFitter::name ( void   )  const [inline, inherited]

returns name.

Definition at line 73 of file TMFitter.h.

References TMFitter::_name.

00073                          {
00074     return _name;
00075 }

double THelixFitter::preChi2 ( void   )  const [inline]

returns sum of chi2 before fit.

Definition at line 299 of file THelixFitter.h.

References _pre_chi2.

00299                                 {
00300     return _pre_chi2;
00301 }

bool THelixFitter::propagation ( bool   )  [inline]

Definition at line 199 of file THelixFitter.h.

References _propagation, and propagation().

00199                                 {
00200     if (a) _propagation = 1;
00201     else   _propagation = 0;
00202     return propagation();
00203 }

bool THelixFitter::propagation ( void   )  const [inline]

sets/returns propagation-delay correction flag.

Definition at line 193 of file THelixFitter.h.

References _propagation.

Referenced by TBuilderCurl::buildStereo(), TTrackManager::determineT0(), TTrackManager::fittingFlag(), propagation(), TBuilderCurl::setParam(), TBuilder::TBuilder(), and TBuilderCurl::TBuilderCurl().

00193                                     {
00194     return (bool) _propagation;
00195 }

bool THelixFitter::sag ( bool   )  [inline]

Definition at line 187 of file THelixFitter.h.

References _sag.

00187                         {
00188     return _sag = a;
00189 }

bool THelixFitter::sag ( void   )  const [inline]

sets/returns sag correction flag.

Definition at line 181 of file THelixFitter.h.

References _sag.

Referenced by TBuilderCurl::buildStereo(), TTrackManager::fittingFlag(), TBuilderCurl::setParam(), TBuilder::TBuilder(), and TBuilderCurl::TBuilderCurl().

00181                             {
00182     return _sag;
00183 }

bool THelixFitter::tanl ( bool   )  [inline]

Definition at line 225 of file THelixFitter.h.

References _tanl.

00225                          {
00226     return _tanl = a;
00227 }

bool THelixFitter::tanl ( void   )  const [inline]

sets/returns tanLambda correction flag.

Definition at line 219 of file THelixFitter.h.

References _tanl.

Referenced by drift().

00219                              {
00220     return _tanl;
00221 }

bool THelixFitter::tof ( bool   )  [inline]

Definition at line 213 of file THelixFitter.h.

References _tof.

00213                         {
00214     return _tof = a;
00215 }

bool THelixFitter::tof ( void   )  const [inline]

sets/returns propagation-delay correction flag.

Definition at line 207 of file THelixFitter.h.

References _tof.

Referenced by TBuilderCurl::buildStereo(), TTrackManager::determineT0(), drift(), TTrackManager::fittingFlag(), TBuilderCurl::setParam(), TBuilder::TBuilder(), and TBuilderCurl::TBuilderCurl().

00207                             {
00208     return _tof;
00209 }


Member Data Documentation

unsigned THelixFitter::_corrections [private]

Definition at line 139 of file THelixFitter.h.

Referenced by corrections().

double THelixFitter::_driftTime [private]

Definition at line 147 of file THelixFitter.h.

bool THelixFitter::_fit2D [private]

Definition at line 137 of file THelixFitter.h.

Referenced by fit2D(), and main().

double THelixFitter::_fitted_chi2 [mutable, private]

Definition at line 149 of file THelixFitter.h.

Referenced by chi2(), and main().

bool THelixFitter::_freeT0 [private]

Definition at line 138 of file THelixFitter.h.

Referenced by fit(), and freeT0().

double THelixFitter::_pre_chi2 [mutable, private]

Definition at line 148 of file THelixFitter.h.

Referenced by main(), and preChi2().

int THelixFitter::_propagation [private]

Definition at line 142 of file THelixFitter.h.

Referenced by drift(), and propagation().

bool THelixFitter::_sag [private]

Definition at line 141 of file THelixFitter.h.

Referenced by main(), and sag().

bool THelixFitter::_tanl [private]

Definition at line 144 of file THelixFitter.h.

Referenced by tanl().

bool THelixFitter::_tof [private]

Definition at line 143 of file THelixFitter.h.

Referenced by drift(), and tof().

IMagneticFieldSvc* THelixFitter::m_pmgnIMF [mutable, private]

Definition at line 151 of file THelixFitter.h.

Referenced by drift(), and getMagneticFieldPointer().


Generated on Tue Nov 29 23:36:00 2016 for BOSS_7.0.2 by  doxygen 1.4.7