CbmRoot
Loading...
Searching...
No Matches
CbmTofTrackletTools.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Norbert Herrmann, Florian Uhlig [committer] */
4
11#include "CbmTofTrackletTools.h"
12
13#include "CbmTofHit.h"
14#include "CbmTofTracklet.h"
15#include "LKFMinuit.h"
16#include "Rtypes.h" // for Double_t, Double32_t, Int_t, etc
17#include "TDecompSVD.h"
18#include "TMatrixD.h"
19#include "TMatrixFSymfwd.h" // for TMatrixFSym
20#include "TVectorD.h"
21
22#include <Logger.h>
23
24using std::vector;
26
28{
30 //if( &fMinuit == NULL ) fMinuit.Initialize();
31}
32
34
35Double_t* CbmTofTrackletTools::Line3DFit(CbmTofTracklet* pTrk, Int_t iDetId)
36{
37 TGraph2DErrors* gr = new TGraph2DErrors();
38 Int_t NHit = 0;
39 for (Int_t iHit = 0; iHit < pTrk->GetNofHits(); iHit++) {
40 if (iDetId == pTrk->GetTofDetIndex(iHit)) continue; // skip this hit of tracklet
41 gr->SetPoint(NHit, pTrk->GetTofHitPointer(iHit)->GetX(), pTrk->GetTofHitPointer(iHit)->GetY(),
42 pTrk->GetTofHitPointer(iHit)->GetZ());
43 gr->SetPointError(NHit, pTrk->GetTofHitPointer(iHit)->GetDx(), pTrk->GetTofHitPointer(iHit)->GetDy(),
44 pTrk->GetTofHitPointer(iHit)->GetDz());
45 NHit++;
46 }
47 // fit the graph now
48 Double_t pStart[4] = {0., 0., 0., 0.};
49 pStart[0] = pTrk->GetFitX(0.);
50 pStart[1] = (pTrk->GetTrackParameter())->GetTx();
51 pStart[2] = pTrk->GetFitY(0.);
52 pStart[3] = (pTrk->GetTrackParameter())->GetTy();
53 LOG(debug1) << "Line3DFit init: X0 " << pStart[0] << ", TX " << pStart[1] << ", Y0 " << pStart[2] << ", TY "
54 << pStart[3];
55 fMinuit.DoFit(gr, pStart);
56 gr->Delete();
57 Double_t* dRes;
58 // LOG(info) << "Get fit results ";
59 dRes = fMinuit.GetParFit();
60 LOG(debug1) << "Line3Dfit result: " << gMinuit->fCstatu << " : X0 " << dRes[0] << ", TX " << dRes[1] << ", Y0 "
61 << dRes[2] << ", TY " << dRes[3] << ", Chi2DoF: " << fMinuit.GetChi2DoF();
62 return dRes;
63}
64
65Double_t CbmTofTrackletTools::FitTt(CbmTofTracklet* pTrk, Int_t iDetId)
66{
67 // Call with iDetId=-1 for full Tracklet fit
68 Int_t nValidHits = 0;
69 Int_t iHit1 = 0;
70 Double_t dDist1 = 0.;
71 //LOG(info) << "FitTt: " << pTrk->GetNofHits() << " hits, exclude " << Form("0x%08x",iDetId);
72 Double_t aR[pTrk->GetNofHits()];
73 Double_t at[pTrk->GetNofHits()];
74 Double_t ae[pTrk->GetNofHits()];
75 for (Int_t iHit = 0; iHit < pTrk->GetNofHits(); iHit++) {
76 if (iDetId == pTrk->GetTofDetIndex(iHit)) continue;
77 if (nValidHits == 0) {
78 iHit1 = iHit;
79 //LOG(info) << "Init Dist1 with " << iHit1;
80 Double_t* dPar = Line3DFit(pTrk, iDetId); // spatial fit without iDetId, dPar[1] = slope dx/dz, dPar[3]=dy/dz
81 dDist1 = pTrk->GetTofHitPointer(iHit1)->GetZ() * TMath::Sqrt(1. + dPar[1] * dPar[1] + dPar[3] * dPar[3]);
82 //LOG(info) << "Dist1 = " << dDist1;
83 }
84 Double_t dSign = 1.;
85 if (pTrk->GetTofHitPointer(iHit)->GetZ() < pTrk->GetTofHitPointer(iHit1)->GetZ()) dSign = -1.;
86 aR[nValidHits] = dDist1 + dSign * pTrk->Dist3D(pTrk->GetTofHitPointer(iHit), pTrk->GetTofHitPointer(iHit1));
87 at[nValidHits] = pTrk->GetTofHitPointer(iHit)->GetTime();
88 ae[nValidHits] = 0.1; // const timing error, FIXME (?)
89 //LOG(info) << "Init vector index " << nValidHits;
90 nValidHits++;
91 }
92 if (nValidHits < 2) return 0.;
93 if (nValidHits == 2) return (at[0] - at[1]) / (aR[0] - aR[1]);
94
95 Double_t RRsum = 0; // Values will follow this procedure:
96 Double_t Rsum = 0; // $Rsum=\sum_{i}^{nValidHits}\frac{R_i}{e_i^2}$
97 Double_t tsum = 0; // where e_i will always be the error on the t measurement
98 Double_t esum = 0; // RR=R^2 in numerator, e denotes 1 in numerator , Rt= R*t in numerator
99 Double_t Rtsum = 0; //
100 Double_t sig_weight = 0; // ae^2
101 Double_t yoffset = at[0] - 10; // T0 time offset to scale times to ns regime and not 10^10ns
102 for (Int_t i = 0; i < nValidHits; i++) {
103 at[i] -= yoffset; // substract offset
104 sig_weight = (ae[i] * ae[i]);
105 Rsum += (aR[i] / sig_weight);
106 tsum += (at[i] / sig_weight);
107 RRsum += (aR[i] * aR[i] / sig_weight);
108 Rtsum += (aR[i] * at[i] / sig_weight);
109 esum += (1 / sig_weight);
110 }
111 Double_t det_cov_mat =
112 esum * RRsum
113 - Rsum * Rsum; // Determinant of inverted Covariance Matrix -> 1/det is common Faktor of Covariance Matrix
114 Double_t dT0 = (RRsum * tsum - Rsum * Rtsum) / det_cov_mat; // Best Guess for time at origin
115 Double_t dTt = (-Rsum * tsum + esum * Rtsum) / det_cov_mat; // Best guess for inverted velocity
116 Double_t dT0Err = TMath::Sqrt(RRsum / det_cov_mat); // sqrt of (0,0) in Covariance matrix -> error on fT0
117 dT0Err /= dT0; // relative error
118 Double_t dTtErr = TMath::Sqrt(esum / det_cov_mat); // sqrt of (1,1) in Covariance Matrix -> error on fTt
119 Double_t dT0TtCov = -Rsum / det_cov_mat; // (0,1)=(1,0) in Covariance Matrix -> cov(fT0,fTt)
120 dT0 += yoffset; // Adding yoffset again
121 // store fit values with tracklet
122 pTrk->SetTt(dTt); // dangerous & dirty, overwrites common fit
123 pTrk->SetTtErr(dTtErr);
124 pTrk->SetT0(dT0);
125 pTrk->SetT0Err(dT0Err);
126 pTrk->SetT0TtCov(dT0TtCov);
127 return dTt;
128}
129
130Double_t CbmTofTrackletTools::GetXdif(CbmTofTracklet* pTrk, Int_t iDetId, CbmTofHit* pHit)
131{
132 Double_t dXref = 0.;
133 Int_t iNref = 0;
134 Double_t dTx = 0;
135
136 if (1) {
137 for (Int_t iHL = 0; iHL < pTrk->GetNofHits() - 1; iHL++) {
138 if (iDetId == pTrk->GetTofDetIndex(iHL) || 0 == pTrk->GetTofDetIndex(iHL)) continue; // exclude faked hits
139 for (Int_t iHH = iHL + 1; iHH < pTrk->GetNofHits(); iHH++) {
140 if (iDetId == pTrk->GetTofDetIndex(iHH) || 0 == pTrk->GetTofDetIndex(iHH)) continue; // exclude faked hits
141 //dTt+=(pTrk->GetTofHitPointer(iHH)->GetTime()-pTrk->GetTofHitPointer(iHL)->GetTime())/(pTrk->GetTofHitPointer(iHH)->GetR()-pTrk->GetTofHitPointer(iHL)->GetR()); // for projective geometries only !!!
142 dTx += (pTrk->GetTofHitPointer(iHH)->GetX() - pTrk->GetTofHitPointer(iHL)->GetX())
143 / (pTrk->GetTofHitPointer(iHH)->GetZ() - pTrk->GetTofHitPointer(iHL)->GetZ());
144 iNref++;
145 }
146 }
147 dTx /= iNref;
148 }
149 else {
150 dTx = pTrk->GetTrackParameter()->GetTx();
151 }
152
153 iNref = 0;
154 for (Int_t iHit = 0; iHit < pTrk->GetNofHits(); iHit++) {
155 if (iDetId == pTrk->GetTofDetIndex(iHit) || 0 == pTrk->GetTofDetIndex(iHit)) continue;
156
157 Double_t dDZ = pHit->GetZ() - pTrk->GetTofHitPointer(iHit)->GetZ();
158 dXref += pTrk->GetTofHitPointer(iHit)->GetX() + dTx * dDZ;
159 iNref++;
160 }
161
162 if (iNref == 0) {
163 LOG(error) << "DetId " << iDetId << ", Nref " << iNref << " sizes " << pTrk->GetNofHits() << ", "
164 << pTrk->GetNofHits();
165 return 1.E20;
166 }
167
168 dXref /= iNref;
169
170 return pHit->GetX() - dXref;
171}
172
173Double_t CbmTofTrackletTools::GetYdif(CbmTofTracklet* pTrk, Int_t iDetId, CbmTofHit* pHit)
174{
175 Double_t dYref = 0.;
176 Int_t iNref = 0;
177 Double_t dTy = 0;
178
179 if (1) {
180 for (Int_t iHL = 0; iHL < pTrk->GetNofHits() - 1; iHL++) {
181 if (iDetId == pTrk->GetTofDetIndex(iHL) || 0 == pTrk->GetTofDetIndex(iHL)) continue; // exclude faked hits
182 for (Int_t iHH = iHL + 1; iHH < pTrk->GetNofHits(); iHH++) {
183 if (iDetId == pTrk->GetTofDetIndex(iHH) || 0 == pTrk->GetTofDetIndex(iHH)) continue; // exclude faked hits
184 dTy += (pTrk->GetTofHitPointer(iHH)->GetY() - pTrk->GetTofHitPointer(iHL)->GetY())
185 / (pTrk->GetTofHitPointer(iHH)->GetZ() - pTrk->GetTofHitPointer(iHL)->GetZ());
186 iNref++;
187 }
188 }
189 dTy /= iNref;
190 }
191 else {
192 dTy = pTrk->GetTrackParameter()->GetTy();
193 }
194
195 iNref = 0;
196 for (Int_t iHit = 0; iHit < pTrk->GetNofHits(); iHit++) {
197 if (iDetId == pTrk->GetTofDetIndex(iHit) || 0 == pTrk->GetTofDetIndex(iHit)) continue;
198
199 Double_t dDZ = pHit->GetZ() - pTrk->GetTofHitPointer(iHit)->GetZ();
200 dYref += pTrk->GetTofHitPointer(iHit)->GetY() + dTy * dDZ;
201 iNref++;
202 }
203
204 if (iNref == 0) {
205 LOG(error) << "DetId " << iDetId << ", Nref " << iNref << " sizes " << pTrk->GetNofHits() << ", "
206 << pTrk->GetNofHits();
207 return 1.E20;
208 }
209
210 dYref /= iNref;
211
212 return pHit->GetY() - dYref;
213}
214
215Double_t CbmTofTrackletTools::GetTdif(CbmTofTracklet* pTrk, Int_t iDetId, CbmTofHit* pHit)
216{
217 Double_t dTref = 0.;
218 Double_t Nref = 0;
219 Double_t dTt = 0.;
220 Int_t iNt = 0;
221
222 if (0) {
223 for (Int_t iHL = 0; iHL < pTrk->GetNofHits() - 1; iHL++) {
224 if (iDetId == pTrk->GetTofDetIndex(iHL) || 0 == pTrk->GetTofDetIndex(iHL)) continue; // exclude faked hits
225 for (Int_t iHH = iHL + 1; iHH < pTrk->GetNofHits(); iHH++) {
226 if (iDetId == pTrk->GetTofDetIndex(iHH) || 0 == pTrk->GetTofDetIndex(iHH)) continue; // exclude faked hits
227 //dTt+=(pTrk->GetTofHitPointer(iHH)->GetTime()-pTrk->GetTofHitPointer(iHL)->GetTime())/(pTrk->GetTofHitPointer(iHH)->GetR()-pTrk->GetTofHitPointer(iHL)->GetR()); // for projective geometries only !!!
228 Double_t dSign = 1.;
229 if (pTrk->GetTofHitPointer(iHH)->GetZ() < pTrk->GetTofHitPointer(iHL)->GetZ()) dSign = -1.;
230 dTt += (pTrk->GetTofHitPointer(iHH)->GetTime() - pTrk->GetTofHitPointer(iHL)->GetTime())
231 / pTrk->Dist3D(pTrk->GetTofHitPointer(iHH), pTrk->GetTofHitPointer(iHL)) * dSign;
232 iNt++;
233 }
234 }
235
236 if (iNt == 0) {
237 LOG(error) << "No valid hit pair ";
238 return 1.E20;
239 }
240 dTt /= (Double_t) iNt;
241 }
242 else {
243 dTt = FitTt(pTrk, iDetId);
244 }
245
246 for (Int_t iHit = 0; iHit < pTrk->GetNofHits(); iHit++) {
247 if (iDetId == pTrk->GetTofDetIndex(iHit) || 0 == pTrk->GetTofDetIndex(iHit)) continue;
248 //dTref += pTrk->GetTofHitPointer(iHit)->GetTime() - dTt*(pTrk->GetTofHitPointer(iHit)->GetR()-pHit->GetR());
249 Double_t dSign = 1.;
250 if (pTrk->GetTofHitPointer(iHit)->GetZ() < pHit->GetZ()) dSign = -1;
251 dTref += pTrk->GetTofHitPointer(iHit)->GetTime() - dTt * dSign * pTrk->Dist3D(pTrk->GetTofHitPointer(iHit), pHit);
252 Nref++;
253 }
254 if (Nref == 0) {
255 LOG(error) << "DetId " << iDetId << ", Nref " << Nref << " sizes " << pTrk->GetNofHits();
256 return 1.E20;
257 }
258 dTref /= (Double_t) Nref;
259 Double_t dTdif = pHit->GetTime() - dTref;
260 // LOG(debug) << "iSt "<< iSt<<" DetId "<<iDetId<<", Nref "<<Nref<<" Tdif
261 // "<<dTdif;
262 return dTdif;
263}
264
265Double_t CbmTofTrackletTools::GetTexpected(CbmTofTracklet* pTrk, Int_t iDetId, CbmTofHit* pHit, double TtLight)
266{
267 Double_t dTref = 0.;
268 Double_t Nref = 0;
269 Double_t dTt = 0.;
270 if (TtLight == 0.)
271 dTt = FitTt(pTrk, iDetId);
272 else
273 dTt = TtLight; // fix slope to speed of light
274
275 for (Int_t iHit = 0; iHit < pTrk->GetNofHits(); iHit++) {
276 if (iDetId == pTrk->GetTofDetIndex(iHit) || 0 == pTrk->GetTofDetIndex(iHit)) continue;
277 Double_t dSign = 1.;
278 if (pTrk->GetTofHitPointer(iHit)->GetZ() < pHit->GetZ()) dSign = -1;
279 dTref += pTrk->GetTofHitPointer(iHit)->GetTime() - dTt * dSign * pTrk->Dist3D(pTrk->GetTofHitPointer(iHit), pHit);
280 Nref++;
281 }
282 if (Nref == 0) {
283 LOG(error) << "DetId " << iDetId << ", Nref " << Nref << " sizes " << pTrk->GetNofHits();
284 return 1.E20;
285 }
286 dTref /= (Double_t) Nref;
287
288 return dTref;
289}
290
291Double_t CbmTofTrackletTools::GetTexpectedError(CbmTofTracklet* pTrk, Int_t iDetId, CbmTofHit* pHit, Double_t dTmean)
292{
293 Double_t dTrms = 0.;
294 Double_t dTrms2 = 0.;
295 Double_t Nref = 0;
296 Double_t dTt = 0.;
297
298 //dTt = FitTt(pTrk, iDetId);
299 dTt = pTrk->GetTt();
300
301 for (Int_t iHit = 0; iHit < pTrk->GetNofHits(); iHit++) {
302 if (iDetId == pTrk->GetTofDetIndex(iHit) || 0 == pTrk->GetTofDetIndex(iHit)) continue;
303 Double_t dSign = 1.;
304 if (pTrk->GetTofHitPointer(iHit)->GetZ() < pHit->GetZ()) dSign = -1;
305 Double_t dTref =
306 pTrk->GetTofHitPointer(iHit)->GetTime() - dTt * dSign * pTrk->Dist3D(pTrk->GetTofHitPointer(iHit), pHit);
307 dTref -= dTmean;
308 dTrms2 += dTref * dTref;
309 Nref++;
310 }
311 if (Nref == 0) {
312 LOG(error) << "DetId " << iDetId << ", Nref " << Nref << " sizes " << pTrk->GetNofHits();
313 return 1.E20;
314 }
315 dTrms2 /= (Double_t) Nref;
316 dTrms = TMath::Sqrt(dTrms2);
317 /*
318 LOG(info)<<"TExpErr: "<<Form("addr 0x%08x, Nhit %d, Nref %d, TM %8.2f, Rms %8.2f ",
319 iDetId, (Int_t)pTrk->GetNofHits(), (Int_t)Nref, dTmean, dTrms);
320 */
321 return dTrms;
322}
323
325{
326 double dTmean = 0.;
327 int nHits = 0;
328 for (Int_t iHit = 0; iHit < pTrk->GetNofHits(); iHit++) {
329 if (pTrk->GetTofHitPointer(iHit) == pHit) continue;
330 dTmean += pTrk->GetTofHitPointer(iHit)->GetTime();
331 nHits++;
332 }
333 dTmean /= nHits;
334 return pHit->GetTime() - dTmean;
335}
336
338{
339 return pTrk->GetTtErr() / pTrk->GetTt() * TMath::Abs(GetDTMean(pTrk, pHit));
340}
ClassImp(CbmConverterManager)
Char_t * gr
static LKFMinuit fMinuit
LKFMinuit fMinuit
double GetDz() const
Definition CbmHit.h:72
double GetTime() const
Definition CbmHit.h:76
double GetZ() const
Definition CbmHit.h:71
double GetDy() const
Definition CbmPixelHit.h:76
double GetDx() const
Definition CbmPixelHit.h:75
double GetY() const
Definition CbmPixelHit.h:74
double GetX() const
Definition CbmPixelHit.h:73
contains fits and resolution functions
virtual Double_t GetYdif(CbmTofTracklet *pTrk, Int_t iDetId, CbmTofHit *pHit)
virtual Double_t GetTexpected(CbmTofTracklet *pTrk, Int_t iDetId, CbmTofHit *pHit, double TtLight=0.)
virtual Double_t GetTexpectedError(CbmTofTracklet *pTrk, Int_t iDetId, CbmTofHit *pHit, Double_t dTexp)
virtual Double_t GetXdif(CbmTofTracklet *pTrk, Int_t iDetId, CbmTofHit *pHit)
Double_t * Line3DFit(CbmTofTracklet *pTrk, Int_t iDetId)
virtual Double_t GetTdif(CbmTofTracklet *pTrk, Int_t iDetId, CbmTofHit *pHit)
virtual Double_t GetDTMeanError(CbmTofTracklet *pTrk, CbmTofHit *pHit)
virtual Double_t GetDTMean(CbmTofTracklet *pTrk, CbmTofHit *pHit)
Double_t FitTt(CbmTofTracklet *pTrk, Int_t iDetId)
Provides information on attaching a TofHit to a TofTrack.
double GetFitY(double Z)
double GetTt() const
int32_t GetNofHits() const
void SetT0TtCov(double val)
CbmTofHit * GetTofHitPointer(int32_t ind)
void SetT0Err(double val)
int32_t GetTofDetIndex(int32_t ind) const
void SetT0(double val)
double GetTtErr() const
void SetTt(double val)
void SetTtErr(double val)
CbmTofTrackletParam * GetTrackParameter()
double GetFitX(double Z)
virtual double Dist3D(CbmTofHit *pHit0, CbmTofHit *pHit1)
static LKFMinuit * Instance()
Definition LKFMinuit.h:27
int DoFit(TGraph2DErrors *gr, double pStart[])
Definition LKFMinuit.cxx:36
double * GetParFit()
Definition LKFMinuit.h:37
double GetChi2DoF()
Definition LKFMinuit.h:39