updated for change TMevSim to TMEVSIM
[u/mrichter/AliRoot.git] / ITS / AliITSTrackerV1.cxx
CommitLineData
b48af428 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/*
17$Log$
def162f4 18Revision 1.24 2002/10/23 14:28:38 barbera
19Fixes added to get into account the new magnetic field conversion factor automatically
20
af50998a 21Revision 1.23 2002/10/22 18:29:34 barbera
22Tracking V1 ported to the HEAD
23
9040b789 24Revision 1.22 2002/10/22 14:45:36 alibrary
25Introducing Riostream.h
26
4ae5bbc4 27Revision 1.21 2002/02/05 09:12:26 hristov
28Small mods for gcc 3.02
29
bcc5d57d 30Revision 1.20 2001/11/21 14:47:45 barbera
31Some unuseful print-out commented out
32
c57de405 33Revision 1.19 2001/11/21 10:49:07 barbera
34Bug correction suggested by Rene done
35
cf411bb5 36Revision 1.18 2001/11/20 15:46:17 barbera
37Point coordinated are calculated in cylindrical reference frame once and for all at the beginning of tracking V1
38
61231d74 39Revision 1.10.2.1 2001/10/24 07:26:04 hristov
40All the changes from the head are merged with the release
41
11091b43 42Revision 1.14 2001/10/24 07:19:57 hristov
43Some pointer correctly initialised in one of the constructors
44
a49bb2c8 45Revision 1.13 2001/10/21 19:17:12 hristov
46Several pointers were set to zero in the default constructors to avoid memory management problems
47
55cd883f 48Revision 1.12 2001/10/19 21:32:35 nilsen
49Minor changes to remove compliation warning on gcc 2.92.2 compiler, and
50cleanded up a little bit of code.
51
b48af428 52*/
af50998a 53// The purpose of this class is to permorm the ITS tracking. The
b48af428 54// constructor has the task to inizialize some private members. The method
55// DoTracking is written to be called by a macro. It gets the event number,
56// the minimum and maximum order number of TPC tracks that are to be tracked
57// trough the ITS, and the file where the recpoints are registered. The
58// method Recursivetracking is a recursive function that performs the
59// tracking trough the ITS The method Intersection found the layer, ladder
60// and detector whre the intersection take place and caluclate the
61// cohordinates of this intersection. It returns an integer that is 0 if the
62// intersection has been found successfully. The two mwthods Kalmanfilter
63// and kalmanfiltervert operate the kalmanfilter without and with the vertex
64// imposition respectively. The authors thank Mariana Bondila to have help
65// them to resolve some problems. July-2000
04b80329 66
4ae5bbc4 67#include <Riostream.h>
68#include <Riostream.h>
13888096 69#include <TMath.h>
13888096 70#include <TBranch.h>
71#include <TVector.h>
13888096 72#include <TFile.h>
73#include <TTree.h>
cbcfa38d 74#include <TStopwatch.h>
75
13888096 76#include "TParticle.h"
77#include "AliRun.h"
78#include "AliITS.h"
04b80329 79#include "AliITSsegmentationSSD.h"
13888096 80#include "AliITSgeomSPD.h"
81#include "AliITSgeomSDD.h"
82#include "AliITSgeomSSD.h"
83#include "AliITSgeom.h"
13888096 84#include "AliITSRecPoint.h"
04b80329 85#include "stdlib.h"
13888096 86#include "AliKalmanTrack.h"
87#include "AliMagF.h"
04b80329 88#include "AliITSTrackV1.h"
89#include "AliITSIOTrack.h"
90#include "AliITSRad.h"
13888096 91#include "../TPC/AliTPCtracker.h"
13888096 92#include "AliITSTrackerV1.h"
0983ac5b 93#include "AliITSVertex.h"
def162f4 94#include "AliITSPid.h"
13888096 95
13888096 96ClassImp(AliITSTrackerV1)
55cd883f 97 //______________________________________________________________________
98AliITSTrackerV1::AliITSTrackerV1() {
99 //Default constructor
100 fITS = 0;
101 fresult = 0;
64ab0d55 102 fPtref=0.;
103 fChi2max=0.;
104 //fepsphi=0.;
105 //fepsz=0.;
55cd883f 106 frecPoints = 0;
107 fvettid = 0;
64ab0d55 108 fflagvert=0;
55cd883f 109 frl = 0;
64ab0d55 110 Int_t ia;
111 for(ia=0; ia<6; ia++) {
112 fNlad[ia]=0;
113 fNdet[ia]=0;
114 fAvrad[ia]=0.;
115 fDetx[ia]=0.;
116 fDetz[ia]=0.;
117 } // end for ia
55cd883f 118 fzmin = 0;
119 fzmax = 0;
120 fphimin = 0;
121 fphimax = 0;
122 fphidet = 0;
64ab0d55 123 fNRecPoints=0;
124 fRecCylR=0;
125 fRecCylPhi=0;
126 fRecCylZ=0;
127 fFieldFactor=0;
55cd883f 128}
b48af428 129//______________________________________________________________________
64ab0d55 130AliITSTrackerV1::AliITSTrackerV1(AliITS* IITTSS, Int_t evnumber, Bool_t flag) {
b48af428 131 //Origin A. Badala' and G.S. Pappalardo:
132 // e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it
133 // Class constructor. It does some initializations.
134
a49bb2c8 135 //PH Initialisation taken from the default constructor
b48af428 136 fITS = IITTSS;
a49bb2c8 137 fresult = 0;
64ab0d55 138 fPtref = 0.;
139 fChi2max =0.;
140 frecPoints = 0;
a49bb2c8 141 fvettid = 0;
64ab0d55 142 fflagvert = flag;
a49bb2c8 143 frl = 0;
144 fzmin = 0;
145 fzmax = 0;
146 fphimin = 0;
147 fphimax = 0;
148 fphidet = 0;
64ab0d55 149
b48af428 150 Int_t imax = 200,jmax = 450;
151 frl = new AliITSRad(imax,jmax);
152
153 ////////// gets information on geometry /////////////////////////////
64ab0d55 154 AliITSgeom *g1 = fITS->GetITSgeom();
b48af428 155 Int_t ll=1, dd=1;
156 TVector det(9);
157
b48af428 158 Int_t ia;
159 for(ia=0; ia<6; ia++) {
160 fNlad[ia]=g1->GetNladders(ia+1);
161 fNdet[ia]=g1->GetNdetectors(ia+1);
162 //cout<<fNlad[i]<<" "<<fNdet[i]<<"\n";
163 } // end for ia
b48af428 164
64ab0d55 165 //cout<<" mean radius = ";
b48af428 166 Int_t ib;
167 for(ib=0; ib<6; ib++) {
168 g1->GetCenterThetaPhi(ib+1,ll,dd,det);
169 Double_t r1=TMath::Sqrt(det(0)*det(0)+det(1)*det(1));
170 g1->GetCenterThetaPhi(ib+1,ll,dd+1,det);
171 Double_t r2=TMath::Sqrt(det(0)*det(0)+det(1)*det(1));
172 fAvrad[ib]=(r1+r2)/2.;
173 //cout<<fAvrad[ib]<<" ";
174 } // end for ib
175 //cout<<"\n"; getchar();
176
177 fDetx[0] = ((AliITSgeomSPD*)(g1->GetShape(1, ll, dd)))->GetDx();
178 fDetz[0] = ((AliITSgeomSPD*)(g1->GetShape(1, ll, dd)))->GetDz();
179
180 fDetx[1] = ((AliITSgeomSPD*)(g1->GetShape(2, ll, dd)))->GetDx();
181 fDetz[1] = ((AliITSgeomSPD*)(g1->GetShape(2, ll, dd)))->GetDz();
182
183 fDetx[2] = ((AliITSgeomSDD*)(g1->GetShape(3, ll, dd)))->GetDx();
184 fDetz[2] = ((AliITSgeomSDD*)(g1->GetShape(3, ll, dd)))->GetDz();
185
186 fDetx[3] = ((AliITSgeomSDD*)(g1->GetShape(4, ll, dd)))->GetDx();
187 fDetz[3] = ((AliITSgeomSDD*)(g1->GetShape(4, ll, dd)))->GetDz();
188
189 fDetx[4] = ((AliITSgeomSSD*)(g1->GetShape(5, ll, dd)))->GetDx();
190 fDetz[4] = ((AliITSgeomSSD*)(g1->GetShape(5, ll, dd)))->GetDz();
191
192 fDetx[5] = ((AliITSgeomSSD*)(g1->GetShape(6, ll, dd)))->GetDx();
193 fDetz[5] = ((AliITSgeomSSD*)(g1->GetShape(6, ll, dd)))->GetDz();
194 //cout<<" Detx Detz\n";
195 //for(Int_t la=0; la<6; la++) cout<<" "<<fDetx[la]<<" "<<
196 // fDetz[la]<<endl;
197 //getchar();
64ab0d55 198
b48af428 199 // allocate memory and define matrices fzmin, fzmax, fphimin and fphimax //
200 Double_t epsz=1.2;
201 Double_t epszdrift=0.05;
202
203 fzmin = new Double_t*[6]; fzmax = new Double_t*[6];
204 Int_t im1, im2, im2max;
205 for(im1=0; im1<6; im1++) {
206 im2max=fNdet[im1];
207 fzmin[im1] = new Double_t[im2max]; fzmax[im1] = new Double_t[im2max];
208 } // end for im1
209
210 for(im1=0; im1<6; im1++) {
211 im2max=fNdet[im1];
212 for(im2=0; im2<im2max; im2++) {
213 g1->GetCenterThetaPhi(im1+1,1,im2+1,det);
214 if(im2!=0) fzmin[im1][im2]=det(2)-fDetz[im1];
215 else
216 fzmin[im1][im2]=det(2)-(fDetz[im1])*epsz;
217 if(im2!=(im2max-1)) fzmax[im1][im2]=det(2)+fDetz[im1];
218 else
cbcfa38d 219 fzmax[im1][im2]=det(2)+fDetz[im1]*epsz;
b48af428 220 if(im1==2 || im1==3) {
221 fzmin[im1][im2]-=epszdrift;
222 fzmax[im1][im2]+=epszdrift;
223 } // end if im1==2 || im1==3
224 } // end for im2
225 } // end for im1
13888096 226
b48af428 227 fphimin = new Double_t*[6]; fphimax = new Double_t*[6];
228 for(im1=0;im1<6;im1++) {
229 im2max=fNlad[im1];
230 fphimin[im1] = new Double_t[im2max];
231 fphimax[im1] = new Double_t[im2max];
232 } // end for im1
233
234 fphidet = new Double_t*[6];
235 for(im1=0; im1<6; im1++) {
236 im2max=fNlad[im1];
237 fphidet[im1] = new Double_t[im2max];
238 } // end for im1
239
def162f4 240 Double_t global[3],local[3];
b48af428 241 Double_t pigre=TMath::Pi();
242 Double_t xmin,ymin,xmax,ymax;
243
244 for(im1=0; im1<6; im1++) {
245 im2max=fNlad[im1];
246 for(im2=0; im2<im2max; im2++) {
247 Int_t idet=2;
248 g1->GetCenterThetaPhi(im1+1,im2+1,idet,det);
249 fphidet[im1][im2] = TMath::ATan2(Double_t(det(1)),
250 Double_t(det(0)));
251 if(fphidet[im1][im2]<0.) fphidet[im1][im2]+=2.*pigre;
252 local[1]=local[2]=0.;
253 local[0]= -(fDetx[im1]);
254 if(im1==0) local[0]= (fDetx[im1]); //to take into account
255 // different reference system
256 g1->LtoG(im1+1,im2+1,idet,local,global);
257 xmax=global[0]; ymax=global[1];
258 local[0]= (fDetx[im1]);
259 if(im1==0) local[0]= -(fDetx[im1]);//take into account different
260 // reference system
261 g1->LtoG(im1+1,im2+1,idet,local,global);
262 xmin=global[0]; ymin=global[1];
263 fphimin[im1][im2]= TMath::ATan2(ymin,xmin);
264 if(fphimin[im1][im2]<0.) fphimin[im1][im2]+=2.*pigre;
265 fphimax[im1][im2]= TMath::ATan2(ymax,xmax);
266 if(fphimax[im1][im2]<0.) fphimax[im1][im2]+=2.*pigre;
267 } // end for im2
268 } // end for im1
64ab0d55 269//////////////////////////////////////////////////////////////////////////////////////////////////////////
270/////////////// allocate memory and define vector fNRecPoints and matrices fRecCylR, fRecCylPhi, fRecCylZ /////////////
271 gAlice->GetEvent(evnumber);
272 Int_t NumOfModules = g1->GetIndexMax();
64ab0d55 273 fRecCylR = new Double_t *[NumOfModules];
64ab0d55 274 fRecCylPhi = new Double_t *[NumOfModules];
64ab0d55 275 fRecCylZ = new Double_t *[NumOfModules];
276 AliITSRecPoint *recp;
277 fNRecPoints = new Int_t[NumOfModules];
278
279 for(Int_t module=0; module<NumOfModules; module++) {
280 fITS->ResetRecPoints();
281 gAlice->TreeR()->GetEvent(module);
282 frecPoints=fITS->RecPoints();
283 Int_t nRecPoints=fNRecPoints[module]=frecPoints->GetEntries();
64ab0d55 284 fRecCylR[module] = new Double_t[nRecPoints];
285 fRecCylPhi[module] = new Double_t[nRecPoints];
286 fRecCylZ[module] = new Double_t[nRecPoints];
287 Int_t ind;
288 for(ind=0; ind<fNRecPoints[module]; ind++) {
289 recp=(AliITSRecPoint*)frecPoints->UncheckedAt(ind);
290 // Float_t global[3], local[3];
291 Double_t global[3], local[3];
292 local[0]=recp->GetX();
293 local[1]=0.;
294 local[2]= recp->GetZ();
295 g1->LtoG(module,local,global);
64ab0d55 296
297 Double_t r = TMath::Sqrt(global[0]*global[0]+global[1]*global[1]); // r hit
298 Double_t phi = TMath::ATan2(global[1],global[0]); if(phi<0.) phi+=2.*TMath::Pi(); // phi hit
def162f4 299 Double_t z = global[2]; // z hit
64ab0d55 300
301 fRecCylR[module][ind]=r;
302 fRecCylPhi[module][ind]=phi;
303 fRecCylZ[module][ind]=z;
304 }
305 }
306 //}
307 //}
308////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
309
b48af428 310
311 ////////// gets magnetic field factor //////////////////////////////
312
313 AliMagF * fieldPointer = gAlice->Field();
af50998a 314 // fFieldFactor = (Double_t)fieldPointer->Factor();
315 fFieldFactor =(Double_t)fieldPointer-> SolenoidField()/10/.2;
316 // cout<< " field factor = "<<fFieldFactor<<"\n"; getchar();
b48af428 317}
318//______________________________________________________________________
04b80329 319AliITSTrackerV1::AliITSTrackerV1(const AliITSTrackerV1 &cobj) {
b48af428 320 // Origin A. Badala' and G.S. Pappalardo:
321 // e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it
322 // copy constructor
64ab0d55 323
324 *fITS = *cobj.fITS;
b48af428 325 *fresult = *cobj.fresult;
326 fPtref = cobj.fPtref;
327 fChi2max = cobj.fChi2max;
328 **fvettid = **cobj.fvettid;
329 fflagvert = cobj.fflagvert;
330 Int_t imax=200,jmax=450;
331 frl = new AliITSRad(imax,jmax);
332 *frl = *cobj.frl;
333 fFieldFactor = cobj.fFieldFactor;
334 Int_t i,im1,im2,im2max;
335 for(i=0; i<6; i++) {
336 fNlad[i] = cobj.fNlad[i];
337 fNdet[i] = cobj.fNdet[i];
338 fAvrad[i] = cobj.fAvrad[i];
339 fDetx[i] = cobj.fDetx[i];
340 fDetz[i] = cobj.fDetz[i];
341 } // end or i
342 fzmin = new Double_t*[6]; fzmax = new Double_t*[6];
343 for(im1=0; im1<6; im1++) {
344 im2max=fNdet[im1];
345 fzmin[im1] = new Double_t[im2max];
346 fzmax[im1] = new Double_t[im2max];
347 } // end for im1
cbcfa38d 348 fphimin = new Double_t*[6]; fphimax = new Double_t*[6];
b48af428 349 for(im1=0;im1<6;im1++) {
350 im2max=fNlad[im1];
351 fphimin[im1] = new Double_t[im2max];
352 fphimax[im1] = new Double_t[im2max];
353 } // end for im1
354
355 fphidet = new Double_t*[6];
356 for(im1=0; im1<6; im1++) {
357 im2max=fNlad[im1];
358 fphidet[im1] = new Double_t[im2max];
359 } // end for im1
360 for(im1=0; im1<6; im1++) {
361 im2max=fNdet[im1];
362 for(im2=0; im2<im2max; im2++) {
363 fzmin[im1][im2]=cobj.fzmin[im1][im2];
364 fzmax[im1][im2]=cobj.fzmax[im1][im2];
365 } // end for im2
366 } // end for im1
367 for(im1=0; im1<6; im1++) {
368 im2max=fNlad[im1];
369 for(im2=0; im2<im2max; im2++) {
370 fphimin[im1][im2]=cobj.fphimin[im1][im2];
371 fphimax[im1][im2]=cobj.fphimax[im1][im2];
372 fphidet[im1][im2]=cobj.fphidet[im1][im2];
373 } // end for im2
374 } // end for im2
64ab0d55 375
376
377 AliITSgeom *g1 = fITS->GetITSgeom();
378 Int_t NumOfModules = g1->GetIndexMax();
379 /*
380 fRecCylR = new Float_t *[NumOfModules];
381 fRecCylPhi = new Float_t *[NumOfModules];
382 fRecCylZ = new Float_t *[NumOfModules];
383 */
384 fRecCylR = new Double_t *[NumOfModules];
385 fRecCylPhi = new Double_t *[NumOfModules];
386 fRecCylZ = new Double_t *[NumOfModules];
387 fNRecPoints = new Int_t[NumOfModules];
388 for(Int_t module=0; module<NumOfModules; module++) {
389 Int_t nRecPoints=fNRecPoints[module]=cobj.fNRecPoints[module];
390 /*
391 fRecCylR[module] = new Float_t[nRecPoints];
392 fRecCylPhi[module] = new Float_t[nRecPoints];
393 fRecCylZ[module] = new Float_t[nRecPoints];
394 */
395 fRecCylR[module] = new Double_t[nRecPoints];
396 fRecCylPhi[module] = new Double_t[nRecPoints];
397 fRecCylZ[module] = new Double_t[nRecPoints];
398 Int_t ind;
399 for(ind=0; ind<nRecPoints; ind++) {
400 fRecCylR[module][ind]=cobj.fRecCylR[module][ind];
401 fRecCylPhi[module][ind]=cobj.fRecCylPhi[module][ind];
402 fRecCylZ[module][ind]=cobj.fRecCylZ[module][ind];
403 }
404 }
405
406}
407void AliITSTrackerV1::DelMatrix(Int_t NumOfModules) {
408 for(Int_t mod=0; mod<NumOfModules; mod++) {
409 delete fRecCylR[mod];
410 delete fRecCylPhi[mod];
411 delete fRecCylZ[mod];
412 }
413 delete fRecCylR;
414 delete fRecCylPhi;
415 delete fRecCylZ;
cbcfa38d 416}
b48af428 417//______________________________________________________________________
cbcfa38d 418AliITSTrackerV1::~AliITSTrackerV1(){
b48af428 419 // Origin A. Badala' and G.S. Pappalardo:
420 // e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it
64ab0d55 421 // class destructor
422 delete frl;
423 delete fNRecPoints;
424 for(Int_t i=0; i<6; i++) {
425 delete fzmin[i];
426 delete fzmax[i];
427 delete fphimin[i];
428 delete fphimax[i];
429 delete fphidet[i];
430 }
431
432 delete fzmin;
433 delete fzmax;
434 delete fphimin;
435 delete fphimax;
436 delete fphidet;
437
13888096 438}
b48af428 439//______________________________________________________________________
04b80329 440AliITSTrackerV1 &AliITSTrackerV1::operator=(AliITSTrackerV1 obj) {
b48af428 441 // Origin A. Badala' and G.S. Pappalardo:
442 // e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it
443 // assignement operator
444
64ab0d55 445 *fITS = *obj.fITS;
b48af428 446 *fresult = *obj.fresult;
447 fPtref = obj.fPtref;
448 fChi2max = obj.fChi2max;
449 **fvettid = **obj.fvettid;
450 fflagvert = obj.fflagvert;
451 Int_t imax=200,jmax=450;
452 frl = new AliITSRad(imax,jmax);
453 *frl = *obj.frl;
454 fFieldFactor = obj.fFieldFactor;
455 Int_t i;
456 for(i=0; i<6; i++) {
457 fNlad[i] = obj.fNlad[i];
458 fNdet[i] = obj.fNdet[i];
459 fAvrad[i] = obj.fAvrad[i];
460 fDetx[i] = obj.fDetx[i];
461 fDetz[i] = obj.fDetz[i];
462 } // end for i
463 fzmin = new Double_t*[6];
464 fzmax = new Double_t*[6];
465 Int_t im1, im2, im2max;
466 for(im1=0; im1<6; im1++) {
467 im2max=fNdet[im1];
468 fzmin[im1] = new Double_t[im2max]; fzmax[im1] = new Double_t[im2max];
469 } // end for im1
cbcfa38d 470 fphimin = new Double_t*[6]; fphimax = new Double_t*[6];
b48af428 471 for(im1=0;im1<6;im1++) {
472 im2max=fNlad[im1];
473 fphimin[im1] = new Double_t[im2max];
474 fphimax[im1] = new Double_t[im2max];
475 } // end for im1
476
477 fphidet = new Double_t*[6];
478 for(im1=0; im1<6; im1++) {
479 im2max=fNlad[im1];
480 fphidet[im1] = new Double_t[im2max];
481 } // end for im1
482 for(im1=0; im1<6; im1++) {
483 im2max=fNdet[im1];
484 for(im2=0; im2<im2max; im2++) {
485 fzmin[im1][im2]=obj.fzmin[im1][im2];
486 fzmax[im1][im2]=obj.fzmax[im1][im2];
487 } // end for im2
488 } // end for im1
489 for(im1=0; im1<6; im1++) {
490 im2max=fNlad[im1];
491 for(im2=0; im2<im2max; im2++) {
492 fphimin[im1][im2]=obj.fphimin[im1][im2];
493 fphimax[im1][im2]=obj.fphimax[im1][im2];
494 fphidet[im1][im2]=obj.fphidet[im1][im2];
495 } // end for im2
496 } // end for im1
497
64ab0d55 498 AliITSgeom *g1 = fITS->GetITSgeom();
499 Int_t NumOfModules = g1->GetIndexMax();
64ab0d55 500 fRecCylR = new Double_t *[NumOfModules];
501 fRecCylPhi = new Double_t *[NumOfModules];
502 fRecCylZ = new Double_t *[NumOfModules];
503 fNRecPoints = new Int_t[NumOfModules];
504 for(Int_t module=0; module<NumOfModules; module++) {
505 Int_t nRecPoints=fNRecPoints[module]=obj.fNRecPoints[module];
64ab0d55 506 fRecCylR[module] = new Double_t[nRecPoints];
507 fRecCylPhi[module] = new Double_t[nRecPoints];
508 fRecCylZ[module] = new Double_t[nRecPoints];
509 Int_t ind;
510 for(ind=0; ind<nRecPoints; ind++) {
511 fRecCylR[module][ind]=obj.fRecCylR[module][ind];
512 fRecCylPhi[module][ind]=obj.fRecCylPhi[module][ind];
513 fRecCylZ[module][ind]=obj.fRecCylZ[module][ind];
514 }
515 }
516
517
b48af428 518 return *this;
04b80329 519}
b48af428 520//______________________________________________________________________
521void AliITSTrackerV1::DoTracking(Int_t evNumber,Int_t minTr,Int_t maxTr,
61231d74 522 TFile *file, Bool_t realmass) {
b48af428 523 // Origin A. Badala' and G.S. Pappalardo:
524 // e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it
525 // The method needs the event number, the minimum and maximum order
526 // number of TPC tracks that
527 // are to be tracked trough the ITS, and the file where the recpoints
528 // are registered.
529 // The method can be called by a macro. It preforms the tracking for
530 // all good TPC tracks
531
532 printf("begin DoTracking - file %p\n",file);
533
534 gAlice->GetEvent(evNumber); //modificato per gestire hbt
13888096 535
b48af428 536 AliKalmanTrack *kkprov;
af50998a 537 //kkprov->SetConvConst(100/0.299792458/0.2/fFieldFactor);
538 kkprov->SetConvConst(1000/0.299792458/gAlice->Field()->SolenoidField());
539 // cout<<" field = "<<gAlice->Field()->SolenoidField()<<endl;
540
b48af428 541
542 TFile *cf=TFile::Open("AliTPCclusters.root");
9040b789 543 AliTPCParam *digp= (AliTPCParam*)cf->Get("75x40_100x60_150x60");
b48af428 544 if (!digp) { cerr<<"TPC parameters have not been found !\n"; getchar();}
545
546 cf->cd();
547 AliTPCtracker *tracker = new AliTPCtracker(digp,evNumber);
548
549 // Load clusters
550 tracker->LoadInnerSectors();
551 tracker->LoadOuterSectors();
552
553 // Load tracks
64ab0d55 554 TFile *tf=TFile::Open("AliTPCtracksSorted.root");
b48af428 555 if (!tf->IsOpen()) {
556 cerr<<"Can't open AliTPCtracksSorted.root !\n";
557 return ;
558 } // end if
559 TObjArray tracks(200000);
560 char tname[100];
561 sprintf(tname,"TreeT_TPC_%d",evNumber);
562
563 TTree *tracktree=(TTree*)tf->Get(tname);
564 if (!tracktree) {cerr<<"Can't get a tree with TPC tracks !\n";}
565 TBranch *tbranch=tracktree->GetBranch("tracks");
566 Int_t nentr=(Int_t)tracktree->GetEntries();
567 Int_t kk;
568
def162f4 569 AliITSRecPoint *recp; // oggi
570 AliTPCtrack *ioTrackTPC=0;
b48af428 571 for (kk=0; kk<nentr; kk++) {
572 ioTrackTPC=new AliTPCtrack;
573 tbranch->SetAddress(&ioTrackTPC);
574 tracktree->GetEvent(kk);
575 tracker->CookLabel(ioTrackTPC,0.1);
576 tracks.AddLast(ioTrackTPC);
577 } // end for kk
578 delete tracker;
579 tf->Close();
580
581 Int_t nt = tracks.GetEntriesFast();
582 cerr<<"Number of found tracks "<<nt<<endl;
583
584 TVector vec(5);
585 TTree *tr=gAlice->TreeR();
586 Int_t nent=(Int_t)tr->GetEntries();
587 frecPoints = fITS->RecPoints();
588
589 Int_t numbpoints;
590 Int_t totalpoints=0;
591 Int_t *np = new Int_t[nent];
592 fvettid = new Int_t* [nent];
593 Int_t mod;
594
595 for (mod=0; mod<nent; mod++) {
596 fvettid[mod]=0;
597 fITS->ResetRecPoints();
598 gAlice->TreeR()->GetEvent(mod);
599 numbpoints = frecPoints->GetEntries();
600 totalpoints+=numbpoints;
601 np[mod] = numbpoints;
602 //cout<<" mod = "<<mod<<" numbpoints = "<<numbpoints<<"\n";getchar();
603 fvettid[mod] = new Int_t[numbpoints];
604 Int_t ii;
605 for (ii=0;ii<numbpoints; ii++) *(fvettid[mod]+ii)=0;
606 } // end for mod
607
608 AliTPCtrack *track=0;
609
610 if(minTr < 0) {minTr = 0; maxTr = nt-1;}
611
612 TVector vgeant(3);
613
614 TTree tracktree1("TreeT","Tree with ITS tracks");
615 AliITSIOTrack *ioTrack=0;
def162f4 616 AliITSPid *pid=new AliITSPid(1000); // oggi
617
b48af428 618 tracktree1.Branch("ITStracks","AliITSIOTrack",&ioTrack,32000,0);
619
def162f4 620 TDatabasePDG * db = new TDatabasePDG;
61231d74 621
b48af428 622 Int_t j;
623 for (j=minTr; j<=maxTr; j++) {
624 track=(AliTPCtrack*)tracks.UncheckedAt(j);
625 if (!track) continue;
61231d74 626
627 /// mass definition ////////////////////////
628 Double_t mass=0.13956995;
629 Int_t pcode=211; // a pion by default
def162f4 630
61231d74 631 if(realmass) {
def162f4 632 if(TMath::Abs(pcode)<20443) mass=db->GetParticle(pcode)->Mass();
61231d74 633 }
def162f4 634 else {
635 mass = track->GetMass();
636 cout << "Mass = " << mass << endl;
637 }
638
61231d74 639
640
d3ab000e 641 // new propagation to the end of TPC
64ab0d55 642 Double_t xk=80.;
643 // track->PropagateTo(xk,0.,0.); //Ne if it's still there //attenzione funziona solo se modifica in TPC
644 // Double_t xk=77.415;
d3ab000e 645 track->PropagateTo(xk, 28.94, 1.204e-3);
646 xk-=0.005;
647 track->PropagateTo(xk, 44.77,1.71); //Tedlar
648 xk-=0.02;
649 track->PropagateTo(xk, 44.86, 1.45); //Kevlar
650 xk-=2.0;
651 track->PropagateTo(xk, 41.28, 0.029);//Nomex
652 xk-=0.02;
653 track->PropagateTo(xk, 44.86, 1.45); //Kevlar
654 xk-=0.005;
655 track->PropagateTo(xk, 44.77, 1.71); //Tedlar
656
657 xk=61.;
64ab0d55 658 // track->PropagateTo(xk,0.,0.); //C02
659 track->PropagateTo(xk,36.2,1.98e-3); //C02 //attenzione funziona solo se modifica in TPC
d3ab000e 660
661 xk -=0.005;
662 track->PropagateTo(xk, 24.01, 2.7); //Al
663 xk -=0.005;
664 track->PropagateTo(xk, 44.77, 1.71); //Tedlar
665 xk -=0.02;
666 track->PropagateTo(xk, 44.86, 1.45); //Kevlar
667 xk -=0.5;
668 track->PropagateTo(xk, 41.28, 0.029); //Nomex
669 xk -=0.02;
670 track->PropagateTo(xk, 44.86, 1.45); //Kevlar
671 xk -=0.005;
672 track->PropagateTo(xk, 44.77, 1.71); //Tedlar
673 xk -=0.005;
64ab0d55 674 track->PropagateTo(xk, 24.01, 2.7); //Al
af50998a 675
64ab0d55 676 ////////////////////////////////////////////////////////////////////////////////////////////////////////
af50998a 677 //AliITSTrackV1 trackITS(*track);
678 AliITSTrackV1 trackITS(*track, fFieldFactor);
679 //cout<<" fFieldFactor = "<<fFieldFactor<<"\n";
61231d74 680 trackITS.PutMass(mass); //new to add mass to track
b48af428 681 if(fresult){ delete fresult; fresult=0;}
682 fresult = new AliITSTrackV1(trackITS);
683
684 AliITSTrackV1 primaryTrack(trackITS);
685 vgeant=(*fresult).GetVertex();
686
687 // Definition of dv and zv for vertex constraint
688 Double_t sigmaDv=0.0050; Double_t sigmaZv=0.010;
689 //Double_t sigmaDv=0.0015; Double_t sigmaZv=0.0015;
13888096 690 Double_t uniform= gRandom->Uniform();
691 Double_t signdv;
692 if(uniform<=0.5) signdv=-1.;
b48af428 693 else
694 signdv=1.;
695
04b80329 696 Double_t vr=TMath::Sqrt(vgeant(0)*vgeant(0)+ vgeant(1)*vgeant(1));
b48af428 697 Double_t dv=gRandom->Gaus(signdv*vr,(Float_t)sigmaDv);
698 Double_t zv=gRandom->Gaus(vgeant(2),(Float_t)sigmaZv);
699 //cout<<" Dv e Zv = "<<dv<<" "<<zv<<"\n";
700 trackITS.SetDv(dv);
701 trackITS.SetZv(zv);
702 trackITS.SetsigmaDv(sigmaDv);
703 trackITS.SetsigmaZv(sigmaZv);
704 (*fresult).SetDv(dv);
705 (*fresult).SetZv(zv);
706 (*fresult).SetsigmaDv(sigmaDv);
707 (*fresult).SetsigmaZv(sigmaZv);
708 primaryTrack.SetDv(dv);
709 primaryTrack.SetZv(zv);
710 primaryTrack.SetsigmaDv(sigmaDv);
711 primaryTrack.SetsigmaZv(sigmaZv);
712 primaryTrack.PrimaryTrack(frl);
713 TVector d2=primaryTrack.Getd2();
714 TVector tgl2=primaryTrack.Gettgl2();
715 TVector dtgl=primaryTrack.Getdtgl();
716 trackITS.Setd2(d2); trackITS.Settgl2(tgl2);
717 trackITS.Setdtgl(dtgl);
718 (*fresult).Setd2(d2); (*fresult).Settgl2(tgl2);
719 (*fresult).Setdtgl(dtgl);
720 /*
721 trackITS.SetVertex(vertex); trackITS.SetErrorVertex(ervertex);
722 (*result).SetVertex(vertex); (*result).SetErrorVertex(ervertex);
723 */
724 TList *list= new TList();
725
726 list->AddLast(&trackITS);
727
728 fPtref=TMath::Abs( (trackITS).GetPt() );
af50998a 729 //cout<<" fPtref = " <<fPtref<<"\n";
b48af428 730 if(fPtref>1.0) fChi2max=40.;
731 if(fPtref<=1.0) fChi2max=20.;
732 if(fPtref<0.4 ) fChi2max=100.;
733 if(fPtref<0.2 ) fChi2max=40.;
734 // if(fPtref<0.4 ) fChi2max=30.;
735 // if(fPtref<0.2 ) fChi2max=20.;
736 //if(fPtref<0.2 ) fChi2max=10.;
737 //if(fPtref<0.1 ) fChi2max=5.;
c57de405 738 //cout << "\n Pt = " << fPtref <<"\n"; //stampa
b48af428 739 RecursiveTracking(list);
740 list->Delete();
741 delete list;
742
743 Int_t itot=-1;
744 TVector vecTotLabRef(18);
745 Int_t lay, k;
746 for(lay=5; lay>=0; lay--) {
747 TVector vecLabRef(3);
748 vecLabRef=(*fresult).GetLabTrack(lay);
749 Float_t clustZ=(*fresult).GetZclusterTrack( lay);
750 for(k=0; k<3; k++){
04b80329 751 Int_t lpp=(Int_t)vecLabRef(k);
752 if(lpp>=0) {
b48af428 753 TParticle *p=(TParticle*) gAlice->Particle(lpp);
754 Int_t pcode=p->GetPdgCode();
755 if(pcode==11) vecLabRef(k)=p->GetFirstMother();
756 } // end if
757 itot++; vecTotLabRef(itot)=vecLabRef(k);
64ab0d55 758 if(vecLabRef(k)==0. && clustZ == -1.) vecTotLabRef(itot) =-3.;
b48af428 759 } // end for k
760 } // end for lay
761 Long_t labref;
762 Int_t freq;
763 (*fresult).Search(vecTotLabRef, labref, freq);
764
765 //if(freq < 6) labref=-labref; // cinque - sei
766 if(freq < 5) labref=-labref; // cinque - sei
767 (*fresult).SetLabel(labref);
768
769 // cout<<" progressive track number = "<<j<<"\r";
770 // cout<<j<<"\r";
771 Int_t numOfCluster=(*fresult).GetNumClust();
c57de405 772 //cout<<" progressive track number = "<<j<<"\n"; // stampa
b48af428 773 Long_t labITS=(*fresult).GetLabel();
c57de405 774 //cout << " ITS track label = " << labITS << "\n"; // stampa
b48af428 775 Int_t lab=track->GetLabel();
c57de405 776 //cout << " TPC track label = " << lab <<"\n"; // stampa
b48af428 777 //propagation to vertex
778
779 Double_t rbeam=3.;
def162f4 780 if((*fresult).DoNotCross(rbeam)) continue; //no intersection with beampipe
b48af428 781 (*fresult).Propagation(rbeam);
782 Double_t c00,c10,c11,c20,c21,c22,c30,c31,c32,c33,c40,c41,c42,c43,c44;
783 (*fresult).GetCElements(c00,
784 c10,c11,
785 c20,c21,c22,
786 c30,c31,c32,c33,
787 c40,c41,c42,c43,c44);
13888096 788
b48af428 789 Double_t pt=TMath::Abs((*fresult).GetPt());
790 Double_t dr=(*fresult).GetD();
791 Double_t z=(*fresult).GetZ();
792 Double_t tgl=(*fresult).GetTgl();
793 Double_t c=(*fresult).GetC();
794 Double_t cy=c/2.;
795 Double_t dz=z-(tgl/cy)*TMath::ASin((*fresult).Arga(rbeam));
796 dz-=vgeant(2);
797 // cout<<" dr e dz alla fine = "<<dr<<" "<<dz<<"\n"; getchar();
798 Double_t phi=(*fresult).Getphi();
799 Double_t phivertex = phi - TMath::ASin((*fresult).ArgA(rbeam));
800 Double_t duepi=2.*TMath::Pi();
801 if(phivertex>duepi) phivertex-=duepi;
802 if(phivertex<0.) phivertex+=duepi;
803 /////////////////////////////////////////////////////////////
804 Int_t idmodule,idpoint;
805 if(numOfCluster >=5) { // cinque - sei
806 //if(numOfCluster ==6) { // cinque - sei
807 AliITSIOTrack outTrack;
808 ioTrack=&outTrack;
809 ioTrack->SetStatePhi(phi);
810 ioTrack->SetStateZ(z);
811 ioTrack->SetStateD(dr);
812 ioTrack->SetStateTgl(tgl);
813 ioTrack->SetStateC(c);
814 Double_t radius=(*fresult).Getrtrack();
815 ioTrack->SetRadius(radius);
816 Int_t charge;
817 if(c>0.) charge=-1; else charge=1;
818 ioTrack->SetCharge(charge);
def162f4 819 Double_t trackmass=(*fresult).GetMass(); // oggi
820 ioTrack->SetMass(trackmass); // oggi
b48af428 821 ioTrack->SetCovMatrix(c00,
822 c10,c11,
823 c20,c21,c22,
824 c30,c31,c32,c33,
825 c40,c41,c42,c43,c44);
826 Double_t px=pt*TMath::Cos(phivertex);
827 Double_t py=pt*TMath::Sin(phivertex);
828 Double_t pz=pt*tgl;
829 Double_t xtrack=dr*TMath::Sin(phivertex);
830 Double_t ytrack=dr*TMath::Cos(phivertex);
831 Double_t ztrack=dz+vgeant(2);
832 ioTrack->SetPx(px);
833 ioTrack->SetPy(py);
834 ioTrack->SetPz(pz);
835 ioTrack->SetX(xtrack);
836 ioTrack->SetY(ytrack);
837 ioTrack->SetZ(ztrack);
838 ioTrack->SetLabel(labITS);
839 ioTrack->SetTPCLabel(lab);
61231d74 840 ioTrack->SetDz(dz);
b48af428 841 Int_t il;
def162f4 842 /*
843 for(il=0;il<6; il++){
b48af428 844 ioTrack->SetIdPoint(il,(*fresult).GetIdPoint(il));
845 ioTrack->SetIdModule(il,(*fresult).GetIdModule(il));
846 } // end for il
def162f4 847 */
848 //tracktree1.Fill();
849 Float_t q[4]={-1.,-1.,-1.,-1.};
850 Float_t globaldedx=0.;
b48af428 851 for (il=0;il<6;il++) {
852 idpoint=(*fresult).GetIdPoint(il);
853 idmodule=(*fresult).GetIdModule(il);
61231d74 854 if(idmodule>0.) *(fvettid[idmodule]+idpoint)=1;
855
b48af428 856 ioTrack->SetIdPoint(il,idpoint);
857 ioTrack->SetIdModule(il,idmodule);
def162f4 858 //// for q definition
859 if(il>1){
860 if(idmodule>0.){
861 fITS->ResetRecPoints();
862 gAlice->TreeR()->GetEvent(idmodule);
863 recp=(AliITSRecPoint*)frecPoints->UncheckedAt(idpoint);
864 q[il-2]=recp->GetQ()*(*fresult).Getfcor(il-2);
865 }
866 }
867 } // end for il
868 q[0]/=280.; q[1]/=280.;
869 q[2]/=38.; q[3]/=38.;
870
871 // cout<<" q prima = "<<q[0]<<" "<<q[1]<<" "<<q[2]<<" "<<q[3]<<"\n"; getchar();
872
873 Int_t swap;
874 do{
875 swap=0;
876 for (il=0; il<3; il++) {
877 if (q[il]<=q[il+1]) continue;
878 Float_t tmp=q[il];
879 q[il]=q[il+1]; q[il+1]=tmp;
880 swap++;
881 }
882 } while(swap);
883
884
885 // cout<<" q dopo = "<<q[0]<<" "<<q[1]<<" "<<q[2]<<" "<<q[3]<<"\n"; getchar();
886
887 if(q[0]<0.) {
888 q[0]=q[1];
889 q[1]=q[2];
890 q[2]=q[3];
891 q[3]=-1.;
892 }
893
894 // cout<<" q dopo if = "<<q[0]<<" "<<q[1]<<" "<<q[2]<<" "<<q[3]<<"\n"; getchar();
895
896 globaldedx=(q[0]+q[1])/2.;
897
898 // if(q[3]> 0.) globaldedx=(q[0]+q[1]+q[2]+q[3])/4.;
899 // else globaldedx=(q[0]+q[1]+q[2])/3.;
900
901 ioTrack->SetdEdx(globaldedx);
902 ioTrack->SetPid(pid->GetPcode(ioTrack));
903
904 tracktree1.Fill();
b48af428 905 } // end if on numOfCluster
906 //gObjectTable->Print(); // stampa memoria
907 } // end for (int j=minTr; j<=maxTr; j++)
61231d74 908 delete db;
b48af428 909 static Bool_t first=kTRUE;
910 static TFile *tfile;
911 if(first) {
912 tfile=new TFile("itstracks.root","RECREATE");
913 //cout<<"I have opened itstracks.root file "<<endl;
914 } // end if
915 first=kFALSE;
916 tfile->cd();
917 tfile->ls();
918 char hname[30];
919 sprintf(hname,"TreeT%d",evNumber);
def162f4 920 cout << "Number of saved ITS tracks " << tracktree1.GetEntries() << endl;
b48af428 921 tracktree1.Write(hname);
922
923 TTree *fAli=gAlice->TreeK();
924 TFile *fileAli=0;
925 if (fAli) fileAli =fAli->GetCurrentFile();
926 fileAli->cd();
927 ////////////////////////////////////////////////////////////////////
928
929 printf("delete vectors\n");
930 if(np) delete [] np;
931 if(fvettid) delete [] fvettid;
932 if(fresult) {delete fresult; fresult=0;}
04b80329 933}
b48af428 934//______________________________________________________________________
04b80329 935void AliITSTrackerV1::RecursiveTracking(TList *trackITSlist) {
b48af428 936 // This function perform the recursive tracking in ITS detectors
937 // reference is a pointer to the final best track
938 // Origin A. Badala' and G.S. Pappalardo:
939 // e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it
940 // The authors thank Mariana Bondila to have help them to resolve some
941 // problems. July-2000
942
943 //Rlayer[0]=4.; Rlayer[1]=7.; Rlayer[2]=14.9;
944 // Rlayer[3]=23.8; Rlayer[4]=39.1; Rlayer[5]=43.6; //vecchio
945
946 //////////////////////
947 Float_t sigmaphil[6], sigmazl[6];
948 sigmaphil[0]=1.44e-6/(fAvrad[0]*fAvrad[0]);
949 sigmaphil[1]=1.44e-6/(fAvrad[1]*fAvrad[1]);
950 sigmaphil[2]=1.444e-5/(fAvrad[2]*fAvrad[2]);
951 sigmaphil[3]=1.444e-5/(fAvrad[3]*fAvrad[3]);
952 sigmaphil[4]=4e-6/(fAvrad[4]*fAvrad[4]);
953 sigmaphil[5]=4e-6/(fAvrad[5]*fAvrad[5]);
954 sigmazl[0]=1e-2;
955 sigmazl[1]=1e-2;
956 sigmazl[2]=7.84e-4;
957 sigmazl[3]=7.84e-4;
958 sigmazl[4]=0.6889;
959 sigmazl[5]=0.6889;
960 ///////////////////////////////////////////////////////////
961 Int_t index;
962 AliITSgeom *g1 = fITS->GetITSgeom();
963 AliITSRecPoint *recp;
964 for(index =0; index<trackITSlist->GetSize(); index++) {
965 AliITSTrackV1 *trackITS = (AliITSTrackV1 *) trackITSlist->At(index);
966 if((*trackITS).GetLayer()==7) fresult->SetChi2(10.223e140);
967 // cout <<" Layer inizio = "<<(*trackITS).GetLayer()<<"\n";
968 // cout<<"fvtrack =" <<"\n";
969 // cout << (*trackITS)(0) << " "<<(*trackITS)(1)<<" "
970 // <<(*trackITS)(2)<<" "<<(*trackITS)(3)<<" "
971 // <<(*trackITS)(4)<<"\n";
972 // cout<< " rtrack = "<<(*trackITS).Getrtrack()<<"\n";
973 // cout<< " Pt = "<<(*trackITS).GetPt()<<"\n";
974 // getchar();
975 Double_t chi2Now, chi2Ref;
976 Float_t numClustRef = fresult->GetNumClust();
977 if((*trackITS).GetLayer()==1 ) {
978 chi2Now = trackITS->GetChi2();
979 Float_t numClustNow = trackITS->GetNumClust();
980 if(trackITS->GetNumClust())
981 chi2Now /= (Double_t)trackITS->GetNumClust();
982 chi2Ref = fresult->GetChi2();
983 if(fresult->GetNumClust())
984 chi2Ref /= (Double_t)fresult->GetNumClust();
985 //cout<<" chi2Now and chi2Ref = "<<chi2Now<<" "<<chi2Ref<<"\n";
986 if( numClustNow > numClustRef ) {*fresult = *trackITS;}
987 if((numClustNow == numClustRef )&&
988 (chi2Now < chi2Ref)) {
989 *fresult = *trackITS;
990 } // end if
991 continue;
992 } // end if
993
994 if(trackITS->Getfnoclust()>=2) continue;
995 Float_t numClustNow = trackITS->GetNumClust();
996 if(numClustNow) {
997 chi2Now = trackITS->GetChi2();
998
999 if(numClustNow<numClustRef && chi2Now>fresult->GetChi2()) continue;
1000 //cout<<" chi2Now = "<<chi2Now<<"\n";
64ab0d55 1001
b48af428 1002 chi2Now/=numClustNow;
1003 if(fPtref > 1.0 && chi2Now > 30.) continue;
1004 if((fPtref >= 0.6 && fPtref<=1.0) && chi2Now > 40.) continue;
1005 // if((fPtref <= 0.6 && fPtref>0.2)&& chi2Now > 40.) continue;
1006 // if(fPtref <= 0.2 && chi2Now > 8.) continue;
1007 if((fPtref <= 0.6 && fPtref>0.2)&& chi2Now > 30.) continue;
1008 if(fPtref <= 0.2 && chi2Now > 7.) continue;
1009 /////////////////////////////
1010 } // end if
1011
1012 Int_t layerInit = (*trackITS).GetLayer();
1013 Int_t layernew = layerInit - 2;// -1 for new layer, -1 for matrix index
1014 TList listoftrack;
1015 Int_t ladp, ladm, detp,detm,ladinters,detinters;
1016 Int_t layerfin=layerInit-1;
1017 // cout<<"Prima di intersection \n";
b48af428 1018 Int_t outinters=Intersection(*trackITS,layerfin,ladinters,detinters);
b48af428 1019 // cout<<" outinters = "<<outinters<<"\n";
1020 // cout<<" Layer ladder detector intersection ="
1021 // <<layerfin<<" "<<ladinters<<" "<<detinters<<"\n";
1022 // cout << " phiinters zinters = "<<(*trackITS)(0)
1023 // << " "<<(*trackITS)(1)<<"\n"; getchar();
1024 if(outinters==-1) continue;
1025 Int_t flaghit=0;
def162f4 1026 (*trackITS).SetLayer(layerfin); // oggi
1027 (*trackITS).Setfcor(); // oggi
b48af428 1028 if(outinters==0){
1029 TVector toucLad(9), toucDet(9);
1030 Int_t lycur=layerfin;
1031 ladp=ladinters+1;
1032 ladm=ladinters-1;
1033 if(ladm <= 0) ladm=fNlad[layerfin-1];
1034 if(ladp > fNlad[layerfin-1]) ladp=1;
1035 detp=detinters+1;
1036 detm=detinters-1;
1037 Int_t idetot=1;
1038 /*
1039 toucLad(0)=ladinters; toucLad(1)=ladm; toucLad(2)=ladp;
1040 toucLad(3)=ladinters; toucLad(4)=ladm; toucLad(5)=ladp;
1041 toucLad(6)=ladinters; toucLad(7)=ladm; toucLad(8)=ladp;
1042 toucDet(0)=detinters; toucDet(1)=detinters; toucDet(2)=detinters;
1043 if(detm > 0 && detp <= fNdet[layerfin-1]) {
1044 idetot=9;
1045 toucDet(3)=detm; toucDet(4)=detm; toucDet(5)=detm;
1046 toucDet(6)=detp; toucDet(7)=detp; toucDet(8)=detp;
1047 } // end if
1048 if(detm > 0 && detp > fNdet[layerfin-1]) {
1049 idetot=6;
1050 toucDet(3)=detm; toucDet(4)=detm; toucDet(5)=detm;
1051 } // end if
1052 if(detm <= 0 && detp <= fNdet[layerfin-1]) {
1053 idetot=6;
1054 toucDet(3)=detp; toucDet(4)=detp; toucDet(5)=detp;
1055 } // end if
1056 */
f66ae545 1057 Float_t epsphi=5.0, epsz=5.0;
b48af428 1058 if(fPtref<0.2) {epsphi=3.; epsz=3.;}
64ab0d55 1059 // new definition of idetot e toucLad e toucDet to be
b48af428 1060 // transformed in a method
1061 // these values could be modified
1062 Float_t pigre=TMath::Pi();
1063 Float_t rangephi=5., rangez=5.;
1064 if(layerfin==1 || layerfin ==2){
1065 rangephi=40.*epsphi*TMath::Sqrt(sigmaphil[layerfin-1]+
1066 (*trackITS).GetSigmaphi());
1067 rangez = 40.*epsz*TMath::Sqrt(sigmazl[layerfin-1]+
1068 (*trackITS).GetSigmaZ());
1069 } // end if
1070 if(layerfin==3 || layerfin ==4){
1071 //rangephi=30.*fepsphi*TMath::Sqrt(sigmaphil[layerfin-1]+
1072 // (*trackITS).GetSigmaphi());
1073 //rangez = 40.*fepsz*TMath::Sqrt(sigmazl[layerfin-1]+
1074 // (*trackITS).GetSigmaZ());
1075 rangephi=40.*epsphi*TMath::Sqrt(sigmaphil[layerfin-1]+
1076 (*trackITS).GetSigmaphi());
1077 rangez = 50.*epsz*TMath::Sqrt(sigmazl[layerfin-1]+
1078 (*trackITS).GetSigmaZ());
1079 } // end if
1080 if(layerfin==5 || layerfin ==6){
1081 rangephi=20.*epsphi*TMath::Sqrt(sigmaphil[layerfin-1]+
1082 (*trackITS).GetSigmaphi());
1083 rangez =5.*epsz*TMath::Sqrt(sigmazl[layerfin-1]+
1084 (*trackITS).GetSigmaZ());
1085 } // end if
1086 Float_t phinters, zinters;
1087 phinters=(*trackITS).Getphi();
1088 zinters=(*trackITS).GetZ();
1089 Float_t distz = 0.0;
1090 Float_t phicm, phicp, distphim, distphip;
1091 phicm=phinters;
cf411bb5 1092 if(phinters>fphimax[layerfin-1][ladm-1]) phicm=phinters-2*pigre; //corretto il 20-11-2001
1093 distphim=TMath::Abs(phicm-fphimax[layerfin-1][ladm-1]); //corretto il 20-11-2001
b48af428 1094 phicp=phinters;
cf411bb5 1095 //cout<<" fNlad[layerfin-1] e ladp = "<<fNlad[layerfin-1]<<" "<<ladp<<endl;
1096 if(phinters>fphimin[layerfin-1][ladp-1]) phicp=phinters-2.*pigre; //corretto il 20-11-2001
1097 distphip=TMath::Abs(phicp-fphimin[layerfin-1][ladp-1]); //corretto il 20-11-2001
b48af428 1098 Int_t flagzmin=0;
1099 Int_t flagzmax=0;
1100 idetot=1;
1101 toucLad(0)=ladinters; toucDet(0)=detinters;
1102 if(detm>0) distz=TMath::Abs(zinters-fzmax[layerfin-1][detm-1]);
1103 if(detm>0 && rangez>=distz){
1104 flagzmin=1;
1105 idetot++; toucLad(idetot-1)=ladinters; toucDet(idetot-1)=detm;
1106 if(rangephi>=distphim){
1107 idetot++;
1108 toucLad(idetot-1)=ladm;
1109 toucDet(idetot-1)=detinters;
1110 idetot++;
1111 toucLad(idetot-1)=ladm;
1112 toucDet(idetot-1)=detm;
1113 } // end if
1114 if(rangephi>=distphip){
1115 idetot++;
1116 toucLad(idetot-1)=ladp;
1117 toucDet(idetot-1)=detinters;
1118 idetot++;
1119 toucLad(idetot-1)=ladp;
1120 toucDet(idetot-1)=detm;
1121 } // end if
1122 } //end detm>0....
1123 if(detp<=fNdet[layerfin-1])
1124 distz=TMath::Abs(zinters-fzmin[layerfin-1][detp-1]);
1125 if(detp<=fNdet[layerfin-1] && rangez>=distz){
1126 flagzmax=1;
1127 idetot++; toucLad(idetot-1)=ladinters; toucDet(idetot-1)=detp;
1128 if(rangephi>=distphim){
1129 idetot++; toucLad(idetot-1)=ladm; toucDet(idetot-1)=detp;
1130 if(flagzmin == 0) {
1131 idetot++;
1132 toucLad(idetot-1)=ladm;
1133 toucDet(idetot-1)=detinters;
1134 } // end if
1135 } // end if
1136 if(rangephi>=distphip){
1137 idetot++;
1138 toucLad(idetot-1)=ladp;
1139 toucDet(idetot-1)=detp;
1140 if(flagzmin == 0) {
1141 idetot++;
1142 toucLad(idetot-1)=ladp;
1143 toucDet(idetot-1)=detinters;
1144 } // end if
1145 } // end if
1146 } //end detm<fNdet[.......
1147
1148 if(flagzmin == 0 && flagzmax==0){
1149 if(rangephi>=distphim){
1150 idetot++;
1151 toucLad(idetot-1)=ladm;
1152 toucDet(idetot-1)=detinters;
1153 } // end if
1154 if(rangephi>=distphip){
1155 idetot++;
1156 toucLad(idetot-1)=ladp;
1157 toucDet(idetot-1)=detinters;
1158 } // end if
1159 } // end if
1160 ////////////////////////////////////////////////////////////
1161 Int_t iriv;
1162 for (iriv=0; iriv<idetot; iriv++) { //for on detectors
1163 ///////////////////////////////////////////////////////
1164 /*** Rec points sorted by module *****/
1165 /**************************************/
64ab0d55 1166 Int_t indexmod;
b48af428 1167 indexmod = g1->GetModuleIndex(lycur,(Int_t)toucLad(iriv),
64ab0d55 1168 (Int_t)toucDet(iriv));
b48af428 1169 fITS->ResetRecPoints();
1170 gAlice->TreeR()->GetEvent(indexmod);
1171 Int_t npoints=frecPoints->GetEntries();
64ab0d55 1172
b48af428 1173 Int_t indnew;
1174 for(indnew=0; indnew<npoints; indnew++){
1175 if (*(fvettid[indexmod]+indnew)==0)
1176 recp =(AliITSRecPoint*)frecPoints->UncheckedAt(indnew);
1177 else
f66ae545 1178 continue;
b48af428 1179 TVector cluster(3),vecclust(9);
64ab0d55 1180 //vecclust(6)=vecclust(7)=vecclust(8)=-1.;
1181 Double_t sigma[2];
1182 // now vecclust is with cylindrical cohordinates
1183 vecclust(0)=(Float_t)fRecCylR[indexmod][indnew];
1184 vecclust(1)=(Float_t)fRecCylPhi[indexmod][indnew];
1185 vecclust(2)=(Float_t)fRecCylZ[indexmod][indnew];
b48af428 1186 vecclust(3) = (Float_t)recp->fTracks[0];
b48af428 1187 vecclust(4) = (Float_t)indnew;
64ab0d55 1188 vecclust(5) = (Float_t)indexmod;
b48af428 1189 vecclust(6) = (Float_t)recp->fTracks[0];
1190 vecclust(7) = (Float_t)recp->fTracks[1];
1191 vecclust(8) = (Float_t)recp->fTracks[2];
1192 sigma[0] = (Double_t) recp->GetSigmaX2();
1193 sigma[1] = (Double_t) recp->GetSigmaZ2();
64ab0d55 1194
1195 cluster(0)=fRecCylR[indexmod][indnew];
1196 cluster(1)=fRecCylPhi[indexmod][indnew];
1197 cluster(2)=fRecCylZ[indexmod][indnew];
1198
b48af428 1199 // cout<<" layer = "<<play<<"\n";
1200 // cout<<" cluster prima = "<<vecclust(0)<<" "
1201 // <<vecclust(1)<<" "
1202 // <<vecclust(2)<<"\n"; getchar();
1203
1204 Float_t sigmatotphi, sigmatotz;
1205 // Float_t epsphi=5.0, epsz=5.0;
1206 //if(fPtref<0.2) {epsphi=3.; epsz=3.;}
1207 Double_t rTrack=(*trackITS).Getrtrack();
1208 Double_t sigmaphi=sigma[0]/(rTrack*rTrack);
1209 sigmatotphi=epsphi*TMath::Sqrt(sigmaphi +
1210 (*trackITS).GetSigmaphi());
1211 sigmatotz=epsz*TMath::Sqrt(sigma[1] +
1212 (*trackITS).GetSigmaZ());
1213 //cout<<"cluster e sigmatotphi e track = "<<cluster(0)
1214 // <<" "<<cluster(1)<<" "<<sigmatotphi<<" "
1215 // <<vecclust(3)<<"\n";
1216 //if(vecclust(3)==481) getchar();
1217 if(cluster(1)<6. && (*trackITS).Getphi()>6.)
1218 cluster(1)=cluster(1)+(2.*TMath::Pi());
1219 if(cluster(1)>6. && (*trackITS).Getphi()<6.)
1220 cluster(1)=cluster(1)-(2.*TMath::Pi());
1221 if(TMath::Abs(cluster(1)-(*trackITS).Getphi())>sigmatotphi)
1222 continue;
1223 // cout<<" supero sigmaphi \n";
1224 AliITSTrackV1 *newTrack = new AliITSTrackV1((*trackITS));
def162f4 1225 //(*newTrack).SetLayer((*trackITS).GetLayer()-1);
b48af428 1226 if (TMath::Abs(rTrack-cluster(0))/rTrack>1e-6)
1227 (*newTrack).Correct(Double_t(cluster(0)));
1228 //cout<<" cluster(2) e(*newTrack).GetZ()="<<cluster(2)<<" "
1229 // << (*newTrack).GetZ()<<"\n";
1230 if(TMath::Abs(cluster(2)-(*newTrack).GetZ()) > sigmatotz){
1231 delete newTrack;
1232 continue;
1233 } // end if
1234 Double_t sigmanew[2];
1235 sigmanew[0]= sigmaphi;
1236 sigmanew[1]=sigma[1];
1237 Double_t m[2];
1238 m[0]=cluster(1);
1239 m[1]=cluster(2);
1240 // Double_t chi2pred=newTrack->GetPredChi2(m,sigmanew);
1241 // cout<<" chi2pred = "<<chi2pred<<"\n";
1242 // if(chi2pred>fChi2max) continue; //aggiunto il 30-7-2001
1243 if(iriv == 0) flaghit=1;
1244 (*newTrack).AddMS(frl); // add the multiple scattering
1245 //matrix to the covariance matrix
1246 (*newTrack).AddEL(frl,1.,0);
1247
b48af428 1248 if(fflagvert){
1249 KalmanFilterVert(newTrack,cluster,sigmanew);
1250 //KalmanFilterVert(newTrack,cluster,sigmanew,chi2pred);
1251 }else{
1252 KalmanFilter(newTrack,cluster,sigmanew);
1253 } // end if
b48af428 1254 (*newTrack).PutCluster(layernew, vecclust);
1255 newTrack->AddClustInTrack();
1256 listoftrack.AddLast(newTrack);
1257 } // end for indnew
b48af428 1258 } // end of for on detectors (iriv)
1259 }//end if(outinters==0)
1260
1261 if(flaghit==0 || outinters==-2) {
1262 AliITSTrackV1 *newTrack = new AliITSTrackV1(*trackITS);
1263 (*newTrack).Setfnoclust();
def162f4 1264 //(*newTrack).SetLayer((*trackITS).GetLayer()-1);
b48af428 1265 (*newTrack).AddMS(frl); // add the multiple scattering matrix
1266 // to the covariance matrix
1267 (*newTrack).AddEL(frl,1.,0);
1268 listoftrack.AddLast(newTrack);
1269 } // end if
1270
1271 //gObjectTable->Print(); // stampa memoria
04b80329 1272
b48af428 1273 RecursiveTracking(&listoftrack);
1274 listoftrack.Delete();
1275 } // end of for on tracks (index)
04b80329 1276
b48af428 1277 //gObjectTable->Print(); // stampa memoria
13888096 1278}
b48af428 1279//______________________________________________________________________
1280Int_t AliITSTrackerV1::Intersection(AliITSTrackV1 &track,Int_t layer,
1281 Int_t &ladder,Int_t &detector) {
1282 // Origin A. Badala' and G.S. Pappalardo
1283 // e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it
1284 // Found the intersection and the detector
1285
1286 Double_t rk=fAvrad[layer-1];
1287 if(track.DoNotCross(rk)){ /*cout<< " Do not cross \n";*/ return -1;}
1288 track.Propagation(rk);
1289 Double_t zinters=track.GetZ();
1290 Double_t phinters=track.Getphi();
1291 //cout<<"zinters = "<<zinters<<" phinters = "<<phinters<<"\n";
1292
1293 TVector det(9);
1294 TVector listDet(2);
1295 TVector distZCenter(2);
1296
1297 Int_t iz=0;
1298 Int_t iD;
1299 for(iD = 1; iD<= fNdet[layer-1]; iD++) {
1300 if(zinters > fzmin[layer-1][iD-1] && zinters <= fzmax[layer-1][iD-1]) {
1301 if(iz>1) {
1302 cout<< " Errore su iz in Intersection \n";
1303 getchar();
1304 }else {
1305 listDet(iz)= iD; distZCenter(iz)=TMath::Abs(zinters-det(2));
1306 iz++;
1307 } // end if
1308 } // end if
1309 } // end for iD
1310
1311 if(iz==0) {/* cout<< " No detector along Z \n";*/ return -2;}
1312 detector=Int_t (listDet(0));
1313 if(iz>1 && (distZCenter(0)>distZCenter(1))) detector=Int_t (listDet(1));
1314
1315 TVector listLad(2);
1316 TVector distPhiCenter(2);
1317 Int_t ip=0;
1318 Double_t pigre=TMath::Pi();
1319 Int_t iLd;
1320 for(iLd = 1; iLd<= fNlad[layer-1]; iLd++) {
1321 Double_t phimin=fphimin[layer-1][iLd-1];
1322 Double_t phimax=fphimax[layer-1][iLd-1];
1323 Double_t phidet=fphidet[layer-1][iLd-1];
1324 Double_t phiconfr=phinters;
1325 if(phimin>phimax) {
1326 //if(phimin <5.5) {cout<<" Error in Intersection for phi \n";
1327 // getchar();}
1328 phimin-=(2.*pigre);
1329 if(phinters>(1.5*pigre)) phiconfr=phinters-(2.*pigre);
1330 if(phidet>(1.5*pigre)) phidet-=(2.*pigre);
1331 } // end if
1332 if(phiconfr>phimin && phiconfr<= phimax) {
1333 if(ip>1) {
1334 cout<< " Errore su ip in Intersection \n"; getchar();
1335 }else {
1336 listLad(ip)= iLd;
1337 distPhiCenter(ip)=TMath::Abs(phiconfr-phidet); ip++;
1338 } // end if
1339 } // end if
1340 } // end for iLd
1341 if(ip==0) { cout<< " No detector along phi \n"; getchar();}
1342 ladder=Int_t (listLad(0));
1343 if(ip>1 && (distPhiCenter(0)>distPhiCenter(1))) ladder=Int_t (listLad(1));
1344 return 0;
1345}
1346//______________________________________________________________________
1347void AliITSTrackerV1::KalmanFilter(AliITSTrackV1 *newTrack,TVector &cluster,
1348 Double_t sigma[2]){
1349 //Origin A. Badala' and G.S. Pappalardo:
1350 // e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it
1351 // Kalman filter without vertex constraint
1352 ////// Evaluation of the measurement vector ////////////////////////
1353 Double_t m[2];
1354 Double_t rk,phik,zk;
1355 rk=cluster(0); phik=cluster(1); zk=cluster(2);
1356 m[0]=phik; m[1]=zk;
1357 //////////////////////// Evaluation of the error matrix V /////////
1358 Double_t v00=sigma[0];
1359 Double_t v11=sigma[1];
1360 ////////////////////////////////////////////////////////////////////
1361 Double_t cin00,cin10,cin20,cin30,cin40,cin11,cin21,cin31,cin41,cin22,
1362 cin32,cin42,cin33,cin43,cin44;
1363
1364 newTrack->GetCElements(cin00,
1365 cin10,cin11,
1366 cin20,cin21,cin22,
1367 cin30,cin31,cin32,cin33,
1368 cin40,cin41,cin42,cin43,cin44); //get C matrix
1369 Double_t rold00=cin00+v00;
1370 Double_t rold10=cin10;
1371 Double_t rold11=cin11+v11;
1372 ////////////////////// R matrix inversion /////////////////////////
1373 Double_t det=rold00*rold11-rold10*rold10;
1374 Double_t r00=rold11/det;
1375 Double_t r10=-rold10/det;
1376 Double_t r11=rold00/det;
1377 ////////////////////////////////////////////////////////////////////
1378 Double_t k00=cin00*r00+cin10*r10;
1379 Double_t k01=cin00*r10+cin10*r11;
1380 Double_t k10=cin10*r00+cin11*r10;
1381 Double_t k11=cin10*r10+cin11*r11;
1382 Double_t k20=cin20*r00+cin21*r10;
1383 Double_t k21=cin20*r10+cin21*r11;
1384 Double_t k30=cin30*r00+cin31*r10;
1385 Double_t k31=cin30*r10+cin31*r11;
1386 Double_t k40=cin40*r00+cin41*r10;
1387 Double_t k41=cin40*r10+cin41*r11;
1388 Double_t x0,x1,x2,x3,x4;
1389 newTrack->GetXElements(x0,x1,x2,x3,x4); // get the state vector
1390 Double_t savex0=x0, savex1=x1;
1391 x0+=k00*(m[0]-savex0)+k01*(m[1]-savex1);
1392 x1+=k10*(m[0]-savex0)+k11*(m[1]-savex1);
1393 x2+=k20*(m[0]-savex0)+k21*(m[1]-savex1);
1394 x3+=k30*(m[0]-savex0)+k31*(m[1]-savex1);
1395 x4+=k40*(m[0]-savex0)+k41*(m[1]-savex1);
1396 Double_t c00,c10,c20,c30,c40,c11,c21,c31,c41,c22,c32,c42,c33,c43,c44;
1397 c00=cin00-k00*cin00-k01*cin10;
1398 c10=cin10-k00*cin10-k01*cin11;
1399 c20=cin20-k00*cin20-k01*cin21;
1400 c30=cin30-k00*cin30-k01*cin31;
1401 c40=cin40-k00*cin40-k01*cin41;
1402 c11=cin11-k10*cin10-k11*cin11;
1403 c21=cin21-k10*cin20-k11*cin21;
1404 c31=cin31-k10*cin30-k11*cin31;
1405 c41=cin41-k10*cin40-k11*cin41;
1406 c22=cin22-k20*cin20-k21*cin21;
1407 c32=cin32-k20*cin30-k21*cin31;
1408 c42=cin42-k20*cin40-k21*cin41;
1409 c33=cin33-k30*cin30-k31*cin31;
1410 c43=cin43-k30*cin40-k31*cin41;
1411 c44=cin44-k40*cin40-k41*cin41;
1412 newTrack->PutXElements(x0,x1,x2,x3,x4); // put the new state vector
1413 newTrack->PutCElements(c00,
1414 c10,c11,
1415 c20,c21,c22,
1416 c30,c31,c32,c33,
1417 c40,c41,c42,c43,c44); // put in track the
1418 // new cov matrix
1419 Double_t vmcold00=v00-c00;
1420 Double_t vmcold10=-c10;
1421 Double_t vmcold11=v11-c11;
1422 ////////////////////// Matrix vmc inversion ///////////////////////
1423 det=vmcold00*vmcold11-vmcold10*vmcold10;
1424 Double_t vmc00=vmcold11/det;
1425 Double_t vmc10=-vmcold10/det;
1426 Double_t vmc11=vmcold00/det;
1427 ////////////////////////////////////////////////////////////////////
1428 Double_t chi2=(m[0]-x0)*( vmc00*(m[0]-x0) + 2.*vmc10*(m[1]-x1) ) +
1429 (m[1]-x1)*vmc11*(m[1]-x1);
04b80329 1430 newTrack->SetChi2(newTrack->GetChi2()+chi2);
b48af428 1431}
1432//----------------------------------------------------------------------
1433//void AliITSTrackerV1::KalmanFilterVert(AliITSTrackV1 *newTrack,
1434// TVector &cluster,Double_t sigma[2]){
1435void AliITSTrackerV1::KalmanFilterVert(AliITSTrackV1 *newTrack,
1436 TVector &cluster,Double_t sigma[2]
1437 /*, Double_t chi2pred*/){
1438 //Origin A. Badala' and G.S. Pappalardo:
1439 // e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it
1440 // Kalman filter with vertex constraint
1441 ///////////////////// Evaluation of the measurement vector m ////////
1442 Double_t m[4];
1443 Double_t rk,phik,zk;
1444 rk=cluster(0); phik=cluster(1); zk=cluster(2);
1445 m[0]=phik; m[1]=zk;
1446 Double_t cc=(*newTrack).GetC();
1447 Double_t zv=(*newTrack).GetZv();
1448 Double_t dv=(*newTrack).GetDv();
1449 Double_t cy=cc/2.;
1450 Double_t tgl= (zk-zv)*cy/TMath::ASin(cy*rk);
1451 m[2]=dv; m[3]=tgl;
1452 /////////////////////// Evaluation of the error matrix V //////////
1453 Int_t layer=newTrack->GetLayer();
1454 Double_t v00=sigma[0];
1455 Double_t v11=sigma[1];
1456 Double_t v31=sigma[1]/rk;
1457 Double_t sigmaDv=newTrack->GetsigmaDv();
1458 Double_t v22=sigmaDv*sigmaDv + newTrack->Getd2(layer-1);
1459 Double_t v32=newTrack->Getdtgl(layer-1);
1460 Double_t sigmaZv=newTrack->GetsigmaZv();
1461 Double_t v33=(sigma[1]+sigmaZv*sigmaZv)/(rk*rk)+newTrack->Gettgl2(layer-1);
1462 //////////////////////////////////////////////////////////////////
1463 Double_t cin00,cin10,cin11,cin20,cin21,cin22,
1464 cin30,cin31,cin32,cin33,cin40,cin41,cin42,cin43,cin44;
1465 newTrack->GetCElements(cin00,
1466 cin10,cin11,
1467 cin20,cin21,cin22,
1468 cin30,cin31,cin32,cin33,
1469 cin40,cin41,cin42,cin43,cin44); //get C matrix
1470 Double_t r[4][4];
1471 r[0][0]=cin00+v00;
1472 r[1][0]=cin10;
1473 r[2][0]=cin20;
1474 r[3][0]=cin30;
1475 r[1][1]=cin11+v11;
1476 r[2][1]=cin21;
1477 r[3][1]=cin31+sigma[1]/rk;
1478 r[2][2]=cin22+sigmaDv*sigmaDv+newTrack->Getd2(layer-1);
1479 r[3][2]=cin32+newTrack->Getdtgl(layer-1);
1480 r[3][3]=cin33+(sigma[1]+sigmaZv*sigmaZv)/(rk*rk)+
1481 newTrack->Gettgl2(layer-1);
1482 r[0][1]=r[1][0]; r[0][2]=r[2][0]; r[0][3]=r[3][0];
1483 r[1][2]=r[2][1]; r[1][3]=r[3][1]; r[2][3]=r[3][2];
1484 ///////////////////// Matrix R inversion //////////////////////////
1485 const Int_t kn=4;
1486 Double_t big, hold;
1487 Double_t d=1.;
1488 Int_t ll[kn],mm[kn];
1489 Int_t i,j,k;
1490
1491 for(k=0; k<kn; k++) {
1492 ll[k]=k;
1493 mm[k]=k;
1494 big=r[k][k];
1495 for(j=k; j<kn ; j++) {
1496 for (i=j; i<kn; i++) {
1497 if(TMath::Abs(big) < TMath::Abs(r[i][j]) ) {
1498 big=r[i][j];
1499 ll[k]=i;
1500 mm[k]=j;
1501 } // end if
1502 } // end for i
1503 } // end for j
1504 //
1505 j= ll[k];
1506 if(j > k) {
1507 for(i=0; i<kn; i++) {
1508 hold=-r[k][i];
1509 r[k][i]=r[j][i];
1510 r[j][i]=hold;
1511 } // end for i
1512 }// end if
1513 //
1514 i=mm[k];
1515 if(i > k ) {
1516 for(j=0; j<kn; j++) {
1517 hold=-r[j][k];
1518 r[j][k]=r[j][i];
1519 r[j][i]=hold;
1520 } // end for j
1521 } // end if
1522 //
1523 if(!big) {
1524 d=0.;
1525 cout << "Singular matrix\n";
1526 } // end if
1527 for(i=0; i<kn; i++) {
1528 if(i == k) { continue; }
1529 r[i][k]=r[i][k]/(-big);
1530 } // end for i
1531 //
1532 for(i=0; i<kn; i++) {
1533 hold=r[i][k];
1534 for(j=0; j<kn; j++) {
1535 if(i == k || j == k) continue;
1536 r[i][j]=hold*r[k][j]+r[i][j];
1537 } // end for j
1538 } // end of ri
1539 //
1540 for(j=0; j<kn; j++) {
1541 if(j == k) continue;
1542 r[k][j]=r[k][j]/big;
1543 } // end for j
1544 //
1545 d=d*big;
1546 //
1547 r[k][k]=1./big;
1548 } // end for k
1549 //
1550 for(k=kn-1; k>=0; k--) {
1551 i=ll[k];
1552 if(i > k) {
1553 for (j=0; j<kn; j++) {
1554 hold=r[j][k];
1555 r[j][k]=-r[j][i];
1556 r[j][i]=hold;
1557 } // end for j
1558 } // end if i
1559 j=mm[k];
1560 if(j > k) {
1561 for (i=0; i<kn; i++) {
1562 hold=r[k][i];
1563 r[k][i]=-r[j][i];
1564 r[j][i]=hold;
1565 } // end for i
1566 } // end if
1567 } // end for k
1568 ////////////////////////////////////////////////////////////////////
1569 Double_t k00=cin00*r[0][0]+cin10*r[1][0]+cin20*r[2][0]+cin30*r[3][0];
1570 Double_t k01=cin00*r[1][0]+cin10*r[1][1]+cin20*r[2][1]+cin30*r[3][1];
1571 Double_t k02=cin00*r[2][0]+cin10*r[2][1]+cin20*r[2][2]+cin30*r[3][2];
1572 Double_t k03=cin00*r[3][0]+cin10*r[3][1]+cin20*r[3][2]+cin30*r[3][3];
1573 Double_t k10=cin10*r[0][0]+cin11*r[1][0]+cin21*r[2][0]+cin31*r[3][0];
1574 Double_t k11=cin10*r[1][0]+cin11*r[1][1]+cin21*r[2][1]+cin31*r[3][1];
1575 Double_t k12=cin10*r[2][0]+cin11*r[2][1]+cin21*r[2][2]+cin31*r[3][2];
1576 Double_t k13=cin10*r[3][0]+cin11*r[3][1]+cin21*r[3][2]+cin31*r[3][3];
1577 Double_t k20=cin20*r[0][0]+cin21*r[1][0]+cin22*r[2][0]+cin32*r[3][0];
1578 Double_t k21=cin20*r[1][0]+cin21*r[1][1]+cin22*r[2][1]+cin32*r[3][1];
1579 Double_t k22=cin20*r[2][0]+cin21*r[2][1]+cin22*r[2][2]+cin32*r[3][2];
1580 Double_t k23=cin20*r[3][0]+cin21*r[3][1]+cin22*r[3][2]+cin32*r[3][3];
1581 Double_t k30=cin30*r[0][0]+cin31*r[1][0]+cin32*r[2][0]+cin33*r[3][0];
1582 Double_t k31=cin30*r[1][0]+cin31*r[1][1]+cin32*r[2][1]+cin33*r[3][1];
1583 Double_t k32=cin30*r[2][0]+cin31*r[2][1]+cin32*r[2][2]+cin33*r[3][2];
1584 Double_t k33=cin30*r[3][0]+cin31*r[3][1]+cin32*r[3][2]+cin33*r[3][3];
1585 Double_t k40=cin40*r[0][0]+cin41*r[1][0]+cin42*r[2][0]+cin43*r[3][0];
1586 Double_t k41=cin40*r[1][0]+cin41*r[1][1]+cin42*r[2][1]+cin43*r[3][1];
1587 Double_t k42=cin40*r[2][0]+cin41*r[2][1]+cin42*r[2][2]+cin43*r[3][2];
1588 Double_t k43=cin40*r[3][0]+cin41*r[3][1]+cin42*r[3][2]+cin43*r[3][3];
1589
1590 Double_t x0,x1,x2,x3,x4;
1591 newTrack->GetXElements(x0,x1,x2,x3,x4); // get the state vector
1592 Double_t savex0=x0, savex1=x1, savex2=x2, savex3=x3;
1593 x0+=k00*(m[0]-savex0)+k01*(m[1]-savex1)+k02*(m[2]-savex2)+
1594 k03*(m[3]-savex3);
1595 x1+=k10*(m[0]-savex0)+k11*(m[1]-savex1)+k12*(m[2]-savex2)+
1596 k13*(m[3]-savex3);
1597 x2+=k20*(m[0]-savex0)+k21*(m[1]-savex1)+k22*(m[2]-savex2)+
1598 k23*(m[3]-savex3);
1599 x3+=k30*(m[0]-savex0)+k31*(m[1]-savex1)+k32*(m[2]-savex2)+
1600 k33*(m[3]-savex3);
1601 x4+=k40*(m[0]-savex0)+k41*(m[1]-savex1)+k42*(m[2]-savex2)+
1602 k43*(m[3]-savex3);
1603 Double_t c00,c10,c20,c30,c40,c11,c21,c31,c41,c22,c32,c42,c33,c43,c44;
1604 c00=cin00-k00*cin00-k01*cin10-k02*cin20-k03*cin30;
1605 c10=cin10-k00*cin10-k01*cin11-k02*cin21-k03*cin31;
1606 c20=cin20-k00*cin20-k01*cin21-k02*cin22-k03*cin32;
1607 c30=cin30-k00*cin30-k01*cin31-k02*cin32-k03*cin33;
1608 c40=cin40-k00*cin40-k01*cin41-k02*cin42-k03*cin43;
1609 c11=cin11-k10*cin10-k11*cin11-k12*cin21-k13*cin31;
1610 c21=cin21-k10*cin20-k11*cin21-k12*cin22-k13*cin32;
1611 c31=cin31-k10*cin30-k11*cin31-k12*cin32-k13*cin33;
1612 c41=cin41-k10*cin40-k11*cin41-k12*cin42-k13*cin43;
1613 c22=cin22-k20*cin20-k21*cin21-k22*cin22-k23*cin32;
1614 c32=cin32-k20*cin30-k21*cin31-k22*cin32-k23*cin33;
1615 c42=cin42-k20*cin40-k21*cin41-k22*cin42-k23*cin43;
1616 c33=cin33-k30*cin30-k31*cin31-k32*cin32-k33*cin33;
1617 c43=cin43-k30*cin40-k31*cin41-k32*cin42-k33*cin43;
1618 c44=cin44-k40*cin40-k41*cin41-k42*cin42-k43*cin43;
1619
1620 newTrack->PutXElements(x0,x1,x2,x3,x4); // put the new state vector
1621 newTrack->PutCElements(c00,
1622 c10,c11,
1623 c20,c21,c22,
1624 c30,c31,c32,c33,
1625 c40,c41,c42,c43,c44); // put in track the
1626 // new cov matrix
1627 Double_t vmc[4][4];
1628 vmc[0][0]=v00-c00; vmc[1][0]=-c10; vmc[2][0]=-c20; vmc[3][0]=-c30;
1629 vmc[1][1]=v11-c11; vmc[2][1]=-c21; vmc[3][1]=v31-c31;
1630 vmc[2][2]=v22-c22; vmc[3][2]=v32-c32;
1631 vmc[3][3]=v33-c33;
1632 vmc[0][1]=vmc[1][0]; vmc[0][2]=vmc[2][0]; vmc[0][3]=vmc[3][0];
1633 vmc[1][2]=vmc[2][1]; vmc[1][3]=vmc[3][1];
1634 vmc[2][3]=vmc[3][2];
1635 /////////////////////// vmc matrix inversion ///////////////////////
1636 d=1.;
1637 for(k=0; k<kn; k++) {
1638 ll[k]=k;
1639 mm[k]=k;
1640 big=vmc[k][k];
1641 for(j=k; j<kn ; j++) {
1642 for (i=j; i<kn; i++) {
1643 if(TMath::Abs(big) < TMath::Abs(vmc[i][j]) ) {
1644 big=vmc[i][j];
1645 ll[k]=i;
1646 mm[k]=j;
1647 } // end if
1648 } // end for i
1649 } // end for j
1650 //
1651 j= ll[k];
1652 if(j > k) {
1653 for(i=0; i<kn; i++) {
1654 hold=-vmc[k][i];
1655 vmc[k][i]=vmc[j][i];
1656 vmc[j][i]=hold;
1657 } // end for i
1658 } // end if
1659 //
1660 i=mm[k];
1661 if(i > k ) {
1662 for(j=0; j<kn; j++) {
1663 hold=-vmc[j][k];
1664 vmc[j][k]=vmc[j][i];
1665 vmc[j][i]=hold;
1666 } // end for j
1667 } // end if
1668 //
1669 if(!big) {
1670 d=0.;
1671 cout << "Singular matrix\n";
1672 } // end if
1673 for(i=0; i<kn; i++) {
1674 if(i == k) continue;
1675 vmc[i][k]=vmc[i][k]/(-big);
1676 } // end for i
1677 //
1678 for(i=0; i<kn; i++) {
1679 hold=vmc[i][k];
1680 for(j=0; j<kn; j++) {
1681 if(i == k || j == k) continue;
1682 vmc[i][j]=hold*vmc[k][j]+vmc[i][j];
1683 } // end for j
1684 } // end for i
1685 //
1686 for(j=0; j<kn; j++) {
1687 if(j == k) continue;
1688 vmc[k][j]=vmc[k][j]/big;
1689 } // end for j
1690 //
1691 d=d*big;
1692 //
1693 vmc[k][k]=1./big;
1694 } // end for k
1695 //
1696 for(k=kn-1; k>=0; k--) {
1697 i=ll[k];
1698 if(i > k) {
1699 for (j=0; j<kn; j++) {
1700 hold=vmc[j][k];
1701 vmc[j][k]=-vmc[j][i];
1702 vmc[j][i]=hold;
1703 } // end for j
1704 } // end if i>k
1705 j=mm[k];
1706 if(j > k) {
1707 for (i=0; i<kn; i++) {
1708 hold=vmc[k][i];
1709 vmc[k][i]=-vmc[j][i];
1710 vmc[j][i]=hold;
1711 } // end for i
1712 } // end if j>k
1713 } // end for k
1714 ////////////////////////////////////////////////////////////////////
1715 Double_t chi2=(m[0]-x0)*( vmc[0][0]*(m[0]-x0) + 2.*vmc[1][0]*(m[1]-x1) +
1716 2.*vmc[2][0]*(m[2]-x2)+ 2.*vmc[3][0]*(m[3]-x3) )+
1717 (m[1]-x1)* ( vmc[1][1]*(m[1]-x1) + 2.*vmc[2][1]*(m[2]-x2)+
1718 2.*vmc[3][1]*(m[3]-x3) ) +
1719 (m[2]-x2)* ( vmc[2][2]*(m[2]-x2)+ 2.*vmc[3][2]*(m[3]-x3) ) +
1720 (m[3]-x3)*vmc[3][3]*(m[3]-x3);
1721 //cout<<" chi2 kalman = "<<chi2<<"\n"; getchar();
1722 newTrack->SetChi2(newTrack->GetChi2()+chi2);
1723 // newTrack->SetChi2(newTrack->GetChi2()+chi2pred);
1724}