Belle II Software development
LowEnergyPi0IdentificationExpertModule.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/LowEnergyPi0IdentificationExpert/LowEnergyPi0IdentificationExpertModule.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
19using namespace Belle2;
20
21REG_MODULE(LowEnergyPi0IdentificationExpert);
22
24{
25 setDescription("Low-energy pi0 identification.");
26 addParam("Pi0ListName", m_Pi0ListName, "Pi0 particle list name.",
27 std::string("pi0"));
28 addParam("Belle1", m_Belle1, "Belle 1 data analysis.", false);
29 addParam("identifier", m_identifier,
30 "Database identifier or file used to load the weights.",
33}
34
38
40{
41 m_ListPi0.isRequired(m_Pi0ListName);
42 if (not(m_identifier.ends_with(".root") or m_identifier.ends_with(".xml"))) {
43 m_weightfile_representation = std::unique_ptr<DBObjPtr<DatabaseRepresentationOfWeightfile>>(new
45 }
47}
48
54
56{
58 if (m_weightfile_representation->hasChanged()) {
59 std::stringstream ss((*m_weightfile_representation)->m_data);
60 auto weightfile = MVA::Weightfile::loadFromStream(ss);
61 init_mva(weightfile);
62 }
63 } else {
65 init_mva(weightfile);
66 }
67}
68
69
71{
72 auto supported_interfaces = MVA::AbstractInterface::getSupportedInterfaces();
73 MVA::GeneralOptions general_options;
74 weightfile.getOptions(general_options);
75 weightfile.addSignalFraction(0.5);
76 m_expert = supported_interfaces[general_options.m_method]->getExpert();
77 m_expert->load(weightfile);
78 std::vector<float> dummy;
79 /* The number of input variables depends on the experiment. */
80 int nInputVariables;
81 if (m_Belle1)
82 nInputVariables = 6;
83 else
84 nInputVariables = 10;
85 dummy.resize(nInputVariables, 0);
86 m_dataset = std::unique_ptr<MVA::SingleDataset>(new MVA::SingleDataset(general_options, std::move(dummy), 0));
87}
88
90{
91 int n = m_ListPi0->getListSize();
92 for (int i = 0; i < n; ++i) {
93 Particle* pi0 = m_ListPi0->getParticle(i);
94 const Particle* gamma1 = pi0->getDaughter(0);
95 const Particle* gamma2 = pi0->getDaughter(1);
96 const Particle* gammaLowEnergy, *gammaHighEnergy;
97 if (gamma1->getEnergy() > gamma2->getEnergy()) {
98 gammaLowEnergy = gamma2;
99 gammaHighEnergy = gamma1;
100 } else {
101 gammaLowEnergy = gamma1;
102 gammaHighEnergy = gamma2;
103 }
104 double gammaLowEnergyPi0Veto, gammaHighEnergyPi0Veto;
105 double gammaLowEnergyE9E21, gammaHighEnergyE9E21;
106 double gammaLowEnergyClusterTheta, gammaHighEnergyClusterTheta;
107 double gammaLowEnergyZernikeMVA, gammaHighEnergyZernikeMVA;
108 double gammaLowEnergyIsolation, gammaHighEnergyIsolation;
109 gammaLowEnergyPi0Veto = pi0->getExtraInfo("lowEnergyPi0VetoGammaLowEnergy");
110 gammaHighEnergyPi0Veto =
111 pi0->getExtraInfo("lowEnergyPi0VetoGammaHighEnergy");
112 gammaLowEnergyE9E21 = Variable::eclClusterE9E21(gammaLowEnergy);
113 gammaHighEnergyE9E21 = Variable::eclClusterE9E21(gammaHighEnergy);
114 gammaLowEnergyClusterTheta = Variable::eclClusterTheta(gammaLowEnergy);
115 gammaHighEnergyClusterTheta = Variable::eclClusterTheta(gammaHighEnergy);
116 if (!m_Belle1) {
117 gammaLowEnergyZernikeMVA = Variable::eclClusterZernikeMVA(gammaLowEnergy);
118 gammaHighEnergyZernikeMVA =
119 Variable::eclClusterZernikeMVA(gammaHighEnergy);
120 gammaLowEnergyIsolation = Variable::eclClusterIsolation(gammaLowEnergy);
121 gammaHighEnergyIsolation = Variable::eclClusterIsolation(gammaHighEnergy);
122 }
123 m_dataset->m_input[0] = gammaLowEnergyPi0Veto;
124 m_dataset->m_input[1] = gammaHighEnergyPi0Veto;
125 m_dataset->m_input[2] = gammaLowEnergyE9E21;
126 m_dataset->m_input[3] = gammaHighEnergyE9E21;
127 m_dataset->m_input[4] = gammaLowEnergyClusterTheta;
128 m_dataset->m_input[5] = gammaHighEnergyClusterTheta;
129 if (!m_Belle1) {
130 m_dataset->m_input[6] = gammaLowEnergyZernikeMVA;
131 m_dataset->m_input[7] = gammaHighEnergyZernikeMVA;
132 m_dataset->m_input[8] = gammaLowEnergyIsolation;
133 m_dataset->m_input[9] = gammaHighEnergyIsolation;
134 }
135 float identification = m_expert->apply(*m_dataset)[0];
136 pi0->addExtraInfo("lowEnergyPi0Identification", identification);
137 }
138}
Class for accessing objects in the database.
Definition DBObjPtr.h:21
std::unique_ptr< MVA::SingleDataset > m_dataset
Pointer to the current dataset.
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 init_mva(MVA::Weightfile &weightfile)
Initialize mva expert, dataset and features Called every time the weightfile in the database changes ...
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 getEnergy() const
Returns total energy.
Definition Particle.h:555
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
double getExtraInfo(const std::string &name) const
Return given value if set.
Definition Particle.cc:1374
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.