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