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