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
83{
84 auto supported_interfaces = MVA::AbstractInterface::getSupportedInterfaces();
85 MVA::GeneralOptions general_options;
86 weightfile.getOptions(general_options);
87 weightfile.addSignalFraction(0.5);
88 m_expert = supported_interfaces[general_options.m_method]->getExpert();
89 m_expert->load(weightfile);
90 std::vector<float> dummy;
91 /* The number of input variables depends on the experiment. */
92 int nInputVariables;
93 if (m_Belle1)
94 nInputVariables = 7;
95 else
96 nInputVariables = 11;
97 dummy.resize(nInputVariables, 0);
98 m_dataset = std::unique_ptr<MVA::SingleDataset>(new MVA::SingleDataset(general_options, std::move(dummy), 0));
99}
100
102 const Particle* pi0Gamma)
103{
104 float maxVeto = 0;
105 int n = m_ListGamma->getListSize();
106 for (int i = 0; i < n; ++i) {
107 const Particle* gamma2 = m_ListGamma->getParticle(i);
108 if (gamma1 == gamma2)
109 continue;
110 if (pi0Gamma != nullptr) {
111 if (pi0Gamma == gamma2)
112 continue;
113 }
114 double pi0Mass = (gamma1->get4Vector() + gamma2->get4Vector()).M();
115 if (pi0Mass < 0.07 || pi0Mass > 0.20)
116 continue;
117 const Particle* gammaLowEnergy, *gammaHighEnergy;
118 if (gamma1->getEnergy() > gamma2->getEnergy()) {
119 gammaLowEnergy = gamma2;
120 gammaHighEnergy = gamma1;
121 } else {
122 gammaLowEnergy = gamma1;
123 gammaHighEnergy = gamma2;
124 }
125 double gammaLowEnergyEnergy, gammaHighEnergyEnergy;
126 double gammaLowEnergyE9E21, gammaHighEnergyE9E21;
127 double gammaLowEnergyClusterTheta, gammaHighEnergyClusterTheta;
128 double gammaLowEnergyZernikeMVA, gammaHighEnergyZernikeMVA;
129 double gammaLowEnergyIsolation, gammaHighEnergyIsolation;
130 double cosHelicityAngleMomentum;
131 gammaLowEnergyEnergy = gammaLowEnergy->getEnergy();
132 gammaHighEnergyEnergy = gammaHighEnergy->getEnergy();
133 ROOT::Math::PxPyPzEVector gammaHighEnergyMomentum(
134 gammaHighEnergy->getPx(), gammaHighEnergy->getPy(),
135 gammaHighEnergy->getPz(), gammaHighEnergyEnergy);
136 ROOT::Math::PxPyPzEVector gammaLowEnergyMomentum(
137 gammaLowEnergy->getPx(), gammaLowEnergy->getPy(),
138 gammaLowEnergy->getPz(), gammaLowEnergyEnergy);
139 ROOT::Math::PxPyPzEVector momentum = gammaHighEnergyMomentum +
140 gammaLowEnergyMomentum;
141 ROOT::Math::XYZVector boost = momentum.BoostToCM();
142 gammaHighEnergyMomentum =
143 ROOT::Math::VectorUtil::boost(gammaHighEnergyMomentum, boost);
144 cosHelicityAngleMomentum =
145 fabs(ROOT::Math::VectorUtil::CosTheta(momentum,
146 gammaHighEnergyMomentum));
147 gammaLowEnergyE9E21 = Variable::eclClusterE9E21(gammaLowEnergy);
148 gammaHighEnergyE9E21 = Variable::eclClusterE9E21(gammaHighEnergy);
149 gammaLowEnergyClusterTheta = Variable::eclClusterTheta(gammaLowEnergy);
150 gammaHighEnergyClusterTheta = Variable::eclClusterTheta(gammaHighEnergy);
151 if (!m_Belle1) {
152 gammaLowEnergyZernikeMVA =
153 Variable::eclClusterZernikeMVA(gammaLowEnergy);
154 gammaHighEnergyZernikeMVA =
155 Variable::eclClusterZernikeMVA(gammaHighEnergy);
156 gammaLowEnergyIsolation = Variable::eclClusterIsolation(gammaLowEnergy);
157 gammaHighEnergyIsolation =
158 Variable::eclClusterIsolation(gammaHighEnergy);
159 }
160 m_dataset->m_input[0] = gammaLowEnergyEnergy;
161 m_dataset->m_input[1] = pi0Mass;
162 m_dataset->m_input[2] = cosHelicityAngleMomentum;
163 m_dataset->m_input[3] = gammaLowEnergyE9E21;
164 m_dataset->m_input[4] = gammaHighEnergyE9E21;
165 m_dataset->m_input[5] = gammaLowEnergyClusterTheta;
166 m_dataset->m_input[6] = gammaHighEnergyClusterTheta;
167 if (!m_Belle1) {
168 m_dataset->m_input[7] = gammaLowEnergyZernikeMVA;
169 m_dataset->m_input[8] = gammaHighEnergyZernikeMVA;
170 m_dataset->m_input[9] = gammaLowEnergyIsolation;
171 m_dataset->m_input[10] = gammaHighEnergyIsolation;
172 }
173 float veto = m_expert->apply(*m_dataset)[0];
174 if (veto > maxVeto)
175 maxVeto = veto;
176 }
177 return maxVeto;
178}
179
181{
182 if (m_VetoPi0Daughters) {
183 int n = m_ListPi0->getListSize();
184 for (int i = 0; i < n; ++i) {
185 Particle* pi0 = m_ListPi0->getParticle(i);
186 const Particle* gamma1 = pi0->getDaughter(0);
187 const Particle* gamma2 = pi0->getDaughter(1);
188 const Particle* gammaLowEnergy, *gammaHighEnergy;
189 if (gamma1->getEnergy() > gamma2->getEnergy()) {
190 gammaLowEnergy = gamma2;
191 gammaHighEnergy = gamma1;
192 } else {
193 gammaLowEnergy = gamma1;
194 gammaHighEnergy = gamma2;
195 }
196 float maxVeto = getMaximumVeto(gammaLowEnergy, gammaHighEnergy);
197 pi0->addExtraInfo("lowEnergyPi0VetoGammaLowEnergy", maxVeto);
198 maxVeto = getMaximumVeto(gammaHighEnergy, gammaLowEnergy);
199 pi0->addExtraInfo("lowEnergyPi0VetoGammaHighEnergy", maxVeto);
200 }
201 } else {
202 int n = m_ListGamma->getListSize();
203 for (int i = 0; i < n; ++i) {
204 Particle* gamma = m_ListGamma->getParticle(i);
205 float maxVeto = getMaximumVeto(gamma, nullptr);
206 gamma->addExtraInfo("lowEnergyPi0Veto", maxVeto);
207 }
208 }
209}
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 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.