AnalysisTree
Loading...
Searching...
No Matches
EventHeader.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_BASEEVENTHEADER_H
5#define ANALYSISTREE_BASEEVENTHEADER_H
6
7#include "Container.hpp"
8#include <array>
9#include <stdexcept>
10
11class TVector3;
12
13namespace AnalysisTree {
14
18class EventHeader : public Container {
19 public:
20 EventHeader() = default;
21 explicit EventHeader(size_t id) : Container(id){};
22 explicit EventHeader(const Container& cont) : Container(cont) {}
23 EventHeader(size_t id, const BranchConfig& branch) noexcept : Container(id, branch) {}
24
25 EventHeader(const EventHeader& eh) = default;
26 EventHeader(EventHeader&& eh) = default;
27 EventHeader& operator=(EventHeader&& eh) = default;
28 EventHeader& operator=(const EventHeader& eh) = default;
29
33 ANALYSISTREE_ATTR_NODISCARD TVector3 GetVertexPosition3() const;
34
35 void SetVertexPosition3(const TVector3& pos);
36
37 template<typename T>
38 T GetField(Integer_t iField) const {
39 if (iField >= 0)
40 return Container::GetField<T>(iField);
41 else {
42 switch (iField) {
43 case EventHeaderFields::kVertexX: return GetVertexX();
44 case EventHeaderFields::kVertexY: return GetVertexY();
45 case EventHeaderFields::kVertexZ: return GetVertexZ();
46 case EventHeaderFields::kId: return GetId();
47 default: throw std::out_of_range("EventHeader::GetField - Index " + std::to_string(iField) + " is not found");
48 }
49 }
50 }
51
52 template<typename T>
53 void SetField(T value, Integer_t field_id) {
54 using AnalysisTree::EventHeaderFields::EventHeaderFields;
55 if (field_id >= 0) {
56 Container::SetField(value, field_id);
57 } else {
58 switch (field_id) {
59 case EventHeaderFields::kVertexX: vtx_pos_[Exyz::kX] = value; break;
60 case EventHeaderFields::kVertexY: vtx_pos_[Exyz::kY] = value; break;
61 case EventHeaderFields::kVertexZ: vtx_pos_[Exyz::kZ] = value; break;
62 case EventHeaderFields::kId: break;
63 default: throw std::runtime_error("Invalid field id");
64 }
65 }
66 }
67
68 ANALYSISTREE_ATTR_NODISCARD inline Floating_t GetVertexX() const { return vtx_pos_[Exyz::kX]; }
69 ANALYSISTREE_ATTR_NODISCARD inline Floating_t GetVertexY() const { return vtx_pos_[Exyz::kY]; }
70 ANALYSISTREE_ATTR_NODISCARD inline Floating_t GetVertexZ() const { return vtx_pos_[Exyz::kZ]; }
71
72 static constexpr size_t GetNumberOfChannels() { return 1; }// needed in order to have EventHeader similar to Detector
73 EventHeader* begin() { return this; }
74 EventHeader* end() { return this; }
75 const EventHeader* cbegin() const { return this; }
76 const EventHeader* cend() const { return this; }
77
78 ANALYSISTREE_ATTR_NODISCARD const EventHeader& GetChannel(size_t i) const;// needed in order to have EventHeader similar to Detector
79 ANALYSISTREE_ATTR_NODISCARD EventHeader& Channel(size_t i); // needed in order to have EventHeader similar to Detector
80 static void ClearChannels() { throw std::runtime_error("Not available for EventHeader"); }
81 static EventHeader* AddChannel() { throw std::runtime_error("Not available for EventHeader"); }
82
83 void Print() const noexcept override;
84
85 protected:
86 std::array<Floating_t, 3> vtx_pos_{{UndefValueFloat, UndefValueFloat, UndefValueFloat}};
87
88 ClassDefOverride(EventHeader, 2)
89};
90
91}// namespace AnalysisTree
92#endif//ANALYSISTREE_BASEEVENTHEADER_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 EventHeader.hpp:18
ANALYSISTREE_ATTR_NODISCARD TVector3 GetVertexPosition3() const
Definition EventHeader.cpp:10
Cuts keep list of SimpleCuts. Logical AND is applied for all SimpleCut in the Cuts object.
Definition BranchConfig.cpp:10