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