|
| 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 HfMlResponseBplusToD0PiReduced.h |
| 13 | +/// \brief Class to compute the ML response for B± → D0(bar) π± analysis selections in the reduced format |
| 14 | +/// \author Antonio Palasciano <[email protected]>, INFN Bari |
| 15 | + |
| 16 | +#ifndef PWGHF_CORE_HFMLRESPONSEBPLUSTOD0PIREDUCED_H_ |
| 17 | +#define PWGHF_CORE_HFMLRESPONSEBPLUSTOD0PIREDUCED_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_BPLUS(FEATURE) \ |
| 30 | + { \ |
| 31 | + #FEATURE, static_cast<uint8_t>(InputFeaturesBplusToD0PiReduced::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_BPLUS_FULL(OBJECT, FEATURE, GETTER) \ |
| 39 | + case static_cast<uint8_t>(InputFeaturesBplusToD0PiReduced::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_BPLUS_FUNC(OBJECT, FEATURE, GETTER) \ |
| 49 | + case static_cast<uint8_t>(InputFeaturesBplusToD0PiReduced::FEATURE): { \ |
| 50 | + inputFeatures.emplace_back(GETTER(OBJECT)); \ |
| 51 | + break; \ |
| 52 | + } |
| 53 | + |
| 54 | +// Specific case of CHECK_AND_FILL_VEC_BPLUS_FULL(OBJECT, FEATURE, GETTER) |
| 55 | +// where OBJECT is named candidate and FEATURE = GETTER |
| 56 | +#define CHECK_AND_FILL_VEC_BPLUS(GETTER) \ |
| 57 | + case static_cast<uint8_t>(InputFeaturesBplusToD0PiReduced::GETTER): { \ |
| 58 | + inputFeatures.emplace_back(candidate.GETTER()); \ |
| 59 | + break; \ |
| 60 | + } |
| 61 | + |
| 62 | +namespace o2::analysis |
| 63 | +{ |
| 64 | + |
| 65 | +enum class InputFeaturesBplusToD0PiReduced : 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 HfMlResponseBplusToD0PiReduced : public HfMlResponse<TypeOutputScore> |
| 89 | +{ |
| 90 | + public: |
| 91 | + /// Default constructor |
| 92 | + HfMlResponseBplusToD0PiReduced() = default; |
| 93 | + /// Default destructor |
| 94 | + virtual ~HfMlResponseBplusToD0PiReduced() = default; |
| 95 | + |
| 96 | + /// Method to get the input features vector needed for ML inference |
| 97 | + /// \param candidate is the B+ 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_BPLUS(ptProng0); |
| 110 | + CHECK_AND_FILL_VEC_BPLUS(ptProng1); |
| 111 | + CHECK_AND_FILL_VEC_BPLUS(impactParameter0); |
| 112 | + CHECK_AND_FILL_VEC_BPLUS(impactParameter1); |
| 113 | + CHECK_AND_FILL_VEC_BPLUS(impactParameterProduct); |
| 114 | + CHECK_AND_FILL_VEC_BPLUS(chi2PCA); |
| 115 | + CHECK_AND_FILL_VEC_BPLUS(decayLength); |
| 116 | + CHECK_AND_FILL_VEC_BPLUS(decayLengthXY); |
| 117 | + CHECK_AND_FILL_VEC_BPLUS(decayLengthNormalised); |
| 118 | + CHECK_AND_FILL_VEC_BPLUS(decayLengthXYNormalised); |
| 119 | + CHECK_AND_FILL_VEC_BPLUS(cpa); |
| 120 | + CHECK_AND_FILL_VEC_BPLUS(cpaXY); |
| 121 | + CHECK_AND_FILL_VEC_BPLUS(maxNormalisedDeltaIP); |
| 122 | + CHECK_AND_FILL_VEC_BPLUS(prong0MlScoreBkg); |
| 123 | + CHECK_AND_FILL_VEC_BPLUS(prong0MlScorePrompt); |
| 124 | + CHECK_AND_FILL_VEC_BPLUS(prong0MlScoreNonprompt); |
| 125 | + // TPC PID variable |
| 126 | + CHECK_AND_FILL_VEC_BPLUS_FULL(prong1, tpcNSigmaPi1, tpcNSigmaPi); |
| 127 | + // TOF PID variable |
| 128 | + CHECK_AND_FILL_VEC_BPLUS_FULL(prong1, tofNSigmaPi1, tofNSigmaPi); |
| 129 | + // Combined PID variables |
| 130 | + CHECK_AND_FILL_VEC_BPLUS_FUNC(prong1, tpcTofNSigmaPi1, o2::pid_tpc_tof_utils::getTpcTofNSigmaPi1); |
| 131 | + } |
| 132 | + } else { |
| 133 | + switch (idx) { |
| 134 | + CHECK_AND_FILL_VEC_BPLUS(ptProng0); |
| 135 | + CHECK_AND_FILL_VEC_BPLUS(ptProng1); |
| 136 | + CHECK_AND_FILL_VEC_BPLUS(impactParameter0); |
| 137 | + CHECK_AND_FILL_VEC_BPLUS(impactParameter1); |
| 138 | + CHECK_AND_FILL_VEC_BPLUS(impactParameterProduct); |
| 139 | + CHECK_AND_FILL_VEC_BPLUS(chi2PCA); |
| 140 | + CHECK_AND_FILL_VEC_BPLUS(decayLength); |
| 141 | + CHECK_AND_FILL_VEC_BPLUS(decayLengthXY); |
| 142 | + CHECK_AND_FILL_VEC_BPLUS(decayLengthNormalised); |
| 143 | + CHECK_AND_FILL_VEC_BPLUS(decayLengthXYNormalised); |
| 144 | + CHECK_AND_FILL_VEC_BPLUS(cpa); |
| 145 | + CHECK_AND_FILL_VEC_BPLUS(cpaXY); |
| 146 | + CHECK_AND_FILL_VEC_BPLUS(maxNormalisedDeltaIP); |
| 147 | + // TPC PID variable |
| 148 | + CHECK_AND_FILL_VEC_BPLUS_FULL(prong1, tpcNSigmaPi1, tpcNSigmaPi); |
| 149 | + // TOF PID variable |
| 150 | + CHECK_AND_FILL_VEC_BPLUS_FULL(prong1, tofNSigmaPi1, tofNSigmaPi); |
| 151 | + // Combined PID variables |
| 152 | + CHECK_AND_FILL_VEC_BPLUS_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_BPLUS(ptProng0), |
| 166 | + FILL_MAP_BPLUS(ptProng1), |
| 167 | + FILL_MAP_BPLUS(impactParameter0), |
| 168 | + FILL_MAP_BPLUS(impactParameter1), |
| 169 | + FILL_MAP_BPLUS(impactParameterProduct), |
| 170 | + FILL_MAP_BPLUS(chi2PCA), |
| 171 | + FILL_MAP_BPLUS(decayLength), |
| 172 | + FILL_MAP_BPLUS(decayLengthXY), |
| 173 | + FILL_MAP_BPLUS(decayLengthNormalised), |
| 174 | + FILL_MAP_BPLUS(decayLengthXYNormalised), |
| 175 | + FILL_MAP_BPLUS(cpa), |
| 176 | + FILL_MAP_BPLUS(cpaXY), |
| 177 | + FILL_MAP_BPLUS(maxNormalisedDeltaIP), |
| 178 | + FILL_MAP_BPLUS(prong0MlScoreBkg), |
| 179 | + FILL_MAP_BPLUS(prong0MlScorePrompt), |
| 180 | + FILL_MAP_BPLUS(prong0MlScoreNonprompt), |
| 181 | + // TPC PID variable |
| 182 | + FILL_MAP_BPLUS(tpcNSigmaPi1), |
| 183 | + // TOF PID variable |
| 184 | + FILL_MAP_BPLUS(tofNSigmaPi1), |
| 185 | + // Combined PID variable |
| 186 | + FILL_MAP_BPLUS(tpcTofNSigmaPi1)}; |
| 187 | + } |
| 188 | +}; |
| 189 | + |
| 190 | +} // namespace o2::analysis |
| 191 | + |
| 192 | +#undef FILL_MAP_BPLUS |
| 193 | +#undef CHECK_AND_FILL_VEC_BPLUS_FULL |
| 194 | +#undef CHECK_AND_FILL_VEC_BPLUS_FUNC |
| 195 | +#undef CHECK_AND_FILL_VEC_BPLUS |
| 196 | + |
| 197 | +#endif // PWGHF_CORE_HFMLRESPONSEBPLUSTOD0PIREDUCED_H_ |
0 commit comments