AnalysisTree
Loading...
Searching...
No Matches
Matching.hpp
1/* Copyright (C) 2019-2026 GSI, Universität Tübingen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Viktor Klochkov, Ilya Selyuzhenkov, Frederic Linz */
4#ifndef ANALYSISTREE_MATCHING_H
5#define ANALYSISTREE_MATCHING_H
6
7#include "Constants.hpp"
8#include <map>
9#include <vector>
10
11namespace AnalysisTree {
12
17class MatchRange {
18 public:
19 MatchRange() = default;
20 MatchRange(const Integer_t* begin, const Integer_t* end) : begin_(begin), end_(end) {}
21
22 ANALYSISTREE_ATTR_NODISCARD const Integer_t* begin() const { return begin_; }
23 ANALYSISTREE_ATTR_NODISCARD const Integer_t* end() const { return end_; }
24 ANALYSISTREE_ATTR_NODISCARD size_t size() const { return end_ - begin_; }
25 ANALYSISTREE_ATTR_NODISCARD bool empty() const { return begin_ == end_; }
26 ANALYSISTREE_ATTR_NODISCARD Integer_t operator[](size_t i) const { return begin_[i]; }
27
28 private:
29 const Integer_t* begin_{nullptr};
30 const Integer_t* end_{nullptr};
31};
32
41class Matching {
42
43 public:
44 Matching() = default;
45 Matching(size_t id1, size_t id2) : branch1_id_(id1), branch2_id_(id2){};
46
47 virtual ~Matching() = default;
48
52 void AddMatch(Integer_t id1, Integer_t id2);
53
57 ANALYSISTREE_ATTR_NODISCARD MatchRange GetMatchesDirect(Integer_t id1) const;
58 ANALYSISTREE_ATTR_NODISCARD MatchRange GetMatchesInverted(Integer_t id2) const;
59 ANALYSISTREE_ATTR_NODISCARD MatchRange GetMatches(Integer_t id, bool is_inverted) const {
60 return is_inverted ? GetMatchesInverted(id) : GetMatchesDirect(id);
61 }
62
66 ANALYSISTREE_ATTR_NODISCARD Integer_t GetMatchDirect(Integer_t id) const;
67 ANALYSISTREE_ATTR_NODISCARD Integer_t GetMatchInverted(Integer_t id) const;
68 ANALYSISTREE_ATTR_NODISCARD Integer_t GetMatch(Integer_t id, bool is_inverted = false) const {
69 return is_inverted ? GetMatchInverted(id) : GetMatchDirect(id);
70 }
71
72 ANALYSISTREE_ATTR_NODISCARD size_t GetNumberOfPairs() const {
74 return ids2_.size();
75 }
76
80 ANALYSISTREE_ATTR_NODISCARD size_t GetNumberOfIds(bool is_inverted = false) const;
81
82 void Clear();
83
84 ANALYSISTREE_ATTR_NODISCARD size_t GetBranch1Id() const { return branch1_id_; }
85 ANALYSISTREE_ATTR_NODISCARD size_t GetBranch2Id() const { return branch2_id_; }
86
87 protected:
88 void BuildInverse() const;
89
93 void ConvertLegacy() const;
94
95 size_t branch1_id_{0};
96 size_t branch2_id_{0};
97
98 std::vector<Integer_t> offsets_{};
99 std::vector<Integer_t> ids2_{};
100
101 std::map<Integer_t, Integer_t> match_{};
102 std::map<Integer_t, Integer_t> match_inverted_{};
103
104 mutable std::vector<Integer_t> inv_offsets_{};
105 mutable std::vector<Integer_t> inv_ids1_{};
106 mutable bool inverse_valid_{false};
107
108 ClassDef(Matching, 3)
109};
110
111}// namespace AnalysisTree
112#endif//ANALYSISTREE_MATCHING_H
Definition Matching.hpp:17
ANALYSISTREE_ATTR_NODISCARD size_t GetNumberOfIds(bool is_inverted=false) const
Definition Matching.cpp:60
std::map< Integer_t, Integer_t > match_inverted_
legacy (version <= 2): only filled when reading old files
Definition Matching.hpp:102
std::vector< Integer_t > inv_ids1_
inverse CSR, built on first use
Definition Matching.hpp:105
std::vector< Integer_t > offsets_
partners of id1 are ids2_[offsets_[id1], offsets_[id1 + 1])
Definition Matching.hpp:98
void ConvertLegacy() const
Definition Matching.cpp:101
ANALYSISTREE_ATTR_NODISCARD MatchRange GetMatchesDirect(Integer_t id1) const
Definition Matching.cpp:31
std::map< Integer_t, Integer_t > match_
legacy (version <= 2): only filled when reading old files
Definition Matching.hpp:101
void AddMatch(Integer_t id1, Integer_t id2)
Definition Matching.cpp:11
std::vector< Integer_t > ids2_
partner ids grouped by id1
Definition Matching.hpp:99
ANALYSISTREE_ATTR_NODISCARD Integer_t GetMatchDirect(Integer_t id) const
Definition Matching.cpp:50
Cuts keep list of SimpleCuts. Logical AND is applied for all SimpleCut in the Cuts object.
Definition BranchConfig.cpp:10