|
| 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 HfMlResponseOmegacToOmegaPi.h |
| 13 | +/// \brief Class to compute the ML response for Ωc± → Ω∓ π± analysis selections |
| 14 | +/// \author Yunfan Liu <yunfan.liu@cern.ch>, China University of Geosciences |
| 15 | + |
| 16 | +#ifndef PWGHF_CORE_HFMLRESPONSEOMEGACTOOMEGAPI_H_ |
| 17 | +#define PWGHF_CORE_HFMLRESPONSEOMEGACTOOMEGAPI_H_ |
| 18 | + |
| 19 | +#include <map> |
| 20 | +#include <string> |
| 21 | +#include <vector> |
| 22 | + |
| 23 | +#include "CommonConstants/PhysicsConstants.h" |
| 24 | + |
| 25 | +#include "PWGHF/Core/HfHelper.h" |
| 26 | +#include "PWGHF/Core/HfMlResponse.h" |
| 27 | + |
| 28 | +// Fill the map of available input features |
| 29 | +// the key is the feature's name (std::string) |
| 30 | +// the value is the corresponding value in EnumInputFeatures |
| 31 | +#define FILL_MAP_OMEGAC0(FEATURE) \ |
| 32 | + { \ |
| 33 | + #FEATURE, static_cast<uint8_t>(InputFeaturesOmegacToOmegaPi::FEATURE) \ |
| 34 | + } |
| 35 | + |
| 36 | +// Check if the index of mCachedIndices (index associated to a FEATURE) |
| 37 | +// matches the entry in EnumInputFeatures associated to this FEATURE |
| 38 | +// if so, the inputFeatures vector is filled with the FEATURE's value |
| 39 | +// by calling the corresponding GETTER from OBJECT |
| 40 | +#define CHECK_AND_FILL_VEC_OMEGAC0_FULL(OBJECT, FEATURE, GETTER) \ |
| 41 | + case static_cast<uint8_t>(InputFeaturesOmegacToOmegaPi::FEATURE): { \ |
| 42 | + inputFeatures.emplace_back(OBJECT.GETTER()); \ |
| 43 | + break; \ |
| 44 | + } |
| 45 | + |
| 46 | +// Specific case of CHECK_AND_FILL_VEC_OMEGAC0_FULL(OBJECT, FEATURE, GETTER) |
| 47 | +// where OBJECT is named candidate and FEATURE = GETTER |
| 48 | +#define CHECK_AND_FILL_VEC_OMEGAC0(GETTER) \ |
| 49 | + case static_cast<uint8_t>(InputFeaturesOmegacToOmegaPi::GETTER): { \ |
| 50 | + inputFeatures.emplace_back(candidate.GETTER()); \ |
| 51 | + break; \ |
| 52 | + } |
| 53 | + |
| 54 | +// Variation of CHECK_AND_FILL_VEC_OMEGAC0_FULL(OBJECT, FEATURE, GETTER) |
| 55 | +// where GETTER is a method of hfHelper |
| 56 | +#define CHECK_AND_FILL_VEC_OMEGAC0_HFHELPER(OBJECT, FEATURE, GETTER) \ |
| 57 | + case static_cast<uint8_t>(InputFeaturesOmegacToOmegaPi::FEATURE): { \ |
| 58 | + inputFeatures.emplace_back(hfHelper.GETTER(OBJECT)); \ |
| 59 | + break; \ |
| 60 | + } |
| 61 | +namespace o2::analysis |
| 62 | +{ |
| 63 | +enum class InputFeaturesOmegacToOmegaPi : uint8_t { |
| 64 | + |
| 65 | + cosPaOmegacToPv = 0, |
| 66 | + kfDcaXYPiFromOmegac, |
| 67 | + cosThetaStarPiFromOmegac, |
| 68 | + chi2TopoPiFromOmegacToPv, |
| 69 | + dcaCharmBaryonDau, |
| 70 | + invMassCascade, |
| 71 | + massCascChi2OverNdf, |
| 72 | + cosPaCascToPv, |
| 73 | + kfDcaXYCascToPv, |
| 74 | + nSigmaTPCPiFromV0, |
| 75 | + nSigmaTPCPiFromOmegac, |
| 76 | + nSigmaTPCKaFromCasc |
| 77 | + |
| 78 | +}; |
| 79 | + |
| 80 | +template <typename TypeOutputScore = float> |
| 81 | +class HfMlResponseOmegacToOmegaPi : public HfMlResponse<TypeOutputScore> |
| 82 | +{ |
| 83 | + public: |
| 84 | + /// Default constructor |
| 85 | + HfMlResponseOmegacToOmegaPi() = default; |
| 86 | + /// Default destructor |
| 87 | + virtual ~HfMlResponseOmegacToOmegaPi() = default; |
| 88 | + |
| 89 | + HfHelper hfHelper; |
| 90 | + |
| 91 | + /// Method to get the input features vector needed for ML inference |
| 92 | + /// \param candidate is the OMEGAC0 candidate |
| 93 | + /// \param lamProngPi is the candidate's lamProngPi |
| 94 | + /// \return inputFeatures vector |
| 95 | + template <typename T1, typename T2, typename T3> |
| 96 | + std::vector<float> getInputFeatures(T1 const& candidate, T2 const& lamProngPi, T2 const& cascProng, T3 const& charmBaryonProng) |
| 97 | + { |
| 98 | + std::vector<float> inputFeatures; |
| 99 | + |
| 100 | + for (const auto& idx : MlResponse<TypeOutputScore>::mCachedIndices) { |
| 101 | + switch (idx) { |
| 102 | + |
| 103 | + CHECK_AND_FILL_VEC_OMEGAC0(kfDcaXYPiFromOmegac); |
| 104 | + CHECK_AND_FILL_VEC_OMEGAC0(cosThetaStarPiFromOmegac); |
| 105 | + CHECK_AND_FILL_VEC_OMEGAC0(chi2TopoPiFromOmegacToPv); |
| 106 | + CHECK_AND_FILL_VEC_OMEGAC0(dcaCharmBaryonDau); |
| 107 | + CHECK_AND_FILL_VEC_OMEGAC0(invMassCascade); |
| 108 | + CHECK_AND_FILL_VEC_OMEGAC0(massCascChi2OverNdf); |
| 109 | + CHECK_AND_FILL_VEC_OMEGAC0(kfDcaXYCascToPv); |
| 110 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(candidate, cosPaOmegacToPv, cosPACharmBaryon); |
| 111 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(candidate, cosPaCascToPv, cosPACasc); |
| 112 | + // TPC PID variables |
| 113 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(lamProngPi, nSigmaTPCPiFromV0, tpcNSigmaPi); |
| 114 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(cascProng, nSigmaTPCKaFromCasc, tpcNSigmaKa); |
| 115 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(charmBaryonProng, nSigmaTPCPiFromOmegac, tpcNSigmaPi); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + return inputFeatures; |
| 120 | + } |
| 121 | + |
| 122 | + protected: |
| 123 | + /// Method to fill the map of available input features |
| 124 | + void setAvailableInputFeatures() |
| 125 | + { |
| 126 | + MlResponse<TypeOutputScore>::mAvailableInputFeatures = { |
| 127 | + |
| 128 | + FILL_MAP_OMEGAC0(invMassCascade), |
| 129 | + FILL_MAP_OMEGAC0(cosPaOmegacToPv), |
| 130 | + FILL_MAP_OMEGAC0(dcaCharmBaryonDau), |
| 131 | + FILL_MAP_OMEGAC0(kfDcaXYPiFromOmegac), |
| 132 | + FILL_MAP_OMEGAC0(cosThetaStarPiFromOmegac), |
| 133 | + FILL_MAP_OMEGAC0(chi2TopoPiFromOmegacToPv), |
| 134 | + FILL_MAP_OMEGAC0(massCascChi2OverNdf), |
| 135 | + FILL_MAP_OMEGAC0(cosPaCascToPv), |
| 136 | + FILL_MAP_OMEGAC0(kfDcaXYCascToPv), |
| 137 | + // TPC PID variables |
| 138 | + FILL_MAP_OMEGAC0(nSigmaTPCPiFromV0), |
| 139 | + FILL_MAP_OMEGAC0(nSigmaTPCKaFromCasc), |
| 140 | + FILL_MAP_OMEGAC0(nSigmaTPCPiFromOmegac), |
| 141 | + |
| 142 | + }; |
| 143 | + } |
| 144 | +}; |
| 145 | + |
| 146 | +} // namespace o2::analysis |
| 147 | + |
| 148 | +#undef FILL_MAP_OMEGAC0 |
| 149 | +#undef CHECK_AND_FILL_VEC_OMEGAC0_FULL |
| 150 | +#undef CHECK_AND_FILL_VEC_OMEGAC0 |
| 151 | +#undef CHECK_AND_FILL_VEC_OMEGAC0_HFHELPER |
| 152 | +#endif // PWGHF_CORE_HFMLRESPONSEOMEGACTOOMEGAPI_H_ |
0 commit comments