Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

THelixFitter Class Reference

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

#include <THelixFitter.h>

Inheritance diagram for THelixFitter:

TMFitter TMFitter List of all members.

Public Member Functions

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

Protected Member Functions

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

Private Member Functions

void drift (const TTrack &, TMLink &, float t0Offset, double &distance, double &itsError, double &ddda) const
 calculates drift distance and its error for free T0 case.
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.
void drift (const TTrack &, TMLink &, float t0Offset, double &distance, double &itsError) const
 calculates drift distance and its error.
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.
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.
int main (TTrackBase &, float &tev, float &tev_err, double *pre_chi2=NULL, double *fitted_chi2=NULL) const
 main routine for free T0.
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.
int main (TTrackBase &, float t0Offset, double *pre_chi2=NULL, double *fitted_chi2=NULL) const
 main routine for fixed T0.

Private Attributes

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

Detailed Description

A class to fit a TTrackBase object to a helix.


Constructor & Destructor Documentation

THelixFitter::THelixFitter const std::string &  name  ) 
 

Constructor.

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 
00133   StatusCode scmgn = Gaudi::svcLocator()->service("MagneticFieldSvc",m_pmgnIMF); 
00134   if(scmgn!=StatusCode::SUCCESS) { 
00135     std::cout<< "Unable to open Magnetic field service"<<std::endl;
00136   }
00137 
00138 }

THelixFitter::~THelixFitter  )  [virtual]
 

Destructor.

00140                             {
00141 }

THelixFitter::THelixFitter const std::string &  name  ) 
 

Constructor.

virtual THelixFitter::~THelixFitter  )  [virtual]
 

Destructor.


Member Function Documentation

double THelixFitter::chi2 void   )  const
 

returns sum of chi2 aftter fit.

double THelixFitter::chi2 void   )  const [inline]
 

returns sum of chi2 aftter fit.

00304                              {
00305     return _fitted_chi2;
00306 }

unsigned THelixFitter::corrections unsigned   ) 
 

unsigned THelixFitter::corrections void   )  const
 

sets/returns correctin flag.

unsigned THelixFitter::corrections unsigned   )  [inline]
 

00292                                     {
00293     return _corrections = a;
00294 }

unsigned THelixFitter::corrections void   )  const [inline]
 

sets/returns correctin flag.

00286                                     {
00287     return _corrections;
00288 }

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.

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

calculates drift distance and its error.

void THelixFitter::drift const TTrack t,
TMLink l,
float  tev,
double &  distance,
double &  err,
double &  dddt
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

01917                                          {
01918 //=========================================
01919 // be cautious here
01920     const TMDCWireHit & h = * l.hit();
01921     const HepPoint3D & onTrack = l.positionOnTrack();
01922     const HepPoint3D & onWire = l.positionOnWire();
01923     unsigned leftRight = WireHitRight;
01924     if (onWire.cross(onTrack).z() < 0.) leftRight = WireHitLeft;
01925 
01926     //...No correction...
01927     if ((tev == 0.) && (! _propagation) && (! _tof)) {
01928         distance = h.drift(leftRight);
01929         err = h.dDrift(leftRight);
01930         return;
01931     }
01932 
01933     //...TOF correction...
01934     float tof = 0.;
01935     if (_tof) {
01936         int imass = 3;
01937         float tl = t.helix().a()[4];
01938         float f = sqrt(1. + tl * tl);
01939         float s = fabs(t.helix().curv()) * fabs(l.dPhi()) * f;
01940         float p = f / fabs(t.helix().a()[2]);
01941 //zsl   calcdc_tof2_(& imass, & p, & s, & tof);
01942         float Mass[5] = {0.000511,0.105,0.140,0.493677,0.98327};
01943         tof = s/29.98*sqrt(1.0+(Mass[imass-1]/p)*(Mass[imass-1]/p));
01944         //cout<<"tof:"<<tof<<endl;
01945     }
01946 
01947     //...T0 and propagation corrections...
01948     int wire = h.wire()->localId();
01949     int layerId = h.wire()->layerId();
01950 //    int wire = h.wire()->id();
01951     int side = leftRight;
01952 
01953 
01955     const double zhit = onWire.z();
01956     const double vinner = 220.0e8; // unit is cm/s
01957     const double vouter = 240.0e8;
01958     
01959     double tprop = 0.;
01960     const double vprop = (layerId<8) ? vinner : vouter;
01961     if (0 == layerId%2){
01963       tprop = fabs((zhit - h.wire()->backwardPosition()[2]))/vprop; 
01964     }else{ 
01966       tprop = fabs(( zhit - h.wire()->forwardPosition()[2]))/vprop;
01967     }
01968 
01969 
01970 //    if (side==0) side = -1;
01971 //    HepVector3D tp = t.helix().momentum(l.dPhi());
01972 //    float p[3] = {tp.x(),tp.y(),tp.z()};
01973 //    float x[3] = {onWire.x(), onWire.y(), onWire.z()};
01974     float time = h.reccdc()->tdc + tev - tof - 1.0e9*tprop;
01975     //    float dist_p;
01976     //    float dist_m;
01977 //    float dist;
01978 //    float edist;
01979 
01980 //  cout<<"tdc: "<<h.reccdc()->tdc<<"  tev: "<<tev<<"  tof: "<<tof<<endl;
01981 
01982 
01983     double EsT0 = -1.;
01984     IMessageSvc *msgSvc;
01985     Gaudi::svcLocator()->service("MessageSvc", msgSvc);
01986     MsgStream log(msgSvc, "TCosmicFitter");
01987 
01988     IDataProviderSvc* eventSvc = NULL;
01989     Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
01990 
01991     SmartDataPtr<RecEsTimeCol> aevtimeCol (eventSvc,"/Event/Recon/RecEsTimeCol");
01992     if (aevtimeCol) {
01993       RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
01994       EsT0 = (*iter_evt)->getTest();
01995     }else{
01996       log << MSG::WARNING << "Could not find RecEsTimeCol" << endreq;
01997     }
01998 
01999     double rawTime = 0.;
02000     rawTime = h.reccdc()->tdc;
02001     double rawadc = 0.;
02002     rawadc =h.reccdc()->adc;
02003 //    double timewalk = CalibFunSvc_->getTimeWalk(layerid, 0.0);
02004 //    double timeDrift = rawTime - tof - tprop - EsTo - toWalk; 
02005 
02006 
02007 //----cal drift----//
02008     IMdcCalibFunSvc* l_mdcCalFunSvc;
02009     Gaudi::svcLocator() -> service("MdcCalibFunSvc", l_mdcCalFunSvc);
02010 
02011     double timeWalk = l_mdcCalFunSvc->getTimeWalk(layerId, rawadc);
02012     double drifttime = rawTime - tof - 1.0e9*tprop - EsT0 - timeWalk;
02013 
02014     l.setDriftTime(drifttime);
02015 
02016 
02017     double dist;
02018     double edist;
02019     int prop = _propagation;
02020 
02021     //    //calculate derivative w.r.t. time in blute force way; need update 
02022     //    //in future to speed up
02023     //    float time_p = time + 0.1;
02024     //    calcdc_driftdist_(& prop,
02025     //                        & wire,
02026     //                        & side,
02027     //                        p,
02028     //                        x,
02029     //                        & time_p,
02030     //                        & dist_p,
02031     //                        & edist);
02032     //
02033     //        float time_m = time - 0.1;
02034     //        calcdc_driftdist_(& prop,
02035     //                        & wire,                 
02036     //                      & side,
02037     //                        p,
02038     //                        x,
02039     //                        & time_m,
02040     //                        & dist_m,
02041     //                        & edist);
02043     //    dddt = (dist_p - dist_m)*5.;
02044     //               std::cout << "side=" << side << std::endl;
02045     //               std::cout << "dddt=" << dddt << std::endl;
02046 
02047 //    float dist2[2];
02048 //    float sigma_d2[2];
02049 //    float deriv2[2];
02050     float time_tmp = time;
02051 
02052     //----cal drift----//
02053 //    IMdcCalibFunSvc* l_mdcCalFunSvc;
02054     Gaudi::svcLocator() -> service("MdcCalibFunSvc", l_mdcCalFunSvc);
02055   //  dist = l_mdcCalFunSvc->rawTimeNoTOFToDist(time_tmp, layerId, wire, side, 0.0);
02056     dist =  l_mdcCalFunSvc->driftTimeToDist(time_tmp,layerId, wire, side,0.0);//by liucy 2010/05/12
02057     edist = l_mdcCalFunSvc->getSigma(layerId, side, dist, 0.0);
02058     dist = dist/10.0; //mm->cm
02059     edist = edist/10.0;
02060 
02061     distance = dist;
02062     err = edist;
02063 
02064 //    cout<<"dist: "<<dist<<" edist: "<<edist<<endl;
02065 
02066     float time_p = time - 0.1;
02067     float time_m = time + 0.1;
02068 //    float dist_p = l_mdcCalFunSvc->rawTimeNoTOFToDist(time_p, layerId, wire, side, 0.0);
02069 //    float dist_m = l_mdcCalFunSvc->rawTimeNoTOFToDist(time_m, layerId, wire, side, 0.0);
02070 //    dist_p = dist_p/10.;
02071 //    dist_m = dist_m/10.;
02072 //    dddt = (dist_m - dist_p)/0.2;
02073 //    dddt = 0;
02074 //    dddt = 0.004;
02075 
02076 //    float dist2[2] = {dist, dist};
02077 //    float sigma_d2[2] = {edist, edist};
02078 //    float deriv2[2] = {dddt_tmp, dddt_tmp}; // cm/ns
02079 //    float deriv2[2] = {0.00, 0.00};
02080 //    float deriv2[2] = {0.004, 0.004};
02081 //cout<<"dddt_tmp: "<<dddt_tmp<<endl;
02082 
02083 //zsl    calcdc_driftdist3_(& prop,
02084 //                     & wire,                
02085 //                     p,
02086 //                     x,
02087 //                     & time_tmp,
02088 //                     dist2,
02089 //                     sigma_d2, 
02090 //                     deriv2);
02091     //n.b. input and output time are slightly different because of prop. 
02092     //delay corr. in driftdist3.
02093     //    calcdc_driftdist_(& prop,
02094     //                        & wire,
02095     //                        & side,
02096     //                        p,
02097     //                        x,
02098     //                        & time,
02099     //                        & dist,
02100     //                        & edist);
02101 
02102 /*    if (side==-1) {
02103       //            std::cout << " " << std::endl;
02104       //            std::cout << dist << " " << dist2[0] << " " <<dist2[1] << std::endl;
02105       //            std::cout << edist << " " << sigma_d2[0] << " " << sigma_d2[1] << std::endl;
02106       //            std::cout << dddt  << " " << 0.001*deriv2[0] << std::endl;
02107       dist  = dist2[0];
02108       edist = sigma_d2[0];
02109       //dddt = 0.001*deriv2[0];
02110       dddt = deriv2[0];
02111     } else if(side== 1) {
02112       //            std::cout << " " << std::endl;
02113       //            std::cout << dist << " " << dist2[1] << " " <<dist2[0] << std::endl;
02114       //            std::cout << edist << " " << sigma_d2[1] << " " << sigma_d2[0] << std::endl;
02115       //            std::cout << dddt  << " " << 0.001*deriv2[1] << std::endl;
02116       dist  = dist2[1];
02117       edist = sigma_d2[1];
02118       //dddt = 0.001*deriv2[1];
02119       dddt = deriv2[1];
02120     }  
02121 
02122     distance = (double) dist;
02123 //    std::cout << "time,distance,dddt="<<time<<" "<<distance<<"  "<<dddt<<std::endl;
02124     err = (double) edist;
02125 */
02126     return;
02127 }

void THelixFitter::drift const TTrack t,
TMLink l,
float  t0Offset,
double &  distance,
double &  err
const [private]
 

calculates drift distance and its error.

by wangjk, propagation correction

01230                                         {
01231 //be cautious here
01232     const TMDCWireHit & h = * l.hit();
01233     const HepPoint3D & onTrack = l.positionOnTrack();
01234     const HepPoint3D & onWire = l.positionOnWire();
01235     unsigned leftRight = WireHitRight;
01236     if (onWire.cross(onTrack).z() < 0.) leftRight = WireHitLeft;
01237 
01238     //...No correction...
01239     if ((t0Offset == 0.) && (! _propagation) && (! _tof)) {
01240         distance = h.drift(leftRight);
01241         err = h.dDrift(leftRight);
01242         return;
01243     }
01244 
01245 //    float x[3]={ onWire.x(), onWire.y(), onWire.z()};
01246 //    float Tcenter = 0;
01247 
01248     //...TOF correction...
01249     float tof = 0.;
01250     if (_tof) {
01251         int imass = 3;
01252         float tl = t.helix().a()[4];
01253         float f = sqrt(1. + tl * tl);
01254         float s = fabs(t.helix().curv()) * fabs(l.dPhi()) * f;
01255         float p = f / fabs(t.helix().a()[2]);
01256 //zsl   calcdc_tof2_(& imass, & p, & s, & tof);
01257         float Mass[5] = {0.000511,0.105,0.140,0.493677,0.98327};
01258         tof = s/29.98*sqrt(1.0+(Mass[imass-1]/p)*(Mass[imass-1]/p));
01259 
01260 /*      float x[3]={ onWire.x(), onWire.y(), onWire.z()};
01261       float Rad = 81; // cm
01262       float dRho = t.helix().a()[0];
01263       float Phi0 = t.helix().a()[1];
01264       float a2 = (dRho*cos(Phi0))*(dRho*cos(Phi0));
01265       float b2 = (dRho*sin(Phi0))*(dRho*sin(Phi0));
01266       float Lproj = sqrt(Rad*Rad - a2 - b2);
01267       Tcenter = Lproj/29.98; //approxiate... cm/ns
01268       tof = s/29.98;  //cosmic
01269       if (x[1]>0) tof = -tof;
01270       */
01271     }
01272 
01273     //...T0 and propagation corrections...
01274     int wire = h.wire()->localId();
01275     int layerId = h.wire()->layerId();
01276     int side = leftRight;
01277 //    if (side == 0) side = -1;
01278 //    HepVector3D tp = t.helix().momentum(l.dPhi());
01279 //    float p[3] = {tp.x(), tp.y(), tp.z()};
01280 //    float x[3] = {onWire.x(), onWire.y(), onWire.z()};
01281 //    float time = h.reccdc()->tdc + t0Offset - tof;
01282 //    float dist;
01283 //    float edist;
01284     double dist;
01285     double edist;
01286     int prop = _propagation;
01287 
01288     const double x0 = t.helix().pivot().x();
01289     const double y0 = t.helix().pivot().y();
01290 Hep3Vector pivot_helix(x0,y0,0);
01291     const double dr    =  t.helix().a()[0];
01292     const double phi0  =  t.helix().a()[1];
01293     const double kappa =  t.helix().a()[2];
01294     const double dz    =  t.helix().a()[3];
01295     const double tanl  =  t.helix().a()[4];
01296 
01297     const double alpha = 333.564095;
01298 
01299     const double cox = x0 + dr*cos(phi0) + alpha*cos(phi0)/kappa;
01300     const double coy = y0 + dr*sin(phi0) + alpha*sin(phi0)/kappa;
01301 
01302 
01303     unsigned nHits = t.links().length();
01304     unsigned nStereos = 0;
01305     unsigned firstLyr = 44;
01306     unsigned lastLyr = 0;
01307 
01308 
01309            HepPoint3D ontrack = l.positionOnTrack();
01310            HepPoint3D onwire = l.positionOnWire();
01311            HepPoint3D dir(ontrack.y()-coy,cox-ontrack.x(),0);           
01312            double pos_phi=onwire.phi();
01313            double dir_phi=dir.phi();
01314            while(pos_phi>pi){pos_phi-=pi;}
01315            while(pos_phi<0){pos_phi+=pi;}
01316            while(dir_phi>pi){dir_phi-=pi;}
01317            while(dir_phi<0){dir_phi+=pi;}
01318            double entrangle=dir_phi-pos_phi;
01319            while(entrangle>pi/2)entrangle-=pi;
01320            while(entrangle<(-1)*pi/2)entrangle+=pi; 
01322   
01323     //std::cout<<" onWire: "<<onWire<<std::endl;
01324     double zhit = onWire.z();
01325     
01326     //std::cout<<" zhit: "<<zhit<<std::endl;
01327 
01328     const double vinner = 220.0e8; // unit is cm/s
01329     const double vouter = 240.0e8; 
01330     double vprop = 300.0e9;
01331 //    double tprop = 0.;
01332     
01333     
01334     if(layerId<8) {
01335       vprop = vinner;
01336     }
01337     else {
01338       vprop = vouter;
01339     }
01340   
01341     
01342     double EsT0 = -1.;
01343     IMessageSvc *msgSvc;
01344     Gaudi::svcLocator()->service("MessageSvc", msgSvc);
01345     MsgStream log(msgSvc, "TCosmicFitter");
01346 
01347     IDataProviderSvc* eventSvc = NULL;
01348     Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
01349 
01350     SmartDataPtr<RecEsTimeCol> aevtimeCol (eventSvc,"/Event/Recon/RecEsTimeCol");
01351     if (aevtimeCol) {
01352       RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
01353       EsT0 = (*iter_evt)->getTest();
01354     }else{
01355       log << MSG::WARNING << "Could not find RecEsTimeCol" << endreq;
01356     }
01357    
01358     double rawTime = 0.;
01359     rawTime = h.reccdc()->tdc;
01360     double rawadc = 0.;
01361     rawadc =h.reccdc()->adc;
01362 //    double timewalk = CalibFunSvc_->getTimeWalk(layerid, 0.0);
01363 //    double timeDrift = rawTime - tof - tprop - EsTo - toWalk; 
01364     
01365 
01366 //----cal drift----//
01367     IMdcCalibFunSvc* l_mdcCalFunSvc;
01368     Gaudi::svcLocator() -> service("MdcCalibFunSvc", l_mdcCalFunSvc);
01369 
01370     double tprop = l_mdcCalFunSvc->getTprop(layerId,zhit*10.);
01371 
01372     double timeWalk = l_mdcCalFunSvc->getTimeWalk(layerId, rawadc);
01373 //std::cout<<"timewalk is : "<< timeWalk << std::endl ;
01374 //std::cout<<"EsT0 is : "<< EsT0 << std::endl ;
01375 //std::cout<<"tprop is : "<< tprop << std::endl ;
01376 //std::cout<<"tof is : "<< tof << std::endl ;
01377 //std::cout<<"rawTime is : "<< rawTime << std::endl ;
01378     double T0 = l_mdcCalFunSvc->getT0(layerId,wire);
01379     double drifttime = rawTime - tof - tprop - timeWalk -T0;
01380     l.setDriftTime(drifttime);
01381 
01382 //    dist = l_mdcCalFunSvc->rawTimeNoTOFToDist(h.reccdc()->tdc - tof - tprop-timeWalk, layerId, wire, side, entrangle); //default entranceangle is 0
01383     dist = l_mdcCalFunSvc->driftTimeToDist(drifttime,layerId, wire, side, entrangle);//by liucy 2010/05/12
01384     edist = l_mdcCalFunSvc->getSigma(layerId, side, dist, entrangle,tanl,zhit*10,rawadc);
01385     dist = dist/10.0; //mm->cm
01386     edist = edist/10.0;
01387 
01388 //zsl    calcdc_driftdist_(& prop,
01389 //                    & wire,
01390 //                    & side,
01391 //                    p,
01392 //                    x,
01393 //                    & time,
01394 //                    & dist,
01395 //                    & edist);
01396 
01397 //      dist = (h.reccdc()->tdc-tof) * 40./10000;
01398 
01399 //    distance = (double) dist;
01400 //    err = (double) edist;
01401     distance = dist;
01402     err = edist;
01403 
01404     return;
01405 }

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

dumps debug information.

Reimplemented from TMFitter.

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.

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.

int THelixFitter::fit TTrackBase ,
float &  tev,
float &  tev_err,
double *  pre_chi2 = NULL,
double *  fitted_chi2 = NULL
const
 

int THelixFitter::fit TTrackBase ,
float  t0Offset,
double *  pre_chi2 = NULL,
double *  fitted_chi2 = NULL
const
 

int THelixFitter::fit TTrackBase ,
double *  pre_chi2,
double *  fitted_chi2
const
 

int THelixFitter::fit TTrackBase  )  const [virtual]
 

Implements TMFitter.

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

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

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

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

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

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

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

Implements TMFitter.

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

bool THelixFitter::fit2D bool   ) 
 

bool THelixFitter::fit2D void   )  const
 

sets/returns 2D flag.

bool THelixFitter::fit2D bool   )  [inline]
 

00174                           {
00175     return _fit2D = a;
00176 }

bool THelixFitter::fit2D void   )  const [inline]
 

sets/returns 2D flag.

00168                               {
00169     return _fit2D;
00170 }

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

sets the fitted flag. (Bad implementation)

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

sets the fitted flag. (Bad implementation)

00024                                       {
00025     t._fitted = true;
00026 }

bool THelixFitter::freeT0 bool   ) 
 

bool THelixFitter::freeT0 void   )  const
 

sets/returns free T0 flag.

bool THelixFitter::freeT0 bool   )  [inline]
 

00280                            {
00281     return _freeT0 = a;
00282 }

bool THelixFitter::freeT0 void   )  const [inline]
 

sets/returns free T0 flag.

00274                                {
00275     return _freeT0;
00276 }

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

main routine for free T0.

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

main routine for fixed T0.

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

main routine for free T0.

01411                                                                 {
01412 //=====================================================================
01413     //...Initialize
01414     _pre_chi2 = _fitted_chi2 = 0.;
01415     if(pre_chi2)*pre_chi2 = _pre_chi2;
01416     if(fitted_chi2)*fitted_chi2 = _fitted_chi2;
01417 
01418     //...Type check...
01419     if (b.objectType() != Track) return TFitUnavailable;
01420     TTrack & t = (TTrack &) b;
01421 
01422     //...Already fitted ?...
01423     if (t.fitted()) return TFitAlreadyFitted;
01424 
01425     //...Count # of hits...
01426     AList<TMLink> cores = t.cores();
01427     if (_fit2D) cores = AxialHits(cores);
01428     unsigned nCores = cores.length();
01429     unsigned nStereoCores = NStereoHits(cores);
01430 
01431     //...2D or 3D...
01432     bool fitBy2D = _fit2D;
01433     if (! fitBy2D) fitBy2D = (! nStereoCores);
01434 
01435     //...Check # of hits...
01436     if (! fitBy2D) {
01437         if ((nStereoCores < 2) || (nCores - nStereoCores < 3))
01438             return TFitErrorFewHits;
01439     }
01440     else {
01441         if (nCores < 3) return TFitErrorFewHits;
01442     }
01443 
01444     //...Setup...
01445     Vector a(6), da(6);
01446     Vector a_5dim(5);
01447     for (unsigned j = 0; j < 5; j++) a[j] = t.helix().a()[j];
01448     a[5] = tev;
01449     Vector dxda(5);
01450     Vector dyda(5);
01451     Vector dzda(5);
01452     Vector dDda(6);
01453     Vector dDda_5dim(5);
01454     Vector dchi2da(6);
01455     SymMatrix d2chi2d2a(6, 0);
01456     static const SymMatrix zero6(6, 0);
01457     double chi2;
01458     double chi2Old = DBL_MAX;
01459 //    const double convergence = Convergence;
01460     const double convergence = 1.0e-4;   //Liuqg
01461     bool allAxial = true;
01462     Matrix e(3, 3);
01463     Vector f(3);
01464     int err = 0;
01465     double factor = 1.0;//jtanaka0715
01466 
01467     //...Fitting loop...
01468     unsigned nTrial = 0;
01469     while (nTrial < NTrailMax) {
01470 
01471         //...Set up...
01472         chi2 = 0.;
01473         for (unsigned j = 0; j < 6; j++) dchi2da[j] = 0.;
01474         d2chi2d2a = zero6;
01475 
01476         //...Loop with hits...
01477         unsigned i = 0;
01478         while (TMLink * l = cores[i++]) {
01479             const TMDCWireHit & h = * l->hit();
01480 
01481             //...Cal. closest points...
01482             t.approach(* l, _sag);
01483             double dPhi = l->dPhi();
01484             const HepPoint3D & onTrack = l->positionOnTrack();
01485             const HepPoint3D & onWire = l->positionOnWire();
01486             unsigned leftRight = (onWire.cross(onTrack).z() < 0.) ? WireHitLeft : WireHitRight;
01487 
01488             //...Obtain drift distance and its error...
01489             double distance;
01490             double eDistance;
01491             double dddt;
01492             drift(t, * l, tev, distance, eDistance, dddt);
01493 //          l->drift(distance,0);
01494 //          l->drift(distance,1);
01495 //          l->dDrift(distance,0);
01496 //          l->dDrift(distance,1);
01497            
01498 
01499             double inv_eDistance2 = 1./(eDistance * eDistance);
01500 
01501 
01502             //...Residual...
01503             HepVector3D v = onTrack - onWire;
01504             double vmag = v.mag();
01505             double dDistance = vmag - distance;
01506 
01507             //...dxda...
01508             this->dxda(* l, t.helix(), dPhi, dxda, dyda, dzda);
01509 
01510             //...Chi2 related...
01511             // dDda = (v.x() * dxda + v.y() * dyda + v.z() * dzda) / vmag;
01512             double vw[3] = { h.wire()->direction().x(),
01513                              h.wire()->direction().y(),
01514                              h.wire()->direction().z() };
01515             double vwxy = vw[0]*vw[1];
01516             double vwyz = vw[1]*vw[2];
01517             double vwzx = vw[2]*vw[0];
01518             dDda_5dim = (vmag > 0.)
01519                 ? ((v.x() * (1. - vw[0] * vw[0]) -
01520                     v.y() * vwxy - v.z() * vwzx)
01521                    * dxda + 
01522                    (v.y() * (1. - vw[1] * vw[1]) -
01523                     v.z() * vwyz - v.x() * vwxy)
01524                    * dyda + 
01525                    (v.z() * (1. - vw[2] * vw[2]) -
01526                     v.x() * vwzx - v.y() * vwyz)
01527                    * dzda) / vmag
01528                 : Vector(5,0);
01529             if (vmag <= 0.0) {
01530                 std::cout << "    in fit " << onTrack << ", " << onWire;
01531                 h.dump();
01532             }
01533             //      for (unsigned j = 0; j < 5; j++) dDda[j] = dDda_5dim[j];
01534             dDda[0] = dDda_5dim[0];
01535             dDda[1] = dDda_5dim[1];
01536             dDda[2] = dDda_5dim[2];
01537             dDda[3] = dDda_5dim[3];
01538             dDda[4] = dDda_5dim[4];
01539             dDda[5] = -dddt;
01540 
01541             dchi2da += (dDistance * inv_eDistance2) * dDda;
01542             d2chi2d2a += vT_times_v(dDda) * inv_eDistance2;
01543             double pChi2 = dDistance * dDistance * inv_eDistance2;
01544             chi2 += pChi2;
01545 
01546             //...Store results...
01547             l->update(onTrack, onWire, leftRight, pChi2);
01548         }
01549 
01550         //...Save chi2 information...
01551         if(nTrial == 0){
01552           _pre_chi2 = chi2;
01553           _fitted_chi2 = chi2;
01554         }else _fitted_chi2 = chi2;
01555 
01556         //...Check condition...
01557         double change = chi2Old - chi2;
01558         if (fabs(change) < convergence) break;
01559         //temp
01560                 factor = 1.0;
01561         //temp
01562         if (change < 0.) {
01563 //          a += factor * da;
01564 //          t._helix->a(a);
01565 //          break;
01566             factor = 0.5;
01567         }
01568 
01569         chi2Old = chi2;
01570 
01571         //...Cal. helix parameters for next loop...
01572         if (fitBy2D) {
01573             f = dchi2da.sub(1, 4);
01574             e = d2chi2d2a.sub(1, 4);
01575             f = solve(e, f);
01576             da[0] = f[0];
01577             da[1] = f[1];
01578             da[2] = f[2];
01579             da[3] = f[3];
01580             da[4] = 0.;
01581             da[5] = 0.;
01582         }
01583         else {
01584             da = solve(d2chi2d2a, dchi2da);
01585         }
01586 
01587         a -= factor * da;
01588 
01589         //      for (unsigned j = 0; j < 5; j++) a_5dim[j] = a[j];
01590         a_5dim[0] = a[0];
01591         a_5dim[1] = a[1];
01592         a_5dim[2] = a[2];
01593         a_5dim[3] = a[3];
01594         a_5dim[4] = a[4];
01595         t._helix->a(a_5dim);
01596         tev = a[5];
01597         //temp
01598         //      if(nTrial == 0) std::cout << "initial chi2=" <<chi2 << std::endl;
01599         //temp
01600         ++nTrial;
01601 
01602 #ifdef TRKRECO_DEBUG
01603         std::cout << "fit " << nTrial-1<< " : " << chi2 << " : " << change << std::endl;
01604 #endif
01605     }
01606 
01607     //...Cal. error matrix...
01608     SymMatrix Ea(6, 0);
01609     unsigned dim;
01610     if (fitBy2D) {
01611         dim = 4;
01612         SymMatrix Eb(4, 0), Ec(4, 0);
01613         Eb = d2chi2d2a.sub(1, 4);
01614         Ec = Eb.inverse(err);
01615         Ea[0][0] = Ec[0][0];
01616         Ea[0][1] = Ec[0][1];
01617         Ea[0][2] = Ec[0][2];
01618         Ea[0][3] = Ec[0][3];
01619         Ea[1][1] = Ec[1][1];
01620         Ea[1][2] = Ec[1][2];
01621         Ea[1][3] = Ec[1][3];
01622         Ea[2][2] = Ec[2][2];
01623         Ea[2][3] = Ec[2][3];
01624         Ea[3][3] = Ec[3][3];
01625     }
01626     else {
01627         dim = 6;
01628         Ea = d2chi2d2a.inverse(err);
01629         //        std::cout << "err flg=" << err << std::endl;
01630     }
01631 
01632 
01633     //...Store information...
01634     if (! err) {
01635         for (unsigned j = 0; j < 5; j++) a_5dim[j] = a[j];
01636         SymMatrix Ea_5dim(5, 0);
01637         Ea_5dim = Ea.sub(1, 5);
01638         t._helix->a(a_5dim);
01639         t._helix->Ea(Ea_5dim);
01640         tev = a[5];
01641         tev_err = sqrt(Ea[5][5]);
01642         //temp
01643         //      std::cout << "nTrial=" << nTrial << std::endl;
01644         //      std::cout << "chi2="   << chi2   << std::endl;
01645         //      std::cout << "pt:" << fabs(1./a_5dim[2])<< std::endl;
01646         //      std::cout << "tev,tev_err="<<tev<<" "<<tev_err<<std::endl;
01647         //temp
01648 
01649         t._fitted = true;
01650     }
01651     else {
01652         err = TFitFailed;
01653     }
01654 
01655     t._ndf = nCores - dim;
01656     t._chi2 = chi2;
01657 
01658     if(pre_chi2)*pre_chi2 = _pre_chi2;
01659     if(fitted_chi2)*fitted_chi2 = _fitted_chi2;
01660 
01661     return err;
01662 }

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

main routine for fixed T0.

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

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

returns name.

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

returns name.

00073                          {
00074     return _name;
00075 }

double THelixFitter::preChi2 void   )  const
 

returns sum of chi2 before fit.

double THelixFitter::preChi2 void   )  const [inline]
 

returns sum of chi2 before fit.

00298                                 {
00299     return _pre_chi2;
00300 }

bool THelixFitter::propagation bool   ) 
 

bool THelixFitter::propagation void   )  const
 

sets/returns propagation-delay correction flag.

bool THelixFitter::propagation bool   )  [inline]
 

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

bool THelixFitter::propagation void   )  const [inline]
 

sets/returns propagation-delay correction flag.

00192                                     {
00193     return (bool) _propagation;
00194 }

bool THelixFitter::sag bool   ) 
 

bool THelixFitter::sag void   )  const
 

sets/returns sag correction flag.

bool THelixFitter::sag bool   )  [inline]
 

00186                         {
00187     return _sag = a;
00188 }

bool THelixFitter::sag void   )  const [inline]
 

sets/returns sag correction flag.

00180                             {
00181     return _sag;
00182 }

bool THelixFitter::tanl bool   ) 
 

bool THelixFitter::tanl void   )  const
 

sets/returns tanLambda correction flag.

bool THelixFitter::tanl bool   )  [inline]
 

00224                          {
00225     return _tanl = a;
00226 }

bool THelixFitter::tanl void   )  const [inline]
 

sets/returns tanLambda correction flag.

00218                              {
00219     return _tanl;
00220 }

bool THelixFitter::tof bool   ) 
 

bool THelixFitter::tof void   )  const
 

sets/returns propagation-delay correction flag.

bool THelixFitter::tof bool   )  [inline]
 

00212                         {
00213     return _tof = a;
00214 }

bool THelixFitter::tof void   )  const [inline]
 

sets/returns propagation-delay correction flag.

00206                             {
00207     return _tof;
00208 }


Member Data Documentation

unsigned THelixFitter::_corrections [private]
 

double THelixFitter::_driftTime [private]
 

bool THelixFitter::_fit2D [private]
 

double THelixFitter::_fitted_chi2 [mutable, private]
 

bool THelixFitter::_freeT0 [private]
 

double THelixFitter::_pre_chi2 [mutable, private]
 

int THelixFitter::_propagation [private]
 

bool THelixFitter::_sag [private]
 

bool THelixFitter::_tanl [private]
 

bool THelixFitter::_tof [private]
 

IMagneticFieldSvc* THelixFitter::m_pmgnIMF [private]
 

IMagneticFieldSvc* THelixFitter::m_pmgnIMF [private]
 


The documentation for this class was generated from the following files:
Generated on Wed Feb 2 18:53:24 2011 for BOSS6.5.5 by  doxygen 1.3.9.1