Skip to content

Commit

Permalink
add HelperFunctions.hpp and place some oftenly used functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lubynets committed Jan 24, 2025
1 parent 20802bc commit 0de8f0f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion core/Constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ typedef UInt_t UInteger_t;
typedef Short_t ShortInt_t;
typedef Long64_t PdgCode_t;

constexpr Floating_t UndefValueFloat = -999.;
constexpr Floating_t UndefValueFloat = -999.f;
constexpr ShortInt_t UndefValueShort = -999;
constexpr Integer_t UndefValueInt = -999;
constexpr double SmallNumber = 1e-6;
constexpr double HugeNumber = 1e9;

namespace Exyz {
enum Exyz : ShortInt_t {
Expand Down
2 changes: 1 addition & 1 deletion infra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(SOURCES
message(STATUS "CMAKE_PROJECT_NAME ${CMAKE_PROJECT_NAME}")

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

include_directories(${CMAKE_SOURCE_DIR}/core ${CMAKE_CURRENT_SOURCE_DIR} $<$<BOOL:${Boost_FOUND}>:${Boost_INCLUDE_DIRS}>)
add_library(AnalysisTreeInfra SHARED ${SOURCES} G__AnalysisTreeInfra.cxx)
Expand Down
30 changes: 30 additions & 0 deletions infra/HelperFunctions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP
#define ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP

#include "SimpleCut.hpp"

#include <string>
#include <vector>

namespace HelperFunctions {

template<typename T>
inline std::string ToStringWithPrecision(const T a_value, const int n) {
std::ostringstream out;
out.precision(n);
out << std::fixed << a_value;
return out.str();
}

inline std::vector<AnalysisTree::SimpleCut> CreateSliceCuts(const std::vector<float>& ranges, const std::string& cutNamePrefix, const std::string& branchFieldName) {
std::vector<AnalysisTree::SimpleCut> sliceCuts;
for(int iRange=0; iRange<ranges.size()-1; iRange++) {
const std::string cutName = cutNamePrefix + ToStringWithPrecision(ranges.at(iRange), 2) + "_" + ToStringWithPrecision(ranges.at(iRange+1), 2);
sliceCuts.emplace_back(AnalysisTree::RangeCut(branchFieldName, ranges.at(iRange), ranges.at(iRange+1), cutName));
}

return sliceCuts;
}

}
#endif // ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP

0 comments on commit 0de8f0f

Please sign in to comment.