Skip to content

Commit

Permalink
Reorganising the code
Browse files Browse the repository at this point in the history
  • Loading branch information
vbertone committed Dec 3, 2019
1 parent eb1b4e9 commit 4317fdd
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 73 deletions.
22 changes: 22 additions & 0 deletions inc/NangaParbat/generategrid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Author: Valerio Bertone: [email protected]
//

#pragma once

#include <vector>

namespace NangaParbat
{
/**
* @brief Utility function to generate an interpolation grid
* @param n: the number of nodes of the grid
* @param min: the lower bound
* @param max: the upper bound
* @param ext: the number of extra nodes (default: 0)
* @param lgt: whether the grid is logarithmically spaced (default: false)
* @return a linearly-spaced grid with "n" nodes between "min" and
* "max" plus "ext" extra nodes on the right.
*/
std::vector<double> GenerateGrid(int const& n, double const& min, double const& max, int const& ext = 0, bool const& lgt = false);
}
19 changes: 0 additions & 19 deletions inc/NangaParbat/utilities.h → inc/NangaParbat/linearsystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@

namespace NangaParbat
{
/**
* @brief Utility function to generate an interpolation grid
* @param n: the number of nodes of the grid
* @param min: the lower bound
* @param max: the upper bound
* @param ext: the number of extra nodes (default: 0)
* @param lgt: whether the grid is logarithmically spaced (default: false)
* @return a linearly-spaced grid with "n" nodes between "min" and
* "max" plus "ext" extra nodes on the right.
*/
std::vector<double> GenerateGrid(int const& n, double const& min, double const& max, int const& ext = 0, bool const& lgt = false);

/**
* @brief Cholesky decomposition of the covariance matrix.
* @param V: the covariance matrix
Expand Down Expand Up @@ -50,11 +38,4 @@ namespace NangaParbat
* @return the solution vector
*/
std::vector<double> SolveSymmetricSystem(apfel::matrix<double> A, std::vector<double> rho);

/**
* @brief Function that lists elements in a directory
* @param path: path to the directory
* @return a vector of elements
*/
std::vector<std::string> list_dir(std::string const& path);
}
17 changes: 17 additions & 0 deletions inc/NangaParbat/listdir.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Author: Valerio Bertone: [email protected]
//

#pragma once

#include <string>

namespace NangaParbat
{
/**
* @brief Function that lists elements in a directory
* @param path: path to the directory
* @return a vector of elements
*/
std::vector<std::string> list_dir(std::string const& path);
}
5 changes: 3 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ add_subdirectory(minimisation)
add_subdirectory(parameterisation)
add_subdirectory(preprocessing)
add_subdirectory(tmdgrid)
add_subdirectory(utilities)

option(SHARED "Build shared-libray instead of static-libray" ON)
if(SHARED)
add_library(NangaParbat SHARED $<TARGET_OBJECTS:fastinterface>
$<TARGET_OBJECTS:data> $<TARGET_OBJECTS:chi2>
$<TARGET_OBJECTS:minimisation> $<TARGET_OBJECTS:parameterisation>
$<TARGET_OBJECTS:preprocessing> $<TARGET_OBJECTS:tmdgrid>)
$<TARGET_OBJECTS:preprocessing> $<TARGET_OBJECTS:tmdgrid> $<TARGET_OBJECTS:utilities>)
else(SHARED)
add_library(NangaParbat STATIC $<TARGET_OBJECTS:fastinterface>
$<TARGET_OBJECTS:data> $<TARGET_OBJECTS:chi2>
$<TARGET_OBJECTS:minimisation> $<TARGET_OBJECTS:parameterisation>
$<TARGET_OBJECTS:preprocessing> $<TARGET_OBJECTS:tmdgrid>)
$<TARGET_OBJECTS:preprocessing> $<TARGET_OBJECTS:tmdgrid> $<TARGET_OBJECTS:utilities>)
endif(SHARED)

target_link_libraries(NangaParbat ${YAML_LDFLAGS} ${APFELXX_LIBRARIES} ${ROOT_LIBRARIES}
Expand Down
2 changes: 1 addition & 1 deletion src/chi2/chisquare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

#include "NangaParbat/chisquare.h"
#include "NangaParbat/utilities.h"
#include "NangaParbat/linearsystems.h"

#include <numeric>
#include <math.h>
Expand Down
2 changes: 1 addition & 1 deletion src/data/datahandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

#include "NangaParbat/datahandler.h"
#include "NangaParbat/utilities.h"
#include "NangaParbat/linearsystems.h"

#include <iostream>
#include <math.h>
Expand Down
2 changes: 0 additions & 2 deletions src/fastinterface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
set(fastinterface_source
fastinterface.cc
convolutiontable.cc
utilities.cc
bstar.cc
)

add_library(fastinterface OBJECT ${fastinterface_source})
3 changes: 1 addition & 2 deletions src/fastinterface/fastinterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
//

#include "NangaParbat/fastinterface.h"
#include "NangaParbat/utilities.h"
#include "NangaParbat/generategrid.h"
#include "NangaParbat/bstar.h"
#include "NangaParbat/twobodyphasespace.h"

#include <LHAPDF/LHAPDF.h>

Expand Down
2 changes: 1 addition & 1 deletion src/parameterisation/meanreplica.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "NangaParbat/meanreplica.h"
#include "NangaParbat/nonpertfunctions.h"
#include "NangaParbat/utilities.h"
#include "NangaParbat/listdir.h"

#include <fstream>
#include <sys/stat.h>
Expand Down
11 changes: 7 additions & 4 deletions src/tmdgrid/tmdgrid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ namespace NangaParbat
{
//_________________________________________________________________________________
TMDGrid::TMDGrid(YAML::Node const& grid):
_xg(std::unique_ptr<apfel::QGrid<double>>(new apfel::QGrid<double> {grid["xg"].as<std::vector<double>>(), 3})),
_qToQg(std::unique_ptr<apfel::QGrid<double>>(new apfel::QGrid<double> {grid["qToQg"].as<std::vector<double>>(), 3})),
_Qg(std::unique_ptr<apfel::QGrid<double>>(new apfel::QGrid<double> {grid["Qg"].as<std::vector<double>>(), 3})),
_tmds(grid["TMDs"].as<std::map<int, std::vector<std::vector<std::vector<double>>>>>())
_xg(std::unique_ptr<apfel::QGrid<double>>(new apfel::QGrid<double>
{
grid["xg"].as<std::vector<double>>(), 3
})),
_qToQg(std::unique_ptr<apfel::QGrid<double>>(new apfel::QGrid<double> {grid["qToQg"].as<std::vector<double>>(), 3})),
_Qg(std::unique_ptr<apfel::QGrid<double>>(new apfel::QGrid<double> {grid["Qg"].as<std::vector<double>>(), 3})),
_tmds(grid["TMDs"].as<std::map<int, std::vector<std::vector<std::vector<double>>>>>())
{
}

Expand Down
8 changes: 8 additions & 0 deletions src/utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set(utilities_source
generategrid.cc
linearsystems.cc
listdir.cc
bstar.cc
)

add_library(utilities OBJECT ${utilities_source})
File renamed without changes.
29 changes: 29 additions & 0 deletions src/utilities/generategrid.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Author: Valerio Bertone: [email protected]
//

#include "NangaParbat/generategrid.h"

#include <cmath>

namespace NangaParbat
{
//_________________________________________________________________________________
std::vector<double> GenerateGrid(int const& n, double const& min, double const& max, int const& ext, bool const& lgt)
{
std::vector<double> grid(n+ext+1);
if (lgt)
{
const double step = log( max / min ) / n;
for (int i = 0; i <= n + ext; i++)
grid[i] = min * exp( i * step );
}
else
{
const double step = ( max - min ) / n;
for (int i = 0; i <= n + ext; i++)
grid[i] = min + i * step;
}
return grid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,12 @@
// Author: Valerio Bertone: [email protected]
//

#include "NangaParbat/utilities.h"
#include "NangaParbat/linearsystems.h"

#include <iostream>
#include <cmath>
#include <gsl/gsl_linalg.h>
#include <apfel/constants.h>
#include <dirent.h>

namespace NangaParbat
{
//_________________________________________________________________________________
std::vector<double> GenerateGrid(int const& n, double const& min, double const& max, int const& ext, bool const& lgt)
{
std::vector<double> grid(n+ext+1);
if (lgt)
{
const double step = log( max / min ) / n;
for (int i = 0; i <= n + ext; i++)
grid[i] = min * exp( i * step );
}
else
{
const double step = ( max - min ) / n;
for (int i = 0; i <= n + ext; i++)
grid[i] = min + i * step;
}
return grid;
}

//_________________________________________________________________________________
apfel::matrix<double> CholeskyDecomposition(apfel::matrix<double> const V)
{
Expand Down Expand Up @@ -151,21 +128,4 @@ namespace NangaParbat
}
return lambda;
}

//_________________________________________________________________________________
std::vector<std::string> list_dir(std::string const& path)
{
struct dirent *entry;
DIR *dir = opendir(path.c_str());

if (dir == NULL)
return {};

std::vector<std::string> dirlist;
while ((entry = readdir(dir)) != NULL)
dirlist.push_back(entry->d_name);

closedir(dir);
return dirlist;
}
}
28 changes: 28 additions & 0 deletions src/utilities/listdir.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Author: Valerio Bertone: [email protected]
//

#include "NangaParbat/listdir.h"

#include <dirent.h>
#include <vector>

namespace NangaParbat
{
//_________________________________________________________________________________
std::vector<std::string> list_dir(std::string const& path)
{
struct dirent *entry;
DIR *dir = opendir(path.c_str());

if (dir == NULL)
return {};

std::vector<std::string> dirlist;
while ((entry = readdir(dir)) != NULL)
dirlist.push_back(entry->d_name);

closedir(dir);
return dirlist;
}
}

0 comments on commit 4317fdd

Please sign in to comment.