|
| 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 HfMlResponseOmegacToOmegaPiQa.h |
| 13 | +/// \brief Class to compute the ML response for Ωc0 → Ω- π+ (and charge-conjugate) analysis selections |
| 14 | +/// \author Yunfan Liu <yunfan.liu@cern.ch>, China University of Geosciences |
| 15 | +/// \author Maria Fernanda Torres Cabrera <maria.fernanda.torres.cabrera@cern.ch>, University of Houston |
| 16 | + |
| 17 | +#ifndef PWGHF_CORE_HFMLRESPONSEOMEGACTOOMEGAPIQA_H_ |
| 18 | +#define PWGHF_CORE_HFMLRESPONSEOMEGACTOOMEGAPIQA_H_ |
| 19 | + |
| 20 | +#include "PWGHF/Core/HfMlResponse.h" |
| 21 | +#include "PWGHF/DataModel/CandidateReconstructionTables.h" |
| 22 | + |
| 23 | +#include "Tools/ML/MlResponse.h" |
| 24 | + |
| 25 | +#include <cstdint> |
| 26 | +#include <map> |
| 27 | +#include <string> |
| 28 | +#include <vector> |
| 29 | + |
| 30 | +// Fill the map of available input features |
| 31 | +// the key is the feature's name (std::string) |
| 32 | +// the value is the corresponding value in EnumInputFeatures |
| 33 | +#define FILL_MAP_OMEGAC0(FEATURE) \ |
| 34 | + { \ |
| 35 | + #FEATURE, static_cast<uint8_t>(InputFeaturesOmegacToOmegaPi::FEATURE)} |
| 36 | + |
| 37 | +// Check if the index of mCachedIndices (index associated to a FEATURE) |
| 38 | +// matches the entry in EnumInputFeatures associated to this FEATURE |
| 39 | +// if so, the inputFeatures vector is filled with the FEATURE's value |
| 40 | +// by calling the corresponding GETTER from OBJECT |
| 41 | +#define CHECK_AND_FILL_VEC_OMEGAC0_FULL(OBJECT, FEATURE, GETTER) \ |
| 42 | + case static_cast<uint8_t>(InputFeaturesOmegacToOmegaPi::FEATURE): { \ |
| 43 | + inputFeatures.emplace_back(OBJECT.GETTER()); \ |
| 44 | + break; \ |
| 45 | + } |
| 46 | + |
| 47 | +// Specific case of CHECK_AND_FILL_VEC_OMEGAC0_FULL(OBJECT, FEATURE, GETTER) |
| 48 | +// where OBJECT is named candidate and FEATURE = GETTER |
| 49 | +#define CHECK_AND_FILL_VEC_OMEGAC0(GETTER) \ |
| 50 | + case static_cast<uint8_t>(InputFeaturesOmegacToOmegaPi::GETTER): { \ |
| 51 | + inputFeatures.emplace_back(candidate.GETTER()); \ |
| 52 | + break; \ |
| 53 | + } |
| 54 | + |
| 55 | +namespace o2::analysis |
| 56 | +{ |
| 57 | +enum class InputFeaturesOmegacToOmegaPi : uint8_t { |
| 58 | + |
| 59 | + // Common variables |
| 60 | + dcaCharmBaryonDau = 0, |
| 61 | + dcaCascDau, |
| 62 | + nSigmaTPCPiFromV0, |
| 63 | + nSigmaTPCPiFromOmegac, |
| 64 | + nSigmaTPCKaFromCasc, |
| 65 | + |
| 66 | + // DCAFitter variables |
| 67 | + impactParBachFromCharmBaryonXY, |
| 68 | + impactParBachFromCharmBaryonZ, |
| 69 | + impactParCascXY, |
| 70 | + impactParCascZ, |
| 71 | + cosPACharmBaryon, |
| 72 | + cosPACasc, |
| 73 | + |
| 74 | + // KFParticle variables |
| 75 | + cosPaOmegacToPv, |
| 76 | + kfDcaXYPiFromOmegac, |
| 77 | + chi2TopoPiFromOmegacToPv, |
| 78 | + invMassCascade, |
| 79 | + massCascChi2OverNdf, |
| 80 | + kfDcaXYCascToPv, |
| 81 | + cosPaCascToPv, |
| 82 | + cosThetaStarPiFromOmegac, |
| 83 | + chi2NdfTopoOmegacToPv, |
| 84 | + ldlCasc, |
| 85 | + cosPaCascToOmegac, |
| 86 | + decayLenXYCasc, |
| 87 | + decayLenXYOmegac, |
| 88 | + ldlOmegac, |
| 89 | + chi2NdfTopoCascToOmegac, |
| 90 | + chi2NdfTopoCascToPv, |
| 91 | + chi2GeoOmegac, |
| 92 | + chi2GeoCasc, |
| 93 | +}; |
| 94 | + |
| 95 | +template <typename TypeOutputScore = float, aod::hf_cand_casc_lf::ConstructMethod reconstructionType = aod::hf_cand_casc_lf::ConstructMethod::DcaFitter> |
| 96 | +class HfMlResponseOmegacToOmegaPi : public HfMlResponse<TypeOutputScore> |
| 97 | +{ |
| 98 | + public: |
| 99 | + /// Default constructor |
| 100 | + HfMlResponseOmegacToOmegaPi() = default; |
| 101 | + /// Default destructor |
| 102 | + virtual ~HfMlResponseOmegacToOmegaPi() = default; |
| 103 | + |
| 104 | + /// Method to get the input features vector needed for ML inference |
| 105 | + /// \param candidate is the OMEGAC0 candidate |
| 106 | + /// \param lamProngPi is the candidate's lamProngPi |
| 107 | + /// \param cascProng is the bachelor track from the Omega decay |
| 108 | + /// \param charmBaryonProng is the bachelor pion from the OmegaC decay |
| 109 | + /// \return inputFeatures vector |
| 110 | + template <typename T1, typename T2, typename T3> |
| 111 | + std::vector<float> getInputFeatures(T1 const& candidate, T2 const& lamProngPi, T2 const& cascProng, T3 const& charmBaryonProng) |
| 112 | + { |
| 113 | + std::vector<float> inputFeatures; |
| 114 | + |
| 115 | + for (const auto& idx : MlResponse<TypeOutputScore>::mCachedIndices) { |
| 116 | + |
| 117 | + // Variables common to DCAFitter and KFParticle |
| 118 | + switch (idx) { |
| 119 | + |
| 120 | + CHECK_AND_FILL_VEC_OMEGAC0(dcaCharmBaryonDau); |
| 121 | + CHECK_AND_FILL_VEC_OMEGAC0(dcaCascDau); |
| 122 | + // TPC PID variables |
| 123 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(lamProngPi, nSigmaTPCPiFromV0, tpcNSigmaPi); |
| 124 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(cascProng, nSigmaTPCKaFromCasc, tpcNSigmaKa); |
| 125 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(charmBaryonProng, nSigmaTPCPiFromOmegac, tpcNSigmaPi); |
| 126 | + } |
| 127 | + |
| 128 | + // DCAFitter variables |
| 129 | + if constexpr (reconstructionType == aod::hf_cand_casc_lf::ConstructMethod::DcaFitter) { |
| 130 | + |
| 131 | + switch (idx) { |
| 132 | + |
| 133 | + CHECK_AND_FILL_VEC_OMEGAC0(impactParBachFromCharmBaryonXY); |
| 134 | + CHECK_AND_FILL_VEC_OMEGAC0(impactParBachFromCharmBaryonZ); |
| 135 | + CHECK_AND_FILL_VEC_OMEGAC0(impactParCascXY); |
| 136 | + CHECK_AND_FILL_VEC_OMEGAC0(impactParCascZ); |
| 137 | + CHECK_AND_FILL_VEC_OMEGAC0(cosPACharmBaryon); |
| 138 | + CHECK_AND_FILL_VEC_OMEGAC0(cosPACasc); |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + // KFParticle variables |
| 143 | + if constexpr (reconstructionType == aod::hf_cand_casc_lf::ConstructMethod::KfParticle) { |
| 144 | + |
| 145 | + switch (idx) { |
| 146 | + |
| 147 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(candidate, cosPaOmegacToPv, cosPACharmBaryon); |
| 148 | + CHECK_AND_FILL_VEC_OMEGAC0(kfDcaXYPiFromOmegac); |
| 149 | + CHECK_AND_FILL_VEC_OMEGAC0(chi2TopoPiFromOmegacToPv); |
| 150 | + CHECK_AND_FILL_VEC_OMEGAC0(invMassCascade); |
| 151 | + CHECK_AND_FILL_VEC_OMEGAC0(massCascChi2OverNdf); |
| 152 | + CHECK_AND_FILL_VEC_OMEGAC0(kfDcaXYCascToPv); |
| 153 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(candidate, cosPaCascToPv, cosPACasc); |
| 154 | + CHECK_AND_FILL_VEC_OMEGAC0(cosThetaStarPiFromOmegac); |
| 155 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(candidate, chi2NdfTopoOmegacToPv, chi2TopoOmegacToPv); |
| 156 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(candidate, ldlCasc, cascldl); |
| 157 | + CHECK_AND_FILL_VEC_OMEGAC0(cosPaCascToOmegac); |
| 158 | + CHECK_AND_FILL_VEC_OMEGAC0(decayLenXYCasc); |
| 159 | + CHECK_AND_FILL_VEC_OMEGAC0(decayLenXYOmegac); |
| 160 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(candidate, ldlOmegac, omegacldl); |
| 161 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(candidate, chi2NdfTopoCascToOmegac, chi2TopoCascToOmegac); |
| 162 | + CHECK_AND_FILL_VEC_OMEGAC0_FULL(candidate, chi2NdfTopoCascToPv, chi2TopoCascToPv); |
| 163 | + CHECK_AND_FILL_VEC_OMEGAC0(chi2GeoOmegac); |
| 164 | + CHECK_AND_FILL_VEC_OMEGAC0(chi2GeoCasc); |
| 165 | + } |
| 166 | + } |
| 167 | + } |
| 168 | + |
| 169 | + return inputFeatures; |
| 170 | + } |
| 171 | + |
| 172 | + protected: |
| 173 | + /// Method to fill the map of available input features |
| 174 | + void setAvailableInputFeatures() |
| 175 | + { |
| 176 | + // Common variables |
| 177 | + MlResponse<TypeOutputScore>::mAvailableInputFeatures = { |
| 178 | + |
| 179 | + FILL_MAP_OMEGAC0(dcaCharmBaryonDau), |
| 180 | + FILL_MAP_OMEGAC0(dcaCascDau), |
| 181 | + FILL_MAP_OMEGAC0(nSigmaTPCPiFromV0), |
| 182 | + FILL_MAP_OMEGAC0(nSigmaTPCPiFromOmegac), |
| 183 | + FILL_MAP_OMEGAC0(nSigmaTPCKaFromCasc)}; |
| 184 | + |
| 185 | + // DCAFitter variables |
| 186 | + if constexpr (reconstructionType == aod::hf_cand_casc_lf::ConstructMethod::DcaFitter) { |
| 187 | + |
| 188 | + std::map<std::string, uint8_t> mapDcaFeatures{ |
| 189 | + |
| 190 | + FILL_MAP_OMEGAC0(impactParBachFromCharmBaryonXY), |
| 191 | + FILL_MAP_OMEGAC0(impactParBachFromCharmBaryonZ), |
| 192 | + FILL_MAP_OMEGAC0(impactParCascXY), |
| 193 | + FILL_MAP_OMEGAC0(impactParCascZ), |
| 194 | + FILL_MAP_OMEGAC0(cosPACharmBaryon), |
| 195 | + FILL_MAP_OMEGAC0(cosPACasc)}; |
| 196 | + |
| 197 | + MlResponse<TypeOutputScore>::mAvailableInputFeatures.insert(mapDcaFeatures.begin(), mapDcaFeatures.end()); |
| 198 | + } |
| 199 | + |
| 200 | + // KFParticle variables |
| 201 | + if constexpr (reconstructionType == aod::hf_cand_casc_lf::ConstructMethod::KfParticle) { |
| 202 | + |
| 203 | + std::map<std::string, uint8_t> mapKfFeatures{ |
| 204 | + |
| 205 | + FILL_MAP_OMEGAC0(cosPaOmegacToPv), |
| 206 | + FILL_MAP_OMEGAC0(kfDcaXYPiFromOmegac), |
| 207 | + FILL_MAP_OMEGAC0(chi2TopoPiFromOmegacToPv), |
| 208 | + FILL_MAP_OMEGAC0(invMassCascade), |
| 209 | + FILL_MAP_OMEGAC0(massCascChi2OverNdf), |
| 210 | + FILL_MAP_OMEGAC0(kfDcaXYCascToPv), |
| 211 | + FILL_MAP_OMEGAC0(cosPaCascToPv), |
| 212 | + FILL_MAP_OMEGAC0(cosThetaStarPiFromOmegac), |
| 213 | + FILL_MAP_OMEGAC0(chi2NdfTopoOmegacToPv), |
| 214 | + FILL_MAP_OMEGAC0(ldlCasc), |
| 215 | + FILL_MAP_OMEGAC0(cosPaCascToOmegac), |
| 216 | + FILL_MAP_OMEGAC0(decayLenXYCasc), |
| 217 | + FILL_MAP_OMEGAC0(decayLenXYOmegac), |
| 218 | + FILL_MAP_OMEGAC0(ldlOmegac), |
| 219 | + FILL_MAP_OMEGAC0(chi2NdfTopoCascToOmegac), |
| 220 | + FILL_MAP_OMEGAC0(chi2NdfTopoCascToPv), |
| 221 | + FILL_MAP_OMEGAC0(chi2GeoOmegac), |
| 222 | + FILL_MAP_OMEGAC0(chi2GeoCasc)}; |
| 223 | + |
| 224 | + MlResponse<TypeOutputScore>::mAvailableInputFeatures.insert(mapKfFeatures.begin(), mapKfFeatures.end()); |
| 225 | + } |
| 226 | + } |
| 227 | +}; |
| 228 | + |
| 229 | +} // namespace o2::analysis |
| 230 | + |
| 231 | +#undef FILL_MAP_OMEGAC0 |
| 232 | +#undef CHECK_AND_FILL_VEC_OMEGAC0_FULL |
| 233 | +#undef CHECK_AND_FILL_VEC_OMEGAC0 |
| 234 | +#endif // PWGHF_CORE_HFMLRESPONSEOMEGACTOOMEGAPIQA_H_ |
0 commit comments