Belle II Software development
PIDDetectorWeights.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
13#include <set>
14
15#include <TObject.h>
16#include <ROOT/RDataFrame.hxx>
17#include <ROOT/RCsvDS.hxx>
18
19
20namespace Belle2 {
25
29 class PIDDetectorWeights : public TObject {
30
31 public:
32
37 class WeightsTable {
38 public:
39
40 WeightsTable() :
41 m_isEmpty(false),
42 m_nPBins(0),
44 {};
45
46 bool m_isEmpty;
47
48 std::set<double> m_pBinEdges;
49 std::set<double> m_thetaBinEdges;
50
53
58 std::unordered_map<double, unsigned int> m_linBinIdxsToRowIdxs;
63 std::map<std::string, std::vector<double>> m_weightsPerDet;
64
65 private:
66
67 ClassDef(WeightsTable, 1);
68 };
69
74
79
86 PIDDetectorWeights(const std::string& weightsCSVFileName)
87 {
88 m_weightsRDataFrame = ROOT::RDF::FromCSV(weightsCSVFileName);
90 };
91
97 PIDDetectorWeights(const std::string& treeName, const std::string& weightsROOTFileName) :
98 m_weightsRDataFrame(treeName, weightsROOTFileName)
99 {
101 };
102
107 ROOT::RDataFrame getWeightsRDF() const
108 {
109 return m_weightsRDataFrame;
110 };
111
119 double getWeight(Const::ChargedStable hypo, Const::EDetector det, double p, double theta) const;
120
121 private:
122
127 std::map<int, WeightsTable> m_weightsTablePerHypo;
128
134 ROOT::RDataFrame m_weightsRDataFrame = ROOT::RDataFrame(1);
135
139 std::map<std::string, std::string> m_weightNames = {
140 {Const::parseDetectors(Const::CDC), "ablat_s_CDC"},
141 {Const::parseDetectors(Const::TOP), "ablat_s_TOP"},
142 {Const::parseDetectors(Const::ARICH), "ablat_s_ARICH"},
143 {Const::parseDetectors(Const::ECL), "ablat_s_ECL"},
144 {Const::parseDetectors(Const::KLM), "ablat_s_KLM"}
145 };
146
151
153
154 };
155
157} // Belle2 namespace
Provides a type-safe way to pass members of the chargedStableSet set.
Definition Const.h:589
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition Const.h:42
static std::string parseDetectors(EDetector det)
Converts Const::EDetector object to string.
Definition UnitConst.cc:161
std::unordered_map< double, unsigned int > m_linBinIdxsToRowIdxs
Map the linearised index of the (p, theta) bin indexes to the row index in the (filtered) table.
std::map< std::string, std::vector< double > > m_weightsPerDet
Map each detector to its vector of weights.
ClassDef(WeightsTable, 1)
Needed for sub-class schema evolution.
std::set< double > m_pBinEdges
Set of p bins edges.
std::set< double > m_thetaBinEdges
Set of theta bins edges.
std::map< std::string, std::string > m_weightNames
The names of the per-detector weight columns in the RDataFrame.
PIDDetectorWeights()
Default constructor, necessary for ROOT to stream the object.
PIDDetectorWeights(const std::string &weightsCSVFileName)
Constructor from CSV file of weights.
ClassDef(PIDDetectorWeights, 4)
ClassDef as this is a TObject.
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(const std::string &treeName, const std::string &weightsROOTFileName)
Constructor from ROOT file w/ TTree of weights.
ROOT::RDataFrame getWeightsRDF() const
Get the RDataFrame of detector weights.
double getWeight(Const::ChargedStable hypo, Const::EDetector det, double p, double theta) const
Lookup the weight from the internal map structures.
std::map< int, WeightsTable > m_weightsTablePerHypo
Map containing a WeightsTable object per particle hypo.
Abstract base class for different kinds of events.