Belle II Software  release-06-02-00
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 #include <iostream>
14 
15 using namespace Belle2;
16 using namespace std;
17 
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 
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  for (unsigned iOld = 0; iOld < nDaughters; iOld++) {
33  const Particle* originalDaughter = original->getDaughter(iOld);
34 
35  Particle* daughterCopy = copyParticle(originalDaughter);
36 
37  // If the particle has undergone Bremsstrahlung correction, removing its
38  // daughters (the original lepton and potential photons) and then appending
39  // the copied versions should not change its source type.
40  bool updateType = true;
41  if (copy->hasExtraInfo("bremsCorrected")) updateType = false;
42  // remove original daughter
43  copy->removeDaughter(originalDaughter, updateType);
44  // append copied daughter instead
45  copy->appendDaughter(daughterCopy, updateType);
46  }
47 
48  return copy;
49 }
50 
52 {
53  unsigned nDaughters = mother->getNDaughters();
54  for (unsigned iOld = 0; iOld < nDaughters; iOld++) {
55  const Particle* originalDaughter = mother->getDaughter(0);
56  Particle* daughterCopy = copyParticle(originalDaughter);
57 
58  // remove original daughter
59  mother->removeDaughter(originalDaughter);
60  // append copied daughter instead
61  mother->appendDaughter(daughterCopy);
62  }
63 }
Class to store reconstructed particles.
Definition: Particle.h:74
unsigned getNDaughters(void) const
Returns number of daughter particles.
Definition: Particle.h:647
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
Definition: Particle.cc:639
std::string getArrayName() const
Get name of array this object is stored in, or "" 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:51
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
Abstract base class for different kinds of events.