Belle II Software  release-08-01-10
PIDDetectorWeights Class Reference

Class for handling the PID weights per detector, used to calculate the track helix isolation score per particle. More...

#include <PIDDetectorWeights.h>

Inheritance diagram for PIDDetectorWeights:
Collaboration diagram for PIDDetectorWeights:

Classes

class  WeightsTable
 Nested class acting as a container the per-detector weights. More...
 

Public Member Functions

 PIDDetectorWeights ()
 Default constructor, necessary for ROOT to stream the object.
 
 ~PIDDetectorWeights ()
 Destructor.
 
 PIDDetectorWeights (const std::string &weightsCSVFileName)
 Constructor from CSV file of weights. More...
 
 PIDDetectorWeights (const std::string &treeName, const std::string &weightsROOTFileName)
 Constructor from ROOT file w/ TTree of weights. More...
 
ROOT::RDataFrame getWeightsRDF () const
 Get the RDataFrame of detector weights. More...
 
double getWeight (Const::ChargedStable hypo, Const::EDetector det, double p, double theta) const
 Lookup the weight from the internal map structures. More...
 

Private Member Functions

void fillWeightsTablePerHypoFromRDF ()
 Fill the internal weights container class per particle hypo, based on the content of the RDataFrame.
 
 ClassDef (PIDDetectorWeights, 4)
 ClassDef as this is a TObject.
 

Private Attributes

std::map< int, WeightsTablem_weightsTablePerHypo
 Map containing a WeightsTable object per particle hypo. More...
 
ROOT::RDataFrame m_weightsRDataFrame = ROOT::RDataFrame(1)
 The RDataFrame containing the detector weights per particle hypo, per phase space bin. More...
 
std::map< std::string, std::string > m_weightNames
 The names of the per-detector weight columns in the RDataFrame. More...
 

Detailed Description

Class for handling the PID weights per detector, used to calculate the track helix isolation score per particle.

Definition at line 31 of file PIDDetectorWeights.h.

Constructor & Destructor Documentation

◆ PIDDetectorWeights() [1/2]

PIDDetectorWeights ( const std::string &  weightsCSVFileName)
inline

Constructor from CSV file of weights.

NB: please ensure all numeric types are stored as double in the CSV!

Parameters
weightsCSVFileNamethe path to the CSV file conatining the detector weights per std charged particle hypothesis, in bins of p and theta.

Definition at line 88 of file PIDDetectorWeights.h.

89  {
90  m_weightsRDataFrame = ROOT::RDF::MakeCsvDataFrame(weightsCSVFileName);
92  };
void fillWeightsTablePerHypoFromRDF()
Fill the internal weights container class per particle hypo, based on the content of the RDataFrame.
ROOT::RDataFrame m_weightsRDataFrame
The RDataFrame containing the detector weights per particle hypo, per phase space bin.

◆ PIDDetectorWeights() [2/2]

PIDDetectorWeights ( const std::string &  treeName,
const std::string &  weightsROOTFileName 
)
inline

Constructor from ROOT file w/ TTree of weights.

Parameters
treeNamethe name of the TTree with detector weights per std charged particle hypothesis, in bins of p and theta.
weightsROOTFileNamethe path to the ROOT file containing the TTree.

Definition at line 99 of file PIDDetectorWeights.h.

Member Function Documentation

◆ getWeight()

double getWeight ( Const::ChargedStable  hypo,
Const::EDetector  det,
double  p,
double  theta 
) const

Lookup the weight from the internal map structures.

Parameters
hypothe input std charged particle.
detthe input PID detector.
pthe particle momentum in [GeV/c].
thetathe particle polar angle in [rad].

Definition at line 112 of file PIDDetectorWeights.cc.

113 {
114 
115  const auto weightsTable = &m_weightsTablePerHypo.at(hypo.getPDGCode());
116 
117  if (weightsTable->m_isEmpty) {
118  // Weights not available for this pdgId.
119  return std::numeric_limits<float>::quiet_NaN();
120  }
121 
122  // Get the bin index of the input p value.
123  auto pBinUpperEdge_it = std::lower_bound(std::begin(weightsTable->m_pBinEdges),
124  std::end(weightsTable->m_pBinEdges),
125  p);
126  auto pBinIdx = std::distance(std::begin(weightsTable->m_pBinEdges), pBinUpperEdge_it);
127  // Get the bin index of the input theta value.
128  auto thetaBinUpperEdge_it = std::lower_bound(std::begin(weightsTable->m_thetaBinEdges),
129  std::end(weightsTable->m_thetaBinEdges),
130  theta);
131  auto thetaBinIdx = std::distance(std::begin(weightsTable->m_thetaBinEdges), thetaBinUpperEdge_it);
132 
133  // Get the linearised bin index to look up.
134  double linBinIdx = (pBinIdx - 1.0) + (thetaBinIdx - 1.0) * weightsTable->m_nPBins;
135 
136  if (!weightsTable->m_linBinIdxsToRowIdxs.count(linBinIdx)) {
137  // Out-of-bin range p or theta
138  B2DEBUG(11, "\n"
139  << "p = " << p << " [GeV/c], theta = " << theta << " [rad].\n"
140  << "Bin indexes: (" << pBinIdx << ", " << thetaBinIdx << ").\n"
141  << "Either input value is outside of bin range for PID detector weights:\n"
142  << "p : [" << *weightsTable->m_pBinEdges.begin() << ", " << *weightsTable->m_pBinEdges.rbegin() << "],\n"
143  << "theta: [" << *weightsTable->m_thetaBinEdges.begin() << ", " << *weightsTable->m_thetaBinEdges.rbegin() << "]");
144  return std::numeric_limits<float>::quiet_NaN();
145  }
146 
147  auto rowIdx = weightsTable->m_linBinIdxsToRowIdxs.at(linBinIdx);
148 
149  return weightsTable->m_weightsPerDet.at(Const::parseDetectors(det)).at(rowIdx);
150 
151 };
int getPDGCode() const
PDG code.
Definition: Const.h:464
static std::string parseDetectors(EDetector det)
Converts Const::EDetector object to string.
Definition: UnitConst.cc:162
std::map< int, WeightsTable > m_weightsTablePerHypo
Map containing a WeightsTable object per particle hypo.

◆ getWeightsRDF()

ROOT::RDataFrame getWeightsRDF ( ) const
inline

Get the RDataFrame of detector weights.

To be used for testing/debugging only when creating the payload.

Definition at line 109 of file PIDDetectorWeights.h.

Member Data Documentation

◆ m_weightNames

std::map<std::string, std::string> m_weightNames
private
Initial value:
= {
{Const::parseDetectors(Const::CDC), "ablat_s_CDC"},
{Const::parseDetectors(Const::TOP), "ablat_s_TOP"},
{Const::parseDetectors(Const::ARICH), "ablat_s_ARICH"},
{Const::parseDetectors(Const::ECL), "ablat_s_ECL"},
{Const::parseDetectors(Const::KLM), "ablat_s_KLM"}
}

The names of the per-detector weight columns in the RDataFrame.

Definition at line 141 of file PIDDetectorWeights.h.

◆ m_weightsRDataFrame

ROOT::RDataFrame m_weightsRDataFrame = ROOT::RDataFrame(1)
private

The RDataFrame containing the detector weights per particle hypo, per phase space bin.

Using an RDataFrame is convenient when creating the payload from an input CSV file. However, an RDataFrame cannot be streamed in the persistent ROOT file, thus we must prevent this from happening.

Definition at line 136 of file PIDDetectorWeights.h.

◆ m_weightsTablePerHypo

std::map<int, WeightsTable> m_weightsTablePerHypo
private

Map containing a WeightsTable object per particle hypo.

Use to lookup the index corresponding to a (p, theta) pair.

Definition at line 129 of file PIDDetectorWeights.h.


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