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 "CbmAddress.h"
13#include "CbmMCDataArray.h"
14#include "CbmMCEventList.h"
15#include "CbmMatch.h"
16#include "CbmTofHit.h"
17#include "CbmTofPoint.h"
18#include "FairRootManager.h"
19#include "FairRunAna.h"
20#include "FairRuntimeDb.h"
21#include "Logger.h"
22#include "TBox.h"
23#include "TClonesArray.h"
24#include "TF1.h"
25#include "TH1F.h"
26#include "TH2F.h"
27#include "TMath.h"
28#include "TStyle.h"
29
30#include <algorithm>
31#include <fstream>
32#include <iomanip>
33#include <numeric>
34
36
37// ---------------------------------------------------------------------------------------------------------------------
38//
39CbmCaInputQaTof::CbmCaInputQaTof(int verbose, bool isMCUsed) : CbmCaInputQaBase("CbmCaInputQaTof", verbose, isMCUsed)
40{
41 // Default parameters of task
43}
44
45// ---------------------------------------------------------------------------------------------------------------------
46//
48{
49 // Base canvases
51
52 // Hit occupancy vs TOF cell
53 {
54 //auto DrawBox = [&](double xLo, double yLo, double xUp, double yUp) {
55 // auto* pBox = new TBox(xLo, yLo, xUp, yUp);
56 // pBox->SetLineWidth(kOrange + 7);
57 // pBox->SetLineStyle(2);
58 // pBox->SetLineColor(2);
59 // pBox->SetFillStyle(0);
60 // pBox->Draw("SAME");
61 //};
62
63 // NOTE: SZh 11.09.2023: Causes memory overconsumption
64 //for (int iSt = 0; iSt < fpDetInterface->GetNtrackingStations(); ++iSt) {
65 // for (int iSmType = 0; iSmType < fDigiBdfPar->GetNbSmTypes(); ++iSmType) {
66 // if (iSmType == 5) { continue; } // skip Bmon
67 // for (int iSm = 0; iSm < fDigiBdfPar->GetNbSm(iSmType); ++iSm) {
68 // for (int iRpc = 0; iRpc < fDigiBdfPar->GetNbRpc(iSmType); ++iRpc) {
69 // for (int iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpc); ++iCh) {
70 // const char* dir = "occup_cell/";
71 // TString name = Form("%s/occup_xy_smt%d_sm%d_rpc%d_ch%d", dir, iSmType, iSm, iRpc, iCh);
72
73 // auto address = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iCh, /*side = */ 0, iSmType);
74 // const auto* pCell = dynamic_cast<const CbmTofCell*>(fDigiPar->GetCell(address));
75 // auto xLo = pCell->GetX() - 0.5 * pCell->GetSizex();
76 // auto xUp = pCell->GetX() + 0.5 * pCell->GetSizex();
77 // auto yLo = pCell->GetY() - 0.5 * pCell->GetSizey();
78 // auto yUp = pCell->GetY() + 0.5 * pCell->GetSizey();
79 // auto zLo = pCell->GetZ() - 1.0;
80 // auto zUp = pCell->GetZ() + 1.0;
81
82 // auto* canv = MakeQaObject<CbmQaCanvas>(name, "", 1500, 800);
83 // canv->Divide(3, 1);
84 // {
85 // canv->cd(1);
86 // fvph_hit_xy_vs_cell[iSmType][iSm][iRpc][iCh]->DrawCopy("colz", "");
87 // DrawBox(xLo, yLo, xUp, yUp);
88
89 // canv->cd(2);
90 // fvph_hit_zx_vs_cell[iSmType][iSm][iRpc][iCh]->DrawCopy("colz", "");
91 // DrawBox(zLo, xLo, zUp, xUp);
92
93 // canv->cd(3);
94 // fvph_hit_zy_vs_cell[iSmType][iSm][iRpc][iCh]->DrawCopy("colz", "");
95 // DrawBox(zLo, yLo, zUp, yUp);
96 // }
97 // }
98 // }
99 // }
100 // }
101 //}
102 }
103}
104
105// ---------------------------------------------------------------------------------------------------------------------
106//
114
115// ---------------------------------------------------------------------------------------------------------------------
116//
118{
119 auto SetRange = [](std::array<double, 2>& range, double min, double max) {
120 range[0] = min;
121 range[1] = max;
122 };
123 // Hit errors
124 SetRange(fRHitDx, 0.0000, 5.00); // [cm]
125 SetRange(fRHitDy, 0.0000, 5.00); // [cm]
126 SetRange(fRHitDu, 0.0000, 5.00); // [cm]
127 SetRange(fRHitDv, 0.0000, 5.00); // [cm]
128 SetRange(fRHitDt, 0.0000, 0.15); // [ns]
129 // Residuals
130 SetRange(fRResX, -2.00, 2.00);
131 SetRange(fRResY, -4.00, 4.00);
132 SetRange(fRResU, -2.00, 2.00);
133 SetRange(fRResV, -4.00, 4.00);
134 SetRange(fRResT, -0.50, 0.50);
135}
136
137// ---------------------------------------------------------------------------------------------------------------------
138//
140{
141 // Base QA execution
143
144 // TOF-specific QA execution
145 if constexpr (0) { // DEBUG
146 auto PrintPoint = [&](const CbmTofPoint* point, std::stringstream& m) {
147 m << "point: trk=" << point->GetTrackID() << ", ";
148 auto pointAddress = point->GetDetectorID();
149 int32_t rpcAddress = (pointAddress << 11); // Address of RPC
150 auto iSmType = CbmTofAddress::GetSmType(pointAddress);
151 auto iSm = CbmTofAddress::GetSmId(pointAddress);
152 auto iRpc = CbmTofAddress::GetRpcId(pointAddress);
153 m << "iSt=" << fpDetInterface->GetTrackingStationId(pointAddress) << ", ";
154 m << "address=" << pointAddress << ", rpcAddress= " << rpcAddress;
155 m << ", (" << iSmType << "," << iSm << "," << iRpc << "), ";
156 m << "x=" << point->GetX() << ", y=" << point->GetY() << ", z=" << point->GetZ();
157 };
158
159 if (IsMCUsed()) {
160 // Print hit sample
161 LOG(info) << fName << ": ===== Hit Sample";
162 for (int iHit = 0; iHit < fpHits->GetEntriesFast(); ++iHit) {
163 const auto* pHit = dynamic_cast<const Hit_t*>(fpHits->At(iHit));
164 if (!pHit) {
165 LOG(error) << fName << "::FillHistogramsPerHit: hit with index " << iHit << " not found";
166 continue;
167 }
168
169 int address = pHit->GetAddress();
170 int iHitSmType = CbmTofAddress::GetSmType(address);
171 int iHitSm = CbmTofAddress::GetSmId(address);
172 int iHitRpc = CbmTofAddress::GetRpcId(address);
173
174 auto* pHitMatch = dynamic_cast<CbmMatch*>(fpHitMatches->At(iHit));
175 std::stringstream msg;
176 msg << fName << ": hit: id=" << iHit << ", NofLinks=" << pHitMatch->GetNofLinks() << ", ";
177 msg << "iSt=" << fpDetInterface->GetTrackingStationId(address) << ", ";
178 msg << "RPC=(" << iHitSmType << "," << iHitSm << "," << iHitRpc << ")";
179 if (pHitMatch->GetNofLinks() == 0) {
180 continue;
181 }
182 const auto& bestLink = pHitMatch->GetMatchedLink();
183 for (int iLink = 0; iLink < pHitMatch->GetNofLinks(); ++iLink) {
184 const auto& link = pHitMatch->GetLink(iLink);
185 int iPointExt = link.GetIndex();
186 int iEvent = link.GetEntry();
187 int iFile = link.GetFile();
188 msg << "\n\tLink " << iLink << ": " << iPointExt << ", " << iEvent << ", " << iFile << " (best? ";
189 msg << (bestLink == link) << ')';
190 if (iPointExt < 0) {
191 continue;
192 }
193 msg << ", ";
194 auto* pPoint = dynamic_cast<CbmTofPoint*>(fpMCPoints->Get(link));
195 PrintPoint(pPoint, msg);
196 }
197 LOG(info) << msg.str();
198 }
199 // Print point sample
200 LOG(info) << fName << ": ===== Point Sample";
201 if (IsMCUsed()) {
202 for (int iE = 0; iE < fpMCEventList->GetNofEvents(); ++iE) {
203 int iFile = fpMCEventList->GetFileIdByIndex(iE);
204 int iEvent = fpMCEventList->GetEventIdByIndex(iE);
205 int nPoints = fpMCPoints->Size(iFile, iEvent);
206 for (int iPoint = 0; iPoint < nPoints; ++iPoint) {
207 auto* pPoint = dynamic_cast<CbmTofPoint*>(fpMCPoints->Get(iFile, iEvent, iPoint));
208 std::stringstream msg;
209 msg << "link: " << iPoint << ", " << iEvent << ", " << iFile << ", ";
210 PrintPoint(pPoint, msg);
211 LOG(info) << '\t' << msg.str();
212 }
213 }
214 }
215 }
216 }
217}
218
219// ---------------------------------------------------------------------------------------------------------------------
220//
222{
223 auto iHit = GetHitQaData().GetHitIndex();
224 const auto* pHit = dynamic_cast<const Hit_t*>(fpHits->At(iHit));
225 if (!pHit) {
226 LOG(error) << fName << "::FillHistogramsPerHit: hit with index " << iHit << " not found";
227 return;
228 }
229
230 int address = pHit->GetAddress();
231 int iHitSmType = CbmTofAddress::GetSmType(address);
232 int iHitSm = CbmTofAddress::GetSmId(address);
233 int iHitRpc = CbmTofAddress::GetRpcId(address);
234
235 { // Check, if the hit is created on the one of the defined RPCs. If not, save to address into map
236 double xHit = pHit->GetX();
237 double yHit = pHit->GetY();
238 double zHit = pHit->GetZ();
239 fvph_hit_xy_vs_cell[iHitSmType][iHitSm][iHitRpc]->Fill(xHit, yHit);
240 fvph_hit_zx_vs_cell[iHitSmType][iHitSm][iHitRpc]->Fill(zHit, xHit);
241 fvph_hit_zy_vs_cell[iHitSmType][iHitSm][iHitRpc]->Fill(zHit, yHit);
242 }
243}
244
245// ---------------------------------------------------------------------------------------------------------------------
246//
248{
249 // TOF tracking detector interface
250 auto initStatus = CbmCaInputQaBase::InitQa();
251 if (kSUCCESS != initStatus) {
252 return initStatus;
253 }
254
255 // ----- Histogram initialization
256 // Hit occupancy vs. TOF cell
257 MakeQaDirectory("occup_cell/");
258 const auto& trkStationIdMap{fpDetInterface->GetTrkStationIdMap()};
259 int nSmTypes = trkStationIdMap.GetNofSmTypes();
260
261 fvph_hit_xy_vs_cell.resize(nSmTypes);
262 fvph_hit_zx_vs_cell.resize(nSmTypes);
263 fvph_hit_zy_vs_cell.resize(nSmTypes);
264 for (int iSmType = 0; iSmType < nSmTypes; ++iSmType) {
265 if (iSmType == 5) {
266 continue;
267 } // skip Bmon
268 MakeQaDirectory(Form("occup_cell/sm_type_%d", iSmType));
269 int nSm = trkStationIdMap.GetNofSm(iSmType);
270 int nRpc = trkStationIdMap.GetNofRpc(iSmType);
271 fvph_hit_xy_vs_cell[iSmType].resize(nSm);
272 fvph_hit_zx_vs_cell[iSmType].resize(nSm);
273 fvph_hit_zy_vs_cell[iSmType].resize(nSm);
274 for (int iSm = 0; iSm < nSm; ++iSm) {
275 MakeQaDirectory(Form("occup_cell/sm_type_%d/sm_%d/", iSmType, iSm));
276 fvph_hit_xy_vs_cell[iSmType][iSm].resize(nRpc, nullptr);
277 fvph_hit_zx_vs_cell[iSmType][iSm].resize(nRpc, nullptr);
278 fvph_hit_zy_vs_cell[iSmType][iSm].resize(nRpc, nullptr);
279 for (int iRpc = 0; iRpc < nRpc; ++iRpc) {
280 const char* dir = Form("occup_cell/sm_type_%d/sm_%d/rpc%d", iSmType, iSm, iRpc);
281 TString name = Form("%s/occup_xy_smt%d_sm%d_rpc%d", dir, iSmType, iSm, iRpc);
282 TString title = Form("Hit Occupancy in xy-Plane for iSmType = %d, iSm = %d, iRpc = %d", iSmType, iSm, iRpc);
283 title += ";x_{hit} [cm];y_{hit} [cm]";
284 fvph_hit_xy_vs_cell[iSmType][iSm][iRpc] =
286 name = Form("%s/occup_zx_smt%d_sm%d_rpc%d", dir, iSmType, iSm, iRpc);
287 title = Form("Hit Occupancy in zx-Plane for iSmType = %d, iSm = %d, iRpc = %d", iSmType, iSm, iRpc);
288 title += ";z_{hit} [cm];x_{hit} [cm]";
289 fvph_hit_zx_vs_cell[iSmType][iSm][iRpc] =
290 MakeQaObject<TH2F>(name, title, fNbinsZ, frZmin.back(), frZmax.back(), fNbXo, fLoXo, fUpXo);
291 name = Form("%s/occup_zy_smt%d_sm%d_rpc%d", dir, iSmType, iSm, iRpc);
292 title = Form("Hit Occupancy in zy-Plane for iSmType = %d, iSm = %d, iRpc = %d", iSmType, iSm, iRpc);
293 title += ";z_{hit} [cm];y_{hit} [cm]";
294 fvph_hit_zy_vs_cell[iSmType][iSm][iRpc] =
295 MakeQaObject<TH2F>(name, title, fNbinsZ, frZmin.back(), frZmax.back(), fNbYo, fLoYo, fUpYo);
296 }
297 }
298 }
299
300 return kSUCCESS;
301}
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)
void CreateSummary() override
Creates summary cavases, tables etc.
void ExecQa() override
Fills histograms per event or time-slice.
CbmCaInputQaBase(const char *name, int verbose, bool isMCUsed)
InitStatus InitQa() override
Initializes QA task.
const cbm::algo::RecoSetupUnit_t< ToCbmModuleId(DetID)> * fpDetInterface
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.
int fLoXo
X min in occupancy [cm].
int fUpXo
X max in occupancy [cm].
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.
int32_t GetNofLinks() const
Definition CbmMatch.h:42
T * MakeQaObject(TString sName, TString sTitle, Args... args)
Definition CbmQaIO.h:260
static int32_t GetSmId(uint32_t address)
static int32_t GetRpcId(uint32_t address)
static int32_t GetSmType(uint32_t address)
Geometric intersection of a MC track with a TOFb detector.
Definition CbmTofPoint.h:44
int GetHitIndex() const
Gets hit index.