Skip to content

Commit

Permalink
PWGHF: Add Bs candidate creator, selector, and task for reduced data …
Browse files Browse the repository at this point in the history
…format (AliceO2Group#7990)

* Add Bs reduced candidate creator

* Add Bs selector and HfMlResponse class for reduced data format

* Please consider the following formatting changes (#8)

* Add Bs task for reduced data model

* Fix typo

* Add check for MC process functions

* Update PWGHF/D2H/Utils/utilsRedDataFormat.h

Co-authored-by: Vít Kučera <[email protected]>

* Update PWGHF/D2H/Utils/utilsRedDataFormat.h

Co-authored-by: Vít Kučera <[email protected]>

* Update PWGHF/D2H/Utils/utilsRedDataFormat.h

Co-authored-by: Vít Kučera <[email protected]>

---------

Co-authored-by: ALICE Builder <[email protected]>
Co-authored-by: Vít Kučera <[email protected]>
  • Loading branch information
3 people authored Oct 16, 2024
1 parent 4085de2 commit fa44f24
Show file tree
Hide file tree
Showing 16 changed files with 1,606 additions and 60 deletions.
26 changes: 1 addition & 25 deletions PWGHF/Core/HfMlResponseB0ToDPi.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <vector>

#include "PWGHF/Core/HfMlResponse.h"
#include "PWGHF/D2H/Utils/utilsRedDataFormat.h"

// Fill the map of available input features
// the key is the feature's name (std::string)
Expand Down Expand Up @@ -58,31 +59,6 @@
break; \
}

namespace o2::pid_tpc_tof_utils
{
template <typename T1>
float getTpcTofNSigmaPi1(const T1& prong1)
{
float defaultNSigma = -999.f; // -999.f is the default value set in TPCPIDResponse.h and PIDTOF.h

bool hasTpc = prong1.hasTPC();
bool hasTof = prong1.hasTOF();

if (hasTpc && hasTof) {
float tpcNSigma = prong1.tpcNSigmaPi();
float tofNSigma = prong1.tofNSigmaPi();
return sqrt(.5f * tpcNSigma * tpcNSigma + .5f * tofNSigma * tofNSigma);
}
if (hasTpc) {
return abs(prong1.tpcNSigmaPi());
}
if (hasTof) {
return abs(prong1.tofNSigmaPi());
}
return defaultNSigma;
}
} // namespace o2::pid_tpc_tof_utils

namespace o2::analysis
{

Expand Down
26 changes: 1 addition & 25 deletions PWGHF/Core/HfMlResponseBplusToD0Pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <vector>

#include "PWGHF/Core/HfMlResponse.h"
#include "PWGHF/D2H/Utils/utilsRedDataFormat.h"

// Fill the map of available input features
// the key is the feature's name (std::string)
Expand Down Expand Up @@ -58,31 +59,6 @@
break; \
}

namespace o2::pid_tpc_tof_utils
{
template <typename T1>
float getTpcTofNSigmaPi1(const T1& prong1)
{
float defaultNSigma = -999.f; // -999.f is the default value set in TPCPIDResponse.h and PIDTOF.h

bool hasTpc = prong1.hasTPC();
bool hasTof = prong1.hasTOF();

if (hasTpc && hasTof) {
float tpcNSigma = prong1.tpcNSigmaPi();
float tofNSigma = prong1.tofNSigmaPi();
return sqrt(.5f * tpcNSigma * tpcNSigma + .5f * tofNSigma * tofNSigma);
}
if (hasTpc) {
return abs(prong1.tpcNSigmaPi());
}
if (hasTof) {
return abs(prong1.tofNSigmaPi());
}
return defaultNSigma;
}
} // namespace o2::pid_tpc_tof_utils

namespace o2::analysis
{

Expand Down
191 changes: 191 additions & 0 deletions PWGHF/Core/HfMlResponseBsToDsPi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// \file HfMlResponsBsToDsPi.h
/// \brief Class to compute the ML response for Bs → Ds∓ π± analysis selections
/// \author Fabio Catalano <[email protected]>, CERN

#ifndef PWGHF_CORE_HFMLRESPONSEBSTODSPI_H_
#define PWGHF_CORE_HFMLRESPONSEBSTODSPI_H_

#include <map>
#include <string>
#include <vector>

#include "PWGHF/Core/HfMlResponse.h"
#include "PWGHF/D2H/Utils/utilsRedDataFormat.h"

// Fill the map of available input features
// the key is the feature's name (std::string)
// the value is the corresponding value in EnumInputFeatures
#define FILL_MAP_BS(FEATURE) \
{ \
#FEATURE, static_cast<uint8_t>(InputFeaturesBsToDsPi::FEATURE) \
}

// Check if the index of mCachedIndices (index associated to a FEATURE)
// matches the entry in EnumInputFeatures associated to this FEATURE
// if so, the inputFeatures vector is filled with the FEATURE's value
// by calling the corresponding GETTER from OBJECT
#define CHECK_AND_FILL_VEC_BS_FULL(OBJECT, FEATURE, GETTER) \
case static_cast<uint8_t>(InputFeaturesBsToDsPi::FEATURE): { \
inputFeatures.emplace_back(OBJECT.GETTER()); \
break; \
}

// Check if the index of mCachedIndices (index associated to a FEATURE)
// matches the entry in EnumInputFeatures associated to this FEATURE
// if so, the inputFeatures vector is filled with the FEATURE's value
// by calling the GETTER function taking OBJECT in argument
#define CHECK_AND_FILL_VEC_BS_FUNC(OBJECT, FEATURE, GETTER) \
case static_cast<uint8_t>(InputFeaturesBsToDsPi::FEATURE): { \
inputFeatures.emplace_back(GETTER(OBJECT)); \
break; \
}

// Specific case of CHECK_AND_FILL_VEC_BS_FULL(OBJECT, FEATURE, GETTER)
// where OBJECT is named candidate and FEATURE = GETTER
#define CHECK_AND_FILL_VEC_BS(GETTER) \
case static_cast<uint8_t>(InputFeaturesBsToDsPi::GETTER): { \
inputFeatures.emplace_back(candidate.GETTER()); \
break; \
}

namespace o2::analysis
{

enum class InputFeaturesBsToDsPi : uint8_t {
ptProng0 = 0,
ptProng1,
impactParameter0,
impactParameter1,
impactParameterProduct,
chi2PCA,
decayLength,
decayLengthXY,
decayLengthNormalised,
decayLengthXYNormalised,
cpa,
cpaXY,
maxNormalisedDeltaIP,
prong0MlScoreBkg,
prong0MlScorePrompt,
prong0MlScoreNonprompt,
tpcNSigmaPi1,
tofNSigmaPi1,
tpcTofNSigmaPi1
};

template <typename TypeOutputScore = float>
class HfMlResponseBsToDsPi : public HfMlResponse<TypeOutputScore>
{
public:
/// Default constructor
HfMlResponseBsToDsPi() = default;
/// Default destructor
virtual ~HfMlResponseBsToDsPi() = default;

/// Method to get the input features vector needed for ML inference
/// \param candidate is the Bs candidate
/// \param prong1 is the candidate's prong1
/// \return inputFeatures vector
template <bool withDmesMl, typename T1, typename T2>
std::vector<float> getInputFeatures(T1 const& candidate,
T2 const& prong1)
{
std::vector<float> inputFeatures;

for (const auto& idx : MlResponse<TypeOutputScore>::mCachedIndices) {
if constexpr (withDmesMl) {
switch (idx) {
CHECK_AND_FILL_VEC_BS(ptProng0);
CHECK_AND_FILL_VEC_BS(ptProng1);
CHECK_AND_FILL_VEC_BS(impactParameter0);
CHECK_AND_FILL_VEC_BS(impactParameter1);
CHECK_AND_FILL_VEC_BS(impactParameterProduct);
CHECK_AND_FILL_VEC_BS(chi2PCA);
CHECK_AND_FILL_VEC_BS(decayLength);
CHECK_AND_FILL_VEC_BS(decayLengthXY);
CHECK_AND_FILL_VEC_BS(decayLengthNormalised);
CHECK_AND_FILL_VEC_BS(decayLengthXYNormalised);
CHECK_AND_FILL_VEC_BS(cpa);
CHECK_AND_FILL_VEC_BS(cpaXY);
CHECK_AND_FILL_VEC_BS(maxNormalisedDeltaIP);
CHECK_AND_FILL_VEC_BS(prong0MlScoreBkg);
CHECK_AND_FILL_VEC_BS(prong0MlScorePrompt);
CHECK_AND_FILL_VEC_BS(prong0MlScoreNonprompt);
// Pion PID variables
CHECK_AND_FILL_VEC_BS_FULL(prong1, tpcNSigmaPi1, tpcNSigmaPi);
CHECK_AND_FILL_VEC_BS_FULL(prong1, tofNSigmaPi1, tofNSigmaPi);
CHECK_AND_FILL_VEC_BS_FUNC(prong1, tpcTofNSigmaPi1, o2::pid_tpc_tof_utils::getTpcTofNSigmaPi1);
}
} else {
switch (idx) {
CHECK_AND_FILL_VEC_BS(ptProng0);
CHECK_AND_FILL_VEC_BS(ptProng1);
CHECK_AND_FILL_VEC_BS(impactParameter0);
CHECK_AND_FILL_VEC_BS(impactParameter1);
CHECK_AND_FILL_VEC_BS(impactParameterProduct);
CHECK_AND_FILL_VEC_BS(chi2PCA);
CHECK_AND_FILL_VEC_BS(decayLength);
CHECK_AND_FILL_VEC_BS(decayLengthXY);
CHECK_AND_FILL_VEC_BS(decayLengthNormalised);
CHECK_AND_FILL_VEC_BS(decayLengthXYNormalised);
CHECK_AND_FILL_VEC_BS(cpa);
CHECK_AND_FILL_VEC_BS(cpaXY);
CHECK_AND_FILL_VEC_BS(maxNormalisedDeltaIP);
// Pion PID variables
CHECK_AND_FILL_VEC_BS_FULL(prong1, tpcNSigmaPi1, tpcNSigmaPi);
CHECK_AND_FILL_VEC_BS_FULL(prong1, tofNSigmaPi1, tofNSigmaPi);
CHECK_AND_FILL_VEC_BS_FUNC(prong1, tpcTofNSigmaPi1, o2::pid_tpc_tof_utils::getTpcTofNSigmaPi1);
}
}
}

return inputFeatures;
}

protected:
/// Method to fill the map of available input features
void setAvailableInputFeatures()
{
MlResponse<TypeOutputScore>::mAvailableInputFeatures = {
FILL_MAP_BS(ptProng0),
FILL_MAP_BS(ptProng1),
FILL_MAP_BS(impactParameter0),
FILL_MAP_BS(impactParameter1),
FILL_MAP_BS(impactParameterProduct),
FILL_MAP_BS(chi2PCA),
FILL_MAP_BS(decayLength),
FILL_MAP_BS(decayLengthXY),
FILL_MAP_BS(decayLengthNormalised),
FILL_MAP_BS(decayLengthXYNormalised),
FILL_MAP_BS(cpa),
FILL_MAP_BS(cpaXY),
FILL_MAP_BS(maxNormalisedDeltaIP),
FILL_MAP_BS(prong0MlScoreBkg),
FILL_MAP_BS(prong0MlScorePrompt),
FILL_MAP_BS(prong0MlScoreNonprompt),
// Pion PID variables
FILL_MAP_BS(tpcNSigmaPi1),
FILL_MAP_BS(tofNSigmaPi1),
FILL_MAP_BS(tpcTofNSigmaPi1)};
}
};

} // namespace o2::analysis

#undef FILL_MAP_BS
#undef CHECK_AND_FILL_VEC_BS_FULL
#undef CHECK_AND_FILL_VEC_BS_FUNC
#undef CHECK_AND_FILL_VEC_BS

#endif // PWGHF_CORE_HFMLRESPONSEBSTODSPI_H_
33 changes: 29 additions & 4 deletions PWGHF/Core/SelectorCuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -903,25 +903,50 @@ static const std::vector<std::string> labelsCutVar = {"m", "CPA", "Chi2PCA", "d0

namespace hf_cuts_bs_to_ds_pi
{
static constexpr int nBinsPt = 2;
static constexpr int nBinsPt = 10;
static constexpr int nCutVars = 10;
// default values for the pT bin edges (can be used to configure histogram axis)
// offset by 1 from the bin numbers in cuts array
constexpr double binsPt[nBinsPt + 1] = {
0,
1.0,
2.0};
2.0,
3.0,
4.0,
5.0,
8.0,
10.0,
12.0,
16.0,
24.0};

auto vecBinsPt = std::vector<double>{binsPt, binsPt + nBinsPt + 1};

// default values for the cuts
// DeltaM CPA chi2PCA d0Ds d0Pi pTDs pTPi BsDecayLength BsDecayLengthXY IPProd
constexpr double cuts[nBinsPt][nCutVars] = {{1., 0.8, 1., 0.01, 0.01, 1.0, 0.15, 0.05, 0.05, 0.}, /* 0 < pt < 1 */
{1., 0.8, 1., 0.01, 0.01, 1.0, 0.15, 0.05, 0.05, 0.}}; /* 1 < pt < 2 */
{1., 0.8, 1., 0.01, 0.01, 1.0, 0.15, 0.05, 0.05, 0.}, /* 1 < pt < 2 */
{1., 0.8, 1., 0.01, 0.01, 1.0, 0.15, 0.05, 0.05, 0.}, /* 2 < pt < 3 */
{1., 0.8, 1., 0.01, 0.01, 1.0, 0.15, 0.05, 0.05, 0.}, /* 3 < pt < 4 */
{1., 0.8, 1., 0.01, 0.01, 1.0, 0.15, 0.05, 0.05, 0.}, /* 4 < pt < 5 */
{1., 0.8, 1., 0.01, 0.01, 1.0, 0.15, 0.05, 0.05, 0.}, /* 5 < pt < 6 */
{1., 0.8, 1., 0.01, 0.01, 1.0, 0.15, 0.05, 0.05, 0.}, /* 8 < pt < 10 */
{1., 0.8, 1., 0.01, 0.01, 1.0, 0.15, 0.05, 0.05, 0.}, /* 10 < pt < 12 */
{1., 0.8, 1., 0.01, 0.01, 1.0, 0.15, 0.05, 0.05, 0.}, /* 12 < pt < 16 */
{1., 0.8, 1., 0.01, 0.01, 1.0, 0.15, 0.05, 0.05, 0.}}; /* 16 < pt < 24 */

// row labels
static const std::vector<std::string> labelsPt = {
"pT bin 0",
"pT bin 1"};
"pT bin 1",
"pT bin 2",
"pT bin 3",
"pT bin 4",
"pT bin 5",
"pT bin 6",
"pT bin 7",
"pT bin 8",
"pT bin 9"};

// column labels
static const std::vector<std::string> labelsCutVar = {"m", "CPA", "Chi2PCA", "d0 Ds", "d0 Pi", "pT Ds", "pT Pi", "Bs decLen", "Bs decLenXY", "Imp. Par. Product"};
Expand Down
10 changes: 10 additions & 0 deletions PWGHF/D2H/TableProducer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ o2physics_add_dpl_workflow(candidate-creator-bplus-reduced
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2::DCAFitter
COMPONENT_NAME Analysis)

o2physics_add_dpl_workflow(candidate-creator-bs-reduced
SOURCES candidateCreatorBsReduced.cxx
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2::DCAFitter
COMPONENT_NAME Analysis)

o2physics_add_dpl_workflow(candidate-creator-charm-reso-reduced
SOURCES candidateCreatorCharmResoReduced.cxx
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
Expand All @@ -38,6 +43,11 @@ o2physics_add_dpl_workflow(candidate-selector-bplus-to-d0-pi-reduced
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2Physics::MLCore
COMPONENT_NAME Analysis)

o2physics_add_dpl_workflow(candidate-selector-bs-to-ds-pi-reduced
SOURCES candidateSelectorBsToDsPiReduced.cxx
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2Physics::MLCore
COMPONENT_NAME Analysis)

# Data creators

o2physics_add_dpl_workflow(data-creator-charm-had-pi-reduced
Expand Down
Loading

0 comments on commit fa44f24

Please sign in to comment.