AnalysisTree
Loading...
Searching...
No Matches
Track.hpp
1/* Copyright (C) 2019-2021 GSI, Universität Tübingen, MEPhI
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Viktor Klochkov, Eugeny Kashirin, Ilya Selyuzhenkov */
4#ifndef ANALYSISTREE_GENERICTRACK_H
5#define ANALYSISTREE_GENERICTRACK_H
6
7#include <cmath>
8#include <stdexcept>
9
10//#include <Math/Vector4D.h>
11#include <TVector3.h>
12
13#include "Container.hpp"
14
15namespace AnalysisTree {
16
22class Track : public Container {
23 public:
24 Track() = default;
25
26 explicit Track(size_t id) noexcept : Container(id) {}
27 explicit Track(const Container& cont) : Container(cont) {}
28 Track(size_t id, const BranchConfig& branch) noexcept : Container(id, branch) {}
29 Track(const Track& track) = default;
30 Track(Track&& track) = default;
31 Track& operator=(Track&&) = default;
32 Track& operator=(const Track& track) = default;
33 ~Track() override = default;
34
40 // ANALYSISTREE_ATTR_NODISCARD inline ROOT::Math::PxPyPzMVector Get4MomentumByMass(Floating_t mass) const noexcept {
41 // return {px_, py_, pz_, mass};
42 // }
43
49 // ANALYSISTREE_ATTR_NODISCARD inline ROOT::Math::PxPyPzMVector Get4Momentum(PdgCode_t pdg) const {
50 // const float mass = GetMassByPdgId(pdg);
51 // return Get4MomentumByMass(mass);
52 // }
53
54 void SetMomentum(Floating_t px, Floating_t py, Floating_t pz) noexcept {
55 px_ = px;
56 py_ = py;
57 pz_ = pz;
58 }
59
60 void SetMomentum3(const TVector3& momentum) noexcept {
61 px_ = momentum.Px();
62 py_ = momentum.Py();
63 pz_ = momentum.Pz();
64 }
65
66 void SetCharge(Int_t charge) noexcept { charge_ = charge; }
67
68 ANALYSISTREE_ATTR_NODISCARD inline Floating_t GetPx() const noexcept { return px_; }
69 ANALYSISTREE_ATTR_NODISCARD inline Floating_t GetPy() const noexcept { return py_; }
70 ANALYSISTREE_ATTR_NODISCARD inline Floating_t GetPz() const noexcept { return pz_; }
71 ANALYSISTREE_ATTR_NODISCARD inline Floating_t GetPt() const noexcept { return sqrt(px_ * px_ + py_ * py_); }
72 ANALYSISTREE_ATTR_NODISCARD inline Floating_t GetPhi() const noexcept { return atan2(py_, px_); }
73 ANALYSISTREE_ATTR_NODISCARD inline Floating_t GetEta() const noexcept { return 0.5f * log((GetP() + pz_) / (GetP() - pz_)); }
74 ANALYSISTREE_ATTR_NODISCARD inline Floating_t GetP() const noexcept { return sqrt(px_ * px_ + py_ * py_ + pz_ * pz_); }
75 ANALYSISTREE_ATTR_NODISCARD inline Integer_t GetCharge() const noexcept { return charge_; }
76
80 ANALYSISTREE_ATTR_NODISCARD inline TVector3 GetMomentum3() const noexcept { return {px_, py_, pz_}; }
81
86 friend bool operator==(const Track& that, const Track& other) noexcept;
87
93 ANALYSISTREE_ATTR_NODISCARD Floating_t GetRapidity(PdgCode_t pdg) const {
94 const float mass = GetMassByPdgId(pdg);
95 return GetRapidityByMass(mass);
96 }
97
103 ANALYSISTREE_ATTR_NODISCARD Floating_t GetRapidityByMass(float mass) const noexcept {
104 const float e = sqrt(mass * mass + GetP() * GetP());
105 return 0.5f * log((e + GetPz()) / (e - GetPz()));
106 }
107
113 template<typename T>
114 T GetField(Integer_t id) const {
115 if (id >= 0)
116 return Container::GetField<T>(id);
117 else {//TODO fix for T=int
118 switch (id) {
119 case TrackFields::kPhi: return GetPhi();
120 case TrackFields::kPt: return GetPt();
121 case TrackFields::kEta: return GetEta();
122 case TrackFields::kP: return GetP();
123 case TrackFields::kPx: return GetPx();
124 case TrackFields::kPy: return GetPy();
125 case TrackFields::kPz: return GetPz();
126 case TrackFields::kQ: return GetCharge();
127 case TrackFields::kId: return GetId();
128 default: throw std::out_of_range("Track::GetField - Index " + std::to_string(id) + " is not found");
129 }
130 }
131 }
132
133 template<typename T>
134 void SetField(T value, Int_t field_id) {
135 if (field_id >= 0) {
136 Container::SetField(value, field_id);
137 } else {
138 switch (field_id) {
139 case TrackFields::kPx: px_ = value; break;
140 case TrackFields::kPy: py_ = value; break;
141 case TrackFields::kPz: pz_ = value; break;
142 case TrackFields::kQ: charge_ = value; break;
143 case TrackFields::kId: break;
144 case TrackFields::kP: /*throw std::runtime_error("Cannot set transient fields");*/ break;
145 case TrackFields::kPt: /*throw std::runtime_error("Cannot set transient fields");*/ break;
146 case TrackFields::kEta: /*throw std::runtime_error("Cannot set transient fields");*/ break;
147 case TrackFields::kPhi: /*throw std::runtime_error("Cannot set transient fields");*/ break;
148 default: throw std::runtime_error("Unknown field");
149 }
150 }
151 }
152
156 void Print() const noexcept override;
157
158 protected:
159 static float GetMassByPdgId(PdgCode_t pdg);
160 static int GetChargeByPdgId(PdgCode_t pdg);
161
162 Floating_t px_{UndefValueFloat};
163 Floating_t py_{UndefValueFloat};
164 Floating_t pz_{UndefValueFloat};
165 Integer_t charge_{-1000};
166
167 ClassDefOverride(Track, 2);
168};
169
170}// namespace AnalysisTree
171#endif//ANALYSISTREE_GENERICTRACK_H
A class to store configuration of the Container.
Definition BranchConfig.hpp:118
A class to store any number of integers, floats and bools.
Definition Container.hpp:18
A class for a generic track with determined momentum.
Definition Track.hpp:22
Floating_t px_
x-component of track's momentum
Definition Track.hpp:162
T GetField(Integer_t id) const
Definition Track.hpp:114
ANALYSISTREE_ATTR_NODISCARD Floating_t GetRapidity(PdgCode_t pdg) const
Definition Track.hpp:93
Floating_t pz_
z-component of track's momentum
Definition Track.hpp:164
Floating_t py_
y-component of track's momentum
Definition Track.hpp:163
void Print() const noexcept override
Definition Track.cpp:12
friend bool operator==(const Track &that, const Track &other) noexcept
Definition Track.cpp:18
void SetMomentum(Floating_t px, Floating_t py, Floating_t pz) noexcept
Definition Track.hpp:54
ANALYSISTREE_ATTR_NODISCARD Floating_t GetRapidityByMass(float mass) const noexcept
Definition Track.hpp:103
ANALYSISTREE_ATTR_NODISCARD TVector3 GetMomentum3() const noexcept
Definition Track.hpp:80
Cuts keep list of SimpleCuts. Logical AND is applied for all SimpleCut in the Cuts object.
Definition BranchConfig.cpp:10