Belle II Software development
LowEnergyPi0VetoExpertModule.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/LowEnergyPi0VetoExpert/LowEnergyPi0VetoExpertModule.h>
11
12/* Analysis headers. */
13#include <analysis/variables/ECLVariables.h>
14
15/* Basf2 headers. */
16#include <mva/dataobjects/DatabaseRepresentationOfWeightfile.h>
17#include <mva/interface/Interface.h>
18
19/* ROOT headers. */
20#include <Math/Vector3D.h>
21#include <Math/Vector4D.h>
22#include <Math/VectorUtil.h>
23
24using namespace Belle2;
25
26REG_MODULE(LowEnergyPi0VetoExpert);
27
29{
30 setDescription("Low-energy pi0 veto.");
32 "VetoPi0Daughters", m_VetoPi0Daughters,
33 "Veto for pi0 daughters (maximum over all pairs excluding this pi0).",
34 false);
35 addParam("GammaListName", m_GammaListName, "Gamma particle list name.",
36 std::string("gamma"));
37 addParam("Pi0ListName", m_Pi0ListName, "Pi0 particle list name.",
38 std::string("pi0"));
39 addParam("Belle1", m_Belle1, "Belle 1 data analysis.", false);
40 addParam("identifier", m_identifier,
41 "Database identifier or file used to load the weights.",
44}
45
49
51{
52 m_ListGamma.isRequired(m_GammaListName);
54 m_ListPi0.isRequired(m_Pi0ListName);
55 if (not(m_identifier.ends_with(".root") or m_identifier.ends_with(".xml"))) {
56 m_weightfile_representation = std::unique_ptr<DBObjPtr<DatabaseRepresentationOfWeightfile>>(new
58 }
60}
61
63{
64 m_expert.reset();
65 m_dataset.reset();
66}
67
69{
71 if (m_weightfile_representation->hasChanged()) {
72 std::stringstream ss((*m_weightfile_representation)->m_data);
73 auto weightfile = MVA::Weightfile::loadFromStream(ss);
74 init_mva(weightfile);
75 }
76 } else {
78 init_mva(weightfile);
79 }
80}
81
85
87{
88 auto supported_interfaces = MVA::AbstractInterface::getSupportedInterfaces();
89 MVA::GeneralOptions general_options;
90 weightfile.getOptions(general_options);
91 weightfile.addSignalFraction(0.5);
92 m_expert = supported_interfaces[general_options.m_method]->getExpert();
93 m_expert->load(weightfile);
94 std::vector<float> dummy;
95 /* The number of input variables depends on the experiment. */
96 int nInputVariables;
97 if (m_Belle1)
98 nInputVariables = 7;
99 else
100 nInputVariables = 11;
101 dummy.resize(nInputVariables, 0);
102 m_dataset = std::unique_ptr<MVA::SingleDataset>(new MVA::SingleDataset(general_options, std::move(dummy), 0));
103}
104
106 const Particle* pi0Gamma)
107{
108 float maxVeto = 0;
109 int n = m_ListGamma->getListSize();
110 for (int i = 0; i < n; ++i) {
111 Particle* gamma2 = m_ListGamma->getParticle(i);
112 if (gamma1 == gamma2)
113 continue;
114 if (pi0Gamma != nullptr) {
115 if (pi0Gamma == gamma2)
116 continue;
117 }
118 double pi0Mass = (gamma1->get4Vector() + gamma2->get4Vector()).M();
119 if (pi0Mass < 0.07 || pi0Mass > 0.20)
120 continue;
121 const Particle* gammaLowEnergy, *gammaHighEnergy;
122 if (gamma1->getEnergy() > gamma2->getEnergy()) {
123 gammaLowEnergy = gamma2;
124 gammaHighEnergy = gamma1;
125 } else {
126 gammaLowEnergy = gamma1;
127 gammaHighEnergy = gamma2;
128 }
129 double gammaLowEnergyEnergy, gammaHighEnergyEnergy;
130 double gammaLowEnergyE9E21, gammaHighEnergyE9E21;
131 double gammaLowEnergyClusterTheta, gammaHighEnergyClusterTheta;
132 double gammaLowEnergyZernikeMVA, gammaHighEnergyZernikeMVA;
133 double gammaLowEnergyIsolation, gammaHighEnergyIsolation;
134 double cosHelicityAngleMomentum;
135 gammaLowEnergyEnergy = gammaLowEnergy->getEnergy();
136 gammaHighEnergyEnergy = gammaHighEnergy->getEnergy();
137 ROOT::Math::PxPyPzEVector gammaHighEnergyMomentum(
138 gammaHighEnergy->getPx(), gammaHighEnergy->getPy(),
139 gammaHighEnergy->getPz(), gammaHighEnergyEnergy);
140 ROOT::Math::PxPyPzEVector gammaLowEnergyMomentum(
141 gammaLowEnergy->getPx(), gammaLowEnergy->getPy(),
142 gammaLowEnergy->getPz(), gammaLowEnergyEnergy);
143 ROOT::Math::PxPyPzEVector momentum = gammaHighEnergyMomentum +
144 gammaLowEnergyMomentum;
145 ROOT::Math::XYZVector boost = momentum.BoostToCM();
146 gammaHighEnergyMomentum =
147 ROOT::Math::VectorUtil::boost(gammaHighEnergyMomentum, boost);
148 cosHelicityAngleMomentum =
149 fabs(ROOT::Math::VectorUtil::CosTheta(momentum,
150 gammaHighEnergyMomentum));
151 gammaLowEnergyE9E21 = Variable::eclClusterE9E21(gammaLowEnergy);
152 gammaHighEnergyE9E21 = Variable::eclClusterE9E21(gammaHighEnergy);
153 gammaLowEnergyClusterTheta = Variable::eclClusterTheta(gammaLowEnergy);
154 gammaHighEnergyClusterTheta = Variable::eclClusterTheta(gammaHighEnergy);
155 if (!m_Belle1) {
156 gammaLowEnergyZernikeMVA =
157 Variable::eclClusterZernikeMVA(gammaLowEnergy);
158 gammaHighEnergyZernikeMVA =
159 Variable::eclClusterZernikeMVA(gammaHighEnergy);
160 gammaLowEnergyIsolation = Variable::eclClusterIsolation(gammaLowEnergy);
161 gammaHighEnergyIsolation =
162 Variable::eclClusterIsolation(gammaHighEnergy);
163 }
164 m_dataset->m_input[0] = gammaLowEnergyEnergy;
165 m_dataset->m_input[1] = pi0Mass;
166 m_dataset->m_input[2] = cosHelicityAngleMomentum;
167 m_dataset->m_input[3] = gammaLowEnergyE9E21;
168 m_dataset->m_input[4] = gammaHighEnergyE9E21;
169 m_dataset->m_input[5] = gammaLowEnergyClusterTheta;
170 m_dataset->m_input[6] = gammaHighEnergyClusterTheta;
171 if (!m_Belle1) {
172 m_dataset->m_input[7] = gammaLowEnergyZernikeMVA;
173 m_dataset->m_input[8] = gammaHighEnergyZernikeMVA;
174 m_dataset->m_input[9] = gammaLowEnergyIsolation;
175 m_dataset->m_input[10] = gammaHighEnergyIsolation;
176 }
177 float veto = m_expert->apply(*m_dataset)[0];
178 if (veto > maxVeto)
179 maxVeto = veto;
180 }
181 return maxVeto;
182}
183
185{
186 if (m_VetoPi0Daughters) {
187 int n = m_ListPi0->getListSize();
188 for (int i = 0; i < n; ++i) {
189 Particle* pi0 = m_ListPi0->getParticle(i);
190 const Particle* gamma1 = pi0->getDaughter(0);
191 const Particle* gamma2 = pi0->getDaughter(1);
192 const Particle* gammaLowEnergy, *gammaHighEnergy;
193 if (gamma1->getEnergy() > gamma2->getEnergy()) {
194 gammaLowEnergy = gamma2;
195 gammaHighEnergy = gamma1;
196 } else {
197 gammaLowEnergy = gamma1;
198 gammaHighEnergy = gamma2;
199 }
200 float maxVeto = getMaximumVeto(gammaLowEnergy, gammaHighEnergy);
201 pi0->addExtraInfo("lowEnergyPi0VetoGammaLowEnergy", maxVeto);
202 maxVeto = getMaximumVeto(gammaHighEnergy, gammaLowEnergy);
203 pi0->addExtraInfo("lowEnergyPi0VetoGammaHighEnergy", maxVeto);
204 }
205 } else {
206 int n = m_ListGamma->getListSize();
207 for (int i = 0; i < n; ++i) {
208 Particle* gamma = m_ListGamma->getParticle(i);
209 float maxVeto = getMaximumVeto(gamma, nullptr);
210 gamma->addExtraInfo("lowEnergyPi0Veto", maxVeto);
211 }
212 }
213}
Class for accessing objects in the database.
Definition DBObjPtr.h:21
std::unique_ptr< MVA::SingleDataset > m_dataset
Pointer to the current dataset.
StoreObjPtr< ParticleList > m_ListGamma
Gamma candidates.
void event() override
This method is called for each event.
void endRun() override
This method is called if the current run ends.
void terminate() override
This method is called at the end of the event processing.
std::unique_ptr< MVA::Expert > m_expert
Pointer to the current MVA expert.
std::unique_ptr< DBObjPtr< DatabaseRepresentationOfWeightfile > > m_weightfile_representation
Database pointer to the database representation of the weightfile.
void beginRun() override
Called when entering a new run.
bool m_VetoPi0Daughters
Calculate veto for pi0 daughter photons (maximum over all pairs excluding this pi0).
StoreObjPtr< ParticleList > m_ListPi0
Pi0 candidates.
void init_mva(MVA::Weightfile &weightfile)
Initialize mva expert, dataset and features Called every time the weightfile in the database changes ...
std::string m_GammaListName
Gamma particle list name.
std::string m_Pi0ListName
Pi0 particle list name.
float getMaximumVeto(const Particle *gamma1, const Particle *pi0Gamma)
Get maximum veto value over all gamma pairs including the photon gamma1.
std::string m_identifier
Database identifier or file used to load the weights.
static void initSupportedInterfaces()
Static function which initializes all supported interfaces, has to be called once before getSupported...
Definition Interface.cc:46
static std::map< std::string, AbstractInterface * > getSupportedInterfaces()
Returns interfaces supported by the MVA Interface.
Definition Interface.h:53
General options which are shared by all MVA trainings.
Definition Options.h:62
Wraps the data of a single event into a Dataset.
Definition Dataset.h:135
The Weightfile class serializes all information about a training into an xml tree.
Definition Weightfile.h:38
static Weightfile loadFromStream(std::istream &stream)
Static function which deserializes a Weightfile from a stream.
static Weightfile loadFromFile(const std::string &filename)
Static function which loads a Weightfile from a file.
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
Module()
Constructor.
Definition Module.cc:30
@ 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 store reconstructed particles.
Definition Particle.h:76
double getPx() const
Returns x component of momentum.
Definition Particle.h:607
double getPz() const
Returns z component of momentum.
Definition Particle.h:625
double getEnergy() const
Returns total energy.
Definition Particle.h:555
double getPy() const
Returns y component of momentum.
Definition Particle.h:616
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
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
Definition Particle.cc:662
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
Abstract base class for different kinds of events.