Belle II Software development
ParticleCopy.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/ParticleCopy.h>
10#include <analysis/dataobjects/Particle.h>
11
12#include <framework/datastore/StoreArray.h>
13
14using namespace Belle2;
15using namespace std;
16
18{
19 StoreArray<Particle> array(original->getArrayName());
20
21 // make a copy of a particle
22 Particle* copy = array.appendNew(*original);
23 copy->copyRelations(original);
24 copy->writeExtraInfo("original_index", original->getArrayIndex());
25
26 // Copy its daughters as well.
27 // At this stage the copy of the particle
28 // internally stores daughter indices of original.
29 // Copy daughters as well.
30 unsigned nDaughters = original->getNDaughters();
31
32 // If the particle has undergone Bremsstrahlung correction, removing its
33 // daughters (the original lepton and potential photons) and then appending
34 // the copied versions should not change its source type.
35 // Or, if the particle's source is V0, it should be kept as V0 rather than changing to Composite.
36 bool updateType = true;
37 if (copy->hasExtraInfo("bremsCorrected") ||
38 copy->getParticleSource() == Particle::EParticleSourceObject::c_V0)
39 updateType = false;
40
41 for (unsigned iOld = 0; iOld < nDaughters; iOld++) {
42 const Particle* originalDaughter = original->getDaughter(iOld);
43
44 Particle* daughterCopy = copyParticle(originalDaughter);
45
46 // remove original daughter
47 copy->removeDaughter(originalDaughter, updateType);
48 // append copied daughter instead
49 copy->appendDaughter(daughterCopy, updateType);
50 }
51
52 return copy;
53}
54
56{
57 // If the particle has undergone Bremsstrahlung correction, removing its
58 // daughters (the original lepton and potential photons) and then appending
59 // the copied versions should not change its source type.
60 // Or, if the particle's source is V0, it should be kept as V0 rather than changing to Composite.
61 bool updateType = true;
62 if (mother->hasExtraInfo("bremsCorrected") ||
63 mother->getParticleSource() == Particle::EParticleSourceObject::c_V0)
64 updateType = false;
65
66 unsigned nDaughters = mother->getNDaughters();
67 for (unsigned iOld_neverUsed = 0; iOld_neverUsed < nDaughters; iOld_neverUsed++) {
68 // always accessing the first daughter of mother that is being updated
69 const Particle* originalDaughter = mother->getDaughter(0);
70 Particle* daughterCopy = copyParticle(originalDaughter);
71
72 // remove original daughter from the beginning of the daughters' vector
73 mother->removeDaughter(originalDaughter, updateType);
74 // append copied daughter instead at the end of the daughters' vector
75 mother->appendDaughter(daughterCopy, updateType);
76 }
77}
Class to store reconstructed particles.
Definition: Particle.h:76
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:707
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
Definition: Particle.cc:1351
unsigned getNDaughters(void) const
Returns number of daughter particles.
Definition: Particle.h:747
EParticleSourceObject getParticleSource() const
Returns particle source as defined with enum EParticleSourceObject.
Definition: Particle.h:489
void removeDaughter(const Particle *daughter, const bool updateType=true)
Removes index of daughter from daughters index array.
Definition: Particle.cc:719
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
Definition: Particle.cc:662
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
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
void copyDaughters(Particle *mother)
Function copies all (grand-)^n-daughter particles of the argument mother Particle.
Definition: ParticleCopy.cc:55
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:17
Abstract base class for different kinds of events.
STL namespace.