38 unsigned int max_bin_number_ = 0;
39 double cycle_period_ = 0.;
43 template <
typename Derived>
48 FTBaseCal(std::string_view hist_name,
unsigned int moduleNum,
const std::vector<FTType>& types)
49 : hist_name_(hist_name)
50 , moduleNum_{ moduleNum }
52 EmptyInitAllDistributions(types);
57 for (
auto& [type, distribution] : fTDistribution_)
59 distribution = std::unique_ptr<TH1>(
dynamic_cast<TH1*
>(hist->Clone()));
60 distribution->SetDirectory(
nullptr);
61 auto name = fmt::format(
"{0}_{1:04d}_{2}", hist_name_, moduleNum_,
FTType2Str(type));
62 distribution->SetNameTitle(name.c_str(), name.c_str());
68 for (
const auto& [_, distribution] : fTDistribution_)
72 fmt::format(
"Writting histogram {} into sink file {}", distribution->GetName(), sink->GetName()));
73 sink->WriteObject(distribution.get(), distribution->GetName());
79 std::map<FTType, FTChannel2TimeRelation> valueErrors)
83 for (
const auto& [type, rel] : valueErrors)
85 R3BLOG(debug4, fmt::format(
"type: {} CalRelSize: {}",
FTType2Str(type), rel.value_error.size()));
95 [[nodiscard]]
auto GetHistName() const -> const auto& {
return hist_name_; }
96 [[nodiscard]]
auto GetModuleNum() const -> const auto& {
return moduleNum_; }
98 template <
typename... Args>
101 auto* hist =
static_cast<typename Derived::HistType*
>(
GetDistribution(type));
102 hist->Fill(std::forward<Args>(args)...);
106 std::string_view hist_name_;
107 unsigned int moduleNum_ = 0;
109 std::map<FTType, std::unique_ptr<TH1>> fTDistribution_;
111 void EmptyInitAllDistributions(
const std::vector<FTType>& types)
113 for (
const auto& type : types)
115 fTDistribution_.insert_or_assign(type,
nullptr);
125 explicit ModuleCal(std::string_view hist_name,
unsigned int mID);
127 template <
typename Strategy>
131 auto correlations = std::map<FTType, FTChannel2TimeRelation>{};
132 for (
const auto& [ftType, distribution2D] : distributions)
134 auto* hist =
static_cast<HistType*
>(distribution2D.get());
137 correlations.insert_or_assign(ftType, strategy.GetChannel2Time(hist));
149 explicit PlaneCal(std::string_view hist_name,
unsigned int mID);
159 auto correlations = std::map<FTType, FTChannel2TimeRelation>{};
160 for (
const auto& [ftType, distribution2D] : distributions)
162 auto* hist2D =
static_cast<HistType*
>(distribution2D.get());
163 auto* hist1D = hist2D->ProjectionY(
"projection", barNum, barNum);
164 if (hist1D !=
nullptr)
166 correlations.insert_or_assign(ftType, strategy.
GetChannel2Time(hist1D));
174 template <
typename CalType>
179 : hist_name_{ std::move(hist_name) }
183 template <
typename... AdditionalPar>
184 void Fill(
FTType type,
unsigned int ftValue,
unsigned int moduleNum, AdditionalPar&&... pars)
186 auto iter = cals_.find(moduleNum);
187 if (iter == cals_.end())
189 iter = cals_.emplace(moduleNum, CalType{ hist_name_, moduleNum }).first;
191 iter->second.Fill(type, ftValue, std::forward<AdditionalPar>(pars)...);
194 template <
typename Strategy>
197 for (
auto& [_, cal] : cals_)
199 cal.Write_to_par(write_strategy, t_cal_par);
205 for (
auto& [_, cal] : cals_)
207 cal.WriteHist2File(sink);
212 std::map<unsigned int, CalType> cals_;
213 std::string hist_name_;
#define R3BLOG(severity, x)
void SetModuleParam(unsigned int module_num, TCalVFTXModulePar par)
void InitAllDistributions(TH1 *hist)
auto GetModuleNum() const -> const auto &
FTBaseCal(std::string_view hist_name, unsigned int moduleNum, const std::vector< FTType > &types)
void Write2Par(unsigned int moduleID, Map2CalPar &t_cal_par, std::map< FTType, FTChannel2TimeRelation > valueErrors)
auto GetAllDistributions() -> const auto &
void AddFineTime(FTType type, Args &&... args)
auto GetHistName() const -> const auto &
auto GetDistribution(FTType type)
void WriteHist2File(TDirectory *sink)
TCalVFTXModulePar::ValueErrors ValueErrors
TCalVFTXModulePar::ValueErrors ValueErrors
void Set_max_bin_number(unsigned int num)
auto GetChannel2Time(TH1 *hist) const -> FTChannel2TimeRelation
auto Get_cycle_period() const -> auto
void Set_error_method(FTCalErrorMethod method)
void Set_cycle_period(double time)
void Writer_to_TCalPar(const Strategy &write_strategy, Map2CalPar &t_cal_par)
void WriteHist2File(TDirectory *sink)
void Fill(FTType type, unsigned int ftValue, unsigned int moduleNum, AdditionalPar &&... pars)
FTEngine(std::string hist_name)
void Fill(FTType type, unsigned int ftValue)
ModuleCal(std::string_view hist_name, unsigned int mID)
void Write_to_par(const Strategy &strategy, Map2CalPar &t_cal_par)
void Write_to_par(const FTCalStrategy &strategy, Map2CalPar &t_cal_par)
void Fill(FTType type, unsigned int ftValue, unsigned int barID)
PlaneCal(std::string_view hist_name, unsigned int mID)
std::vector< ValueError< double > > ValueErrors
void Set_correlation(std::map< FTType, FTChannel2TimeRelation > correlation)
auto FTType2Str(FTType type) -> std::string_view
constexpr auto BarsPerPlane
constexpr auto Neuland_PlaneBar2ModuleNum(unsigned int planeNum, unsigned int barNum) -> unsigned int