11#include "FairRootManager.h"
12#include "TStopwatch.h"
15#include <FairRunSim.h>
16#include <nlohmann/json.hpp>
23 : FairTask(
"BmnScWallDigitizer")
27 , fSiPM(2668, 55, 0.1, 0.0021)
28 , fPointArray(nullptr)
39 const char* vmc = getenv(
"VMCWORKDIR");
40 if (!vmc || !vmc[0]) {
41 LOG(error) << Form(
"%s::LoadConfig: VMCWORKDIR is not set", GetName());
46 const std::string fullPath = std::string(vmc) +
"/parameters/scwall/" +
config;
47 std::ifstream input(fullPath);
48 if (!input.is_open()) {
49 LOG(error) << Form(
"%s::LoadConfig: cannot open file %s", GetName(), fullPath.c_str());
57 }
catch (
const std::exception& e) {
58 LOG(error) << Form(
"%s::LoadConfig: failed to parse JSON %s: %s", GetName(), fullPath.c_str(), e.what());
63 const std::string version = j.
value(
"version",
"unknown");
64 const std::string comment = j.
value(
"comment",
"none");
67 fScale = j[
"scale"].
get<
double>();
70 fThreshold = j[
"threshold"].get<double>();
73 fTimeCut = j[
"timecut"].get<double>();
76 const auto& jsipm = j[
"sipm"];
83 if (jsipm.contains(
"n_pixels"))
84 nPixels = jsipm[
"n_pixels"].get<int>();
86 if (jsipm.contains(
"mip_pixels"))
87 mipPixels = jsipm[
"mip_pixels"].get<int>();
89 if (jsipm.contains(
"noise"))
90 noise = jsipm[
"noise"].get<double>();
92 if (jsipm.contains(
"mip_energy"))
93 mipEnergy = jsipm[
"mip_energy"].get<double>();
95 fSiPM =
SiPM(nPixels, mipPixels, noise, mipEnergy);
98 LOG(info) << Form(
"%s::LoadConfig: loaded %s (version=%s, comment=%s)", GetName(), fullPath.c_str(),
99 version.c_str(), comment.c_str());
108 fDigiArray->Delete();
117 LOG(detail) <<
"-I- BmnScWallDigitizer: Init started..." << std::endl;
119 FairRootManager* ioman = FairRootManager::Instance();
121 LOG(error) <<
"-E- BmnScWallDigitizer::Init: RootManager not instantiated!" << std::endl;
125 fPointArray =
static_cast<TClonesArray*
>(ioman->GetObject(
"ScWallPoint"));
127 LOG(error) <<
"-E- BmnScWallDigitizer::Init: No ScWallPoint array!" << std::endl;
131 fDigiArray =
new TClonesArray(
"BmnScWallDigit");
132 ioman->Register(
"ScWallDigit",
"ScWall", fDigiArray, kTRUE);
134 LOG(detail) <<
"-I- BmnScWallDigitizer: Initialization successful" << std::endl;
145 LOG(debug2) <<
"BmnScWallDigitizer::Exec() started..." << std::endl;
147 Fatal(
"Exec",
"No DigiArray");
152 for (
auto& it : fuoHitMap) {
153 uint32_t address = it.first;
154 const auto& tracks_contributions = it.second;
156 double totalEnergy = 0.0;
157 double crossTime = 0.0;
158 bool reachedThreshold =
false;
159 for (
const auto* point : tracks_contributions) {
160 if (point->GetTime() > fTimeCut)
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()) {
176 TClonesArray& ar = *fDigiArray;
177 long entries = fDigiArray->GetEntriesFast();
178 new (ar[entries])
BmnScWallDigit(address, crossTime, totalEnergy);
179 if (FairLogger::GetLogger()->IsLogNeeded(fair::Severity::debug2))
185 fworkTime += sw.RealTime();
188void BmnScWallDigitizer::FillHitMap()
193 for (
int iPoint = 0, nPoint = fPointArray->GetEntriesFast(); iPoint < nPoint; ++iPoint) {
194 auto* point =
static_cast<BmnScWallPoint*
>(fPointArray->At(iPoint));
196 fuoHitMap[address].push_back(point);
200 for (
auto& pair : fuoHitMap) {
201 std::vector<BmnScWallPoint*>& points = pair.second;
202 std::sort(points.begin(), points.end(),
206 LOG(debug2) <<
"BmnScWallDigitizer::FillHitMap() event " << gMC->CurrentEvent() <<
" fired sections "
212 printf(
"Work time of the ScWall digitizer: %.4f sec.\n", fworkTime);
static uint32_t GetAddress(uint32_t CellId)
Return address from system ID, Cell ID.
virtual void Exec(Option_t *opt)
InitStatus LoadConfig(const char *config)
virtual ~BmnScWallDigitizer()
BmnScWallDigitizer(const int period)
virtual InitStatus Init()
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)