Belle II Software  release-05-01-25
ParticleCopy.cc
1 // ******************************************************************
2 // Particle copy utility
3 // authors: A. Zupanc (anze.zupanc@ijs.si)
4 // ******************************************************************
5 
6 #include <analysis/utility/ParticleCopy.h>
7 #include <analysis/dataobjects/Particle.h>
8 
9 #include <framework/datastore/StoreArray.h>
10 #include <iostream>
11 
12 using namespace Belle2;
13 using namespace std;
14 
16 {
17  StoreArray<Particle> array(original->getArrayName());
18 
19  // make a copy of a particle
20  Particle* copy = array.appendNew(*original);
21  copy->copyRelations(original);
22 
23  // Copy its daughters as well.
24  // At this stage the copy of the particle
25  // internally stores daughter indicies of original.
26  // Copy daughters as well.
27  unsigned nDaughters = original->getNDaughters();
28 
29  for (unsigned iOld = 0; iOld < nDaughters; iOld++) {
30  const Particle* originalDaughter = original->getDaughter(iOld);
31 
32  Particle* daughterCopy = copyParticle(originalDaughter);
33 
34  // If the particle has undergone Bremsstrahlung correction, removing its
35  // daughters (the original lepton and potential photons) and then appending
36  // the copied versions should not change its source type.
37  bool updateType = true;
38  if (copy->hasExtraInfo("bremsCorrected")) updateType = false;
39  // remove original daughter
40  copy->removeDaughter(originalDaughter, updateType);
41  // append copied daughter instead
42  copy->appendDaughter(daughterCopy, updateType);
43  }
44 
45  return copy;
46 }
47 
49 {
50  unsigned nDaughters = mother->getNDaughters();
51  for (unsigned iOld = 0; iOld < nDaughters; iOld++) {
52  const Particle* originalDaughter = mother->getDaughter(0);
53  Particle* daughterCopy = copyParticle(originalDaughter);
54 
55  // remove original daughter
56  mother->removeDaughter(originalDaughter);
57  // append copied daughter instead
58  mother->appendDaughter(daughterCopy);
59  }
60 }
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
Belle2::RelationsInterface::getArrayName
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
Definition: RelationsObject.h:379
Belle2::ParticleCopy::copyParticle
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:15
Belle2::Particle::getDaughter
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
Definition: Particle.cc:595
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Particle::getNDaughters
unsigned getNDaughters(void) const
Returns number of daughter particles.
Definition: Particle.h:625
Belle2::Particle
Class to store reconstructed particles.
Definition: Particle.h:77
Belle2::StoreArray< Particle >
Belle2::ParticleCopy::copyDaughters
void copyDaughters(Particle *mother)
Function copies all (grand-)^n-daughter particles of the argument mother Particle.
Definition: ParticleCopy.cc:48