|
| 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 EmMLResponsePCM.h |
| 13 | +/// \brief Class to compute the ML response for PCM analysis selections |
| 14 | +/// \author Isabel Kantak <isabel.kantak@cern.ch>, University of Heidelberg |
| 15 | + |
| 16 | +#ifndef PWGEM_PHOTONMESON_CORE_EMMLRESPONSEPCM_H_ |
| 17 | +#define PWGEM_PHOTONMESON_CORE_EMMLRESPONSEPCM_H_ |
| 18 | + |
| 19 | +#include "PWGEM/PhotonMeson/Core/EmMlResponse.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_PCM(FEATURE) \ |
| 30 | + { \ |
| 31 | + #FEATURE, static_cast<uint8_t>(InputFeaturesPCM::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_PCM_FULL(OBJECT, FEATURE, GETTER) \ |
| 39 | + case static_cast<uint8_t>(InputFeaturesPCM::FEATURE): { \ |
| 40 | + inputFeatures.emplace_back(OBJECT.GETTER()); \ |
| 41 | + break; \ |
| 42 | + } |
| 43 | + |
| 44 | +// Specific case of CHECK_AND_FILL_VEC_PCM_FULL(OBJECT, FEATURE, GETTER) |
| 45 | +// where OBJECT is named candidate and FEATURE = GETTER |
| 46 | +#define CHECK_AND_FILL_VEC_PCM(GETTER) \ |
| 47 | + case static_cast<uint8_t>(InputFeaturesPCM::GETTER): { \ |
| 48 | + inputFeatures.emplace_back(candidate.GETTER()); \ |
| 49 | + break; \ |
| 50 | + } |
| 51 | + |
| 52 | +namespace o2::analysis |
| 53 | +{ |
| 54 | + |
| 55 | +enum class InputFeaturesPCM : uint8_t { |
| 56 | + v0PhotonCandidatefDCAxyToPV, |
| 57 | + v0PhotonCandidatefDCAzToPV, |
| 58 | + v0PhotonCandidatefPCA, |
| 59 | + v0PhotonCandidatefAlpha, |
| 60 | + v0PhotonCandidatefQtArm, |
| 61 | + v0PhotonCandidatefChiSquareNDF, |
| 62 | + v0PhotonCandidatefCosPA, |
| 63 | + posV0LegfTPCNSigmaEl, |
| 64 | + posV0LegfTPCNSigmaPi, |
| 65 | + negV0LegfTPCNSigmaEl, |
| 66 | + negV0LegfTPCNSigmaPi |
| 67 | +}; |
| 68 | + |
| 69 | +template <typename TypeOutputScore = float> |
| 70 | +class EmMlResponsePCM : public EmMlResponse<TypeOutputScore> |
| 71 | +{ |
| 72 | + public: |
| 73 | + /// Default constructor |
| 74 | + EmMlResponsePCM() = default; |
| 75 | + /// Default destructor |
| 76 | + virtual ~EmMlResponsePCM() = default; |
| 77 | + |
| 78 | + /// Method to get the input features vector needed for ML inference |
| 79 | + /// \param candidate is the V0photon candidate |
| 80 | + /// \return inputFeatures vector |
| 81 | + template <typename T1, typename T2> |
| 82 | + std::vector<float> getInputFeatures(T1 const& candidate, T2 const& posLeg, T2 const& negLeg) |
| 83 | + { |
| 84 | + std::vector<float> inputFeatures; |
| 85 | + |
| 86 | + for (const auto& idx : MlResponse<TypeOutputScore>::mCachedIndices) { |
| 87 | + switch (idx) { |
| 88 | + CHECK_AND_FILL_VEC_PCM_FULL(candidate, v0PhotonCandidatefDCAxyToPV, GetDcaXYToPV); |
| 89 | + CHECK_AND_FILL_VEC_PCM_FULL(candidate, v0PhotonCandidatefDCAzToPV, GetDcaZToPV); |
| 90 | + CHECK_AND_FILL_VEC_PCM_FULL(candidate, v0PhotonCandidatefPCA, GetPCA); |
| 91 | + CHECK_AND_FILL_VEC_PCM_FULL(candidate, v0PhotonCandidatefAlpha, GetAlpha); |
| 92 | + CHECK_AND_FILL_VEC_PCM_FULL(candidate, v0PhotonCandidatefQtArm, GetQt); |
| 93 | + CHECK_AND_FILL_VEC_PCM_FULL(candidate, v0PhotonCandidatefChiSquareNDF, GetChi2NDF); |
| 94 | + CHECK_AND_FILL_VEC_PCM_FULL(candidate, v0PhotonCandidatefCosPA, GetCosPA); |
| 95 | + CHECK_AND_FILL_VEC_PCM_FULL(posLeg, posV0LegfTPCNSigmaEl, tpcNSigmaEl); |
| 96 | + CHECK_AND_FILL_VEC_PCM_FULL(posLeg, posV0LegfTPCNSigmaPi, tpcNSigmaPi); |
| 97 | + CHECK_AND_FILL_VEC_PCM_FULL(negLeg, negV0LegfTPCNSigmaEl, tpcNSigmaEl); |
| 98 | + CHECK_AND_FILL_VEC_PCM_FULL(negLeg, negV0LegfTPCNSigmaPi, tpcNSigmaPi); |
| 99 | + } |
| 100 | + } |
| 101 | + return inputFeatures; |
| 102 | + } |
| 103 | + |
| 104 | + protected: |
| 105 | + /// Method to fill the map of available input features |
| 106 | + void setAvailableInputFeatures() |
| 107 | + { |
| 108 | + MlResponse<TypeOutputScore>::mAvailableInputFeatures = { |
| 109 | + FILL_MAP_PCM(v0PhotonCandidatefDCAxyToPV), |
| 110 | + FILL_MAP_PCM(v0PhotonCandidatefDCAzToPV), |
| 111 | + FILL_MAP_PCM(v0PhotonCandidatefPCA), |
| 112 | + FILL_MAP_PCM(v0PhotonCandidatefAlpha), |
| 113 | + FILL_MAP_PCM(v0PhotonCandidatefQtArm), |
| 114 | + FILL_MAP_PCM(v0PhotonCandidatefChiSquareNDF), |
| 115 | + FILL_MAP_PCM(v0PhotonCandidatefCosPA), |
| 116 | + FILL_MAP_PCM(posV0LegfTPCNSigmaEl), |
| 117 | + FILL_MAP_PCM(posV0LegfTPCNSigmaPi), |
| 118 | + FILL_MAP_PCM(negV0LegfTPCNSigmaEl), |
| 119 | + FILL_MAP_PCM(negV0LegfTPCNSigmaPi)}; |
| 120 | + } |
| 121 | +}; |
| 122 | + |
| 123 | +} // namespace o2::analysis |
| 124 | + |
| 125 | +#undef FILL_MAP_PCM |
| 126 | +#undef CHECK_AND_FILL_VEC_PCM_FULL |
| 127 | +#undef CHECK_AND_FILL_VEC_PCM |
| 128 | + |
| 129 | +#endif // PWGEM_PHOTONMESON_CORE_EMMLRESPONSEPCM_H_ |
0 commit comments