3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright © ALICE HLT Group
6 #include "AliL3StandardIncludes.h"
7 #include "AliL3HoughTest.h"
8 #include "AliL3ModelTrack.h"
9 #include "AliL3Transform.h"
10 #include "AliL3Histogram.h"
11 #include "AliL3TrackArray.h"
12 #include "AliL3HoughTrack.h"
24 //_____________________________________________________________
28 ClassImp(AliL3HoughTest)
30 AliL3HoughTest::AliL3HoughTest()
36 AliL3HoughTest::~AliL3HoughTest()
42 Bool_t AliL3HoughTest::GenerateTrackData(Double_t pt,Double_t psi,Double_t tgl,Int_t sign,Int_t patch,Int_t minhits)
47 fData = new SimData[AliL3Transform::GetNRows(patch)];
48 memset(fData,0,AliL3Transform::GetNRows(patch)*sizeof(SimData));
50 AliL3ModelTrack *track = new AliL3ModelTrack();
55 track->SetCharge(sign);
56 track->SetFirstPoint(0,0,0);
57 track->CalculateHelix();
60 Int_t temp2[AliL3Transform::GetNTimeBins()];
62 Int_t clustercharge=100;
64 for(Int_t i=AliL3Transform::GetFirstRow(patch); i<=AliL3Transform::GetLastRow(patch); i++)
68 if(!track->GetCrossingPoint(i,xyz))
71 Int_t rowindex = i - AliL3Transform::GetFirstRow(patch);
73 AliL3Transform::Slice2Sector(0,i,sector,row);
74 AliL3Transform::Local2Raw(xyz,sector,row);
76 if(xyz[1] < 0 || xyz[1] >= AliL3Transform::GetNPads(i) || xyz[2] < 0 || xyz[2] >= AliL3Transform::GetNTimeBins())
79 track->SetPadHit(i,xyz[1]);
80 track->SetTimeHit(i,xyz[2]);
82 Double_t beta = track->GetCrossingAngle(i);
83 track->SetCrossingAngleLUT(i,beta);
84 track->CalculateClusterWidths(i);
86 memset(temp,0,200*sizeof(Int_t));
87 memset(temp2,0,AliL3Transform::GetNTimeBins()*sizeof(Int_t));
88 Double_t xysigma = sqrt(track->GetParSigmaY2(i));
89 Double_t zsigma = sqrt(track->GetParSigmaZ2(i));
93 for(j=0; j<entries; j++)
95 Int_t pad = TMath::Nint(gRandom->Gaus(xyz[1],xysigma));
96 Int_t time = TMath::Nint(gRandom->Gaus(xyz[2],zsigma));
97 if(pad < 0 || pad >= AliL3Transform::GetNPads(i) || time < 0 || time >= AliL3Transform::GetNTimeBins())
109 if(temp[j]==0) continue;
111 Int_t index = j - minpad;
113 if(index < 0 || index >= 10)
115 cerr<<"AliL3HoughTest::GenerateTrackData : Wrong index "<<index<<endl;
119 Int_t seq_charge = clustercharge*temp[j]/entries;
121 for(Int_t k=0; k<AliL3Transform::GetNTimeBins(); k++)
123 if(temp2[k]==0) continue;
124 Int_t tindex = k - mintime;
125 if(tindex < 0 || tindex >= 10)
127 cerr<<"AliL3HoughTest::GenerateTrackData : Wrong timeindex "<<tindex<<" "<<k<<" "<<mintime<<endl;
130 Int_t charge = seq_charge*temp2[k]/entries;
135 //cout<<"row "<<i<<" pad "<<j<<" time "<<k<<" charge "<<charge<<endl;
137 fData[rowindex].pads[index][tindex]=charge;
140 fData[rowindex].minpad=minpad;
141 fData[rowindex].mintime=mintime;
142 fData[rowindex].npads=npads;
145 if(hitcounter < minhits)
150 void AliL3HoughTest::Transform2Circle(AliL3Histogram *hist)
154 cerr<<"AliL3HoughTest::Transform : No data"<<endl;
157 Float_t R,phi,phi0,kappa,xyz[3];
158 Int_t pad,time,charge,sector,row;
159 for(Int_t i=AliL3Transform::GetFirstRow(fCurrentPatch); i<=AliL3Transform::GetLastRow(fCurrentPatch); i++)
161 Int_t rowindex = i - AliL3Transform::GetFirstRow(fCurrentPatch);
162 AliL3Transform::Slice2Sector(0,i,sector,row);
163 for(Int_t j=0; j<fData[rowindex].npads; j++)
165 pad = j + fData[rowindex].minpad;
166 for(Int_t k=0; k<10; k++)
168 time = k + fData[rowindex].mintime;
169 charge = fData[rowindex].pads[j][k];
170 if(charge == 0) continue;
171 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
173 R = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
175 phi = AliL3Transform::GetPhi(xyz);
177 for(Int_t k=hist->GetFirstYbin(); k<=hist->GetLastYbin(); k++)
179 phi0 = hist->GetBinCenterY(k);
180 kappa = 2*sin(phi-phi0)/R;
181 hist->Fill(kappa,phi0,charge);
188 void AliL3HoughTest::Transform2CircleC(AliL3Histogram *hist)
192 cerr<<"AliL3HoughTest::TransformC : No data"<<endl;
195 Int_t pad1,pad2,time1,time2,charge1,charge2,sector,row;
196 Float_t r1,r2,phi1,phi2,phi_0,kappa,hit[3],hit2[3];
197 for(Int_t i=AliL3Transform::GetFirstRow(fCurrentPatch); i<=AliL3Transform::GetLastRow(fCurrentPatch); i++)
199 Int_t rowindex1 = i - AliL3Transform::GetFirstRow(fCurrentPatch);
200 for(Int_t d1=0; d1<fData[rowindex1].npads; d1++)
202 pad1 = d1 + fData[rowindex1].minpad;
203 for(Int_t j=0; j<10; j++)
205 time1 = j + fData[rowindex1].mintime;
206 charge1 = fData[rowindex1].pads[d1][j];
207 if(charge1==0) continue;
208 AliL3Transform::Slice2Sector(0,i,sector,row);
209 AliL3Transform::Raw2Local(hit,sector,row,pad1,time1);
210 r1 = sqrt(hit[0]*hit[0]+hit[1]*hit[1]);
211 phi1 = atan2(hit[1],hit[0]);
213 for(Int_t j=i+1; j<=AliL3Transform::GetLastRow(fCurrentPatch); j++)
215 Int_t rowindex2 = j - AliL3Transform::GetFirstRow(fCurrentPatch);
216 for(Int_t d2=0; d2<fData[rowindex2].npads; d2++)
218 pad2 = d2 + fData[rowindex2].minpad;
219 for(Int_t k=0; k<10; k++)
221 time2 = k + fData[rowindex2].mintime;
222 charge2 = fData[rowindex2].pads[d2][k];
223 if(charge2==0) continue;
224 AliL3Transform::Slice2Sector(0,j,sector,row);
225 AliL3Transform::Raw2Local(hit2,sector,row,pad2,time2);
226 r2 = sqrt(hit2[0]*hit2[0]+hit2[1]*hit2[1]);
227 phi2 = atan2(hit2[1],hit2[0]);
228 phi_0 = atan( (r2*sin(phi1) - r1*sin(phi2)) / (r2*cos(phi1) - r1*cos(phi2)) );
230 kappa = 2*sin(phi1-phi_0) / r1;
231 hist->Fill(kappa,phi_0,charge1+charge2);
241 void AliL3HoughTest::Transform2CircleF(AliL3Histogram *hist)
243 //Fix one point in the middle of the tpc
247 cerr<<"AliL3HoughTest::TransformF : No data"<<endl;
250 Int_t pad1,pad2,time1,time2,charge1,charge2,sector,row;
251 Float_t r1,r2,phi1,phi2,phi_0,kappa,hit[3],hit2[3];
253 Int_t rowindex1 = 80 - AliL3Transform::GetFirstRow(fCurrentPatch);
254 for(Int_t d1=1; d1<fData[rowindex1].npads; d1++)
256 pad1 = d1 + fData[rowindex1].minpad;
258 AliL3Transform::Slice2Sector(0,80,sector,row);
259 AliL3Transform::Raw2Local(hit,sector,row,pad1,0);
260 r1 = sqrt(hit[0]*hit[0]+hit[1]*hit[1]);
261 phi1 = atan2(hit[1],hit[0]);
263 for(Int_t j=0; j<10; j++)
265 time1 = j + fData[rowindex1].mintime;
266 charge1 = fData[rowindex1].pads[d1][j];
267 if(charge1==0) continue;
269 for(Int_t j=0; j<=AliL3Transform::GetLastRow(fCurrentPatch); j++)
272 Int_t rowindex2 = j - AliL3Transform::GetFirstRow(fCurrentPatch);
273 for(Int_t d2=0; d2<fData[rowindex2].npads; d2++)
275 pad2 = d2 + fData[rowindex2].minpad;
276 for(Int_t k=0; k<10; k++)
278 time2 = k + fData[rowindex2].mintime;
279 charge2 = fData[rowindex2].pads[d2][k];
280 if(charge2==0) continue;
281 AliL3Transform::Slice2Sector(0,j,sector,row);
282 AliL3Transform::Raw2Local(hit2,sector,row,pad2,time2);
283 r2 = sqrt(hit2[0]*hit2[0]+hit2[1]*hit2[1]);
284 phi2 = atan2(hit2[1],hit2[0]);
285 phi_0 = atan( (r2*sin(phi1) - r1*sin(phi2)) / (r2*cos(phi1) - r1*cos(phi2)) );
287 kappa = 2*sin(phi1-phi_0) / r1;
288 hist->Fill(kappa,phi_0,charge1+charge2);
289 //cout<<"Filling "<<kappa<<" psi "<<phi_0<<" charge "<<charge1<<endl;
298 void AliL3HoughTest::Transform2Line(AliL3Histogram *hist,Int_t *rowrange)
302 cerr<<"AliL3HoughTest::Transform2Line : No data"<<endl;
306 Int_t pad,time,charge,sector,row;
307 Float_t hit[3],theta,rho;
308 for(Int_t i=AliL3Transform::GetFirstRow(fCurrentPatch); i<=AliL3Transform::GetLastRow(fCurrentPatch); i++)
314 Int_t rowindex = i - AliL3Transform::GetFirstRow(fCurrentPatch);
315 for(Int_t d=0; d<fData[rowindex].npads; d++)
317 pad = d + fData[rowindex].minpad;
318 for(Int_t j=0; j<10; j++)
320 time = j + fData[rowindex].mintime;
321 charge = fData[rowindex].pads[d][j];
322 if(charge==0) continue;
323 AliL3Transform::Slice2Sector(0,i,sector,row);
324 AliL3Transform::Raw2Local(hit,sector,row,pad,time);
326 hit[0] = hit[0] - AliL3Transform::Row2X(rowrange[0]);
328 for(Int_t xbin=hist->GetFirstXbin(); xbin<hist->GetLastXbin(); xbin++)
330 theta = hist->GetBinCenterX(xbin);
331 rho = hit[0]*cos(theta) + hit[1]*sin(theta);
332 hist->Fill(theta,rho,charge);
339 void AliL3HoughTest::Transform2LineC(AliL3Histogram *hist,Int_t *rowrange)
343 cerr<<"AliL3HoughTest::Transform2Line : No data"<<endl;
347 Int_t pad1,pad2,time1,time2,charge1,charge2,sector,row;
348 Float_t theta,rho,hit[3],hit2[3];
349 for(Int_t i=rowrange[0]; i<=rowrange[1]; i++)
351 Int_t rowindex1 = i - AliL3Transform::GetFirstRow(fCurrentPatch);
352 for(Int_t d1=0; d1<fData[rowindex1].npads; d1++)
354 pad1 = d1 + fData[rowindex1].minpad;
355 for(Int_t j=0; j<10; j++)
357 time1 = j + fData[rowindex1].mintime;
358 charge1 = fData[rowindex1].pads[d1][j];
359 if(charge1==0) continue;
360 AliL3Transform::Slice2Sector(0,i,sector,row);
361 AliL3Transform::Raw2Local(hit,sector,row,pad1,time1);
363 hit[0] = hit[0] - AliL3Transform::Row2X(rowrange[0]);
365 for(Int_t i2=i+1; i2<=rowrange[1]; i2++)
367 Int_t rowindex2 = i2 - AliL3Transform::GetFirstRow(fCurrentPatch);
368 for(Int_t d2=0; d2<fData[rowindex2].npads; d2++)
370 pad2 = d2 + fData[rowindex2].minpad;
371 for(Int_t k=0; k<10; k++)
373 time2 = k + fData[rowindex2].mintime;
374 charge2 = fData[rowindex2].pads[d2][k];
375 if(charge2==0) continue;
376 AliL3Transform::Slice2Sector(0,i2,sector,row);
377 AliL3Transform::Raw2Local(hit2,sector,row,pad2,time2);
379 hit2[0] = hit2[0] - AliL3Transform::Row2X(rowrange[0]);
381 theta = atan2(hit2[0]-hit[0],hit[1]-hit2[1]);
382 rho = hit[0]*cos(theta)+hit[1]*sin(theta);
383 hist->Fill(theta,rho,charge1+charge2);
392 void AliL3HoughTest::FillImage(TH2 *hist,Int_t displayrow)
396 cerr<<"AliL3HoughTest::FillImage : No data to fill"<<endl;
400 for(Int_t i=AliL3Transform::GetFirstRow(fCurrentPatch); i<=AliL3Transform::GetLastRow(fCurrentPatch); i++)
402 Int_t rowindex = i - AliL3Transform::GetFirstRow(fCurrentPatch);
404 if(i != displayrow) continue;
406 //cout<<"row "<<i<<" npads "<<fData[rowindex].npads<<endl;
407 for(Int_t j=0; j<fData[rowindex].npads; j++)
409 Int_t pad = j + fData[rowindex].minpad;
410 for(Int_t k=0; k<10; k++)
412 Int_t time = k + fData[rowindex].mintime;
413 Int_t charge = fData[rowindex].pads[j][k];
414 if(charge==0) continue;
415 //cout<<i<<" "<<pad<<" "<<time<<" "<<charge<<endl;
418 AliL3Transform::Slice2Sector(0,i,sector,row);
419 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
421 hist->Fill(pad,time,charge);
423 hist->Fill(xyz[0],xyz[1],charge);
431 void AliL3HoughTest::Transform2Line3D(TH3 *hist,Int_t *rowrange,Float_t *phirange)
435 cerr<<"AliL3HoughTest::Transform2Line : No data"<<endl;
439 Int_t pad,time,charge,sector,row;
440 Float_t hit[3],theta,rho,R,delta;
441 for(Int_t i=AliL3Transform::GetFirstRow(fCurrentPatch); i<=AliL3Transform::GetLastRow(fCurrentPatch); i++)
449 Int_t rowindex = i - AliL3Transform::GetFirstRow(fCurrentPatch);
450 for(Int_t d=0; d<fData[rowindex].npads; d++)
452 pad = d + fData[rowindex].minpad;
453 for(Int_t j=0; j<10; j++)
455 time = j + fData[rowindex].mintime;
456 charge = fData[rowindex].pads[d][j];
457 if(charge==0) continue;
458 AliL3Transform::Slice2Sector(0,i,sector,row);
459 AliL3Transform::Raw2Local(hit,sector,row,pad,time);
461 Float_t phi = AliL3Transform::GetPhi(hit);
462 if(phi < phirange[0] || phi > phirange[1])
465 hit[0] = hit[0] - AliL3Transform::Row2X(rowrange[0]);
466 Float_t x = hit[0] + AliL3Transform::Row2X(rowrange[0]);
467 R = sqrt(x*x + hit[1]*hit[1]);
468 delta = atan(hit[2]/R);
470 for(Int_t xbin=hist->GetXaxis()->GetFirst(); xbin<=hist->GetXaxis()->GetLast(); xbin++)
472 theta = hist->GetXaxis()->GetBinCenter(xbin);
473 rho = hit[0]*cos(theta) + hit[1]*sin(theta);
474 hist->Fill(theta,rho,delta,charge);
481 void AliL3HoughTest::Transform2LineC3D(TH3 *hist,Int_t *rowrange)
485 cerr<<"AliL3HoughTest::Transform2Line : No data"<<endl;
489 Int_t pad1,pad2,time1,time2,charge1,charge2,sector,row;
490 Float_t theta,rho,hit[3],hit2[3],R1,R2,delta,delta1,delta2;
491 for(Int_t i=AliL3Transform::GetFirstRow(fCurrentPatch); i<=AliL3Transform::GetLastRow(fCurrentPatch); i++)
497 Int_t rowindex1 = i - AliL3Transform::GetFirstRow(fCurrentPatch);
498 for(Int_t d1=0; d1<fData[rowindex1].npads; d1++)
500 pad1 = d1 + fData[rowindex1].minpad;
501 for(Int_t j=0; j<10; j++)
503 time1 = j + fData[rowindex1].mintime;
504 charge1 = fData[rowindex1].pads[d1][j];
505 if(charge1==0) continue;
506 AliL3Transform::Slice2Sector(0,i,sector,row);
507 AliL3Transform::Raw2Local(hit,sector,row,pad1,time1);
508 R1 = sqrt(hit[0]*hit[0]+hit[1]*hit[1]);
509 delta1 = atan(hit[2]/R1);
510 hit[0] = hit[0] - AliL3Transform::Row2X(rowrange[0]);
512 for(Int_t i2=i+1; i2<=rowrange[1]; i2++)
514 Int_t rowindex2 = i2 - AliL3Transform::GetFirstRow(fCurrentPatch);
515 for(Int_t d2=0; d2<fData[rowindex2].npads; d2++)
517 pad2 = d2 + fData[rowindex2].minpad;
518 for(Int_t k=0; k<10; k++)
520 time2 = k + fData[rowindex2].mintime;
521 charge2 = fData[rowindex2].pads[d2][k];
522 if(charge2==0) continue;
523 AliL3Transform::Slice2Sector(0,i2,sector,row);
524 AliL3Transform::Raw2Local(hit2,sector,row,pad2,time2);
525 R2 = sqrt(hit2[0]*hit2[0]+hit2[1]*hit2[1]);
526 delta2 = atan(hit2[2]/R2);
527 delta = (charge1*delta1 + charge2*delta2)/(charge1+charge2);
528 hit2[0] = hit2[0] - AliL3Transform::Row2X(rowrange[0]);
530 theta = atan2(hit2[0]-hit[0],hit[1]-hit2[1]);
531 rho = hit[0]*cos(theta)+hit[1]*sin(theta);
532 hist->Fill(theta,rho,delta,charge1+charge2);
541 void AliL3HoughTest::TransformLines2Circle(TH3 *hist,AliL3TrackArray *tracks)
544 for(Int_t i=0; i<tracks->GetNTracks(); i++)
546 AliL3HoughTrack *tr = (AliL3HoughTrack*)tracks->GetCheckedTrack(i);
548 Int_t middlerow = (Int_t)(tr->GetFirstRow()+(tr->GetLastRow()-tr->GetFirstRow())/2);
550 tr->GetLineCrossingPoint(middlerow,hit);
551 hit[0] += AliL3Transform::Row2X(tr->GetFirstRow());
552 Float_t R = sqrt(hit[0]*hit[0] + hit[1]*hit[1]);
553 hit[2] = R*tr->GetTgl();
554 Float_t phi = atan2(hit[1],hit[0]);
555 Float_t theta = tr->GetPsiLine() - AliL3Transform::Pi()/2;
556 Float_t psi = 2*phi - theta;
557 Float_t kappa = 2/R*sin(phi-psi);
558 Float_t delta = atan(hit[2]/R);
559 hist->Fill(kappa,psi,delta,tr->GetWeight());
564 void AliL3HoughTest::Transform2Center(AliL3Histogram *hist)
566 //Choose parameter space to be center of curvature.
570 cerr<<"AliL3HoughTest::TransformC : No data"<<endl;
573 Int_t pad1,pad2,time1,time2,charge1,charge2,sector,row;
574 Float_t r1,r2,phi1,phi2,hit[3],hit2[3];
575 //Float_t phi_0,kappa;
576 for(Int_t i=AliL3Transform::GetFirstRow(fCurrentPatch); i<=AliL3Transform::GetLastRow(fCurrentPatch); i++)
578 Int_t rowindex1 = i - AliL3Transform::GetFirstRow(fCurrentPatch);
579 for(Int_t d1=0; d1<fData[rowindex1].npads; d1++)
581 pad1 = d1 + fData[rowindex1].minpad;
582 for(Int_t j=0; j<10; j++)
584 time1 = j + fData[rowindex1].mintime;
585 charge1 = fData[rowindex1].pads[d1][j];
586 if(charge1==0) continue;
587 AliL3Transform::Slice2Sector(0,i,sector,row);
588 AliL3Transform::Raw2Local(hit,sector,row,pad1,time1);
589 r1 = sqrt(hit[0]*hit[0]+hit[1]*hit[1])/2;
590 phi1 = atan2(hit[1],hit[0]);
592 for(Int_t j=i+1; j<=AliL3Transform::GetLastRow(fCurrentPatch); j++)
594 Int_t rowindex2 = j - AliL3Transform::GetFirstRow(fCurrentPatch);
595 for(Int_t d2=0; d2<fData[rowindex2].npads; d2++)
597 pad2 = d2 + fData[rowindex2].minpad;
598 for(Int_t k=0; k<10; k++)
600 time2 = k + fData[rowindex2].mintime;
601 charge2 = fData[rowindex2].pads[d2][k];
602 if(charge2==0) continue;
603 AliL3Transform::Slice2Sector(0,j,sector,row);
604 AliL3Transform::Raw2Local(hit2,sector,row,pad2,time2);
605 r2 = sqrt(hit2[0]*hit2[0]+hit2[1]*hit2[1])/2;
606 phi2 = atan2(hit2[1],hit2[0]);
607 Float_t yc = (r2-(r1/cos(phi1))*cos(phi2))/(sin(phi2)-tan(phi1)*cos(phi2));
608 Float_t xc = r1/cos(phi1) - (r2*tan(phi1)-r1*sin(phi1)*cos(phi2))/(sin(phi2)-tan(phi1)*cos(phi2));
609 hist->Fill(xc,yc,charge1+charge2);
619 void AliL3HoughTest::FindAbsMaxima(TH3 *hist,Int_t zsearch,Float_t &max_x,Float_t &max_y,Float_t &max_z,Int_t &maxvalue)
622 TH1 *h1 = hist->Project3D("z");
624 TAxis *z = hist->GetZaxis();
626 Int_t n=0,i,zbin[50];
627 for(i=z->GetFirst()+1; i<z->GetLast()-1; i++)
629 int bin1 = h1->GetBin(i-1);
630 int bin2 = h1->GetBin(i);
631 int bin3 = h1->GetBin(i+1);
632 if(h1->GetBinContent(bin2) > h1->GetBinContent(bin1) && h1->GetBinContent(bin2) > h1->GetBinContent(bin3))
635 zpeak[n++]=h1->GetBinCenter(bin2);
639 Int_t zrange[2] = {z->GetFirst(),z->GetLast()};
640 z->SetRange(zbin[0]-zsearch,zbin[0]+zsearch);
642 TH1 *h2 = hist->Project3D("yx");
643 z->SetRange(zrange[0],zrange[1]);
645 TAxis *x = h2->GetXaxis();
646 TAxis *y = h2->GetYaxis();
650 for(Int_t xbin=x->GetFirst(); xbin<=x->GetLast(); xbin++)
652 Float_t xvalue = x->GetBinCenter(xbin);
653 for(Int_t ybin=y->GetFirst(); ybin<=y->GetLast(); ybin++)
655 Float_t yvalue = y->GetBinCenter(ybin);
656 Int_t value = (Int_t)h2->GetBinContent(xbin,ybin);