Skip to content

Commit 9ab30b9

Browse files
add yaml interface
1 parent 71be74d commit 9ab30b9

19 files changed

Lines changed: 414 additions & 197 deletions

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ set(AnalysisTreeQA_BUILD_TASKS OFF CACHE BOOL "Build user' AnalysisTreeQA tasks
1313
set(AnalysisTreeQA_BUILD_EXAMPLES ON CACHE BOOL "Build AnalysisTreeQA examples (examples/)")
1414
set(AnalysisTreeQA_BUILD_TESTS OFF CACHE BOOL "Build tests for AnalysisTreeQA")
1515
set(AnalysisTreeQA_BUNDLED_AT ON CACHE BOOL "Get and build AnalysisTree")
16-
set(AnalysisTreeQA_BUNDLED_AT_VERSION "v2.2.5" CACHE STRING "Bundled AnalysisTree version")
16+
set(AnalysisTreeQA_BUNDLED_AT_VERSION "v2.2.6" CACHE STRING "Bundled AnalysisTree version")
1717
set(AnalysisTreeQA_BUNDLED_CUTS ON CACHE BOOL "Get and build AnalysisTreeCuts")
1818
set(AnalysisTreeQA_BUNDLED_CUTS_VERSION "v0.0.1" CACHE STRING "Bundled AnalysisTreeCuts version")
1919

20+
option(yaml-cpp_BUNDLED "Build bundled yaml-cpp" OFF)
21+
2022
# by default build optimized code
2123
if(NOT DEFINED CMAKE_BUILD_TYPE)
2224
set(CMAKE_BUILD_TYPE RELEASE)
@@ -46,16 +48,20 @@ message(STATUS "Using CXX flags for ${CMAKE_BUILD_TYPE}: ${CMAKE_CXX_FLAGS_${CMA
4648

4749
list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
4850
list(APPEND CMAKE_PREFIX_PATH ${ROOTSYS})
51+
4952
find_package(ROOT REQUIRED RIO)
5053

54+
include(cmake_modules/YamlCpp.cmake)
55+
include(cmake_modules/AnalysisTree.cmake)
56+
5157
message(STATUS "Using ROOT: ${ROOT_VERSION} <${ROOT_CONFIG}>")
5258
include_directories(${CMAKE_SOURCE_DIR} ${ROOT_INCLUDE_DIR} ${ROOT_INCLUDE_DIRS})
5359
include(${ROOT_USE_FILE})
5460

5561
set(EXTERNAL_DIR ${CMAKE_BINARY_DIR}/external)
5662
set(EXTERNAL_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/external)
5763

58-
include_directories(${CMAKE_SOURCE_DIR} ${AnalysisTree_INCLUDE_DIR} ${PROJECT_INCLUDE_DIRECTORIES})
64+
include_directories(${CMAKE_SOURCE_DIR} ${AnalysisTree_INCLUDE_DIR} ${YAML_CPP_INCLUDE_DIR} ${PROJECT_INCLUDE_DIRECTORIES})
5965

6066
add_subdirectory(src)
6167

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ To apply the flag use -D{Name}={value}, for example, if you want to compile usin
3030
cmake -DCMAKE_CXX_STANDARD=11 ../
3131

3232
| Name | Default value | Possible values |
33-
| ------------- | ------------- | ---------- |
34-
| CMAKE_BUILD_TYPE | RELEASE | RELEASE/DEBUG |
35-
| CMAKE_CXX_STANDARD | 17 | 11/14/17 |
36-
| AnalysisTreeQA_BUILD_TESTS | ON | ON/OFF |
37-
| AnalysisTreeQA_BUILD_TASKS | OFF | ON/OFF |
38-
| AnalysisTreeQA_BUNDLED_AT | ON | ON/OFF |
39-
| AnalysisTreeQA_BUNDLED_AT_VERSION | master | master/v2.0.1/... |
33+
| ------------- |---------------| ---------- |
34+
| CMAKE_BUILD_TYPE | RELEASE | RELEASE/DEBUG |
35+
| CMAKE_CXX_STANDARD | 17 | 11/14/17 |
36+
| AnalysisTreeQA_BUILD_TESTS | OFF | ON/OFF |
37+
| AnalysisTreeQA_BUILD_TASKS | OFF | ON/OFF |
38+
| AnalysisTreeQA_BUNDLED_AT | ON | ON/OFF |
39+
| AnalysisTreeQA_BUNDLED_AT_VERSION | master | master/v2.0.1/... |
4040

4141
## Usage
4242

cmake_modules/YamlCpp.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
if (yaml-cpp_BUNDLED)
2+
message("-- Building bundled yaml-cpp package...")
3+
include(ExternalProject)
4+
5+
ExternalProject_Add(
6+
yaml-cpp_Ext
7+
GIT_REPOSITORY "https://github.com/jbeder/yaml-cpp.git"
8+
GIT_TAG yaml-cpp-0.6.3
9+
GIT_SHALLOW ON
10+
CMAKE_ARGS
11+
-DYAML_BUILD_SHARED_LIBS=ON
12+
-DCMAKE_BUILD_TYPE=Release
13+
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/external/yaml-cpp
14+
PREFIX ${CMAKE_BINARY_DIR}/external/yaml-cpp
15+
)
16+
17+
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/external/yaml-cpp/include)
18+
19+
add_library(yaml-cpp SHARED IMPORTED GLOBAL)
20+
set_target_properties(yaml-cpp PROPERTIES IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/external/yaml-cpp/lib/libyaml-cpp.so)
21+
target_include_directories(yaml-cpp INTERFACE ${CMAKE_BINARY_DIR}/external/yaml-cpp/include)
22+
add_dependencies(yaml-cpp yaml-cpp_Ext yaml-cpp.include)
23+
24+
set(yaml-cpp_FOUND TRUE)
25+
set(yaml-cpp_INCLUDE_DIR ${CMAKE_BINARY_DIR}/external/yaml-cpp/include)
26+
else()
27+
find_package(yaml-cpp REQUIRED)
28+
endif ()

examples/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
include(AnalysisTree)
2-
31
if(Boost_FOUND)
42
include_directories(${PROJECT_INCLUDE_DIRECTORIES} ${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIR})
53
link_directories(${PROJECT_LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS})
@@ -17,4 +15,8 @@ add_executable(example example.cpp)
1715
add_dependencies(example AnalysisTreeQA)
1816
target_link_libraries(example ${ROOT_LIBRARIES} AnalysisTreeQA AnalysisTreeBase AnalysisTreeInfra)
1917

18+
add_executable(example_yaml example_yaml.cpp)
19+
add_dependencies(example_yaml AnalysisTreeQA)
20+
target_link_libraries(example_yaml ${ROOT_LIBRARIES} AnalysisTreeQA AnalysisTreeBase AnalysisTreeInfra ${YAML_CPP_LIBRARIES})
21+
2022
install (TARGETS example RUNTIME DESTINATION bin)

examples/example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void example(const std::string& filelist){
1717
task->AddH1({"p_{T}, GeV/c", Variable::FromString("VtxTracks.pT"), {100, 0, 3}});
1818

1919
// 1D histo with cut
20-
Cuts* pT_cut = new Cuts("pT_cut", {RangeCut("VtxTracks.pT", 1, 1.5)});
20+
Cuts* pT_cut = new Cuts("pT_cut", {RangeCut("VtxTracks.pT", 0, 1.5)});
2121
task->AddH1({"p_{T}, GeV/c", Variable::FromString("VtxTracks.pT"), {100, 0, 3}}, pT_cut);
2222

2323
// AnalysisTree::Variable in case of more complicated plot

examples/example.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
1D:
2+
# Simplest way to define plot
3+
- x_axis:
4+
field: "SimParticles.pT"
5+
bins: [100, 0, 3]
6+
# Better way to define plot (cuts are defined in C++ code)
7+
- name: "sim_pT_y_1.5_3"
8+
x_axis: &sim_pT # anchor could be reused later
9+
title: "p_{T}, GeV/c"
10+
field: "SimParticles.pT"
11+
bins: [100, 0, 3]
12+
cuts: "sim_y_cut"
13+
# Plot by variable name (defined in C++ code)
14+
- name: "pxpy"
15+
x_axis:
16+
field: "pxpy"
17+
bin_edges: [-3, -1.5, -0.5, 0, 0.5, 1.5, 3]
18+
2D:
19+
- name: "sim_pT_y"
20+
x_axis: &sim_y
21+
title: "#it{y}"
22+
field: "SimParticles.rapidity"
23+
bins: [100, -2, 2]
24+
y_axis: *sim_pT
25+
Profile:
26+
- name: "pT_y_profile"
27+
x_axis: *sim_pT
28+
y_axis: *sim_y
29+
Integral:
30+
- name: "pT_integral"
31+
x_axis: &sim_pT_integral
32+
title: "#sum{p_{T}, GeV/c}"
33+
field: "SimParticles.pT"
34+
bins: [100, 0, 30]
35+
cuts: "sim_y_cut"
36+
Integral2D:
37+
- name: "pT_M_integral"
38+
x_axis:
39+
title: "M"
40+
field: "SimParticles.ones"
41+
bins: [100, 70, 130]
42+
y_axis: *sim_pT_integral
43+
y_cuts: "sim_y_cut"
44+

examples/example_yaml.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <string>
2+
3+
#include "AnalysisTree/TaskManager.hpp"
4+
#include "AnalysisTree/Variable.hpp"
5+
6+
#include "Task.hpp"
7+
#include "YamlReader.hpp"
8+
9+
using namespace AnalysisTree;
10+
11+
void example(const std::string& filelist){
12+
auto* man = TaskManager::GetInstance();
13+
14+
auto* task = new QA::Task;
15+
task->SetOutputFileName("cbm_qa.root");
16+
17+
Variable pxpy("pxpy", {{"RecTracks", "px"}, {"RecTracks", "py"}}, []( std::vector<double>& var ) { return var.at(0)*var.at(1); });
18+
19+
task->AddCut(new Cuts("sim_y_cut", {RangeCut("SimParticles.rapidity", 1.5, 3)}));
20+
task->AddCut(new Cuts("rec_pT_cut", {RangeCut("RecTracks.pT", 1, 1.5)}));
21+
task->AddVariable(pxpy);
22+
23+
QA::YamlReader r("/Users/viktor/Soft/AnalysisTreeQA/examples/example.yaml");
24+
r.AddPlotsFromYaml(task);
25+
26+
man->AddTask(task);
27+
28+
man->Init({filelist}, {"tTree"});
29+
man->Run(-1);
30+
man->Finish();
31+
}
32+
33+
int main(int argc, char* argv[]){
34+
if (argc < 2) {
35+
std::cout << "Error! Please use " << std::endl;
36+
std::cout << " ./example filename" << std::endl;
37+
exit(EXIT_FAILURE);
38+
}
39+
40+
const std::string filename = argv[1];
41+
example(filename);
42+
43+
return 0;
44+
}

src/Axis.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "Axis.hpp"
2+
3+
namespace AnalysisTree {
4+
namespace QA {
5+
6+
using std::cout;
7+
using std::endl;
8+
using std::setw;
9+
10+
void Axis::Print() const {
11+
cout << setw(25) << this->name_ << " ";
12+
cout << setw(6) << this->GetNbins() << setw(6) << this->GetXmin() << setw(6) << this->GetXmax();
13+
}
14+
15+
}
16+
}

src/Axis.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef ANALYSISTREEQA_AXIS_HPP
2+
#define ANALYSISTREEQA_AXIS_HPP
3+
4+
#include "TAxis.h"
5+
#include "AnalysisTree/Variable.hpp"
6+
7+
namespace AnalysisTree {
8+
namespace QA {
9+
10+
class Axis : public Variable, public TAxis {
11+
public:
12+
Axis() = default;
13+
Axis(const std::string& title, const Variable& var, const TAxis& a) : Variable(var), TAxis(a) {
14+
this->SetTitle(title.c_str());
15+
if(this->GetFields().size() == 1 && this->GetFields().at(0).GetName() == "ones"){
16+
this->lambda_ = [](const std::vector<double>& ){ return 1; };
17+
this->name_ = this->GetBranchName() + ".ones";
18+
}
19+
}
20+
const char* GetName() const override { return Variable::GetName().c_str(); }
21+
void Print() const override ;
22+
23+
protected:
24+
ClassDefOverride(Axis, 1);
25+
};
26+
}
27+
}
28+
#endif//ANALYSISTREEQA_AXIS_HPP

src/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include(AnalysisTree)
33
set(SOURCES
44
EntryConfig.cpp
55
Task.cpp
6-
)
6+
YamlReader.cpp Axis.cpp Axis.hpp)
77

88
string(REPLACE ".cpp" ".hpp" HEADERS "${SOURCES}")
99
list(APPEND HEADERS "BasicQA.hpp")
@@ -18,7 +18,7 @@ else ()
1818
link_directories(${PROJECT_LINK_DIRECTORIES})
1919
endif ()
2020

21-
#add_dependencies(AnalysisTreeQA ${PROJECT_DEPENDENCIES})
21+
add_dependencies(AnalysisTreeQA AnalysisTreeInfra AnalysisTreeBase)
2222

2323
ROOT_GENERATE_DICTIONARY(G__AnalysisTreeQA
2424
${HEADERS}
@@ -29,10 +29,13 @@ target_link_libraries(AnalysisTreeQA
2929
PUBLIC
3030
AnalysisTreeBase
3131
AnalysisTreeInfra
32+
yaml-cpp
3233
)
3334
target_include_directories(AnalysisTreeQA
3435
PUBLIC
3536
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
37+
${YAML_CPP_INCLUDE_DIR}
38+
${yaml-cpp_INCLUDE_DIR}
3639
)
3740

3841
install(TARGETS AnalysisTreeQA EXPORT AnalysisTreeQATargets

0 commit comments

Comments
 (0)