#include #include #include #include #include #include #include #include #include using namespace RAT; using namespace RAT::Methods; using namespace RAT::DS; using namespace RAT::PMTSelectors; #include #include using namespace std; void TimeLikelihood::DefaultSeed() { FitVertex vertex; vertex.SetPosition( TVector3( 0.0, 0.0, 0.0 ), false, true ); vertex.SetPositionErrors( ROOT::Math::XYZVectorF(0.0, 0.0, 0.0), false, true ); /// This is always zero vertex.SetTime( 240.0, false, true ); vertex.SetTimeErrors( 100.0, false, true ); fSeedResult.SetVertex( 0, vertex ); } FitResult TimeLikelihood::GetBestFit() { fFitResult.Reset(); if( fPMTData.empty() ) return fFitResult; CopySeedToResult(); SelectPMTData( fFitResult.GetVertex( 0 ) ); fFitResult.SetFOM( "SelectedNHit", static_cast( fSelectedPMTData.size() ) ); if( fSelectedPMTData.empty() ) throw MethodFailError( "PositionTimeLikelihood: No hits to fit" ); fOptimiser->SetComponent( this ); // Call the designated optimiser to fit and save the fom const double logL = fOptimiser->Maximise(); fFitResult.SetFOM( "LogL", logL ); // Now save the optimised values SetParams( fOptimiser->GetParams() ); SetPositiveErrors( fOptimiser->GetPositiveErrors() ); SetNegativeErrors( fOptimiser->GetNegativeErrors() ); return fFitResult; } // Following function calculates the log-likelihood value given the current // fit parameter values in params. It is called by the optimizer. double TimeLikelihood::operator()( const std::vector& params ) { SetParams( params ); double logLike = 0.0; for( vector::const_iterator iPMT = fSelectedPMTData.begin(); iPMT != fSelectedPMTData.end(); ++iPMT ) { double delta = log( fPDF->GetProbability( *iPMT, fFitResult.GetVertex( 0 ) ) ); logLike += delta; } return logLike; } vector TimeLikelihood::GetParams() const { vector params; FitVertex vertex = fFitResult.GetVertex(0); params.push_back( vertex.GetTime() ); return params; } // The following 2 functions do the same thing, but both are required in order to match with the other Fit Methods vector TimeLikelihood::GetPositiveErrors() const { vector errors; FitVertex vertex = fFitResult.GetVertex(0); errors.push_back( vertex.GetPositiveTimeError() ); return errors; } vector TimeLikelihood::GetNegativeErrors() const { vector errors; FitVertex vertex = fFitResult.GetVertex(0); errors.push_back( vertex.GetNegativeTimeError() ); return errors; } void TimeLikelihood::SetParams( const std::vector& params ) { FitVertex vertex = fFitResult.GetVertex(0); vertex.SetTime( params[0], fOptimiser->GetValid() ); fFitResult.SetVertex( 0, vertex ); } // The following 2 functions do the same thing, but both are required in order to match with the other Fit Methods void TimeLikelihood::SetPositiveErrors( const std::vector& errors ) { FitVertex vertex = fFitResult.GetVertex(0); vertex.SetPositiveTimeError( errors[0], fOptimiser->GetValid() ); fFitResult.SetVertex( 0, vertex ); } void TimeLikelihood::SetNegativeErrors( const std::vector& errors ) { FitVertex vertex = fFitResult.GetVertex(0); vertex.SetNegativeTimeError( errors[0], fOptimiser->GetValid() ); fFitResult.SetVertex( 0, vertex ); }