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 <iostream>
11#include <sstream>
12
13namespace Belle2 {
19 bool DecayNode::find_decay(const DecayNode& to_find) const
20 {
21 if (to_find == (*this))
22 return true;
23 for (const auto& node : daughters) {
24 if (node.find_decay(to_find))
25 return true;
26 }
27 return false;
28 }
29
30 std::string DecayNode::print_node(unsigned int indent) const
31 {
32 std::stringstream output;
33
34 for (unsigned int i = 0; i < indent; ++i) {
35 output << " ";
36 }
37
38 output << std::to_string(pdg);
39 output << std::endl;
40
41 for (const auto& d : daughters) {
42 output << d.print_node(indent + 1);
43 }
44
45 return output.str();
46 }
47
48 bool operator==(const DecayNode& node1, const DecayNode& node2)
49 {
50 if (node1.pdg == node2.pdg) {
51 if (node1.daughters.size() > 0 and node2.daughters.size() > 0) {
52 if (node1.daughters.size() != node2.daughters.size())
53 return false;
54 for (unsigned int i = 0; i < node1.daughters.size(); ++i) {
55 if (node1.daughters[i] != node2.daughters[i])
56 if (node1.daughters[i] != 0 and node2.daughters[i] != 0)
57 return false;
58 }
59 }
60 return true;
61 }
62 return false;
63 }
64
65 bool operator!=(const DecayNode& node1, const DecayNode& node2)
66 {
67 return not(node1 == node2);
68 }
69
71}
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:30
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:48
bool operator!=(const DecayNode &node1, const DecayNode &node2)
Not equal: See operator==.
Definition: DecayNode.cc:65
bool find_decay(const DecayNode &to_find) const
Check if the decay node contains the given decay tree.
Definition: DecayNode.cc:19
Abstract base class for different kinds of events.