Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@
.idea/vcs.xml
.idea/

.vscode/
.vscode/*

*build*/
install/
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ set(AnalysisTreeQA_BUNDLED_AT_GIT_SHALLOW ON CACHE BOOL "Use CMake GIT_SHALLOW o
set(AnalysisTreeQA_BUNDLED_CUTS ON CACHE BOOL "Get and build AnalysisTreeCuts")
set(AnalysisTreeQA_BUNDLED_CUTS_VERSION "v0.0.1" CACHE STRING "Bundled AnalysisTreeCuts version")

option(USE_THD_HISTOGRAMS "Use THD histograms if ON, otherwise THF" OFF)
if (USE_THD_HISTOGRAMS)
add_definitions(-DUseTHDHistograms)
endif()

# by default build optimized code
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RELEASE)
Expand Down
58 changes: 34 additions & 24 deletions src/EntryConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

#include "EntryConfig.hpp"

#ifdef UseTHDHistograms
using TH1FD = TH1D;
using TH2FD = TH2D;
#else
using TH1FD = TH1F;
using TH2FD = TH2F;
#endif

namespace AnalysisTree {
namespace QA {

Expand All @@ -31,28 +39,30 @@ struct write_struct : public Utils::Visitor<void> {
std::string name_;
};

EntryConfig::EntryConfig(const Axis& axis, Variable& weight, Cuts* cuts, bool is_integral)
: name_(axis.GetName()),
EntryConfig::EntryConfig(const Axis& axis, Variable& weight, const std::string& name, Cuts* cuts, bool is_integral)
: name_(name == "" ? axis.GetName() : name),
type_(is_integral ? PlotType::kIntegral1D : PlotType::kHisto1D),
axes_({axis}),
var4weight_(weight),
entry_cuts_(cuts) {
if (cuts)
name_ += "_" + cuts->GetName();
if (!var4weight_.GetName().empty() && var4weight_.GetFields().at(0).GetName() != "ones") {
name_ += "_weight_" + var4weight_.GetName();
}
if(is_integral){
name_ += "_integral";
if(name == "") {
if (cuts)
name_ += "_" + cuts->GetName();
if (!var4weight_.GetName().empty() && var4weight_.GetFields().at(0).GetName() != "ones") {
name_ += "_weight_" + var4weight_.GetName();
}
if(is_integral){
name_ += "_integral";
}
}
InitPlot();
}

EntryConfig::EntryConfig(const Axis& x, const Axis& y, Variable& weight, Cuts* cuts, bool is_profile) : type_(is_profile ? PlotType::kProfile : PlotType::kHisto2D),
EntryConfig::EntryConfig(const Axis& x, const Axis& y, Variable& weight, const std::string& name, Cuts* cuts, bool is_profile) : type_(is_profile ? PlotType::kProfile : PlotType::kHisto2D),
axes_({x, y}),
var4weight_(weight),
entry_cuts_(cuts) {
Set2DName();
Set2DName(name);
InitPlot();
}

Expand All @@ -63,10 +73,8 @@ EntryConfig::EntryConfig(const Axis& x, Cuts* cuts_x, const Axis& y, Cuts* cuts_
InitPlot();
}



TH1* EntryConfig::CreateHisto1D() const {
auto* ret = new TH1F(name_.c_str(), title_.c_str(),
auto* ret = new TH1FD(name_.c_str(), title_.c_str(),
axes_.at(0).GetNbins(), axes_.at(0).GetXmin(), axes_.at(0).GetXmax());
ret->SetXTitle(axes_.at(0).GetTitle());
ret->SetYTitle("Entries");
Expand All @@ -91,7 +99,7 @@ TProfile* EntryConfig::CreateProfile() const {

TH2* EntryConfig::CreateHisto2D() const {

auto* ret = new TH2F(name_.c_str(), title_.c_str(),
auto* ret = new TH2FD(name_.c_str(), title_.c_str(),
axes_.at(0).GetNbins(), axes_.at(0).GetXmin(), axes_.at(0).GetXmax(),
axes_.at(1).GetNbins(), axes_.at(1).GetXmin(), axes_.at(1).GetXmax());
ret->SetXTitle(axes_.at(0).GetTitle());
Expand Down Expand Up @@ -129,17 +137,19 @@ void EntryConfig::InitPlot() {
}
}

void EntryConfig::Set2DName() {
name_ = Form("%s_%s", axes_[0].GetName(), axes_[1].GetName());
if (entry_cuts_ != nullptr)
name_ += "_" + entry_cuts_->GetName();
void EntryConfig::Set2DName(const std::string& name) {
name_ = name == "" ? Form("%s_%s", axes_[0].GetName(), axes_[1].GetName()) : name;
if(name == "") {
if (entry_cuts_ != nullptr)
name_ += "_" + entry_cuts_->GetName();

if (!var4weight_.GetName().empty() && var4weight_.GetFields().at(0).GetName() != "ones") {
name_ += "_weight_" + var4weight_.GetName();
}
if (!var4weight_.GetName().empty() && var4weight_.GetFields().at(0).GetName() != "ones") {
name_ += "_weight_" + var4weight_.GetName();
}

if (type_ == PlotType::kProfile) {
name_ += "_profile";
if (type_ == PlotType::kProfile) {
name_ += "_profile";
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/EntryConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class EntryConfig {
};

EntryConfig() = default;
explicit EntryConfig(const Axis& axis, [[maybe_unused]] Variable& weight, Cuts* cuts = nullptr, bool is_integral = false);
EntryConfig(const Axis& x, const Axis& y, Variable& weight, Cuts* cuts = nullptr, bool is_profile = false);
explicit EntryConfig(const Axis& axis, [[maybe_unused]] Variable& weight, const std::string& name, Cuts* cuts = nullptr, bool is_integral = false);
EntryConfig(const Axis& x, const Axis& y, Variable& weight, const std::string& name, Cuts* cuts = nullptr, bool is_profile = false);
EntryConfig(const Axis& x, Cuts* cuts_x, const Axis& y, Cuts* cuts_y);

EntryConfig(const EntryConfig&) = default;
Expand Down Expand Up @@ -94,7 +94,7 @@ class EntryConfig {
ANALYSISTREE_ATTR_NODISCARD TH1* CreateHisto1D() const;
ANALYSISTREE_ATTR_NODISCARD TH2* CreateHisto2D() const;
ANALYSISTREE_ATTR_NODISCARD TProfile* CreateProfile() const;
void Set2DName();
void Set2DName(const std::string& name="");

PlotPointer plot_;
std::string name_;///< Name of the plot
Expand Down
32 changes: 24 additions & 8 deletions src/Task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,54 @@ class Task : public AnalysisTask {
void Exec() override;
void Finish() override;

size_t AddH1(const Axis& x, Cuts* cuts = nullptr, Variable weight = Variable{}) {
size_t AddH1(const std::string& name, const Axis& x, Cuts* cuts = nullptr, Variable weight = Variable{}) {
weight.IfEmptyVariableConvertToOnes(x);
entries_.emplace_back(EntryConfig(x, weight, cuts, false));
entries_.emplace_back(EntryConfig(x, weight, name, cuts, false));
auto var_id = AddEntry(AnalysisEntry(entries_.back().GetVariables(), entries_.back().GetEntryCuts(), entries_.back().GetVariableForWeight()));
entries_.back().SetVariablesId({{var_id.first, var_id.second.at(0)}});
return entries_.size() - 1;
}

size_t AddH2(const Axis& x, const Axis& y, Cuts* cuts = nullptr, Variable weight = Variable{}) {
size_t AddH1(const Axis& x, Cuts* cuts = nullptr, Variable weight = Variable{}) {
return AddH1("", x, cuts, weight);
}

size_t AddH2(const std::string& name, const Axis& x, const Axis& y, Cuts* cuts = nullptr, Variable weight = Variable{}) {
weight.IfEmptyVariableConvertToOnes(x);
entries_.emplace_back(EntryConfig(x, y, weight, cuts));
entries_.emplace_back(EntryConfig(x, y, weight, name, cuts));
auto var_id = AddEntry(AnalysisEntry(entries_.back().GetVariables(), entries_.back().GetEntryCuts(), entries_.back().GetVariableForWeight()));
entries_.back().SetVariablesId({ {var_id.first, var_id.second.at(0)}, {var_id.first, var_id.second.at(1)} });
return entries_.size() - 1;
}

size_t AddProfile(const Axis& x, const Axis& y, Cuts* cuts = nullptr, Variable weight = Variable{}) {
size_t AddH2(const Axis& x, const Axis& y, Cuts* cuts = nullptr, Variable weight = Variable{}) {
return AddH2("", x, y, cuts, weight);
}

size_t AddProfile(const std::string& name, const Axis& x, const Axis& y, Cuts* cuts = nullptr, Variable weight = Variable{}) {
weight.IfEmptyVariableConvertToOnes(x);
entries_.emplace_back(EntryConfig(x, y, weight, cuts, true));
entries_.emplace_back(EntryConfig(x, y, weight, name, cuts, true));
auto var_id = AddEntry(AnalysisEntry(entries_.back().GetVariables(), entries_.back().GetEntryCuts(), entries_.back().GetVariableForWeight()));
entries_.back().SetVariablesId({ {var_id.first, var_id.second.at(0)}, {var_id.first, var_id.second.at(1)} });
return entries_.size() - 1;
}

size_t AddIntegral(const Axis& x, Cuts* cuts = nullptr, Variable weight = Variable{}) {
size_t AddProfile(const Axis& x, const Axis& y, Cuts* cuts = nullptr, Variable weight = Variable{}) {
return AddProfile("", x, y, cuts, weight);
}

size_t AddIntegral(const std::string& name, const Axis& x, Cuts* cuts = nullptr, Variable weight = Variable{}) {
weight.IfEmptyVariableConvertToOnes(x);
entries_.emplace_back(EntryConfig(x, weight, cuts, true));
entries_.emplace_back(EntryConfig(x, weight, name, cuts, true));
auto var_id = AddEntry(AnalysisEntry(entries_.back().GetVariables(), entries_.back().GetEntryCuts(), entries_.back().GetVariableForWeight()));
entries_.back().SetVariablesId({{var_id.first, var_id.second.at(0)}});
return entries_.size() - 1;
}

size_t AddIntegral(const Axis& x, Cuts* cuts = nullptr, Variable weight = Variable{}) {
return AddIntegral("", x, cuts, weight);
}

size_t AddIntegral(const Axis& x, const Axis& y, Cuts* cuts_x = nullptr, Cuts* cuts_y = nullptr) {
entries_.emplace_back(EntryConfig(x, cuts_x, y, cuts_y));
auto var_id_x = AddEntry(AnalysisEntry({entries_.back().GetVariables()[0]}, cuts_x));
Expand Down
Loading