Belle II Software development
DecayNode.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <analysis/utility/DecayNode.h>
10#include <sstream>
11
12namespace Belle2 {
18 bool DecayNode::find_decay(const DecayNode& to_find) const
19 {
20 if (to_find == (*this))
21 return true;
22 for (const auto& node : daughters) {
23 if (node.find_decay(to_find))
24 return true;
25 }
26 return false;
27 }
28
29 std::string DecayNode::print_node(unsigned int indent) const
30 {
31 std::stringstream output;
32
33 for (unsigned int i = 0; i < indent; ++i) {
34 output << " ";
35 }
36
37 output << std::to_string(pdg);
38 output << std::endl;
39
40 for (const auto& d : daughters) {
41 output << d.print_node(indent + 1);
42 }
43
44 return output.str();
45 }
46
47 bool operator==(const DecayNode& node1, const DecayNode& node2)
48 {
49 if (node1.pdg == node2.pdg) {
50 if (node1.daughters.size() > 0 and node2.daughters.size() > 0) {
51 if (node1.daughters.size() != node2.daughters.size())
52 return false;
53 for (unsigned int i = 0; i < node1.daughters.size(); ++i) {
54 if (node1.daughters[i] != node2.daughters[i])
55 if (node1.daughters[i] != 0 and node2.daughters[i] != 0)
56 return false;
57 }
58 }
59 return true;
60 }
61 return false;
62 }
63
64 bool operator!=(const DecayNode& node1, const DecayNode& node2)
65 {
66 return not(node1 == node2);
67 }
68
70}
DecayNode describes the decay of a particle identified by its pdg code, into list of daughters.
Definition: DecayNode.h:23
std::vector< DecayNode > daughters
daughter decay nodes
Definition: DecayNode.h:48
int pdg
pdg code of the particle
Definition: DecayNode.h:47
std::string print_node(unsigned int indent=0) const
Output a single node.
Definition: DecayNode.cc:29
bool operator==(const DecayNode &node1, const DecayNode &node2)
Compare two Decay Nodes: They are equal if All daughter decay nodes are equal or one of the daughter ...
Definition: DecayNode.cc:47
bool operator!=(const DecayNode &node1, const DecayNode &node2)
Not equal: See operator==.
Definition: DecayNode.cc:64
bool find_decay(const DecayNode &to_find) const
Check if the decay node contains the given decay tree.
Definition: DecayNode.cc:18
Abstract base class for different kinds of events.