Belle II Software development
BelleBremRecoveryModule.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// Own header.
10#include <analysis/modules/BremsCorrection/BelleBremRecoveryModule.h>
11// framework aux
12#include <framework/logging/Logger.h>
13
14// dataobjects
15#include <mdst/dataobjects/Track.h>
16
17// utilities
18#include <analysis/DecayDescriptor/ParticleListName.h>
19
20// variables
21#include <analysis/variables/ECLVariables.h>
22
23#include <algorithm>
24#include <TMatrixFSym.h>
25#include <Math/Vector3D.h>
26#include <Math/Vector4D.h>
27#include <Math/VectorUtil.h>
28
29#include <vector>
30
31using namespace std;
32using namespace Belle2;
33
34//-----------------------------------------------------------------
35// Register module
36//-----------------------------------------------------------------
37
38REG_MODULE(BelleBremRecovery);
39
40//-----------------------------------------------------------------
41// Implementation
42//-----------------------------------------------------------------
43
45 Module(), m_pdgCode(0)
46
47{
48 // set module description (e.g. insert text)
49 setDescription(R"DOC(
50Takes the charged particle from the given charged particle list (``inputListName``) and
51copies it to the output list (``outputListName``). The 4-vector of the nearest (all) photon(s)
52from ``gammaListName`` (considered as radiative) is added to the charged particle, if it is
53found inside the cone around the charged particle with the given maximum angle (``angleThreshold``).
54 )DOC");
56
57 // Add parameters
58 addParam("inputListName", m_inputListName,
59 "The initial charged particle list containing the charged particles to correct, should already exist.");
60 addParam("outputListName", m_outputListName, "The output charged particle list containing the corrected charged particles.");
61 addParam("gammaListName", m_gammaListName, "The gammas list containing possibly radiative gammas, should already exist.");
62 addParam("angleThreshold", m_angleThres,
63 "The maximum angle in radians between the charged particle and the (radiative) gamma to be accepted.", 0.05);
64 addParam("multiplePhotons", m_isMultiPho, "If only the nearest photon to add then make it False otherwise true", true);
65 addParam("usePhotonOnlyOnce", m_usePhotonOnlyOnce,
66 "If false, a photon is used for correction of the closest charged particle in the inputList. "
67 "If true, a photon is allowed to be used for correction multiple times. "
68 "WARNING: One cannot use a photon twice to reconstruct a composite particle. Thus, for example, if e+ and e- are corrected with a gamma, they cannot form a J/psi -> e+ e- candidate.",
69 false);
70
71 addParam("writeOut", m_writeOut,
72 "Set to true if you want to write out the output list to a root file", false);
73
74}
75
77{
78 // check the validity of output ParticleList name
80 if (!valid)
81 B2ERROR("[BelleBremRecoveryModule] Invalid output ParticleList name: " << m_outputListName);
82
83 // output particle
85 m_pdgCode = mother->getPDGCode();
87
88 // get existing particle lists
90 B2ERROR("[BelleBremRecoveryModule] Input and output particle list names are the same: " << m_inputListName);
92 B2ERROR("[BelleBremRecoveryModule] Invalid input particle list name: " << m_inputListName);
93 } else {
95 }
96
98 B2ERROR("[BelleBremRecoveryModule] Invalid gamma particle list name: " << m_gammaListName);
99 } else {
100 m_gammaList.isRequired(m_gammaListName);
101 }
102
103 // make output list
105 m_outputparticleList.registerInDataStore(m_outputListName, flags);
106 m_outputAntiparticleList.registerInDataStore(m_outputAntiListName, flags);
107
109}
110
111
113{
114 // new output particle list
115 m_outputparticleList.create();
117
120 m_outputAntiparticleList->bindAntiParticleList(*(m_outputparticleList));
121
122 const unsigned int nLep = m_inputparticleList->getListSize();
123 const unsigned int nGam = m_gammaList->getListSize();
124
125 if (nLep == 0) return;
126
127 const std::string extraInfoSuffix = "BelleBremRecovery_" + m_inputListName + "_" + m_gammaListName;
128
129 std::vector<std::vector<Particle*>> selectedGammas_nLep; // only used if m_usePhotonOnlyOnce is true
130 if (m_usePhotonOnlyOnce) selectedGammas_nLep.resize(nLep);
131
132 // loop over charged particles
133 for (unsigned iLep = 0; iLep < nLep; iLep++) {
134 std::vector<Particle*> selectedGammas;
135
136 const Particle* lepton = m_inputparticleList->getParticle(iLep);
137 const ROOT::Math::XYZVector pLep = lepton->getMomentum();
138
139 // look for all possible (radiative) gamma
140 for (unsigned iGam = 0; iGam < nGam; iGam++) {
141 Particle* gamma = m_gammaList->getParticle(iGam); // to write extraInfo
142 const ROOT::Math::XYZVector pGam = gamma->getMomentum();
143
144 const double angle = ROOT::Math::VectorUtil::Angle(pLep, pGam);
145
146 if (angle < m_angleThres) {
147 if (!m_usePhotonOnlyOnce) { // if multiple use is allowed, keep all selected gammas
148 gamma->writeExtraInfo("angle_" + extraInfoSuffix, angle);
149 gamma->writeExtraInfo("indexLep_" + extraInfoSuffix, iLep);
150 selectedGammas.push_back(gamma);
151 } else {
152 if (gamma->hasExtraInfo("angle_" + extraInfoSuffix)) { // check if the gamma has already selected
153 if (angle < gamma->getExtraInfo("angle_" + extraInfoSuffix)) {
154 // this lepton is closer to the gamma than previous lepton
155 int indexLep_prev = gamma->getExtraInfo("indexLep_" + extraInfoSuffix);
156 selectedGammas_nLep[indexLep_prev].erase(std::remove(selectedGammas_nLep[indexLep_prev].begin(),
157 selectedGammas_nLep[indexLep_prev].end(),
158 gamma),
159 selectedGammas_nLep[indexLep_prev].end());
160 gamma->writeExtraInfo("angle_" + extraInfoSuffix, angle);
161 gamma->writeExtraInfo("indexLep_" + extraInfoSuffix, iLep);
162 selectedGammas.push_back(gamma);
163 } // else, the gamma will not be used for correction
164 } else {
165 gamma->writeExtraInfo("angle_" + extraInfoSuffix, angle);
166 gamma->writeExtraInfo("indexLep_" + extraInfoSuffix, iLep);
167 selectedGammas.push_back(gamma);
168 }
169 }
170 }
171 }
172
173 // sorting the bremphotons in ascending order of the angle with the charged particle
174 std::sort(selectedGammas.begin(), selectedGammas.end(),
175 [extraInfoSuffix](const Particle * photon1, const Particle * photon2) {
176 return photon1->getExtraInfo("angle_" + extraInfoSuffix) < photon2->getExtraInfo("angle_" + extraInfoSuffix);
177 });
178
179 if (m_usePhotonOnlyOnce) // store the selectedGammas to check the closest lepton to gammas
180 selectedGammas_nLep[iLep] = selectedGammas;
181 else // perform correction here.
182 correctLepton(lepton, selectedGammas);
183
184 }
185
187 for (unsigned iLep = 0; iLep < nLep; iLep++) {
188 const Particle* lepton = m_inputparticleList->getParticle(iLep);
189 correctLepton(lepton, selectedGammas_nLep[iLep]);
190 }
191 }
192
193}
194
195void BelleBremRecoveryModule::correctLepton(const Particle* lepton, std::vector<Particle*> selectedGammas)
196{
197 // Updates 4-vector and errorMatrix
198 ROOT::Math::PxPyPzEVector new4Vec = lepton->get4Vector();
199 const TMatrixFSym& lepErrorMatrix = lepton->getMomentumVertexErrorMatrix();
200 TMatrixFSym corLepMatrix = lepErrorMatrix;
201
202 // Sum of energy of correction gammas for the extraInfo
203 double bremsGammaEnergySum = 0.0;
204
205 // Create a correctedLepton. 4-vector will be updated
206 Particle correctedLepton(new4Vec, lepton->getPDGCode(), Particle::EFlavorType::c_Flavored, Particle::c_Track,
207 lepton->getTrack()->getArrayIndex());
208
209 correctedLepton.setVertex(lepton->getVertex());
210 correctedLepton.setPValue(lepton->getPValue());
211
212 correctedLepton.appendDaughter(lepton, false);
213
214 for (auto gamma : selectedGammas) {
215
216 new4Vec += gamma->get4Vector();
217 bremsGammaEnergySum += Variable::eclClusterE(gamma);
218
219 const TMatrixFSym& fsrErrorMatrix = gamma->getMomentumVertexErrorMatrix();
220 for (int irow = 0; irow <= 3 ; irow++)
221 for (int icol = irow; icol <= 3; icol++)
222 corLepMatrix(irow, icol) += fsrErrorMatrix(irow, icol);
223
224 correctedLepton.appendDaughter(gamma, false);
225
226 B2DEBUG(19, "[BelleBremRecoveryModule] Found a radiative gamma and added its 4-vector to the charge particle");
227
228 if (!m_isMultiPho) break;
229 }
230
231 correctedLepton.set4Vector(new4Vec);
232 correctedLepton.updateMass(m_pdgCode);
233 correctedLepton.setMomentumVertexErrorMatrix(corLepMatrix);
234 correctedLepton.addExtraInfo("bremsCorrected", float(bremsGammaEnergySum > 0));
235 correctedLepton.addExtraInfo("bremsCorrectedPhotonEnergy", bremsGammaEnergySum);
236
237 // add the mc relation
238 Particle* newLepton = m_particles.appendNew(correctedLepton);
239 const MCParticle* mcLepton = lepton->getRelated<MCParticle>();
240 const PIDLikelihood* pid = lepton->getPIDLikelihood();
241 if (pid)
242 newLepton->addRelationTo(pid);
243 if (mcLepton)
244 newLepton->addRelationTo(mcLepton);
245
246 m_outputparticleList->addParticle(newLepton);
247
248}
void correctLepton(const Particle *lepton, std::vector< Particle * > selectedGammas)
Correct lepton kinematics using the selectedGammas.
StoreObjPtr< ParticleList > m_outputparticleList
StoreObjptr for output particlelist.
virtual void initialize() override
Initialize the Module.
std::string m_gammaListName
input ParticleList names
virtual void event() override
Event processor.
bool m_isMultiPho
multiple or one bremphoton addition option
StoreArray< Particle > m_particles
StoreArray of Particle objects.
double m_angleThres
input max angle to be accepted (in radian)
StoreArray< PIDLikelihood > m_pidlikelihoods
StoreArray of PIDLikelihood objects.
StoreObjPtr< ParticleList > m_gammaList
StoreObjptr for gamma list.
StoreObjPtr< ParticleList > m_inputparticleList
StoreObjptr for input charged particlelist.
StoreObjPtr< ParticleList > m_outputAntiparticleList
StoreObjptr for output antiparticlelist.
DecayDescriptor m_decaydescriptorGamma
Decay descriptor of the decay being reconstructed.
DecayDescriptor m_decaydescriptor
Decay descriptor of the charged particle decay.
bool m_writeOut
toggle output particle list btw.
bool m_usePhotonOnlyOnce
Each brems photon can be used to correct only one particle (the one with the smallest relation weight...
int m_pdgCode
PDG code of the combined mother particle.
std::string m_outputAntiListName
output anti-particle list name
std::string m_inputListName
input ParticleList names
std::string m_outputListName
output ParticleList name
EStoreFlags
Flags describing behaviours of objects etc.
Definition: DataStore.h:69
@ c_WriteOut
Object/array should be saved by output modules.
Definition: DataStore.h:70
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition: DataStore.h:71
Represents a particle in the DecayDescriptor.
int getPDGCode() const
Return PDG code.
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
const DecayDescriptorParticle * getMother() const
return mother.
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
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 collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes...
Definition: PIDLikelihood.h:29
Class to store reconstructed particles.
Definition: Particle.h:76
const Track * getTrack() const
Returns the pointer to the Track object that was used to create this Particle (ParticleType == c_Trac...
Definition: Particle.cc:916
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
void writeExtraInfo(const std::string &name, const double value)
Sets the user defined extraInfo.
Definition: Particle.cc:1393
void setVertex(const ROOT::Math::XYZVector &vertex)
Sets position (decay vertex)
Definition: Particle.h:306
double getPValue() const
Returns chi^2 probability of fit if done or -1.
Definition: Particle.h:687
ROOT::Math::XYZVector getVertex() const
Returns vertex position (POCA for charged, IP for neutral FS particles)
Definition: Particle.h:651
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
Definition: Particle.cc:1351
const PIDLikelihood * getPIDLikelihood() const
Returns the pointer to the PIDLikelihood object that is related to the Track, which was used to creat...
Definition: Particle.cc:947
int getPDGCode(void) const
Returns PDG code.
Definition: Particle.h:465
ROOT::Math::PxPyPzEVector get4Vector() const
Returns Lorentz vector.
Definition: Particle.h:567
void addExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
Definition: Particle.cc:1421
void set4Vector(const ROOT::Math::PxPyPzEVector &p4)
Sets Lorentz vector.
Definition: Particle.h:282
void setMomentumVertexErrorMatrix(const TMatrixFSym &errMatrix)
Sets 7x7 error matrix.
Definition: Particle.cc:424
ROOT::Math::XYZVector getMomentum() const
Returns momentum vector.
Definition: Particle.h:580
void setPValue(double pValue)
Sets chi^2 probability of fit.
Definition: Particle.h:377
void updateMass(const int pdgCode)
Updates particle mass with the mass of the particle corresponding to the given PDG.
Definition: Particle.cc:628
@ c_Flavored
Is either particle or antiparticle.
Definition: Particle.h:98
TMatrixFSym getMomentumVertexErrorMatrix() const
Returns 7x7 error matrix.
Definition: Particle.cc:451
double getExtraInfo(const std::string &name) const
Return given value if set.
Definition: Particle.cc:1374
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition: StoreArray.h:140
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:649
std::string antiParticleListName(const std::string &listName)
Returns name of anti-particle-list corresponding to listName.
Abstract base class for different kinds of events.
STL namespace.