Skip to content

Commit 4fe564f

Browse files
committed
Updating B+ selector task to be similar to B+ reduced selector task
1 parent c231493 commit 4fe564f

16 files changed

+455
-149
lines changed

PWGHF/Core/HfHelper.h

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -947,34 +947,59 @@ class HfHelper
947947
}
948948

949949
/// Apply selection on ML scores for charm-hadron daughter in b-hadron decays (common for all the beauty channels)
950-
/// \param candB b-hadron candidates
951950
/// \param cuts ML score selection per bin of charm-hadron pT
952951
/// \param binsPtC pT bin limits of charm hadron
952+
/// \param mlScores vector with ml scores of charm hadron (position 0:bkg 1:prompt 2:nonprompt)
953953
/// \return true if b-hadron candidate passes all selections
954-
template <typename T1, typename T2, typename T3>
955-
bool selectionDmesMlScoresForB(const T1& candB, const T2& cuts, const T3& binsPtC)
954+
template <typename T1, typename T2>
955+
bool applySelectionDmesMlScoresForB(const T1& cuts, const T2& binsPtC, float ptC, std::vector<float> mlScores)
956956
{
957-
auto ptC = RecoDecay::pt(candB.pxProng0(), candB.pyProng0()); // the first daughter is the charm hadron
958957
int pTBin = o2::analysis::findBin(binsPtC, ptC);
959958
if (pTBin == -1) {
960959
return false;
961960
}
962961

963-
if (candB.prong0MlScoreBkg() > cuts->get(pTBin, "ML score charm bkg")) {
962+
if (mlScores[0] > cuts->get(pTBin, "ML score charm bkg")) {
964963
return false;
965964
}
966965

967-
if (candB.prong0MlScorePrompt() > cuts->get(pTBin, "ML score charm prompt")) { // we want non-prompt for beauty
966+
if (mlScores[1] > cuts->get(pTBin, "ML score charm prompt")) { // we want non-prompt for beauty
968967
return false;
969968
}
970969

971-
if (candB.prong0MlScoreNonprompt() < cuts->get(pTBin, "ML score charm nonprompt")) { // we want non-prompt for beauty
970+
if (mlScores[2] < cuts->get(pTBin, "ML score charm nonprompt")) { // we want non-prompt for beauty
972971
return false;
973972
}
974973

975974
return true;
976975
}
977976

977+
/// Apply selection on ML scores for charm-hadron daughter in b-hadron decays (could be common for all the beauty channels)
978+
/// \param candB b-hadron candidates
979+
/// \param cuts ML score selection per bin of charm-hadron pT
980+
/// \param binsPtC pT bin limits of charm hadron
981+
/// \return true if b-hadron candidate passes all selections
982+
template <typename T1, typename T2, typename T3>
983+
bool selectionDmesMlScoresForB(const T1& candD, const T2& cuts, const T3& binsPtC, const std::vector<float>& mlScores)
984+
{
985+
return applySelectionDmesMlScoresForB(cuts, binsPtC, candD.pt(), mlScores);
986+
}
987+
988+
/// Apply selection on ML scores for charm-hadron daughter in b-hadron decays in reduced format (common for all the beauty channels)
989+
/// \param candB b-hadron candidates
990+
/// \param cuts ML score selection per bin of charm-hadron pT
991+
/// \param binsPtC pT bin limits of charm hadron
992+
/// \return true if b-hadron candidate passes all selections
993+
template <typename T1, typename T2, typename T3>
994+
bool selectionDmesMlScoresForBRed(const T1& candB, const T2& cuts, const T3& binsPtC)
995+
{
996+
std::vector<float> mlScores;
997+
mlScores.push_back(candB.prong0MlScoreBkg());
998+
mlScores.push_back(candB.prong0MlScorePrompt());
999+
mlScores.push_back(candB.prong0MlScoreNonprompt()); // we want non-prompt for beauty
1000+
return applySelectionDmesMlScoresForB(cuts, binsPtC, RecoDecay::pt(candB.pxProng0(), candB.pyProng0()), mlScores);
1001+
}
1002+
9781003
private:
9791004
};
9801005

PWGHF/Core/HfMlResponseBplusToD0Pi.h

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@
5959
break; \
6060
}
6161

62+
// where OBJECT is named candidateD and FEATURE = GETTER
63+
#define CHECK_AND_FILL_VEC_D0_INDEX(FEATURE, GETTER1, GETTER2, INDEX) \
64+
case static_cast<uint8_t>(InputFeaturesBplusToD0Pi::FEATURE): { \
65+
if (pdgCode == o2::constants::physics::kD0) { \
66+
inputFeatures.emplace_back((candidateD0.GETTER1())[INDEX]); \
67+
} else { \
68+
inputFeatures.emplace_back((candidateD0.GETTER2())[INDEX]); \
69+
} \
70+
break; \
71+
}
72+
6273
namespace o2::analysis
6374
{
6475

@@ -76,9 +87,9 @@ enum class InputFeaturesBplusToD0Pi : uint8_t {
7687
cpa,
7788
cpaXY,
7889
maxNormalisedDeltaIP,
79-
prong0MlScoreBkg,
80-
prong0MlScorePrompt,
81-
prong0MlScoreNonprompt,
90+
prong0MlProbBkg,
91+
prong0MlProbPrompt,
92+
prong0MlProbNonPrompt,
8293
tpcNSigmaPi1,
8394
tofNSigmaPi1,
8495
tpcTofNSigmaPi1
@@ -97,9 +108,11 @@ class HfMlResponseBplusToD0Pi : public HfMlResponse<TypeOutputScore>
97108
/// \param candidate is the B+ candidate
98109
/// \param prong1 is the candidate's prong1
99110
/// \return inputFeatures vector
100-
template <bool withDmesMl, typename T1, typename T2>
111+
template <bool withDmesMl, typename T1, typename T2, typename T3>
101112
std::vector<float> getInputFeatures(T1 const& candidate,
102-
T2 const& prong1)
113+
T2 const& candidateD0,
114+
int const& pdgCode,
115+
T3 const& prong1)
103116
{
104117
std::vector<float> inputFeatures;
105118

@@ -119,9 +132,9 @@ class HfMlResponseBplusToD0Pi : public HfMlResponse<TypeOutputScore>
119132
CHECK_AND_FILL_VEC_BPLUS(cpa);
120133
CHECK_AND_FILL_VEC_BPLUS(cpaXY);
121134
CHECK_AND_FILL_VEC_BPLUS(maxNormalisedDeltaIP);
122-
CHECK_AND_FILL_VEC_BPLUS(prong0MlScoreBkg);
123-
CHECK_AND_FILL_VEC_BPLUS(prong0MlScorePrompt);
124-
CHECK_AND_FILL_VEC_BPLUS(prong0MlScoreNonprompt);
135+
CHECK_AND_FILL_VEC_D0_INDEX(prong0MlProbBkg, mlProbD0, mlProbD0bar, 0);
136+
CHECK_AND_FILL_VEC_D0_INDEX(prong0MlProbPrompt, mlProbD0, mlProbD0bar, 1);
137+
CHECK_AND_FILL_VEC_D0_INDEX(prong0MlProbNonPrompt, mlProbD0, mlProbD0bar, 2);
125138
// TPC PID variable
126139
CHECK_AND_FILL_VEC_BPLUS_FULL(prong1, tpcNSigmaPi1, tpcNSigmaPi);
127140
// TOF PID variable
@@ -175,9 +188,9 @@ class HfMlResponseBplusToD0Pi : public HfMlResponse<TypeOutputScore>
175188
FILL_MAP_BPLUS(cpa),
176189
FILL_MAP_BPLUS(cpaXY),
177190
FILL_MAP_BPLUS(maxNormalisedDeltaIP),
178-
FILL_MAP_BPLUS(prong0MlScoreBkg),
179-
FILL_MAP_BPLUS(prong0MlScorePrompt),
180-
FILL_MAP_BPLUS(prong0MlScoreNonprompt),
191+
FILL_MAP_BPLUS(prong0MlProbBkg),
192+
FILL_MAP_BPLUS(prong0MlProbPrompt),
193+
FILL_MAP_BPLUS(prong0MlProbNonPrompt),
181194
// TPC PID variable
182195
FILL_MAP_BPLUS(tpcNSigmaPi1),
183196
// TOF PID variable
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file HfMlResponseBplusToD0PiReduced.h
13+
/// \brief Class to compute the ML response for B± → D0(bar) π± analysis selections in the reduced format
14+
/// \author Antonio Palasciano <antonio.palasciano@ba.infn.it>, INFN Bari
15+
16+
#ifndef PWGHF_CORE_HFMLRESPONSEBPLUSTOD0PIREDUCED_H_
17+
#define PWGHF_CORE_HFMLRESPONSEBPLUSTOD0PIREDUCED_H_
18+
19+
#include <map>
20+
#include <string>
21+
#include <vector>
22+
23+
#include "PWGHF/Core/HfMlResponse.h"
24+
#include "PWGHF/D2H/Utils/utilsRedDataFormat.h"
25+
26+
// Fill the map of available input features
27+
// the key is the feature's name (std::string)
28+
// the value is the corresponding value in EnumInputFeatures
29+
#define FILL_MAP_BPLUS(FEATURE) \
30+
{ \
31+
#FEATURE, static_cast<uint8_t>(InputFeaturesBplusToD0PiReduced::FEATURE)}
32+
33+
// Check if the index of mCachedIndices (index associated to a FEATURE)
34+
// matches the entry in EnumInputFeatures associated to this FEATURE
35+
// if so, the inputFeatures vector is filled with the FEATURE's value
36+
// by calling the corresponding GETTER from OBJECT
37+
#define CHECK_AND_FILL_VEC_BPLUS_FULL(OBJECT, FEATURE, GETTER) \
38+
case static_cast<uint8_t>(InputFeaturesBplusToD0PiReduced::FEATURE): { \
39+
inputFeatures.emplace_back(OBJECT.GETTER()); \
40+
break; \
41+
}
42+
43+
// Check if the index of mCachedIndices (index associated to a FEATURE)
44+
// matches the entry in EnumInputFeatures associated to this FEATURE
45+
// if so, the inputFeatures vector is filled with the FEATURE's value
46+
// by calling the GETTER function taking OBJECT in argument
47+
#define CHECK_AND_FILL_VEC_BPLUS_FUNC(OBJECT, FEATURE, GETTER) \
48+
case static_cast<uint8_t>(InputFeaturesBplusToD0PiReduced::FEATURE): { \
49+
inputFeatures.emplace_back(GETTER(OBJECT)); \
50+
break; \
51+
}
52+
53+
// Specific case of CHECK_AND_FILL_VEC_BPLUS_FULL(OBJECT, FEATURE, GETTER)
54+
// where OBJECT is named candidate and FEATURE = GETTER
55+
#define CHECK_AND_FILL_VEC_BPLUS(GETTER) \
56+
case static_cast<uint8_t>(InputFeaturesBplusToD0PiReduced::GETTER): { \
57+
inputFeatures.emplace_back(candidate.GETTER()); \
58+
break; \
59+
}
60+
61+
namespace o2::analysis
62+
{
63+
64+
enum class InputFeaturesBplusToD0PiReduced : uint8_t {
65+
ptProng0 = 0,
66+
ptProng1,
67+
impactParameter0,
68+
impactParameter1,
69+
impactParameterProduct,
70+
chi2PCA,
71+
decayLength,
72+
decayLengthXY,
73+
decayLengthNormalised,
74+
decayLengthXYNormalised,
75+
cpa,
76+
cpaXY,
77+
maxNormalisedDeltaIP,
78+
prong0MlScoreBkg,
79+
prong0MlScorePrompt,
80+
prong0MlScoreNonprompt,
81+
tpcNSigmaPi1,
82+
tofNSigmaPi1,
83+
tpcTofNSigmaPi1
84+
};
85+
86+
template <typename TypeOutputScore = float>
87+
class HfMlResponseBplusToD0PiReduced : public HfMlResponse<TypeOutputScore>
88+
{
89+
public:
90+
/// Default constructor
91+
HfMlResponseBplusToD0PiReduced() = default;
92+
/// Default destructor
93+
virtual ~HfMlResponseBplusToD0PiReduced() = default;
94+
95+
/// Method to get the input features vector needed for ML inference
96+
/// \param candidate is the B+ candidate
97+
/// \param prong1 is the candidate's prong1
98+
/// \return inputFeatures vector
99+
template <bool withDmesMl, typename T1, typename T2>
100+
std::vector<float> getInputFeatures(T1 const& candidate,
101+
T2 const& prong1)
102+
{
103+
std::vector<float> inputFeatures;
104+
105+
for (const auto& idx : MlResponse<TypeOutputScore>::mCachedIndices) {
106+
if constexpr (withDmesMl) {
107+
switch (idx) {
108+
CHECK_AND_FILL_VEC_BPLUS(ptProng0);
109+
CHECK_AND_FILL_VEC_BPLUS(ptProng1);
110+
CHECK_AND_FILL_VEC_BPLUS(impactParameter0);
111+
CHECK_AND_FILL_VEC_BPLUS(impactParameter1);
112+
CHECK_AND_FILL_VEC_BPLUS(impactParameterProduct);
113+
CHECK_AND_FILL_VEC_BPLUS(chi2PCA);
114+
CHECK_AND_FILL_VEC_BPLUS(decayLength);
115+
CHECK_AND_FILL_VEC_BPLUS(decayLengthXY);
116+
CHECK_AND_FILL_VEC_BPLUS(decayLengthNormalised);
117+
CHECK_AND_FILL_VEC_BPLUS(decayLengthXYNormalised);
118+
CHECK_AND_FILL_VEC_BPLUS(cpa);
119+
CHECK_AND_FILL_VEC_BPLUS(cpaXY);
120+
CHECK_AND_FILL_VEC_BPLUS(maxNormalisedDeltaIP);
121+
CHECK_AND_FILL_VEC_BPLUS(prong0MlScoreBkg);
122+
CHECK_AND_FILL_VEC_BPLUS(prong0MlScorePrompt);
123+
CHECK_AND_FILL_VEC_BPLUS(prong0MlScoreNonprompt);
124+
// TPC PID variable
125+
CHECK_AND_FILL_VEC_BPLUS_FULL(prong1, tpcNSigmaPi1, tpcNSigmaPi);
126+
// TOF PID variable
127+
CHECK_AND_FILL_VEC_BPLUS_FULL(prong1, tofNSigmaPi1, tofNSigmaPi);
128+
// Combined PID variables
129+
CHECK_AND_FILL_VEC_BPLUS_FUNC(prong1, tpcTofNSigmaPi1, o2::pid_tpc_tof_utils::getTpcTofNSigmaPi1);
130+
}
131+
} else {
132+
switch (idx) {
133+
CHECK_AND_FILL_VEC_BPLUS(ptProng0);
134+
CHECK_AND_FILL_VEC_BPLUS(ptProng1);
135+
CHECK_AND_FILL_VEC_BPLUS(impactParameter0);
136+
CHECK_AND_FILL_VEC_BPLUS(impactParameter1);
137+
CHECK_AND_FILL_VEC_BPLUS(impactParameterProduct);
138+
CHECK_AND_FILL_VEC_BPLUS(chi2PCA);
139+
CHECK_AND_FILL_VEC_BPLUS(decayLength);
140+
CHECK_AND_FILL_VEC_BPLUS(decayLengthXY);
141+
CHECK_AND_FILL_VEC_BPLUS(decayLengthNormalised);
142+
CHECK_AND_FILL_VEC_BPLUS(decayLengthXYNormalised);
143+
CHECK_AND_FILL_VEC_BPLUS(cpa);
144+
CHECK_AND_FILL_VEC_BPLUS(cpaXY);
145+
CHECK_AND_FILL_VEC_BPLUS(maxNormalisedDeltaIP);
146+
// TPC PID variable
147+
CHECK_AND_FILL_VEC_BPLUS_FULL(prong1, tpcNSigmaPi1, tpcNSigmaPi);
148+
// TOF PID variable
149+
CHECK_AND_FILL_VEC_BPLUS_FULL(prong1, tofNSigmaPi1, tofNSigmaPi);
150+
// Combined PID variables
151+
CHECK_AND_FILL_VEC_BPLUS_FUNC(prong1, tpcTofNSigmaPi1, o2::pid_tpc_tof_utils::getTpcTofNSigmaPi1);
152+
}
153+
}
154+
}
155+
156+
return inputFeatures;
157+
}
158+
159+
protected:
160+
/// Method to fill the map of available input features
161+
void setAvailableInputFeatures()
162+
{
163+
MlResponse<TypeOutputScore>::mAvailableInputFeatures = {
164+
FILL_MAP_BPLUS(ptProng0),
165+
FILL_MAP_BPLUS(ptProng1),
166+
FILL_MAP_BPLUS(impactParameter0),
167+
FILL_MAP_BPLUS(impactParameter1),
168+
FILL_MAP_BPLUS(impactParameterProduct),
169+
FILL_MAP_BPLUS(chi2PCA),
170+
FILL_MAP_BPLUS(decayLength),
171+
FILL_MAP_BPLUS(decayLengthXY),
172+
FILL_MAP_BPLUS(decayLengthNormalised),
173+
FILL_MAP_BPLUS(decayLengthXYNormalised),
174+
FILL_MAP_BPLUS(cpa),
175+
FILL_MAP_BPLUS(cpaXY),
176+
FILL_MAP_BPLUS(maxNormalisedDeltaIP),
177+
FILL_MAP_BPLUS(prong0MlScoreBkg),
178+
FILL_MAP_BPLUS(prong0MlScorePrompt),
179+
FILL_MAP_BPLUS(prong0MlScoreNonprompt),
180+
// TPC PID variable
181+
FILL_MAP_BPLUS(tpcNSigmaPi1),
182+
// TOF PID variable
183+
FILL_MAP_BPLUS(tofNSigmaPi1),
184+
// Combined PID variable
185+
FILL_MAP_BPLUS(tpcTofNSigmaPi1)};
186+
}
187+
};
188+
189+
} // namespace o2::analysis
190+
191+
#undef FILL_MAP_BPLUS
192+
#undef CHECK_AND_FILL_VEC_BPLUS_FULL
193+
#undef CHECK_AND_FILL_VEC_BPLUS_FUNC
194+
#undef CHECK_AND_FILL_VEC_BPLUS
195+
196+
#endif // PWGHF_CORE_HFMLRESPONSEBPLUSTOD0PIREDUCED_H_

PWGHF/D2H/TableProducer/candidateSelectorB0ToDPiReduced.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ struct HfCandidateSelectorB0ToDPiReduced {
173173
}
174174

175175
if constexpr (withDmesMl) { // we include it in the topological selections
176-
if (!hfHelper.selectionDmesMlScoresForB(hfCandB0, cutsDmesMl, binsPtDmesMl)) {
176+
if (!hfHelper.selectionDmesMlScoresForBRed(hfCandB0, cutsDmesMl, binsPtDmesMl)) {
177177
hfSelB0ToDPiCandidate(statusB0ToDPi);
178178
if (applyB0Ml) {
179179
hfMlB0ToDPiCandidate(outputMlNotPreselected);

PWGHF/D2H/TableProducer/candidateSelectorBplusToD0PiReduced.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "Common/Core/TrackSelectorPID.h"
2424

2525
#include "PWGHF/Core/HfHelper.h"
26-
#include "PWGHF/Core/HfMlResponseBplusToD0Pi.h"
26+
#include "PWGHF/Core/HfMlResponseBplusToD0PiReduced.h"
2727
#include "PWGHF/Core/SelectorCuts.h"
2828
#include "PWGHF/DataModel/CandidateReconstructionTables.h"
2929
#include "PWGHF/DataModel/CandidateSelectionTables.h"
@@ -78,7 +78,7 @@ struct HfCandidateSelectorBplusToD0PiReduced {
7878
int mySelectionFlagD0 = -1;
7979
int mySelectionFlagD0bar = -1;
8080

81-
o2::analysis::HfMlResponseBplusToD0Pi<float> hfMlResponse;
81+
o2::analysis::HfMlResponseBplusToD0PiReduced<float> hfMlResponse;
8282
float outputMlNotPreselected = -1.;
8383
std::vector<float> outputMl = {};
8484
o2::ccdb::CcdbApi ccdbApi;
@@ -174,7 +174,7 @@ struct HfCandidateSelectorBplusToD0PiReduced {
174174
}
175175

176176
if constexpr (withDmesMl) { // we include it in the topological selections
177-
if (!hfHelper.selectionDmesMlScoresForB(hfCandBp, cutsDmesMl, binsPtDmesMl)) {
177+
if (!hfHelper.selectionDmesMlScoresForBRed(hfCandBp, cutsDmesMl, binsPtDmesMl)) {
178178
hfSelBplusToD0PiCandidate(statusBplus);
179179
if (applyBplusMl) {
180180
hfMlBplusToD0PiCandidate(outputMlNotPreselected);

PWGHF/D2H/TableProducer/candidateSelectorBsToDsPiReduced.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ struct HfCandidateSelectorBsToDsPiReduced {
164164
}
165165

166166
if constexpr (withDmesMl) { // we include it in the topological selections
167-
if (!hfHelper.selectionDmesMlScoresForB(hfCandBs, cutsDmesMl, binsPtDmesMl)) {
167+
if (!hfHelper.selectionDmesMlScoresForBRed(hfCandBs, cutsDmesMl, binsPtDmesMl)) {
168168
hfSelBsToDsPiCandidate(statusBsToDsPi);
169169
if (applyBsMl) {
170170
hfMlBsToDsPiCandidate(outputMl);

PWGHF/DataModel/CandidateSelectionTables.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ DECLARE_SOA_COLUMN(IsRecoCand, isRecoCand, int); //!
4444
DECLARE_SOA_COLUMN(IsRecoPid, isRecoPid, int);
4545
DECLARE_SOA_COLUMN(MlProbD0, mlProbD0, std::vector<float>); //!
4646
DECLARE_SOA_COLUMN(MlProbD0bar, mlProbD0bar, std::vector<float>); //!
47+
4748
} // namespace hf_sel_candidate_d0
4849

4950
DECLARE_SOA_TABLE(HfSelD0, "AOD", "HFSELD0", //!

0 commit comments

Comments
 (0)