CbmRoot
Loading...
Searching...
No Matches
TofHitfindQa.cxx
Go to the documentation of this file.
1/* Copyright (C) 2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
11
12#include "CbmTofAddress.h"
13#include "qa/Histogram.h"
14#include "tof/Hit.h"
15
16#include <fmt/format.h>
17
19
20// ---------------------------------------------------------------------------------------------------------------------
21//
23try {
24 using fmt::format;
25 using qa::CanvasConfig;
26 using qa::PadConfig;
27 if (!IsActive()) {
28 return;
29 }
30
31 size_t nRpcs = fParameters.rpcs.size();
32 if (nRpcs < 1) {
33 throw std::runtime_error("parameters were not initialized. Please, provide the configuration using the function "
34 "HitfindQa::InitParameters(hitSetup)");
35 }
36
37 // Histogram initialization
38 fvphRpcHitOccupX.resize(nRpcs, nullptr);
39 fvphRpcHitOccupY.resize(nRpcs, nullptr);
40 fvphRpcHitOccupCh.resize(nRpcs, nullptr);
41
42 auto cOccupX = CanvasConfig(format("{}/tof_rpc_occup_x", GetTaskName()), "RPC hit occupancy vs. X", 1, 1);
43 auto cOccupY = CanvasConfig(format("{}/tof_rpc_occup_y", GetTaskName()), "RPC hit occupancy vs. Y", 1, 1);
44 auto cOccupCh = CanvasConfig(format("{}/tof_rpc_occup_ch", GetTaskName()), "RPC hit occupancy vs. channel", 1, 1);
45 for (size_t iRpc = 0; iRpc < nRpcs; ++iRpc) {
46 const auto& rpcPar = fParameters.rpcs[iRpc];
47 int nCh = rpcPar.chAddresses.size();
48 auto sDN = format("{:#010x}", rpcPar.address); // diamond suffix
49 auto sDT = CbmTofAddress::ToString(rpcPar.address);
50
51 // Histograms initialisation
52 fvphRpcHitOccupX[iRpc] = MakeObj<qa::H1D>(format("tof_hit_occup_x_{}", sDN), format("RPC {};x [cm];counts", sDT),
54 fvphRpcHitOccupY[iRpc] = MakeObj<qa::H1D>(format("tof_hit_occup_y_{}", sDN), format("RPC {};y [cm];counts", sDT),
56 fvphRpcHitOccupCh[iRpc] = MakeObj<qa::H1D>(format("tof_hit_occup_chan_{}", sDN),
57 format("RPC {};channel;counts", sDT), nCh, -0.5, nCh - 0.5);
58
59 {
60 auto pad = PadConfig(fvphRpcHitOccupX[iRpc], "hist");
61 pad.SetLog(false, true, false);
62 cOccupX.AddPadConfig(pad);
63 }
64 {
65 auto pad = PadConfig(fvphRpcHitOccupY[iRpc], "hist");
66 pad.SetLog(false, true, false);
67 cOccupY.AddPadConfig(pad);
68 }
69 {
70 auto pad = PadConfig(fvphRpcHitOccupCh[iRpc], "hist");
71 pad.SetLog(false, true, false);
72 cOccupCh.AddPadConfig(pad);
73 }
74 }
75
76 AddCanvasConfig(cOccupX);
77 AddCanvasConfig(cOccupY);
78 AddCanvasConfig(cOccupCh);
79}
80catch (const std::exception& err) {
81 L_(fatal) << "tof::HitfindQa: initialization failed. Reason: " << err.what();
82 throw std::runtime_error("tof::HitfindQa initialization failure");
83}
84
85// ---------------------------------------------------------------------------------------------------------------------
86//
88{
89 if (!IsActive()) {
90 return;
91 }
92
93 // Fill hit distributions
94 const auto& hits = fpHits->Data();
95 for (size_t iH = 0; iH < hits.size(); ++iH) {
96 const auto& hit = hits[iH];
97 int32_t hitAddress = hit.address;
98 int32_t iCh = CbmTofAddress::GetChannelId(hitAddress);
99 uint32_t rpcAddress = CbmTofAddress::GetModFullId(hitAddress);
100 auto itAddress = fParameters.lookupMap.find(rpcAddress);
101 if (itAddress == fParameters.lookupMap.end()) {
102 L_(error) << "tof::HitfindQa: unknown RPC address " << CbmTofAddress::ToString(rpcAddress);
103 continue;
104 }
105 uint32_t iRpc = itAddress->second;
106 fvphRpcHitOccupX[iRpc]->Fill(hit.X());
107 fvphRpcHitOccupY[iRpc]->Fill(hit.Y());
108 fvphRpcHitOccupCh[iRpc]->Fill(iCh);
109 }
110}
#define L_(level)
static vector< vector< QAHit > > hits
ROOT-free implementation of a histogram.
A TOF hitfinder QA.
static int32_t GetModFullId(uint32_t address)
static std::string ToString(int32_t address)
static int32_t GetChannelId(uint32_t address)
A canvas configuration for the histogram server.
A pad configuration for the histogram server.
Definition PadConfig.h:26
const std::string & GetTaskName()
Gets name of the task.
void AddCanvasConfig(const CanvasConfig &canvas)
Adds a canvas configuration.
bool IsActive() const
Checks, if the task is active.
Obj * MakeObj(Args... args)
Creates a QA-object and returns the pointer to it.
A QA module for the BMON hit-finder.
static constexpr double kHitOccupU
Hit occupancy: upper bound [cm].
std::vector< qa::H1D * > fvphRpcHitOccupX
Hit occupancy in RPC vs. x.
static constexpr double kHitOccupL
Hit occupancy: lower bound [cm].
void Exec()
Executes the task, fills the histograms.
HitfindQaParameters fParameters
Parameters of the hit finder QA.
std::vector< qa::H1D * > fvphRpcHitOccupCh
Hit occupancy in RPC vs. channel.
std::vector< qa::H1D * > fvphRpcHitOccupY
Hit occupancy in RPC vs. y.
void Init()
Initialized the task.
static constexpr int kHitOccupB
Hit occupancy: n bins.
const PartitionedVector< tof::Hit > * fpHits
Pointer to TOF hit sample.
std::unordered_map< uint32_t, uint32_t > lookupMap
A lookup map for RPC addresses.
std::vector< Rpc > rpcs
A map for different RPC properties.