Belle II Software development
ParticleMomentumUpdaterModule.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 <iostream>
10
11#include <analysis/modules/ParticleMomentumUpdater/ParticleMomentumUpdaterModule.h>
12#include <analysis/dataobjects/ParticleList.h>
13
14#include <framework/datastore/StoreArray.h>
15#include <framework/logging/Logger.h>
16
17#include <analysis/utility/PCmsLabTransform.h>
18#include <analysis/utility/ParticleCopy.h>
19
20#include <algorithm>
21
22using namespace std;
23using namespace Belle2;
24
25// Register module in the framework
26REG_MODULE(ParticleMomentumUpdater);
27
29{
30
31 //Set module properties
32 setDescription("This module replaces the momentum of the particles in the selected target particle list by p(beam) - p(selected daughters). The momentum of the mother particle will not be changed.");
34 //Parameter definition
35 addParam("particleList", m_particleList, "Name of particle list with reconstructed particles.");
36 addParam("decayStringTarget", m_decayStringTarget,
37 "DecayString specifying the target particle whose momentum will be updated",
38 std::string(""));
39 addParam("decayStringDaughters", m_decayStringDaughters,
40 "DecayString specifying the daughter particles used to replace the momentum of the target particle by p(beam)-p(daughters)",
41 std::string(""));
42}
43
45{
48 particles.isRequired();
49
51 if (!valid)
52 B2ERROR("ParticleMomentumUpdaterModule::initialize invalid Decay Descriptor: " << m_decayStringDaughters);
53
55 if (!valid)
56 B2ERROR("ParticleMomentumUpdaterModule::initialize invalid Decay Descriptor: " << m_decayStringTarget);
57 else if (m_pDDescriptorTarget.getSelectionPDGCodes().size() != 1)
58 B2ERROR("ParticleMomentumUpdaterModule::initialize please select exactly one target: " << m_decayStringTarget);
59}
60
62{
63
64 StoreArray<Particle> particles;
66
67 if (!plist) {
68 B2ERROR("ParticleList " << m_particleList << " not found");
69 return;
70 }
71
73 ROOT::Math::PxPyPzEVector boost4Vector = T.getBeamFourMomentum();
74 ROOT::Math::PxPyPzEVector daughters4Vector;
75
76 const unsigned int numParticles = plist->getListSize();
77 for (unsigned int i = 0; i < numParticles; i++) {
78 Particle* iParticle = plist->getParticle(i);
79
80 std::vector<const Particle*> selParticlesTarget = m_pDDescriptorTarget.getSelectionParticles(iParticle);
81 std::vector<const Particle*> selParticlesDaughters = m_pDDescriptorDaughters.getSelectionParticles(iParticle);
82
83 daughters4Vector = {0., 0., 0., 0.};
84 for (auto& selParticle : selParticlesDaughters) {
85 daughters4Vector += selParticle->get4Vector();
86 }
87
88 Particle* targetP = particles[selParticlesTarget[0]->getArrayIndex()];
89 if (targetP == iParticle) {
90 iParticle->set4Vector(boost4Vector - daughters4Vector);
91 } else {
92 Particle* daughterCopy = Belle2::ParticleCopy::copyParticle(targetP);
93 daughterCopy->set4Vector(boost4Vector - daughters4Vector);
94 bool isReplaced = iParticle->replaceDaughterRecursively(targetP, daughterCopy);
95 if (!isReplaced)
96 B2ERROR("ParticleMomentumUpdaterModule::event No target particle found for " << m_decayStringTarget);
97 }
98 }
99}
100
102{
103}
104
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
std::vector< int > getSelectionPDGCodes()
Return list of PDG codes of selected particles.
std::vector< const Particle * > getSelectionParticles(const Particle *particle)
Get a vector of pointers with selected daughters in the decay tree.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
Class to hold Lorentz transformations from/to CMS and boost vector.
ROOT::Math::PxPyPzEVector getBeamFourMomentum() const
Returns LAB four-momentum of e+e-, i.e.
std::string m_decayStringDaughters
DecayString specifying the daughters used to update the momentum of the target particle.
virtual void initialize() override
Initialises the module.
virtual void event() override
Method called for each event.
virtual void terminate() override
Write TTree to file, and close file if necessary.
DecayDescriptor m_pDDescriptorTarget
Decay descriptor of the target particles.
std::string m_particleList
name of input particle list.
DecayDescriptor m_pDDescriptorDaughters
Decay descriptor of the daughter particles.
std::string m_decayStringTarget
DecayString specifying the target Particle whose momentum will be updated.
Class to store reconstructed particles.
Definition: Particle.h:75
void set4Vector(const ROOT::Math::PxPyPzEVector &p4)
Sets Lorentz vector.
Definition: Particle.h:271
bool replaceDaughterRecursively(const Particle *oldDaughter, Particle *newDaughter)
Apply replaceDaughter to all Particles in the decay tree by looping recursively through it,...
Definition: Particle.cc:723
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
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.
STL namespace.