Skip to content

Commit 0de8f0f

Browse files
committed
add HelperFunctions.hpp and place some oftenly used functions
1 parent 20802bc commit 0de8f0f

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

core/Constants.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ typedef UInt_t UInteger_t;
3030
typedef Short_t ShortInt_t;
3131
typedef Long64_t PdgCode_t;
3232

33-
constexpr Floating_t UndefValueFloat = -999.;
33+
constexpr Floating_t UndefValueFloat = -999.f;
3434
constexpr ShortInt_t UndefValueShort = -999;
3535
constexpr Integer_t UndefValueInt = -999;
3636
constexpr double SmallNumber = 1e-6;
37+
constexpr double HugeNumber = 1e9;
3738

3839
namespace Exyz {
3940
enum Exyz : ShortInt_t {

infra/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set(SOURCES
1919
message(STATUS "CMAKE_PROJECT_NAME ${CMAKE_PROJECT_NAME}")
2020

2121
string(REPLACE ".cpp" ".hpp" HEADERS "${SOURCES}")
22-
list(APPEND HEADERS "VariantMagic.hpp" "ToyMC.hpp" "Utils.hpp" "BranchHashHelper.hpp")
22+
list(APPEND HEADERS "VariantMagic.hpp" "ToyMC.hpp" "Utils.hpp" "BranchHashHelper.hpp" "HelperFunctions.hpp")
2323

2424
include_directories(${CMAKE_SOURCE_DIR}/core ${CMAKE_CURRENT_SOURCE_DIR} $<$<BOOL:${Boost_FOUND}>:${Boost_INCLUDE_DIRS}>)
2525
add_library(AnalysisTreeInfra SHARED ${SOURCES} G__AnalysisTreeInfra.cxx)

infra/HelperFunctions.hpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP
2+
#define ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP
3+
4+
#include "SimpleCut.hpp"
5+
6+
#include <string>
7+
#include <vector>
8+
9+
namespace HelperFunctions {
10+
11+
template<typename T>
12+
inline std::string ToStringWithPrecision(const T a_value, const int n) {
13+
std::ostringstream out;
14+
out.precision(n);
15+
out << std::fixed << a_value;
16+
return out.str();
17+
}
18+
19+
inline std::vector<AnalysisTree::SimpleCut> CreateSliceCuts(const std::vector<float>& ranges, const std::string& cutNamePrefix, const std::string& branchFieldName) {
20+
std::vector<AnalysisTree::SimpleCut> sliceCuts;
21+
for(int iRange=0; iRange<ranges.size()-1; iRange++) {
22+
const std::string cutName = cutNamePrefix + ToStringWithPrecision(ranges.at(iRange), 2) + "_" + ToStringWithPrecision(ranges.at(iRange+1), 2);
23+
sliceCuts.emplace_back(AnalysisTree::RangeCut(branchFieldName, ranges.at(iRange), ranges.at(iRange+1), cutName));
24+
}
25+
26+
return sliceCuts;
27+
}
28+
29+
}
30+
#endif // ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP

0 commit comments

Comments
 (0)