Belle II Software development
PIDCalibrationWeight.h
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#pragma once
10
11#include <framework/gearbox/Const.h>
12#include <framework/logging/Logger.h>
13
14#include <boost/algorithm/string.hpp>
15
16#include <TObject.h>
17
18namespace Belle2 {
23
30 typedef std::vector<std::vector<double>> WeightMatrix;
31
35 class PIDCalibrationWeight : public TObject {
36
37 public:
40
42 explicit PIDCalibrationWeight(const WeightMatrix& weightMatrix)
43 : m_weightMatrix(weightMatrix)
44 {};
45
50 void setWeightMatrix(const WeightMatrix& weightMatrix)
51 {
52 m_weightMatrix = weightMatrix;
53 };
54
59 {
60 return m_weightMatrix;
61 };
62
69 double getWeight(int pdg, std::string detector) const
70 {
71 std::vector<double> weightVector = getWeights(pdg);
72
73 Const::EDetector det = Const::invalidDetector; // default value, will be overwritten
74 boost::to_lower(detector);
75 if (detector == "svd") det = Const::SVD;
76 else if (detector == "cdc") det = Const::CDC;
77 else if (detector == "top") det = Const::TOP;
78 else if (detector == "arich") det = Const::ARICH;
79 else if (detector == "ecl") det = Const::ECL;
80 else if (detector == "klm") det = Const::KLM;
81 else B2FATAL("Unknown detector component: " << detector);
82 int det_index = Const::PIDDetectors::c_set.getIndex(det);
83
84 return weightVector[det_index];
85 };
86
93 double getWeight(int pdg, Const::EDetector det) const
94 {
95 std::vector<double> weightVector = getWeights(pdg);
96
97 int det_index = Const::PIDDetectors::c_set.getIndex(det);
98 return weightVector[det_index];
99 };
100
106 std::vector<double> getWeights(int pdg) const
107 {
108 int p_index = -1;
109 for (const auto& pdgIter : Const::chargedStableSet) {
110 if (pdgIter.getPDGCode() == pdg) {
111 p_index = pdgIter.getIndex();
112 break;
113 }
114 }
115 if (p_index == -1)
116 B2FATAL("Invalid particle: " << pdg);
117
118 return m_weightMatrix[p_index];
119 };
120
121 private:
122
127
129
130 };
131
133} // Belle2 namespace
134
135
static const DetectorSet c_set
The set of valid PID detectors.
Definition Const.h:375
static const ParticleSet chargedStableSet
set of charged stable particles
Definition Const.h:618
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition Const.h:42
std::vector< double > getWeights(int pdg) const
Get the weights for the given PDG code.
const WeightMatrix & getWeightMatrix() const
Get the WeightMatrix.
PIDCalibrationWeight(const WeightMatrix &weightMatrix)
Constructor with the initial WeightMatrix.
WeightMatrix m_weightMatrix
PID calibration weight matrix.
double getWeight(int pdg, Const::EDetector det) const
Get the weight for the given combination of the PDG code and the detector in Const::EDetector.
void setWeightMatrix(const WeightMatrix &weightMatrix)
Set the WeightMatrix.
double getWeight(int pdg, std::string detector) const
Get the weight for the given combination of the PDG code and the detector name.
ClassDef(PIDCalibrationWeight, 1)
ClassDef as this is a TObject.
std::vector< std::vector< double > > WeightMatrix
PID calibration weight matrix, 6 (particle type) x 6 (detectors).
Abstract base class for different kinds of events.