kalmanalignment is hosted by Hepforge, IPPP Durham
Kalman Alignment

/home/mweber/Dokumente/CMS/Alignment/kalmanalignment/trunk/util/Utilities.h

Go to the documentation of this file.
00001 #ifndef _Utilities_h
00002 #define _Utilities_h
00003 
00004 // C++ / STL includes
00005 #include <string>
00006 #include <iostream>
00007 #include <assert.h>
00008 
00009 // ROOT includes
00010 #include "TString.h" // for char *Form(...)
00011 #include "TVectorD.h"
00012 #include "TMatrixD.h"
00013 #include "TMatrixDSym.h"
00014 #include "TObject.h"
00015 #include "TTree.h"
00016 
00017 // CLHEP includes
00018 #include <CLHEP/Matrix/Vector.h>
00019 #include <CLHEP/Matrix/Matrix.h>
00020 #include <CLHEP/Matrix/SymMatrix.h>
00021 
00029 // global Variable to log errors (1), warnings (2), info (3), debug(4,5,...)
00030 extern int gLogLevel;
00031 
00032 #ifndef NDEBUG
00033 #define LOG(level, message) if (gLogLevel >= level) { switch (level) { \
00034 case 1: std::cerr << "ERROR: " << message << std::endl; break; \
00035 case 2: std::cerr << "WARNING: " << message << std::endl; break; \
00036 case 3: std::cout << "INFO: " << message << std::endl; break; \
00037 default: std::cout << "DEBUG: " << message << std::endl; } }
00038 #else
00039 #define LOG(level, message) ;
00040 #endif
00041 
00042 #define ERROR(message) LOG(1, message);
00043 #define WARNING(message) LOG(2, message);
00044 #define INFO(message) LOG(3, message);
00045 
00046 #define MATRIX_SIZE(mname, matrix) std::cout << "Matrix " << mname << " has " << matrix.num_row() << " rows and " << matrix.num_col() << " columns." << std::endl;
00047 #define PMATRIX(mname, matrix) if (gLogLevel > 2) { cout << mname; matrix.Print(); }
00048 #define MATRIX(matrix) PMATRIX(#matrix, matrix)
00049 
00050 // throw an exception that tells me where the exception happened
00051 #define THROW(errmsg) throw (std::string( __PRETTY_FUNCTION__ )+std::string(" (file: ")+std::string( __FILE__ )+std::string(", line: ")+std::string( Form("%d", __LINE__) )+std::string(") ")+std::string(errmsg));
00052 #define CATCH catch (std::string message) { cerr << "EXCEPTION in " << message << std::endl; }
00053   
00054 void setXYZ(CLHEP::HepVector & v, double x, double y, double z);
00055 bool equal(const double val1, const double val2, const double precision);
00056 
00058 void GetSubMatrix(const CLHEP::HepMatrix & m, int startRow, int startColumn, int endRow, int endColumn, CLHEP::HepMatrix & sub);
00059 void GetSubMatrix(const CLHEP::HepSymMatrix & m, int startRow, int startColumn, int endRow, int endColumn, CLHEP::HepMatrix & sub);
00061 void SetSubMatrix(CLHEP::HepMatrix & m, int startRow, int startColumn, const CLHEP::HepMatrix & sub);
00062 void SetSubMatrix(CLHEP::HepSymMatrix & m, int startRow, int startColumn, const CLHEP::HepMatrix & sub);
00063 
00065 CLHEP::HepVector GetSubVector(const CLHEP::HepVector & v, int start, int end);
00066 void SetSubVector(CLHEP::HepVector & v, int start, const CLHEP::HepVector & sub);
00067 
00069 // Conversion of matrices
00070 
00071 void CLHEPtoROOT(const CLHEP::HepMatrix & oldM, TMatrixD * newM);
00072 void CLHEPtoROOT(const CLHEP::HepSymMatrix & oldM, TMatrixDSym * newM);
00073 void CLHEPtoROOT(const CLHEP::HepVector & oldV, TVectorD * newV);
00074 
00076 // Find objects from ROOT files
00077 
00078 TObject * get_object(const char * objectname, const char * filename);
00079 TTree * get_tree(const char * treename, const char * filename);
00080 TTree * init_align_tree(const char * filename);
00081 
00082 #endif