Belle II Software  release-06-02-00
DecayForest.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/DecayForest.h>
10 
11 #include <cassert>
12 
13 using namespace Belle2;
14 
15 
16 DecayForest::DecayForest(const std::string& full_decaystring, bool save_memory, bool removeRadiativeGammaFlag)
17 {
18 
20  unsigned int start = 0;
21  for (unsigned int i = 0; i < full_decaystring.size(); ++i) {
22  if (full_decaystring[i] == '|') {
23  forest.emplace_back(full_decaystring.substr(start, i - start), removeRadiativeGammaFlag);
24  start = i + 1;
25  if (save_memory and forest.back().isValid() and forest.size() > 1)
26  break;
27  }
28  }
29 
30  if (not(save_memory and forest.back().isValid() and forest.size() > 1))
31  forest.emplace_back(full_decaystring.substr(start, full_decaystring.size() - start), removeRadiativeGammaFlag);
32 
33  for (unsigned int j = 1; j < forest.size(); ++j) {
34  if (forest[j].isValid()) {
36  break;
37  }
38  }
39 
40 }
41 
42 
43 int DecayForest::decayHashFloatToInt(float decayHash, float decayHashExtended)
44 {
45 
46  // Convert unsigned int decay hash into a float keeping the same bit pattern
47  assert(sizeof(float) == sizeof(uint32_t));
48 
49  union convert {
50  uint32_t i;
51  float f;
52  };
53  convert bitconverter;
54 
55  uint64_t integer = 0;
56 
57  bitconverter.f = decayHash;
58  integer = static_cast<uint64_t>(bitconverter.i) << 32;
59  // cppcheck throws false positives here (doesn't understand this use of a union)
60  //
61  // cppcheck-suppress redundantAssignment
62  bitconverter.f = decayHashExtended;
63  integer += bitconverter.i;
64 
65  return integer;
66 
67 }
std::vector< DecayTree > forest
vector of DecayTrees
Definition: DecayForest.h:66
size_t m_first_valid_original
The first valid DecayTree.
Definition: DecayForest.h:67
static int decayHashFloatToInt(float decayHash, float decayHashExtended)
Convert DecayHashes outputted by ParticleMCDecayString module to an integer.
Definition: DecayForest.cc:43
DecayForest(const std::string &full_decaystring, bool save_memory=true, bool removeRadiativeGammaFlag=false)
Create a DecayForest from a full decaystring outputted by ParticleMCDecayString.
Definition: DecayForest.cc:16
Abstract base class for different kinds of events.