|
| 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 | +/// |
| 13 | +/// \file PIDutils.h |
| 14 | +/// \author Gleb Romanenko gleb.romanenko@cern.ch |
| 15 | +/// \brief SFINAE checks for existance of PID info |
| 16 | +/// \since 24/03/2025 |
| 17 | +/// |
| 18 | + |
| 19 | +#ifndef PWGCF_FEMTO3D_DATAMODEL_PIDUTILS_H_ |
| 20 | +#define PWGCF_FEMTO3D_DATAMODEL_PIDUTILS_H_ |
| 21 | + |
| 22 | +#include <type_traits> |
| 23 | +#include <utility> |
| 24 | +#include <vector> |
| 25 | +#include "Common/DataModel/PIDResponse.h" |
| 26 | + |
| 27 | +namespace o2::aod::singletrackselector |
| 28 | +{ |
| 29 | +namespace pidutils |
| 30 | +{ |
| 31 | + |
| 32 | +//========================================== SFINAE checks ========================================== |
| 33 | + |
| 34 | +template <typename T, typename = void> |
| 35 | +struct hasTPCPi : std::false_type { |
| 36 | +}; |
| 37 | +template <typename T> |
| 38 | +struct hasTPCPi<T, std::void_t<o2::aod::pidutils::hasTPCPi<T>>> : std::true_type { |
| 39 | +}; |
| 40 | + |
| 41 | +template <typename T, typename = void> |
| 42 | +struct hasTPCKa : std::false_type { |
| 43 | +}; |
| 44 | +template <typename T> |
| 45 | +struct hasTPCKa<T, std::void_t<o2::aod::pidutils::hasTPCKa<T>>> : std::true_type { |
| 46 | +}; |
| 47 | + |
| 48 | +template <typename T, typename = void> |
| 49 | +struct hasTPCPr : std::false_type { |
| 50 | +}; |
| 51 | +template <typename T> |
| 52 | +struct hasTPCPr<T, std::void_t<o2::aod::pidutils::hasTPCPr<T>>> : std::true_type { |
| 53 | +}; |
| 54 | + |
| 55 | +template <typename T, typename = void> |
| 56 | +struct hasTPCDe : std::false_type { |
| 57 | +}; |
| 58 | +template <typename T> |
| 59 | +struct hasTPCDe<T, std::void_t<o2::aod::pidutils::hasTPCDe<T>>> : std::true_type { |
| 60 | +}; |
| 61 | + |
| 62 | +template <typename T, typename = void> |
| 63 | +struct hasTPCTr : std::false_type { |
| 64 | +}; |
| 65 | +template <typename T> |
| 66 | +struct hasTPCTr<T, std::void_t<o2::aod::pidutils::hasTPCTr<T>>> : std::true_type { |
| 67 | +}; |
| 68 | + |
| 69 | +template <typename T, typename = void> |
| 70 | +struct hasTPCHe : std::false_type { |
| 71 | +}; |
| 72 | +template <typename T> |
| 73 | +struct hasTPCHe<T, std::void_t<o2::aod::pidutils::hasTPCHe<T>>> : std::true_type { |
| 74 | +}; |
| 75 | + |
| 76 | +template <typename T, typename = void> |
| 77 | +struct hasTOFPi : std::false_type { |
| 78 | +}; |
| 79 | +template <typename T> |
| 80 | +struct hasTOFPi<T, std::void_t<o2::aod::pidutils::hasTOFPi<T>>> : std::true_type { |
| 81 | +}; |
| 82 | + |
| 83 | +template <typename T, typename = void> |
| 84 | +struct hasTOFKa : std::false_type { |
| 85 | +}; |
| 86 | +template <typename T> |
| 87 | +struct hasTOFKa<T, std::void_t<o2::aod::pidutils::hasTOFKa<T>>> : std::true_type { |
| 88 | +}; |
| 89 | + |
| 90 | +template <typename T, typename = void> |
| 91 | +struct hasTOFPr : std::false_type { |
| 92 | +}; |
| 93 | +template <typename T> |
| 94 | +struct hasTOFPr<T, std::void_t<o2::aod::pidutils::hasTOFPr<T>>> : std::true_type { |
| 95 | +}; |
| 96 | + |
| 97 | +template <typename T, typename = void> |
| 98 | +struct hasTOFDe : std::false_type { |
| 99 | +}; |
| 100 | +template <typename T> |
| 101 | +struct hasTOFDe<T, std::void_t<o2::aod::pidutils::hasTOFDe<T>>> : std::true_type { |
| 102 | +}; |
| 103 | + |
| 104 | +template <typename T, typename = void> |
| 105 | +struct hasTOFTr : std::false_type { |
| 106 | +}; |
| 107 | +template <typename T> |
| 108 | +struct hasTOFTr<T, std::void_t<o2::aod::pidutils::hasTOFTr<T>>> : std::true_type { |
| 109 | +}; |
| 110 | + |
| 111 | +template <typename T, typename = void> |
| 112 | +struct hasTOFHe : std::false_type { |
| 113 | +}; |
| 114 | +template <typename T> |
| 115 | +struct hasTOFHe<T, std::void_t<o2::aod::pidutils::hasTOFHe<T>>> : std::true_type { |
| 116 | +}; |
| 117 | + |
| 118 | +} // namespace pidutils |
| 119 | + |
| 120 | +//========================================== ITS PID ========================================== |
| 121 | + |
| 122 | +template <typename TrackType> |
| 123 | +inline float getITSNsigma(TrackType const& track, int const& PDG) |
| 124 | +{ |
| 125 | + switch (PDG) { |
| 126 | + case 211: |
| 127 | + return track.itsNSigmaPi(); |
| 128 | + case 321: |
| 129 | + return track.itsNSigmaKa(); |
| 130 | + case 2212: |
| 131 | + return track.itsNSigmaPr(); |
| 132 | + case 1000010020: |
| 133 | + return track.itsNSigmaDe(); |
| 134 | + case 1000020030: |
| 135 | + return track.itsNSigmaHe(); |
| 136 | + case 1000010030: |
| 137 | + return track.itsNSigmaTr(); |
| 138 | + case 0: |
| 139 | + return -1000.0; |
| 140 | + default: |
| 141 | + LOG(fatal) << "Cannot interpret PDG for ITS selection: " << PDG; |
| 142 | + return -1000.0; |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +template <typename TrackType> |
| 147 | +inline bool ITSselection(TrackType const& track, std::pair<int, std::vector<float>> const& PIDcuts) |
| 148 | +{ |
| 149 | + float Nsigma = getITSNsigma(track, PIDcuts.first); |
| 150 | + |
| 151 | + if (Nsigma > PIDcuts.second[0] && Nsigma < PIDcuts.second[1]) { |
| 152 | + return true; |
| 153 | + } |
| 154 | + return false; |
| 155 | +} |
| 156 | + |
| 157 | +//========================================== TPC PID ========================================== |
| 158 | + |
| 159 | +template <typename TrackType> |
| 160 | +inline float getTPCNsigma(TrackType const& track, int const& PDG) |
| 161 | +{ |
| 162 | + switch (PDG) { |
| 163 | + case 211: |
| 164 | + if constexpr (o2::aod::singletrackselector::pidutils::hasTPCPi<TrackType>::value) |
| 165 | + return track.tpcNSigmaPi(); |
| 166 | + case 321: |
| 167 | + if constexpr (o2::aod::singletrackselector::pidutils::hasTPCKa<TrackType>::value) |
| 168 | + return track.tpcNSigmaKa(); |
| 169 | + case 2212: |
| 170 | + if constexpr (o2::aod::singletrackselector::pidutils::hasTPCPr<TrackType>::value) |
| 171 | + return track.tpcNSigmaPr(); |
| 172 | + case 1000010020: |
| 173 | + if constexpr (o2::aod::singletrackselector::pidutils::hasTPCDe<TrackType>::value) |
| 174 | + return track.tpcNSigmaDe(); |
| 175 | + case 1000020030: |
| 176 | + if constexpr (o2::aod::singletrackselector::pidutils::hasTPCHe<TrackType>::value) |
| 177 | + return track.tpcNSigmaHe(); |
| 178 | + case 1000010030: |
| 179 | + if constexpr (o2::aod::singletrackselector::pidutils::hasTPCTr<TrackType>::value) |
| 180 | + return track.tpcNSigmaTr(); |
| 181 | + case 0: |
| 182 | + return -1000.0; |
| 183 | + default: |
| 184 | + LOG(fatal) << "Cannot interpret PDG for TPC selection: " << PDG; |
| 185 | + return -1000.0; |
| 186 | + } |
| 187 | +} |
| 188 | + |
| 189 | +template <bool useITS, typename TrackType> |
| 190 | +inline bool TPCselection(TrackType const& track, std::pair<int, std::vector<float>> const& PIDcuts, std::vector<float> const& ITSCut = std::vector<float>{}) |
| 191 | +{ |
| 192 | + int PDG = PIDcuts.first; |
| 193 | + |
| 194 | + if constexpr (useITS) { |
| 195 | + if (ITSCut.size() != 0 && !ITSselection(track, std::make_pair(PDG, ITSCut))) |
| 196 | + return false; |
| 197 | + } |
| 198 | + |
| 199 | + float Nsigma = getTPCNsigma(track, PDG); |
| 200 | + |
| 201 | + if (Nsigma > PIDcuts.second[0] && Nsigma < PIDcuts.second[1]) { |
| 202 | + return true; |
| 203 | + } |
| 204 | + return false; |
| 205 | +} |
| 206 | + |
| 207 | +//========================================== TOF PID ========================================== |
| 208 | + |
| 209 | +template <typename TrackType> |
| 210 | +inline float getTOFNsigma(TrackType const& track, int const& PDG) |
| 211 | +{ |
| 212 | + switch (PDG) { |
| 213 | + case 211: |
| 214 | + if constexpr (o2::aod::singletrackselector::pidutils::hasTOFPi<TrackType>::value) |
| 215 | + return track.tofNSigmaPi(); |
| 216 | + case 321: |
| 217 | + if constexpr (o2::aod::singletrackselector::pidutils::hasTOFKa<TrackType>::value) |
| 218 | + return track.tofNSigmaKa(); |
| 219 | + case 2212: |
| 220 | + if constexpr (o2::aod::singletrackselector::pidutils::hasTOFPr<TrackType>::value) |
| 221 | + return track.tofNSigmaPr(); |
| 222 | + case 1000010020: |
| 223 | + if constexpr (o2::aod::singletrackselector::pidutils::hasTOFDe<TrackType>::value) |
| 224 | + return track.tofNSigmaDe(); |
| 225 | + case 1000020030: |
| 226 | + if constexpr (o2::aod::singletrackselector::pidutils::hasTOFHe<TrackType>::value) |
| 227 | + return track.tofNSigmaHe(); |
| 228 | + case 1000010030: |
| 229 | + if constexpr (o2::aod::singletrackselector::pidutils::hasTOFTr<TrackType>::value) |
| 230 | + return track.tofNSigmaTr(); |
| 231 | + case 0: |
| 232 | + return -1000.0; |
| 233 | + default: |
| 234 | + LOG(fatal) << "Cannot interpret PDG for TOF selection: " << PDG; |
| 235 | + return -1000.0; |
| 236 | + } |
| 237 | +} |
| 238 | + |
| 239 | +template <typename TrackType> |
| 240 | +inline bool TOFselection(TrackType const& track, std::pair<int, std::vector<float>> const& PIDcuts, std::vector<float> const& TPCresidualCut = std::vector<float>{-5.0f, 5.0f}) |
| 241 | +{ |
| 242 | + int PDG = PIDcuts.first; |
| 243 | + if (!TPCselection<false>(track, std::make_pair(PDG, TPCresidualCut))) |
| 244 | + return false; |
| 245 | + |
| 246 | + float Nsigma = getTOFNsigma(track, PDG); |
| 247 | + |
| 248 | + if (Nsigma > PIDcuts.second[0] && Nsigma < PIDcuts.second[1]) { |
| 249 | + return true; |
| 250 | + } |
| 251 | + return false; |
| 252 | +} |
| 253 | +} // namespace o2::aod::singletrackselector |
| 254 | + |
| 255 | +#endif // PWGCF_FEMTO3D_DATAMODEL_PIDUTILS_H_ |
0 commit comments