Belle II Software  release-05-02-19
DecayNode.cc
1 /* BASF2 (Belle Analysis Framework 2) *
2  * Copyright(C) 2016 - Belle II Collaboration *
3  * *
4  * Author: The Belle II Collaboration *
5  * Contributors: Thomas Keck *
6  * *
7  * This software is provided "as is" without any warranty. *
8  * *
9  **************************************************************************/
10 
11 #include <analysis/utility/DecayNode.h>
12 #include <iostream>
13 #include <sstream>
14 
15 namespace Belle2 {
21  bool DecayNode::find_decay(const DecayNode& to_find) const
22  {
23  if (to_find == (*this))
24  return true;
25  for (const auto& node : daughters) {
26  if (node.find_decay(to_find))
27  return true;
28  }
29  return false;
30  }
31 
32  std::string DecayNode::print_node(unsigned int indent) const
33  {
34  std::stringstream output;
35 
36  for (unsigned int i = 0; i < indent; ++i) {
37  output << " ";
38  }
39 
40  output << std::to_string(pdg);
41  output << std::endl;
42 
43  for (const auto& d : daughters) {
44  output << d.print_node(indent + 1);
45  }
46 
47  return output.str();
48  }
49 
50  bool operator==(const DecayNode& node1, const DecayNode& node2)
51  {
52  if (node1.pdg == node2.pdg) {
53  if (node1.daughters.size() > 0 and node2.daughters.size() > 0) {
54  if (node1.daughters.size() != node2.daughters.size())
55  return false;
56  for (unsigned int i = 0; i < node1.daughters.size(); ++i) {
57  if (node1.daughters[i] != node2.daughters[i])
58  if (node1.daughters[i] != 0 and node2.daughters[i] != 0)
59  return false;
60  }
61  }
62  return true;
63  }
64  return false;
65  }
66 
67  bool operator!=(const DecayNode& node1, const DecayNode& node2)
68  {
69  return not(node1 == node2);
70  }
71 
73 }
Belle2::DecayNode::print_node
std::string print_node(unsigned int indent=0) const
Output a single node.
Definition: DecayNode.cc:32
Belle2::operator==
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:50
Belle2::operator!=
bool operator!=(const DecayNode &node1, const DecayNode &node2)
Not equal: See operator==.
Definition: DecayNode.cc:67
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DecayNode::find_decay
bool find_decay(const DecayNode &to_find) const
Check if the decay node contains the given decay tree.
Definition: DecayNode.cc:21
Belle2::DecayNode
DecayNode describes the decay of a particle identified by its pdg code, into list of daughters.
Definition: DecayNode.h:35
Belle2::DecayNode::daughters
std::vector< DecayNode > daughters
daughter decay nodes
Definition: DecayNode.h:60
Belle2::DecayNode::pdg
int pdg
pdg code of the particle
Definition: DecayNode.h:59