Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F19251540
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 447f38a0..09ced84c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,70 +1,76 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
## Set project name and enable fortran
project("Reversed HEJ" C CXX Fortran)
## Flags for the compiler. No warning allowed.
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(warnings "-Wall -Wextra -Werror -std=c++0x")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(warnings "-Wall -Wextra -Werror -std=c++11")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(warnings "/W4 /WX /EHsc")
endif()
if (NOT CONFIGURED_ONCE)
set(CMAKE_CXX_FLAGS "${warnings}"
CACHE STRING "Flags used by the compiler during all build types." FORCE)
set(CMAKE_C_FLAGS "${warnings}"
CACHE STRING "Flags used by the compiler during all build types." FORCE)
endif()
## Fortran flags
set (CMAKE_Fortran_FLAGS "-O3 -ffixed-line-length-132")
## Add directories and find dependences
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
add_subdirectory(${CMAKE_SOURCE_DIR}/madgraph/sm)
add_subdirectory(${CMAKE_SOURCE_DIR}/madgraph/HELAS)
find_package(fastjet REQUIRED)
find_package(clhep REQUIRED)
find_package(lhapdf REQUIRED)
find_package(gsl REQUIRED)
find_package(ROOT REQUIRED MODULE COMPONENTS Hist Tree MathCore)
include_directories(SYSTEM ${lhapdf_INCLUDE_PATH})
include_directories(SYSTEM ${fastjet_INCLUDE_PATH})
include_directories(SYSTEM ${clhep_INCLUDE_PATH})
include_directories(SYSTEM ${gsl_INCLUDE_PATH})
include_directories(SYSTEM ${ROOT_INCLUDE_DIR})
include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/LHEF")
add_subdirectory(src)
## define executable
add_executable(rHEJ main.cc)
## link libraries
set(libraries src ${LHAPDF_LIBRARIES} ${CLHEP_LIBRARIES} ${FASTJET_LIBRARIES} ${GSL_LIBRARIES} helasf modelf ${ROOT_LIBRARIES})
target_link_libraries(rHEJ ${libraries})
enable_testing()
set(tst_dir "${CMAKE_CURRENT_SOURCE_DIR}/t")
get_property(rHEJ_location TARGET rHEJ PROPERTY LOCATION)
add_executable(test_weights ${tst_dir}/test_weights.cc)
+add_executable(test_Matrix ${tst_dir}/test_Matrix.cc)
target_link_libraries(test_weights ${libraries})
+target_link_libraries(test_Matrix ${libraries})
add_test(
NAME t_weights
COMMAND test_weights ref_events.lhe ref_weights.txt
WORKING_DIRECTORY ${tst_dir}
)
+add_test(
+ NAME t_matrix
+ COMMAND test_Matrix
+ )
set(CONFIGURED_ONCE TRUE CACHE INTERNAL
"A flag showing that CMake has configured at least once.")
\ No newline at end of file
diff --git a/src/Matrix.cc b/src/Matrix.cc
new file mode 100644
index 00000000..e79272bf
--- /dev/null
+++ b/src/Matrix.cc
@@ -0,0 +1,80 @@
+#include "Matrix.hpp"
+#include <iostream>
+
+#include <gsl/gsl_linalg.h>
+
+namespace RHEJ{
+
+ Matrix::Matrix(size_t rows, size_t columns):
+ m(gsl_matrix_alloc(rows, columns))
+ {}
+
+ size_t Matrix::rows() const{
+ return m->size1;
+ }
+
+ size_t Matrix::columns() const{
+ return m->size2;
+ }
+
+ Matrix::Matrix(Matrix const & other):
+ m(gsl_matrix_alloc(other.rows(), other.columns()))
+ {
+ gsl_matrix_memcpy(m, other.m);
+ }
+
+ Matrix::Matrix(Matrix && other):
+ m(other.m)
+ {
+ other.m = gsl_matrix_alloc(0, 0);
+ }
+
+ double & Matrix::operator()(size_t row, size_t column){
+ return *gsl_matrix_ptr(m, row, column);
+ }
+
+ double const & Matrix::operator()(size_t row, size_t column) const{
+ return *gsl_matrix_const_ptr(m, row, column);
+ }
+
+ Matrix & Matrix::operator=(Matrix const & other){
+ Matrix o{other};
+ swap(*this, o);
+ return *this;
+ }
+
+ Matrix & Matrix::operator=(Matrix && other){
+ std::swap(m, other.m);
+ return *this;
+ }
+
+ Matrix::~Matrix(){
+ gsl_matrix_free(m);
+ }
+
+ void swap(Matrix & a, Matrix & b){
+ std::swap(a.m, b.m);
+ }
+
+ namespace{
+ struct permutation{
+ gsl_permutation* p;
+ permutation(size_t size):
+ p{gsl_permutation_alloc(size)}
+ {}
+ permutation(permutation const & other) = delete;
+ void operator=(permutation const & other) = delete;
+
+ ~permutation(){
+ gsl_permutation_free(p);
+ }
+ };
+ }
+
+ double det(Matrix m){
+ int signum;
+ permutation p(m.rows());
+ gsl_linalg_LU_decomp(m.m , p.p , &signum);
+ return gsl_linalg_LU_det(m.m, signum);
+ }
+}
diff --git a/src/Matrix.hpp b/src/Matrix.hpp
new file mode 100644
index 00000000..55b1487c
--- /dev/null
+++ b/src/Matrix.hpp
@@ -0,0 +1,36 @@
+#pragma once
+
+#include <cstddef> // needed for size_t
+
+#include <gsl/gsl_matrix.h>
+
+namespace RHEJ{
+
+ class Matrix{
+ public:
+ Matrix() = default;
+ Matrix(size_t rows, size_t columns);
+ double & operator()(size_t row, size_t column);
+ double const & operator()(size_t row, size_t column) const;
+
+ size_t rows() const;
+ size_t columns() const;
+
+ Matrix(Matrix const & other);
+ Matrix(Matrix && other);
+
+ Matrix & operator=(Matrix const & other);
+ Matrix & operator=(Matrix && other);
+
+ ~Matrix();
+ private:
+ gsl_matrix* m;
+
+ friend double det(Matrix m);
+ friend void swap(Matrix & a, Matrix & b);
+ };
+
+ void swap(Matrix & a, Matrix & b);
+
+ double det(Matrix m);
+}
diff --git a/t/test_Matrix.cc b/t/test_Matrix.cc
new file mode 100644
index 00000000..51ec6a09
--- /dev/null
+++ b/t/test_Matrix.cc
@@ -0,0 +1,47 @@
+#ifdef NDEBUG
+#undef NDEBUG
+#endif
+
+#include <cassert>
+#include <cmath>
+#include <iostream>
+
+#include "src/Matrix.hpp"
+
+int main(){
+ constexpr size_t dim = 4;
+ constexpr double ep = 1e-16;
+
+ auto m = RHEJ::Matrix{dim, dim};
+ assert(m.rows() == dim);
+ assert(m.columns() == dim);
+ m(0,0) = 0.35388638718713294;
+ assert(m(0,0) == 0.35388638718713294);
+ m(0,1) = 0.441472069363144;
+ m(0,2) = 0.7821385102801595;
+ m(0,3) = 0.4506533375385655;
+ m(1,0) = 0.5954699211986723;
+ m(1,1) = 0.7337301649423917;
+ m(1,2) = 0.24953309317812855;
+ m(1,3) = 0.5747608628993972;
+ m(2,0) = 0.5241499726390944;
+ m(2,1) = 0.5202946315779862;
+ m(2,2) = 0.5178464229701134;
+ m(2,3) = 0.22486555579427625;
+ m(3,0) = 0.28294299023923397;
+ m(3,1) = 0.23061982229765166;
+ m(3,2) = 0.9472220498156341;
+ m(3,3) = 0.68515373407338;
+ auto mcpy = m;
+ assert(mcpy.rows() == m.rows());
+ assert(mcpy.columns() == m.columns());
+ assert(mcpy(0,0) == 0.35388638718713294);
+ m(0,0) = 0;
+ assert(m(0,0) == 0);
+ assert(mcpy(0,0) == 0.35388638718713294);
+ m = std::move(mcpy);
+ assert(m.rows() == dim);
+ assert(m.columns() == dim);
+ assert(m(0,0) == 0.35388638718713294);
+ assert(std::abs(det(m) + 0.028722124827027316) < ep);
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Sep 30, 6:03 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6566417
Default Alt Text
(6 KB)
Attached To
Mode
rHEJ HEJ
Attached
Detach File
Event Timeline
Log In to Comment