CbmRoot
Loading...
Searching...
No Matches
CbmCaInputQaTof.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#include "CbmCaInputQaTof.h"
11
12#include "CaToolsLinkKey.h"
13#include "CbmAddress.h"
14#include "CbmMCDataArray.h"
15#include "CbmMCEventList.h"
16#include "CbmMatch.h"
17#include "CbmTofHit.h"
18#include "CbmTofPoint.h"
20#include "FairRootManager.h"
21#include "FairRunAna.h"
22#include "FairRuntimeDb.h"
23#include "Logger.h"
24#include "TBox.h"
25#include "TClonesArray.h"
26#include "TF1.h"
27#include "TH1F.h"
28#include "TH2F.h"
29#include "TMath.h"
30#include "TStyle.h"
31
32#include <algorithm>
33#include <fstream>
34#include <iomanip>
35#include <numeric>
36
38
39// ---------------------------------------------------------------------------------------------------------------------
40//
41CbmCaInputQaTof::CbmCaInputQaTof(int verbose, bool isMCUsed) : CbmCaInputQaBase("CbmCaInputQaTof", verbose, isMCUsed)
42{
43 // Default parameters of task
45}
46
47// ---------------------------------------------------------------------------------------------------------------------
48//
50{
51 // Base canvases
53
54 // Hit occupancy vs TOF cell
55 {
56 //auto DrawBox = [&](double xLo, double yLo, double xUp, double yUp) {
57 // auto* pBox = new TBox(xLo, yLo, xUp, yUp);
58 // pBox->SetLineWidth(kOrange + 7);
59 // pBox->SetLineStyle(2);
60 // pBox->SetLineColor(2);
61 // pBox->SetFillStyle(0);
62 // pBox->Draw("SAME");
63 //};
64
65 // NOTE: SZh 11.09.2023: Causes memory overconsumption
66 //for (int iSt = 0; iSt < fpDetInterface->GetNtrackingStations(); ++iSt) {
67 // for (int iSmType = 0; iSmType < fDigiBdfPar->GetNbSmTypes(); ++iSmType) {
68 // if (iSmType == 5) { continue; } // skip Bmon
69 // for (int iSm = 0; iSm < fDigiBdfPar->GetNbSm(iSmType); ++iSm) {
70 // for (int iRpc = 0; iRpc < fDigiBdfPar->GetNbRpc(iSmType); ++iRpc) {
71 // for (int iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpc); ++iCh) {
72 // const char* dir = "occup_cell/";
73 // TString name = Form("%s/occup_xy_smt%d_sm%d_rpc%d_ch%d", dir, iSmType, iSm, iRpc, iCh);
74
75 // auto address = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iCh, /*side = */ 0, iSmType);
76 // const auto* pCell = dynamic_cast<const CbmTofCell*>(fDigiPar->GetCell(address));
77 // auto xLo = pCell->GetX() - 0.5 * pCell->GetSizex();
78 // auto xUp = pCell->GetX() + 0.5 * pCell->GetSizex();
79 // auto yLo = pCell->GetY() - 0.5 * pCell->GetSizey();
80 // auto yUp = pCell->GetY() + 0.5 * pCell->GetSizey();
81 // auto zLo = pCell->GetZ() - 1.0;
82 // auto zUp = pCell->GetZ() + 1.0;
83
84 // auto* canv = MakeQaObject<CbmQaCanvas>(name, "", 1500, 800);
85 // canv->Divide(3, 1);
86 // {
87 // canv->cd(1);
88 // fvph_hit_xy_vs_cell[iSmType][iSm][iRpc][iCh]->DrawCopy("colz", "");
89 // DrawBox(xLo, yLo, xUp, yUp);
90
91 // canv->cd(2);
92 // fvph_hit_zx_vs_cell[iSmType][iSm][iRpc][iCh]->DrawCopy("colz", "");
93 // DrawBox(zLo, xLo, zUp, xUp);
94
95 // canv->cd(3);
96 // fvph_hit_zy_vs_cell[iSmType][iSm][iRpc][iCh]->DrawCopy("colz", "");
97 // DrawBox(zLo, yLo, zUp, yUp);
98 // }
99 // }
100 // }
101 // }
102 // }
103 //}
104 }
105}
106
107// ---------------------------------------------------------------------------------------------------------------------
108//
116
117// ---------------------------------------------------------------------------------------------------------------------
118//
120{
121 auto SetRange = [](std::array<double, 2>& range, double min, double max) {
122 range[0] = min;
123 range[1] = max;
124 };
125 // Hit errors
126 SetRange(fRHitDx, 0.0000, 5.00); // [cm]
127 SetRange(fRHitDy, 0.0000, 5.00); // [cm]
128 SetRange(fRHitDu, 0.0000, 5.00); // [cm]
129 SetRange(fRHitDv, 0.0000, 5.00); // [cm]
130 SetRange(fRHitDt, 0.0000, 0.15); // [ns]
131 // Residuals
132 SetRange(fRResX, -2.00, 2.00);
133 SetRange(fRResY, -4.00, 4.00);
134 SetRange(fRResU, -2.00, 2.00);
135 SetRange(fRResV, -4.00, 4.00);
136 SetRange(fRResT, -0.50, 0.50);
137}
138
139// ---------------------------------------------------------------------------------------------------------------------
140//
142{
143 // Base QA execution
145
146 // TOF-specific QA execution
147 if constexpr (0) { // DEBUG
148 auto PrintPoint = [&](const CbmTofPoint* point, std::stringstream& m) {
149 m << "point: trk=" << point->GetTrackID() << ", ";
150 auto pointAddress = point->GetDetectorID();
151 int32_t rpcAddress = (pointAddress << 11); // Address of RPC
152 auto iSmType = CbmTofAddress::GetSmType(pointAddress);
153 auto iSm = CbmTofAddress::GetSmId(pointAddress);
154 auto iRpc = CbmTofAddress::GetRpcId(pointAddress);
155 m << "iSt=" << fpDetInterface->GetTrackingStationIndex(pointAddress) << ", ";
156 m << "address=" << pointAddress << ", rpcAddress= " << rpcAddress;
157 m << ", (" << iSmType << "," << iSm << "," << iRpc << "), ";
158 m << "x=" << point->GetX() << ", y=" << point->GetY() << ", z=" << point->GetZ();
159 };
160
161 if (IsMCUsed()) {
162 // Print hit sample
163 LOG(info) << fName << ": ===== Hit Sample";
164 for (int iHit = 0; iHit < fpHits->GetEntriesFast(); ++iHit) {
165 const auto* pHit = dynamic_cast<const Hit_t*>(fpHits->At(iHit));
166 if (!pHit) {
167 LOG(error) << fName << "::FillHistogramsPerHit: hit with index " << iHit << " not found";
168 continue;
169 }
170
171 int address = pHit->GetAddress();
172 int iHitSmType = CbmTofAddress::GetSmType(address);
173 int iHitSm = CbmTofAddress::GetSmId(address);
174 int iHitRpc = CbmTofAddress::GetRpcId(address);
175
176 auto* pHitMatch = dynamic_cast<CbmMatch*>(fpHitMatches->At(iHit));
177 std::stringstream msg;
178 msg << fName << ": hit: id=" << iHit << ", NofLinks=" << pHitMatch->GetNofLinks() << ", ";
179 msg << "iSt=" << fpDetInterface->GetTrackingStationIndex(address) << ", ";
180 msg << "RPC=(" << iHitSmType << "," << iHitSm << "," << iHitRpc << ")";
181 if (pHitMatch->GetNofLinks() == 0) {
182 continue;
183 }
184 const auto& bestLink = pHitMatch->GetMatchedLink();
185 for (int iLink = 0; iLink < pHitMatch->GetNofLinks(); ++iLink) {
186 const auto& link = pHitMatch->GetLink(iLink);
187 int iPointExt = link.GetIndex();
188 int iEvent = link.GetEntry();
189 int iFile = link.GetFile();
190 msg << "\n\tLink " << iLink << ": " << iPointExt << ", " << iEvent << ", " << iFile << " (best? ";
191 msg << (bestLink == link) << ')';
192 if (iPointExt < 0) {
193 continue;
194 }
195 msg << ", ";
196 auto* pPoint = dynamic_cast<CbmTofPoint*>(fpMCPoints->Get(link));
197 PrintPoint(pPoint, msg);
198 }
199 LOG(info) << msg.str();
200 }
201 // Print point sample
202 LOG(info) << fName << ": ===== Point Sample";
203 if (IsMCUsed()) {
204 for (int iE = 0; iE < fpMCEventList->GetNofEvents(); ++iE) {
205 int iFile = fpMCEventList->GetFileIdByIndex(iE);
206 int iEvent = fpMCEventList->GetEventIdByIndex(iE);
207 int nPoints = fpMCPoints->Size(iFile, iEvent);
208 for (int iPoint = 0; iPoint < nPoints; ++iPoint) {
209 auto* pPoint = dynamic_cast<CbmTofPoint*>(fpMCPoints->Get(iFile, iEvent, iPoint));
210 std::stringstream msg;
211 msg << "link: " << iPoint << ", " << iEvent << ", " << iFile << ", ";
212 PrintPoint(pPoint, msg);
213 LOG(info) << '\t' << msg.str();
214 }
215 }
216 }
217 }
218 }
219}
220
221// ---------------------------------------------------------------------------------------------------------------------
222//
224{
225 auto iHit = GetHitQaData().GetHitIndex();
226 const auto* pHit = dynamic_cast<const Hit_t*>(fpHits->At(iHit));
227 if (!pHit) {
228 LOG(error) << fName << "::FillHistogramsPerHit: hit with index " << iHit << " not found";
229 return;
230 }
231
232 int address = pHit->GetAddress();
233 int iHitSmType = CbmTofAddress::GetSmType(address);
234 int iHitSm = CbmTofAddress::GetSmId(address);
235 int iHitRpc = CbmTofAddress::GetRpcId(address);
236
237 { // Check, if the hit is created on the one of the defined RPCs. If not, save to address into map
238 double xHit = pHit->GetX();
239 double yHit = pHit->GetY();
240 double zHit = pHit->GetZ();
241 fvph_hit_xy_vs_cell[iHitSmType][iHitSm][iHitRpc]->Fill(xHit, yHit);
242 fvph_hit_zx_vs_cell[iHitSmType][iHitSm][iHitRpc]->Fill(zHit, xHit);
243 fvph_hit_zy_vs_cell[iHitSmType][iHitSm][iHitRpc]->Fill(zHit, yHit);
244 }
245}
246
247// ---------------------------------------------------------------------------------------------------------------------
248//
250{
251 // TOF tracking detector interface
253
254 auto initStatus = CbmCaInputQaBase::InitQa();
255 if (kSUCCESS != initStatus) {
256 return initStatus;
257 }
258
259 // FIXME: Move to the parameters definition function
260 auto* pRuntimeDb = FairRunAna::Instance()->GetRuntimeDb();
261 fDigiPar = dynamic_cast<CbmTofDigiPar*>(pRuntimeDb->getContainer("CbmTofDigiPar"));
262 fDigiBdfPar = dynamic_cast<CbmTofDigiBdfPar*>(pRuntimeDb->getContainer("CbmTofDigiBdfPar"));
263
264 // ----- Histogram initialization
265 // Hit occupancy vs. TOF cell
266 MakeQaDirectory("occup_cell/");
267 int nSmTypes = fDigiBdfPar->GetNbSmTypes();
268 fvph_hit_xy_vs_cell.resize(nSmTypes);
269 fvph_hit_zx_vs_cell.resize(nSmTypes);
270 fvph_hit_zy_vs_cell.resize(nSmTypes);
271 for (int iSmType = 0; iSmType < nSmTypes; ++iSmType) {
272 if (iSmType == 5) {
273 continue;
274 } // skip Bmon
275 MakeQaDirectory(Form("occup_cell/sm_type_%d", iSmType));
276 int nSm = fDigiBdfPar->GetNbSm(iSmType);
277 int nRpc = fDigiBdfPar->GetNbRpc(iSmType);
278 fvph_hit_xy_vs_cell[iSmType].resize(nSm);
279 fvph_hit_zx_vs_cell[iSmType].resize(nSm);
280 fvph_hit_zy_vs_cell[iSmType].resize(nSm);
281 for (int iSm = 0; iSm < fDigiBdfPar->GetNbSm(iSmType); ++iSm) {
282 MakeQaDirectory(Form("occup_cell/sm_type_%d/sm_%d/", iSmType, iSm));
283 fvph_hit_xy_vs_cell[iSmType][iSm].resize(nRpc, nullptr);
284 fvph_hit_zx_vs_cell[iSmType][iSm].resize(nRpc, nullptr);
285 fvph_hit_zy_vs_cell[iSmType][iSm].resize(nRpc, nullptr);
286 for (int iRpc = 0; iRpc < nRpc; ++iRpc) {
287 const char* dir = Form("occup_cell/sm_type_%d/sm_%d/rpc%d", iSmType, iSm, iRpc);
288 TString name = Form("%s/occup_xy_smt%d_sm%d_rpc%d", dir, iSmType, iSm, iRpc);
289 TString title = Form("Hit Occupancy in xy-Plane for iSmType = %d, iSm = %d, iRpc = %d", iSmType, iSm, iRpc);
290 title += ";x_{hit} [cm];y_{hit} [cm]";
291 fvph_hit_xy_vs_cell[iSmType][iSm][iRpc] =
293 name = Form("%s/occup_zx_smt%d_sm%d_rpc%d", dir, iSmType, iSm, iRpc);
294 title = Form("Hit Occupancy in zx-Plane for iSmType = %d, iSm = %d, iRpc = %d", iSmType, iSm, iRpc);
295 title += ";z_{hit} [cm];x_{hit} [cm]";
296 fvph_hit_zx_vs_cell[iSmType][iSm][iRpc] =
297 MakeQaObject<TH2F>(name, title, fNbinsZ, frZmin.back(), frZmax.back(), fNbXo, fLoXo, fUpXo);
298 name = Form("%s/occup_zy_smt%d_sm%d_rpc%d", dir, iSmType, iSm, iRpc);
299 title = Form("Hit Occupancy in zy-Plane for iSmType = %d, iSm = %d, iRpc = %d", iSmType, iSm, iRpc);
300 title += ";z_{hit} [cm];y_{hit} [cm]";
301 fvph_hit_zy_vs_cell[iSmType][iSm][iRpc] =
302 MakeQaObject<TH2F>(name, title, fNbinsZ, frZmin.back(), frZmax.back(), fNbYo, fLoYo, fUpYo);
303 }
304 }
305 }
306
307 return kSUCCESS;
308}
Data structure to represent a MC link in CA tracking MC module.
ClassImp(CbmCaInputQaTof)
QA-task for CA tracking input from TOF detector (header)
friend fscal max(fscal x, fscal y)
friend fscal min(fscal x, fscal y)
A QA-task class, which provides assurance of MuCh hits and geometry.
CbmTrackingDetectorInterfaceBase * fpDetInterface
void CreateSummary() override
Creates summary cavases, tables etc.
void ExecQa() override
Fills histograms per event or time-slice.
InitStatus InitQa() override
Initializes QA task.
void DeInit() override
De-initializes histograms.
int fLoYo
Y min in occupancy [cm].
Vector3D_t< TH2F * > fvph_hit_xy_vs_cell
Hit occupancy vs. TOF cell ix XY-plane.
void FillHistogramsPerHit() override
Fills histograms per hit.
CbmTofDigiBdfPar * fDigiBdfPar
int fLoXo
X min in occupancy [cm].
int fUpXo
X max in occupancy [cm].
CbmTofDigiPar * fDigiPar
int fNbXo
Number of bins in occupancy.
void CreateSummary() override
Creates summary cavases, tables etc.
CbmCaInputQaTof(int verbose, bool isMCUsed)
Constructor from parameters.
Vector3D_t< TH2F * > fvph_hit_zy_vs_cell
Hit occupancy vs. TOF cell in ZY-plane.
void DeInit() override
De-initializes histograms.
void DefineParameters() override
Defines parameters of the task.
InitStatus InitQa() override
Initializes histograms, data-branches and other modules in the beginning of the run.
void ExecQa() override
Fills histograms per event or time-slice.
int fUpYo
Y max in occupancy [cm].
Vector3D_t< TH2F * > fvph_hit_zx_vs_cell
Hit occupancy vs. TOF cell in ZX-plane.
int fNbYo
Number of bins in occupancy.
TObject * Get(const CbmLink *lnk)
Int_t Size(Int_t fileNumber, Int_t eventNumber)
int32_t GetFileIdByIndex(uint32_t index)
File number by index @value File number for event at given index in list.
int32_t GetEventIdByIndex(uint32_t index)
Event number by index @value Event number for event at given index in list.
std::size_t GetNofEvents() const
Number of events in the list @value Number of events.
int32_t GetNofLinks() const
Definition CbmMatch.h:42
T * MakeQaObject(TString sName, TString sTitle, Args... args)
Definition CbmQaIO.h:261
void MakeQaDirectory(TString sName)
Definition CbmQaIO.cxx:132
bool IsMCUsed() const
Returns flag, whether MC information is used or not in the task.
Definition CbmQaTask.h:126
static int32_t GetSmId(uint32_t address)
static int32_t GetRpcId(uint32_t address)
static int32_t GetSmType(uint32_t address)
Parameters class for the CBM ToF digitizer using beam data distributions.
Int_t GetNbSmTypes() const
Int_t GetNbSm(Int_t iSmType) const
Int_t GetNbRpc(Int_t iSmType) const
Geometric intersection of a MC track with a TOFb detector.
Definition CbmTofPoint.h:44
static CbmTofTrackingInterface * Instance()
Gets pointer to the instance of the CbmTofTrackingInterface.
virtual int GetTrackingStationIndex(const CbmHit *hit) const =0
Gets a tracking station of a CbmHit.
int GetHitIndex() const
Gets hit index.