//////////////////////////////////////////////////////////////////////// /// \class RAT::DS::FitResult /// /// \brief Container class for fit vertices /// /// \author Phil G Jones /// \author Matthew Mottram -- contact person /// /// REVISION HISTORY:\n /// 27/04/2011 : P G Jones - New file \n /// 2014-02-26 : P G Jones - DS Review refactor \n /// /// \details This class contains the fit vertices. /// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /// \class RAT::DS::FitResult::NoFitResultError /// /// \brief An exception that is thrown when a user atempts to retrieve /// a fit result that does not exist. /// /// \author Phil G Jones /// /// REVISION HISTORY:\n /// 29/05/2012 : P G Jones - New file \n /// 2014-02-26 : P G Jones - Inherit from DataNotFound. \n /// /// \details This error is thrown when a fit has not been executed or /// if the fit fails /// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /// \class RAT::DS::FitResult::NoVertexError /// /// \brief An exception that is thrown when a user atempts to retrieve /// a vertex that does not exist /// /// \author Phil G Jones /// /// REVISION HISTORY:\n /// 15/06/2011 : P G Jones - New file \n /// 2014-02-26 : P G Jones - Inherit from DataNotFound. \n /// /// \details As brief /// //////////////////////////////////////////////////////////////////////// #ifndef __RAT_DS_FitResult_ #define __RAT_DS_FitResult_ #include #include #include #include #include #include #include namespace RAT { namespace DS { class FitResult : public TObject { public: class NoFitResultError : public DataNotFound { public: /// Construct the error naming the variable that is problematic /// /// @param[in] className of class the variable is a member of /// @param[in] fieldName of the variable NoFitResultError( const std::string className, const std::string fieldName ) : DataNotFound(className, fieldName) { } }; class NoVertexError : public DataNotFound { public: /// Construct the error naming the variable that is problematic /// /// @param[in] className of class the variable is a member of /// @param[in] fieldName of the variable NoVertexError( const std::string className, const std::string fieldName ) : DataNotFound(className, fieldName) { } }; /// Constructs the fit result FitResult() : TObject(), executionTime(0.0) { Reset(); } /// Reset this fit result of data inline void Reset(); /// Set a fit vertex by index /// /// @param[in] index the index of the fit vertex to set /// @param[in] vertex to set inline void SetVertex( const size_t index, const FitVertex& vertex ); /// Set a figure of merit for the named /// /// @param[in] name of the figure of merit /// @param[in] value of the figure of merit void SetFOM( const std::string& name, const Double_t value ) { foms[name] = value; }; /// Sets the execution time /// /// @param[in] time of execution in seconds void SetExecutionTime( const Double_t time ) { executionTime = time; } /// Get a fit vertex by index /// /// @param[in] index of the vertex /// @throws NoFitVertexError if there is no fit vertex at that index FitVertex& GetVertex( const size_t index ) { if( vertices.size() <= index ) throw NoVertexError("FitResult", "vertices"); return vertices.at(index); } const FitVertex& GetVertex( const size_t index ) const { if( vertices.size() <= index ) throw NoVertexError("FitResult", "vertices"); return vertices.at(index); } /// Return the number of vertices /// /// @return number of vertices size_t GetVertexCount() const { return vertices.size(); } /// Returns the FOM by name /// /// @param[in] name of the figure of merit of interest /// @return the fom value /// @throws out_of_range if there is no fom with the name Double_t GetFOM( const std::string& name ) const { return foms.at( name ); }; /// Get the Figure of Merit names /// /// @return list of FOM names std::vector GetFOMNames() const { return keys_in_map( foms ); } /// Returns the execution time /// /// @return the execution time in seconds Double_t GetExecutionTime() const { return executionTime; } /// Returns fit validity /// /// @return true if all the vertices are valid, or false if there are no vertices. inline Bool_t GetValid() const; // This ROOT macro adds dictionary methods to this class. // The number should be incremented whenever this class's members are changed. // It assumes this class has no virtual methods, use ClassDef if change this. ClassDefNV( FitResult, 4 ); private: std::map foms; ///< Figure of merit mapping std::vector vertices; ///< Fit Vertices i.e. position, time etc... Double32_t executionTime; ///< Returns fit execution time, for comparisons }; inline void FitResult::Reset() { foms.clear(); vertices.clear(); executionTime = 0.0; } inline void FitResult::SetVertex( const size_t index, const FitVertex& vertex ) { if( index + 1 > vertices.size() ) vertices.resize( index + 1 ); vertices[index] = vertex; } inline Bool_t FitResult::GetValid() const { if( vertices.empty() ) // Return invalid if no vertices exist return false; Bool_t valid = true; for( std::vector::const_iterator iVertex = vertices.begin(); iVertex != vertices.end(); iVertex++ ) valid = valid && iVertex->GetValid(); return valid; } } //::DS } //::RAT #endif