Belle II Software light-2406-ragdoll
TwoBodyISRPhotonCorrectorModule.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/TwoBodyISRPhotonCorrector/TwoBodyISRPhotonCorrectorModule.h>
12
13#include <analysis/dataobjects/Particle.h>
14
15#include <framework/datastore/StoreArray.h>
16#include <framework/logging/Logger.h>
17#include <framework/gearbox/Const.h>
18
19#include <analysis/DecayDescriptor/DecayDescriptor.h>
20#include <analysis/DecayDescriptor/DecayDescriptorParticle.h>
21#include <analysis/utility/PCmsLabTransform.h>
22#include <analysis/utility/ParticleCopy.h>
23#include <TDatabasePDG.h>
24
25#include <algorithm>
26
27using namespace Belle2;
28
29// Register module in the framework
30REG_MODULE(TwoBodyISRPhotonCorrector);
31
33{
34 //Set module properties
35 setDescription("This module corrects the energy and momentum of high energy ISR photons in single ISR events based on the beam energy, photon direction, and mass of the recoil particle. The corrected photons are stored in a new list, the original photon kinematics can be accessed via the originalParticle() metavariable.");
36 //Parameter definition
37 addParam("inputGammaList", m_inputGammaListName, "Name of photon list containing the ISR gammas to be corrected");
38 addParam("outputGammaList", m_outputGammaListName, "Name of photon list containing the corrected ISR gammas");
39 addParam("massiveParticlePDGCode", m_massiveParticlePDGCode,
40 "Name of the massive particle participating in the two body decay with the ISR gamma.");
41}
42
44{
46 DecayDescriptor inputDD, outputDD;
47
48 // Output list checks
49 bool outputValid = outputDD.init(m_outputGammaListName);
50 if (!outputValid)
51 B2ERROR("Invalid output ParticleList: " << m_outputGammaListName);
52 if (outputDD.getMother()->getPDGCode() != Const::photon.getPDGCode())
53 B2ERROR("TwoBodyISRPhotonCorrectorModule::event ParticleList " << m_outputGammaListName << " is not a gamma list");
54
55 // Input list checks
57 B2ERROR("TwoBodyISRPhotonCorrectorModule: cannot copy Particles from " << m_inputGammaListName <<
58 " to itself!");
59 } else if (!inputDD.init(m_inputGammaListName)) {
60 B2ERROR("Invalid input ParticleList name: " << m_inputGammaListName);
61 } else {
62 if (inputDD.getMother()->getPDGCode() != Const::photon.getPDGCode())
63 B2ERROR("TwoBodyISRPhotonCorrectorModule::event ParticleList " << m_inputGammaListName << " is not a gamma list");
64
66 }
67
69
70 TParticlePDG* massiveParticlePDG = TDatabasePDG::Instance()->GetParticle(m_massiveParticlePDGCode);
71 B2DEBUG(19, "TwoBodyISRPhotonCorrectorModule: PDG code " << m_massiveParticlePDGCode <<
72 " selected for massive particle participating in two body decay. Its mass is " <<
73 massiveParticlePDG->Mass() << " GeV/c^2.");
74
75}
76
78{
80
81 bool existingList = m_outputGammaList.isValid();
82 if (!existingList) {
83 // new particle list: create it
84 m_outputGammaList.create();
85 m_outputGammaList->initialize(Const::photon.getPDGCode(), m_outputGammaListName);
86 } else {
87 B2WARNING("TwoBodyISRPhotonCorrectorModule: Output ParticleList " << m_outputGammaListName << " already exists. Overwriting.");
88 m_outputGammaList->clear();
89 }
90
91 // Initialize the mass to which we are constraining and the beam momentum
92 const double massMassiveParticle = TDatabasePDG::Instance()->GetParticle(m_massiveParticlePDGCode)->Mass();
94 ROOT::Math::PxPyPzEVector P4beam = T.getBeamFourMomentum();
95
96 // Loop through the given gamma list
97 const unsigned int numParticles = inputGammaList->getListSize();
98 for (unsigned int i = 0; i < numParticles; i++) {
99 ROOT::Math::PxPyPzEVector P4corrected;
100
101 // Get gamma and it's 4 momentum
102 Particle* iParticle = inputGammaList->getParticle(i);
103 ROOT::Math::PxPyPzEVector P4gamma = iParticle->get4Vector();
104
105 // Calculate corrected energy for photon in list
106 ROOT::Math::XYZVector p3gamma_unit((P4gamma.Vect()).Unit());
107 ROOT::Math::XYZVector pbeam(P4beam.Vect());
108 double E_corrected = 0.5 * (P4beam.mag2() - massMassiveParticle * massMassiveParticle) /
109 (P4beam.E() - pbeam.Dot(p3gamma_unit));
110 P4corrected.SetPxPyPzE(p3gamma_unit.X()*E_corrected, p3gamma_unit.Y()*E_corrected,
111 p3gamma_unit.Z()*E_corrected, E_corrected);
112
113 // Set particle's new 4 momentum in a copy
114 Particle* correctedP = ParticleCopy::copyParticle(iParticle);
115 correctedP->setMomentumScalingFactor(1.0);
116 correctedP->set4Vector(P4corrected);
117
118 m_outputGammaList->addParticle(correctedP);
119 }
120
121 const unsigned int numCopy = m_outputGammaList->getListSize();
122 if (numCopy != numParticles)
123 B2FATAL("Size of the ParticleList " << m_inputGammaListName
124 << " has changed while copying the Particles! original size = "
125 << numParticles << " vs. new size = " << numCopy);
126
127}
128
129
int getPDGCode() const
PDG code.
Definition: Const.h:473
static const ParticleType photon
photon particle
Definition: Const.h:673
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition: DataStore.h:71
int getPDGCode() const
Return PDG code.
The DecayDescriptor stores information about a decay tree or parts of a decay tree.
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
const DecayDescriptorParticle * getMother() const
return mother.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
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.
Class to store reconstructed particles.
Definition: Particle.h:75
void setMomentumScalingFactor(double momentumScalingFactor)
Sets momentum scaling.
Definition: Particle.h:334
ROOT::Math::PxPyPzEVector get4Vector() const
Returns Lorentz vector.
Definition: Particle.h:547
void set4Vector(const ROOT::Math::PxPyPzEVector &p4)
Sets Lorentz vector.
Definition: Particle.h:271
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
virtual void initialize() override
Initialises the module.
virtual void event() override
Method called for each event.
std::string m_inputGammaListName
name of input particle list.
StoreObjPtr< ParticleList > m_outputGammaList
output particleList
std::string m_outputGammaListName
name of output particle list.
Int_t m_massiveParticlePDGCode
PDG code of particle constraining the gamma energy.
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.
Definition: ClusterUtils.h:24