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/interface/Interface.h>
17
18/* Boost headers. */
19#include <boost/algorithm/string/predicate.hpp>
20
21/* ROOT headers. */
22#include <Math/Vector3D.h>
23#include <Math/Vector4D.h>
24#include <Math/VectorUtil.h>
25
26using namespace Belle2;
27
28REG_MODULE(LowEnergyPi0VetoExpert);
29
31{
32 setDescription("Low-energy pi0 veto.");
34 "VetoPi0Daughters", m_VetoPi0Daughters,
35 "Veto for pi0 daughters (maximum over all pairs excluding this pi0).",
36 false);
37 addParam("GammaListName", m_GammaListName, "Gamma particle list name.",
38 std::string("gamma"));
39 addParam("Pi0ListName", m_Pi0ListName, "Pi0 particle list name.",
40 std::string("pi0"));
41 addParam("Belle1", m_Belle1, "Belle 1 data analysis.", false);
42 addParam("identifier", m_identifier,
43 "Database identifier or file used to load the weights.",
46}
47
49{
50}
51
53{
54 m_ListGamma.isRequired(m_GammaListName);
56 m_ListPi0.isRequired(m_Pi0ListName);
57 if (not(boost::ends_with(m_identifier, ".root") or boost::ends_with(m_identifier, ".xml"))) {
58 m_weightfile_representation = std::unique_ptr<DBObjPtr<DatabaseRepresentationOfWeightfile>>(new
60 }
62}
63
65{
66 m_expert.reset();
67 m_dataset.reset();
68}
69
71{
73 if (m_weightfile_representation->hasChanged()) {
74 std::stringstream ss((*m_weightfile_representation)->m_data);
75 auto weightfile = MVA::Weightfile::loadFromStream(ss);
76 init_mva(weightfile);
77 }
78 } else {
80 init_mva(weightfile);
81 }
82}
83
85{
86}
87
89{
90 auto supported_interfaces = MVA::AbstractInterface::getSupportedInterfaces();
91 MVA::GeneralOptions general_options;
92 weightfile.getOptions(general_options);
93 weightfile.addSignalFraction(0.5);
94 m_expert = supported_interfaces[general_options.m_method]->getExpert();
95 m_expert->load(weightfile);
96 std::vector<float> dummy;
97 /* The number of input variables depends on the experiment. */
98 int nInputVariables;
99 if (m_Belle1)
100 nInputVariables = 7;
101 else
102 nInputVariables = 11;
103 dummy.resize(nInputVariables, 0);
104 m_dataset = std::unique_ptr<MVA::SingleDataset>(new MVA::SingleDataset(general_options, std::move(dummy), 0));
105}
106
108 const Particle* pi0Gamma)
109{
110 float maxVeto = 0;
111 int n = m_ListGamma->getListSize();
112 for (int i = 0; i < n; ++i) {
113 Particle* gamma2 = m_ListGamma->getParticle(i);
114 if (gamma1 == gamma2)
115 continue;
116 if (pi0Gamma != nullptr) {
117 if (pi0Gamma == gamma2)
118 continue;
119 }
120 double pi0Mass = (gamma1->get4Vector() + gamma2->get4Vector()).M();
121 if (pi0Mass < 0.07 || pi0Mass > 0.20)
122 continue;
123 const Particle* gammaLowEnergy, *gammaHighEnergy;
124 if (gamma1->getEnergy() > gamma2->getEnergy()) {
125 gammaLowEnergy = gamma2;
126 gammaHighEnergy = gamma1;
127 } else {
128 gammaLowEnergy = gamma1;
129 gammaHighEnergy = gamma2;
130 }
131 double gammaLowEnergyEnergy, gammaHighEnergyEnergy;
132 double gammaLowEnergyE9E21, gammaHighEnergyE9E21;
133 double gammaLowEnergyClusterTheta, gammaHighEnergyClusterTheta;
134 double gammaLowEnergyZernikeMVA, gammaHighEnergyZernikeMVA;
135 double gammaLowEnergyIsolation, gammaHighEnergyIsolation;
136 double cosHelicityAngleMomentum;
137 gammaLowEnergyEnergy = gammaLowEnergy->getEnergy();
138 gammaHighEnergyEnergy = gammaHighEnergy->getEnergy();
139 ROOT::Math::PxPyPzEVector gammaHighEnergyMomentum(
140 gammaHighEnergy->getPx(), gammaHighEnergy->getPy(),
141 gammaHighEnergy->getPz(), gammaHighEnergyEnergy);
142 ROOT::Math::PxPyPzEVector gammaLowEnergyMomentum(
143 gammaLowEnergy->getPx(), gammaLowEnergy->getPy(),
144 gammaLowEnergy->getPz(), gammaLowEnergyEnergy);
145 ROOT::Math::PxPyPzEVector momentum = gammaHighEnergyMomentum +
146 gammaLowEnergyMomentum;
147 ROOT::Math::XYZVector boost = momentum.BoostToCM();
148 gammaHighEnergyMomentum =
149 ROOT::Math::VectorUtil::boost(gammaHighEnergyMomentum, boost);
150 cosHelicityAngleMomentum =
151 fabs(ROOT::Math::VectorUtil::CosTheta(momentum.Vect(),
152 gammaHighEnergyMomentum.Vect()));
153 gammaLowEnergyE9E21 = Variable::eclClusterE9E21(gammaLowEnergy);
154 gammaHighEnergyE9E21 = Variable::eclClusterE9E21(gammaHighEnergy);
155 gammaLowEnergyClusterTheta = Variable::eclClusterTheta(gammaLowEnergy);
156 gammaHighEnergyClusterTheta = Variable::eclClusterTheta(gammaHighEnergy);
157 if (!m_Belle1) {
158 gammaLowEnergyZernikeMVA =
159 Variable::eclClusterZernikeMVA(gammaLowEnergy);
160 gammaHighEnergyZernikeMVA =
161 Variable::eclClusterZernikeMVA(gammaHighEnergy);
162 gammaLowEnergyIsolation = Variable::eclClusterIsolation(gammaLowEnergy);
163 gammaHighEnergyIsolation =
164 Variable::eclClusterIsolation(gammaHighEnergy);
165 }
166 m_dataset->m_input[0] = gammaLowEnergyEnergy;
167 m_dataset->m_input[1] = pi0Mass;
168 m_dataset->m_input[2] = cosHelicityAngleMomentum;
169 m_dataset->m_input[3] = gammaLowEnergyE9E21;
170 m_dataset->m_input[4] = gammaHighEnergyE9E21;
171 m_dataset->m_input[5] = gammaLowEnergyClusterTheta;
172 m_dataset->m_input[6] = gammaHighEnergyClusterTheta;
173 if (!m_Belle1) {
174 m_dataset->m_input[7] = gammaLowEnergyZernikeMVA;
175 m_dataset->m_input[8] = gammaHighEnergyZernikeMVA;
176 m_dataset->m_input[9] = gammaLowEnergyIsolation;
177 m_dataset->m_input[10] = gammaHighEnergyIsolation;
178 }
179 float veto = m_expert->apply(*m_dataset)[0];
180 if (veto > maxVeto)
181 maxVeto = veto;
182 }
183 return maxVeto;
184}
185
187{
188 if (m_VetoPi0Daughters) {
189 int n = m_ListPi0->getListSize();
190 for (int i = 0; i < n; ++i) {
191 Particle* pi0 = m_ListPi0->getParticle(i);
192 const Particle* gamma1 = pi0->getDaughter(0);
193 const Particle* gamma2 = pi0->getDaughter(1);
194 const Particle* gammaLowEnergy, *gammaHighEnergy;
195 if (gamma1->getEnergy() > gamma2->getEnergy()) {
196 gammaLowEnergy = gamma2;
197 gammaHighEnergy = gamma1;
198 } else {
199 gammaLowEnergy = gamma1;
200 gammaHighEnergy = gamma2;
201 }
202 float maxVeto = getMaximumVeto(gammaLowEnergy, gammaHighEnergy);
203 pi0->addExtraInfo("lowEnergyPi0VetoGammaLowEnergy", maxVeto);
204 maxVeto = getMaximumVeto(gammaHighEnergy, gammaLowEnergy);
205 pi0->addExtraInfo("lowEnergyPi0VetoGammaHighEnergy", maxVeto);
206 }
207 } else {
208 int n = m_ListGamma->getListSize();
209 for (int i = 0; i < n; ++i) {
210 Particle* gamma = m_ListGamma->getParticle(i);
211 float maxVeto = getMaximumVeto(gamma, nullptr);
212 gamma->addExtraInfo("lowEnergyPi0Veto", maxVeto);
213 }
214 }
215}
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 initliazes all supported interfaces, has to be called once before getSupportedI...
Definition: Interface.cc:45
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.
Definition: Weightfile.cc:251
void getOptions(Options &options) const
Fills an Option object from the xml tree.
Definition: Weightfile.cc:67
static Weightfile loadFromFile(const std::string &filename)
Static function which loads a Weightfile from a file.
Definition: Weightfile.cc:206
void addSignalFraction(float signal_fraction)
Saves the signal fraction in the xml tree.
Definition: Weightfile.cc:95
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 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.