]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDseed.cxx
Updated tracking code by Alexandru und Markus
[u/mrichter/AliRoot.git] / TRD / AliTRDseed.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15                                                       
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  The seed of a local TRD track                                            //  
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include "TMath.h"
25 #include "TLinearFitter.h"
26
27 #include "AliMathBase.h"
28
29 #include "AliTRDseed.h"
30 #include "AliTRDcalibDB.h"
31 #include "AliTRDcluster.h"
32 #include "AliTRDtracker.h"
33
34 ClassImp(AliTRDseed)
35 Int_t AliTRDseed::fgTimeBins = 0;
36 //_____________________________________________________________________________
37 AliTRDseed::AliTRDseed() 
38   :TObject()
39   ,fTimeBinsRange(0)
40   ,fTilt(0)
41   ,fPadLength(0)
42   ,fX0(0)
43   ,fSigmaY(0)
44   ,fSigmaY2(0)
45   ,fMeanz(0)
46   ,fZProb(0)
47   ,fN(0)
48   ,fN2(0)
49   ,fNUsed(0)
50   ,fFreq(0)
51   ,fNChange(0)
52   ,fMPads(0)
53   ,fC(0)
54   ,fCC(0)
55   ,fChi2(1.0e10)
56   ,fChi2Z(1.0e10)
57 {
58   //
59   // Default constructor  
60   //
61
62   for (Int_t i = 0; i < knTimebins; i++) {
63     fX[i]        = 0;   // x position
64     fY[i]        = 0;   // y position
65     fZ[i]        = 0;   // z position
66     fIndexes[i]  = 0;   // Indexes
67     fClusters[i] = 0x0; // Clusters
68     fUsable[i]   = 0;   // Indication  - usable cluster
69   }
70
71   for (Int_t i = 0; i < 2; i++) {
72     fYref[i]     = 0;   // Reference y
73     fZref[i]     = 0;   // Reference z
74     fYfit[i]     = 0;   // Y fit position +derivation
75     fYfitR[i]    = 0;   // Y fit position +derivation
76     fZfit[i]     = 0;   // Z fit position
77     fZfitR[i]    = 0;   // Z fit position
78     fLabels[i]   = 0;   // Labels
79   }
80
81 }
82
83 //_____________________________________________________________________________
84 AliTRDseed::AliTRDseed(const AliTRDseed &s)
85   :TObject(s)
86   ,fTimeBinsRange(s.fTimeBinsRange)
87   ,fTilt(s.fTilt)
88   ,fPadLength(s.fPadLength)
89   ,fX0(s.fX0)
90   ,fSigmaY(s.fSigmaY)
91   ,fSigmaY2(s.fSigmaY2)
92   ,fMeanz(s.fMeanz)
93   ,fZProb(s.fZProb)
94   ,fN(s.fN)
95   ,fN2(s.fN2)
96   ,fNUsed(s.fNUsed)
97   ,fFreq(s.fFreq)
98   ,fNChange(s.fNChange)
99   ,fMPads(s.fMPads)
100   ,fC(s.fC)
101   ,fCC(s.fCC)
102   ,fChi2(s.fChi2)
103   ,fChi2Z(s.fChi2Z)
104 {
105   //
106   // Copy constructor  
107   //
108
109   for (Int_t i = 0; i < knTimebins; i++) {
110     fX[i]        = s.fX[i];        // x position
111     fY[i]        = s.fY[i];        // y position
112     fZ[i]        = s.fZ[i];        // z position
113     fIndexes[i]  = s.fIndexes[i];  // Indexes
114     fClusters[i] = s.fClusters[i]; // Clusters
115     fUsable[i]   = s.fUsable[i];   // Indication  - usable cluster
116   }
117
118   for (Int_t i = 0; i < 2; i++) {
119     fYref[i]     = s.fYref[i];     // Reference y
120     fZref[i]     = s.fZref[i];     // Reference z
121     fYfit[i]     = s.fYfit[i];     // Y fit position +derivation
122     fYfitR[i]    = s.fYfitR[i];    // Y fit position +derivation
123     fZfit[i]     = s.fZfit[i];     // Z fit position
124     fZfitR[i]    = s.fZfitR[i];    // Z fit position
125     fLabels[i]   = s.fLabels[i];   // Labels
126   }
127
128 }
129
130 //_____________________________________________________________________________
131 void AliTRDseed::Copy(TObject &o) const
132 {
133         //printf("AliTRDseed::Copy()\n");
134
135         AliTRDseed &seed = (AliTRDseed &)o;
136   
137         seed.fTimeBinsRange = fTimeBinsRange;
138         seed.fTilt = fTilt;
139   seed.fPadLength = fPadLength;
140   seed.fX0 = fX0;
141   seed.fSigmaY = fSigmaY;
142   seed.fSigmaY2 = fSigmaY2;
143   seed.fMeanz = fMeanz;
144   seed.fZProb = fZProb;
145   seed.fN = fN;
146   seed.fN2 = fN2;
147   seed.fNUsed = fNUsed;
148   seed.fFreq = fFreq;
149   seed.fNChange = fNChange;
150   seed.fMPads = fMPads;
151   seed.fC = fC;
152   seed.fCC = fCC;
153   seed.fChi2 = fChi2;
154   seed.fChi2Z = fChi2Z;
155         for (Int_t i = 0; i < knTimebins; i++) {
156     seed.fX[i]        = fX[i];
157     seed.fY[i]        = fY[i]; 
158     seed.fZ[i]        = fZ[i]; 
159     seed.fIndexes[i]  = fIndexes[i]; 
160     seed.fClusters[i] = fClusters[i]; 
161     seed.fUsable[i]   = fUsable[i]; 
162   }
163
164   for (Int_t i = 0; i < 2; i++) {
165     seed.fYref[i]     = fYref[i];
166     seed.fZref[i]     = fZref[i];
167     seed.fYfit[i]     = fYfit[i];
168     seed.fYfitR[i]    = fYfitR[i]; 
169     seed.fZfit[i]     = fZfit[i]; 
170     seed.fZfitR[i]    = fZfitR[i];  
171     seed.fLabels[i]   = fLabels[i]; 
172   }
173
174   TObject::Copy(seed);
175
176 }
177
178 //_____________________________________________________________________________
179 void AliTRDseed::Reset()
180 {
181   //
182   // Reset seed
183   //
184
185   for (Int_t i = 0; i < knTimebins; i++) {
186     fX[i]        = 0;  // X position
187     fY[i]        = 0;  // Y position
188     fZ[i]        = 0;  // Z position
189     fIndexes[i]  = 0;  // Indexes
190     fClusters[i] = 0x0;  // Clusters
191     fUsable[i]   = kFALSE;    
192   }
193
194   for (Int_t i = 0; i < 2; i++) {
195     fYref[i]     = 0;  // Reference y
196     fZref[i]     = 0;  // Reference z
197     fYfit[i]     = 0;  // Y fit position +derivation
198     fYfitR[i]    = 0;  // Y fit position +derivation
199     fZfit[i]     = 0;  // Z fit position
200     fZfitR[i]    = 0;  // Z fit position
201     fLabels[i]   = -1; // Labels
202   }
203   fSigmaY  = 0;        // "Robust" sigma in y
204   fSigmaY2 = 0;        // "Robust" sigma in y
205   fMeanz   = 0;        // Mean vaue of z
206   fZProb   = 0;        // Max probbable z
207   fMPads   = 0;
208   fN       = 0;        // Number of associated clusters
209   fN2      = 0;        // Number of not crossed
210   fNUsed   = 0;        // Number of used clusters
211   fNChange = 0;        // Change z counter
212
213 }
214
215 //_____________________________________________________________________________
216 void AliTRDseed::CookLabels()
217 {
218   //
219   // Cook 2 labels for seed
220   //
221
222   Int_t labels[200];
223   Int_t out[200];
224   Int_t nlab = 0;
225
226   for (Int_t i = 0; i < fgTimeBins+1; i++) {
227     if (!fClusters[i]) continue;
228     for (Int_t ilab = 0; ilab < 3; ilab++) {
229       if (fClusters[i]->GetLabel(ilab) >= 0) {
230         labels[nlab] = fClusters[i]->GetLabel(ilab);
231         nlab++;
232       }
233     }
234   }
235
236   Int_t nlab2 = AliTRDtracker::Freq(nlab,labels,out,kTRUE);
237   fLabels[0] = out[0];
238   if ((nlab2  > 1) && 
239       (out[3] > 1)) {
240     fLabels[1] = out[2];
241   }
242
243 }
244
245 //_____________________________________________________________________________
246 void AliTRDseed::UseClusters()
247 {
248   //
249   // Use clusters
250   //
251
252   for (Int_t i = 0; i < fgTimeBins+1; i++) {
253     if (!fClusters[i]) continue;
254     if (!(fClusters[i]->IsUsed())) fClusters[i]->Use();
255   }
256
257 }
258
259 //_____________________________________________________________________________
260 void AliTRDseed::Update()
261 {
262   //
263   // Update the seed.
264   //
265
266
267         // linear fit on the y direction
268         // dy|x = (yc|x - dz|x*tg(tilt)) - (y0 + dy/dx|x * x )
269         // dz|x = zc|x - (z0 + dz/dx|x) 
270
271   const Float_t kRatio  = 0.8;
272   const Int_t   kClmin  = 5;
273   const Float_t kmaxtan = 2;
274
275
276   if (TMath::Abs(fYref[1]) > kmaxtan){
277                 //printf("Exit: Abs(fYref[1]) = %3.3f, kmaxtan = %3.3f\n", TMath::Abs(fYref[1]), kmaxtan);
278                 return;              // Track inclined too much
279         }
280
281   Float_t  sigmaexp  = 0.05 + TMath::Abs(fYref[1] * 0.25); // Expected r.m.s in y direction
282   Float_t  ycrosscor = fPadLength * fTilt * 0.5;           // Y correction for crossing 
283   fNChange = 0;
284
285   Double_t sumw;
286   Double_t sumwx;
287   Double_t sumwx2;
288   Double_t sumwy;
289   Double_t sumwxy;
290   Double_t sumwz;
291   Double_t sumwxz;
292
293         // Buffering: Leave it constant fot Performance issues
294   Int_t    zints[knTimebins];            // Histograming of the z coordinate 
295                                          // Get 1 and second max probable coodinates in z
296   Int_t    zouts[2*knTimebins];       
297   Float_t  allowedz[knTimebins];         // Allowed z for given time bin
298   Float_t  yres[knTimebins];             // Residuals from reference
299   Float_t  anglecor = fTilt * fZref[1];  // Correction to the angle
300   
301   
302   fN  = 0; 
303   fN2 = 0;
304   for (Int_t i = 0; i < fTimeBinsRange; i++) {
305     yres[i] = 10000.0;
306     if (!fClusters[i]) continue;
307     yres[i] = fY[i] - fYref[0] - (fYref[1] + anglecor) * fX[i];   // Residual y
308     zints[fN] = Int_t(fZ[i]);
309     fN++;    
310   }
311
312   if (fN < kClmin){
313                 //printf("Exit fN < kClmin: fN = %d\n", fN);
314                 return; 
315         }
316   Int_t nz = AliTRDtracker::Freq(fN,zints,zouts,kFALSE);
317   fZProb   = zouts[0];
318   if (nz <= 1) zouts[3] = 0;
319   if (zouts[1] + zouts[3] < kClmin) {
320                 //printf("Exit zouts[1] = %d, zouts[3] = %d\n",zouts[1],zouts[3]);
321                 return;
322         }
323   
324   // Z distance bigger than pad - length
325   if (TMath::Abs(zouts[0]-zouts[2]) > 12.0) {
326     zouts[3]=0;           
327   }
328   
329   Int_t  breaktime = -1;
330   Bool_t mbefore   = kFALSE;
331   Int_t  cumul[knTimebins][2];
332   Int_t  counts[2] = { 0, 0 };
333   
334   if (zouts[3] >= 3) {
335
336     //
337     // Find the break time allowing one chage on pad-rows
338     // with maximal numebr of accepted clusters
339     //
340     fNChange = 1;
341     for (Int_t i = 0; i < fTimeBinsRange; i++) {
342       cumul[i][0] = counts[0];
343       cumul[i][1] = counts[1];
344       if (TMath::Abs(fZ[i]-zouts[0]) < 2) counts[0]++;
345       if (TMath::Abs(fZ[i]-zouts[2]) < 2) counts[1]++;
346     }
347     Int_t  maxcount = 0;
348     for (Int_t i = 0; i < fTimeBinsRange; i++) {
349       Int_t after  = cumul[fTimeBinsRange][0] - cumul[i][0];
350       Int_t before = cumul[i][1];
351       if (after + before > maxcount) { 
352         maxcount  = after + before; 
353         breaktime = i;
354         mbefore   = kFALSE;
355       }
356       after  = cumul[fTimeBinsRange-1][1] - cumul[i][1];
357       before = cumul[i][0];
358       if (after + before > maxcount) { 
359         maxcount  = after + before; 
360         breaktime = i;
361         mbefore   = kTRUE;
362       }
363     }
364
365     breaktime -= 1;
366
367   }
368
369   for (Int_t i = 0; i < fTimeBinsRange+1; i++) {
370     if (i >  breaktime) allowedz[i] =   mbefore  ? zouts[2] : zouts[0];
371     if (i <= breaktime) allowedz[i] = (!mbefore) ? zouts[2] : zouts[0];
372   }  
373
374   if (((allowedz[0] > allowedz[fTimeBinsRange]) && (fZref[1] < 0)) ||
375       ((allowedz[0] < allowedz[fTimeBinsRange]) && (fZref[1] > 0))) {
376     //
377     // Tracklet z-direction not in correspondance with track z direction 
378     //
379     fNChange = 0;
380     for (Int_t i = 0; i < fTimeBinsRange+1; i++) {
381       allowedz[i] = zouts[0];  // Only longest taken
382     } 
383   }
384   
385   if (fNChange > 0) {
386     //
387     // Cross pad -row tracklet  - take the step change into account
388     //
389     for (Int_t i = 0; i < fTimeBinsRange+1; i++) {
390       if (!fClusters[i]) continue; 
391       if (TMath::Abs(fZ[i] - allowedz[i]) > 2) continue;
392       yres[i] = fY[i] - fYref[0] - (fYref[1] + anglecor) * fX[i];   // Residual y
393       if (TMath::Abs(fZ[i] - fZProb) > 2) {
394         if (fZ[i] > fZProb) yres[i] += fTilt * fPadLength;
395         if (fZ[i] < fZProb) yres[i] -= fTilt * fPadLength;
396       }
397     }
398   }
399   
400   Double_t yres2[knTimebins];
401   Double_t mean;
402   Double_t sigma;
403   for (Int_t i = 0; i < fTimeBinsRange+1; i++) {
404     if (!fClusters[i]) continue;
405     if (TMath::Abs(fZ[i] - allowedz[i]) > 2) continue;
406     yres2[fN2] = yres[i];
407     fN2++;
408   }
409   if (fN2 < kClmin) {
410                 //printf("Exit fN2 < kClmin: fN2 = %d\n", fN2);
411     fN2 = 0;
412     return;
413   }
414   AliMathBase::EvaluateUni(fN2,yres2,mean,sigma, Int_t(fN2*kRatio-2.));
415   if (sigma < sigmaexp * 0.8) {
416     sigma = sigmaexp;
417   }
418   fSigmaY = sigma;
419
420   // Reset sums
421   sumw   = 0; 
422   sumwx  = 0; 
423   sumwx2 = 0;
424   sumwy  = 0; 
425   sumwxy = 0; 
426   sumwz  = 0;
427   sumwxz = 0;
428
429   fN2    = 0;
430   fMeanz = 0;
431   fMPads = 0;
432
433   for (Int_t i = 0; i < fTimeBinsRange+1; i++) {
434
435     fUsable[i] = kFALSE;
436     if (!fClusters[i]) continue;
437     if (TMath::Abs(fZ[i] - allowedz[i]) > 2){fClusters[i] = 0x0; continue;}
438     if (TMath::Abs(yres[i] - mean) > 4.0 * sigma){fClusters[i] = 0x0;  continue;}
439     fUsable[i] = kTRUE;
440     fN2++;
441     fMPads += fClusters[i]->GetNPads();
442     Float_t weight = 1.0;
443     if (fClusters[i]->GetNPads() > 4) weight = 0.5;
444     if (fClusters[i]->GetNPads() > 5) weight = 0.2;
445    
446         
447     Double_t x = fX[i];
448     //printf("x = %7.3f dy = %7.3f fit %7.3f\n", x, yres[i], fY[i]-yres[i]);
449     
450     sumw   += weight; 
451     sumwx  += x * weight; 
452     sumwx2 += x*x * weight;
453     sumwy  += weight * yres[i];  
454     sumwxy += weight * (yres[i]) * x;
455     sumwz  += weight * fZ[i];    
456     sumwxz += weight * fZ[i] * x;
457
458   }
459
460   if (fN2 < kClmin){
461                 //printf("Exit fN2 < kClmin(2): fN2 = %d\n",fN2);
462     fN2 = 0;
463     return;
464   }
465   fMeanz = sumwz / sumw;
466   Float_t correction = 0;
467   if (fNChange > 0) {
468     // Tracklet on boundary
469     if (fMeanz < fZProb) correction =  ycrosscor;
470     if (fMeanz > fZProb) correction = -ycrosscor;
471   }
472
473   Double_t det = sumw * sumwx2 - sumwx * sumwx;
474   fYfitR[0]    = (sumwx2 * sumwy  - sumwx * sumwxy) / det;
475   fYfitR[1]    = (sumw   * sumwxy - sumwx * sumwy)  / det;
476   
477   fSigmaY2 = 0;
478   for (Int_t i = 0; i < fTimeBinsRange+1; i++) {
479     if (!fUsable[i]) continue;
480     Float_t delta = yres[i] - fYfitR[0] - fYfitR[1] * fX[i];
481     fSigmaY2 += delta*delta;
482   }
483   fSigmaY2 = TMath::Sqrt(fSigmaY2 / Float_t(fN2-2));
484         // TEMPORARY UNTIL covariance properly calculated
485         fSigmaY2 = TMath::Max(fSigmaY2, Float_t(.1));
486   
487   fZfitR[0]  = (sumwx2 * sumwz  - sumwx * sumwxz) / det;
488   fZfitR[1]  = (sumw   * sumwxz - sumwx * sumwz)  / det;
489   fZfit[0]   = (sumwx2 * sumwz  - sumwx * sumwxz) / det;
490   fZfit[1]   = (sumw   * sumwxz - sumwx * sumwz)  / det;
491   fYfitR[0] += fYref[0] + correction;
492   fYfitR[1] += fYref[1];
493   fYfit[0]   = fYfitR[0];
494   fYfit[1]   = fYfitR[1];
495
496         //printf("y0 = %7.3f tgy = %7.3f z0 = %7.3f tgz = %7.3f \n", fYfitR[0], fYfitR[1], fZfitR[0], fZfitR[1]);
497
498   UpdateUsed();
499
500 }
501
502 //_____________________________________________________________________________
503 void AliTRDseed::UpdateUsed()
504 {
505   //
506   // Update used seed
507   //
508
509   fNUsed = 0;
510   for (Int_t i = 0; i < fgTimeBins; i++) {
511     if (!fClusters[i]) continue;
512                 if(!fUsable[i]) continue;   
513     if ((fClusters[i]->IsUsed())) fNUsed++;
514   }
515
516 }
517
518 //_____________________________________________________________________________
519 Float_t AliTRDseed::FitRiemanTilt(AliTRDseed * cseed, Bool_t terror)
520 {
521   //
522   // Fit the Rieman tilt
523   //
524
525   // Fitting with tilting pads - kz not fixed
526   TLinearFitter fitterT2(4,"hyp4");  
527   fitterT2.StoreData(kTRUE);
528         
529   Float_t xref2 = (cseed[2].fX0 + cseed[3].fX0) * 0.5; // Reference x0 for z
530   
531   Int_t npointsT = 0;
532   fitterT2.ClearPoints();
533
534   for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
535
536     if (!cseed[iLayer].IsOK()) continue;
537     Double_t tilt = cseed[iLayer].fTilt;
538
539     for (Int_t itime = 0; itime < fgTimeBins+1; itime++) {
540
541       if (!cseed[iLayer].fUsable[itime]) continue;
542       // x relative to the midle chamber
543       Double_t x = cseed[iLayer].fX[itime] + cseed[iLayer].fX0 - xref2;  
544       Double_t y = cseed[iLayer].fY[itime];
545       Double_t z = cseed[iLayer].fZ[itime];
546
547       //
548       // Tilted rieman
549       //
550       Double_t uvt[6];
551       Double_t x2 = cseed[iLayer].fX[itime] + cseed[iLayer].fX0;      // Global x
552       Double_t t  = 1.0 / (x2*x2 + y*y);
553       uvt[1]  = t;
554       uvt[0]  = 2.0 * x2   * uvt[1];
555       uvt[2]  = 2.0 * tilt * uvt[1];
556       uvt[3]  = 2.0 * tilt *uvt[1] * x;       
557       uvt[4]  = 2.0 * (y + tilt * z) * uvt[1];
558       
559       Double_t error = 2.0 * uvt[1];
560       if (terror) {
561         error *= cseed[iLayer].fSigmaY;
562       }
563       else {
564         error *= 0.2; //Default error
565       } 
566       fitterT2.AddPoint(uvt,uvt[4],error);
567       npointsT++;
568
569     }
570
571   }
572
573   fitterT2.Eval();
574   Double_t rpolz0 = fitterT2.GetParameter(3);
575   Double_t rpolz1 = fitterT2.GetParameter(4);       
576
577   //
578   // Linear fitter  - not possible to make boundaries
579   // non accept non possible z and dzdx combination
580   //        
581   Bool_t acceptablez = kTRUE;
582   for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
583     if (!cseed[iLayer].IsOK()) continue;
584     Double_t zT2 = rpolz0 + rpolz1 * (cseed[iLayer].fX0 - xref2);
585     if (TMath::Abs(cseed[iLayer].fZProb - zT2) > cseed[iLayer].fPadLength * 0.5 + 1.0) acceptablez = kFALSE;
586   }
587   if (!acceptablez) {
588     Double_t zmf  = cseed[2].fZref[0] + cseed[2].fZref[1] * (xref2 - cseed[2].fX0);
589     Double_t dzmf = (cseed[2].fZref[1] + cseed[3].fZref[1]) * 0.5;
590     fitterT2.FixParameter(3,zmf);
591     fitterT2.FixParameter(4,dzmf);
592     fitterT2.Eval();
593     fitterT2.ReleaseParameter(3);
594     fitterT2.ReleaseParameter(4);
595     rpolz0 = fitterT2.GetParameter(3);
596     rpolz1 = fitterT2.GetParameter(4);
597   }
598   
599   Double_t chi2TR = fitterT2.GetChisquare() / Float_t(npointsT);  
600   Double_t params[3];
601   params[0] =  fitterT2.GetParameter(0);
602   params[1] =  fitterT2.GetParameter(1);
603   params[2] =  fitterT2.GetParameter(2);            
604   Double_t curvature =  1.0 + params[1] * params[1] - params[2] * params[0];
605
606         
607   for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
608     Double_t  x  = cseed[iLayer].fX0;
609     Double_t  y  = 0;
610     Double_t  dy = 0;
611     Double_t  z  = 0;
612     Double_t  dz = 0;
613
614     // y
615     Double_t res2 = (x * params[0] + params[1]);
616     res2 *= res2;
617     res2  = 1.0 - params[2]*params[0] + params[1]*params[1] - res2;
618     if (res2 >= 0) {
619       res2 = TMath::Sqrt(res2);
620       y    = (1.0 - res2) / params[0];
621     }
622
623     //dy
624     Double_t x0 = -params[1] / params[0];
625     if (-params[2]*params[0] + params[1]*params[1] + 1 > 0) {
626       Double_t rm1 = params[0] / TMath::Sqrt(-params[2]*params[0] + params[1]*params[1] + 1); 
627       if (1.0/(rm1*rm1) - (x-x0) * (x-x0) > 0.0) {
628                                 Double_t res = (x - x0) / TMath::Sqrt(1.0 / (rm1*rm1) - (x-x0)*(x-x0));
629                                 if (params[0] < 0) res *= -1.0;
630                                 dy = res;
631       }
632     }
633     z  = rpolz0 + rpolz1 * (x - xref2);
634     dz = rpolz1;
635     cseed[iLayer].fYref[0] = y;
636     cseed[iLayer].fYref[1] = dy;
637     cseed[iLayer].fZref[0] = z;
638     cseed[iLayer].fZref[1] = dz;
639     cseed[iLayer].fC       = curvature;
640     
641   }
642
643   return chi2TR;
644
645 }