65 std::string fullPath = std::string(getenv(
"VMCWORKDIR")) +
"/parameters/hgnd/" + calibrationFile;
66 std::ifstream input(fullPath);
67 if (!input.is_open()) {
68 LOG(error) <<
"BmnHgndRaw2Digit::ParseCalibration: Cannot open file " << fullPath;
75 }
catch (
const std::exception& e) {
76 LOG(error) <<
"BmnHgndRaw2Digit::ParseCalibration: Failed to parse JSON: " << e.what();
80 std::string version = j.
value(
"version",
"unknown");
81 std::string comment = j.
value(
"comment",
"none");
82 double totThreshold = j.
value(
"totThreshold", 20.0);
83 double Rload = j.
value(
"Rload", 33.0);
85 LOG(debug) <<
"BmnHgndRaw2Digit::ParseCalibration. Calibration version: " << version;
86 LOG(debug) <<
"BmnHgndRaw2Digit::ParseCalibration. Comment: " << comment;
89 for (
const auto& entry : j[
"calibration"]) {
90 int det = entry[
"detector"];
91 int lay = entry[
"layer"];
92 int row = entry[
"row"];
93 int col = entry[
"column"];
94 double off = entry[
"offset"];
95 double p = entry[
"p"];
96 double tau = entry[
"tau"];
97 double RC = entry[
"RC"];
102 fuoCalibMap.emplace(address, std::make_pair(tdc, qdc));
129 LOG(debug) <<
"BmnHgndRaw2Digit::fillEvent";
130 for (Int_t iTdc = 0, nEntries = tdc->GetEntriesFast(); iTdc < nEntries; ++iTdc) {
134 if (!catch_address.has_value())
137 const auto address = catch_address.value();
142 if (!catch_calib.has_value())
145 const auto& [slew_func, charge_func] = catch_calib.value();
147 LOG(debug4) << Form(
"BmnHgndRaw2Digit::fillEvent: Ev %d Hdr ns %d. Hdr+ST %d. Hgnd l%d ns %ld",
151 const int64_t delta_sec = tdcDig->GetTimeSec() - hdr->
GetEventTimeTS().GetSec();
152 const int64_t delta_nsec = tdcDig->GetTimeNsec() - hdr->
GetEventTimeTS().GetNanoSec();
153 const int64_t wr_tof_ns = delta_sec * 1000000000LL + delta_nsec;
156 LOG(warn) << Form(
"BmnHgndRaw2Digit::fillEvent: Sync lost. Hdr sec %ld Hgnd sec %ld",
159 const double raw_time = wr_tof_ns + tdcDig->GetToa() *
TDCBIN;
160 const double tot = tdcDig->GetTot() *
TDCBIN;
161 const double time = raw_time - slew_func(tot);
162 const double signal = charge_func(tot);
164 new ((*digits)[digits->GetEntriesFast()])
BmnHgndDigi(address, time, signal, raw_time, tot);