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
14 changes: 14 additions & 0 deletions .github/workflows/clang.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Clang Format Checker
on:
push:
pull_request:
branches: [ master ]
jobs:
clang-format-checking:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: RafikFarhad/clang-format-github-action@v2.0.0
with:
sources: "src/*.*pp examples/*.*pp"
style: file
1 change: 1 addition & 0 deletions cmake_modules/AnalysisTreeQAConfig.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ source ${AT_INSTALL_BIN}/AnalysisTreeConfig.sh

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${CMAKE_INSTALL_PREFIX}/lib
export ROOT_INCLUDE_PATH=$ROOT_INCLUDE_PATH:${CMAKE_INSTALL_PREFIX}/include/AnalysisTreeQA
export PATH=$PATH:${CMAKE_INSTALL_PREFIX}/bin
60 changes: 41 additions & 19 deletions src/EntryConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ using TH1FD = TH1F;
using TH2FD = TH2F;
#endif

namespace AnalysisTree::QA {
namespace AnalysisTree {
namespace QA {

struct fill2_struct : public Utils::Visitor<void> {
fill2_struct(double val1, double val2) : val1_(val1), val2_(val2) {}
void operator()(TH1* h1) const { h1->Fill(val1_, val2_); }
void operator()(TH1* h1) const {
if (FloatingEqualZero(val2_)) return;
if (FloatingEqualOne(val2_)) h1->Fill(val1_);
else
h1->Fill(val1_, val2_);
}
void operator()(TH2* h2) const { h2->Fill(val1_, val2_); }
void operator()(TProfile* p) const { p->Fill(val1_, val2_); }
double val1_, val2_;
Expand All @@ -26,17 +32,27 @@ struct fill2_struct : public Utils::Visitor<void> {
struct fill3_struct : public Utils::Visitor<void> {
fill3_struct(double val1, double val2, double val3) : val1_(val1), val2_(val2), val3_(val3) {}
void operator()(TH1*) const { throw std::runtime_error("EntryConfig, fill3_struct: cannot fill TH1 with 3 arguments"); }
void operator()(TH2* h2) const { h2->Fill(val1_, val2_, val3_); }
void operator()(TProfile* p) const { p->Fill(val1_, val2_, val3_); }
void operator()(TH2* h2) const {
if (FloatingEqualZero(val3_)) return;
if (FloatingEqualOne(val3_)) h2->Fill(val1_, val2_);
else
h2->Fill(val1_, val2_, val3_);
}
void operator()(TProfile* p) const {
if (FloatingEqualZero(val3_)) return;
if (FloatingEqualOne(val3_)) p->Fill(val1_, val2_);
else
p->Fill(val1_, val2_, val3_);
}
double val1_, val2_, val3_;
};

EntryConfig::EntryConfig(const Axis& axis, Variable& weight, const std::string& name, Cuts* cuts, bool is_integral)
EntryConfig::EntryConfig(const Axis& axis, const 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) {
entry_cuts_name_(cuts != nullptr ? cuts->GetName() : "") {
if (name == "") {
if (cuts)
name_ += "_" + cuts->GetName();
Expand All @@ -50,18 +66,22 @@ EntryConfig::EntryConfig(const Axis& axis, Variable& weight, const std::string&
InitPlot();
}

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) {
EntryConfig::EntryConfig(const Axis& x, const Axis& y, const 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_name_(cuts != nullptr ? cuts->GetName() : "") {
Set2DName(name);
InitPlot();
}

EntryConfig::EntryConfig(const Axis& x, Cuts* cuts_x, const Axis& y, Cuts* cuts_y) : type_(PlotType::kIntegral2D),
axes_({x, y}),
entry_cuts_(cuts_x) {
Set2DName();
EntryConfig::EntryConfig(const Axis& x, Cuts* cuts_x, const Axis& y, Cuts* cuts_y, const std::string& name) : type_(PlotType::kIntegral2D),
axes_({x, y}) {
const std::string cutNameX = cuts_x != nullptr ? cuts_x->GetName() : "";
const std::string cutNameY = cuts_y != nullptr ? cuts_y->GetName() : "";
const std::string cutNameSeparator = cuts_x != nullptr && cuts_y != nullptr ? "_" : "";
entry_cuts_name_ = cutNameX + cutNameSeparator + cutNameY;

Set2DName(name);
InitPlot();
}

Expand Down Expand Up @@ -172,8 +192,9 @@ void EntryConfig::InitPlot() {
void EntryConfig::Set2DName(const std::string& name) {
name_ = name.empty() ? Form("%s_%s", axes_[0].GetName(), axes_[1].GetName()) : name;
if (name.empty()) {
if (entry_cuts_ != nullptr)
name_ += "_" + entry_cuts_->GetName();
if (!entry_cuts_name_.empty()) {
name_ += "_" + entry_cuts_name_;
}

if (!var4weight_.GetName().empty() && var4weight_.GetFields().at(0).GetName() != "ones") {
name_ += "_weight_" + var4weight_.GetName();
Expand Down Expand Up @@ -206,13 +227,14 @@ std::string EntryConfig::GetDirectoryName() const {
for (auto it = ++branches.begin(); it != branches.end(); ++it) {
name += "_" + *it;
}
if (entry_cuts_) {
name += "_" + entry_cuts_->GetName();
if (!entry_cuts_name_.empty()) {
name += "_" + entry_cuts_name_;
}
if (!var4weight_.GetName().empty() && var4weight_.GetFields().at(0).GetName() != "ones") {
name += "_weight_" + var4weight_.GetName();
}
return name;
}

}// namespace AnalysisTree::QA
}// namespace QA
}// namespace AnalysisTree
19 changes: 12 additions & 7 deletions src/EntryConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include "AnalysisTree/Cuts.hpp"
#include "AnalysisTree/Utils.hpp"

namespace AnalysisTree::QA {
namespace AnalysisTree {
namespace QA {

class Axis : public Variable, public TAxis {
public:
Expand Down Expand Up @@ -44,9 +45,9 @@ class EntryConfig {
};

EntryConfig() = default;
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);
explicit EntryConfig(const Axis& axis, [[maybe_unused]] const Variable& weight, const std::string& name, Cuts* cuts = nullptr, bool is_integral = false);
EntryConfig(const Axis& x, const Axis& y, const 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, const std::string& name);

EntryConfig(const EntryConfig&) = default;
EntryConfig(EntryConfig&&) = default;
Expand All @@ -59,7 +60,7 @@ class EntryConfig {
void Fill(double value1, double value2, double value3);

ANALYSISTREE_ATTR_NODISCARD unsigned int GetNdimensions() const { return axes_.size(); }
ANALYSISTREE_ATTR_NODISCARD Cuts* GetEntryCuts() const { return entry_cuts_; }
ANALYSISTREE_ATTR_NODISCARD const std::string& GetEntryCutsName() const { return entry_cuts_name_; }
ANALYSISTREE_ATTR_NODISCARD PlotType GetType() const { return type_; }

ANALYSISTREE_ATTR_NODISCARD std::vector<std::pair<int, int>> GetVariablesId() const { return vars_id_; }
Expand Down Expand Up @@ -97,11 +98,15 @@ class EntryConfig {

std::vector<Axis> axes_{};
Variable var4weight_{};
Cuts* entry_cuts_{nullptr};
std::string entry_cuts_name_{};
std::vector<std::pair<int, int>> vars_id_{};

ClassDef(EntryConfig, 1);
};

}// namespace AnalysisTree::QA
inline bool FloatingEqualZero(const double value, const double eps = 1e-6) { return std::fabs(value) < eps; }
inline bool FloatingEqualOne(const double value, const double eps = 1e-6) { return std::fabs(value - 1) < eps; }

}// namespace QA
}// namespace AnalysisTree
#endif//ANALYSISTREE_QA_ENTRYCONFIG_H
Loading
Loading