|
| 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 | +/// \brief |
| 13 | +/// \author Roman Lavicka, roman.lavicka@cern.ch |
| 14 | +/// \since 27.10.2022 |
| 15 | + |
| 16 | +#ifndef PWGUD_CORE_UPCTAUCENTRALBARRELHELPERRL_H_ |
| 17 | +#define PWGUD_CORE_UPCTAUCENTRALBARRELHELPERRL_H_ |
| 18 | + |
| 19 | +#include <string> |
| 20 | +#include <algorithm> |
| 21 | + |
| 22 | +using namespace o2; |
| 23 | +using namespace o2::framework; |
| 24 | +using namespace o2::framework::expressions; |
| 25 | + |
| 26 | +enum MyParticle { |
| 27 | + P_ELECTRON = 0, |
| 28 | + P_MUON = 1, |
| 29 | + P_PION = 2, |
| 30 | + P_KAON = 3, |
| 31 | + P_PROTON = 4 |
| 32 | +}; |
| 33 | + |
| 34 | +void printLargeMessage(std::string info) |
| 35 | +// Helper to printf info message to terminal |
| 36 | +{ |
| 37 | + LOGF(info, "################################### %s ###################################", info); |
| 38 | +} |
| 39 | + |
| 40 | +void printMediumMessage(std::string info) |
| 41 | +// Helper to printf info message to terminal |
| 42 | +{ |
| 43 | + LOGF(info, "+++++++++++++ %s +++++++++++++", info); |
| 44 | +} |
| 45 | + |
| 46 | +template <typename T> |
| 47 | +int testPIDhypothesis(T trackPIDinfo, float nSigmaShift = 0., bool isMC = false) |
| 48 | +// Choose, which particle it is according to PID |
| 49 | +{ |
| 50 | + float nSigmaTPC[5]; |
| 51 | + nSigmaTPC[P_ELECTRON] = std::abs(trackPIDinfo.tpcNSigmaEl()); |
| 52 | + nSigmaTPC[P_MUON] = std::abs(trackPIDinfo.tpcNSigmaMu()); |
| 53 | + nSigmaTPC[P_PION] = std::abs(trackPIDinfo.tpcNSigmaPi()); |
| 54 | + nSigmaTPC[P_KAON] = std::abs(trackPIDinfo.tpcNSigmaKa()); |
| 55 | + nSigmaTPC[P_PROTON] = std::abs(trackPIDinfo.tpcNSigmaPr()); |
| 56 | + // Correction if TPC tuneOnData is wrong |
| 57 | + if (isMC) { |
| 58 | + for (int i = 0; i < 5; i++) |
| 59 | + nSigmaTPC[i] -= nSigmaShift; |
| 60 | + } |
| 61 | + int enumChoiceTPC = std::distance(std::begin(nSigmaTPC), |
| 62 | + std::min_element(std::begin(nSigmaTPC), std::end(nSigmaTPC))); |
| 63 | + |
| 64 | + float nSigmaTOF[5]; |
| 65 | + nSigmaTOF[P_ELECTRON] = std::abs(trackPIDinfo.tofNSigmaEl()); |
| 66 | + nSigmaTOF[P_MUON] = std::abs(trackPIDinfo.tofNSigmaMu()); |
| 67 | + nSigmaTOF[P_PION] = std::abs(trackPIDinfo.tofNSigmaPi()); |
| 68 | + nSigmaTOF[P_KAON] = std::abs(trackPIDinfo.tofNSigmaKa()); |
| 69 | + nSigmaTOF[P_PROTON] = std::abs(trackPIDinfo.tofNSigmaPr()); |
| 70 | + int enumChoiceTOF = std::distance(std::begin(nSigmaTOF), |
| 71 | + std::min_element(std::begin(nSigmaTOF), std::end(nSigmaTOF))); |
| 72 | + |
| 73 | + if (trackPIDinfo.hasTPC() || trackPIDinfo.hasTOF()) { |
| 74 | + if (trackPIDinfo.hasTOF()) { |
| 75 | + return enumChoiceTOF; |
| 76 | + } else { |
| 77 | + return enumChoiceTPC; |
| 78 | + } |
| 79 | + } else { |
| 80 | + LOGF(debug, "testPIDhypothesis failed - track did not leave information in TPC or TOF"); |
| 81 | + return -1; |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +template <typename T> |
| 86 | +int trackPDG(T trackPIDinfo) |
| 87 | +// using testPIDhypothesis, reads enumMyParticle and return pdg value |
| 88 | +{ |
| 89 | + if (testPIDhypothesis(trackPIDinfo) == P_ELECTRON) { |
| 90 | + return 11; |
| 91 | + } else if (testPIDhypothesis(trackPIDinfo) == P_MUON) { |
| 92 | + return 13; |
| 93 | + } else if (testPIDhypothesis(trackPIDinfo) == P_PION) { |
| 94 | + return 211; |
| 95 | + } else if (testPIDhypothesis(trackPIDinfo) == P_KAON) { |
| 96 | + return 321; |
| 97 | + } else if (testPIDhypothesis(trackPIDinfo) == P_PROTON) { |
| 98 | + return 2212; |
| 99 | + } else { |
| 100 | + printMediumMessage("Something is wrong with track PDG selector"); |
| 101 | + return -1.; |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +int enumMyParticle(int valuePDG) |
| 106 | +// reads pdg value and returns particle number as in enumMyParticle |
| 107 | +{ |
| 108 | + if (std::abs(valuePDG) == 11) { |
| 109 | + return P_ELECTRON; |
| 110 | + } else if (std::abs(valuePDG) == 13) { |
| 111 | + return P_MUON; |
| 112 | + } else if (std::abs(valuePDG) == 211) { |
| 113 | + return P_PION; |
| 114 | + } else if (std::abs(valuePDG) == 321) { |
| 115 | + return P_KAON; |
| 116 | + } else if (std::abs(valuePDG) == 2212) { |
| 117 | + return P_PROTON; |
| 118 | + } else { |
| 119 | + printMediumMessage("PDG value not found in enumMyParticle. Returning -1."); |
| 120 | + return -1.; |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +float momentum(float px, float py, float pz) |
| 125 | +// Just a simple function to return momentum |
| 126 | +{ |
| 127 | + return std::sqrt(px * px + py * py + pz * pz); |
| 128 | +} |
| 129 | + |
| 130 | +float invariantMass(float E, float px, float py, float pz) |
| 131 | +// Just a simple function to return invariant mass |
| 132 | +{ |
| 133 | + return std::sqrt(E * E - px * px - py * py - pz * pz); |
| 134 | +} |
| 135 | + |
| 136 | +float phi(float px, float py) |
| 137 | +// Just a simple function to return azimuthal angle |
| 138 | +{ |
| 139 | + if (px != 0) |
| 140 | + return std::atan(py / px); |
| 141 | + return -999.; |
| 142 | +} |
| 143 | + |
| 144 | +float eta(float px, float py, float pz) |
| 145 | +// Just a simple function to return pseudorapidity |
| 146 | +{ |
| 147 | + float eta = -999.; |
| 148 | + float mom = momentum(px, py, pz); |
| 149 | + if (mom != 0) |
| 150 | + eta = std::atanh(pz / mom); |
| 151 | + if (-1. < eta && eta < 1.) |
| 152 | + return eta; |
| 153 | + return -999.; |
| 154 | +} |
| 155 | + |
| 156 | +float energy(float mass, float px, float py, float pz) |
| 157 | +// Just a simple function to return track energy |
| 158 | +{ |
| 159 | + return std::sqrt(mass * mass + px * px + py * py + pz * pz); |
| 160 | +} |
| 161 | + |
| 162 | +float rapidity(float mass, float px, float py, float pz) |
| 163 | +// Just a simple function to return track rapidity |
| 164 | +{ |
| 165 | + return 0.5 * std::log((energy(mass, px, py, pz) + pz) / (energy(mass, px, py, pz) - pz)); |
| 166 | +} |
| 167 | + |
| 168 | +double calculateAcoplanarity(double phi_trk1, double phi_trk2) |
| 169 | +// Function to calculate acoplanarity of two tracks based on phi of both tracks, which is in interval (0,2*pi) |
| 170 | +{ |
| 171 | + double aco = std::abs(phi_trk1 - phi_trk2); |
| 172 | + if (aco <= o2::constants::math::PI) |
| 173 | + return aco; |
| 174 | + else |
| 175 | + return (o2::constants::math::TwoPI - aco); |
| 176 | +} |
| 177 | + |
| 178 | +#endif // PWGUD_CORE_UPCTAUCENTRALBARRELHELPERRL_H_ |
0 commit comments