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.
 
void setSerialisedWeight (std::string weight)
 Setter 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 129 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 133 of file ECLChargedPIDMVAWeights.h.

133 : unsigned int {
135 c_LogTransform = 0,
137 c_LogTransformSingle = 1,
139 c_GaussianTransform = 2,
141 c_DecorrelationTransform = 3,
143 c_DirectMVAResponse = 4,
145 c_LogMVAResponse = 5
146 };

Constructor & Destructor Documentation

◆ ECLChargedPIDPhasespaceCategory() [1/2]

Default constructor, necessary for ROOT to stream the object.

Definition at line 151 of file ECLChargedPIDMVAWeights.h.

151 :
152 m_log_transform_offset("logTransformOffset", 1e-15),
153 m_max_possible_response_value("maxPossibleResponseValue", 1.0),
154 m_temperature("temperature", 1.0)
155 {};

◆ 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 164 of file ECLChargedPIDMVAWeights.h.

166 :
167 m_log_transform_offset("logTransformOffset", 1e-15),
168 m_max_possible_response_value("maxPossibleResponseValue", 1.0),
169 m_temperature("temperature", 1.0)
170 {
171 // Load and serialize the MVA::Weightfile object into a string for storage in the database,
172 // otherwise there are issues w/ dictionary generation for the payload class...
173 Belle2::MVA::Weightfile weightfile;
174 if (weightfilePath.ends_with(".root")) {
175 weightfile = Belle2::MVA::Weightfile::loadFromROOTFile(weightfilePath);
176 } else if (weightfilePath.ends_with(".xml")) {
177 weightfile = Belle2::MVA::Weightfile::loadFromXMLFile(weightfilePath);
178 } else {
179 B2WARNING("Unknown file extension for file: " << weightfilePath << ", fallback to xml...");
180 weightfile = Belle2::MVA::Weightfile::loadFromXMLFile(weightfilePath);
181 }
182 std::stringstream ss;
184
185 // store
186 m_weight = ss.str();
187 m_mvaResponseTransformMode = mvaResponeTransformMode;
188 m_mvaIndexForHypothesis = mvaIndexForHypothesis;
189 }
static Weightfile loadFromXMLFile(const std::string &filename)
Static function which loads a Weightfile from a XML file.
static Weightfile loadFromROOTFile(const std::string &filename)
Static function which loads a Weightfile from a ROOT file.
static void saveToStream(Weightfile &weightfile, std::ostream &stream)
Static function which serializes a Weightfile to a stream.

◆ ~ECLChargedPIDPhasespaceCategory()

Destructor.

Definition at line 194 of file ECLChargedPIDMVAWeights.h.

194{};

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 226 of file ECLChargedPIDMVAWeights.h.

227 {
228 return &m_cdfs.at(iMVAResponse).at(hypoPDG);
229 }

◆ 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 235 of file ECLChargedPIDMVAWeights.h.

236 {
237 return &m_decorrelationMatrices.at(hypoPDG);
238 }

◆ getLogTransformOffset()

float getLogTransformOffset ( ) const
inline

Getter for the log transform offset.

Definition at line 274 of file ECLChargedPIDMVAWeights.h.

275 {
276 return m_log_transform_offset.GetVal();
277 }

◆ getMaxPossibleResponseValue()

float getMaxPossibleResponseValue ( ) const
inline

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

Definition at line 306 of file ECLChargedPIDMVAWeights.h.

307 {
308 return m_max_possible_response_value.GetVal();
309 }

◆ 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 317 of file ECLChargedPIDMVAWeights.h.

318 {
319 return m_mvaIndexForHypothesis.at(hypoPDG);
320 }

◆ 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 216 of file ECLChargedPIDMVAWeights.h.

217 {
218 return &m_pdfs.at(iMVAResponse).at(hypoPDG);
219 }

◆ getSerialisedWeight()

const std::string getSerialisedWeight ( ) const
inline

Getter for serialised weightfile.

Definition at line 199 of file ECLChargedPIDMVAWeights.h.

199{return m_weight;}

◆ getTemperature()

float getTemperature ( ) const
inline

Getter for the temperature.

Definition at line 290 of file ECLChargedPIDMVAWeights.h.

291 {
292 return m_temperature.GetVal();
293 }

◆ getTransformMode()

MVAResponseTransformMode getTransformMode ( ) const
inline

Getter for the MVA transform mode.

Definition at line 209 of file ECLChargedPIDMVAWeights.h.

209{return m_mvaResponseTransformMode;}

◆ 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 244 of file ECLChargedPIDMVAWeights.h.

244{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 258 of file ECLChargedPIDMVAWeights.h.

259 {
260 m_decorrelationMatrices = decorrelationMatrices;
261 }

◆ 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 266 of file ECLChargedPIDMVAWeights.h.

267 {
268 m_log_transform_offset.SetVal(offset);
269 }

◆ setMaxPossibleResponseValue()

void setMaxPossibleResponseValue ( const float & offset)
inline

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

Definition at line 298 of file ECLChargedPIDMVAWeights.h.

299 {
300 m_max_possible_response_value.SetVal(offset);
301 }

◆ 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 251 of file ECLChargedPIDMVAWeights.h.

251{m_pdfs = pdfs;}

◆ setSerialisedWeight()

void setSerialisedWeight ( std::string weight)
inline

Setter for serialised weightfile.

Definition at line 204 of file ECLChargedPIDMVAWeights.h.

204{ m_weight = weight; }

◆ setTemperature()

void setTemperature ( const float & temperature)
inline

Set the temperature parameter used to calibrate the MVA.

Definition at line 282 of file ECLChargedPIDMVAWeights.h.

283 {
284 m_temperature.SetVal(temperature);
285 }

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 355 of file ECLChargedPIDMVAWeights.h.

◆ m_decorrelationMatrices

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

Decorrelation matrices.

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

Definition at line 361 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 324 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 325 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 348 of file ECLChargedPIDMVAWeights.h.

◆ m_mvaResponseTransformMode

MVAResponseTransformMode m_mvaResponseTransformMode
private

Stores which transformation mode to apply to the mva responses.

Definition at line 336 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 likelihood will be taken.

Definition at line 342 of file ECLChargedPIDMVAWeights.h.

◆ m_temperature

TParameter<float> m_temperature
private

calibration factor for MVA responses.

Follows arXiv:1706.04599

Definition at line 326 of file ECLChargedPIDMVAWeights.h.

◆ m_weight

std::string m_weight
private

Serialsed MVA weightfile.

Definition at line 331 of file ECLChargedPIDMVAWeights.h.


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