AnalysisTree
Loading...
Searching...
No Matches
Particle.hpp
1/* Copyright (C) 2019-2021 GSI, Universität Tübingen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Viktor Klochkov, Ilya Selyuzhenkov */
4#ifndef ANALYSISTREE_SRC_PARTICLE_H_
5#define ANALYSISTREE_SRC_PARTICLE_H_
6
7#include "Track.hpp"
8
9namespace AnalysisTree {
10
11class Particle : public Track {
12
13 public:
14 Particle() = default;
15 explicit Particle(size_t id) : Track(id) {}
16 Particle(size_t id, const BranchConfig& branch) noexcept : Track(id, branch) {}
17
18 explicit Particle(const Container& cont) : Track(cont) {}
19 explicit Particle(const Track& track) : Track(track) {}
20
21 Particle(const Particle& particle) = default;
22 Particle(Particle&& particle) = default;
23 Particle& operator=(Particle&&) = default;
24 Particle& operator=(const Particle& particle) = default;
25 ~Particle() override = default;
26
27 ANALYSISTREE_ATTR_NODISCARD Floating_t GetRapidity() const { return Track::GetRapidityByMass(mass_); }
28 ANALYSISTREE_ATTR_NODISCARD PdgCode_t GetPid() const { return pid_; }
29 ANALYSISTREE_ATTR_NODISCARD Floating_t GetMass() const { return mass_; }
30
31 void SetMass(Floating_t mass) {
32 CheckIsAllowedSetMassAndChargeExplicitly();
33 mass_ = mass;
34 }
35
36 void SetCharge(Int_t charge) {
37 CheckIsAllowedSetMassAndChargeExplicitly();
38 Track::SetCharge(charge);
39 }
40
41 void SetPid(PdgCode_t pid);
42
43 void SetIsAllowedSetMassAndChargeExplicitly(bool is = true) { is_allowed_set_charge_and_mass_explicitly_ = is; }
44
45 void CheckIsAllowedSetMassAndChargeExplicitly() const;
46
47 ANALYSISTREE_ATTR_NODISCARD Floating_t GetEnergy() const { return sqrt(mass_ * mass_ + GetP() * GetP()); }
48 ANALYSISTREE_ATTR_NODISCARD Floating_t GetKineticEnergy() const { return GetEnergy() - mass_; }
49
50 template<typename T>
51 T GetField(Integer_t iField) const {
52 if (iField >= 0)
53 return Container::GetField<T>(iField);
54 else {//TODO fix for T=int
55 switch (iField) {
56 case ParticleFields::kPhi: return GetPhi();
57 case ParticleFields::kPt: return GetPt();
58 case ParticleFields::kRapidity: return GetRapidity();
59 case ParticleFields::kPid: return GetPid();
60 case ParticleFields::kMass: return GetMass();
61 case ParticleFields::kEta: return GetEta();
62 case ParticleFields::kP: return GetP();
63 case ParticleFields::kEnergy: return GetEnergy();
64 case ParticleFields::kKineticEnergy: return GetKineticEnergy();
65 case ParticleFields::kPx: return GetPx();
66 case ParticleFields::kPy: return GetPy();
67 case ParticleFields::kPz: return GetPz();
68 case ParticleFields::kQ: return GetCharge();
69 case ParticleFields::kId: return GetId();
70 default: throw std::out_of_range("Particle::GetField - Index " + std::to_string(iField) + " is not found");
71 }
72 }
73 }
74
75 template<typename T>
76 void SetField(T value, Int_t field_id) {
77 if (field_id >= 0) {
78 Container::SetField(value, field_id);
79 } else {
80 switch (field_id) {
81 case ParticleFields::kPx: px_ = value; break;
82 case ParticleFields::kPy: py_ = value; break;
83 case ParticleFields::kPz: pz_ = value; break;
84 case ParticleFields::kMass: mass_ = value; break;
85 case ParticleFields::kQ: charge_ = value; break;
86 case ParticleFields::kPid: SetPid(value); break;
87 case ParticleFields::kId: break;
88 case ParticleFields::kP: /*throw std::runtime_error("Cannot set transient fields");*/ break;
89 case ParticleFields::kEnergy: /*throw std::runtime_error("Cannot set transient fields");*/ break;
90 case ParticleFields::kKineticEnergy: /*throw std::runtime_error("Cannot set transient fields");*/ break;
91 case ParticleFields::kPt: /*throw std::runtime_error("Cannot set transient fields");*/ break;
92 case ParticleFields::kEta: /*throw std::runtime_error("Cannot set transient fields");*/ break;
93 case ParticleFields::kPhi: /*throw std::runtime_error("Cannot set transient fields");*/ break;
94 case ParticleFields::kRapidity: /*throw std::runtime_error("Cannot set transient fields");*/ break;
95 default: throw std::runtime_error("Particle::SetField - Index " + std::to_string(field_id) + " is not found");
96 }
97 }
98 }
99
100 protected:
101 Floating_t mass_{-1000.f};
102 PdgCode_t pid_{0};
103 bool is_allowed_set_charge_and_mass_explicitly_{false};
104
105 ClassDefOverride(Particle, 2);
106};
107
108}// namespace AnalysisTree
109
110#endif//ANALYSISTREE_SRC_PARTICLE_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
Definition Particle.hpp:11
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
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
ANALYSISTREE_ATTR_NODISCARD Floating_t GetRapidityByMass(float mass) const noexcept
Definition Track.hpp:103
Cuts keep list of SimpleCuts. Logical AND is applied for all SimpleCut in the Cuts object.
Definition BranchConfig.cpp:10