FitStateIterating Class Reference

#include <FitStateIterating.h>

Inheritance diagram for FitStateIterating:
FitState

List of all members.

Public Member Functions

void Iterate (FitContext &context) const
const std::string & Name () const

Detailed Description

FitStateIterating is the main state of the fitter - repeating iterations with a fixed number of planes until the converges or diverges.

Author:
Sergei avva@fnal.gov

Definition at line 18 of file FitStateIterating.h.


Member Function Documentation

void FitStateIterating::Iterate ( FitContext context  )  const [virtual]

Iterate

Iterate method

Implements FitState.

Definition at line 57 of file FitStateIterating.cxx.

References FitContext::fConvergenceCond, FitContext::fConvergenceMaster, FitContext::fCurrentFit, FitContext::fData, FitContext::fDChi2, FitContext::fMatCalc, FitContext::fNIterationsStep, FitContext::fNIterationsTotal, FitContext::fNMaxDiverging, FitContext::fNMaxIterations, FitContext::fNPlanesFit, FitContext::fNTriesDiverges, FitContext::fSwimmer, MatrixCalculator::GetDChi2(), ConvergenceMaster::GetNPlanesCur(), ConvergenceMaster::GetNPlanesMin(), MatrixCalculator::GetTrackOut(), FitStateFactory::Instance(), Msg::kInfo, ConstFT::kQoverP, MSG, FitContext::Print(), ConvergenceMaster::SetConverged(), ConvergenceMaster::SetDiverged(), DataFT::SetInitial(), FitContext::SetState(), Particle::Sign(), and MatrixCalculator::Solve().

00058 {
00059     context.fNIterationsStep++;
00060     context.fNIterationsTotal++;
00061     
00062     // check if max number of iterations reached 
00063     if ( context.fNIterationsStep > context.fNMaxIterations ) {
00064         // max number of iterations -> switch to Diverged state
00065         context.fConvergenceMaster.SetDiverged();
00066         context.SetState(FitStateFactory::Instance().GetFitState("Diverged"));
00067         context.Print();
00068         MSG("FitTrackSA",Msg::kInfo) << "Exceeded max # of iterations.\n";
00069         MSG("FitTrackSA",Msg::kInfo) << "Switched from Iterating to Diverged\n";
00070         return;
00071     }
00072 
00073     // protect from bad q/p values
00074     // should be made configurable
00075     if ( fabs(context.fCurrentFit(kQoverP))>4. ) {
00076         MSG("FitTrackSA",Msg::kInfo) << "Bad value of q/p = " 
00077             << context.fCurrentFit(kQoverP) << "\n";
00078         context.fCurrentFit(kQoverP) = 
00079             4.*TMath::Sign(1., context.fCurrentFit(kQoverP));
00080     }
00081         
00082     context.fNPlanesFit = context.fData.SetInitial(context.fCurrentFit, 
00083                 context.fConvergenceMaster.GetNPlanesCur(), *context.fSwimmer);
00084     
00085     if ( context.fNPlanesFit < context.fConvergenceMaster.GetNPlanesMin() ) {
00086         context.fConvergenceMaster.SetDiverged();
00087         context.SetState(FitStateFactory::Instance().GetFitState("Diverged"));
00088         context.Print();
00089         MSG("FitTrackSA",Msg::kInfo) << "fNPlanesFit is smaller than fMinPlanes.\n";
00090         MSG("FitTrackSA",Msg::kInfo) << "Switched from Iterating to Diverged\n";
00091         return;        
00092     }
00093         
00094     //    
00095     context.fMatCalc.Solve(context.fData);
00096     context.fCurrentFit = context.fMatCalc.GetTrackOut();        
00097     Double_t dchi2 = context.fMatCalc.GetDChi2();
00098 
00099     //MSG("FitTrackSA",Msg::kInfo) << "new dchi2=" << dchi2 << "\n";
00100 
00101     if ( dchi2 < context.fConvergenceCond &&
00102             context.fNPlanesFit == context.fConvergenceMaster.GetNPlanesCur() ) {
00103         // excellent - fit for NPlanesToFit converged!
00104         context.fDChi2 = dchi2;
00105         // switching to Converged state
00106         context.fConvergenceMaster.SetConverged();
00107         context.SetState(FitStateFactory::Instance().
00108                                                 GetFitState("Converged"));
00109         context.Print();
00110         MSG("FitTrackSA",Msg::kInfo) << "Switched from Iterating to Converged\n";
00111         return;
00112     }
00113     
00114     if ( dchi2 < context.fConvergenceCond &&
00115             context.fNPlanesFit != context.fConvergenceMaster.GetNPlanesCur() ) {
00116             //context.fNPlanesFit != context.fNPlanesToFit ) {
00117         // fit converged, but not to requested number of planes
00118         // switching to ConvergedPartial state
00119         context.fDChi2 = dchi2;
00120         context.fConvergenceMaster.SetDiverged();
00121         context.SetState(FitStateFactory::Instance().
00122                                             GetFitState("Diverged"));
00123         MSG("FitTrackSA",Msg::kInfo) << "#Planes fit != #Planes requested\n";
00124         MSG("FitTrackSA",Msg::kInfo) << "Switched from Iterating to Diverged\n";
00125         context.Print();
00126         return;
00127     }
00128     
00129     // check if the iterations are converging
00130     if ( dchi2 < context.fDChi2 ) {
00131         // good - fit is converging
00132         context.fDChi2 = dchi2;
00133         context.Print();
00134         return;
00135     } else {
00136         // fit is not converging - bump count
00137         context.fNTriesDiverges++;
00138         context.fDChi2 = dchi2;
00139         
00140         if ( context.fNTriesDiverges > context.fNMaxDiverging ) {
00141             // reached maximal count of diverging steps -
00142             // switch to Diverged state
00143             context.fConvergenceMaster.SetDiverged();
00144             context.SetState(FitStateFactory::Instance().
00145                                                     GetFitState("Diverged"));
00146             context.Print();
00147             MSG("FitTrackSA",Msg::kInfo) << "Delta(Chi2) is not decreasing\n";
00148             MSG("FitTrackSA",Msg::kInfo) << "Switching from Iterating to Diverged\n";
00149             return;
00150         }
00151         return;
00152     }        
00153     
00154     assert(kFALSE && "Should never get here!!");
00155 }

const std::string & FitStateIterating::Name (  )  const [virtual]

Name() - return name of the state

Implements FitState.

Definition at line 49 of file FitStateIterating.cxx.

References ITERATING_FIT_STATE.

00050 {
00051     return ITERATING_FIT_STATE;
00052 }    


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1