Commit 7bfab4e9 authored by Claus Kleinwort's avatar Claus Kleinwort
Browse files

cpp: cleanup and fixes for first Eigen based release

git-svn-id: http://svnsrv.desy.de/public/GeneralBrokenLines/trunk@128 281f6f2b-e318-4fd1-8bce-1a4ba7aab212
parent 5a07f1e8
# - Try to find Eigen3 lib
#
# This module supports requiring a minimum version, e.g. you can do
# find_package(Eigen3 3.1.2)
# to require version 3.1.2 or newer of Eigen3.
#
# Once done this will define
#
# EIGEN3_FOUND - system has eigen lib with correct version
# EIGEN3_INCLUDE_DIR - the eigen include directory
# EIGEN3_VERSION - eigen version
# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
# Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
# Redistribution and use is allowed according to the terms of the 2-clause BSD license.
if(NOT Eigen3_FIND_VERSION)
if(NOT Eigen3_FIND_VERSION_MAJOR)
set(Eigen3_FIND_VERSION_MAJOR 2)
endif(NOT Eigen3_FIND_VERSION_MAJOR)
if(NOT Eigen3_FIND_VERSION_MINOR)
set(Eigen3_FIND_VERSION_MINOR 91)
endif(NOT Eigen3_FIND_VERSION_MINOR)
if(NOT Eigen3_FIND_VERSION_PATCH)
set(Eigen3_FIND_VERSION_PATCH 0)
endif(NOT Eigen3_FIND_VERSION_PATCH)
set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}")
endif(NOT Eigen3_FIND_VERSION)
macro(_eigen3_check_version)
file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}")
set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}")
set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}")
set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}")
set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION})
if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
set(EIGEN3_VERSION_OK FALSE)
else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
set(EIGEN3_VERSION_OK TRUE)
endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
if(NOT EIGEN3_VERSION_OK)
message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, "
"but at least version ${Eigen3_FIND_VERSION} is required")
endif(NOT EIGEN3_VERSION_OK)
endmacro(_eigen3_check_version)
if (EIGEN3_INCLUDE_DIR)
# in cache already
_eigen3_check_version()
set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})
else (EIGEN3_INCLUDE_DIR)
find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
PATHS
${CMAKE_INSTALL_PREFIX}/include
${KDE4_INCLUDE_DIR}
${EIGEN3_DIR}/include
PATH_SUFFIXES eigen3 eigen
)
if(EIGEN3_INCLUDE_DIR)
_eigen3_check_version()
endif(EIGEN3_INCLUDE_DIR)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
mark_as_advanced(EIGEN3_INCLUDE_DIR)
endif(EIGEN3_INCLUDE_DIR)
...@@ -86,8 +86,10 @@ public: ...@@ -86,8 +86,10 @@ public:
const std::vector<double>* aVector); const std::vector<double>* aVector);
void addBlockMatrix(double aWeight, unsigned int nSimple, void addBlockMatrix(double aWeight, unsigned int nSimple,
unsigned int* anIndex, double* aVector); unsigned int* anIndex, double* aVector);
Eigen::MatrixXd getBlockMatrix(const std::vector<unsigned int> anIndex) const; Eigen::MatrixXd getBlockMatrix(
Eigen::MatrixXd getBlockMatrix(unsigned int aSize, unsigned int* anIndex) const; const std::vector<unsigned int> anIndex) const;
Eigen::MatrixXd getBlockMatrix(unsigned int aSize,
unsigned int* anIndex) const;
void printMatrix() const; void printMatrix() const;
private: private:
......
...@@ -36,12 +36,13 @@ ...@@ -36,12 +36,13 @@
#include "VMatrix.h" #include "VMatrix.h"
#include "Eigen/Core" #include "Eigen/Core"
typedef Eigen::Matrix<double, 5, 5> Matrix5d;
typedef Eigen::Matrix<double, 2, 7> Matrix27d;
//! Namespace for the general broken lines package //! Namespace for the general broken lines package
namespace gbl { namespace gbl {
typedef Eigen::Matrix<double, 5, 5> Matrix5d;
typedef Eigen::Matrix<double, 2, 7> Matrix27d;
enum dataBlockType { enum dataBlockType {
None, InternalMeasurement, InternalKink, ExternalSeed, ExternalMeasurement None, InternalMeasurement, InternalKink, ExternalSeed, ExternalMeasurement
}; };
...@@ -58,8 +59,8 @@ public: ...@@ -58,8 +59,8 @@ public:
virtual ~GblData(); virtual ~GblData();
void addDerivatives(unsigned int iRow, void addDerivatives(unsigned int iRow,
const std::vector<unsigned int> &labDer, const Matrix5d &matDer, const std::vector<unsigned int> &labDer, const Matrix5d &matDer,
unsigned int iOff, const Eigen::MatrixXd &derLocal, unsigned int nLocal, unsigned int iOff, const Eigen::MatrixXd &derLocal,
const Eigen::MatrixXd &derTrans); unsigned int nLocal, const Eigen::MatrixXd &derTrans);
void addDerivatives(unsigned int iRow, void addDerivatives(unsigned int iRow,
const std::vector<unsigned int> &labDer, const Matrix27d &matDer, const std::vector<unsigned int> &labDer, const Matrix27d &matDer,
unsigned int nLocal, const Eigen::MatrixXd &derTrans); unsigned int nLocal, const Eigen::MatrixXd &derTrans);
......
...@@ -87,14 +87,16 @@ public: ...@@ -87,14 +87,16 @@ public:
const TMatrixD &aDerivatives); const TMatrixD &aDerivatives);
#endif #endif
// input via Eigen // input via Eigen
void addMeasurement(const Eigen::MatrixXd &aProjection, const Eigen::VectorXd &aResiduals, void addMeasurement(const Eigen::MatrixXd &aProjection,
const Eigen::VectorXd &aResiduals,
const Eigen::MatrixXd &aPrecision, double minPrecision = 0.); const Eigen::MatrixXd &aPrecision, double minPrecision = 0.);
void addMeasurement(const Eigen::VectorXd &aResiduals, const Eigen::MatrixXd &aPrecision, void addMeasurement(const Eigen::VectorXd &aResiduals,
double minPrecision = 0.); const Eigen::MatrixXd &aPrecision, double minPrecision = 0.);
void addScatterer(const Eigen::Vector2d &aResiduals, const Eigen::MatrixXd &aPrecision); void addScatterer(const Eigen::Vector2d &aResiduals,
const Eigen::MatrixXd &aPrecision);
void addLocals(const Eigen::MatrixXd &aDerivatives); void addLocals(const Eigen::MatrixXd &aDerivatives);
void addGlobals(const std::vector<int> &aLabels, void addGlobals(const std::vector<int> &aLabels,
const Eigen::MatrixXd &aDerivatives); const Eigen::MatrixXd &aDerivatives);
// //
unsigned int hasMeasurement() const; unsigned int hasMeasurement() const;
double getMeasPrecMin() const; double getMeasPrecMin() const;
...@@ -102,8 +104,8 @@ public: ...@@ -102,8 +104,8 @@ public:
Vector5d &aPrecision) const; Vector5d &aPrecision) const;
void getMeasTransformation(Eigen::MatrixXd &aTransformation) const; void getMeasTransformation(Eigen::MatrixXd &aTransformation) const;
bool hasScatterer() const; bool hasScatterer() const;
void getScatterer(Eigen::Matrix2d &aTransformation, Eigen::Vector2d &aResiduals, void getScatterer(Eigen::Matrix2d &aTransformation,
Eigen::Vector2d &aPrecision) const; Eigen::Vector2d &aResiduals, Eigen::Vector2d &aPrecision) const;
void getScatTransformation(Eigen::Matrix2d &aTransformation) const; void getScatTransformation(Eigen::Matrix2d &aTransformation) const;
unsigned int getNumLocals() const; unsigned int getNumLocals() const;
const Eigen::MatrixXd& getLocalDerivatives() const; const Eigen::MatrixXd& getLocalDerivatives() const;
...@@ -115,8 +117,8 @@ public: ...@@ -115,8 +117,8 @@ public:
unsigned int getLabel() const; unsigned int getLabel() const;
int getOffset() const; int getOffset() const;
const Matrix5d& getP2pJacobian() const; const Matrix5d& getP2pJacobian() const;
void getDerivatives(int aDirection, Eigen::Matrix2d &matW, Eigen::Matrix2d &matWJ, void getDerivatives(int aDirection, Eigen::Matrix2d &matW,
Eigen::Vector2d &vecWd) const; Eigen::Matrix2d &matWJ, Eigen::Vector2d &vecWd) const;
void printPoint(unsigned int level = 0) const; void printPoint(unsigned int level = 0) const;
private: private:
......
...@@ -97,7 +97,8 @@ public: ...@@ -97,7 +97,8 @@ public:
TVectorD &aDownWeights); TVectorD &aDownWeights);
#endif #endif
unsigned int getLabels(std::vector<unsigned int> &aLabelList) const; unsigned int getLabels(std::vector<unsigned int> &aLabelList) const;
unsigned int getLabels(std::vector<std::vector<unsigned int> > &aLabelList) const; unsigned int getLabels(
std::vector<std::vector<unsigned int> > &aLabelList) const;
unsigned int fit(double &Chi2, int &Ndf, double &lostWeight, unsigned int fit(double &Chi2, int &Ndf, double &lostWeight,
std::string optionList = "", unsigned int aLabel = 0); std::string optionList = "", unsigned int aLabel = 0);
void milleOut(MilleBinary &aMille); void milleOut(MilleBinary &aMille);
......
...@@ -71,9 +71,9 @@ public: ...@@ -71,9 +71,9 @@ public:
bool doublePrec = false, unsigned int aSize = 2000); bool doublePrec = false, unsigned int aSize = 2000);
virtual ~MilleBinary(); virtual ~MilleBinary();
void addData(double aMeas, double aErr, unsigned int numLocal, void addData(double aMeas, double aErr, unsigned int numLocal,
unsigned int* indLocal, double* derLocal, unsigned int* indLocal, double* derLocal,
const std::vector<int> &labGlobal, const std::vector<int> &labGlobal,
const std::vector<double> &derGlobal); const std::vector<double> &derGlobal);
void writeRecord(); void writeRecord();
private: private:
......
This diff is collapsed.
...@@ -236,7 +236,8 @@ GblTrajectory::GblTrajectory( ...@@ -236,7 +236,8 @@ GblTrajectory::GblTrajectory(
*/ */
GblTrajectory::GblTrajectory( GblTrajectory::GblTrajectory(
const std::vector<std::pair<std::vector<GblPoint>, Eigen::MatrixXd> > &aPointsAndTransList, const std::vector<std::pair<std::vector<GblPoint>, Eigen::MatrixXd> > &aPointsAndTransList,
const Eigen::MatrixXd &extDerivatives, const Eigen::VectorXd &extMeasurements, const Eigen::MatrixXd &extDerivatives,
const Eigen::VectorXd &extMeasurements,
const Eigen::MatrixXd &extPrecisions) : const Eigen::MatrixXd &extPrecisions) :
numAllPoints(), numPoints(), numOffsets(0), numInnerTrans( numAllPoints(), numPoints(), numOffsets(0), numInnerTrans(
aPointsAndTransList.size()), numParameters(0), numLocals(0), numMeasurements( aPointsAndTransList.size()), numParameters(0), numLocals(0), numMeasurements(
...@@ -805,8 +806,8 @@ void GblTrajectory::getFitToKinkJacobian(std::vector<unsigned int> &anIndex, ...@@ -805,8 +806,8 @@ void GblTrajectory::getFitToKinkJacobian(std::vector<unsigned int> &anIndex,
* \param [out] localCov Covariance for local parameters * \param [out] localCov Covariance for local parameters
* \return error code (non-zero if trajectory not fitted successfully) * \return error code (non-zero if trajectory not fitted successfully)
*/ */
unsigned int GblTrajectory::getResults(int aSignedLabel, Eigen::VectorXd &localPar, unsigned int GblTrajectory::getResults(int aSignedLabel,
Eigen::MatrixXd &localCov) const { Eigen::VectorXd &localPar, Eigen::MatrixXd &localCov) const {
if (not fitOK) if (not fitOK)
return 1; return 1;
std::pair<std::vector<unsigned int>, MatrixXd> indexAndJacobian = std::pair<std::vector<unsigned int>, MatrixXd> indexAndJacobian =
...@@ -837,8 +838,9 @@ unsigned int GblTrajectory::getResults(int aSignedLabel, Eigen::VectorXd &localP ...@@ -837,8 +838,9 @@ unsigned int GblTrajectory::getResults(int aSignedLabel, Eigen::VectorXd &localP
* \return error code (non-zero if trajectory not fitted successfully) * \return error code (non-zero if trajectory not fitted successfully)
*/ */
unsigned int GblTrajectory::getMeasResults(unsigned int aLabel, unsigned int GblTrajectory::getMeasResults(unsigned int aLabel,
unsigned int &numData, Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors, unsigned int &numData, Eigen::VectorXd &aResiduals,
Eigen::VectorXd &aResErrors, Eigen::VectorXd &aDownWeights) { Eigen::VectorXd &aMeasErrors, Eigen::VectorXd &aResErrors,
Eigen::VectorXd &aDownWeights) {
numData = 0; numData = 0;
if (not fitOK) if (not fitOK)
return 1; return 1;
...@@ -866,8 +868,9 @@ unsigned int GblTrajectory::getMeasResults(unsigned int aLabel, ...@@ -866,8 +868,9 @@ unsigned int GblTrajectory::getMeasResults(unsigned int aLabel,
* \return error code (non-zero if trajectory not fitted successfully) * \return error code (non-zero if trajectory not fitted successfully)
*/ */
unsigned int GblTrajectory::getScatResults(unsigned int aLabel, unsigned int GblTrajectory::getScatResults(unsigned int aLabel,
unsigned int &numData, Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors, unsigned int &numData, Eigen::VectorXd &aResiduals,
Eigen::VectorXd &aResErrors, Eigen::VectorXd &aDownWeights) { Eigen::VectorXd &aMeasErrors, Eigen::VectorXd &aResErrors,
Eigen::VectorXd &aDownWeights) {
numData = 0; numData = 0;
if (not fitOK) if (not fitOK)
return 1; return 1;
...@@ -988,7 +991,8 @@ unsigned int GblTrajectory::getScatResults(unsigned int aLabel, ...@@ -988,7 +991,8 @@ unsigned int GblTrajectory::getScatResults(unsigned int aLabel,
* \param [out] aLabelList List of labels (aLabelList[i] = i+1) * \param [out] aLabelList List of labels (aLabelList[i] = i+1)
* \return error code (non-zero if trajectory not valid (constructed successfully)) * \return error code (non-zero if trajectory not valid (constructed successfully))
*/ */
unsigned int GblTrajectory::getLabels(std::vector<unsigned int> &aLabelList) const { unsigned int GblTrajectory::getLabels(
std::vector<unsigned int> &aLabelList) const {
if (not constructOK) if (not constructOK)
return 1; return 1;
...@@ -1492,8 +1496,9 @@ void GblTrajectory::printTrajectory(unsigned int level) const { ...@@ -1492,8 +1496,9 @@ void GblTrajectory::printTrajectory(unsigned int level) const {
void GblTrajectory::printPoints(unsigned int level) const { void GblTrajectory::printPoints(unsigned int level) const {
std::cout << "GblPoints " << std::endl; std::cout << "GblPoints " << std::endl;
for (unsigned int iTraj = 0; iTraj < numTrajectories; ++iTraj) { for (unsigned int iTraj = 0; iTraj < numTrajectories; ++iTraj) {
for (std::vector<GblPoint>::const_iterator itPoint = thePoints[iTraj].begin(); for (std::vector<GblPoint>::const_iterator itPoint =
itPoint < thePoints[iTraj].end(); ++itPoint) { thePoints[iTraj].begin(); itPoint < thePoints[iTraj].end();
++itPoint) {
itPoint->printPoint(level); itPoint->printPoint(level);
} }
} }
...@@ -1502,7 +1507,8 @@ void GblTrajectory::printPoints(unsigned int level) const { ...@@ -1502,7 +1507,8 @@ void GblTrajectory::printPoints(unsigned int level) const {
/// Print GblData blocks for trajectory /// Print GblData blocks for trajectory
void GblTrajectory::printData() const { void GblTrajectory::printData() const {
std::cout << "GblData blocks " << std::endl; std::cout << "GblData blocks " << std::endl;
for (std::vector<GblData>::const_iterator itData = theData.begin(); itData < theData.end(); ++itData) { for (std::vector<GblData>::const_iterator itData = theData.begin();
itData < theData.end(); ++itData) {
itData->printData(); itData->printData();
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment