FitContext Class Reference

#include <FitContext.h>

List of all members.

Public Member Functions

 FitContext (const AlgConfig &algcfg, const TrackContext &context, TrackEstimator *estimator, SwimSwimmer *swimmer)
 ~FitContext ()
void Iterate ()
void Print ()
void PrintCurrentFit ()
void Config (const AlgConfig &ac)
FitStateGetState () const
void SetState (const FitState *state)
void SetFitParams (const TVectorD &fit)
void SetLastGoodFitParams (const TVectorD &fit)
void SetFromLastGoodFit ()
Float_t GetPrange ()
NtpFitSA MakeNtpFitSA () const
void FillNtpFitSA (NtpFitSA &ntp) const
void FillNtpPlaneInfo (NtpFitSA &ntp) const
void FillNtpBFieldCalib (NtpFitSA &ntp) const
void FillNtpFitSR (NtpFitSA &ntp) const
const DataFTGetData () const
Double_t GetCpu () const
void SetCpu (Double_t cpu)

Public Attributes

const TrackContextfTrackContext
const FitStatefState
SwimSwimmerfSwimmer
TrackEstimatorfEstimator
DataFT fData
ConvergenceMaster fConvergenceMaster
MatrixCalculator fMatCalc
Int_t fNIterationsStep
Int_t fNIterationsTotal
Int_t fNPlanesFit
TVectorD fCurrentFit
Int_t fTimesConverged
FitResult fLastGoodFit
Double_t fDChi2
Int_t fNTriesDiverges
Int_t fNHitsInViewMin
Int_t fNMaxIterations
Int_t fNMaxDiverging
Double_t fConvergenceCond
Double_t fCpu

Detailed Description

FitContext is the Context part of the State design pattern - it keeps all the info about current status of the fit.

Author:
Sergei avva@fnal.gov

Definition at line 25 of file FitContext.h.


Constructor & Destructor Documentation

FitContext::FitContext ( const AlgConfig ac,
const TrackContext context,
TrackEstimator estimator,
SwimSwimmer swimmer 
)

ctor

Definition at line 30 of file FitContext.cxx.

References ConvergenceMaster::BuildMasks(), Config(), fConvergenceMaster, fData, fNHitsInViewMin, fState, FitStateFactory::GetFitState(), FitStateFactory::Instance(), and ConvergenceMaster::SetNHitsInViewMin().

00031                                                                            :
00032     fTrackContext(context), fState(0), 
00033     fSwimmer(swimmer), fEstimator(estimator),
00034     fData(ac, context), 
00035     fConvergenceMaster(), 
00036     fMatCalc(ac, context),
00037     fNIterationsStep(0), fNIterationsTotal(0),
00038     // fNPlanesToFit(0), 
00039     fNPlanesFit(0),
00040     fCurrentFit(ConstFT::NTrackParams), fTimesConverged(0), fLastGoodFit(),
00041     fDChi2(ConstFT::InitialDChi2), fNTriesDiverges(0), fNHitsInViewMin(4),
00042     fNMaxIterations(100), fNMaxDiverging(1), fConvergenceCond(0.1)
00043 {
00044     TracerSA trace(
00045     "FitContext::FitContext(const AlgConfig&,const TrackContext&,SwimSwimmer*)"
00046     );
00047     
00048     Config(ac);
00049     
00050     fState = FitStateFactory::Instance().GetFitState(std::string("Initial"));
00051     
00052     fConvergenceMaster.SetNHitsInViewMin(fNHitsInViewMin);    
00053     fConvergenceMaster.BuildMasks(fData);    
00054 }

FitContext::~FitContext (  ) 

dtor

Definition at line 60 of file FitContext.cxx.

00061 {
00062     TracerSA trace("FitContext::~FitContext()");
00063 }


Member Function Documentation

void FitContext::Config ( const AlgConfig ac  ) 

get configurable parameters from AlgConfig

read configuration parameters from AlgConfig

Definition at line 69 of file FitContext.cxx.

References fConvergenceCond, fNHitsInViewMin, fNMaxDiverging, fNMaxIterations, Registry::GetDouble(), Registry::GetInt(), and Registry::KeyExists().

Referenced by FitContext().

00070 {
00071     TracerSA trace("FitContext::Config(const AlgConfig&)");
00072     
00073     if ( ac.KeyExists("NHitsInViewMin") ) {
00074         fNHitsInViewMin = ac.GetInt("NHitsInViewMin");
00075     }    
00076     if ( ac.KeyExists("NMaxIterations") ) {
00077         fNMaxIterations = ac.GetInt("NMaxIterations");
00078     }
00079     if ( ac.KeyExists("NMaxDiverging") ) {
00080         fNMaxDiverging = ac.GetInt("NMaxDiverging");
00081     }
00082     if ( ac.KeyExists("ConvergenceCond") ) {
00083         fConvergenceCond = ac.GetDouble("ConvergenceCond");
00084     }        
00085 }

void FitContext::FillNtpBFieldCalib ( NtpFitSA ntp  )  const

Definition at line 197 of file FitContext.cxx.

References NtpFitSA::bfcalib, fData, fTrackContext, TrackContext::GetPrange(), DataFT::GetUMean(), DataFT::GetVMean(), NtpFitSABFieldCalib::prange, NtpFitSABFieldCalib::umean, and NtpFitSABFieldCalib::vmean.

Referenced by MakeNtpFitSA().

00198 {
00199     TracerSA trace("FitContext::FillNtpBFieldCalib()");
00200     //ntp.bfcalib.bin   =  segment.GetBin();
00201     ntp.bfcalib.prange = fTrackContext.GetPrange();
00202     //ntp.bfcalib.pmc    = segment.GetPtrue();
00203     ntp.bfcalib.umean  = fData.GetUMean();
00204     ntp.bfcalib.vmean  = fData.GetVMean();        
00205 }

void FitContext::FillNtpFitSA ( NtpFitSA ntp  )  const

Definition at line 133 of file FitContext.cxx.

References NtpFitSAFit::chi2, NtpFitSAFit::cpu, NtpFitSAFit::dcosu, NtpFitSAFit::dcosv, NtpFitSAFit::dcosz, NtpFitSAFit::dudz, NtpFitSAFit::dvdz, NtpFitSAFit::edcosu, NtpFitSAFit::edcosv, NtpFitSAFit::edudz, NtpFitSAFit::edvdz, NtpFitSAFit::ep, NtpFitSAFit::eqp, NtpFitSAFit::eu, NtpFitSAFit::ev, fCpu, fData, NtpFitSA::fit, fLastGoodFit, fNIterationsTotal, fTimesConverged, fTrackContext, FitResult::GetChi2(), TrackContext::GetDir(), FitResult::GetEP(), FitResult::GetFitErrM(), FitResult::GetFitParameter(), FitResult::GetFitParameterError(), FitResult::GetNdof(), FitResult::GetP(), FitResult::GetQ(), FitResult::GetTrackOut(), DataFT::GetZVtx(), ConstFT::kdUdZ, ConstFT::kdVdZ, ConstFT::kQoverP, kU, kV, NtpFitSAFit::ndf, NtpFitSAFit::niter, ConstFT::NTrackParams, NtpFitSAFit::p, NtpFitSAFit::par, NtpFitSAFit::parerr, NtpFitSAFit::pass, NtpFitSAFit::q, NtpFitSAFit::qp, NtpFitSAFit::rchi2, ConstFT::TinyNumber, NtpFitSAFit::u, NtpFitSAFit::v, and NtpFitSAFit::z.

Referenced by MakeNtpFitSA().

00134 {
00135     TracerSA trace("FitContext::FillNtpFitSA()");
00136     // 
00137     if ( fTimesConverged == 0 ) {    
00138         ntp.fit.pass     = 0;
00139     } else {
00140         ntp.fit.pass     = 1;
00141     }
00142     ntp.fit.niter   = fNIterationsTotal;
00143     ntp.fit.ndf     = fLastGoodFit.GetNdof();
00144     ntp.fit.q       = fLastGoodFit.GetQ();    
00145     ntp.fit.chi2    = fLastGoodFit.GetChi2();
00146     if ( TMath::Abs(ntp.fit.ndf) > TinyNumber ) { 
00147         ntp.fit.rchi2 = ntp.fit.chi2/ntp.fit.ndf;
00148     } else {
00149         ntp.fit.rchi2 = -1.;
00150     }
00151     
00152     ntp.fit.cpu     = fCpu;
00153     ntp.fit.p       = fLastGoodFit.GetP();
00154     ntp.fit.ep      = fLastGoodFit.GetEP();
00155     
00156     ntp.fit.u        = fLastGoodFit.GetFitParameter(kU);
00157     ntp.fit.eu       = fLastGoodFit.GetFitParameterError(kU);    
00158     ntp.fit.dudz     = fLastGoodFit.GetFitParameter(kdUdZ);
00159     ntp.fit.edudz    = fLastGoodFit.GetFitParameterError(kdUdZ);
00160     ntp.fit.v        = fLastGoodFit.GetFitParameter(kV);
00161     ntp.fit.ev       = fLastGoodFit.GetFitParameterError(kV);
00162     ntp.fit.dvdz     = fLastGoodFit.GetFitParameter(kdVdZ);
00163     ntp.fit.edvdz    = fLastGoodFit.GetFitParameterError(kdVdZ);
00164     ntp.fit.qp       = fLastGoodFit.GetFitParameter(kQoverP);
00165     ntp.fit.eqp      = fLastGoodFit.GetFitParameterError(kQoverP);
00166     
00167     ntp.fit.z        = fData.GetZVtx();        
00168         
00169     // fill direction cosines
00170     Float_t dcosu, dcosv, dcosz;    
00171     dcosz = fTrackContext.GetDir()*
00172                         pow(1. + pow(fLastGoodFit.GetTrackOut(kdUdZ),2)
00173                             + pow(fLastGoodFit.GetTrackOut(kdVdZ),2),-0.5);
00174     dcosu = fLastGoodFit.GetTrackOut(kdUdZ)*dcosz;
00175     dcosv = fLastGoodFit.GetTrackOut(kdVdZ)*dcosz;
00176     ntp.fit.dcosu    = dcosu;
00177     ntp.fit.edcosu   = sqrt(fabs(dcosz))*sqrt(pow(dcosu*dcosv*ntp.fit.edvdz,2)+
00178                             pow((pow(dcosz,2)+pow(dcosv,2))*ntp.fit.edudz,2));
00179     ntp.fit.dcosv    = dcosv;
00180     ntp.fit.edcosv   = sqrt(fabs(dcosz))*sqrt(pow(dcosu*dcosv*ntp.fit.edudz,2)+
00181                             pow((pow(dcosz,2)+pow(dcosu,2))*ntp.fit.edvdz,2));
00182     ntp.fit.dcosz    = dcosz;
00183 
00184     //
00185     for ( int i = 0; i < NTrackParams; i++ ) {
00186         ntp.fit.par[i] = fLastGoodFit.GetFitParameter(i);
00187         for ( int j = 0; j < NTrackParams; j++ ) {
00188             ntp.fit.parerr[i][j] = fLastGoodFit.GetFitErrM(i,j);
00189         }
00190     }
00191 }

void FitContext::FillNtpFitSR ( NtpFitSA ntp  )  const

Definition at line 211 of file FitContext.cxx.

References NtpFitSAFitSR::chi2, NtpFitSAFitSR::cpu, NtpFitSAFitSR::dcosu, NtpFitSAFitSR::dcosv, NtpFitSAFitSR::dcosz, NtpFitSAFitSR::edcosu, NtpFitSAFitSR::edcosv, NtpFitSAFitSR::eqp, NtpFitSAFitSR::eu, NtpFitSAFitSR::ev, NtpFitSA::fitsr, fTrackContext, TrackContext::GetChi2SR(), TrackContext::GetCpuSR(), TrackContext::GetDirCosUSR(), TrackContext::GetDirCosVSR(), TrackContext::GetDirCosZSR(), TrackContext::GetEDirCosUSR(), TrackContext::GetEDirCosVSR(), TrackContext::GetEMChargeSR(), TrackContext::GetEQPSR(), TrackContext::GetIterationsSR(), TrackContext::GetMomentumRangeSR(), TrackContext::GetMomentumSR(), TrackContext::GetNdofSR(), TrackContext::GetPassSR(), TrackContext::GetQPSR(), TrackContext::GetRChi2SR(), TrackContext::GetUErrorSR(), TrackContext::GetUSR(), TrackContext::GetVErrorSR(), TrackContext::GetVSR(), NtpFitSAFitSR::ndf, NtpFitSAFitSR::niter, NtpFitSAFitSR::p, NtpFitSAFitSR::pass, NtpFitSAFitSR::prange, NtpFitSAFitSR::q, NtpFitSAFitSR::qp, NtpFitSAFitSR::rchi2, NtpFitSAFitSR::u, and NtpFitSAFitSR::v.

Referenced by MakeNtpFitSA().

00212 {
00213     TracerSA trace("FitContext::FillNtpFitSR()");
00214     ntp.fitsr.pass      = fTrackContext.GetPassSR();
00215     ntp.fitsr.niter     = fTrackContext.GetIterationsSR();
00216     ntp.fitsr.ndf       = fTrackContext.GetNdofSR();
00217     ntp.fitsr.q         = fTrackContext.GetEMChargeSR();
00218     ntp.fitsr.chi2      = fTrackContext.GetChi2SR();
00219     ntp.fitsr.rchi2     = fTrackContext.GetRChi2SR();
00220     ntp.fitsr.cpu       = fTrackContext.GetCpuSR();
00221     ntp.fitsr.qp        = fTrackContext.GetQPSR();
00222     ntp.fitsr.eqp       = fTrackContext.GetEQPSR();
00223     ntp.fitsr.u         = fTrackContext.GetUSR();
00224     ntp.fitsr.eu        = fTrackContext.GetUErrorSR();
00225     ntp.fitsr.v         = fTrackContext.GetVSR();
00226     ntp.fitsr.ev        = fTrackContext.GetVErrorSR();
00227     ntp.fitsr.dcosu     = fTrackContext.GetDirCosUSR();
00228     ntp.fitsr.edcosu    = fTrackContext.GetEDirCosUSR();
00229     ntp.fitsr.dcosv     = fTrackContext.GetDirCosVSR();
00230     ntp.fitsr.edcosv    = fTrackContext.GetEDirCosVSR();
00231     ntp.fitsr.dcosz     = fTrackContext.GetDirCosZSR();
00232     ntp.fitsr.p         = fTrackContext.GetMomentumSR();
00233     ntp.fitsr.prange    = fTrackContext.GetMomentumRangeSR();
00234 }

void FitContext::FillNtpPlaneInfo ( NtpFitSA ntp  )  const
Double_t FitContext::GetCpu (  )  const [inline]

Definition at line 67 of file FitContext.h.

References fCpu.

00067 { return fCpu; };

const DataFT* FitContext::GetData (  )  const [inline]

Definition at line 65 of file FitContext.h.

References fData.

00065 { return &fData; };

Float_t FitContext::GetPrange (  )  [inline]

Definition at line 56 of file FitContext.h.

References fTrackContext, and TrackContext::GetPrange().

Referenced by TrackEstimatorRange::EstimateTrackParams().

00056 { return fTrackContext.GetPrange(); };

FitState* FitContext::GetState (  )  const
void FitContext::Iterate (  ) 

This is the basic iteration - it calls fState->Iterate

do iterations - call Iterate() method of the current FitState

Definition at line 91 of file FitContext.cxx.

References fState, and FitState::Iterate().

Referenced by AlgFitTrackSA::DoFit().

00092 {
00093     TracerSA trace("FitContext::Iterate()");
00094     fState->Iterate(*this);    
00095 }

NtpFitSA FitContext::MakeNtpFitSA (  )  const

Definition at line 113 of file FitContext.cxx.

References FillNtpBFieldCalib(), FillNtpFitSA(), FillNtpFitSR(), FillNtpPlaneInfo(), fTrackContext, TrackContext::GetDir(), and NtpFitSA::zdir.

Referenced by AlgFitTrackSA::DoFit().

00114 {
00115     TracerSA trace("FitContext::MakeNtpFitSA()");
00116     
00117     NtpFitSA ntp;
00118 
00119     // Fill
00120     ntp.zdir = fTrackContext.GetDir();
00121     FillNtpFitSA(ntp);   
00122     FillNtpPlaneInfo(ntp);
00123     FillNtpBFieldCalib(ntp);
00124     FillNtpFitSR(ntp);
00125             
00126     return ntp;
00127 }

void FitContext::Print (  ) 

print out FitContext for debugging

Definition at line 306 of file FitContext.cxx.

References fConvergenceMaster, fCurrentFit, fDChi2, fNIterationsStep, fNIterationsTotal, fNPlanesFit, ConvergenceMaster::GetNPlanesCur(), Msg::kInfo, ConstFT::kQoverP, and MSGSTREAM.

Referenced by FitStateInitial::Iterate(), and FitStateIterating::Iterate().

00307 {        
00308     TracerSA trace("FitContext::Print()");
00309      MsgStream *mftsa = &MSGSTREAM("FitTrackSA", Msg::kInfo);
00310 
00311      (*mftsa) << "Step " << fNIterationsStep << "/" << fNIterationsTotal 
00312         //<< "; #ToFit=" << fNPlanesToFit
00313         << "; #ToFit=" << fConvergenceMaster.GetNPlanesCur()
00314         << "; #Fit=" << fNPlanesFit << "; dchi2=" << fDChi2 
00315         << "; q/p=" << fCurrentFit(kQoverP) <<  "\n";
00316 
00317 }

void FitContext::PrintCurrentFit (  ) 

print out FitContext for debugging

Definition at line 293 of file FitContext.cxx.

References fCurrentFit, ConstFT::kdUdZ, ConstFT::kdVdZ, Msg::kInfo, ConstFT::kQoverP, kU, kV, and MSGSTREAM.

Referenced by SetFitParams().

00294 {  
00295     TracerSA trace("FitContext::PrintCurrentFit()");
00296      MsgStream *mftsa = &MSGSTREAM("FitTrackSA", Msg::kInfo);
00297 
00298      (*mftsa) << "U=" << fCurrentFit(kU) << "; dU/dZ=" << fCurrentFit(kdUdZ) 
00299         << "; V=" << fCurrentFit(kV) << "; dV/dZ=" << fCurrentFit(kdVdZ) 
00300         << "; Q/P=" << fCurrentFit(kQoverP) <<  "\n";
00301 }

void FitContext::SetCpu ( Double_t  cpu  )  [inline]

Definition at line 68 of file FitContext.h.

References fCpu.

Referenced by AlgFitTrackSA::DoFit().

00068 { fCpu = cpu; };

void FitContext::SetFitParams ( const TVectorD &  fit  ) 

Definition at line 265 of file FitContext.cxx.

References fCurrentFit, and PrintCurrentFit().

00266 { 
00267     TracerSA trace("FitContext::SetFitParams(const TVectorD&)");
00268     fCurrentFit = fit; 
00269     PrintCurrentFit();
00270 }

void FitContext::SetFromLastGoodFit (  ) 

Definition at line 275 of file FitContext.cxx.

References fCurrentFit, fLastGoodFit, and FitResult::GetTrackOut().

Referenced by FitStateDiverged::Iterate().

00276 { 
00277     TracerSA trace("FitContext::SetFromLastGoodFit()");
00278     fCurrentFit = fLastGoodFit.GetTrackOut(); 
00279 }

void FitContext::SetLastGoodFitParams ( const TVectorD &  fit  ) 

used by track estimator to set initial track parameters

Definition at line 284 of file FitContext.cxx.

References fLastGoodFit, and FitResult::SetTrackOut().

Referenced by FitStateInitial::Iterate().

00285 { 
00286     TracerSA trace("FitContext::SetLastGoodFitParams(const TVectorD&)");
00287     fLastGoodFit.SetTrackOut(fit); 
00288 }

void FitContext::SetState ( const FitState state  ) 

switch to given FitState

Definition at line 101 of file FitContext.cxx.

References fState, Msg::kDebug, MSG, and FitState::Name().

Referenced by FitStateInitial::Iterate(), FitStateIterating::Iterate(), FitStateDiverged::Iterate(), and FitStateConverged::Iterate().

00102 {
00103     TracerSA trace("FitContext::SetState(const FitState*)");
00104     fState = state;    
00105     MSG("FitTrackSA",Msg::kDebug) << "Switched to " 
00106         << state->Name() << " state.\n";
00107 }


Member Data Documentation

Definition at line 129 of file FitContext.h.

Referenced by Config(), and FitStateIterating::Iterate().

Double_t FitContext::fCpu

Definition at line 131 of file FitContext.h.

Referenced by FillNtpFitSA(), GetCpu(), and SetCpu().

Initial estimation of the track parameters

Definition at line 90 of file FitContext.h.

Referenced by FitStateInitial::Iterate().

Definition at line 123 of file FitContext.h.

Referenced by Config(), and FitContext().

Definition at line 108 of file FitContext.h.

Referenced by FillNtpFitSA(), FitStateIterating::Iterate(), and Print().

Definition at line 127 of file FitContext.h.

Referenced by Config(), and FitStateIterating::Iterate().

Definition at line 125 of file FitContext.h.

Referenced by Config(), and FitStateIterating::Iterate().

Definition at line 111 of file FitContext.h.

Referenced by FitStateIterating::Iterate(), FitStateInitial::Iterate(), and Print().

fitter state

Definition at line 80 of file FitContext.h.

Referenced by AlgFitTrackSA::DoFit(), FitContext(), Iterate(), and SetState().

Particle swimmer

Definition at line 85 of file FitContext.h.

Referenced by FitStateIterating::Iterate(), and FitStateInitial::Iterate().

Definition at line 115 of file FitContext.h.

Referenced by FillNtpFitSA(), FitStateFinal::Iterate(), and FitStateConverged::Iterate().

track context

Definition at line 68 of file FitContext.h.

Referenced by FillNtpBFieldCalib(), FillNtpFitSA(), FillNtpFitSR(), GetPrange(), and MakeNtpFitSA().


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

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1