PandaRoot
SQM.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
14 {
15 
16  //#include "Tang.h"
17 
18  Double_t det;
19  TMatrixD H(4, 4);
20  TMatrixD HY(4, 1);
21  TMatrixD Cov(4, 4);
22  TMatrixD HC(4, 1);
23 
24  float f1, f2, f3, f4, f5, Y, chi2;
25 
26  for (Int_t i = 0; i < 4; i++) {
27  HY(i, 0) = 0;
28  HC(i, 0) = 0;
29  for (Int_t j = 0; j < 4; j++) {
30  H(i, j) = 0;
31  }
32  }
33 
34  const int N = triplet.N();
35 
36  float Tx, Ty, Bx, By;
37 
38  //#include "SQM_0.h"
39 
40  cout << " **************** Param before Refit_1 ************ " << endl;
41 
42  PndFTSCATrackParamVector &param = triplet.Param();
43 
44  cout << " param.Tx()[0] " << param.Tx()[0] << " param.Ty()[0] " << param.Ty()[0] << " param.QP()[0] " << param.QP()[0] << " param.X()[0] " << param.X()[0] << " param.Y()[0] "
45  << param.Y()[0] << " param.Z()[0] " << param.Z()[0] << " param.Chi2()[0] " << param.Chi2()[0] << " param.NDF()[0] " << param.NDF()[0] << endl;
46 
47  Tx = param.Tx()[0];
48  Ty = param.Ty()[0];
49  Bx = param.X()[0] - param.Tx()[0] * param.Z()[0];
50  By = param.Y()[0] - param.Ty()[0] * param.Z()[0];
51 
52  float Tx_K = Tx;
53  float Ty_K = Ty;
54  float Bx_K = Bx;
55  float By_K = By;
56 
57  cout << " **************** Before Refit_1 ************ " << endl;
58  cout << " Tx " << Tx << endl;
59  cout << " Ty " << Ty << endl;
60  cout << " Bx " << Bx << endl;
61  cout << " By " << By << endl;
62 
63  // float_m active = triplet.IsValid();
64 
65  for (int it = 0; it < 3; it++) {
66 
67  for (Int_t i = 0; i < 4; i++) {
68  HY(i, 0) = 0;
69  HC(i, 0) = 0;
70  for (Int_t j = 0; j < 4; j++) {
71  H(i, j) = 0;
72  }
73  }
74 
75  for (int ihit = 0; ihit < N; ihit++) {
76  const TESV &index = triplet.IHit(ihit);
77  cout << "index.s station " << index.s << " index.e " << index.e << endl;
78  const FTSCAElementsOnStation<FTSCAHit> &hits_st = hits.OnStationConst(index.s[0]);
79 
80  const FTSCAHit &hit = hits_st[index.e[0]];
81 
82  int ISta = (int)hit.IStation();
83  cout << "chtck hit.IStation()" << ISta << endl;
84 
85  // float fX = param.X()[0] - param.Tx()[0]*(param.Z()[0] - hit.X0());
86  // float fY = param.Y()[0] - param.Ty()[0]*(param.Z()[0] - hit.X0());
87 
88  const PndFTSCAGBHit &hit_1 = fHits[hit.Id()];
89 
90  cout << " ************************************************* " << endl;
91  cout << " MC_Tx " << hit_1.point_Px / hit_1.point_Pz << endl;
92  cout << " MC_Ty " << hit_1.point_Py / hit_1.point_Pz << endl;
93  cout << " MC_Bx " << (hit_1.point_X - (hit_1.point_Px / hit_1.point_Pz) * hit_1.point_Z) << endl;
94  cout << " MC_By " << (hit_1.point_Y - (hit_1.point_Py / hit_1.point_Pz) * hit_1.point_Z) << endl;
95 
96  cout << " hit.R() " << hit.R() << " hit.ErrR() " << sqrt(hit.Err2R()) << endl;
97  cout << " X " << hit.X1() << " Y " << hit.X2() << " Z " << hit.X0() << endl;
98 
99  const FTSCAStation &station = GetParameters().Station(ISta);
100  const float s = station.f.sin;
101 
102  const float c = station.f.cos;
103 
104  cout << " s " << s << " c " << c << endl;
105 
106  float Tx_MC = hit_1.point_Px / hit_1.point_Pz;
107  float Ty_MC = hit_1.point_Py / hit_1.point_Pz;
108  float Bx_MC = (hit_1.point_X - (hit_1.point_Px / hit_1.point_Pz) * hit_1.point_Z);
109  float By_MC = (hit_1.point_Y - (hit_1.point_Py / hit_1.point_Pz) * hit_1.point_Z);
110  float R_MC = (c * (Tx_MC * hit.X0() + Bx_MC - hit.X1()) + s * (Ty_MC * hit.X0() + By_MC - hit.X2())) / sqrt(1.f + (c * Tx_MC + s * Ty_MC) * (c * Tx_MC + s * Ty_MC));
111 
112  if (s == 0) {
113 
114  float D2_mc_hit = sqrt((hit_1.point_X - hit.X1()) * (hit_1.point_X - hit.X1()) + (hit_1.point_Z - hit.X0()) * (hit_1.point_Z - hit.X0()));
115  float Diff_D_R = D2_mc_hit - hit.R();
116  cout << " D2_mc_hit " << D2_mc_hit << " hit.R() " << hit.R() << " Diff_D_R " << Diff_D_R << endl;
117  }
118 
119  float diff_R;
120 
121  if (R_MC > 0.f)
122  diff_R = R_MC - hit.R();
123  else
124  diff_R = R_MC + hit.R();
125 
126  cout << " diff_R " << diff_R << endl;
127 
128  float R_MC_1 =
129  (c * (Tx_MC * hit_1.point_Z + Bx_MC - hit.X1()) + s * (Ty_MC * hit_1.point_Z + By_MC - hit.X2())) / sqrt(1.f + (c * Tx_MC + s * Ty_MC) * (c * Tx_MC + s * Ty_MC));
130 
131  float diff_R_1;
132  if (R_MC_1 > 0.f)
133  diff_R_1 = R_MC_1 - hit.R();
134  else
135  diff_R_1 = R_MC_1 + hit.R();
136 
137  cout << " diff_R_1 " << diff_R_1 << endl;
138 
139  float R_MC_2 = (c * (hit_1.point_X - hit.X1()) + s * (hit_1.point_Y - hit.X2())) / sqrt(1.f + (c * Tx_MC + s * Ty_MC) * (c * Tx_MC + s * Ty_MC));
140 
141  cout << " R_MC_2 " << R_MC_2 << " hit.R()" << hit.R() << endl;
142 
143  float diff_R_2;
144  if (R_MC_2 < 0.f)
145  diff_R_2 = R_MC_2 + hit.R();
146  else
147  diff_R_2 = R_MC_2 - hit.R();
148 
149  cout << " diff_R_2 " << diff_R_2 << endl;
150 
151  // dbg
152  /*
153  if ( ihit==0 ) {
154  Tx = hit_1.point_Px/hit_1.point_Pz;
155  Ty = hit_1.point_Py/hit_1.point_Pz;
156  Bx = hit_1.point_X - (hit_1.point_Px/hit_1.point_Pz)*hit_1.point_Z;
157  By = hit_1.point_Y - (hit_1.point_Py/hit_1.point_Pz)*hit_1.point_Z;
158  }
159 
160  */
161 
162  float Y_point_of_wire = 0.f;
163  // dbg
164 
165  float fX = Tx * hit.X0() + Bx;
166  float fY = Ty * hit.X0() + By;
167 
168  cout << " Tx " << Tx << " Bx " << Bx << " Ty " << Ty << " By " << By << endl;
169 
170  float tx = c * Tx + s * Ty;
171  float rCorrection = sqrt(1.f + tx * tx);
172 
173  float Diff = c * (fX - hit.X1()) + s * (fY - hit.X2());
174  // float Diff = c*(fX - hit.X1()) + s*(fY - Y_point_of_wire);
175 
176  float Diff_mc = c * (hit_1.point_X - hit.X1()) + s * (hit_1.point_Y - hit.X2());
177 
178  // float Diff_mc = c*(hit_1.point_X -hit.X1()) + s*(hit_1.point_Y - Y_point_of_wire);
179 
180  cout << " Diff " << Diff << " Diff_mc " << Diff_mc << endl;
181 
182  cout << " ************************************************* " << endl;
183 
184  float R = hit.R();
185 
186  if (Diff < 0.f)
187  R = (-1.f) * R;
188 
189  // if (Diff_mc < 0.f ) R=(-1.f)*R; //dbg
190 
191  // float err = (sqrt(hit.Err2R())+ s*sqrt(hit.Err2X2()))*rCorrection;
192 
193  float err = sqrt(hit.Err2R());
194  // float err1= 2*hit.R()*err;
195 
196  Y = (R - (Diff / rCorrection)) / err;
197  // Y = (R*R - Diff*Diff/(rCorrection*rCorrection) )/err;
198 
199  f1 = (c * hit.X0() / rCorrection - c * Diff * tx / (rCorrection * rCorrection * rCorrection)) / err;
200 
201  // float rCorrection2= rCorrection*rCorrection;
202  // f1 = (2*Diff*c*hit.X0()/rCorrection2 - (Diff*Diff*2*tx*c)/(rCorrection2*rCorrection2))/err;
203 
204  f2 = c / (rCorrection * err);
205  // f2 = 2*Diff*c/(rCorrection*rCorrection*err);
206 
207  f3 = (s * hit.X0() / rCorrection - s * Diff * tx / (rCorrection * rCorrection * rCorrection)) / err;
208  // f3 = (2*Diff*s*hit.X0()/rCorrection2- (Diff*Diff*2*tx*s)/(rCorrection2*rCorrection2))/err;
209 
210  f4 = s / (rCorrection * err);
211 
212  // f4 =2*Diff*s/(rCorrection*rCorrection*err);
213 
214  // f4=2*Diff*s/(rCorrection*rCorrection*err);
215 
216  H(0, 0) = H(0, 0) + f1 * f1;
217  H(0, 1) = H(0, 1) + f1 * f2;
218  H(0, 2) = H(0, 2) + f1 * f3;
219  H(0, 3) = H(0, 3) + f1 * f4;
220  H(1, 0) = H(0, 1);
221  H(1, 1) = H(1, 1) + f2 * f2;
222  H(1, 2) = H(1, 2) + f2 * f3;
223  H(1, 3) = H(1, 3) + f2 * f4;
224  H(2, 0) = H(0, 2);
225  H(2, 1) = H(1, 2);
226  H(2, 2) = H(2, 2) + f3 * f3;
227  H(2, 3) = H(2, 3) + f3 * f4;
228  H(3, 0) = H(0, 3);
229  H(3, 1) = H(1, 3);
230  H(3, 2) = H(2, 3);
231  H(3, 3) = H(2, 3) + f4 * f4;
232 
233  HY(0, 0) = HY(0, 0) + Y * f1;
234  HY(1, 0) = HY(1, 0) + Y * f2;
235  HY(2, 0) = HY(2, 0) + Y * f3;
236  HY(3, 0) = HY(3, 0) + Y * f4;
237 
238  } // ihit
239 
240  H.Print();
241  H.Invert(&det);
242  Cov = H;
243  H.Print();
244  Cov.Print();
245  cout << "det= " << det << endl;
246 
247  HC = H * HY;
248  HC.Print();
249 
250  cout << "DTx= " << HC(0, 0) << " +- " << sqrt(Cov(0, 0)) << endl;
251  cout << "DBx= " << HC(1, 0) << " +- " << sqrt(Cov(1, 1)) << endl;
252  cout << "DTy= " << HC(2, 0) << " +- " << sqrt(Cov(2, 2)) << endl;
253  cout << "DBy= " << HC(3, 0) << " +- " << sqrt(Cov(3, 3)) << endl;
254 
255  Tx = Tx + HC(0, 0);
256  Bx = Bx + HC(1, 0);
257  Ty = Ty + HC(2, 0);
258  By = By + HC(3, 0);
259 
260  cout << "Tx= " << Tx << endl;
261  cout << "Ty= " << Ty << endl;
262  cout << "Bx= " << Bx << endl;
263  cout << "By= " << By << endl;
264 
265  } // it
266 
267  param.SetTx(Tx);
268  param.SetTy(Ty);
269  param.SetX(Tx * param.Z()[0] + Bx);
270  param.SetY(Ty * param.Z()[0] + By);
271  param.SetBx(Bx);
272  // float Err2_Tx=(float)Cov(0,0);
273  // param.SetCov( 5, Err2_Tx);
274 
275  float Tx_1 = param.Tx()[0];
276  float Ty_1 = param.Ty()[0];
277  float Bx_1 = param.Bx()[0];
278  float By_1 = By;
279 
280  chi2 = 0.0;
281  float chi2_k = 0.0;
282  for (int ihit = 0; ihit < N; ihit++) {
283  const TESV &index = triplet.IHit(ihit);
284  cout << "index.s station " << index.s << " index.e " << index.e << endl;
285  const FTSCAElementsOnStation<FTSCAHit> &hits_st = hits.OnStationConst(index.s[0]);
286 
287  const FTSCAHit &hit = hits_st[index.e[0]];
288 
289  int ISta = (int)hit.IStation();
290  cout << "chtck hit.IStation()" << ISta << endl;
291 
292  const FTSCAStation &station = GetParameters().Station(ISta);
293  const float s_1 = station.f.sin;
294 
295  const float c_1 = station.f.cos;
296 
297  cout << " s_1 " << s_1 << " c_1 " << c_1 << endl;
298 
299  float tx_1 = c_1 * Tx_1 + s_1 * Ty_1;
300  float rCorrection_1 = sqrt(1.f + tx_1 * tx_1);
301  float fX_1 = Tx_1 * hit.X0() + Bx_1;
302  float fY_1 = Ty_1 * hit.X0() + By_1;
303 
304  float Diff_1 = c_1 * (fX_1 - hit.X1()) + s_1 * (fY_1 - hit.X2());
305 
306  float tx_k = c_1 * Tx_K + s_1 * Ty_K;
307  float rCorrection_k = sqrt(1.f + tx_k * tx_k);
308  float fX_k = Tx_K * hit.X0() + Bx_K;
309  float fY_k = Ty_K * hit.X0() + By_K;
310 
311  float Diff_k = c_1 * (fX_k - hit.X1()) + s_1 * (fY_k - hit.X2());
312  float R_k = hit.R();
313  if (Diff_k < 0.f)
314  R_k = (-1.f) * R_k;
315  // float err_k = (sqrt(hit.Err2R())+ s_1*sqrt(hit.Err2X2()) )*rCorrection_k;
316 
317  float Y_point_of_wire_1 = 0.f;
318  // float Diff_1 = c_1*(fX_1 - hit.X1()) + s_1*(fY_1 - Y_point_of_wire_1);
319  float R_1 = hit.R();
320  if (Diff_1 < 0.f)
321  R_1 = (-1.f) * R_1;
322 
323  // float err_1 = (sqrt(hit.Err2R())+ s_1*sqrt(hit.Err2X2()) )*rCorrection_1;
324  float err_1 = sqrt(hit.Err2R());
325  float err_k = err_1;
326 
327  float Mes, Mes_k;
328  if (ISta > 50) {
329  Mes = (Diff_1 / rCorrection_1 - R_1) / (sqrt(hit.Err2R()) + s_1 * sqrt(hit.Err2X2()) + c_1 * sqrt(hit.Err2X1()));
330  Mes_k = (Diff_k / rCorrection_k - R_k) / (sqrt(hit.Err2R()) + s_1 * sqrt(hit.Err2X2()) + c_1 * sqrt(hit.Err2X1()));
331  } else {
332  // Mes = (Diff_1/rCorrection_1 - R_1)/(sqrt(hit.Err2R())+ s_1*sqrt(hit.Err2X2()) );
333  // Mes_k = (Diff_k/rCorrection_k - R_k)/(sqrt(hit.Err2R())+ s_1*sqrt(hit.Err2X2()) );
334  Mes = (Diff_1 / rCorrection_1 - R_1) / sqrt(hit.Err2R());
335  Mes_k = (Diff_k / rCorrection_k - R_k) / sqrt(hit.Err2R());
336  }
337  float Mes1 = (Diff_1 - R_1 * rCorrection_1) / (err_1 * rCorrection_1);
338  if (Mes > 10.f)
339  cout << " change sighn for hit " << ihit << endl;
340 
341  cout << " Mes " << Mes << " Mes1 " << Mes1 << endl;
342  chi2 = chi2 + Mes * Mes;
343  chi2_k = chi2_k + Mes_k * Mes_k;
344  cout << " Mes*Mes " << Mes * Mes << endl;
345  }
346  cout << " chi2 " << chi2 << " chi2_k " << chi2_k << endl;
347 
348  param.SetChi2(chi2);
349 }
int N() const
Definition: FTSCANPletsV.h:61
int_v s
Definition: FTSCATES.h:49
FTSCAStripInfo f
Definition: FTSCAStation.h:44
const PndFTSCATrackParamVector & Param() const
Definition: FTSCANPletsV.h:65
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:40
const PndFTSCAParam & GetParameters() const
int Id() const
Definition: FTSCAHits.h:49
Definition: FTSCATES.h:37
const FTSCAStation & Station(short i) const
Definition: PndFTSCAParam.h:58
unsigned int i
Definition: P4_F32vec4.h:33
PndFTSResizableArray< PndFTSCAGBHit > fHits
float X2() const
Definition: FTSCAHits.h:57
float X1() const
Definition: FTSCAHits.h:56
const TESV & IHit(int IH) const
Definition: FTSCANPletsV.h:63
uint_v e
Definition: FTSCATES.h:50
const FTSCAElementsOnStation< T > & OnStationConst(char i) const
Definition: FTSCAHits.h:152
float f
Definition: P4_F32vec4.h:32
float Err2X2() const
Definition: FTSCAHits.h:66
char IStation() const
Definition: FTSCAHits.h:47
float X0() const
Definition: FTSCAHits.h:55
TMatrixT< double > TMatrixD
Definition: PndLmdDim.h:64
float Err2X1() const
Definition: FTSCAHits.h:64
void Refit_1(FTSCANPletV &triplet, const FTSCAHits &hits)
Definition: SQM.h:13