Belle II Software  release-05-01-25
ParticleCombiner.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2014-2019 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Keck, Anze Zupanc *
7  * Sam Cunliffe, Torben Ferber *
8  * *
9  * This software is provided "as is" without any warranty. *
10  **************************************************************************/
11 
12 #pragma once
13 
14 #include <analysis/dataobjects/ParticleList.h>
15 #include <analysis/dataobjects/Particle.h>
16 #include <analysis/VariableManager/Utility.h>
17 #include <analysis/DecayDescriptor/DecayDescriptor.h>
18 
19 #include <framework/datastore/StoreArray.h>
20 #include <framework/datastore/StoreObjPtr.h>
21 
22 #include <vector>
23 #include <set>
24 #include <unordered_set>
25 #include <unordered_map>
26 
27 #include <utility>
28 
29 #include <boost/functional/hash/extensions.hpp>
30 
31 namespace std {
33  template<> struct hash<std::set<int>> {
35  std::size_t operator()(const std::set<int>& v) const
36  {
37  return boost::hash_value(v);
38  }
39  };
40 }
41 
42 namespace Belle2 {
53 
54  public:
59 
64  void init(const std::vector<unsigned int>& _sizes);
65 
69  bool loadNext();
70 
74  const std::vector<unsigned int>& getCurrentIndices() const;
75 
76 
77  private:
78 
79  unsigned int m_numberOfLists;
80  unsigned int m_iCombination;
81  unsigned int m_nCombinations;
82  std::vector<unsigned int> indices;
83  std::vector<unsigned int> sizes;
85  };
86 
95  public:
100 
105  void init(unsigned int _numberOfLists);
106 
110  bool loadNext();
111 
115  const std::vector<ParticleList::EParticleType>& getCurrentIndices() const;
116 
117  private:
118 
119  unsigned int m_numberOfLists;
120  unsigned int m_iCombination;
121  unsigned int m_nCombinations;
122  std::vector<ParticleList::EParticleType> m_types;
124  };
125 
130  public:
131 
132  public:
138  explicit ParticleGenerator(const std::string& decayString, const std::string& cutParameter = "");
139 
145  explicit ParticleGenerator(const DecayDescriptor& decaydescriptor, const std::string& cutParameter = "");
146 
150  void init();
151 
155  bool loadNext(bool loadAntiParticle = true);
156 
161 
169  bool inputListsCollide() const {return m_inputListsCollide; };
170 
176  bool inputListsCollide(const std::pair<unsigned, unsigned>& pair) const;
177 
185  int getUniqueID(int index) const;
186 
187  private:
192 
196  bool loadNextParticle(bool useAntiParticle);
197 
202 
212 
227 
236 
244 
250  void fillIndicesToUniqueIDMap(const std::vector<int>& listA, const std::vector<int>& listB, int& uniqueID);
251 
255  void fillIndicesToUniqueIDMap(const std::vector<int>& listA, int& uniqueID);
256 
257  private:
258 
259  int m_pdgCode;
261  unsigned int m_iParticleType;
263  std::vector<int> m_daughterProperties;
265  unsigned int m_numberOfLists;
266  std::vector<StoreObjPtr<ParticleList>> m_plists;
274  std::vector<Particle*> m_particles;
275  std::vector<int> m_indices;
276  std::unordered_set<std::set<int>> m_usedCombinations;
279  std::vector<std::pair<unsigned, unsigned>> m_collidingLists;
280  std::unordered_map<int, int>
283  std::unique_ptr<Variable::Cut> m_cut;
286  };
287 
288 
290 }
Belle2::ParticleGenerator::m_indices
std::vector< int > m_indices
Indices stored in the ParticleLists of the current combination.
Definition: ParticleCombiner.h:275
Belle2::ParticleIndexGenerator::indices
std::vector< unsigned int > indices
The indices of the current loaded combination.
Definition: ParticleCombiner.h:82
Belle2::ParticleGenerator::m_listIndexGenerator
ListIndexGenerator m_listIndexGenerator
listIndexGenerator makes the combinations of the types of sublists of the ParticleLists
Definition: ParticleCombiner.h:269
Belle2::ParticleGenerator::initIndicesToUniqueIDMap
void initIndicesToUniqueIDMap()
In the case input daughter particle lists collide (two or more lists contain copies of Particles) the...
Definition: ParticleCombiner.cc:245
Belle2::ParticleGenerator::init
void init()
Initialises the generator to produce the given type of sublist.
Definition: ParticleCombiner.cc:231
Belle2::ParticleGenerator::getUniqueID
int getUniqueID(int index) const
Returns the unique ID assigned to Particle with given index from the IndicesToUniqueID map.
Definition: ParticleCombiner.cc:585
Belle2::ParticleGenerator::m_pdgCode
int m_pdgCode
PDG Code of the particle which is combined.
Definition: ParticleCombiner.h:259
Belle2::ParticleGenerator::loadNextParticle
bool loadNextParticle(bool useAntiParticle)
Loads the next combination.
Definition: ParticleCombiner.cc:373
Belle2::ListIndexGenerator::getCurrentIndices
const std::vector< ParticleList::EParticleType > & getCurrentIndices() const
Returns the type of the sublist of the current loaded combination.
Definition: ParticleCombiner.cc:115
Belle2::ParticleGenerator::loadNext
bool loadNext(bool loadAntiParticle=true)
Loads the next combination.
Definition: ParticleCombiner.cc:336
Belle2::ListIndexGenerator
ListIndexGenerator is a generator for all the combinations of the sublists (FlavorSpecificParticle = ...
Definition: ParticleCombiner.h:94
Belle2::ParticleGenerator::m_isSelfConjugated
bool m_isSelfConjugated
True if the combined particle is self-conjugated.
Definition: ParticleCombiner.h:260
Belle2::ParticleGenerator::m_particleArray
const StoreArray< Particle > m_particleArray
Global list of particles.
Definition: ParticleCombiner.h:273
Belle2::ParticleGenerator::m_cut
std::unique_ptr< Variable::Cut > m_cut
cut object which performs the cuts
Definition: ParticleCombiner.h:283
Belle2::ParticleGenerator::fillIndicesToUniqueIDMap
void fillIndicesToUniqueIDMap(const std::vector< int > &listA, const std::vector< int > &listB, int &uniqueID)
Assignes unique IDs to all particles in list A, which do not have the unique ID already assigned.
Definition: ParticleCombiner.cc:297
Belle2::ParticleGenerator::m_collidingLists
std::vector< std::pair< unsigned, unsigned > > m_collidingLists
pairs of lists that can contain copies.
Definition: ParticleCombiner.h:279
Belle2::ListIndexGenerator::ListIndexGenerator
ListIndexGenerator()
Default constructor.
Definition: ParticleCombiner.h:99
Belle2::ListIndexGenerator::m_types
std::vector< ParticleList::EParticleType > m_types
The current types of sublist of the ParticleLists for this combination.
Definition: ParticleCombiner.h:122
Belle2::ParticleGenerator::m_numberOfLists
unsigned int m_numberOfLists
Number of lists which are combined.
Definition: ParticleCombiner.h:265
Belle2::ParticleGenerator::m_particleIndexGenerator
ParticleIndexGenerator m_particleIndexGenerator
particleIndexGenerator makes the combinations of indices stored in the sublists of the ParticleLists
Definition: ParticleCombiner.h:271
Belle2::ParticleIndexGenerator::ParticleIndexGenerator
ParticleIndexGenerator()
Default constructor.
Definition: ParticleCombiner.h:58
Belle2::ParticleGenerator::inputListsCollide
bool inputListsCollide() const
True if input lists collide (can contain copies of particles in the input lists).
Definition: ParticleCombiner.h:169
Belle2::ParticleIndexGenerator::init
void init(const std::vector< unsigned int > &_sizes)
Initialises the generator to produce combinations with the given sizes of each particle list.
Definition: ParticleCombiner.cc:38
Belle2::ParticleGenerator::m_particles
std::vector< Particle * > m_particles
Pointers to the particle objects of the current combination.
Definition: ParticleCombiner.h:274
Belle2::ParticleGenerator::currentCombinationHasDifferentSources
bool currentCombinationHasDifferentSources()
Check that all FS particles of a combination differ.
Definition: ParticleCombiner.cc:485
Belle2::ParticleGenerator::ParticleGenerator
ParticleGenerator(const std::string &decayString, const std::string &cutParameter="")
Initialises the generator to produce the given type of sublist.
Definition: ParticleCombiner.cc:120
Belle2::ParticleIndexGenerator
ParticleIndexGenerator is a generator for all the combinations of the particle indices stored in the ...
Definition: ParticleCombiner.h:52
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ParticleIndexGenerator::m_numberOfLists
unsigned int m_numberOfLists
Number of lists which are combined.
Definition: ParticleCombiner.h:79
Belle2::ParticleGenerator::m_indicesToUniqueIDs
std::unordered_map< int, int > m_indicesToUniqueIDs
map of store array indices of input Particles to their unique IDs.
Definition: ParticleCombiner.h:281
Belle2::ParticleGenerator::getCurrentParticle
Particle getCurrentParticle() const
Returns the particle.
Definition: ParticleCombiner.cc:480
Belle2::ParticleIndexGenerator::loadNext
bool loadNext()
Loads the next combination.
Definition: ParticleCombiner.cc:61
Belle2::ListIndexGenerator::m_nCombinations
unsigned int m_nCombinations
The total amount of combinations.
Definition: ParticleCombiner.h:121
Belle2::ParticleGenerator::m_daughterProperties
std::vector< int > m_daughterProperties
Daughter's particle properties.
Definition: ParticleCombiner.h:263
Belle2::ListIndexGenerator::m_iCombination
unsigned int m_iCombination
The current position of the combination.
Definition: ParticleCombiner.h:120
Belle2::ParticleGenerator::m_iParticleType
unsigned int m_iParticleType
The type of particle which is currently generated.
Definition: ParticleCombiner.h:261
Belle2::ParticleIndexGenerator::m_iCombination
unsigned int m_iCombination
The current position of the combination.
Definition: ParticleCombiner.h:80
Belle2::ParticleGenerator::m_usedCombinations
std::unordered_set< std::set< int > > m_usedCombinations
already used combinations (as sets of indices or unique IDs).
Definition: ParticleCombiner.h:276
Belle2::ListIndexGenerator::init
void init(unsigned int _numberOfLists)
Initialises the generator to produce the given type of sublist.
Definition: ParticleCombiner.cc:90
Belle2::ParticleIndexGenerator::getCurrentIndices
const std::vector< unsigned int > & getCurrentIndices() const
Returns theindices of the current loaded combination.
Definition: ParticleCombiner.cc:85
Belle2::ParticleGenerator::m_inputListsCollide
bool m_inputListsCollide
True if the daughter lists can contain copies of Particles.
Definition: ParticleCombiner.h:278
Belle2::ParticleGenerator::m_current_particle
Particle m_current_particle
The current Particle object generated by this combiner.
Definition: ParticleCombiner.h:285
Belle2::Particle
Class to store reconstructed particles.
Definition: Particle.h:77
Belle2::ParticleGenerator::m_plists
std::vector< StoreObjPtr< ParticleList > > m_plists
particle lists
Definition: ParticleCombiner.h:266
Belle2::ParticleIndexGenerator::m_nCombinations
unsigned int m_nCombinations
The total amount of combinations.
Definition: ParticleCombiner.h:81
Belle2::ParticleGenerator::currentCombinationIsECLCRUnique
bool currentCombinationIsECLCRUnique()
Check that: if the current combination has at least two particles from an ECL source,...
Definition: ParticleCombiner.cc:533
Belle2::ListIndexGenerator::m_numberOfLists
unsigned int m_numberOfLists
Number of lists which are combined.
Definition: ParticleCombiner.h:119
Belle2::DecayDescriptor
The DecayDescriptor stores information about a decay tree or parts of a decay tree.
Definition: DecayDescriptor.h:43
Belle2::ParticleGenerator::currentCombinationIsUnique
bool currentCombinationIsUnique()
Check that the combination is unique.
Definition: ParticleCombiner.cc:511
Belle2::ParticleIndexGenerator::sizes
std::vector< unsigned int > sizes
The sizes of the particle lists which are combined.
Definition: ParticleCombiner.h:83
Belle2::StoreArray< Particle >
Belle2::ParticleGenerator::createCurrentParticle
Particle createCurrentParticle() const
Create current particle object.
Definition: ParticleCombiner.cc:449
Belle2::ParticleGenerator::m_properties
int m_properties
Particle property.
Definition: ParticleCombiner.h:262
Belle2::ParticleGenerator::loadNextSelfConjugatedParticle
bool loadNextSelfConjugatedParticle()
Loads the next combination.
Definition: ParticleCombiner.cc:417
Belle2::ParticleGenerator
ParticleGenerator is a generator for all the particles combined from the given ParticleLists.
Definition: ParticleCombiner.h:129