|
| 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 EmMlResponseEMCConversion.h |
| 13 | +/// \brief Class to compute the ML response for EMC conversion selections |
| 14 | +/// \author Marvin Hemmer <marvin.hemmer@cern.ch> |
| 15 | + |
| 16 | +#ifndef PWGEM_PHOTONMESON_CORE_EMMLRESPONSEEMCCONVERSION_H_ |
| 17 | +#define PWGEM_PHOTONMESON_CORE_EMMLRESPONSEEMCCONVERSION_H_ |
| 18 | + |
| 19 | +#include "PWGEM/PhotonMeson/Core/EMCConversionCandidate.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_EMC_CONV(FEATURE) \ |
| 30 | + { \ |
| 31 | + #FEATURE, static_cast<uint8_t>(InputFeaturesEMCConversion::FEATURE)} |
| 32 | + |
| 33 | +// Check if the index of mCachedIndices (index associated to a FEATURE) |
| 34 | +// matches the entry in EnumInputFeatures associated to this FEATURE |
| 35 | +// if so, the inputFeatures vector is filled with the FEATURE's value |
| 36 | +// by calling the corresponding GETTER from OBJECT |
| 37 | +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) |
| 38 | +#define CHECK_AND_FILL_VEC_EMC_CONV(GETTER) \ |
| 39 | + case static_cast<uint8_t>(InputFeaturesEMCConversion::GETTER): { \ |
| 40 | + inputFeatures.emplace_back(candidate.GETTER()); \ |
| 41 | + break; \ |
| 42 | + } |
| 43 | + |
| 44 | +namespace o2::analysis::em::emcconv |
| 45 | +{ |
| 46 | + |
| 47 | +// input feature used in the ml model |
| 48 | +enum class InputFeaturesEMCConversion : uint8_t { |
| 49 | + minv, |
| 50 | + deltaEta, |
| 51 | + deltaR, |
| 52 | + phiv, |
| 53 | + rConv, |
| 54 | + totE, |
| 55 | + e2, |
| 56 | + e1, |
| 57 | + deltaPhi |
| 58 | +}; |
| 59 | + |
| 60 | +template <typename TypeOutputScore = float> |
| 61 | +class EmMlResponseEMCConversion : public MlResponse<TypeOutputScore> |
| 62 | +{ |
| 63 | + public: |
| 64 | + EmMlResponseEMCConversion() = default; |
| 65 | + virtual ~EmMlResponseEMCConversion() = default; |
| 66 | + |
| 67 | + template <o2::analysis::em::IsEmcConversionCandidate TCandidate> |
| 68 | + std::vector<float> getInputFeatures(TCandidate const& candidate) |
| 69 | + { |
| 70 | + std::vector<float> inputFeatures; |
| 71 | + for (const auto& idx : MlResponse<TypeOutputScore>::mCachedIndices) { |
| 72 | + switch (idx) { |
| 73 | + CHECK_AND_FILL_VEC_EMC_CONV(minv) |
| 74 | + CHECK_AND_FILL_VEC_EMC_CONV(deltaEta) |
| 75 | + CHECK_AND_FILL_VEC_EMC_CONV(deltaR) |
| 76 | + CHECK_AND_FILL_VEC_EMC_CONV(phiv) |
| 77 | + CHECK_AND_FILL_VEC_EMC_CONV(rConv) |
| 78 | + CHECK_AND_FILL_VEC_EMC_CONV(totE) |
| 79 | + CHECK_AND_FILL_VEC_EMC_CONV(e2) |
| 80 | + CHECK_AND_FILL_VEC_EMC_CONV(e1) |
| 81 | + CHECK_AND_FILL_VEC_EMC_CONV(deltaPhi) |
| 82 | + } |
| 83 | + } |
| 84 | + return inputFeatures; |
| 85 | + } |
| 86 | + |
| 87 | + protected: |
| 88 | + void setAvailableInputFeatures() |
| 89 | + { |
| 90 | + MlResponse<TypeOutputScore>::mAvailableInputFeatures = { |
| 91 | + FILL_MAP_EMC_CONV(minv), FILL_MAP_EMC_CONV(deltaEta), FILL_MAP_EMC_CONV(deltaR), |
| 92 | + FILL_MAP_EMC_CONV(phiv), FILL_MAP_EMC_CONV(rConv), FILL_MAP_EMC_CONV(totE), |
| 93 | + FILL_MAP_EMC_CONV(e2), FILL_MAP_EMC_CONV(e1), FILL_MAP_EMC_CONV(deltaPhi)}; |
| 94 | + } |
| 95 | +}; |
| 96 | + |
| 97 | +} // namespace o2::analysis::em::emcconv |
| 98 | + |
| 99 | +#undef FILL_MAP_EMC_CONV |
| 100 | +#undef CHECK_AND_FILL_VEC_EMC_CONV |
| 101 | + |
| 102 | +#endif // PWGEM_PHOTONMESON_CORE_EMMLRESPONSEEMCCONVERSION_H_ |
0 commit comments