AnalysisTree
Loading...
Searching...
No Matches
Cuts.hpp
1/* Copyright (C) 2019-2021 GSI, Universität Tübingen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Viktor Klochkov, Ilya Selyuzhenkov */
4#ifndef ANALYSISTREE_CUTS_H
5#define ANALYSISTREE_CUTS_H
6
7#include <set>
8#include <stdexcept>
9#include <string>
10#include <utility>
11#include <vector>
12
13#include "Constants.hpp"
14#include "SimpleCut.hpp"
18namespace AnalysisTree {
19
20class Configuration;
21
25class Cuts {
26
27 public:
28 Cuts() = default;
29 Cuts(const Cuts& cut) = default;
30 Cuts(Cuts&& cut) = default;
31 Cuts& operator=(Cuts&&) = default;
32 Cuts& operator=(const Cuts& cut) = default;
33 virtual ~Cuts() = default;
34
35 Cuts(std::string name, std::vector<SimpleCut> cuts) : name_(std::move(name)),
36 cuts_(std::move(cuts)) {
37 for (const auto& v : cuts_) {
38 const auto& br = v.GetBranches();
39 branch_names_.insert(br.begin(), br.end());
40 }
41 };
42
43 Cuts(std::string name, std::initializer_list<SimpleCut> cuts) : name_(std::move(name)),
44 cuts_(cuts.begin(), cuts.end()) {
45 for (const auto& v : cuts_) {
46 const auto& br = v.GetBranches();
47 branch_names_.insert(br.begin(), br.end());
48 }
49 }
50
57 template<class T>
58 bool Apply(const T& object) const {
59 if (!is_init_) {
60 throw std::runtime_error("Cuts::Apply - cut is not initialized!!");
61 }
62 for (const auto& cut : cuts_) {
63 if (!cut.Apply(object))
64 return false;
65 }
66 return true;
67 }
68
69 bool Apply(const BranchChannel& ob) const;
70
71 bool Apply(std::vector<const BranchChannel*>& bch, std::vector<size_t>& id) const;
72 [[deprecated]] bool Apply(const BranchChannel& a, size_t a_id, const BranchChannel& b, size_t b_id) const;
73
74 void Init(const Configuration& conf);
75 void Print() const;
76
77 ANALYSISTREE_ATTR_NODISCARD const std::set<std::string>& GetBranches() const { return branch_names_; }
78 ANALYSISTREE_ATTR_DEPRECATED()
79 ANALYSISTREE_ATTR_NODISCARD const std::string&
80 GetBranchName() const {
81 assert(branch_names_.size() == 1);
82 return *branch_names_.begin();
83 }
84
85 ANALYSISTREE_ATTR_NODISCARD std::set<size_t> GetBranchIds() const { return branch_ids_; }
86 ANALYSISTREE_ATTR_NODISCARD const std::string& GetName() const { return name_; }
87
88 std::vector<SimpleCut>& GetCuts() { return cuts_; }
89
90 friend bool operator==(const Cuts& that, const Cuts& other);
91 static bool Equal(const Cuts* that, const Cuts* other);
92
93 protected:
94 std::string name_;
95 std::set<std::string> branch_names_{};
96 std::set<size_t> branch_ids_{};
97 std::vector<SimpleCut> cuts_{};
98
99 bool is_init_{false};
100
101 ClassDef(Cuts, 1);
102};
103
104}// namespace AnalysisTree
105#endif//ANALYSISTREE_CUTS_H
Definition BranchChannel.hpp:19
A class to store configuration of the whole AnalysisTree object.
Definition Configuration.hpp:58
Cuts holds list of SimpleCuts and provides Apply function which subsequently applies cuts.
Definition Cuts.hpp:25
bool Apply(const T &object) const
Evaluates all SimpleCuts.
Definition Cuts.hpp:58
Cuts keep list of SimpleCuts. Logical AND is applied for all SimpleCut in the Cuts object.
Definition BranchConfig.cpp:10