R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandCalibrationTask.cxx
Go to the documentation of this file.
3#include <FairParSet.h>
4#include <FairRootManager.h>
5#include <FairRuntimeDb.h>
6#include <FairTask.h>
7#include <R3BEventHeader.h>
8#include <R3BException.h>
9#include <R3BLogger.h>
10#include <RtypesCore.h>
11#include <TH1.h>
12#include <fairlogger/Logger.h>
13#include <fmt/core.h>
14#include <range/v3/algorithm/find_if.hpp>
15#include <range/v3/algorithm/for_each.hpp>
16#include <string_view>
17
18namespace R3B::Neuland
19{
20
21 CalibrationTask::CalibrationTask(std::string_view name, int iVerbose)
22 : FairTask(name.data(), iVerbose)
23 {
24 }
25
27 : CalibrationTask("NeulandCalibrationReader", 1)
28 {
29 }
30
32 {
33 if (auto* rtdb = FairRuntimeDb::instance(); rtdb != nullptr)
34 {
35 SetExtraPar(rtdb);
36 }
37 else
38 {
39 throw R3B::runtime_error("Fail to get a non-nullptr FairRuntimeDb!");
40 }
41 }
42
43 auto CalibrationTask::Init() -> InitStatus
44 {
45 if (auto* rootMan = FairRootManager::Instance(); rootMan != nullptr)
46 {
47 if (eventHeader_ = dynamic_cast<R3BEventHeader*>(rootMan->GetObject("EventHeader."));
48 eventHeader_ == nullptr)
49 {
50 throw R3B::logic_error("R3BEventHeader is required. But it's nullptr!");
51 }
52
54 offspill_tpat_bit_ = base_par_->get_offspill_tpat_pos();
55
56 ExtraInit(rootMan);
57
58 if (not is_hist_disabled_)
59 {
61 }
62
63 LOGP(info,
64 "Neuland calibration task \"{}\" has event trigger type: {}",
65 GetName(),
67 return kSUCCESS;
68 }
69 return kFATAL;
70 }
71
72 void CalibrationTask::Exec(Option_t* /*option*/)
73 {
75 LOGP(debug, "Event number: {}, tpat: {:016b}", eventHeader_->GetEventno(), eventHeader_->GetTpat());
77 }
78
80 {
81 if (!check_trigger())
82 {
83 hist_trig_check_->Fill(fmt::format("{:016b}", eventHeader_->GetTpat()).c_str(), 1);
84 return;
85 }
86 hist_trig_check_->Fill("triggered", 1);
87 if (!CheckConditions())
88 {
89 hist_condition_check_->Fill("failure", 1);
90 return;
91 }
92 hist_condition_check_->Fill("success", 1);
95 }
96
98 {
100 {
103 }
104 }
105
107 {
108 EndOfTask();
109 LOGP(info,
110 R"(Passed events with the trigger type "{}" in task "{}": {})",
112 GetName(),
115 {
116 histograms_.save_to_sink(GetName());
117 }
118 else
119 {
120 LOGP(info,
121
122 "Figures not saved due to current configuration: hist_disabled = {}, write_hist_disabled = {}",
125 }
126 ranges::for_each(output_pars_, [](FairParSet* par) { par->setChanged(); });
127 reset();
128 }
129
131 {
132 LOGP(debug2,
133 R"(From task "{}": tpat {}. Trig type {})",
134 GetName(),
135 eventHeader_->GetTpat(),
138 }
139
141 {
142 hist_trig_check_ = histograms_.add_hist<TH1I>("trig_check", "check the triggered or passed events", 1, 0., 0.);
143 hist_condition_check_ = histograms_.add_hist<TH1I>("condition_check", "check the condition", 1, 0., 0.);
145 }
146
148 {
149 auto par_not_changed = ranges::find_if(input_pars_, [](auto* par) { return !par->hasChanged(); });
150 if (par_not_changed != input_pars_.end())
151 {
152 auto par_name = std::string_view{ (*par_not_changed)->GetName() };
153 throw R3B::runtime_error(
154 fmt::format(R"(Calibration parameter "{}" is not initiated from the root file!)", par_name));
155 }
156 }
158 {
160 histograms_.reset_all_hists();
161 }
162} // namespace R3B::Neuland
virtual void SetExtraPar(FairRuntimeDb *rtdb)
virtual void ExtraInit(FairRootManager *rootMan)
virtual auto CheckConditions() const -> bool
virtual void HistogramInit(DataMonitor &histograms)
auto Init() -> InitStatus override
virtual void TriggeredExec()=0
void Exec(Option_t *option) override
std::vector< FairParSet * > output_pars_
std::vector< FairParSet * > input_pars_
Simulation of NeuLAND Bar/Paddle.
auto CheckTriggerWithTpat(CalTrigger trigger, int tpat, int off_spill_bit) -> bool
auto CalTrigger2Str(CalTrigger cal_trigger) -> std::string
constexpr auto CalTrigger2Tpat(CalTrigger cal_trigger, int off_spill_bit) -> std::bitset< TPAT_BITSIZE >