4#include "FairRootManager.h"
12#include <nlohmann/json.hpp>
21 : FairTask(
"BmnFHCalDigitizer")
22 , fScale(1.0 / 0.0048)
25 , fSiPM(90000, 40, 0.3, 0.0048)
26 , fPointArray(nullptr)
37 const char* vmc = getenv(
"VMCWORKDIR");
38 if (!vmc || !vmc[0]) {
39 LOG(error) << Form(
"%s::LoadConfig: VMCWORKDIR is not set", GetName());
44 const std::string fullPath = std::string(vmc) +
"/parameters/fhcal/" +
config;
45 std::ifstream input(fullPath);
46 if (!input.is_open()) {
47 LOG(error) << Form(
"%s::LoadConfig: cannot open file %s", GetName(), fullPath.c_str());
55 }
catch (
const std::exception& e) {
56 LOG(error) << Form(
"%s::LoadConfig: failed to parse JSON %s: %s", GetName(), fullPath.c_str(), e.what());
61 const std::string version = j.
value(
"version",
"unknown");
62 const std::string comment = j.
value(
"comment",
"none");
65 fScale = j[
"scale"].
get<
double>();
68 fThreshold = j[
"threshold"].get<double>();
71 fTimeCut = j[
"timecut"].get<double>();
74 const auto& jsipm = j[
"sipm"];
81 if (jsipm.contains(
"n_pixels"))
82 nPixels = jsipm[
"n_pixels"].get<int>();
84 if (jsipm.contains(
"mip_pixels"))
85 mipPixels = jsipm[
"mip_pixels"].get<int>();
87 if (jsipm.contains(
"noise"))
88 noise = jsipm[
"noise"].get<double>();
90 if (jsipm.contains(
"mip_energy"))
91 mipEnergy = jsipm[
"mip_energy"].get<double>();
93 fSiPM =
SiPM(nPixels, mipPixels, noise, mipEnergy);
96 LOG(info) << Form(
"%s::LoadConfig: loaded %s (version=%s, comment=%s)", GetName(), fullPath.c_str(),
97 version.c_str(), comment.c_str());
106 fDigiArray->Delete();
115 LOG(detail) <<
"-I- BmnFHCalDigitizer: Init started..." << std::endl;
117 FairRootManager* ioman = FairRootManager::Instance();
119 LOG(error) <<
"-E- BmnFHCalDigitizer::Init: RootManager not instantiated!" << std::endl;
123 fPointArray =
static_cast<TClonesArray*
>(ioman->GetObject(
"FHCalPoint"));
125 LOG(error) <<
"-E- BmnFHCalDigitizer::Init: No FHCalPoint array!" << std::endl;
129 fDigiArray =
new TClonesArray(
"BmnFHCalDigit");
130 ioman->Register(
"FHCalDigit",
"FHCal", fDigiArray, kTRUE);
132 LOG(detail) <<
"-I- BmnFHCalDigitizer: Initialization successful" << std::endl;
143 LOG(debug2) <<
"BmnFHCalDigitizer::Exec() started..." << std::endl;
145 Fatal(
"Exec",
"No DigiArray");
150 for (
auto& it : fuoHitMap) {
151 uint32_t address = it.first;
152 const auto& tracks_contributions = it.second;
154 double totalEnergy = 0.0;
155 double crossTime = 0.0;
156 bool reachedThreshold =
false;
157 for (
const auto* point : tracks_contributions) {
158 if (point->GetTime() > fTimeCut)
160 if (FairLogger::GetLogger()->IsLogNeeded(fair::Severity::debug2))
163 totalEnergy += point->GetEnergyLoss();
164 if (!reachedThreshold && totalEnergy * fScale > fThreshold) {
165 crossTime = point->GetTime();
166 reachedThreshold =
true;
167 LOG(debug2) << Form(
"Reached threshold. Energy %.4f Weighted time %.4f", totalEnergy, crossTime);
171 totalEnergy *= fScale;
173 if (!reachedThreshold || totalEnergy < std::numeric_limits<double>::epsilon()) {
177 TClonesArray& ar = *fDigiArray;
178 long entries = fDigiArray->GetEntriesFast();
179 new (ar[entries])
BmnFHCalDigit(address, crossTime, totalEnergy);
180 if (FairLogger::GetLogger()->IsLogNeeded(fair::Severity::debug2))
186 fworkTime += sw.RealTime();
189void BmnFHCalDigitizer::FillHitMap()
194 for (
int iPoint = 0, nPoint = fPointArray->GetEntriesFast(); iPoint < nPoint; ++iPoint) {
195 auto* point =
static_cast<BmnFHCalPoint*
>(fPointArray->At(iPoint));
197 fuoHitMap[address].push_back(point);
201 for (
auto& pair : fuoHitMap) {
202 std::vector<BmnFHCalPoint*>& points = pair.second;
203 std::sort(points.begin(), points.end(),
207 LOG(debug2) <<
"BmnFHCalDigitizer::FillHitMap() event " << gMC->CurrentEvent() <<
" fired sections "
213 printf(
"Work time of the FHCal digitizer: %.4f sec.\n", fworkTime);
static std::string GetInfoString(uint32_t address)
Return a formatted string with all address components.
static uint32_t GetPhysicalAddress(uint32_t address)
Return Physical address (w/o scintillator id) from address.
virtual ~BmnFHCalDigitizer()
virtual void Exec(Option_t *opt)
InitStatus LoadConfig(const char *config)
virtual InitStatus Init()
BmnFHCalDigitizer(const int period)
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
constexpr bool is_object() const noexcept
return whether value is an object
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)
double ModelResponse(double pfELoss)