]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/comp/AliL3Modeller.cxx
Changing name of libRAW into libRAWData
[u/mrichter/AliRoot.git] / HLT / comp / AliL3Modeller.cxx
1 // @(#) $Id$
2
3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright &copy ALICE HLT Group
5 //_____________________________________________________________
6 // AliL3Modeller
7 //
8 // Class for modeling TPC data.
9 // 
10 // This performs the cluster finding, based on track parameters.
11 // Basically it propagates the tracks to all padrows, and looks 
12 // for a corresponding cluster. For the moment only cog is calculated,
13 // and no deconvolution is done. 
14
15
16 #include "AliL3StandardIncludes.h"
17
18 #include "AliL3Logging.h"
19 #include "AliL3Modeller.h"
20 #include "AliL3MemHandler.h"
21 #include "AliL3TrackArray.h"
22 #include "AliL3ModelTrack.h"
23 #include "AliL3DigitData.h"
24 #include "AliL3Transform.h"
25 #include "AliL3SpacePointData.h"
26
27 #ifdef use_aliroot
28 #include "AliL3FileHandler.h"
29 #endif
30
31 #if __GNUC__ == 3
32 using namespace std;
33 #endif
34
35 ClassImp(AliL3Modeller)
36
37 AliL3Modeller::AliL3Modeller()
38 {
39   // default constructor
40   fMemHandler=0;
41   fTracks=0;
42   fRow=0;
43   fTrackThreshold=0;
44   SetOverlap();
45   SetTrackThreshold();
46   SetSearchRange();
47   SetMaxClusterRange(0,0);
48   fDebug=kFALSE;
49 }
50
51
52 AliL3Modeller::~AliL3Modeller()
53 {
54   // destructor
55   if(fMemHandler)
56     delete fMemHandler;
57   if(fTracks)
58     delete fTracks;
59   if(fRow)
60     delete [] fRow;
61 }
62
63 void AliL3Modeller::Init(Int_t slice,Int_t patch,Char_t *trackdata,Char_t *path,Bool_t houghtracks,Bool_t binary)
64 {
65   // Initialization
66   fSlice = slice;
67   fPatch = patch;
68   fHoughTracks=houghtracks;
69
70   sprintf(fPath,"%s",path);
71   
72   fTracks = new AliL3TrackArray("AliL3ModelTrack");
73   
74   Char_t fname[100];
75   AliL3MemHandler *file = new AliL3MemHandler();
76   if(!houghtracks)
77     sprintf(fname,"%s/tracks_tr_%d_0.raw",trackdata,fSlice); //output tracks from the tracker (no merging)
78   else 
79     sprintf(fname,"%s/tracks_ho_%d.raw",trackdata,fSlice);
80   //sprintf(fname,"%s/tracks_ho_%d_%d.raw",trackdata,fSlice,fPatch);
81   if(!file->SetBinaryInput(fname))
82     {
83       cerr<<"AliL3Modeller::Init : Error opening trackfile: "<<fname<<endl;
84       return;
85     }
86   file->Binary2TrackArray(fTracks);
87   file->CloseBinaryInput();
88   delete file;
89   
90   if(!houghtracks)
91     fTracks->QSort();
92   
93   for(Int_t i=0; i<fTracks->GetNTracks(); i++)
94     {
95       AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(i);
96       if(!track) continue;
97       track->Init(fSlice,fPatch);
98
99       //Only if the tracks has been merged across sector boundaries:
100       //if(!houghtracks)
101       //track->Rotate(fSlice,kTRUE); //!!!!!!!!!!!!!!!!!!!
102       
103       track->CalculateHelix();
104     }    
105   
106   Int_t ntimes = AliL3Transform::GetNTimeBins()+1;
107   Int_t npads = AliL3Transform::GetNPads(AliL3Transform::GetLastRow(fPatch))+1;//Max num of pads.
108   Int_t bounds = ntimes*npads;
109   fRow = new Digit[bounds];
110   
111   
112   UInt_t ndigits=0;
113   AliL3DigitRowData *digits=0;
114 #ifdef use_aliroot
115   fMemHandler = new AliL3FileHandler();
116   fMemHandler->Init(slice,patch);
117   if(binary == kFALSE)
118     {
119       sprintf(fname,"%s/digitfile.root",fPath);
120       fMemHandler->SetAliInput(fname);
121       digits = fMemHandler->AliAltroDigits2Memory(ndigits);
122     }
123   else
124     {
125       sprintf(fname,"%sdigits_%d_%d.raw",fPath,fSlice,fPatch);
126       if(!fMemHandler->SetBinaryInput(fname))
127         {
128           cerr<<"AliL3Modeller::Init : Error opening file "<<fname<<endl;
129           return;
130         }
131       digits=(AliL3DigitRowData*)fMemHandler->CompBinary2Memory(ndigits);
132     }
133 #else
134   fMemHandler = new AliL3MemHandler();
135   fMemHandler->Init(slice,patch);
136   if(binary == kFALSE)
137     {
138       cerr<<"AliL3Modeller::Init : Compile with AliROOT if you want rootfile as input"<<endl;
139       return;
140     }
141   else
142     {
143       sprintf(fname,"%sdigits_%d_%d.raw",fPath,fSlice,fPatch);
144       if(!fMemHandler->SetBinaryInput(fname))
145         {
146           cerr<<"AliL3Modeller::Init : Error opening file "<<fname<<endl;
147           return;
148         }
149     }
150   digits=(AliL3DigitRowData*)fMemHandler->CompBinary2Memory(ndigits);
151 #endif
152   
153   SetInputData(digits);
154 }
155
156 void AliL3Modeller::FindClusters()
157 {
158   // Finds clusters
159   if(fDebug)
160     cout<<"AliL3Modeller::FindClusters : Processing slice "<<fSlice<<" patch "<<fPatch<<endl;
161   if(!fTracks)
162     {
163       cerr<<"AliL3Modeller::Process : No tracks"<<endl;
164       return;
165     }
166   if(!fRowData)
167     {
168       cerr<<"AliL3Modeller::Process : No data "<<endl;
169       return;
170     }
171   
172   AliL3DigitRowData *rowPt = fRowData;
173   AliL3DigitData *digPt=0;
174
175   Int_t pad,time;
176   Short_t charge;
177   Cluster cluster;
178   ClusterRegion region[200];
179   
180   for(Int_t i=AliL3Transform::GetFirstRow(fPatch); i<=AliL3Transform::GetLastRow(fPatch); i++)
181     {
182       if(i != (Int_t)rowPt->fRow)
183         {
184           cerr<<"AliL3Modeller::FindClusters : Mismatching rownumbering "<<i<<" "<<rowPt->fRow<<endl;
185           return;
186         }
187       fCurrentPadRow = i;
188       memset((void*)fRow,0,(AliL3Transform::GetNTimeBins()+1)*(AliL3Transform::GetNPads(i)+1)*sizeof(Digit));
189       digPt = (AliL3DigitData*)rowPt->fDigitData;
190       //cout<<"Loading row "<<i<<" with "<<(Int_t)rowPt->fNDigit<<" digits"<<endl;
191       for(UInt_t j=0; j<rowPt->fNDigit; j++)
192         {
193           pad = digPt[j].fPad;
194           time = digPt[j].fTime;
195           charge = digPt[j].fCharge;
196           fRow[(AliL3Transform::GetNTimeBins()+1)*pad + time].fCharge = charge;
197           fRow[(AliL3Transform::GetNTimeBins()+1)*pad + time].fUsed = kFALSE;
198           //cout<<"Row "<<i<<" pad "<<pad<<" time "<<time<<" charge "<<charge<<endl;
199         }
200       
201       for(Int_t k=0; k<fTracks->GetNTracks(); k++)
202         {
203           AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(k);
204           if(!track) continue;
205           
206           if(track->GetPadHit(i)<0 || track->GetTimeHit(i)<0 || track->GetNOverlaps(i)>0)//track->GetOverlap(i)>=0)
207             {
208               //cout<<"Track "<<k<<" is empty on row "<<i<<" "<<track->GetPadHit(i)<<" "<<track->GetTimeHit(i)<<endl;
209               track->SetCluster(i,0,0,0,0,0,0); //The track has left the patch, or it is overlapping
210               continue;
211             }
212           
213           Int_t minpad,mintime,maxpad,maxtime;
214           minpad = mintime = 999;
215           maxpad = maxtime = 0;
216           
217           memset(&cluster,0,sizeof(Cluster));
218           LocateCluster(track,region,minpad,maxpad);//,mintime,maxtime);
219           if(maxpad - minpad + 1 > fMaxPads ||  // maxtime - mintime + 1 > fMaxTimebins ||
220              maxpad - minpad < 1)               //  || maxtime - mintime < 1)
221             {
222               //cout<<"Cluster not found on row "<<i<<" maxpad "<<maxpad<<" minpad "<<minpad<<" maxtime "<<maxtime<<" mintime "<<mintime
223               //  <<" padhit "<<track->GetPadHit(i)<<" timehit "<<track->GetTimeHit(i)<<endl;
224                 
225               track->SetCluster(i,0,0,0,0,0,0);
226               continue;
227             }
228           
229           Int_t npads=0;
230           for(pad=minpad; pad<=maxpad; pad++)
231             {
232               Int_t ntimes=0;
233               for(time=region[pad].fMintime; time<=region[pad].fMaxtime; time++)
234                 {
235                   charge = fRow[(AliL3Transform::GetNTimeBins()+1)*pad+time].fCharge;
236                   if(!charge) continue;
237                   if(fRow[(AliL3Transform::GetNTimeBins()+1)*pad+time].fUsed == kTRUE)
238                     continue;
239                   ntimes++;
240                   
241                   //Update the cluster parameters with this timebin
242                   cluster.fTime += time*charge;
243                   cluster.fPad += pad*charge;
244                   cluster.fCharge += charge;
245                   cluster.fSigmaY2 += pad*pad*charge;
246                   cluster.fSigmaZ2 += time*time*charge;
247                   fRow[(AliL3Transform::GetNTimeBins()+1)*pad+time].fUsed = kTRUE;
248                 }
249               if(ntimes)
250                 npads++;
251             }
252           FillCluster(track,&cluster,i,npads);
253         }
254       FillZeros(rowPt);
255       fMemHandler->UpdateRowPointer(rowPt);
256     }
257   //cout<<"done processing"<<endl;
258   
259
260   //Debug:
261   for(Int_t i=0; i<fTracks->GetNTracks(); i++)
262     {
263       AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(i);
264       if(!track) continue;
265       if(track->GetNClusters() != AliL3Transform::GetNRows(fPatch))
266         cerr<<endl<<"Mismatching hitcounts; nclusters: "<<track->GetNClusters()<<" nrows "<<AliL3Transform::GetNRows(fPatch)<<endl<<endl;
267     }
268   
269 }
270
271
272 void AliL3Modeller::LocateCluster(AliL3ModelTrack *track,ClusterRegion *region,Int_t &padmin,Int_t &padmax)
273 {
274   //Set the cluster range
275   //This method searches for _all_ nonzeros timebins which are neigbours.
276   //This makes it rather impractical when dealing with high occupancy,
277   //because then you might have very large "cluster" areas from low
278   //pt electrons/noise. 
279   
280   Int_t row=fCurrentPadRow,charge,prtmin=0,prtmax=999;
281   Int_t hitpad = (Int_t)rint(track->GetPadHit(row));
282   Int_t hittime = (Int_t)rint(track->GetTimeHit(row));
283   Int_t tmin = hittime;
284   Int_t tmax = tmin;
285     
286   Int_t clustercharge=0;
287   Int_t pad=hitpad;
288   Bool_t pm = kTRUE;
289   Int_t npads=0,middlemax=tmax,middlemin=tmin;
290   while(1)
291     {
292       Bool_t padpr=kFALSE;
293       Int_t time = hittime;
294       Bool_t tm = kTRUE;
295       if(pad < 0)
296         {
297           padmin = 0;
298           pad = hitpad+1;
299           pm = kFALSE;
300           prtmin = middlemin;
301           prtmax = middlemax;
302           continue;
303         }
304       else if(pad >= AliL3Transform::GetNPads(row))
305         {
306           padmax = AliL3Transform::GetNPads(row)-1;
307           break;
308         }
309       
310       tmin = 999;
311       tmax = 0;
312       //if(row==0)
313       //cout<<"Starting to look in pad "<<pad<<" time "<<time<<endl;
314       while(1)
315         {
316           if(time < 0)
317             {
318               time = hittime+1;
319               tm = kFALSE;
320             }
321           else if(time >= AliL3Transform::GetNTimeBins())
322             {
323               //timemax = AliL3Transform::GetNTimeBins()-1;
324               break;
325             }
326           charge = fRow[(AliL3Transform::GetNTimeBins()+1)*pad+time].fCharge;
327           //if(row==0)
328           //cout<<"charge "<<charge<<" at pad "<<pad<<" time "<<time<<endl;
329           if(charge>0)
330             {
331               clustercharge+=charge;
332               padpr = kTRUE;
333               if(time < tmin)
334                 tmin = time;
335               if(time > tmax)
336                 tmax = time;
337               if(tm)
338                 time--;
339               else
340                 time++;
341             }
342           else
343             {
344               if(tm)
345                 {
346                   //if(abs(time - hittime) < fTimeSearch && padpr == kFALSE)//Keep looking
347                   if(time > prtmin && npads!=0)
348                     time--;
349                   else
350                     {
351                       time = hittime+1;
352                       tm=kFALSE;
353                     }
354                 }
355               //else if(abs(time-hittime) < fTimeSearch && padpr == kFALSE)//Keep looking
356               else if(time < prtmax && npads != 0)
357                 time++;
358               else
359                 break;
360             }
361         }
362       if(npads==0)
363         {
364           middlemax = tmax;
365           middlemin = tmin;
366         }
367       //      if(row==0)
368       //cout<<"tmax "<<tmax<<" tmin "<<tmin<<" prtmin "<<prtmin<<" ptrmax "<<prtmax<<endl;
369       
370       if(padpr && tmax >= prtmin && tmin <= prtmax)//Sequence is overlapping with the previous
371         {
372           //if(row==0)
373           //cout<<"Incrementing pad "<<endl;
374           npads++;
375           
376           region[pad].fMintime=tmin;
377           region[pad].fMaxtime=tmax;
378           
379           /*
380           if(tmin < timemin)
381             timemin=tmin;
382           if(tmax > timemax)
383             timemax=tmax;
384           */
385           if(pad < padmin)
386             padmin = pad;
387           if(pad > padmax)
388             padmax = pad;
389           if(pm)
390             pad--;
391           else
392             pad++;
393           
394           prtmin = tmin;
395           prtmax = tmax;
396         }
397       else
398         {
399           if(pm)
400             {
401               if(abs(pad-hitpad)<fPadSearch && clustercharge == 0)
402                 pad--;
403               else
404                 {
405                   //if(row==0)
406                   //cout<<"Setting new pad "<<hitpad+1<<endl;
407                   pad = hitpad+1;
408                   pm = kFALSE;
409                   prtmin = middlemin;
410                   prtmax = middlemax;
411                   continue;
412                 }
413             }
414           else 
415             {
416               if(abs(pad-hitpad)<fPadSearch && clustercharge==0)
417                 pad++;
418               else
419                 break;
420             }
421         }
422     }
423   
424 }
425
426
427 void AliL3Modeller::FillCluster(AliL3ModelTrack *track,Cluster *cluster,Int_t row,Int_t npads)
428 {
429   // Fill clusters
430   if(cluster->fCharge==0)
431     {
432       track->SetCluster(row,0,0,0,0,0,0);
433       return;
434     }
435   Float_t fcharge = (Float_t)cluster->fCharge;
436   Float_t fpad = ((Float_t)cluster->fPad/fcharge);
437   Float_t ftime = ((Float_t)cluster->fTime/fcharge);
438   Float_t sigmaY2,sigmaZ2;
439   CalcClusterWidth(cluster,sigmaY2,sigmaZ2);
440   track->SetCluster(row,fpad,ftime,fcharge,sigmaY2,sigmaZ2,npads);
441 #ifdef do_mc
442   Int_t trackID[3];
443   GetTrackID((Int_t)rint(fpad),(Int_t)rint(ftime),trackID);
444   track->SetClusterLabel(row,trackID);
445 #endif
446 }
447
448
449
450 void AliL3Modeller::FillZeros(AliL3DigitRowData *rowPt,Bool_t reversesign)
451 {
452   //Fill zero where data has been used.
453
454   AliL3DigitData *digPt = (AliL3DigitData*)rowPt->fDigitData;
455   for(UInt_t j=0; j<rowPt->fNDigit; j++)
456     {
457       Int_t pad = digPt[j].fPad;
458       Int_t time = digPt[j].fTime;
459       if(fRow[(AliL3Transform::GetNTimeBins()+1)*pad+time].fUsed==kTRUE)
460         {
461           if(reversesign)
462             {
463               if(digPt[j].fCharge < 1024)
464                 digPt[j].fCharge += 1024;
465             }
466           else
467             digPt[j].fCharge = 0;
468         }
469     }
470 }
471
472 void AliL3Modeller::WriteRemaining()
473 {
474   //Write remaining (nonzero) digits to file.
475   
476   AliL3DigitRowData *rowPt;
477   rowPt = (AliL3DigitRowData*)fRowData;
478   Int_t digitcount=0;
479   Int_t *ndigits=new Int_t[(AliL3Transform::GetNRows(fPatch))];
480   for(Int_t i=AliL3Transform::GetFirstRow(fPatch); i<=AliL3Transform::GetLastRow(fPatch); i++)
481     {
482       AliL3DigitData *digPt = (AliL3DigitData*)rowPt->fDigitData;
483       ndigits[(i-AliL3Transform::GetFirstRow(fPatch))]=0;
484       for(UInt_t j=0; j<rowPt->fNDigit; j++)
485         {
486           if(digPt[j].fCharge==0) continue;
487           digitcount++;
488           ndigits[(i-AliL3Transform::GetFirstRow(fPatch))]++;
489         }
490       //cout<<"Difference "<<(int)ndigits[(i-AliL3Transform::GetFirstRow(fPatch))]<<" "<<(int)rowPt->fNDigit<<endl;
491       fMemHandler->UpdateRowPointer(rowPt);
492     }
493   
494   Int_t size = digitcount*sizeof(AliL3DigitData) + AliL3Transform::GetNRows(fPatch)*sizeof(AliL3DigitRowData);
495   Byte_t *data = new Byte_t[size];
496   memset(data,0,size);
497   AliL3DigitRowData *tempPt = (AliL3DigitRowData*)data;
498   rowPt = (AliL3DigitRowData*)fRowData;
499   
500   for(Int_t i=AliL3Transform::GetFirstRow(fPatch); i<=AliL3Transform::GetLastRow(fPatch); i++)
501     {
502       Int_t localcount=0;
503       tempPt->fRow = i;
504       tempPt->fNDigit = ndigits[(i-AliL3Transform::GetFirstRow(fPatch))];
505       AliL3DigitData *digPt = (AliL3DigitData*)rowPt->fDigitData;
506       for(UInt_t j=0; j<rowPt->fNDigit; j++)
507         {
508           if(digPt[j].fCharge==0) continue;
509           if(localcount >= ndigits[(i-AliL3Transform::GetFirstRow(fPatch))])
510             {
511               cerr<<"AliL3Modeller::WriteRemaining : Digitarray out of range!!"<<endl;
512               return;
513             }
514           tempPt->fDigitData[localcount].fCharge = digPt[j].fCharge;
515           tempPt->fDigitData[localcount].fPad = digPt[j].fPad;
516           tempPt->fDigitData[localcount].fTime = digPt[j].fTime;
517
518           localcount++;
519         }
520       if(ndigits[(i-AliL3Transform::GetFirstRow(fPatch))] != localcount)
521         {
522           cerr<<"AliL3Modeller::WriteRemaining : Mismatch in digitcount"<<endl;
523           return;
524         }
525       fMemHandler->UpdateRowPointer(rowPt);
526       Byte_t *tmp = (Byte_t*)tempPt;
527       Int_t size = sizeof(AliL3DigitRowData) + ndigits[(i-AliL3Transform::GetFirstRow(fPatch))]*sizeof(AliL3DigitData);
528       tmp += size;
529       tempPt = (AliL3DigitRowData*)tmp;
530     }
531
532   Char_t fname[100];
533   AliL3MemHandler *mem = new AliL3MemHandler();
534   sprintf(fname,"%s/comp/remains_%d_%d.raw",fPath,fSlice,fPatch);
535   mem->Init(fSlice,fPatch);
536   mem->SetBinaryOutput(fname);
537   mem->Memory2CompBinary((UInt_t)AliL3Transform::GetNRows(fPatch),(AliL3DigitRowData*)data);
538   mem->CloseBinaryOutput();
539   delete mem;
540   delete [] data;
541   delete [] ndigits;
542 }
543
544 void AliL3Modeller::RemoveBadTracks()
545 {
546   //Remove tracsk which should not be included in the compression scheme.
547
548   for(Int_t i=0; i<fTracks->GetNTracks(); i++)
549     {
550       AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(i);
551       if(!track) continue;
552
553       if(track->GetPt() < 0.08)
554         {
555           fTracks->Remove(i);
556           continue;
557         }
558
559       if(!fHoughTracks)
560         if(track->GetNHits() < fTrackThreshold)
561           fTracks->Remove(i);
562     }
563   fTracks->Compress();
564   
565 }
566
567 void AliL3Modeller::CalculateCrossingPoints()
568 {
569   // calculates crossing points
570   if(fDebug)
571     cout<<"Calculating crossing points on "<<fTracks->GetNTracks()<<" tracks"<<endl;
572   if(!fTracks)
573     {
574       cerr<<"AliL3Modeller::CalculateCrossingPoints(): No tracks"<<endl;
575       return;
576     }
577   Float_t hit[3];
578   
579   Int_t sector,row;
580   for(Int_t i=AliL3Transform::GetLastRow(fPatch); i>=AliL3Transform::GetFirstRow(fPatch); i--)
581     {
582       for(Int_t j=0; j<fTracks->GetNTracks(); j++)
583         {
584           AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(j);
585           if(!track) continue;
586
587           if(!track->GetCrossingPoint(i,hit)) 
588             {
589               //cerr<<"AliL3Modeller::CalculateCrossingPoints : Track "<<j<<" does not intersect row "<<i<<" :"<<endl<<
590               //        " pt "<<track->GetPt()<<
591               //        " tgl "<<track->GetTgl()<<" psi "<<track->GetPsi()<<" charge "<<track->GetCharge()<<endl;
592               //fTracks->Remove(j);
593               track->SetPadHit(i,-1);
594               track->SetTimeHit(i,-1);
595               continue;
596             }
597           //cout<<"X "<<hit[0]<<" Y "<<hit[1]<<" Z "<<hit[2]<<" tgl "<<track->GetTgl()<<endl;
598           
599           AliL3Transform::Slice2Sector(fSlice,i,sector,row);
600           AliL3Transform::Local2Raw(hit,sector,row);
601           //cout<<"Pad "<<hit[1]<<" time "<<hit[2]<<" in sector "<<sector<<" row "<<row<<endl;
602           if(hit[1]<0 || hit[1]>AliL3Transform::GetNPads(i) ||
603              hit[2]<0 || hit[2]>AliL3Transform::GetNTimeBins())
604             {//Track is leaving the patch, so flag the track hits (<0)
605               track->SetPadHit(i,-1);
606               track->SetTimeHit(i,-1);
607               continue;
608             }
609
610           track->SetPadHit(i,hit[1]);
611           track->SetTimeHit(i,hit[2]);
612           track->CalculateClusterWidths(i);
613
614           Double_t beta = track->GetCrossingAngle(i);
615           track->SetCrossingAngleLUT(i,beta);
616           
617           //if(hit[1]<0 || hit[2]>445)
618           //if(hit[2]<0 || hit[2]>445)
619           //cout<<"pad "<<hit[1]<<" time "<<hit[2]<<" pt "<<track->GetPt()<<" psi "<<track->GetPsi()<<" tgl "<<track->GetTgl()<<" firstpoint "<<track->GetFirstPointX()<<" "<<track->GetFirstPointY()<<" "<<track->GetFirstPointZ()<<endl;
620           //cout<<"Crossing pad "<<hit[1]<<" time "<<hit[2]<<endl;
621         }
622     }
623   fTracks->Compress();
624   if(fDebug)
625     cout<<"And there are "<<fTracks->GetNTracks()<<" tracks remaining"<<endl;
626 }
627
628 void AliL3Modeller::CheckForOverlaps(Float_t dangle,Int_t *rowrange)
629 {
630   //Flag the tracks that overlap
631   
632   if(fDebug)
633     cout<<"Checking for overlaps on "<<fTracks->GetNTracks()<<endl;
634   Int_t counter=0;
635   
636   for(Int_t k=AliL3Transform::GetFirstRow(fPatch); k<=AliL3Transform::GetLastRow(fPatch); k++)
637     {
638       if(rowrange)
639         {
640           if(k < rowrange[0]) continue;
641           if(k > rowrange[1]) break;
642         }
643       for(Int_t i=0; i<fTracks->GetNTracks(); i++)
644         {
645           AliL3ModelTrack *track1 = (AliL3ModelTrack*)fTracks->GetCheckedTrack(i);
646           if(!track1) continue;
647           if(track1->GetPadHit(k)<0 || track1->GetTimeHit(k)<0) continue;
648           
649           for(Int_t j=i+1; j<fTracks->GetNTracks(); j++)
650             {
651               AliL3ModelTrack *track2 = (AliL3ModelTrack*)fTracks->GetCheckedTrack(j);
652               if(!track2) continue;
653               if(track2->GetPadHit(k)<0 || track2->GetTimeHit(k)<0) continue;
654               
655               if(abs((Int_t)rint(track1->GetPadHit(k))-(Int_t)rint(track2->GetPadHit(k))) <= fPadOverlap &&
656                  abs((Int_t)rint(track1->GetTimeHit(k))-(Int_t)rint(track2->GetTimeHit(k))) <= fTimeOverlap)
657                 {
658                   if(dangle>0 && fabs(track1->GetCrossingAngleLUT(k) - track2->GetCrossingAngleLUT(k)) < dangle)
659                     fTracks->Remove(j);
660                   
661                   //cout<<"row "<<k<<" "<<i<<" "<<j<<" "<<track1->GetPadHit(k)<<" "<<track2->GetPadHit(k)<<" "<<fabs(track1->GetCrossingAngleLUT(k) - track2->GetCrossingAngleLUT(k))<<endl;
662
663                   else
664                     track1->SetOverlap(k,j);
665                   counter++;
666                 }
667             }
668         }
669     }
670   fTracks->Compress();
671   if(fDebug)
672     cout<<"and there are "<<fTracks->GetNTracks()<<" track left"<<endl;
673   //cout<<"found "<<counter<<" done"<<endl;
674 }
675
676
677 void AliL3Modeller::CalcClusterWidth(Cluster *cl,Float_t &sigmaY2,Float_t &sigmaZ2)
678 {
679   // calculates cluster's width
680   Float_t padw,timew;
681   
682   padw = AliL3Transform::GetPadPitchWidth(fPatch);
683   
684   Float_t charge = (Float_t)cl->fCharge;
685   Float_t pad = (Float_t)cl->fPad/charge;
686   Float_t time = (Float_t)cl->fTime/charge;
687   Float_t s2 = (Float_t)cl->fSigmaY2/charge - pad*pad;
688   
689   //Save the sigmas in pad and time:
690   
691   sigmaY2 = (s2);// + 1./12);//*padw*padw;
692   
693   /*Constants added by offline
694     if(s2 != 0)
695     {
696     sigmaY2 = sigmaY2*0.108;
697     if(fPatch<3)
698     sigmaY2 = sigmaY2*2.07;
699     }
700   */
701
702   s2 = (Float_t)cl->fSigmaZ2/charge - time*time;
703   timew = AliL3Transform::GetZWidth();
704   sigmaZ2 = (s2);// +1./12);//*timew*timew;
705   
706
707   
708   /*
709     Constants added by offline
710     if(s2 != 0)
711     {
712     sigmaZ2 = sigmaZ2*0.169;
713     if(fPatch < 3)
714     sigmaZ2 = sigmaZ2*1.77;
715     }
716   */
717 }
718
719 #ifdef do_mc
720 void AliL3Modeller::GetTrackID(Int_t pad,Int_t time,Int_t *trackID)
721 {
722   // Gets track ID
723   AliL3DigitRowData *rowPt = (AliL3DigitRowData*)fRowData;
724   
725   trackID[0]=trackID[1]=trackID[2]=-2;
726   
727   for(Int_t i=AliL3Transform::GetFirstRow(fPatch); i<=AliL3Transform::GetLastRow(fPatch); i++)
728     {
729       if(rowPt->fRow < (UInt_t)fCurrentPadRow)
730         {
731           AliL3MemHandler::UpdateRowPointer(rowPt);
732           continue;
733         }
734       AliL3DigitData *digPt = (AliL3DigitData*)rowPt->fDigitData;
735       for(UInt_t j=0; j<rowPt->fNDigit; j++)
736         {
737           Int_t cpad = digPt[j].fPad;
738           Int_t ctime = digPt[j].fTime;
739           if(cpad != pad) continue;
740           if(ctime != time) continue;
741           //if(cpad != pad && ctime != ctime) continue;
742           //cout<<"Reading row "<<fCurrentRow<<" pad "<<cpad<<" time "<<ctime<<" trackID "<<digPt[j].fTrackID[0]<<endl;
743           trackID[0] = digPt[j].fTrackID[0];
744           trackID[1] = digPt[j].fTrackID[1];
745           trackID[2] = digPt[j].fTrackID[2];
746           break;
747           //cout<<"Reading trackID "<<trackID[0]<<endl;
748         }
749       break;
750     }
751 #else
752   void AliL3Modeller::GetTrackID(Int_t /*pad*/,Int_t /*time*/,Int_t */*trackID*/)
753 {
754   // Does nothing if do_mc undefined
755   return;
756 #endif
757 }
758