CbmRoot
Loading...
Searching...
No Matches
CbmCaTrackFitQa.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 "CbmCaTrackFitQa.h"
11
12#include "CaToolsField.h"
13#include "CaToolsMCData.h"
14#include "CbmL1Track.h"
15#include "CbmQaCanvas.h"
16#include "CbmQaUtil.h"
17#include "KfFieldRegion.h"
18#include "KfTrackKalmanFilter.h"
19#include "TF1.h"
20#include "TFormula.h"
21#include "TH1.h"
22#include "TProfile.h"
23#include "TString.h"
24
25#include <algorithm>
26
27using namespace cbm::algo::ca;
29
30// *******************************************************
31// ** Implementation of cbm::ca::TrackFitQa functions **
32// *******************************************************
33
36
37using namespace cbm::algo; // TODO: SZh 16.05.2023: Remove this line
38
39// ---------------------------------------------------------------------------------------------------------------------
40//
41TrackFitQa::TrackFitQa(const char* pointTag, const char* prefix, std::shared_ptr<ObjList_t> pObjList)
42 : CbmQaIO(Form("%s_%s", prefix, pointTag), pObjList)
43{
45}
46
47// ---------------------------------------------------------------------------------------------------------------------
48//
50{
51 auto* pCanv = MakeQaObject<CbmQaCanvas>("canv_residuals", " residuals", kCXSIZEPX * 4, kCYSIZEPX * 2);
52 pCanv->Divide2D(7);
53
54
55 for (int iType = static_cast<int>(ETrackParType::BEGIN); iType < static_cast<int>(ETrackParType::END); ++iType) {
56 ETrackParType type = static_cast<ETrackParType>(iType);
57 if (fvbParIgnored[type]) {
58 continue;
59 }
60 pCanv->cd(iType + 1);
61 fvphResiduals[type]->Draw();
62 }
63
64 return pCanv;
65}
66
67// ---------------------------------------------------------------------------------------------------------------------
68//
70{
71 auto* pCanv = MakeQaObject<CbmQaCanvas>(fsPrefix + "_canv_pulls", " pulls", kCXSIZEPX * 4, kCYSIZEPX * 2);
72 pCanv->Divide2D(7);
73
74 for (int iType = static_cast<int>(ETrackParType::BEGIN); iType < static_cast<int>(ETrackParType::END); ++iType) {
75 ETrackParType type = static_cast<ETrackParType>(iType);
76 if (fvbParIgnored[type]) {
77 continue;
78 }
79 auto fit = TF1("fitpull", "[0] * TMath::Exp(TMath::ASinH(-0.5*[3]*((x-[1])/[2])**2)/[3])", -10., 10.);
80 fit.SetParameters(100, 0., 1., .3);
81 fit.SetParLimits(3, 0., 2.);
82 pCanv->cd(iType + 1);
83 fvphPulls[type]->Draw();
85 }
86
87 return pCanv;
88}
89
90// ---------------------------------------------------------------------------------------------------------------------
91void TrackFitQa::FillResAndPull(ETrackParType type, double recoVal, double recoErr, double trueVal)
92{
93 if (fvbParIgnored[type]) {
94 return;
95 }
96 double res = recoVal - trueVal;
97 double pull = res / recoErr;
98 if (type == ETrackParType::kQP) { // for the q/p parameter, the residual is calculated for the momentum
99 res = (recoVal / trueVal - 1.);
100 }
101 fvphResiduals[type]->Fill(res);
102 fvphPulls[type]->Fill(pull);
103}
104
105// ---------------------------------------------------------------------------------------------------------------------
106//
108{
109 // Init default distribution properties
111
113
114 auto CreateResidualHisto = [&](ETrackParType t, const char* name, const char* title) {
115 if (fvbParIgnored[t]) {
116 return;
117 }
118 TString sPrefix = (fsTitle.Length() > 0) ? fsTitle + " point residual for " : "residual for ";
119 fvphResiduals[t] = MakeQaObject<TH1F>(name, sPrefix + title, fvRBins[t], fvRLo[t], fvRUp[t]);
120 };
121
122 auto CreatePullHisto = [&](ETrackParType t, const char* name, const char* title) {
123 if (fvbParIgnored[t]) {
124 return;
125 }
126 TString sPrefix = (fsTitle.Length() > 0) ? fsTitle + " point pull for " : "pull for ";
127 fvphPulls[t] = MakeQaObject<TH1F>(name, sPrefix + title, fvPBins[t], fvPLo[t], fvPUp[t]);
128 };
129
130 CreateResidualHisto(ETrackParType::kX, "res_x", "x-coordinate;x^{reco} - x^{MC} [cm]");
131 CreateResidualHisto(ETrackParType::kY, "res_y", "y-coordinate;y^{reco} - y^{MC} [cm]");
132 CreateResidualHisto(ETrackParType::kTX, "res_tx", "slope along x-axis;T_{x}^{reco} - T_{x}^{MC}");
133 CreateResidualHisto(ETrackParType::kTY, "res_ty", "slope along y-axis;T_{y}^{reco} - T_{y}^{MC}");
134 CreateResidualHisto(ETrackParType::kQP, "res_P", "momentum; (p^{reco} - p^{MC})/p^{MC} []");
135 CreateResidualHisto(ETrackParType::kTIME, "res_t", "time;t^{reco} - t^{MC} [ns]");
136 CreateResidualHisto(ETrackParType::kVI, "res_vi", "inverse speed;v^{-1}_{reco} - v^{-1}_{MC} [c^{-1}]");
137
138 CreatePullHisto(ETrackParType::kX, "pull_x", "x-coordinate;(x^{reco} - x^{MC})/#sigma_{x}");
139 CreatePullHisto(ETrackParType::kY, "pull_y", "y-coordinate;(y^{reco} - y^{MC})/#sigma_{y}");
140 CreatePullHisto(ETrackParType::kTX, "pull_tx", "slope along x-axis;(T_{x}^{reco} - T_{x}^{MC})/#sigma_{T_{x}}");
141 CreatePullHisto(ETrackParType::kTY, "pull_ty", "slope along y-axis;(T_{y}^{reco} - T_{y}^{MC})/#sigma_{T_{y}}");
142 CreatePullHisto(ETrackParType::kQP, "pull_qp", "charge over mom.;((q/p)^{reco} - (q/p)^{MC})/#sigma_{q/p}");
143 CreatePullHisto(ETrackParType::kTIME, "pull_t", "time;(t^{reco} - t^{MC})/#sigma_{t}");
144 CreatePullHisto(ETrackParType::kVI, "pull_vi", "inverse speed;(v^{-1}_{reco} - v^{-1}_{MC})/#sigma_{v^{-1}}");
145
146 // FIXME: Replace hardcoded parameters with variables
147 fph_res_p_pMC = MakeQaObject<TProfile>("res_p_vs_pMC", "", 100, 0.0, 10.0, -2., 2.);
148 fph_res_phi_phiMC = MakeQaObject<TProfile>("res_phi_vs_phiMC", "", 100, -3.2, 3.2, -2., 2.);
149 fph_res_theta_thetaMC = MakeQaObject<TProfile>("res_theta_vs_phiMC", "", 100, 0., 3.2, -2., 2.);
150
151 // Set histogram titles
152 TString sPrefix = (fsTitle.Length() > 0) ? fsTitle + " point " : "";
153 fph_res_p_pMC->SetTitle(sPrefix + " resolution of momentum;p^{MC} [GeV/c];#delta p [GeV/c]");
154 fph_res_phi_phiMC->SetTitle(sPrefix + " resolution of polar angle;#phi^{MC} [rad];#delta#phi [rad]");
155 fph_res_theta_thetaMC->SetTitle(sPrefix + " resolution of polar angle;#theta^{MC} [rad];#delta#theta [rad]");
156}
157
158// ---------------------------------------------------------------------------------------------------------------------
159//
160void TrackFitQa::Fill(const TrackParamV& trPar, const tools::MCPoint& mcPoint, bool bTimeMeasured, double /*weight*/)
161{
162 // Probably, a bottleneck
164 fitter.SetParticleMass(fMass);
165 fitter.SetMask(fmask::One());
166 fitter.SetDoFitVelocity(true);
167 fitter.SetTrack(trPar);
170 fitter.Extrapolate(mcPoint.GetZ(), fieldRegion);
171
172 const TrackParamV& trParExtr = fitter.Tr(); // Track parameters extrapolated to given MC point
173
174 // ** Time-independent measurements **
175 FillResAndPull(ETrackParType::kX, trParExtr.GetX()[0], trParExtr.GetXError()[0], mcPoint.GetX());
176 FillResAndPull(ETrackParType::kY, trParExtr.GetY()[0], trParExtr.GetYError()[0], mcPoint.GetY());
177 FillResAndPull(ETrackParType::kTX, trParExtr.GetTx()[0], trParExtr.GetTxError()[0], mcPoint.GetTx());
178 FillResAndPull(ETrackParType::kTY, trParExtr.GetTy()[0], trParExtr.GetTyError()[0], mcPoint.GetTy());
179 FillResAndPull(ETrackParType::kQP, trParExtr.GetQp()[0], trParExtr.GetQpError()[0], mcPoint.GetQp());
180
181 // Momentum resolution
182 double recoP = std::fabs(mcPoint.GetCharge() / trParExtr.GetQp()[0]); // reco mom. (with MC charge)
183 double resP = recoP - mcPoint.GetP(); // residual of total momentum
184
185 // Phi resolution
186 double mcPhi = mcPoint.GetPhi();
187 double recoTx = trParExtr.Tx()[0];
188 double recoTy = trParExtr.Ty()[0];
189 double resPhi = atan2(recoTx * cos(mcPhi) + recoTy * sin(mcPhi), -recoTx * cos(mcPhi) + recoTy * sin(mcPhi));
190
191 // Theta resolution
192 double resTheta = trParExtr.GetTheta()[0] - mcPoint.GetTheta(); // residual of polar angle
193
194 resPhi = std::atan2(std::sin(resPhi), std::cos(resPhi)); // overflow over (-pi, pi] protection
195
196 fph_res_p_pMC->Fill(mcPoint.GetP(), resP);
197 fph_res_phi_phiMC->Fill(mcPoint.GetPhi(), resPhi);
198 fph_res_theta_thetaMC->Fill(mcPoint.GetTheta(), resTheta);
199
200 // ** Time-dependent measurements **
201 if (bTimeMeasured) {
202 FillResAndPull(ETrackParType::kTIME, trParExtr.GetTime()[0], trParExtr.GetTimeError()[0], mcPoint.GetTime());
203 FillResAndPull(ETrackParType::kVI, trParExtr.GetVi()[0], trParExtr.GetViError()[0], mcPoint.GetInvSpeed());
204 }
205}
206
207// ---------------------------------------------------------------------------------------------------------------------
208//
210{
211 // ** Residual distribution parameters **
213 fvRLo[ETrackParType::kX] = -4.e-3;
214 fvRUp[ETrackParType::kX] = +4.e-3;
216 fvRLo[ETrackParType::kY] = -4.e-2;
217 fvRUp[ETrackParType::kY] = +4.e-2;
219 fvRLo[ETrackParType::kTX] = -4.e-3;
220 fvRUp[ETrackParType::kTX] = +4.e-3;
222 fvRLo[ETrackParType::kTY] = -4.e-3;
223 fvRUp[ETrackParType::kTY] = +4.e-3;
233
234 // ** Pulls distribution parameters **
236 fvPLo[ETrackParType::kX] = -10.;
237 fvPUp[ETrackParType::kX] = +10.;
239 fvPLo[ETrackParType::kY] = -10.;
240 fvPUp[ETrackParType::kY] = +10.;
242 fvPLo[ETrackParType::kTX] = -10.;
243 fvPUp[ETrackParType::kTX] = +10.;
245 fvPLo[ETrackParType::kTY] = -10.;
246 fvPUp[ETrackParType::kTY] = +10.;
248 fvPLo[ETrackParType::kQP] = -10.;
249 fvPUp[ETrackParType::kQP] = +10.;
254 fvPLo[ETrackParType::kVI] = -10.;
255 fvPUp[ETrackParType::kVI] = +10.;
256}
257
258// ---------------------------------------------------------------------------------------------------------------------
259//
260void TrackFitQa::SetResidualHistoProperties(ETrackParType type, int nBins, double lo, double up)
261{
262 fvRBins[type] = nBins;
263 fvRLo[type] = lo;
264 fvRUp[type] = up;
265}
266
267// ---------------------------------------------------------------------------------------------------------------------
268//
269void TrackFitQa::SetPullHistoProperties(ETrackParType type, int nBins, double lo, double up)
270{
271 fvPBins[type] = nBins;
272 fvPLo[type] = lo;
273 fvPUp[type] = up;
274}
Tracking Field class (header)
Data structure for internal tracking MC-information (header)
QA submodule for track fit results (residuals and puls) at selected z-coordinate (header)
Definition of the CbmQaCanvas class.
Useful utilities for CBM QA tasks.
Magnetic flux density interpolation along the track vs. z-coordinate (header)
friend fvec cos(const fvec &a)
friend fvec sin(const fvec &a)
Track fit utilities for the CA tracking based on the Kalman filter.
ROOT object IO interface for QA.
Definition CbmQaIO.h:44
T * MakeQaObject(TString sName, TString sTitle, Args... args)
Definition CbmQaIO.h:261
TString fsPrefix
Unique prefix for all writeable root.
Definition CbmQaIO.h:159
@ kSAMEDIR
Objects of different type will be stored to root directory.
EStoringMode fStoringMode
Objects storing mode.
Definition CbmQaIO.h:161
Magnetic field region, corresponding to a hit triplet.
static EFieldType fgOriginalFieldType
Global field type.
static FieldFn_t fgOriginalField
Global variable to store the fielf funciton (x,y,z)->(Bx,By,Bz)
void Extrapolate(DataT z, const kf::FieldRegion< DataT > &F)
kf::TrackParam< DataT > & Tr()
void SetParticleMass(DataT mass)
set particle mass for the fit
void SetTrack(const kf::TrackParam< T > &t)
T GetTxError() const
Gets error of slope along x-axis.
T GetVi() const
Gets inverse velocity [ns/cm] in downstream direction.
T GetXError() const
Gets x position error [cm].
T GetYError() const
Gets y position error [cm].
T GetTy() const
Gets slope along y-axis.
T GetTimeError() const
Gets time error [ns].
T Tx() const
Gets slope along x-axis.
T GetTime() const
Gets time [ns].
T GetTyError() const
Gets error of slope along y-axis.
T GetTheta() const
Gets polar angle [rad].
T GetTx() const
Gets slope along x-axis.
T GetViError() const
Gets inverse velocity error [ns/cm].
T GetQp() const
Gets charge over momentum [ec/GeV].
T GetQpError() const
Gets error of charge over momentum [ec/GeV].
T GetY() const
Gets y position [cm].
T Ty() const
Gets slope along y-axis.
T GetX() const
Gets x position [cm].
static fmask One()
Set of histograms to monitor track parameters.
static constexpr int kCXSIZEPX
Canvas size along x-axis [px].
TrackParArray_t< double > fvRUp
Upper boundary, residuals.
TrackParArray_t< TH1F * > fvphResiduals
Residuals for different track parameters.
TrackParArray_t< double > fvRLo
Lower boundary, residuals.
TrackFitQa(const char *pointTag, const char *prefix, std::shared_ptr< ObjList_t > pObjList)
Constructor.
TrackParArray_t< int > fvPBins
Number of bins, pulls.
TProfile * fph_res_theta_thetaMC
Resolution of polar angle [rad].
TrackParArray_t< TH1F * > fvphPulls
Pulls for different track parameters.
TString fsTitle
Title of the point.
void Init()
Initializes histograms.
static constexpr int kCYSIZEPX
Canvas size along y-axis [px].
void SetDefaultProperties()
Sets default histogram and track parameter properties.
TProfile * fph_res_phi_phiMC
Resolution of azimuthal angle [rad].
TrackParArray_t< bool > fvbParIgnored
Flag: true - parameter is ignored.
TrackParArray_t< int > fvRBins
Number of bins, residuals.
void FillResAndPull(ETrackParType type, double recoVal, double recoErr, double trueVal)
Fills residual and pull for a given track parameter.
CbmQaCanvas * CreatePullPlot()
Creates pulls plot.
void SetPullHistoProperties(ETrackParType type, int nBins, double lo, double up)
Sets properties for a pull histogram.
TrackParArray_t< double > fvPUp
Upper boundary, pulls.
TrackParArray_t< double > fvPLo
Lower boundary, pulls.
void Fill(const cbm::algo::kf::TrackParamV &trPar, const tools::MCPoint &mcPoint, bool bTimeMeasured, double weight=1)
Fills pull and residual histograms.
void SetResidualHistoProperties(ETrackParType type, int nBins, double lo, double up)
Sets properties for a residual histogram.
TProfile * fph_res_p_pMC
Resolution of momentum [GeV/c].
CbmQaCanvas * CreateResidualPlot()
Creates residuals plot.
Class describes a unified MC-point, used in CA tracking QA analysis.
double GetTime() const
Gets time [ns].
double GetPhi() const
Gets track azimuthal angle at reference z of station [rad].
double GetTx() const
Gets slope along x-axis at reference z of station.
double GetTheta() const
Gets polar angle at reference z of station [rad].
double GetZ() const
Gets z coordinate at reference z of station [cm].
double GetY() const
Gets y coordinate at reference z of station [cm].
double GetX() const
Gets x coordinate at reference z of station [cm].
double GetTy() const
Gets slope along x-axis at reference z of station.
int GetInvSpeed() const
Gets inverse speed at reference z of station [ns/cm].
double GetQp() const
Gets track charge over momentum at reference z of station [ec/GeV].
double GetP() const
Gets track momentum absolute value at reference z of station [GeV/c].
double GetCharge() const
Gets charge of the particle [e].
TODO: SZh 8.11.2022: add selection of parameterisation.
Definition CaBranch.h:14
void SetOriginalCbmField()
pass the original magnetic field to L1Algo
ETrackParType
Enumeration for track parameter type.
@ BEGIN
begin of enumeration
@ kVI
inverse speed
@ kQP
charge over total momentum
@ END
end of enumeration
@ kTY
slope along y-axis
@ kTX
slope along x-axis
std::tuple< double, double > FitKaniadakisGaussian(TH1 *pHist)
Fit a histogram with Kaniadakis Gaussian Distribution.
Definition CbmQaUtil.cxx:88