Belle II Software development
SelectorMVA Class Reference

MVA based selector for tagging curl tracks in Belle and Belle II. More...

#include <SelectorMVA.h>

Inheritance diagram for SelectorMVA:
Selector

Public Member Functions

 SelectorMVA (bool belleFlag, bool trainFlag, std::string tFileName)
 Constructor.
 
 ~SelectorMVA ()
 Destructor.
 
virtual float getResponse (Particle *iPart, Particle *jPart) override
 Selector response that this pair of particles come from the same mc/actual particle.
 
virtual float getOptimalResponseCut () override
 returns optimal cut to use with selector
 
virtual std::vector< float > getVariables (Particle *iPart, Particle *jPart) override
 returns vector of variables used by this selector.
 
virtual void initialize () override
 initialize whatever needs to be initialized (root file etc)
 
virtual void collectTrainingInfo (Particle *iPart, Particle *jPart) override
 collect training data and save to a root file
 
virtual void finalize () override
 finalize whatever needs to be finalized (train the MVA)
 
void initializeMVA ()
 initialize the MVA Expert
 

Private Member Functions

void updateVariables (Particle *iPart, Particle *jPart)
 updates the value of the MVA variable
 

Private Attributes

bool m_TrainFlag
 applying mva or training it
 
std::string m_TFileName
 name of output file for training data
 
TFile * m_TFile
 output file for training data
 
TTree * m_TTree
 training data tree
 
std::unique_ptr< DBObjPtr< DatabaseRepresentationOfWeightfile > > m_weightfile_representation
 Database pointer to the Database representation of the weightfile.
 
MVA::Weightfile m_weightfile
 mva weightfile
 
MVA::GeneralOptions m_generalOptions
 mva general options (for the expert)
 
MVA::FastBDTExpert m_expert
 mva expert
 
std::string m_identifier
 mva identifier
 
std::vector< std::string > m_datafiles
 name of datafile
 
std::vector< std::string > m_variables
 names of variables used by mva
 
std::string m_target_variable
 name of target variable (isCurl)
 
Float_t m_PPhi
 angle between particle momentum vectors
 
Float_t m_ChargeProduct
 charge(p1) * charge(p2)
 
Float_t m_PtDiffEW
 error weighted particle Pt difference
 
Float_t m_PzDiffEW
 error weighted particle Pz difference
 
Float_t m_TrackD0DiffEW
 error weighted track D0 difference
 
Float_t m_TrackZ0DiffEW
 error weighted track Z0 difference
 
Float_t m_TrackTanLambdaDiffEW
 error weighted track tan lambda diff difference
 
Float_t m_TrackPhi0DiffEW
 error weighted track Phi0 difference
 
Float_t m_TrackOmegaDiffEW
 error weighted track Omega difference
 
Bool_t m_IsCurl
 isCurl Truth
 

Detailed Description

MVA based selector for tagging curl tracks in Belle and Belle II.

Definition at line 34 of file SelectorMVA.h.

Constructor & Destructor Documentation

◆ SelectorMVA()

SelectorMVA ( bool belleFlag,
bool trainFlag,
std::string tFileName )

Constructor.

Definition at line 22 of file SelectorMVA.cc.

23{
24 m_TrainFlag = trainFlag;
25 m_TFileName = tFileName;
26 if (belleFlag) {
27 m_identifier = "CurlTagger_FastBDT_Belle";
28 } else {
29 m_identifier = "CurlTagger_FastBDT_BelleII";
30 }
31}
bool m_TrainFlag
applying mva or training it
Definition SelectorMVA.h:70
std::string m_TFileName
name of output file for training data
Definition SelectorMVA.h:73
std::string m_identifier
mva identifier
Definition SelectorMVA.h:95

Member Function Documentation

◆ collectTrainingInfo()

void collectTrainingInfo ( Particle * iPart,
Particle * jPart )
overridevirtual

collect training data and save to a root file

Reimplemented from Selector.

Definition at line 75 of file SelectorMVA.cc.

76{
77 updateVariables(iPart, jPart);
78 m_TTree -> Fill();
79}
void updateVariables(Particle *iPart, Particle *jPart)
updates the value of the MVA variable
TTree * m_TTree
training data tree
Definition SelectorMVA.h:79

◆ finalize()

void finalize ( )
overridevirtual

finalize whatever needs to be finalized (train the MVA)

Reimplemented from Selector.

Definition at line 137 of file SelectorMVA.cc.

138{
139 if (m_TrainFlag) {
140 m_TFile -> cd();
141 m_TTree -> Write();
142 m_TFile -> Write();
143 m_TFile -> Close();
144 }
145}
TFile * m_TFile
output file for training data
Definition SelectorMVA.h:76

◆ getOptimalResponseCut()

float getOptimalResponseCut ( )
overridevirtual

returns optimal cut to use with selector

Reimplemented from Selector.

Definition at line 124 of file SelectorMVA.cc.

125{
126 if (m_TrainFlag) {
127 return 0.5;
128 }
129 std::string elementIdentfier = "optimal_cut";
130 if (!m_weightfile.containsElement(elementIdentfier)) {
131 B2FATAL("No optimal cut stored in curlTagger MVA payload!");
132 }
133 // require the default value for the compiler to deduce the template class
134 return m_weightfile.getElement(elementIdentfier, 0.5);
135}
MVA::Weightfile m_weightfile
mva weightfile
Definition SelectorMVA.h:85

◆ getResponse()

float getResponse ( Particle * iPart,
Particle * jPart )
overridevirtual

Selector response that this pair of particles come from the same mc/actual particle.

Implements Selector.

Definition at line 147 of file SelectorMVA.cc.

148{
149 MVA::SingleDataset dataset(m_generalOptions, getVariables(iPart, jPart));
150 return m_expert.apply(dataset)[0];
151}
virtual std::vector< float > getVariables(Particle *iPart, Particle *jPart) override
returns vector of variables used by this selector.
MVA::FastBDTExpert m_expert
mva expert
Definition SelectorMVA.h:91
MVA::GeneralOptions m_generalOptions
mva general options (for the expert)
Definition SelectorMVA.h:88

◆ getVariables()

std::vector< float > getVariables ( Particle * iPart,
Particle * jPart )
overridevirtual

returns vector of variables used by this selector.

Implements Selector.

Definition at line 67 of file SelectorMVA.cc.

68{
69 updateVariables(iPart, jPart);
73}
Float_t m_TrackTanLambdaDiffEW
error weighted track tan lambda diff difference
Float_t m_TrackZ0DiffEW
error weighted track Z0 difference
Float_t m_PtDiffEW
error weighted particle Pt difference
Float_t m_PPhi
angle between particle momentum vectors
Float_t m_TrackPhi0DiffEW
error weighted track Phi0 difference
Float_t m_PzDiffEW
error weighted particle Pz difference
Float_t m_TrackD0DiffEW
error weighted track D0 difference
Float_t m_ChargeProduct
charge(p1) * charge(p2)
Float_t m_TrackOmegaDiffEW
error weighted track Omega difference

◆ initialize()

void initialize ( )
overridevirtual

initialize whatever needs to be initialized (root file etc)

Reimplemented from Selector.

Definition at line 81 of file SelectorMVA.cc.

82{
83 if (m_TrainFlag) {
84 //make training data
85 m_TFile = TFile::Open(m_TFileName.c_str(), "RECREATE");
86 m_TTree = new TTree("ntuple", "Training Data for the Curl Tagger MVA");
87
88 m_TTree -> Branch("PPhi", &m_PPhi, "PPhi/F");
89 m_TTree -> Branch("ChargeProduct", &m_ChargeProduct, "ChargeProduct/F");
90 m_TTree -> Branch("PtDiffEW", &m_PtDiffEW, "PtDiffEW/F");
91 m_TTree -> Branch("PzDiffEW", &m_PzDiffEW, "PzDiffEW/F");
92 m_TTree -> Branch("TrackD0DiffEW", &m_TrackD0DiffEW, "TrackD0DiffEW/F");
93 m_TTree -> Branch("TrackZ0DiffEW", &m_TrackZ0DiffEW, "TrackZ0DiffEW/F");
94 m_TTree -> Branch("TrackTanLambdaDiffEW", &m_TrackTanLambdaDiffEW, "TrackTanLambdaDiffEW/F");
95 m_TTree -> Branch("TrackPhi0DiffEW", &m_TrackPhi0DiffEW, "TrackPhi0DiffEW/F");
96 m_TTree -> Branch("TrackOmegaDiffEW", &m_TrackOmegaDiffEW, "TrackOmegaDiffEW/F");
97
98 m_TTree -> Branch("IsCurl", &m_IsCurl, "IsCurl/O");
99
100 m_target_variable = "IsCurl";
101 m_variables = {"PPhi", "ChargeProduct", "PtDiffEW",
102 "PzDiffEW", "TrackD0DiffEW", "TrackZ0DiffEW",
103 "TrackTanLambdaDiffEW", "TrackPhi0DiffEW", "TrackOmegaDiffEW"
104 };
105
106 } else {
107 // normal application
108 m_weightfile_representation = std::make_unique<DBObjPtr<DatabaseRepresentationOfWeightfile>>(
109 MVA::makeSaveForDatabase(m_identifier));
110 (*m_weightfile_representation.get()).addCallback([this]() { initializeMVA();});
112 }
113}
std::vector< std::string > m_variables
names of variables used by mva
void initializeMVA()
initialize the MVA Expert
std::unique_ptr< DBObjPtr< DatabaseRepresentationOfWeightfile > > m_weightfile_representation
Database pointer to the Database representation of the weightfile.
Definition SelectorMVA.h:82
std::string m_target_variable
name of target variable (isCurl)

◆ initializeMVA()

void initializeMVA ( )

initialize the MVA Expert

Definition at line 115 of file SelectorMVA.cc.

116{
117 std::stringstream ss((*m_weightfile_representation)->m_data);
119 m_weightfile.getOptions(m_generalOptions);
121}
static Weightfile loadFromStream(std::istream &stream)
Static function which deserializes a Weightfile from a stream.

◆ updateVariables()

void updateVariables ( Particle * iPart,
Particle * jPart )
private

updates the value of the MVA variable

Definition at line 35 of file SelectorMVA.cc.

36{
37 if (m_TrainFlag) {
38 m_IsCurl = Variable::genParticleIndex(iPart) == Variable::genParticleIndex(jPart);
39 }
40 m_ChargeProduct = iPart->getCharge() * jPart->getCharge();
41
42 m_PPhi = acos(iPart->getMomentum().Unit().Dot(jPart->getMomentum().Unit()));
43
44 m_PtDiffEW = std::abs(Variable::particlePt(iPart) - Variable::particlePt(jPart)) / sqrt(pow(Variable::particlePtErr(
45 iPart), 2) + pow(Variable::particlePtErr(jPart), 2));
46
47 m_PzDiffEW = std::abs(Variable::particlePz(iPart) - Variable::particlePz(jPart)) / sqrt(pow(Variable::particlePzErr(
48 iPart), 2) + pow(Variable::particlePzErr(jPart), 2));
49
50 m_TrackD0DiffEW = std::abs(Variable::trackD0(iPart) - Variable::trackD0(jPart)) / sqrt(pow(Variable::trackD0Error(
51 iPart), 2) + pow(Variable::trackD0Error(jPart), 2));
52
53 m_TrackZ0DiffEW = std::abs(Variable::trackZ0(iPart) - Variable::trackZ0(jPart)) / sqrt(pow(Variable::trackZ0Error(
54 iPart), 2) + pow(Variable::trackZ0Error(jPart), 2));
55
56 m_TrackTanLambdaDiffEW = std::abs(Variable::trackTanLambda(iPart) - Variable::trackTanLambda(jPart)) / sqrt(pow(
57 Variable::trackTanLambdaError(
58 iPart), 2) + pow(Variable::trackTanLambdaError(jPart), 2));
59
60 m_TrackPhi0DiffEW = std::abs(Variable::trackPhi0(iPart) - Variable::trackPhi0(jPart)) / sqrt(pow(Variable::trackPhi0Error(
61 iPart), 2) + pow(Variable::trackPhi0Error(jPart), 2));
62
63 m_TrackOmegaDiffEW = std::abs(Variable::trackOmega(iPart) - Variable::trackOmega(jPart)) / sqrt(pow(Variable::trackOmegaError(
64 iPart), 2) + pow(Variable::trackOmegaError(jPart), 2));
65}
double getCharge(void) const
Returns particle charge.
Definition Particle.cc:653
ROOT::Math::XYZVector getMomentum() const
Returns momentum vector.
Definition Particle.h:580
double sqrt(double a)
sqrt for double
Definition beamHelpers.h:28

Member Data Documentation

◆ m_ChargeProduct

Float_t m_ChargeProduct
private

charge(p1) * charge(p2)

Definition at line 112 of file SelectorMVA.h.

◆ m_datafiles

std::vector<std::string> m_datafiles
private

name of datafile

Definition at line 98 of file SelectorMVA.h.

◆ m_expert

MVA::FastBDTExpert m_expert
private

mva expert

Definition at line 91 of file SelectorMVA.h.

◆ m_generalOptions

MVA::GeneralOptions m_generalOptions
private

mva general options (for the expert)

Definition at line 88 of file SelectorMVA.h.

◆ m_identifier

std::string m_identifier
private

mva identifier

Definition at line 95 of file SelectorMVA.h.

◆ m_IsCurl

Bool_t m_IsCurl
private

isCurl Truth

Definition at line 136 of file SelectorMVA.h.

◆ m_PPhi

Float_t m_PPhi
private

angle between particle momentum vectors

Definition at line 109 of file SelectorMVA.h.

◆ m_PtDiffEW

Float_t m_PtDiffEW
private

error weighted particle Pt difference

Definition at line 115 of file SelectorMVA.h.

◆ m_PzDiffEW

Float_t m_PzDiffEW
private

error weighted particle Pz difference

Definition at line 118 of file SelectorMVA.h.

◆ m_target_variable

std::string m_target_variable
private

name of target variable (isCurl)

Definition at line 104 of file SelectorMVA.h.

◆ m_TFile

TFile* m_TFile
private

output file for training data

Definition at line 76 of file SelectorMVA.h.

◆ m_TFileName

std::string m_TFileName
private

name of output file for training data

Definition at line 73 of file SelectorMVA.h.

◆ m_TrackD0DiffEW

Float_t m_TrackD0DiffEW
private

error weighted track D0 difference

Definition at line 121 of file SelectorMVA.h.

◆ m_TrackOmegaDiffEW

Float_t m_TrackOmegaDiffEW
private

error weighted track Omega difference

Definition at line 133 of file SelectorMVA.h.

◆ m_TrackPhi0DiffEW

Float_t m_TrackPhi0DiffEW
private

error weighted track Phi0 difference

Definition at line 130 of file SelectorMVA.h.

◆ m_TrackTanLambdaDiffEW

Float_t m_TrackTanLambdaDiffEW
private

error weighted track tan lambda diff difference

Definition at line 127 of file SelectorMVA.h.

◆ m_TrackZ0DiffEW

Float_t m_TrackZ0DiffEW
private

error weighted track Z0 difference

Definition at line 124 of file SelectorMVA.h.

◆ m_TrainFlag

bool m_TrainFlag
private

applying mva or training it

Definition at line 70 of file SelectorMVA.h.

◆ m_TTree

TTree* m_TTree
private

training data tree

Definition at line 79 of file SelectorMVA.h.

◆ m_variables

std::vector<std::string> m_variables
private

names of variables used by mva

Definition at line 101 of file SelectorMVA.h.

◆ m_weightfile

MVA::Weightfile m_weightfile
private

mva weightfile

Definition at line 85 of file SelectorMVA.h.

◆ m_weightfile_representation

std::unique_ptr<DBObjPtr<DatabaseRepresentationOfWeightfile> > m_weightfile_representation
private

Database pointer to the Database representation of the weightfile.

Definition at line 82 of file SelectorMVA.h.


The documentation for this class was generated from the following files: