Belle II Software development
Belle2::ParticleCopy Namespace Reference

Functions that create copies of Particles. More...

Functions

ParticlecopyParticle (const Particle *original)
 Function takes argument Particle and creates a copy of it and copies of all its (grand-)^n-daughters.
 
void copyDaughters (Particle *mother)
 Function copies all (grand-)^n-daughter particles of the argument mother Particle.
 

Detailed Description

Functions that create copies of Particles.

Functions take existing Particle and create its copy ((grand)^n-daughter particles are copied as well).

Function Documentation

◆ copyDaughters()

void copyDaughters ( Belle2::Particle mother)

Function copies all (grand-)^n-daughter particles of the argument mother Particle.

The copied particles are stored in the same StoreArray as the mother Particle and its original daughters. The indices of daughter particles in the mother Particle are replaced with the indices of copied daughter particles. The existing relations of the original daughter Particles are copied as well. Note that only the relation is copied and that the related object is not. Copy is related to the same object as the original one.

Parameters
motherpointer to the mother Particle whose daughters are to be copied

Definition at line 56 of file ParticleCopy.cc.

57{
58 // If the particle has undergone Bremsstrahlung correction, removing its
59 // daughters (the original lepton and potential photons) and then appending
60 // the copied versions should not change its source type.
61 // Or, if the particle's source is V0, it should be kept as V0 rather than changing to Composite.
62 bool updateType = true;
63 if (mother->hasExtraInfo("bremsCorrected") ||
64 mother->getParticleSource() == Particle::EParticleSourceObject::c_V0)
65 updateType = false;
66
67 unsigned nDaughters = mother->getNDaughters();
68 for (unsigned iOld_neverUsed = 0; iOld_neverUsed < nDaughters; iOld_neverUsed++) {
69 // always accessing the first daughter of mother that is being updated
70 const Particle* originalDaughter = mother->getDaughter(0);
71 Particle* daughterCopy = copyParticle(originalDaughter);
72
73 // remove original daughter from the beginning of the daughters' vector
74 mother->removeDaughter(originalDaughter, updateType);
75 // append copied daughter instead at the end of the daughters' vector
76 mother->appendDaughter(daughterCopy, updateType);
77 }
78}
Class to store reconstructed particles.
Definition: Particle.h:75
void appendDaughter(const Particle *daughter, const bool updateType=true, const int daughterProperty=c_Ordinary)
Appends index of daughter to daughters index array.
Definition: Particle.cc:676
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
Definition: Particle.cc:1266
unsigned getNDaughters(void) const
Returns number of daughter particles.
Definition: Particle.h:727
EParticleSourceObject getParticleSource() const
Returns particle source as defined with enum EParticleSourceObject.
Definition: Particle.h:478
void removeDaughter(const Particle *daughter, const bool updateType=true)
Removes index of daughter from daughters index array.
Definition: Particle.cc:688
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
Definition: Particle.cc:631
Particle * copyParticle(const Particle *original)
Function takes argument Particle and creates a copy of it and copies of all its (grand-)^n-daughters.
Definition: ParticleCopy.cc:18

◆ copyParticle()

Particle * copyParticle ( const Particle original)

Function takes argument Particle and creates a copy of it and copies of all its (grand-)^n-daughters.

The existing relations of the original Particle are copied as well. Note that only the relation is copied and that the related object is not. Copy is related to the same object as the original one.

Created copies are stored in the same StoreArray as the original Particle.

Parameters
originalpointer to the original Particle to be copied
Returns
returns pointer to the copied Particle

Definition at line 18 of file ParticleCopy.cc.

19{
20 StoreArray<Particle> array(original->getArrayName());
21
22 // make a copy of a particle
23 Particle* copy = array.appendNew(*original);
24 copy->copyRelations(original);
25 copy->writeExtraInfo("original_index", original->getArrayIndex());
26
27 // Copy its daughters as well.
28 // At this stage the copy of the particle
29 // internally stores daughter indices of original.
30 // Copy daughters as well.
31 unsigned nDaughters = original->getNDaughters();
32
33 // If the particle has undergone Bremsstrahlung correction, removing its
34 // daughters (the original lepton and potential photons) and then appending
35 // the copied versions should not change its source type.
36 // Or, if the particle's source is V0, it should be kept as V0 rather than changing to Composite.
37 bool updateType = true;
38 if (copy->hasExtraInfo("bremsCorrected") ||
39 copy->getParticleSource() == Particle::EParticleSourceObject::c_V0)
40 updateType = false;
41
42 for (unsigned iOld = 0; iOld < nDaughters; iOld++) {
43 const Particle* originalDaughter = original->getDaughter(iOld);
44
45 Particle* daughterCopy = copyParticle(originalDaughter);
46
47 // remove original daughter
48 copy->removeDaughter(originalDaughter, updateType);
49 // append copied daughter instead
50 copy->appendDaughter(daughterCopy, updateType);
51 }
52
53 return copy;
54}
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113