3 // Author: Anders Vestbo <mailto:vestbo$fi.uib.no>
4 //*-- Copyright © ALICE HLT Group
6 #include "AliL3StandardIncludes.h"
8 #include "AliL3Logging.h"
9 #include "AliL3ModelTrack.h"
10 #include "AliL3Transform.h"
11 #include "AliL3DataCompressor.h"
17 //_____________________________________________________________
22 ClassImp(AliL3ModelTrack)
24 AliL3ModelTrack::AliL3ModelTrack()
40 AliL3ModelTrack::~AliL3ModelTrack()
49 delete [] fCrossingAngle;
51 delete [] fParSigmaY2;
53 delete [] fParSigmaZ2;
60 for(Int_t i=0; i<AliL3Transform::GetNRows(fPatch); i++)
61 delete [] fOverlap[i];
66 void AliL3ModelTrack::Init(Int_t slice,Int_t patch)
68 fNClusters=AliL3Transform::GetNRows(patch);//is not incremented in setcluster anymore
71 Int_t nrows = AliL3Transform::GetNRows(fPatch);
72 fClusters = new AliL3ClusterModel[nrows];
73 fPad = new Float_t[nrows];
74 fTime = new Float_t[nrows];
75 fCrossingAngle = new Float_t[nrows];
76 fParSigmaY2 = new Float_t[nrows];
77 fParSigmaZ2 = new Float_t[nrows];
78 fTrackModel = new AliL3TrackModel;
80 fOverlap = new Int_t*[nrows];
81 fNoverlaps = new Int_t[nrows];
84 memset(fNoverlaps,0,nrows*sizeof(Int_t));
85 memset(fClusters,0,nrows*sizeof(AliL3ClusterModel));
86 memset(fPad,0,nrows*sizeof(Float_t));
87 memset(fTime,0,nrows*sizeof(Float_t));
88 memset(fCrossingAngle,0,nrows*sizeof(Float_t));
89 memset(fParSigmaY2,0,nrows*sizeof(Float_t));
90 memset(fParSigmaZ2,0,nrows*sizeof(Float_t));
91 memset(fTrackModel,0,sizeof(AliL3TrackModel));
92 for(Int_t i=0; i<nrows; i++)
94 fOverlap[i] = new Int_t[fMaxOverlaps];
95 for(Int_t j=0; j<fMaxOverlaps; j++)
97 fClusters[i].fSlice = -1;
102 void AliL3ModelTrack::CalculateClusterWidths(Int_t row,Bool_t parametrize)
108 Int_t index = row - AliL3Transform::GetFirstRow(fPatch);
109 if(index < 0 || index > AliL3Transform::GetNRows(fPatch))
111 cerr<<"AliL3ModelTrack::CalculcateClusterWidths : Wrond index "<<index<<" row "<<row<<endl;
114 Int_t patch = AliL3Transform::GetPatch(row);
115 AliL3Transform::Slice2Sector(0,row,sr,lr);
116 AliL3Transform::Raw2Local(xyz,sr,lr,GetPadHit(row),GetTimeHit(row));
117 fParSigmaY2[index] = AliL3Transform::GetParSigmaY2(row,xyz[2],GetCrossingAngleLUT(row));
118 fParSigmaZ2[index] = AliL3Transform::GetParSigmaZ2(row,xyz[2],GetTgl());
122 fParSigmaY2[index] = (fParSigmaY2[index] + (1./12)*pow(AliL3Transform::GetPadPitchWidth(patch),2) );
123 fParSigmaY2[index] *= 0.108;
125 fParSigmaY2[index] *= 2.07;
127 fParSigmaZ2[index] = (fParSigmaZ2[index] + (1./12)*pow(AliL3Transform::GetZWidth(),2) );
128 fParSigmaZ2[index] *= 0.169;
130 fParSigmaZ2[index] *= 1.77;
133 //convert to raw coordinates:
134 fParSigmaY2[index] /= pow(AliL3Transform::GetPadPitchWidth(patch),2);
135 fParSigmaZ2[index] /= pow(AliL3Transform::GetZWidth(),2);
138 void AliL3ModelTrack::SetCluster(Int_t row,Float_t fpad,Float_t ftime,Float_t charge,
139 Float_t sigmaY2,Float_t sigmaZ2,Int_t npads)
141 AliL3ClusterModel *cl = GetClusterModel(row);
143 //First bit: Cluster is present or not
144 //Second bit: Cluster was set, meaning an fit attempt was done (if true)
146 cl->fPresent |= 0x2; //set second bit to true, because a fit attempt has been made
148 Int_t patch = AliL3Transform::GetPatch(row);
149 if(!charge || npads == 1)
151 cl->fPresent &= ~0x1; //set first bit to false
155 cl->fPresent|=0x1;//set first bit to true
156 cl->fDTime = (ftime - GetTimeHit(row))/(AliL3DataCompressor::GetZResidualStep(row)/AliL3Transform::GetZWidth());
157 cl->fDPad = (fpad - GetPadHit(row))/(AliL3DataCompressor::GetXYResidualStep(row)/AliL3Transform::GetPadPitchWidth(patch));
158 cl->fDCharge = charge;// - AliL3DataCompressor::GetClusterCharge();
159 //cl->fSlice = fSlice;
160 if(sigmaY2==0 && sigmaZ2==0)
162 cl->fDSigmaY2=0;//if width is zero, shape is not supposed to be written
167 cl->fDSigmaY2 = (sigmaY2 - GetParSigmaY2(row))/(AliL3DataCompressor::GetXYWidthStep()/pow(AliL3Transform::GetPadPitchWidth(patch),2));
168 cl->fDSigmaZ2 = (sigmaZ2 - GetParSigmaZ2(row))/(AliL3DataCompressor::GetZWidthStep()/pow(AliL3Transform::GetZWidth(),2));
176 void AliL3ModelTrack::Set(AliL3Track *tpt)
178 AliL3ModelTrack *tr = (AliL3ModelTrack*)tpt;
179 SetRowRange(tr->GetFirstRow(),tr->GetLastRow());
180 SetPhi0(tr->GetPhi0());
181 SetKappa(tr->GetKappa());
182 SetFirstPoint(tr->GetFirstPointX(),tr->GetFirstPointY(),tr->GetFirstPointZ());
183 SetLastPoint(tr->GetLastPointX(),tr->GetLastPointY(),tr->GetLastPointZ());
185 SetPsi(tr->GetPsi());
186 SetTgl(tr->GetTgl());
187 SetCharge(tr->GetCharge());
191 cerr<<"AliL3ModelTrack::Set : Init has already been called for this object!"<<endl;
195 //Init(tr->fSlice,tr->fPatch);
197 memcpy(fClusters,tr->fClusters,AliL3Transform::GetNRows(fPatch)*sizeof(AliL3ClusterModel));
198 memcpy(fPad,tr->fPad,AliL3Transform::GetNRows(fPatch)*sizeof(Float_t));
199 memcpy(fTime,tr->fTime,AliL3Transform::GetNRows(fPatch)*sizeof(Float_t));
200 memcpy(fParSigmaY2,tr->fParSigmaY2,AliL3Transform::GetNRows(fPatch)*sizeof(Float_t));
201 memcpy(fParSigmaZ2,tr->fParSigmaZ2,AliL3Transform::GetNRows(fPatch)*sizeof(Float_t));
202 memcpy(fCrossingAngle,tr->fCrossingAngle,AliL3Transform::GetNRows(fPatch)*sizeof(Float_t));
203 memcpy(fTrackModel,tr->fTrackModel,sizeof(AliL3TrackModel));
207 Int_t AliL3ModelTrack::GetNPresentClusters()
209 //Return the number of assigned clusters to the track.
210 //Differs from fNClusters, which should be equal to the
211 //number of padrows in the present patch.
215 for(Int_t i=AliL3Transform::GetFirstRow(fPatch); i<=AliL3Transform::GetLastRow(fPatch); i++)
222 void AliL3ModelTrack::FillModel()
224 //Fill the track structure
226 if(fNClusters != AliL3Transform::GetNRows(fPatch))
228 cout<<"AliL3ModelTrack::FillModel : fNClusters != nrows; beware, this could be caused by a bug!!!"<<endl;
229 fNClusters = AliL3Transform::GetNRows(fPatch);
234 cerr<<"AliL3ModelTrack::FillModel() : No trackmodel "<<endl;
237 fTrackModel->fKappa = GetKappa();
239 fTrackModel->fFirstPointX = GetFirstPointX();
240 fTrackModel->fFirstPointY = GetFirstPointY();
241 fTrackModel->fFirstPointZ = GetFirstPointZ();
242 fTrackModel->fTgl = GetTgl();
243 fTrackModel->fPsi = GetPsi();
244 //fTrackModel->fLength = (Short_t)GetLength();
245 //fTrackModel->fNClusters = fNClusters;
248 void AliL3ModelTrack::FillTrack()
250 //Fill the track parameters from the structure.
254 cerr<<"AliL3ModelTrack::FillTrack() : No data!!"<<endl;
257 SetKappa(fTrackModel->fKappa);
258 SetCharge((-1*(Int_t)copysign(1.,GetKappa())));
259 SetFirstPoint(fTrackModel->fFirstPointX,fTrackModel->fFirstPointY,fTrackModel->fFirstPointZ);
260 SetTgl(fTrackModel->fTgl);
261 SetPsi(fTrackModel->fPsi);
262 //SetLength(fTrackModel->fLength);
263 fNClusters = AliL3Transform::GetNRows(fPatch);//fTrackModel->fNClusters;
264 SetPt((AliL3Transform::GetBFact()*AliL3Transform::GetBField())/fabs(GetKappa()));
268 for(Int_t i=AliL3Transform::GetFirstRow(fPatch); i<=AliL3Transform::GetLastRow(fPatch); i++)
270 AliL3ClusterModel *cl = GetClusterModel(i);
279 if(cl->fSlice < 0 || cl->fSlice > 35)
281 cerr<<"AliL3ModelTrack::FillTrack : Slice out of range "<<cl->fSlice<<" on row "<<i<<endl;
287 AliL3Transform::Local2GlobalAngle(&angle,cl->fSlice);
288 if(!CalculateReferencePoint(angle,AliL3Transform::Row2X(i)))
292 cerr<<"AliL3ModelTrack::FillTrack : Track does not cross slice "<<cl->fSlice<<" row "<<i<<" Points "
293 <<GetPointX()<<" "<<GetPointY()<<" "<<GetPointZ()<<endl;
301 Float_t hit[3] = {GetPointX(),GetPointY(),GetPointZ()};
303 AliL3Transform::Slice2Sector(cl->fSlice,i,sector,row);
304 AliL3Transform::Global2Raw(hit,sector,row);
307 SetTimeHit(i,hit[2]);
309 Float_t crossingangle = GetCrossingAngle(i,cl->fSlice);
311 SetCrossingAngleLUT(i,crossingangle);
312 CalculateClusterWidths(i,kTRUE);
317 void AliL3ModelTrack::SetPadHit(Int_t row,Float_t pad)
319 Int_t index = row-AliL3Transform::GetFirstRow(fPatch);
320 if(index < 0 || index > AliL3Transform::GetNRows(fPatch))
322 cerr<<"AliL3ModelTrack::SetPadHit() : Wrong index: "<<index<<endl;
328 void AliL3ModelTrack::SetTimeHit(Int_t row,Float_t time)
330 Int_t index = row-AliL3Transform::GetFirstRow(fPatch);
331 if(index < 0 || index > AliL3Transform::GetNRows(fPatch))
333 cerr<<"AliL3ModelTrack::SetTimeHit() : Wrong index: "<<index<<endl;
339 void AliL3ModelTrack::SetCrossingAngleLUT(Int_t row,Float_t angle)
341 Int_t index = row-AliL3Transform::GetFirstRow(fPatch);
342 if(index < 0 || index > AliL3Transform::GetNRows(fPatch))
344 cerr<<"AliL3ModelTrack::SetCrossingAngle() : Wrong index: "<<index<<endl;
347 fCrossingAngle[index]=angle;
350 void AliL3ModelTrack::SetOverlap(Int_t row,Int_t id)
353 Int_t index = row-AliL3Transform::GetFirstRow(fPatch);
354 if(index < 0 || index > AliL3Transform::GetNRows(fPatch))
356 cerr<<"AliL3ModelTrack::SetOverlap() : Wrong index: "<<index<<endl;
359 if(fNoverlaps[index] >= fMaxOverlaps) return;
360 fOverlap[index][fNoverlaps[index]++] = id;
363 Bool_t AliL3ModelTrack::IsPresent(Int_t row)
365 AliL3ClusterModel *cl = GetClusterModel(row);
366 return (Bool_t)(cl->fPresent & 0x1);
369 Bool_t AliL3ModelTrack::IsSet(Int_t row)
371 AliL3ClusterModel *cl = GetClusterModel(row);
372 return (Bool_t)(cl->fPresent & 0x2);
375 Int_t AliL3ModelTrack::GetNPads(Int_t row)
377 AliL3ClusterModel *cl = GetClusterModel(row);
381 Bool_t AliL3ModelTrack::GetPad(Int_t row,Float_t &pad)
383 //(ftime - GetTimeHit(fNClusters))/AliL3DataCompressor::GetXYResidualStep();
384 //(fpad - GetPadHit(fNClusters))/AliL3DataCompressor::GetZResidualStep();
386 AliL3ClusterModel *cl = GetClusterModel(row);
387 Int_t patch = AliL3Transform::GetPatch(row);
388 pad = cl->fDPad*(AliL3DataCompressor::GetXYResidualStep(row)/AliL3Transform::GetPadPitchWidth(patch)) + GetPadHit(row);
390 return IsPresent(row);
393 Bool_t AliL3ModelTrack::GetTime(Int_t row,Float_t &time)
395 AliL3ClusterModel *cl = GetClusterModel(row);
396 time = cl->fDTime*(AliL3DataCompressor::GetZResidualStep(row)/AliL3Transform::GetZWidth()) + GetTimeHit(row);
398 return IsPresent(row);
401 Bool_t AliL3ModelTrack::GetClusterCharge(Int_t row,Int_t &charge)
403 AliL3ClusterModel *cl = GetClusterModel(row);
404 charge = (Int_t)cl->fDCharge;// + AliL3DataCompressor::GetClusterCharge();
406 return IsPresent(row);
409 Bool_t AliL3ModelTrack::GetXYWidth(Int_t row,Float_t &width)
411 //cl->fDSigmaY2 = (sigmaY2 - GetParSigmaY2(row))/AliL3DataCompressor::GetXYWidthStep();
412 AliL3ClusterModel *cl = GetClusterModel(row);
413 Int_t patch = AliL3Transform::GetPatch(row);
414 width = cl->fDSigmaY2*(AliL3DataCompressor::GetXYWidthStep()/pow(AliL3Transform::GetPadPitchWidth(patch),2)) + GetParSigmaY2(row);
416 return IsPresent(row);
419 Bool_t AliL3ModelTrack::GetZWidth(Int_t row,Float_t &width)
421 AliL3ClusterModel *cl = GetClusterModel(row);
422 width = cl->fDSigmaZ2*(AliL3DataCompressor::GetZWidthStep()/pow(AliL3Transform::GetZWidth(),2)) + GetParSigmaZ2(row);
424 return IsPresent(row);
427 Bool_t AliL3ModelTrack::GetPadResidual(Int_t row,Float_t &res)
429 AliL3ClusterModel *cl = GetClusterModel(row);
431 return IsPresent(row);
434 Bool_t AliL3ModelTrack::GetTimeResidual(Int_t row,Float_t &res)
436 AliL3ClusterModel *cl = GetClusterModel(row);
438 return IsPresent(row);
441 Bool_t AliL3ModelTrack::GetXYWidthResidual(Int_t row,Float_t &res)
443 AliL3ClusterModel *cl = GetClusterModel(row);
445 return IsPresent(row);
448 Bool_t AliL3ModelTrack::GetZWidthResidual(Int_t row,Float_t &res)
450 AliL3ClusterModel *cl = GetClusterModel(row);
452 return IsPresent(row);
455 Int_t AliL3ModelTrack::GetSlice(Int_t row)
457 AliL3ClusterModel *cl = GetClusterModel(row);
461 Float_t AliL3ModelTrack::GetPadHit(Int_t row)
463 Int_t index = row-AliL3Transform::GetFirstRow(fPatch);
464 if(index < 0 || index > AliL3Transform::GetNRows(fPatch))
466 cerr<<"AliL3ModelTrack::GetPadHit() : Wrong index: "<<index<<" row "<<row<<endl;
472 Float_t AliL3ModelTrack::GetTimeHit(Int_t row)
474 Int_t index = row-AliL3Transform::GetFirstRow(fPatch);
475 if(index < 0 || index > AliL3Transform::GetNRows(fPatch))
477 cerr<<"AliL3ModelTrack::GetTimeHit() : Wrong index: "<<index<<" row "<<row<<endl;
483 Float_t AliL3ModelTrack::GetCrossingAngleLUT(Int_t row)
485 Int_t index = row-AliL3Transform::GetFirstRow(fPatch);
486 if(index < 0 || index > AliL3Transform::GetNRows(fPatch))
488 cerr<<"AliL3ModelTrack::GetCrossingAngleLUT() : Wrong index: "<<index<<" row "<<row<<endl;
491 return fCrossingAngle[index];
494 Float_t AliL3ModelTrack::GetParSigmaY2(Int_t row)
496 Int_t index = row-AliL3Transform::GetFirstRow(fPatch);
497 if(index < 0 || index > AliL3Transform::GetNRows(fPatch))
499 cerr<<"AliL3ModelTrack::GetParSigmaY2() : Wrong index: "<<index<<" row "<<row<<endl;
502 return fParSigmaY2[index];
505 Float_t AliL3ModelTrack::GetParSigmaZ2(Int_t row)
507 Int_t index = row-AliL3Transform::GetFirstRow(fPatch);
508 if(index < 0 || index > AliL3Transform::GetNRows(fPatch))
510 cerr<<"AliL3ModelTrack::GetParSigmaZ2() : Wrong index: "<<index<<" row "<<row<<endl;
513 return fParSigmaZ2[index];
516 Int_t AliL3ModelTrack::GetNOverlaps(Int_t row)
518 Int_t index = row - AliL3Transform::GetFirstRow(fPatch);
519 if(index < 0 || index > AliL3Transform::GetNRows(fPatch))
521 cerr<<"AliL3ModelTrack::GetOverlap() : Wrong index: "<<index<<endl;
524 return fNoverlaps[index];
527 Int_t *AliL3ModelTrack::GetOverlaps(Int_t row)
529 Int_t index = row - AliL3Transform::GetFirstRow(fPatch);
530 if(index < 0 || index > AliL3Transform::GetNRows(fPatch))
532 cerr<<"AliL3ModelTrack::GetOverlap() : Wrong index: "<<index<<endl;
535 return fOverlap[index];
538 AliL3ClusterModel *AliL3ModelTrack::GetClusterModel(Int_t row)
540 if(!fClusters) return 0;
541 Int_t index = row-AliL3Transform::GetFirstRow(fPatch);
542 if(index < 0 || index > AliL3Transform::GetNRows(fPatch))
544 cerr<<"AliL3ModelTrack::GetClusterModel() : Wrong index: "<<index<<endl;
547 return &fClusters[index];
550 void AliL3ModelTrack::Print(Bool_t everything)
554 cout<<"First point "<<GetFirstPointX()<<" "<<GetFirstPointY()<<" "<<GetFirstPointZ()<<endl;
555 cout<<"Last point "<<GetLastPointX()<<" "<<GetLastPointY()<<" "<<GetLastPointZ()<<endl;
556 cout<<"Pt "<<GetPt()<<" kappa "<<GetKappa()<<" tgl "<<GetTgl()<<" psi "<<GetPsi()<<" charge "<<GetCharge()<<endl;
557 cout<<"Center "<<GetCenterX()<<" "<<GetCenterY()<<endl<<endl;
560 cout<<"NHits "<<GetNClusters()<<endl;
562 cout<<"Clusters:"<<endl;
563 Int_t origslice=-1,counter=0;
565 for(Int_t i=AliL3Transform::GetFirstRow(fPatch); i<=AliL3Transform::GetLastRow(fPatch); i++)
567 AliL3ClusterModel *cl = GetClusterModel(i);
570 cout<<i<<" Empty"<<" Slice "<<cl->fSlice<<" Padcrossing "<<GetPadHit(i)<<" Timecrossing "<<GetTimeHit(i)<<" ";
576 origslice=cl->fSlice;
577 else if(cl->fSlice != origslice)
578 cout<<"Change in slice "<<cl->fSlice<<" "<<origslice<<endl;
579 cout<<i<<" Slice "<<cl->fSlice<<" Dpad "<<cl->fDPad<<" Dtime "<<cl->fDTime<<" Dcharge "<<cl->fDCharge;
580 cout<<" sigmaY2 "<<GetParSigmaY2(i)<<" sigmaZ2 "<<GetParSigmaZ2(i);
581 cout<<" Pad "<<fpad<<" padhit "<<GetPadHit(i)<<" Time "<<ftime<<" timehit "<<GetTimeHit(i)<<" ";
582 cout<<"Number of pads "<<GetNPads(i)<<" Overlaps "<<GetNOverlaps(i);
589 void AliL3ModelTrack::SetClusterLabel(Int_t row,Int_t *trackID)
592 AliL3ClusterModel *cl = GetClusterModel(row);
593 cl->fTrackID[0] = trackID[0];
594 cl->fTrackID[1] = trackID[1];
595 cl->fTrackID[2] = trackID[2];
600 void AliL3ModelTrack::GetClusterLabel(Int_t row,Int_t *trackID)
603 AliL3ClusterModel *cl = GetClusterModel(row);
604 trackID[0] = cl->fTrackID[0];
605 trackID[1] = cl->fTrackID[1];
606 trackID[2] = cl->fTrackID[2];