Skip to content

Commit ed6f45e

Browse files
zhangbiao-phyalibuildfgrosavkucera
authored
[PWGHF] Add Lb reduced workflow into the framework (#10978)
Co-authored-by: ALICE Action Bot <alibuild@cern.ch> Co-authored-by: Fabrizio <fabrizio.grosa@cern.ch> Co-authored-by: Vít Kučera <vit.kucera@cern.ch>
1 parent 590935c commit ed6f45e

12 files changed

+2384
-111
lines changed

PWGHF/Core/HfHelper.h

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,87 @@ class HfHelper
958958
return true;
959959
}
960960

961+
/// Apply topological cuts as defined in SelectorCuts.h
962+
/// \param candLb Lb candidate
963+
/// \param cuts Lb candidate selection per pT bin"
964+
/// \param binsPt pT bin limits
965+
/// \return true if candidate passes all selections
966+
template <typename T1, typename T2, typename T3>
967+
bool selectionLbToLcPiTopol(const T1& candLb, const T2& cuts, const T3& binsPt)
968+
{
969+
auto ptCandLb = candLb.pt();
970+
auto ptLc = candLb.ptProng0();
971+
auto ptPi = candLb.ptProng1();
972+
973+
int pTBin = o2::analysis::findBin(binsPt, ptCandLb);
974+
if (pTBin == -1) {
975+
return false;
976+
}
977+
978+
// Lb mass cut
979+
if (std::abs(invMassLbToLcPi(candLb) - o2::constants::physics::MassLambdaB0) > cuts->get(pTBin, "m")) {
980+
return false;
981+
}
982+
983+
// pion pt
984+
if (ptPi < cuts->get(pTBin, "pT Pi")) {
985+
return false;
986+
}
987+
988+
// Lc pt
989+
if (ptLc < cuts->get(pTBin, "pT Lc")) {
990+
return false;
991+
}
992+
993+
// Lb Decay length
994+
if (candLb.decayLength() < cuts->get(pTBin, "Lb decLen")) {
995+
return false;
996+
}
997+
998+
// Lb Decay length XY
999+
if (candLb.decayLengthXY() < cuts->get(pTBin, "Lb decLenXY")) {
1000+
return false;
1001+
}
1002+
1003+
// Lb chi2PCA cut
1004+
if (candLb.chi2PCA() > cuts->get(pTBin, "Chi2PCA")) {
1005+
return false;
1006+
}
1007+
1008+
// Lb CPA cut
1009+
if (candLb.cpa() < cuts->get(pTBin, "CPA")) {
1010+
return false;
1011+
}
1012+
1013+
// d0 of pi
1014+
if (std::abs(candLb.impactParameter1()) < cuts->get(pTBin, "d0 Pi")) {
1015+
return false;
1016+
}
1017+
1018+
// d0 of Lc
1019+
if (std::abs(candLb.impactParameter0()) < cuts->get(pTBin, "d0 Lc")) {
1020+
return false;
1021+
}
1022+
1023+
return true;
1024+
}
1025+
1026+
/// \param pidTrackPi PID status of trackPi (prong1 of Lb candidate)
1027+
/// \param acceptPIDNotApplicable switch to accept Status::NotApplicable
1028+
/// \return true if prong1 of Lb candidate passes all selections
1029+
template <typename T1 = int, typename T2 = bool>
1030+
bool selectionLbToLcPiPid(const T1& pidTrackPi, const T2& acceptPIDNotApplicable)
1031+
{
1032+
if (!acceptPIDNotApplicable && pidTrackPi != TrackSelectorPID::Accepted) {
1033+
return false;
1034+
}
1035+
if (acceptPIDNotApplicable && pidTrackPi == TrackSelectorPID::Rejected) {
1036+
return false;
1037+
}
1038+
1039+
return true;
1040+
}
1041+
9611042
/// Apply selection on ML scores for charm-hadron daughter in b-hadron decays (common for all the beauty channels)
9621043
/// \param cuts ML score selection per bin of charm-hadron pT
9631044
/// \param binsPtC pT bin limits of charm hadron

PWGHF/Core/HfMlResponseLbToLcPi.h

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
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 HfMlResponseLbToLcPi.h
13+
/// \brief Class to compute the ML response for Lb → Lc∓ π± analysis selections
14+
/// \author Biao Zhang <biao.zhang@cern.ch>, Heidelberg University
15+
16+
#ifndef PWGHF_CORE_HFMLRESPONSELBTOLCPI_H_
17+
#define PWGHF_CORE_HFMLRESPONSELBTOLCPI_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_LB(FEATURE) \
30+
{ \
31+
#FEATURE, static_cast<uint8_t>(InputFeaturesLbToLcPi::FEATURE) \
32+
}
33+
34+
// Check if the index of mCachedIndices (index associated to a FEATURE)
35+
// matches the entry in EnumInputFeatures associated to this FEATURE
36+
// if so, the inputFeatures vector is filled with the FEATURE's value
37+
// by calling the corresponding GETTER from OBJECT
38+
#define CHECK_AND_FILL_VEC_LB_FULL(OBJECT, FEATURE, GETTER) \
39+
case static_cast<uint8_t>(InputFeaturesLbToLcPi::FEATURE): { \
40+
inputFeatures.emplace_back(OBJECT.GETTER()); \
41+
break; \
42+
}
43+
44+
// Check if the index of mCachedIndices (index associated to a FEATURE)
45+
// matches the entry in EnumInputFeatures associated to this FEATURE
46+
// if so, the inputFeatures vector is filled with the FEATURE's value
47+
// by calling the GETTER function taking OBJECT in argument
48+
#define CHECK_AND_FILL_VEC_LB_FUNC(OBJECT, FEATURE, GETTER) \
49+
case static_cast<uint8_t>(InputFeaturesLbToLcPi::FEATURE): { \
50+
inputFeatures.emplace_back(GETTER(OBJECT)); \
51+
break; \
52+
}
53+
54+
// Specific case of (OBJECT, FEATURE, GETTER)
55+
// where OBJECT is named candidate and FEATURE = GETTER
56+
#define CHECK_AND_FILL_VEC_LB(GETTER) \
57+
case static_cast<uint8_t>(InputFeaturesLbToLcPi::GETTER): { \
58+
inputFeatures.emplace_back(candidate.GETTER()); \
59+
break; \
60+
}
61+
62+
namespace o2::analysis
63+
{
64+
65+
enum class InputFeaturesLbToLcPi : uint8_t {
66+
ptProng0 = 0,
67+
ptProng1,
68+
impactParameter0,
69+
impactParameter1,
70+
impactParameterProduct,
71+
chi2PCA,
72+
decayLength,
73+
decayLengthXY,
74+
decayLengthNormalised,
75+
decayLengthXYNormalised,
76+
cpa,
77+
cpaXY,
78+
maxNormalisedDeltaIP,
79+
prong0MlScoreBkg,
80+
prong0MlScorePrompt,
81+
prong0MlScoreNonprompt,
82+
tpcNSigmaPi1,
83+
tofNSigmaPi1,
84+
tpcTofNSigmaPi1
85+
};
86+
87+
template <typename TypeOutputScore = float>
88+
class HfMlResponseLbToLcPi : public HfMlResponse<TypeOutputScore>
89+
{
90+
public:
91+
/// Default constructor
92+
HfMlResponseLbToLcPi() = default;
93+
/// Default destructor
94+
virtual ~HfMlResponseLbToLcPi() = default;
95+
96+
/// Method to get the input features vector needed for ML inference
97+
/// \param candidate is the Lb candidate
98+
/// \param prong1 is the candidate's prong1
99+
/// \return inputFeatures vector
100+
template <bool withDmesMl, typename T1, typename T2>
101+
std::vector<float> getInputFeatures(T1 const& candidate,
102+
T2 const& prong1)
103+
{
104+
std::vector<float> inputFeatures;
105+
106+
for (const auto& idx : MlResponse<TypeOutputScore>::mCachedIndices) {
107+
if constexpr (withDmesMl) {
108+
switch (idx) {
109+
CHECK_AND_FILL_VEC_LB(ptProng0);
110+
CHECK_AND_FILL_VEC_LB(ptProng1);
111+
CHECK_AND_FILL_VEC_LB(impactParameter0);
112+
CHECK_AND_FILL_VEC_LB(impactParameter1);
113+
CHECK_AND_FILL_VEC_LB(impactParameterProduct);
114+
CHECK_AND_FILL_VEC_LB(chi2PCA);
115+
CHECK_AND_FILL_VEC_LB(decayLength);
116+
CHECK_AND_FILL_VEC_LB(decayLengthXY);
117+
CHECK_AND_FILL_VEC_LB(decayLengthNormalised);
118+
CHECK_AND_FILL_VEC_LB(decayLengthXYNormalised);
119+
CHECK_AND_FILL_VEC_LB(cpa);
120+
CHECK_AND_FILL_VEC_LB(cpaXY);
121+
CHECK_AND_FILL_VEC_LB(maxNormalisedDeltaIP);
122+
CHECK_AND_FILL_VEC_LB(prong0MlScoreBkg);
123+
CHECK_AND_FILL_VEC_LB(prong0MlScorePrompt);
124+
CHECK_AND_FILL_VEC_LB(prong0MlScoreNonprompt);
125+
// TPC PID variable
126+
CHECK_AND_FILL_VEC_LB_FULL(prong1, tpcNSigmaPi1, tpcNSigmaPi);
127+
// TOF PID variable
128+
CHECK_AND_FILL_VEC_LB_FULL(prong1, tofNSigmaPi1, tofNSigmaPi);
129+
// Combined PID variables
130+
CHECK_AND_FILL_VEC_LB_FUNC(prong1, tpcTofNSigmaPi1, o2::pid_tpc_tof_utils::getTpcTofNSigmaPi1);
131+
}
132+
} else {
133+
switch (idx) {
134+
CHECK_AND_FILL_VEC_LB(ptProng0);
135+
CHECK_AND_FILL_VEC_LB(ptProng1);
136+
CHECK_AND_FILL_VEC_LB(impactParameter0);
137+
CHECK_AND_FILL_VEC_LB(impactParameter1);
138+
CHECK_AND_FILL_VEC_LB(impactParameterProduct);
139+
CHECK_AND_FILL_VEC_LB(chi2PCA);
140+
CHECK_AND_FILL_VEC_LB(decayLength);
141+
CHECK_AND_FILL_VEC_LB(decayLengthXY);
142+
CHECK_AND_FILL_VEC_LB(decayLengthNormalised);
143+
CHECK_AND_FILL_VEC_LB(decayLengthXYNormalised);
144+
CHECK_AND_FILL_VEC_LB(cpa);
145+
CHECK_AND_FILL_VEC_LB(cpaXY);
146+
CHECK_AND_FILL_VEC_LB(maxNormalisedDeltaIP);
147+
// TPC PID variable
148+
CHECK_AND_FILL_VEC_LB_FULL(prong1, tpcNSigmaPi1, tpcNSigmaPi);
149+
// TOF PID variable
150+
CHECK_AND_FILL_VEC_LB_FULL(prong1, tofNSigmaPi1, tofNSigmaPi);
151+
// Combined PID variables
152+
CHECK_AND_FILL_VEC_LB_FUNC(prong1, tpcTofNSigmaPi1, o2::pid_tpc_tof_utils::getTpcTofNSigmaPi1);
153+
}
154+
}
155+
}
156+
157+
return inputFeatures;
158+
}
159+
160+
protected:
161+
/// Method to fill the map of available input features
162+
void setAvailableInputFeatures()
163+
{
164+
MlResponse<TypeOutputScore>::mAvailableInputFeatures = {
165+
FILL_MAP_LB(ptProng0),
166+
FILL_MAP_LB(ptProng1),
167+
FILL_MAP_LB(impactParameter0),
168+
FILL_MAP_LB(impactParameter1),
169+
FILL_MAP_LB(impactParameterProduct),
170+
FILL_MAP_LB(chi2PCA),
171+
FILL_MAP_LB(decayLength),
172+
FILL_MAP_LB(decayLengthXY),
173+
FILL_MAP_LB(decayLengthNormalised),
174+
FILL_MAP_LB(decayLengthXYNormalised),
175+
FILL_MAP_LB(cpa),
176+
FILL_MAP_LB(cpaXY),
177+
FILL_MAP_LB(maxNormalisedDeltaIP),
178+
FILL_MAP_LB(prong0MlScoreBkg),
179+
FILL_MAP_LB(prong0MlScorePrompt),
180+
FILL_MAP_LB(prong0MlScoreNonprompt),
181+
// TPC PID variable
182+
FILL_MAP_LB(tpcNSigmaPi1),
183+
// TOF PID variable
184+
FILL_MAP_LB(tofNSigmaPi1),
185+
// Combined PID variable
186+
FILL_MAP_LB(tpcTofNSigmaPi1)};
187+
}
188+
};
189+
190+
} // namespace o2::analysis
191+
192+
#undef FILL_MAP_LB
193+
#undef CHECK_AND_FILL_VEC_LB_FULL
194+
#undef CHECK_AND_FILL_VEC_LB_FUNC
195+
#undef CHECK_AND_FILL_VEC_LB
196+
197+
#endif // PWGHF_CORE_HFMLRESPONSELBTOLCPI_H_

0 commit comments

Comments
 (0)