AnalysisTree
Loading...
Searching...
No Matches
Hit.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_SRC_HIT_H_
5#define ANALYSISTREE_SRC_HIT_H_
6
7#include <stdexcept>
8
9#include <TVector3.h>
10
11#include "Constants.hpp"
12#include "Container.hpp"
13
14namespace AnalysisTree {
15
16class Hit : public Container {
17
18 public:
19 Hit() = default;
20 explicit Hit(const Container& cont) : Container(cont) {}
21 Hit(const Hit& otherHit) = default;
22 Hit(Hit&& otherHit) = default;
23 Hit& operator=(Hit&&) = default;
24 Hit& operator=(const Hit& part) = default;
25
26 explicit Hit(size_t id) : Container(id) {}
27 Hit(size_t id, const BranchConfig& branch) noexcept : Container(id, branch) {}
28
29 friend bool operator==(const Hit& that, const Hit& other);
30
31 void SetPosition(const TVector3& position) {
32 x_ = position.X();
33 y_ = position.Y();
34 z_ = position.Z();
35 }
36
37 void SetPosition(Double_t x, Double_t y, Double_t z) {
38 x_ = x;
39 y_ = y;
40 z_ = z;
41 }
42
43 void SetSignal(Double_t signal) {
44 signal_ = signal;
45 }
46
47 ANALYSISTREE_ATTR_NODISCARD TVector3 GetPosition() const { return TVector3(x_, y_, z_); }
48 ANALYSISTREE_ATTR_NODISCARD Floating_t GetSignal() const { return signal_; }
49 ANALYSISTREE_ATTR_NODISCARD Floating_t GetX() const { return x_; }
50 ANALYSISTREE_ATTR_NODISCARD Floating_t GetY() const { return y_; }
51 ANALYSISTREE_ATTR_NODISCARD Floating_t GetZ() const { return z_; }
52 ANALYSISTREE_ATTR_NODISCARD Floating_t GetPhi() const;
53
54 template<typename T>
55 ANALYSISTREE_ATTR_NODISCARD T GetField(Integer_t iField) const {
56 if (iField >= 0)
57 return Container::GetField<T>(iField);
58 else {
59 switch (iField) {
60 case HitFields::kX: return GetX();
61 case HitFields::kY: return GetY();
62 case HitFields::kZ: return GetZ();
63 case HitFields::kPhi: return GetPhi();
64 case HitFields::kSignal: return GetSignal();
65 case HitFields::kId: return GetId();
66 default: throw std::out_of_range("Hit::GetField - Index " + std::to_string(iField) + " is not found");
67 }
68 }
69 }
70
71 template<typename T>
72 void SetField(T value, Int_t field_id) {
73 if (field_id >= 0) {
74 Container::SetField(value, field_id);
75 } else {
76 switch (field_id) {
77 case HitFields::kX: x_ = value; break;
78 case HitFields::kY: y_ = value; break;
79 case HitFields::kZ: z_ = value; break;
80 case HitFields::kSignal: signal_ = value; break;
81 case HitFields::kId: break;
82 case HitFields::kPhi: /*throw std::runtime_error("Cannot set transient fields");*/ break;
83 default: throw std::runtime_error("Unknown field");
84 }
85 }
86 }
87
88 void Print() const noexcept override;
89
90 protected:
91 Floating_t x_{UndefValueFloat};
92 Floating_t y_{UndefValueFloat};
93 Floating_t z_{UndefValueFloat};
94 Floating_t signal_{UndefValueFloat};
95
96 ClassDefOverride(Hit, 2)
97};
98
99}// namespace AnalysisTree
100#endif//ANALYSISTREE_SRC_HIT_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 Hit.hpp:16
Cuts keep list of SimpleCuts. Logical AND is applied for all SimpleCut in the Cuts object.
Definition BranchConfig.cpp:10