R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandCalibrationTask.h
Go to the documentation of this file.
1#pragma once
2/******************************************************************************
3 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
4 * Copyright (C) 2019-2023 Members of R3B Collaboration *
5 * *
6 * This software is distributed under the terms of the *
7 * GNU General Public Licence (GPL) version 3, *
8 * copied verbatim in the file "LICENSE". *
9 * *
10 * In applying this license GSI does not waive the privileges and immunities *
11 * granted to it by virtue of its status as an Intergovernmental Organization *
12 * or submit itself to any jurisdiction. *
13 ******************************************************************************/
14
15#include "R3BDataMonitor.h"
16#include "R3BNeulandBasePar.h"
18#include <FairRuntimeDb.h>
19#include <FairTask.h>
20#include <R3BEventHeader.h>
21
22class FairParSet;
23
24namespace R3B::Neuland
25{
26 class CalibrationTask : public FairTask
27 {
28 public:
30 explicit CalibrationTask(std::string_view name, int iVerbose = 1);
31
32 // Getters:
33 [[nodiscard]] auto GetEventHeader() const -> auto* { return eventHeader_; }
34 [[nodiscard]] auto GetHistMonitor() -> DataMonitor& { return histograms_; }
35 [[nodiscard]] auto IsHistDisabled() const -> bool { return is_hist_disabled_; }
36
37 void SetTrigger(CalTrigger trigger) { trig_type_ = trigger; }
38 void SetDisableHist(bool is_hist_disabled = true) { is_hist_disabled_ = is_hist_disabled; }
39 void SetDisableHistWrite(bool is_write_hist_disabled = true)
40 {
41 is_write_hist_disabled_ = is_write_hist_disabled;
42 }
43
44 auto GetBasePar() -> auto* { return base_par_; }
45 // void SetOnline()
46
47 protected:
48 template <typename ParType>
49 auto InputPar(std::string_view par_name, FairRuntimeDb* rtdb = FairRuntimeDb::instance()) -> ParType*
50 {
51 return add_par<ParType>(par_name, input_pars_, rtdb);
52 }
53
54 template <typename ParType>
55 auto OutputPar(std::string_view par_name, FairRuntimeDb* rtdb = FairRuntimeDb::instance()) -> ParType*
56 {
57 return add_par<ParType>(par_name, output_pars_, rtdb);
58 }
59
60 private:
61 bool is_hist_disabled_ = false;
62 bool is_write_hist_disabled_ = false;
63 int offspill_tpat_bit_ = 0;
64 int64_t passed_num_of_events = 0;
65 CalTrigger trig_type_ = CalTrigger::all;
66 R3BEventHeader* eventHeader_ = nullptr;
67 std::vector<FairParSet*> input_pars_;
68 std::vector<FairParSet*> output_pars_;
69
70 CalibrationBasePar* base_par_ = InputPar<CalibrationBasePar>("NeulandCalibrationBasePar");
71 TH1I* hist_trig_check_ = nullptr;
72 TH1I* hist_condition_check_ = nullptr;
73
74 // helpers:
75 DataMonitor histograms_;
76
77 // virtual functions:
78 virtual void HistogramInit(DataMonitor& histograms) {}
79 virtual void ExtraInit(FairRootManager* rootMan) {}
80 virtual void SetExtraPar(FairRuntimeDb* rtdb) {}
81 virtual void BeginOfEvent() {};
82 virtual void TriggeredExec() = 0;
83 virtual void EndOfTask() {};
84 [[nodiscard]] virtual auto CheckConditions() const -> bool { return true; }
85
86 // overriden functions:
87 auto Init() -> InitStatus override;
88 void SetParContainers() override;
89 void Exec(Option_t* option) override;
90 void FinishTask() override;
91
92 // private functions:
93 void init_histogram();
94 void check_input_par();
95 void execute_no_hist();
96 void execute_with_hist();
97 void reset();
98
99 [[nodiscard]] auto check_trigger() const -> bool;
100 template <typename ParType>
101 [[nodiscard]] auto add_par(std::string_view par_name,
102 std::vector<FairParSet*>& pars,
103 FairRuntimeDb* rtdb) -> ParType*;
104 };
105
106 template <typename ParType>
107 auto CalibrationTask::add_par(std::string_view par_name,
108 std::vector<FairParSet*>& pars,
109 FairRuntimeDb* rtdb) -> ParType*
110 {
111 auto* par = dynamic_cast<ParType*>(rtdb->findContainer(par_name.data()));
112 if (par == nullptr)
113 {
114 par = std::make_unique<ParType>(par_name.data()).release();
115 if (rtdb->addContainer(par); par == nullptr)
116 {
117 throw R3B::runtime_error("Calibration parameter becomes nullptr!");
118 }
119 }
120 pars.push_back(par);
121 return par;
122 }
123
124}; // 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
void SetDisableHist(bool is_hist_disabled=true)
virtual void TriggeredExec()=0
auto InputPar(std::string_view par_name, FairRuntimeDb *rtdb=FairRuntimeDb::instance()) -> ParType *
auto OutputPar(std::string_view par_name, FairRuntimeDb *rtdb=FairRuntimeDb::instance()) -> ParType *
void Exec(Option_t *option) override
void SetDisableHistWrite(bool is_write_hist_disabled=true)
Simulation of NeuLAND Bar/Paddle.