4#include "FairRootManager.h"
12#include <nlohmann/json.hpp>
23 : FairTask(
"BmnHodoDigitizer")
27 , fSaturation(
std::numeric_limits<double>::
max())
28 , fPointArray(nullptr)
38 const char* vmc = getenv(
"VMCWORKDIR");
39 if (!vmc || !vmc[0]) {
40 LOG(error) << Form(
"%s::LoadConfig: VMCWORKDIR is not set", GetName());
45 const std::string fullPath = std::string(vmc) +
"/parameters/hodo/" +
config;
46 std::ifstream input(fullPath);
47 if (!input.is_open()) {
48 LOG(error) << Form(
"%s::LoadConfig: cannot open file %s", GetName(), fullPath.c_str());
56 }
catch (
const std::exception& e) {
57 LOG(error) << Form(
"%s::LoadConfig: failed to parse JSON %s: %s", GetName(), fullPath.c_str(), e.what());
62 const std::string version = j.
value(
"version",
"unknown");
63 const std::string comment = j.
value(
"comment",
"none");
66 fScale = j[
"scale"].
get<
double>();
69 fThreshold = j[
"threshold"].get<double>();
72 fTimeCut = j[
"timecut"].get<double>();
74 LOG(info) << Form(
"%s::LoadConfig: loaded %s (version=%s, comment=%s)", GetName(), fullPath.c_str(),
75 version.c_str(), comment.c_str());
93 LOG(detail) <<
"-I- BmnHodoDigitizer: Init started..." << std::endl;
95 FairRootManager* ioman = FairRootManager::Instance();
97 LOG(error) <<
"-E- BmnHodoDigitizer::Init: RootManager not instantiated!" << std::endl;
101 fPointArray =
static_cast<TClonesArray*
>(ioman->GetObject(
"HodoPoint"));
103 LOG(error) <<
"-W- BmnHodoDigitizer::Init: No HodoPoint array!" << std::endl;
107 fDigiArray =
new TClonesArray(
"BmnHodoDigit");
108 ioman->Register(
"HodoDigit",
"Hodo", fDigiArray, kTRUE);
110 LOG(detail) <<
"-I- BmnHodoDigitizer: Initialization successful" << std::endl;
117 std::string fullPath = std::string(getenv(
"VMCWORKDIR")) +
"/parameters/hodo/" + inputFile;
118 std::ifstream input(fullPath);
119 if (!input.is_open()) {
120 LOG(error) <<
"BmnHodoDigitizer::LoadCalibration: Cannot open file " << fullPath;
127 }
catch (
const std::exception& e) {
128 LOG(error) <<
"BmnHodoDigitizer::LoadCalibration: Failed to parse JSON: " << e.what();
132 std::string version = j.
value(
"version",
"unknown");
133 std::string comment = j.
value(
"comment",
"none");
135 LOG(debug) <<
"BmnHodoDigitizer::LoadCalibration. Version: " << version;
136 LOG(debug) <<
"BmnHodoDigitizer::LoadCalibration. Comment: " << comment;
138 fSaturation = j.
at(
"parameters").
at(
"saturation");
140 fuoResolutionMap.clear();
141 for (
const auto& entry : j[
"calibration"]) {
142 int strip = entry[
"strip"];
143 int side = entry[
"side"];
144 int gain = entry[
"gain"];
145 double calib = entry[
"calib"];
146 double stochastic = entry[
"stochastic"];
147 double constant = entry[
"constant"];
150 Kernel resolution(stochastic, constant);
151 fuoResolutionMap.emplace(address, std::make_pair(calib, resolution));
166 for (
const auto& it : fuoHitMap) {
167 uint32_t strip = it.first;
168 const auto& points = it.second;
170 double energyLoss = 0.0;
172 for (
const auto* point : points) {
173 if (FairLogger::GetLogger()->IsLogNeeded(fair::Severity::debug))
175 energyLoss += point->GetEnergyLoss();
176 time += point->GetTime();
178 time /= points.size();
180 if (fuoResolutionMap.empty()) {
182 double z2 = energyLoss * fScale;
183 LOG(debug) <<
"BmnHodoDigitizer::Exec Empty resoultion map. Smoothed energy: " << z2;
188 TClonesArray& ar = *fDigiArray;
189 new (ar[ar.GetEntriesFast()])
BmnHodoDigit(address, time, z2);
192 for (
const auto& jt : fuoResolutionMap) {
193 uint32_t address = jt.first;
196 double z2 = jt.second.second(energyLoss * fScale);
197 double adc = z2 / jt.second.first;
199 "BmnHodoDigitizer::Exec Resoultion map for strid %d side %d gain %d. Smoothed energy: %f",
206 TClonesArray& ar = *fDigiArray;
208 if (adc >= fSaturation) {
209 digit->
SetSignal(fSaturation * jt.second.first);
218 fworkTime += sw.RealTime();
222void BmnHodoDigitizer::FillHitMap()
226 for (
int i = 0;
i < fPointArray->GetEntriesFast(); ++
i) {
227 auto* point =
static_cast<BmnHodoPoint*
>(fPointArray->At(
i));
229 fuoHitMap[iStrip].emplace_back(point);
232 LOG(debug) <<
"BmnHodoDigitizer::FillHitMap() - Number of fired cells: " << fuoHitMap.size();
238 printf(
"Work time of the Hodo digitizer: %.4f sec.\n", fworkTime);
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
void SetSignal(double signal)
static uint32_t GetStripSide(uint32_t address)
Return Strip side from address.
static uint32_t GetStripId(uint32_t address)
Return Strip id from address.
static uint32_t GetAddress(uint32_t StripId, uint32_t StripSide, uint32_t Gain)
Return address from system ID, StripId, StripSide, Gain.
static uint32_t GetGain(uint32_t address)
Return Gain from address.
void SetIsSaturated(bool satur)
virtual ~BmnHodoDigitizer()
virtual InitStatus Init()
BmnHodoDigitizer(const int period)
InitStatus LoadConfig(const char *config)
virtual void Exec(Option_t *opt)
void LoadCalibration(const char *calib)
Short_t GetCopyMother() const
a class to store JSON values
bool contains(KeyT &&key) const
check the existence of an element in a JSON object
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
reference at(size_type idx)
access specified array element with bounds checking
auto get() const noexcept(noexcept(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))) -> decltype(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))
get a (pointer) value (explicit)