|
| 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 OTFParticle.h |
| 14 | +/// \brief Basic class to hold information regarding a mc particle to be used in fast simulation |
| 15 | +/// \author Jesper Karlsson Gumprecht <jesper.gumprecht@cern.ch> |
| 16 | +/// |
| 17 | + |
| 18 | +#ifndef ALICE3_CORE_OTFPARTICLE_H_ |
| 19 | +#define ALICE3_CORE_OTFPARTICLE_H_ |
| 20 | + |
| 21 | +#include <CommonConstants/MathConstants.h> |
| 22 | + |
| 23 | +#include <array> |
| 24 | +#include <cmath> |
| 25 | +#include <cstdint> |
| 26 | +#include <span> |
| 27 | + |
| 28 | +namespace o2::upgrade |
| 29 | +{ |
| 30 | + |
| 31 | +class OTFParticle |
| 32 | +{ |
| 33 | + public: |
| 34 | + OTFParticle() = default; |
| 35 | + |
| 36 | + template <typename TParticle> |
| 37 | + explicit OTFParticle(const TParticle& particle) |
| 38 | + { |
| 39 | + mPdgCode = particle.pdgCode(); |
| 40 | + mGlobalIndex = particle.globalIndex(); |
| 41 | + mCollisionId = particle.mcCollisionId(); |
| 42 | + mPx = particle.px(); |
| 43 | + mPy = particle.py(); |
| 44 | + mPz = particle.pz(); |
| 45 | + mE = particle.e(); |
| 46 | + mVx = particle.vx(); |
| 47 | + mVy = particle.vy(); |
| 48 | + mVz = particle.vz(); |
| 49 | + mVt = particle.vt(); |
| 50 | + mIsFromMcParticles = true; |
| 51 | + if (particle.has_mothers()) { |
| 52 | + mIndicesMother = {particle.mothersIds().front(), particle.mothersIds().back()}; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + // Setters |
| 57 | + void setIsAlive(const bool isAlive) { mIsAlive = isAlive; } |
| 58 | + void setIsPrimary(const bool isPrimary) { mIsPrimary = isPrimary; } |
| 59 | + void setCollisionId(const int collisionId) { mCollisionId = collisionId; } |
| 60 | + void setPDG(const int pdg) { mPdgCode = pdg; } |
| 61 | + void setIndicesMother(const int start, const int stop) { mIndicesMother = {start, stop}; } |
| 62 | + void setIndicesDaughter(const int start, const int stop) { mIndicesDaughter = {start, stop}; } |
| 63 | + void setProductionTime(const float vt) { mVt = vt; } |
| 64 | + void setVxVyVz(const float vx, const float vy, const float vz) |
| 65 | + { |
| 66 | + mVx = vx; |
| 67 | + mVy = vy; |
| 68 | + mVz = vz; |
| 69 | + } |
| 70 | + void setPxPyPzE(const float px, const float py, const float pz, const float e) |
| 71 | + { |
| 72 | + mPx = px; |
| 73 | + mPy = py; |
| 74 | + mPz = pz; |
| 75 | + mE = e; |
| 76 | + } |
| 77 | + |
| 78 | + // Getters |
| 79 | + int pdgCode() const { return mPdgCode; } |
| 80 | + int globalIndex() const { return mGlobalIndex; } |
| 81 | + int collisionId() const { return mCollisionId; } |
| 82 | + bool isAlive() const { return mIsAlive; } |
| 83 | + bool isPrimary() const { return mIsPrimary; } |
| 84 | + bool isFromMcParticles() const { return mIsFromMcParticles; } |
| 85 | + float weight() const |
| 86 | + { |
| 87 | + static constexpr float Weight = 1.f; |
| 88 | + return Weight; |
| 89 | + } |
| 90 | + uint8_t flags() const |
| 91 | + { |
| 92 | + static constexpr uint8_t Flags = 1; |
| 93 | + return Flags; // todo |
| 94 | + } |
| 95 | + int statusCode() const |
| 96 | + { |
| 97 | + static constexpr int StatusCode = 1; |
| 98 | + return StatusCode; // todo |
| 99 | + } |
| 100 | + float vx() const { return mVx; } |
| 101 | + float vy() const { return mVy; } |
| 102 | + float vz() const { return mVz; } |
| 103 | + float vt() const { return mVt; } |
| 104 | + float px() const { return mPx; } |
| 105 | + float py() const { return mPy; } |
| 106 | + float pz() const { return mPz; } |
| 107 | + float e() const { return mE; } |
| 108 | + float radius() const { return std::hypot(mVx, mVy); } |
| 109 | + float r() const { return radius(); } |
| 110 | + float pt() const { return std::hypot(mPx, mPy); } |
| 111 | + float p() const { return std::hypot(mPx, mPy, mPz); } |
| 112 | + float phi() const { return o2::constants::math::PI + std::atan2(-1.0f * py(), -1.0f * px()); } |
| 113 | + float eta() const |
| 114 | + { |
| 115 | + // As https://github.com/AliceO2Group/AliceO2/blob/dev/Framework/Core/include/Framework/AnalysisDataModel.h#L1943 |
| 116 | + static constexpr float Tolerance = 1e-7f; |
| 117 | + if ((p() - mPz) < Tolerance) { |
| 118 | + return (mPz < 0.0f) ? -100.0f : 100.0f; |
| 119 | + } else { |
| 120 | + return 0.5f * std::log((p() + mPz) / (p() - mPz)); |
| 121 | + } |
| 122 | + } |
| 123 | + float y() const |
| 124 | + { |
| 125 | + // As https://github.com/AliceO2Group/AliceO2/blob/dev/Framework/Core/include/Framework/AnalysisDataModel.h#L1922 |
| 126 | + static constexpr float Tolerance = 1e-7f; |
| 127 | + if ((e() - mPz) < Tolerance) { |
| 128 | + return (mPz < 0.0f) ? -100.0f : 100.0f; |
| 129 | + } else { |
| 130 | + return 0.5f * std::log((mE + mPz) / (mE - mPz)); |
| 131 | + } |
| 132 | + } |
| 133 | + int getMotherIndexStart() const { return mIndicesMother[0]; } |
| 134 | + int getMotherIndexStop() const { return mIndicesMother[1]; } |
| 135 | + int getDaughterIndexStart() const { return mIndicesDaughter[0]; } |
| 136 | + int getDaughterIndexStop() const { return mIndicesDaughter[1]; } |
| 137 | + std::array<int, 2> getMothers() const { return mIndicesMother; } |
| 138 | + std::array<int, 2> getDaughters() const { return mIndicesDaughter; } |
| 139 | + std::span<const int> getMotherSpan() const { return hasMothers() ? std::span<const int>(mIndicesMother.data(), 2) : std::span<const int>(); } |
| 140 | + |
| 141 | + // Checks |
| 142 | + bool hasDaughters() const { return (mIndicesDaughter[0] > 0); } |
| 143 | + bool hasMothers() const { return (mIndicesMother[0] > 0); } |
| 144 | + bool hasNaN() const |
| 145 | + { |
| 146 | + return std::isnan(mPx) || std::isnan(mPy) || std::isnan(mPz) || std::isnan(mE) || |
| 147 | + std::isnan(mVx) || std::isnan(mVy) || std::isnan(mVz); |
| 148 | + } |
| 149 | + bool hasIndex() const |
| 150 | + { |
| 151 | + return (mGlobalIndex != -1); |
| 152 | + } |
| 153 | + |
| 154 | + private: |
| 155 | + int mPdgCode{}, mGlobalIndex{-1}; |
| 156 | + int mCollisionId{}; |
| 157 | + float mVx{}, mVy{}, mVz{}, mVt{}; |
| 158 | + float mPx{}, mPy{}, mPz{}, mE{}; |
| 159 | + bool mIsAlive{}, mIsFromMcParticles{false}; |
| 160 | + bool mIsPrimary{}; |
| 161 | + std::array<int, 2> mIndicesMother{-1, -1}, mIndicesDaughter{-1, -1}; |
| 162 | +}; |
| 163 | + |
| 164 | +} // namespace o2::upgrade |
| 165 | +#endif // ALICE3_CORE_OTFPARTICLE_H_ |
0 commit comments