AnalysisTree
Loading...
Searching...
No Matches
GenericContainerFiller.hpp
1//
2// Created by oleksii on 09.04.25.
3//
4
5#ifndef ANALYSISTREE_GENERICCONTAINERFILLER_HPP
6#define ANALYSISTREE_GENERICCONTAINERFILLER_HPP
7
8#include "Configuration.hpp"
9#include "Container.hpp"
10#include "Detector.hpp"
11
12#include <TFile.h>
13#include <TTree.h>
14
15#include <string>
16#include <vector>
17
18struct IndexMap {
19 std::string name_;
20 std::string field_type_;
21 short index_;
22};
23
24struct FICS {// FICS stands for float, int, char, short
25 float float_{-199.f};
26 int int_{-199};
27 char char_{static_cast<char>(-199)};
28 short short_{static_cast<short>(-199)};
29
30 float get() {
31 if (std::fabs(float_ + 199.f) > 1e-4) return float_;
32 if (int_ != -199) return static_cast<float>(int_);
33 if (char_ != static_cast<char>(-199)) return static_cast<float>(char_);
34 if (short_ != static_cast<short>(-199)) return static_cast<float>(short_);
35 throw std::runtime_error("GenericContainerFiller, FICS::get(): none of values initialized");
36 }
37};
38
39namespace AnalysisTree {
40
41class GenericContainerFiller {
42 public:
43 GenericContainerFiller() = delete;
44 explicit GenericContainerFiller(std::string fileInName, std::string treeInName = "pTree");
45 virtual ~GenericContainerFiller() = default;
46
47 void SetOutputFileName(const std::string& name) { file_out_name_ = name; }
48 void SetOutputTreeName(const std::string& name) { tree_out_name_ = name; }
49 void SetOutputBranchName(const std::string& name) { branch_out_name_ = name; }
50
51 void SetFieldsToIgnore(const std::vector<std::string>& fields) { fields_to_ignore_ = fields; }
52 void SetFieldsToPreserve(const std::vector<std::string>& fields) { fields_to_preserve_ = fields; }
53
54 void SetEntrySwitchTriggerVarName(const std::string& name) { entry_switch_trigger_var_name_ = name; }
55
56 void SetNChannelsPerEntry(int n) { n_channels_per_entry_ = n; }
57
58 void Run(int nEntries = -1);
59
60 protected:
61 void Init();
62 int Exec(int iEntry, int previousTriggerVar);
63 void Finish();
64
65 static int DetermineFieldIdByName(const std::vector<IndexMap>& iMap, const std::string& name);
66 static void SetAddressFICS(TBranch* branch, const IndexMap& imap, FICS& ficc);
67 static void SetFieldsFICS(const std::vector<IndexMap>& imap, AnalysisTree::Container& container, const std::vector<FICS>& ficc);
68
69 std::string file_in_name_;
70 std::string tree_in_name_;
71
72 std::string file_out_name_{"AnalysisTree.root"};
73 std::string tree_out_name_{"aTree"};
74 std::string branch_out_name_{"PlainBranch"};
75
76 TFile* file_in_{nullptr};
77 TTree* tree_in_{nullptr};
78 TFile* file_out_{nullptr};
79 TTree* tree_out_{nullptr};
80
82 AnalysisTree::GenericDetector* generic_detector_{nullptr};
83 std::vector<IndexMap> branch_map_;
84 std::vector<FICS> branch_values_;
85
86 // variable, change of value of which triggers switch to a new AT event
87 std::string entry_switch_trigger_var_name_{""};
88
89 int entry_switch_trigger_id_{-1};
90
91 // if entry_switch_trigger_var_name_ is not empty, this field does not matter
92 // if entry_switch_trigger_var_name_ is empty, sets how many AT channels
93 // will constitute a single AT entry (event)
94 int n_channels_per_entry_{-1};
95
96 std::vector<std::string> fields_to_ignore_{};
97 std::vector<std::string> fields_to_preserve_{};
98};
99}// namespace AnalysisTree
100#endif//ANALYSISTREE_GENERICCONTAINERFILLER_HPP
A class to store configuration of the whole AnalysisTree object.
Definition Configuration.hpp:58
A class to store any number of integers, floats and bools.
Definition Container.hpp:18
Cuts keep list of SimpleCuts. Logical AND is applied for all SimpleCut in the Cuts object.
Definition BranchConfig.cpp:10
Definition GenericContainerFiller.hpp:24
Definition GenericContainerFiller.hpp:18