]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/comp/AliL3Modeller.cxx
Use SetProjectile and SetTarget from AliMC.
[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
b4686276 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
735e167e 15
4994a25d 16#include "AliL3StandardIncludes.h"
735e167e 17
3e87ef69 18#include "AliL3Logging.h"
735e167e 19#include "AliL3Modeller.h"
20#include "AliL3MemHandler.h"
21#include "AliL3TrackArray.h"
22#include "AliL3ModelTrack.h"
23#include "AliL3DigitData.h"
24#include "AliL3Transform.h"
3e87ef69 25#include "AliL3SpacePointData.h"
26
27#ifdef use_aliroot
28#include "AliL3FileHandler.h"
29#endif
735e167e 30
0bd0c1ef 31#if __GNUC__ == 3
4994a25d 32using namespace std;
33#endif
34
735e167e 35ClassImp(AliL3Modeller)
36
37AliL3Modeller::AliL3Modeller()
38{
b4686276 39 // default constructor
735e167e 40 fMemHandler=0;
41 fTracks=0;
3e87ef69 42 fRow=0;
4a838220 43 fTrackThreshold=0;
2357bb38 44 SetOverlap();
45 SetTrackThreshold();
f64c4364 46 SetSearchRange();
3e87ef69 47 SetMaxClusterRange(0,0);
48 fDebug=kFALSE;
735e167e 49}
50
51
52AliL3Modeller::~AliL3Modeller()
53{
b4686276 54 // destructor
735e167e 55 if(fMemHandler)
56 delete fMemHandler;
57 if(fTracks)
58 delete fTracks;
3e87ef69 59 if(fRow)
60 delete [] fRow;
735e167e 61}
62
4994a25d 63void AliL3Modeller::Init(Int_t slice,Int_t patch,Char_t *trackdata,Char_t *path,Bool_t houghtracks,Bool_t binary)
735e167e 64{
b4686276 65 // Initialization
735e167e 66 fSlice = slice;
67 fPatch = patch;
3e87ef69 68 fHoughTracks=houghtracks;
2357bb38 69
be6ddb10 70 sprintf(fPath,"%s",path);
029912b7 71
735e167e 72 fTracks = new AliL3TrackArray("AliL3ModelTrack");
92a876e2 73
74 Char_t fname[100];
735e167e 75 AliL3MemHandler *file = new AliL3MemHandler();
3e87ef69 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);
92a876e2 81 if(!file->SetBinaryInput(fname))
735e167e 82 {
92a876e2 83 cerr<<"AliL3Modeller::Init : Error opening trackfile: "<<fname<<endl;
735e167e 84 return;
85 }
86 file->Binary2TrackArray(fTracks);
87 file->CloseBinaryInput();
88 delete file;
89
4a838220 90 if(!houghtracks)
91 fTracks->QSort();
92
735e167e 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);
4a838220 98
99 //Only if the tracks has been merged across sector boundaries:
100 //if(!houghtracks)
101 //track->Rotate(fSlice,kTRUE); //!!!!!!!!!!!!!!!!!!!
102
735e167e 103 track->CalculateHelix();
104 }
105
3e87ef69 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
8487f697 112 UInt_t ndigits=0;
113 AliL3DigitRowData *digits=0;
114#ifdef use_aliroot
115 fMemHandler = new AliL3FileHandler();
2357bb38 116 fMemHandler->Init(slice,patch);
8487f697 117 if(binary == kFALSE)
118 {
2357bb38 119 sprintf(fname,"%s/digitfile.root",fPath);
8487f697 120 fMemHandler->SetAliInput(fname);
3e87ef69 121 digits = fMemHandler->AliAltroDigits2Memory(ndigits);
8487f697 122 }
2357bb38 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 }
8487f697 133#else
735e167e 134 fMemHandler = new AliL3MemHandler();
2357bb38 135 fMemHandler->Init(slice,patch);
8487f697 136 if(binary == kFALSE)
735e167e 137 {
8487f697 138 cerr<<"AliL3Modeller::Init : Compile with AliROOT if you want rootfile as input"<<endl;
735e167e 139 return;
140 }
8487f697 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
735e167e 152
153 SetInputData(digits);
154}
155
029912b7 156void AliL3Modeller::FindClusters()
735e167e 157{
b4686276 158 // Finds clusters
3e87ef69 159 if(fDebug)
160 cout<<"AliL3Modeller::FindClusters : Processing slice "<<fSlice<<" patch "<<fPatch<<endl;
735e167e 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
3e87ef69 175 Int_t pad,time;
735e167e 176 Short_t charge;
177 Cluster cluster;
3e87ef69 178 ClusterRegion region[200];
179
4a838220 180 for(Int_t i=AliL3Transform::GetFirstRow(fPatch); i<=AliL3Transform::GetLastRow(fPatch); i++)
735e167e 181 {
3e87ef69 182 if(i != (Int_t)rowPt->fRow)
183 {
184 cerr<<"AliL3Modeller::FindClusters : Mismatching rownumbering "<<i<<" "<<rowPt->fRow<<endl;
185 return;
186 }
8487f697 187 fCurrentPadRow = i;
3e87ef69 188 memset((void*)fRow,0,(AliL3Transform::GetNTimeBins()+1)*(AliL3Transform::GetNPads(i)+1)*sizeof(Digit));
735e167e 189 digPt = (AliL3DigitData*)rowPt->fDigitData;
2357bb38 190 //cout<<"Loading row "<<i<<" with "<<(Int_t)rowPt->fNDigit<<" digits"<<endl;
735e167e 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;
3e87ef69 196 fRow[(AliL3Transform::GetNTimeBins()+1)*pad + time].fCharge = charge;
197 fRow[(AliL3Transform::GetNTimeBins()+1)*pad + time].fUsed = kFALSE;
029912b7 198 //cout<<"Row "<<i<<" pad "<<pad<<" time "<<time<<" charge "<<charge<<endl;
735e167e 199 }
200
201 for(Int_t k=0; k<fTracks->GetNTracks(); k++)
202 {
203 AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(k);
204 if(!track) continue;
029912b7 205
3e87ef69 206 if(track->GetPadHit(i)<0 || track->GetTimeHit(i)<0 || track->GetNOverlaps(i)>0)//track->GetOverlap(i)>=0)
95a00d93 207 {
3e87ef69 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
95a00d93 210 continue;
211 }
735e167e 212
3e87ef69 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)
fe1c53fa 221 {
3e87ef69 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);
fe1c53fa 226 continue;
227 }
735e167e 228
4a838220 229 Int_t npads=0;
3e87ef69 230 for(pad=minpad; pad<=maxpad; pad++)
735e167e 231 {
3e87ef69 232 Int_t ntimes=0;
b4686276 233 for(time=region[pad].fMintime; time<=region[pad].fMaxtime; time++)
735e167e 234 {
3e87ef69 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++;
2357bb38 240
241 //Update the cluster parameters with this timebin
735e167e 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;
3e87ef69 247 fRow[(AliL3Transform::GetNTimeBins()+1)*pad+time].fUsed = kTRUE;
735e167e 248 }
3e87ef69 249 if(ntimes)
250 npads++;
735e167e 251 }
3e87ef69 252 FillCluster(track,&cluster,i,npads);
735e167e 253 }
3e87ef69 254 FillZeros(rowPt);
735e167e 255 fMemHandler->UpdateRowPointer(rowPt);
735e167e 256 }
f64c4364 257 //cout<<"done processing"<<endl;
029912b7 258
3e87ef69 259
029912b7 260 //Debug:
261 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
262 {
263 AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(i);
264 if(!track) continue;
4a838220 265 if(track->GetNClusters() != AliL3Transform::GetNRows(fPatch))
266 cerr<<endl<<"Mismatching hitcounts; nclusters: "<<track->GetNClusters()<<" nrows "<<AliL3Transform::GetNRows(fPatch)<<endl<<endl;
029912b7 267 }
268
269}
270
3e87ef69 271
272void AliL3Modeller::LocateCluster(AliL3ModelTrack *track,ClusterRegion *region,Int_t &padmin,Int_t &padmax)
fe1c53fa 273{
3e87ef69 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;
fe1c53fa 290 while(1)
291 {
3e87ef69 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;
fe1c53fa 314 while(1)
315 {
3e87ef69 316 if(time < 0)
fe1c53fa 317 {
3e87ef69 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)
fe1c53fa 345 {
3e87ef69 346 //if(abs(time - hittime) < fTimeSearch && padpr == kFALSE)//Keep looking
347 if(time > prtmin && npads!=0)
fe1c53fa 348 time--;
349 else
3e87ef69 350 {
351 time = hittime+1;
352 tm=kFALSE;
353 }
fe1c53fa 354 }
3e87ef69 355 //else if(abs(time-hittime) < fTimeSearch && padpr == kFALSE)//Keep looking
356 else if(time < prtmax && npads != 0)
357 time++;
fe1c53fa 358 else
359 break;
360 }
fe1c53fa 361 }
3e87ef69 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;
fe1c53fa 369
3e87ef69 370 if(padpr && tmax >= prtmin && tmin <= prtmax)//Sequence is overlapping with the previous
bd53cfb7 371 {
3e87ef69 372 //if(row==0)
373 //cout<<"Incrementing pad "<<endl;
bd53cfb7 374 npads++;
3e87ef69 375
b4686276 376 region[pad].fMintime=tmin;
377 region[pad].fMaxtime=tmax;
3e87ef69 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;
bd53cfb7 396 }
fe1c53fa 397 else
398 {
3e87ef69 399 if(pm)
fe1c53fa 400 {
3e87ef69 401 if(abs(pad-hitpad)<fPadSearch && clustercharge == 0)
fe1c53fa 402 pad--;
403 else
3e87ef69 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 }
fe1c53fa 413 }
3e87ef69 414 else
fe1c53fa 415 {
3e87ef69 416 if(abs(pad-hitpad)<fPadSearch && clustercharge==0)
417 pad++;
418 else
419 break;
fe1c53fa 420 }
fe1c53fa 421 }
fe1c53fa 422 }
423
fe1c53fa 424}
425
3e87ef69 426
4a838220 427void AliL3Modeller::FillCluster(AliL3ModelTrack *track,Cluster *cluster,Int_t row,Int_t npads)
029912b7 428{
b4686276 429 // Fill clusters
029912b7 430 if(cluster->fCharge==0)
431 {
4a838220 432 track->SetCluster(row,0,0,0,0,0,0);
029912b7 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);
4a838220 440 track->SetCluster(row,fpad,ftime,fcharge,sigmaY2,sigmaZ2,npads);
3e87ef69 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
735e167e 446}
447
3e87ef69 448
449
450void AliL3Modeller::FillZeros(AliL3DigitRowData *rowPt,Bool_t reversesign)
95a00d93 451{
452 //Fill zero where data has been used.
3e87ef69 453
95a00d93 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;
3e87ef69 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 }
95a00d93 469 }
470}
471
be6ddb10 472void AliL3Modeller::WriteRemaining()
95a00d93 473{
474 //Write remaining (nonzero) digits to file.
475
95a00d93 476 AliL3DigitRowData *rowPt;
477 rowPt = (AliL3DigitRowData*)fRowData;
478 Int_t digitcount=0;
de3c3890 479 Int_t *ndigits=new Int_t[(AliL3Transform::GetNRows(fPatch))];
4a838220 480 for(Int_t i=AliL3Transform::GetFirstRow(fPatch); i<=AliL3Transform::GetLastRow(fPatch); i++)
95a00d93 481 {
482 AliL3DigitData *digPt = (AliL3DigitData*)rowPt->fDigitData;
4a838220 483 ndigits[(i-AliL3Transform::GetFirstRow(fPatch))]=0;
95a00d93 484 for(UInt_t j=0; j<rowPt->fNDigit; j++)
485 {
486 if(digPt[j].fCharge==0) continue;
487 digitcount++;
4a838220 488 ndigits[(i-AliL3Transform::GetFirstRow(fPatch))]++;
95a00d93 489 }
4a838220 490 //cout<<"Difference "<<(int)ndigits[(i-AliL3Transform::GetFirstRow(fPatch))]<<" "<<(int)rowPt->fNDigit<<endl;
95a00d93 491 fMemHandler->UpdateRowPointer(rowPt);
492 }
493
4a838220 494 Int_t size = digitcount*sizeof(AliL3DigitData) + AliL3Transform::GetNRows(fPatch)*sizeof(AliL3DigitRowData);
95a00d93 495 Byte_t *data = new Byte_t[size];
496 memset(data,0,size);
497 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)data;
498 rowPt = (AliL3DigitRowData*)fRowData;
499
4a838220 500 for(Int_t i=AliL3Transform::GetFirstRow(fPatch); i<=AliL3Transform::GetLastRow(fPatch); i++)
95a00d93 501 {
502 Int_t localcount=0;
503 tempPt->fRow = i;
4a838220 504 tempPt->fNDigit = ndigits[(i-AliL3Transform::GetFirstRow(fPatch))];
95a00d93 505 AliL3DigitData *digPt = (AliL3DigitData*)rowPt->fDigitData;
506 for(UInt_t j=0; j<rowPt->fNDigit; j++)
507 {
508 if(digPt[j].fCharge==0) continue;
4a838220 509 if(localcount >= ndigits[(i-AliL3Transform::GetFirstRow(fPatch))])
95a00d93 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;
4a838220 517
95a00d93 518 localcount++;
519 }
4a838220 520 if(ndigits[(i-AliL3Transform::GetFirstRow(fPatch))] != localcount)
95a00d93 521 {
522 cerr<<"AliL3Modeller::WriteRemaining : Mismatch in digitcount"<<endl;
523 return;
524 }
525 fMemHandler->UpdateRowPointer(rowPt);
526 Byte_t *tmp = (Byte_t*)tempPt;
4a838220 527 Int_t size = sizeof(AliL3DigitRowData) + ndigits[(i-AliL3Transform::GetFirstRow(fPatch))]*sizeof(AliL3DigitData);
95a00d93 528 tmp += size;
529 tempPt = (AliL3DigitRowData*)tmp;
530 }
531
be6ddb10 532 Char_t fname[100];
95a00d93 533 AliL3MemHandler *mem = new AliL3MemHandler();
2357bb38 534 sprintf(fname,"%s/comp/remains_%d_%d.raw",fPath,fSlice,fPatch);
3e87ef69 535 mem->Init(fSlice,fPatch);
be6ddb10 536 mem->SetBinaryOutput(fname);
4a838220 537 mem->Memory2CompBinary((UInt_t)AliL3Transform::GetNRows(fPatch),(AliL3DigitRowData*)data);
95a00d93 538 mem->CloseBinaryOutput();
539 delete mem;
029912b7 540 delete [] data;
62bb4b3d 541 delete [] ndigits;
95a00d93 542}
543
3e87ef69 544void 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}
95a00d93 566
735e167e 567void AliL3Modeller::CalculateCrossingPoints()
568{
b4686276 569 // calculates crossing points
3e87ef69 570 if(fDebug)
571 cout<<"Calculating crossing points on "<<fTracks->GetNTracks()<<" tracks"<<endl;
735e167e 572 if(!fTracks)
573 {
574 cerr<<"AliL3Modeller::CalculateCrossingPoints(): No tracks"<<endl;
575 return;
576 }
577 Float_t hit[3];
029912b7 578
029912b7 579 Int_t sector,row;
4a838220 580 for(Int_t i=AliL3Transform::GetLastRow(fPatch); i>=AliL3Transform::GetFirstRow(fPatch); i--)
735e167e 581 {
582 for(Int_t j=0; j<fTracks->GetNTracks(); j++)
583 {
584 AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(j);
585 if(!track) continue;
4a838220 586
95a00d93 587 if(!track->GetCrossingPoint(i,hit))
735e167e 588 {
f64c4364 589 //cerr<<"AliL3Modeller::CalculateCrossingPoints : Track "<<j<<" does not intersect row "<<i<<" :"<<endl<<
3e87ef69 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);
735e167e 595 continue;
596 }
2357bb38 597 //cout<<"X "<<hit[0]<<" Y "<<hit[1]<<" Z "<<hit[2]<<" tgl "<<track->GetTgl()<<endl;
95a00d93 598
4a838220 599 AliL3Transform::Slice2Sector(fSlice,i,sector,row);
600 AliL3Transform::Local2Raw(hit,sector,row);
2357bb38 601 //cout<<"Pad "<<hit[1]<<" time "<<hit[2]<<" in sector "<<sector<<" row "<<row<<endl;
4a838220 602 if(hit[1]<0 || hit[1]>AliL3Transform::GetNPads(i) ||
603 hit[2]<0 || hit[2]>AliL3Transform::GetNTimeBins())
95a00d93 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 }
3e87ef69 609
735e167e 610 track->SetPadHit(i,hit[1]);
611 track->SetTimeHit(i,hit[2]);
3e87ef69 612 track->CalculateClusterWidths(i);
613
614 Double_t beta = track->GetCrossingAngle(i);
615 track->SetCrossingAngleLUT(i,beta);
95a00d93 616
735e167e 617 //if(hit[1]<0 || hit[2]>445)
95a00d93 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;
735e167e 620 //cout<<"Crossing pad "<<hit[1]<<" time "<<hit[2]<<endl;
621 }
622 }
623 fTracks->Compress();
3e87ef69 624 if(fDebug)
625 cout<<"And there are "<<fTracks->GetNTracks()<<" tracks remaining"<<endl;
735e167e 626}
627
3e87ef69 628void AliL3Modeller::CheckForOverlaps(Float_t dangle,Int_t *rowrange)
735e167e 629{
630 //Flag the tracks that overlap
631
3e87ef69 632 if(fDebug)
633 cout<<"Checking for overlaps on "<<fTracks->GetNTracks()<<endl;
2357bb38 634 Int_t counter=0;
3e87ef69 635
636 for(Int_t k=AliL3Transform::GetFirstRow(fPatch); k<=AliL3Transform::GetLastRow(fPatch); k++)
735e167e 637 {
3e87ef69 638 if(rowrange)
735e167e 639 {
3e87ef69 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++)
735e167e 650 {
3e87ef69 651 AliL3ModelTrack *track2 = (AliL3ModelTrack*)fTracks->GetCheckedTrack(j);
652 if(!track2) continue;
653 if(track2->GetPadHit(k)<0 || track2->GetTimeHit(k)<0) continue;
2357bb38 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)
735e167e 657 {
3e87ef69 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);
2357bb38 665 counter++;
735e167e 666 }
667 }
668 }
669 }
3e87ef69 670 fTracks->Compress();
671 if(fDebug)
672 cout<<"and there are "<<fTracks->GetNTracks()<<" track left"<<endl;
f64c4364 673 //cout<<"found "<<counter<<" done"<<endl;
735e167e 674}
675
676
677void AliL3Modeller::CalcClusterWidth(Cluster *cl,Float_t &sigmaY2,Float_t &sigmaZ2)
678{
b4686276 679 // calculates cluster's width
735e167e 680 Float_t padw,timew;
4a838220 681
682 padw = AliL3Transform::GetPadPitchWidth(fPatch);
683
735e167e 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;
4a838220 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)
735e167e 695 {
4a838220 696 sigmaY2 = sigmaY2*0.108;
697 if(fPatch<3)
698 sigmaY2 = sigmaY2*2.07;
735e167e 699 }
4a838220 700 */
701
735e167e 702 s2 = (Float_t)cl->fSigmaZ2/charge - time*time;
4a838220 703 timew = AliL3Transform::GetZWidth();
704 sigmaZ2 = (s2);// +1./12);//*timew*timew;
705
706
707
3e87ef69 708 /*
709 Constants added by offline
4a838220 710 if(s2 != 0)
735e167e 711 {
4a838220 712 sigmaZ2 = sigmaZ2*0.169;
713 if(fPatch < 3)
714 sigmaZ2 = sigmaZ2*1.77;
735e167e 715 }
4a838220 716 */
735e167e 717}
f64c4364 718
3cb5c013 719#ifdef do_mc
3e87ef69 720void AliL3Modeller::GetTrackID(Int_t pad,Int_t time,Int_t *trackID)
721{
b4686276 722 // Gets track ID
3e87ef69 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 }
3cb5c013 751#else
752 void AliL3Modeller::GetTrackID(Int_t /*pad*/,Int_t /*time*/,Int_t */*trackID*/)
753{
754 // Does nothing if do_mc undefined
3e87ef69 755 return;
3cb5c013 756#endif
3e87ef69 757}
758