Belle II Software development
ECLChargedPIDPhasespaceCategory Class Reference

Stores all required information for the ECLChargedPIDMVA for a phasespace category. More...

#include <ECLChargedPIDMVAWeights.h>

Inheritance diagram for ECLChargedPIDPhasespaceCategory:

Public Types

enum class  MVAResponseTransformMode : unsigned int {
  c_LogTransform = 0 ,
  c_LogTransformSingle = 1 ,
  c_GaussianTransform = 2 ,
  c_DecorrelationTransform = 3 ,
  c_DirectMVAResponse = 4 ,
  c_LogMVAResponse = 5
}
 Enum of implemented transformations which can be applied to the MVA response. More...
 

Public Member Functions

 ECLChargedPIDPhasespaceCategory ()
 Default constructor, necessary for ROOT to stream the object.
 
 ECLChargedPIDPhasespaceCategory (const std::string weightfilePath, const MVAResponseTransformMode &mvaResponeTransformMode, const std::unordered_map< unsigned int, unsigned int > &mvaIndexForHypothesis)
 Useful constructor.
 
 ~ECLChargedPIDPhasespaceCategory ()
 Destructor.
 
const std::string getSerialisedWeight () const
 Getter for serialised weightfile.
 
MVAResponseTransformMode getTransformMode () const
 Getter for the MVA transform mode.
 
const TF1 * getPDF (const unsigned int iMVAResponse, const unsigned int hypoPDG) const
 Getter for pdfs.
 
const TH1F * getCDF (const unsigned int iMVAResponse, const int hypoPDG) const
 Gets the cdf for the hypothesis pdg for a given response value.
 
const std::vector< float > * getDecorrelationMatrix (const int hypoPDG) const
 Gets the decorrelation matrix for a given particle hypothesis.
 
void setCDFs (std::vector< std::unordered_map< unsigned int, TH1F > > cdfs)
 Set the cdfs.
 
void setPDFs (std::vector< std::unordered_map< unsigned int, TF1 > > &pdfs)
 Set the pdfs.
 
void setDecorrelationMatrixMap (std::unordered_map< unsigned int, std::vector< float > > decorrelationMatrices)
 Set the decorrelation matrices.
 
void setlogTransformOffset (const float &offset)
 Set the offset used in the log transformation to be consistent with the offset used when generating the p.d.f.s.
 
float getLogTransformOffset () const
 Getter for the log transform offset.
 
void setTemperature (const float &temperature)
 Set the temperature parameter used to calibrate the MVA.
 
float getTemperature () const
 Getter for the temperature.
 
void setMaxPossibleResponseValue (const float &offset)
 Set the max possible response value, used in log transformation of the responses.
 
float getMaxPossibleResponseValue () const
 Get the max possible response value, used in log transformation of the responses.
 
unsigned int getMVAIndexForHypothesis (const unsigned int hypoPDG) const
 Maps a charged stable pdg code to an index of the MVA response.
 

Private Member Functions

 ClassDef (ECLChargedPIDPhasespaceCategory, 1)
 ClassDef.
 

Private Attributes

TParameter< float > m_log_transform_offset
 Small offset to avoid mva response values of 1.0 being log transformed to NaN.
 
TParameter< float > m_max_possible_response_value
 Max possible value of the mva response.
 
TParameter< float > m_temperature
 calibration factor for MVA responses.
 
std::string m_weight
 Serialsed MVA weightfile.
 
MVAResponseTransformMode m_mvaResponseTransformMode
 Stores which transformation mode to apply to the mva responses.
 
std::vector< std::unordered_map< unsigned int, TF1 > > m_pdfs
 A vector of unodered maps.
 
std::unordered_map< unsigned int, unsigned int > m_mvaIndexForHypothesis
 Unordered map of abs(pdg_code) for the 6 charged stable hypotheses to index of the MVA response vector.
 
std::vector< std::unordered_map< unsigned int, TH1F > > m_cdfs
 CDFs for each mva return value for each hypothesis.
 
std::unordered_map< unsigned int, std::vector< float > > m_decorrelationMatrices
 Decorrelation matrices.
 

Detailed Description

Stores all required information for the ECLChargedPIDMVA for a phasespace category.

This includes:

  • MVA weightfiles for multiclass MVA.
  • MVAResponseTransform mode detailing which transformations will be applied to the MVA response.
  • unordered_map mapping a particle hypothesis to the output index of a MVA.
  • (Optional) TF1 p.d.fs for each charged particle hypothesis for each mva output variable.
  • (Optional) TH1F for each charged particle hypothesis for each mva output variable for gaussianisation.
  • (Optional) vector of floats (flattened square matrix) for potential linear decorrelation of the gaussian transformed mva response variables.

Definition at line 132 of file ECLChargedPIDMVAWeights.h.

Member Enumeration Documentation

◆ MVAResponseTransformMode

enum class MVAResponseTransformMode : unsigned int
strong

Enum of implemented transformations which can be applied to the MVA response.

Enumerator
c_LogTransform 

Log transform the mva responses.

And take the likelihood as the product of likelihoods from all mva responses.

c_LogTransformSingle 

Log transform the mva responses.

Take the likelihood from only the mva response for the hypothesis.

c_GaussianTransform 

Gaussian transform of the log transformed mva response.

c_DecorrelationTransform 

Decorrelation transform of the gaussian transformed mva responses.

c_DirectMVAResponse 

Directly take the MVA response as the logL, useful if we train neural nets to learn the logL.

c_LogMVAResponse 

Take the log of the MVA response.

Essentially undoes the softmax function.

Definition at line 136 of file ECLChargedPIDMVAWeights.h.

136 : unsigned int {
138 c_LogTransform = 0,
149 };
@ c_DirectMVAResponse
Directly take the MVA response as the logL, useful if we train neural nets to learn the logL.
@ c_DecorrelationTransform
Decorrelation transform of the gaussian transformed mva responses.
@ c_GaussianTransform
Gaussian transform of the log transformed mva response.

Constructor & Destructor Documentation

◆ ECLChargedPIDPhasespaceCategory() [1/2]

Default constructor, necessary for ROOT to stream the object.

Definition at line 154 of file ECLChargedPIDMVAWeights.h.

154 :
155 m_log_transform_offset("logTransformOffset", 1e-15),
156 m_max_possible_response_value("maxPossibleResponseValue", 1.0),
157 m_temperature("temperature", 1.0)
158 {};
TParameter< float > m_max_possible_response_value
Max possible value of the mva response.
TParameter< float > m_temperature
calibration factor for MVA responses.
TParameter< float > m_log_transform_offset
Small offset to avoid mva response values of 1.0 being log transformed to NaN.

◆ ECLChargedPIDPhasespaceCategory() [2/2]

ECLChargedPIDPhasespaceCategory ( const std::string  weightfilePath,
const MVAResponseTransformMode mvaResponeTransformMode,
const std::unordered_map< unsigned int, unsigned int > &  mvaIndexForHypothesis 
)
inline

Useful constructor.

Parameters
weightfilePathpath to the MVA weightfile for this phasespace category.
mvaResponeTransformModemva response transform mode booked for this phasespace.
mvaIndexForHypothesisunordered_map mapping hypothesis to index of mva response. Useful if we exclude a class from the MVA training but want to use the likelihood of a different particle. For example using the proton pdf for a deuteron.

Definition at line 167 of file ECLChargedPIDMVAWeights.h.

169 :
170 m_log_transform_offset("logTransformOffset", 1e-15),
171 m_max_possible_response_value("maxPossibleResponseValue", 1.0),
172 m_temperature("temperature", 1.0)
173 {
174 // Load and serialize the MVA::Weightfile object into a string for storage in the database,
175 // otherwise there are issues w/ dictionary generation for the payload class...
176 Belle2::MVA::Weightfile weightfile;
177 if (boost::ends_with(weightfilePath, ".root")) {
178 weightfile = Belle2::MVA::Weightfile::loadFromROOTFile(weightfilePath);
179 } else if (boost::ends_with(weightfilePath, ".xml")) {
180 weightfile = Belle2::MVA::Weightfile::loadFromXMLFile(weightfilePath);
181 } else {
182 B2WARNING("Unkown file extension for file: " << weightfilePath << ", fallback to xml...");
183 weightfile = Belle2::MVA::Weightfile::loadFromXMLFile(weightfilePath);
184 }
185 std::stringstream ss;
187
188 // store
189 m_weight = ss.str();
190 m_mvaResponseTransformMode = mvaResponeTransformMode;
191 m_mvaIndexForHypothesis = mvaIndexForHypothesis;
192 }
MVAResponseTransformMode m_mvaResponseTransformMode
Stores which transformation mode to apply to the mva responses.
std::unordered_map< unsigned int, unsigned int > m_mvaIndexForHypothesis
Unordered map of abs(pdg_code) for the 6 charged stable hypotheses to index of the MVA response vecto...
std::string m_weight
Serialsed MVA weightfile.
The Weightfile class serializes all information about a training into an xml tree.
Definition: Weightfile.h:38
static Weightfile loadFromXMLFile(const std::string &filename)
Static function which loads a Weightfile from a XML file.
Definition: Weightfile.cc:240
static Weightfile loadFromROOTFile(const std::string &filename)
Static function which loads a Weightfile from a ROOT file.
Definition: Weightfile.cc:217
static void saveToStream(Weightfile &weightfile, std::ostream &stream)
Static function which serializes a Weightfile to a stream.
Definition: Weightfile.cc:185

◆ ~ECLChargedPIDPhasespaceCategory()

Destructor.

Definition at line 197 of file ECLChargedPIDMVAWeights.h.

197{};

Member Function Documentation

◆ getCDF()

const TH1F * getCDF ( const unsigned int  iMVAResponse,
const int  hypoPDG 
) const
inline

Gets the cdf for the hypothesis pdg for a given response value.

Parameters
iMVAResponseindex of MVA response.
hypoPDGhypothesis pdg.

Definition at line 224 of file ECLChargedPIDMVAWeights.h.

225 {
226 return &m_cdfs.at(iMVAResponse).at(hypoPDG);
227 }
std::vector< std::unordered_map< unsigned int, TH1F > > m_cdfs
CDFs for each mva return value for each hypothesis.

◆ getDecorrelationMatrix()

const std::vector< float > * getDecorrelationMatrix ( const int  hypoPDG) const
inline

Gets the decorrelation matrix for a given particle hypothesis.

Parameters
hypoPDGhypothesis pdg.

Definition at line 233 of file ECLChargedPIDMVAWeights.h.

234 {
235 return &m_decorrelationMatrices.at(hypoPDG);
236 }
std::unordered_map< unsigned int, std::vector< float > > m_decorrelationMatrices
Decorrelation matrices.

◆ getLogTransformOffset()

float getLogTransformOffset ( ) const
inline

Getter for the log transform offset.

Definition at line 272 of file ECLChargedPIDMVAWeights.h.

273 {
274 return m_log_transform_offset.GetVal();
275 }

◆ getMaxPossibleResponseValue()

float getMaxPossibleResponseValue ( ) const
inline

Get the max possible response value, used in log transformation of the responses.

Definition at line 304 of file ECLChargedPIDMVAWeights.h.

305 {
306 return m_max_possible_response_value.GetVal();
307 }

◆ getMVAIndexForHypothesis()

unsigned int getMVAIndexForHypothesis ( const unsigned int  hypoPDG) const
inline

Maps a charged stable pdg code to an index of the MVA response.

In general this is a one-to-one mapping however in cases where we do not include all six stable charged particles in the MVA training we may have a many-to-one mapping. For example if we take the proton response value also for deuterons.

Definition at line 315 of file ECLChargedPIDMVAWeights.h.

316 {
317 return m_mvaIndexForHypothesis.at(hypoPDG);
318 }

◆ getPDF()

const TF1 * getPDF ( const unsigned int  iMVAResponse,
const unsigned int  hypoPDG 
) const
inline

Getter for pdfs.

Parameters
iMVAResponseindex of MVA response.
hypoPDGhypothesis pdg.

Definition at line 214 of file ECLChargedPIDMVAWeights.h.

215 {
216 return &m_pdfs.at(iMVAResponse).at(hypoPDG);
217 }
std::vector< std::unordered_map< unsigned int, TF1 > > m_pdfs
A vector of unodered maps.

◆ getSerialisedWeight()

const std::string getSerialisedWeight ( ) const
inline

Getter for serialised weightfile.

Definition at line 202 of file ECLChargedPIDMVAWeights.h.

202{return m_weight;}

◆ getTemperature()

float getTemperature ( ) const
inline

Getter for the temperature.

Definition at line 288 of file ECLChargedPIDMVAWeights.h.

289 {
290 return m_temperature.GetVal();
291 }

◆ getTransformMode()

MVAResponseTransformMode getTransformMode ( ) const
inline

Getter for the MVA transform mode.

Definition at line 207 of file ECLChargedPIDMVAWeights.h.

◆ setCDFs()

void setCDFs ( std::vector< std::unordered_map< unsigned int, TH1F > >  cdfs)
inline

Set the cdfs.

Parameters
cdfsvector of map of cdfs to be stored in the payload.

Definition at line 242 of file ECLChargedPIDMVAWeights.h.

242{m_cdfs = cdfs;}

◆ setDecorrelationMatrixMap()

void setDecorrelationMatrixMap ( std::unordered_map< unsigned int, std::vector< float > >  decorrelationMatrices)
inline

Set the decorrelation matrices.

Parameters
decorrelationMatricesmap of decorrelation matrices to be stored in the payload.

Definition at line 256 of file ECLChargedPIDMVAWeights.h.

257 {
258 m_decorrelationMatrices = decorrelationMatrices;
259 }

◆ setlogTransformOffset()

void setlogTransformOffset ( const float &  offset)
inline

Set the offset used in the log transformation to be consistent with the offset used when generating the p.d.f.s.

Definition at line 264 of file ECLChargedPIDMVAWeights.h.

265 {
266 m_log_transform_offset.SetVal(offset);
267 }

◆ setMaxPossibleResponseValue()

void setMaxPossibleResponseValue ( const float &  offset)
inline

Set the max possible response value, used in log transformation of the responses.

Definition at line 296 of file ECLChargedPIDMVAWeights.h.

297 {
298 m_max_possible_response_value.SetVal(offset);
299 }

◆ setPDFs()

void setPDFs ( std::vector< std::unordered_map< unsigned int, TF1 > > &  pdfs)
inline

Set the pdfs.

Parameters
pdfsvector of map of pdfs to be stored in the payload.

Definition at line 249 of file ECLChargedPIDMVAWeights.h.

249{m_pdfs = pdfs;}

◆ setTemperature()

void setTemperature ( const float &  temperature)
inline

Set the temperature parameter used to calibrate the MVA.

Definition at line 280 of file ECLChargedPIDMVAWeights.h.

281 {
282 m_temperature.SetVal(temperature);
283 }

Member Data Documentation

◆ m_cdfs

std::vector<std::unordered_map<unsigned int, TH1F> > m_cdfs
private

CDFs for each mva return value for each hypothesis.

The N vector elements correspond to the N MVA return values. The unordered map maps the hypothesis pdg values to their matching TH1F cdfs which can be used for a gaussianisation.

Definition at line 353 of file ECLChargedPIDMVAWeights.h.

◆ m_decorrelationMatrices

std::unordered_map<unsigned int, std::vector<float> > m_decorrelationMatrices
private

Decorrelation matrices.

To be used (optionally) afer gaussianisation. The unordered map maps the hypothesis pdg values to their matching linearised decorrelation matrix.

Definition at line 359 of file ECLChargedPIDMVAWeights.h.

◆ m_log_transform_offset

TParameter<float> m_log_transform_offset
private

Small offset to avoid mva response values of 1.0 being log transformed to NaN.

Definition at line 322 of file ECLChargedPIDMVAWeights.h.

◆ m_max_possible_response_value

TParameter<float> m_max_possible_response_value
private

Max possible value of the mva response.

Used in the log transformation.

Definition at line 323 of file ECLChargedPIDMVAWeights.h.

◆ m_mvaIndexForHypothesis

std::unordered_map<unsigned int, unsigned int> m_mvaIndexForHypothesis
private

Unordered map of abs(pdg_code) for the 6 charged stable hypotheses to index of the MVA response vector.

Needed if we do not train with all 6 species to map several to the same MVA response value.

Definition at line 346 of file ECLChargedPIDMVAWeights.h.

◆ m_mvaResponseTransformMode

MVAResponseTransformMode m_mvaResponseTransformMode
private

Stores which transformation mode to apply to the mva responses.

Definition at line 334 of file ECLChargedPIDMVAWeights.h.

◆ m_pdfs

std::vector<std::unordered_map<unsigned int, TF1> > m_pdfs
private

A vector of unodered maps.

The vector corresponds to the return values of the MVA, one for each class correspondonding to charged stable particles considered by the MVA. In general this is the full six charged stable particles {e, mu, pi, K, p, d}. The unordered map maps the hypothesis pdg values to their matching TF1 pdfs from which the liklihood will be taken.

Definition at line 340 of file ECLChargedPIDMVAWeights.h.

◆ m_temperature

TParameter<float> m_temperature
private

calibration factor for MVA responses.

Follows arXiv:1706.04599

Definition at line 324 of file ECLChargedPIDMVAWeights.h.

◆ m_weight

std::string m_weight
private

Serialsed MVA weightfile.

Definition at line 329 of file ECLChargedPIDMVAWeights.h.


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