24#include <FairRootManager.h>
31#include <fairlogger/Logger.h>
33#include <fmt/format.h>
34#include <fmt/ranges.h>
36#include <range/v3/view/map.hpp>
44 auto GetWalkCorrection(
double value) ->
double
46 value = value * 17.2278 / 162.464;
47 const auto veronika3 = -4.29359 + 17.3841 / sqrt(value) + 0.073181;
48 const auto veronika2 = 1.59667 + 78.5274 * pow(value, -1.97051) - 4.00192 / value - 0.125473 * value +
49 0.00130958 * value * value;
50 const auto result = (value > 25.0000) ? veronika3 : (veronika3 + veronika2) / 2.;
66 ,
cal_data_{ get_from_sep_string(0, config.write) }
80 constexpr auto BINSIZE_TOT = 1000;
81 constexpr auto BINSIZE_LT = 1000;
82 constexpr auto BINSIZE_TIME = 8000;
83 constexpr auto HIST_MAX_TIME = 6000.;
84 constexpr auto HIST_MIN_TIME = -5000.;
85 constexpr auto HIST_MAX_TOT = 600.;
86 constexpr auto HIST_MAX_LT = 2000.;
88 histograms.
add_hist<TH1D>(
"module_num",
"Counts with module ids", total_bar_num, -0.5, total_bar_num + 0.5);
89 histograms.
add_hist<TH1D>(
"ToT",
"Time over threshold", BINSIZE_TOT * 2, 0., BINSIZE_TOT + 0.);
90 histograms.
add_hist<TH1D>(
"LeadingTime",
"Leading time", BINSIZE_LT, 0., HIST_MAX_LT);
91 histograms.
add_hist<TH1D>(
"TriggerTime",
"Trigger time", BINSIZE_LT, 0., HIST_MAX_LT);
92 histograms.
add_hist<TH1D>(
"Leading_minus_trigger",
"Time", BINSIZE_TIME, HIST_MIN_TIME, HIST_MAX_TIME);
94 "Bar_hitNum_l",
"Number of hits on the left PMT per bar", total_bar_num, 0.5, 0.5 + total_bar_num);
96 "Bar_hitNum_r",
"Number of hits on the right PMT per bar", total_bar_num, 0.5, 0.5 + total_bar_num);
98 histograms.
add_hist<TH2D>(
"TimeLVsBar",
106 histograms.
add_hist<TH2D>(
"TimeRVsBar",
116 "ToTLVsBar",
"ToT_vs_bar_left", total_bar_num, 0.5, 0.5 + total_bar_num, BINSIZE_TOT, 0., HIST_MAX_TOT);
118 "ToTRVsBar",
"ToT_vs_bar_right", total_bar_num, 0.5, 0.5 + total_bar_num, BINSIZE_TOT, 0., HIST_MAX_TOT);
134 LOGP(warn,
"plane number obtained from the calibration parameters is 0!");
152 LOGP(warn,
"Coarse time frequency obtained from parameters is 0! Use default value.");
159 LOGP(info,
"Coarse time frequency set to be {} MHz", ct_freq);
168 "Minimal signal size: {}. Current signal size: {}. Number of PMTs: {}",
172 if (std::cmp_less(signal_size,
config_.min_stat))
175 "condition of the minimal size is not met with current paddle signal size. Skip the "
190 const auto& modulePar = calPar->GetParamAt(module_num);
191 const auto fineTime = modulePar.GetFineTime(ftType, signal.fine);
195 return { coarseTime - fineTime.value, fineTime.error };
201 const auto& triggerMap =
GetBasePar()->get_trig_id_map();
202 auto triggerIDPair = triggerMap.find(module_num);
203 if (triggerIDPair == triggerMap.end())
206 LOGP(error,
"Can't find the trigger ID for the module ID {} in the event {}", module_num, eventNum);
209 const auto triggerID = (side ==
Side::left) ? triggerIDPair->second.first : triggerIDPair->second.second;
210 const auto trigData = std::ranges::find_if(
211 trig_map_data_, [&triggerID](
const auto& ele) ->
bool {
return ele.first == triggerID; });
216 "No such trigger ID {} in mappedTrigData for moduleNum {} in the event {}!",
220 LOGP(error,
"Available trigIDs: {}", fmt::join(
trig_map_data_ | ranges::views::keys,
", "));
234 const auto time_over_thresh = trailingT - leadingT;
235 LOGP(debug3,
"leading :{} trailing: {}", leadingT.value, trailingT.value);
236 return (time_over_thresh.value > 0) ? time_over_thresh : time_over_thresh +
max_coarse_time_;
254 calDataSignal.time_over_threshold =
get_tot(double_edge_signal, module_num, side);
255 const auto walk_correction =
256 (
config_.enable_walk_effect) ? GetWalkCorrection(calDataSignal.time_over_threshold.value) : 0.;
257 calDataSignal.leading_time =
262 LOGP(debug,
"Adding a new cal signal: {}", calDataSignal);
263 return calDataSignal;
268 R3B::Side side)
const -> std::vector<CalDataSignal>
270 const auto& signals = (side ==
Side::left) ? map_bar_signals.left : map_bar_signals.right;
271 auto calSignals = std::vector<CalDataSignal>{};
272 calSignals.reserve(signals.size());
273 std::ranges::transform(signals,
274 std::back_inserter(calSignals),
275 [module_num, side,
this](
const auto& dESignal) ->
CalDataSignal
294 LOGP(debug2,
"mapped Data size: {}",
map_data_.size());
300 for (
const auto& [plane_num, plane_signals] :
map_data_)
302 for (
const auto& [bar_num, bar_signals] : plane_signals.bars)
309 auto& cal =
cal_data_.get().emplace_back(module_num);
321 for (
const auto& signal : calSignals)
323 const auto lTime = signal.leading_time.value;
324 const auto time_over_thresh = signal.time_over_threshold.value;
325 const auto triggerTime = signal.trigger_time.value;
326 histograms.get(
"ToT")->Fill(time_over_thresh);
327 histograms.get(
"LeadingTime")->Fill(lTime);
328 histograms.get(
"TriggerTime")->Fill(triggerTime);
329 histograms.get(
"Leading_minus_trigger")->Fill(lTime - triggerTime);
332 histograms.get(
"TimeLVsBar")->Fill(module_num, lTime - triggerTime);
333 histograms.get(
"ToTLVsBar")->Fill(module_num, time_over_thresh);
334 histograms.get(
"Bar_hitNum_l")->Fill(module_num);
338 histograms.get(
"TimeRVsBar")->Fill(module_num, lTime - triggerTime);
339 histograms.get(
"ToTRVsBar")->Fill(module_num, time_over_thresh);
340 histograms.get(
"Bar_hitNum_r")->Fill(module_num);
R3B::Map2CalPar R3BTCalPar2
auto add_hist(std::unique_ptr< TH1 > hist) -> TH1 *
auto IsHistDisabled() const -> bool
auto GetHistMonitor() -> DataMonitor &
auto GetEventHeader() const -> auto *
void SetTrigger(CalTrigger trigger)
auto GetBasePar() const -> auto *
static void ConditionFillToHist(TH1L *hist_condition, std::string_view condition)
void HistogramInit(DataMonitor &histograms) override
float coarse_time_frequency_
auto mapBarSignal_to_calSignals(const MapBarSignal &map_bar_signals, int module_num, R3B::Side side) const -> std::vector< CalDataSignal >
OutputVectorConnector< BarCalData > cal_data_
auto CheckConditions(TH1L *hist_condition) const -> bool override
auto convert_to_real_time(R3BTCalPar2 *calPar, SingleEdgeSignal signal, FTType ftType, int module_num) const -> ValueError< double >
InputMapConnector< int, PaddleTamexMappedData > map_data_
auto get_trigger_time(int module_num, Side side) const -> ValueError< double >
void FinishEvent() override
unsigned int total_pmt_nums_
unsigned int coarse_time_max_num_
InputMapConnector< int, PaddleTamexTrigMappedData > trig_map_data_
void overflow_correct(R3B::Neuland::CalDataSignal &calSignal) const
auto doubleEdgeSignal_to_calSignal(const DoubleEdgeSignal &double_edge_signal, R3B::Side side, int module_num) const -> CalDataSignal
void ExtraInit(FairRootManager *rootMan) override
void fill_cal_data(BarCalData &cal, const MapBarSignal &signals)
Map2CalTask(const Config &config)
void TriggeredExec() override
void SetExtraPar(FairRuntimeDb *rtdb) override
InputParView< Map2CalPar > calibration_par_
auto get_tot(const DoubleEdgeSignal &pmtSignal, int module_num, R3B::Side module_side) const -> ValueError< double >
void histogram_monitor(const BarCalData &cal, Side side)
InputParView< Map2CalPar > calibration_trig_par_
Simulation of NeuLAND Bar/Paddle.
constexpr auto COARSE_TIME_CLOCK_FREQUENCY_MHZ
constexpr auto BarsPerPlane
constexpr auto Neuland_PlaneBar2ModuleNum(int planeNum, int barNum) -> int
std::vector< CalDataSignal > left
std::vector< CalDataSignal > right
ValueError< double > trigger_time
ValueError< double > leading_time