|
| 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 HfMlResponseXic0ToXiPi.h |
| 13 | +/// \brief Class to compute the ML response for Ξc^0 → Ξ∓ π± analysis selections |
| 14 | +/// \author Tao Fang <tao.fang@cern.ch>, Central China Normal University |
| 15 | + |
| 16 | +#ifndef PWGHF_CORE_HFMLRESPONSEXIC0TOXIPI_H_ |
| 17 | +#define PWGHF_CORE_HFMLRESPONSEXIC0TOXIPI_H_ |
| 18 | + |
| 19 | +#include "PWGHF/Core/HfMlResponse.h" |
| 20 | + |
| 21 | +#include "Tools/ML/MlResponse.h" |
| 22 | + |
| 23 | +#include <cstdint> |
| 24 | +#include <vector> |
| 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_XIC0TOXIPI(FEATURE) \ |
| 30 | + { \ |
| 31 | + #FEATURE, static_cast<uint8_t>(InputFeaturesXic0ToXiPi::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_XIC0TOXIPI_FULL(OBJECT, FEATURE, GETTER) \ |
| 39 | + case static_cast<uint8_t>(InputFeaturesXic0ToXiPi::FEATURE): { \ |
| 40 | + inputFeatures.emplace_back(OBJECT.GETTER()); \ |
| 41 | + break; \ |
| 42 | + } |
| 43 | + |
| 44 | +// where OBJECT is named candidate and FEATURE = GETTER |
| 45 | +#define CHECK_AND_FILL_VEC_XIC0TOXIPI(GETTER) \ |
| 46 | + case static_cast<uint8_t>(InputFeaturesXic0ToXiPi::GETTER): { \ |
| 47 | + inputFeatures.emplace_back(candidate.GETTER()); \ |
| 48 | + break; \ |
| 49 | + } |
| 50 | + |
| 51 | +namespace o2::analysis |
| 52 | +{ |
| 53 | + |
| 54 | +enum class InputFeaturesXic0ToXiPi : uint8_t { |
| 55 | + tpcNSigmaPiFromLambda, |
| 56 | + tpcNSigmaPiFromCasc, |
| 57 | + tpcNSigmaPiFromCharmBaryon, |
| 58 | + dcaCascDau, |
| 59 | + dcaCharmBaryonDau, |
| 60 | + cosPACharmBaryon, |
| 61 | + cosPACasc, |
| 62 | + cosPAV0, |
| 63 | + impactParBachFromCharmBaryonXY, |
| 64 | + impactParCascXY |
| 65 | +}; |
| 66 | + |
| 67 | +template <typename TypeOutputScore = float> |
| 68 | +class HfMlResponseXic0ToXiPi : public HfMlResponse<TypeOutputScore> |
| 69 | +{ |
| 70 | + public: |
| 71 | + /// Default constructor |
| 72 | + HfMlResponseXic0ToXiPi() = default; |
| 73 | + /// Default destructor |
| 74 | + virtual ~HfMlResponseXic0ToXiPi() = default; |
| 75 | + |
| 76 | + /// Method to get the input features vector needed for ML inference |
| 77 | + /// \param candidate is the Xic0 candidate |
| 78 | + /// \return inputFeatures vector |
| 79 | + template <typename T1, typename T2, typename T3> |
| 80 | + // std::vector<float> getInputFeatures(T1 const& candidate) |
| 81 | + std::vector<float> getInputFeatures(T1 const& candidate, T2 const& lamProngPi, T2 const& cascProngPi, T3 const& charmBaryonProngPi) |
| 82 | + { |
| 83 | + std::vector<float> inputFeatures; |
| 84 | + |
| 85 | + for (const auto& idx : MlResponse<TypeOutputScore>::mCachedIndices) { |
| 86 | + switch (idx) { |
| 87 | + // PID variables |
| 88 | + CHECK_AND_FILL_VEC_XIC0TOXIPI_FULL(lamProngPi, tpcNSigmaPiFromLambda, tpcNSigmaPi); |
| 89 | + CHECK_AND_FILL_VEC_XIC0TOXIPI_FULL(cascProngPi, tpcNSigmaPiFromCasc, tpcNSigmaPi); |
| 90 | + CHECK_AND_FILL_VEC_XIC0TOXIPI_FULL(charmBaryonProngPi, tpcNSigmaPiFromCharmBaryon, tpcNSigmaPi); |
| 91 | + // DCA |
| 92 | + CHECK_AND_FILL_VEC_XIC0TOXIPI(dcaCascDau); |
| 93 | + CHECK_AND_FILL_VEC_XIC0TOXIPI(dcaCharmBaryonDau); |
| 94 | + // CosPA |
| 95 | + CHECK_AND_FILL_VEC_XIC0TOXIPI(cosPACharmBaryon); |
| 96 | + CHECK_AND_FILL_VEC_XIC0TOXIPI(cosPACasc); |
| 97 | + CHECK_AND_FILL_VEC_XIC0TOXIPI(cosPAV0); |
| 98 | + // ImpactPar |
| 99 | + CHECK_AND_FILL_VEC_XIC0TOXIPI(impactParBachFromCharmBaryonXY); |
| 100 | + CHECK_AND_FILL_VEC_XIC0TOXIPI(impactParCascXY); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + return inputFeatures; |
| 105 | + } |
| 106 | + |
| 107 | + protected: |
| 108 | + /// Method to fill the map of available input features |
| 109 | + void setAvailableInputFeatures() |
| 110 | + { |
| 111 | + MlResponse<TypeOutputScore>::mAvailableInputFeatures = { |
| 112 | + FILL_MAP_XIC0TOXIPI(tpcNSigmaPiFromLambda), |
| 113 | + FILL_MAP_XIC0TOXIPI(tpcNSigmaPiFromCasc), |
| 114 | + FILL_MAP_XIC0TOXIPI(tpcNSigmaPiFromCharmBaryon), |
| 115 | + FILL_MAP_XIC0TOXIPI(dcaCascDau), |
| 116 | + FILL_MAP_XIC0TOXIPI(dcaCharmBaryonDau), |
| 117 | + FILL_MAP_XIC0TOXIPI(cosPACharmBaryon), |
| 118 | + FILL_MAP_XIC0TOXIPI(cosPACasc), |
| 119 | + FILL_MAP_XIC0TOXIPI(cosPAV0), |
| 120 | + FILL_MAP_XIC0TOXIPI(impactParBachFromCharmBaryonXY), |
| 121 | + FILL_MAP_XIC0TOXIPI(impactParCascXY)}; |
| 122 | + } |
| 123 | +}; |
| 124 | + |
| 125 | +} // namespace o2::analysis |
| 126 | + |
| 127 | +#undef FILL_MAP_XIC0TOXIPI |
| 128 | +#undef CHECK_AND_FILL_VEC_XIC0TOXIPI_FULL |
| 129 | +#undef CHECK_AND_FILL_VEC_XIC0TOXIPI |
| 130 | + |
| 131 | +#endif // PWGHF_CORE_HFMLRESPONSEXIC0TOXIPI_H_ |
0 commit comments