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()];
61 Int_t * temp2 = new Int_t[AliL3Transform::GetNTimeBins()];
63 Int_t clustercharge=100;
65 for(Int_t i=AliL3Transform::GetFirstRow(patch); i<=AliL3Transform::GetLastRow(patch); i++)
69 if(!track->GetCrossingPoint(i,xyz))
72 Int_t rowindex = i - AliL3Transform::GetFirstRow(patch);
74 AliL3Transform::Slice2Sector(0,i,sector,row);
75 AliL3Transform::Local2Raw(xyz,sector,row);
77 if(xyz[1] < 0 || xyz[1] >= AliL3Transform::GetNPads(i) || xyz[2] < 0 || xyz[2] >= AliL3Transform::GetNTimeBins())
80 track->SetPadHit(i,xyz[1]);
81 track->SetTimeHit(i,xyz[2]);
83 Double_t beta = track->GetCrossingAngle(i);
84 track->SetCrossingAngleLUT(i,beta);
85 track->CalculateClusterWidths(i);
87 memset(temp,0,200*sizeof(Int_t));
88 memset(temp2,0,AliL3Transform::GetNTimeBins()*sizeof(Int_t));
89 Double_t xysigma = sqrt(track->GetParSigmaY2(i));
90 Double_t zsigma = sqrt(track->GetParSigmaZ2(i));
94 for(j=0; j<entries; j++)
96 Int_t pad = TMath::Nint(gRandom->Gaus(xyz[1],xysigma));
97 Int_t time = TMath::Nint(gRandom->Gaus(xyz[2],zsigma));
98 if(pad < 0 || pad >= AliL3Transform::GetNPads(i) || time < 0 || time >= AliL3Transform::GetNTimeBins())
110 if(temp[j]==0) continue;
112 Int_t index = j - minpad;
114 if(index < 0 || index >= 10)
116 cerr<<"AliL3HoughTest::GenerateTrackData : Wrong index "<<index<<endl;
120 Int_t seq_charge = clustercharge*temp[j]/entries;
122 for(Int_t k=0; k<AliL3Transform::GetNTimeBins(); k++)
124 if(temp2[k]==0) continue;
125 Int_t tindex = k - mintime;
126 if(tindex < 0 || tindex >= 10)
128 cerr<<"AliL3HoughTest::GenerateTrackData : Wrong timeindex "<<tindex<<" "<<k<<" "<<mintime<<endl;
131 Int_t charge = seq_charge*temp2[k]/entries;
136 //cout<<"row "<<i<<" pad "<<j<<" time "<<k<<" charge "<<charge<<endl;
138 fData[rowindex].pads[index][tindex]=charge;
141 fData[rowindex].minpad=minpad;
142 fData[rowindex].mintime=mintime;
143 fData[rowindex].npads=npads;
147 if(hitcounter < minhits)
152 void AliL3HoughTest::Transform2Circle(AliL3Histogram *hist)
156 cerr<<"AliL3HoughTest::Transform : No data"<<endl;
159 Float_t R,phi,phi0,kappa,xyz[3];
160 Int_t pad,time,charge,sector,row;
161 for(Int_t i=AliL3Transform::GetFirstRow(fCurrentPatch); i<=AliL3Transform::GetLastRow(fCurrentPatch); i++)
163 Int_t rowindex = i - AliL3Transform::GetFirstRow(fCurrentPatch);
164 AliL3Transform::Slice2Sector(0,i,sector,row);
165 for(Int_t j=0; j<fData[rowindex].npads; j++)
167 pad = j + fData[rowindex].minpad;
168 for(Int_t k=0; k<10; k++)
170 time = k + fData[rowindex].mintime;
171 charge = fData[rowindex].pads[j][k];
172 if(charge == 0) continue;
173 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
175 R = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
177 phi = AliL3Transform::GetPhi(xyz);
179 for(Int_t k=hist->GetFirstYbin(); k<=hist->GetLastYbin(); k++)
181 phi0 = hist->GetBinCenterY(k);
182 kappa = 2*sin(phi-phi0)/R;
183 hist->Fill(kappa,phi0,charge);
190 void AliL3HoughTest::Transform2CircleC(AliL3Histogram *hist)
194 cerr<<"AliL3HoughTest::TransformC : No data"<<endl;
197 Int_t pad1,pad2,time1,time2,charge1,charge2,sector,row;
198 Float_t r1,r2,phi1,phi2,phi_0,kappa,hit[3],hit2[3];
199 for(Int_t i=AliL3Transform::GetFirstRow(fCurrentPatch); i<=AliL3Transform::GetLastRow(fCurrentPatch); i++)
201 Int_t rowindex1 = i - AliL3Transform::GetFirstRow(fCurrentPatch);
202 for(Int_t d1=0; d1<fData[rowindex1].npads; d1++)
204 pad1 = d1 + fData[rowindex1].minpad;
205 for(Int_t j=0; j<10; j++)
207 time1 = j + fData[rowindex1].mintime;
208 charge1 = fData[rowindex1].pads[d1][j];
209 if(charge1==0) continue;
210 AliL3Transform::Slice2Sector(0,i,sector,row);
211 AliL3Transform::Raw2Local(hit,sector,row,pad1,time1);
212 r1 = sqrt(hit[0]*hit[0]+hit[1]*hit[1]);
213 phi1 = atan2(hit[1],hit[0]);
215 for(Int_t j=i+1; j<=AliL3Transform::GetLastRow(fCurrentPatch); j++)
217 Int_t rowindex2 = j - AliL3Transform::GetFirstRow(fCurrentPatch);
218 for(Int_t d2=0; d2<fData[rowindex2].npads; d2++)
220 pad2 = d2 + fData[rowindex2].minpad;
221 for(Int_t k=0; k<10; k++)
223 time2 = k + fData[rowindex2].mintime;
224 charge2 = fData[rowindex2].pads[d2][k];
225 if(charge2==0) continue;
226 AliL3Transform::Slice2Sector(0,j,sector,row);
227 AliL3Transform::Raw2Local(hit2,sector,row,pad2,time2);
228 r2 = sqrt(hit2[0]*hit2[0]+hit2[1]*hit2[1]);
229 phi2 = atan2(hit2[1],hit2[0]);
230 phi_0 = atan( (r2*sin(phi1) - r1*sin(phi2)) / (r2*cos(phi1) - r1*cos(phi2)) );
232 kappa = 2*sin(phi1-phi_0) / r1;
233 hist->Fill(kappa,phi_0,charge1+charge2);
243 void AliL3HoughTest::Transform2CircleF(AliL3Histogram *hist)
245 //Fix one point in the middle of the tpc
249 cerr<<"AliL3HoughTest::TransformF : No data"<<endl;
252 Int_t pad1,pad2,time1,time2,charge1,charge2,sector,row;
253 Float_t r1,r2,phi1,phi2,phi_0,kappa,hit[3],hit2[3];
255 Int_t rowindex1 = 80 - AliL3Transform::GetFirstRow(fCurrentPatch);
256 for(Int_t d1=1; d1<fData[rowindex1].npads; d1++)
258 pad1 = d1 + fData[rowindex1].minpad;
260 AliL3Transform::Slice2Sector(0,80,sector,row);
261 AliL3Transform::Raw2Local(hit,sector,row,pad1,0);
262 r1 = sqrt(hit[0]*hit[0]+hit[1]*hit[1]);
263 phi1 = atan2(hit[1],hit[0]);
265 for(Int_t j=0; j<10; j++)
267 time1 = j + fData[rowindex1].mintime;
268 charge1 = fData[rowindex1].pads[d1][j];
269 if(charge1==0) continue;
271 for(Int_t j=0; j<=AliL3Transform::GetLastRow(fCurrentPatch); j++)
274 Int_t rowindex2 = j - AliL3Transform::GetFirstRow(fCurrentPatch);
275 for(Int_t d2=0; d2<fData[rowindex2].npads; d2++)
277 pad2 = d2 + fData[rowindex2].minpad;
278 for(Int_t k=0; k<10; k++)
280 time2 = k + fData[rowindex2].mintime;
281 charge2 = fData[rowindex2].pads[d2][k];
282 if(charge2==0) continue;
283 AliL3Transform::Slice2Sector(0,j,sector,row);
284 AliL3Transform::Raw2Local(hit2,sector,row,pad2,time2);
285 r2 = sqrt(hit2[0]*hit2[0]+hit2[1]*hit2[1]);
286 phi2 = atan2(hit2[1],hit2[0]);
287 phi_0 = atan( (r2*sin(phi1) - r1*sin(phi2)) / (r2*cos(phi1) - r1*cos(phi2)) );
289 kappa = 2*sin(phi1-phi_0) / r1;
290 hist->Fill(kappa,phi_0,charge1+charge2);
291 //cout<<"Filling "<<kappa<<" psi "<<phi_0<<" charge "<<charge1<<endl;
300 void AliL3HoughTest::Transform2Line(AliL3Histogram *hist,Int_t *rowrange)
304 cerr<<"AliL3HoughTest::Transform2Line : No data"<<endl;
308 Int_t pad,time,charge,sector,row;
309 Float_t hit[3],theta,rho;
310 for(Int_t i=AliL3Transform::GetFirstRow(fCurrentPatch); i<=AliL3Transform::GetLastRow(fCurrentPatch); i++)
316 Int_t rowindex = i - AliL3Transform::GetFirstRow(fCurrentPatch);
317 for(Int_t d=0; d<fData[rowindex].npads; d++)
319 pad = d + fData[rowindex].minpad;
320 for(Int_t j=0; j<10; j++)
322 time = j + fData[rowindex].mintime;
323 charge = fData[rowindex].pads[d][j];
324 if(charge==0) continue;
325 AliL3Transform::Slice2Sector(0,i,sector,row);
326 AliL3Transform::Raw2Local(hit,sector,row,pad,time);
328 hit[0] = hit[0] - AliL3Transform::Row2X(rowrange[0]);
330 for(Int_t xbin=hist->GetFirstXbin(); xbin<hist->GetLastXbin(); xbin++)
332 theta = hist->GetBinCenterX(xbin);
333 rho = hit[0]*cos(theta) + hit[1]*sin(theta);
334 hist->Fill(theta,rho,charge);
341 void AliL3HoughTest::Transform2LineC(AliL3Histogram *hist,Int_t *rowrange)
345 cerr<<"AliL3HoughTest::Transform2Line : No data"<<endl;
349 Int_t pad1,pad2,time1,time2,charge1,charge2,sector,row;
350 Float_t theta,rho,hit[3],hit2[3];
351 for(Int_t i=rowrange[0]; i<=rowrange[1]; i++)
353 Int_t rowindex1 = i - AliL3Transform::GetFirstRow(fCurrentPatch);
354 for(Int_t d1=0; d1<fData[rowindex1].npads; d1++)
356 pad1 = d1 + fData[rowindex1].minpad;
357 for(Int_t j=0; j<10; j++)
359 time1 = j + fData[rowindex1].mintime;
360 charge1 = fData[rowindex1].pads[d1][j];
361 if(charge1==0) continue;
362 AliL3Transform::Slice2Sector(0,i,sector,row);
363 AliL3Transform::Raw2Local(hit,sector,row,pad1,time1);
365 hit[0] = hit[0] - AliL3Transform::Row2X(rowrange[0]);
367 for(Int_t i2=i+1; i2<=rowrange[1]; i2++)
369 Int_t rowindex2 = i2 - AliL3Transform::GetFirstRow(fCurrentPatch);
370 for(Int_t d2=0; d2<fData[rowindex2].npads; d2++)
372 pad2 = d2 + fData[rowindex2].minpad;
373 for(Int_t k=0; k<10; k++)
375 time2 = k + fData[rowindex2].mintime;
376 charge2 = fData[rowindex2].pads[d2][k];
377 if(charge2==0) continue;
378 AliL3Transform::Slice2Sector(0,i2,sector,row);
379 AliL3Transform::Raw2Local(hit2,sector,row,pad2,time2);
381 hit2[0] = hit2[0] - AliL3Transform::Row2X(rowrange[0]);
383 theta = atan2(hit2[0]-hit[0],hit[1]-hit2[1]);
384 rho = hit[0]*cos(theta)+hit[1]*sin(theta);
385 hist->Fill(theta,rho,charge1+charge2);
394 void AliL3HoughTest::FillImage(TH2 *hist,Int_t displayrow)
398 cerr<<"AliL3HoughTest::FillImage : No data to fill"<<endl;
402 for(Int_t i=AliL3Transform::GetFirstRow(fCurrentPatch); i<=AliL3Transform::GetLastRow(fCurrentPatch); i++)
404 Int_t rowindex = i - AliL3Transform::GetFirstRow(fCurrentPatch);
406 if(i != displayrow) continue;
408 //cout<<"row "<<i<<" npads "<<fData[rowindex].npads<<endl;
409 for(Int_t j=0; j<fData[rowindex].npads; j++)
411 Int_t pad = j + fData[rowindex].minpad;
412 for(Int_t k=0; k<10; k++)
414 Int_t time = k + fData[rowindex].mintime;
415 Int_t charge = fData[rowindex].pads[j][k];
416 if(charge==0) continue;
417 //cout<<i<<" "<<pad<<" "<<time<<" "<<charge<<endl;
420 AliL3Transform::Slice2Sector(0,i,sector,row);
421 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
423 hist->Fill(pad,time,charge);
425 hist->Fill(xyz[0],xyz[1],charge);
433 void AliL3HoughTest::Transform2Line3D(TH3 *hist,Int_t *rowrange,Float_t *phirange)
437 cerr<<"AliL3HoughTest::Transform2Line : No data"<<endl;
441 Int_t pad,time,charge,sector,row;
442 Float_t hit[3],theta,rho,R,delta;
443 for(Int_t i=AliL3Transform::GetFirstRow(fCurrentPatch); i<=AliL3Transform::GetLastRow(fCurrentPatch); i++)
451 Int_t rowindex = i - AliL3Transform::GetFirstRow(fCurrentPatch);
452 for(Int_t d=0; d<fData[rowindex].npads; d++)
454 pad = d + fData[rowindex].minpad;
455 for(Int_t j=0; j<10; j++)
457 time = j + fData[rowindex].mintime;
458 charge = fData[rowindex].pads[d][j];
459 if(charge==0) continue;
460 AliL3Transform::Slice2Sector(0,i,sector,row);
461 AliL3Transform::Raw2Local(hit,sector,row,pad,time);
463 Float_t phi = AliL3Transform::GetPhi(hit);
464 if(phi < phirange[0] || phi > phirange[1])
467 hit[0] = hit[0] - AliL3Transform::Row2X(rowrange[0]);
468 Float_t x = hit[0] + AliL3Transform::Row2X(rowrange[0]);
469 R = sqrt(x*x + hit[1]*hit[1]);
470 delta = atan(hit[2]/R);
472 for(Int_t xbin=hist->GetXaxis()->GetFirst(); xbin<=hist->GetXaxis()->GetLast(); xbin++)
474 theta = hist->GetXaxis()->GetBinCenter(xbin);
475 rho = hit[0]*cos(theta) + hit[1]*sin(theta);
476 hist->Fill(theta,rho,delta,charge);
483 void AliL3HoughTest::Transform2LineC3D(TH3 *hist,Int_t *rowrange)
487 cerr<<"AliL3HoughTest::Transform2Line : No data"<<endl;
491 Int_t pad1,pad2,time1,time2,charge1,charge2,sector,row;
492 Float_t theta,rho,hit[3],hit2[3],R1,R2,delta,delta1,delta2;
493 for(Int_t i=AliL3Transform::GetFirstRow(fCurrentPatch); i<=AliL3Transform::GetLastRow(fCurrentPatch); i++)
499 Int_t rowindex1 = i - AliL3Transform::GetFirstRow(fCurrentPatch);
500 for(Int_t d1=0; d1<fData[rowindex1].npads; d1++)
502 pad1 = d1 + fData[rowindex1].minpad;
503 for(Int_t j=0; j<10; j++)
505 time1 = j + fData[rowindex1].mintime;
506 charge1 = fData[rowindex1].pads[d1][j];
507 if(charge1==0) continue;
508 AliL3Transform::Slice2Sector(0,i,sector,row);
509 AliL3Transform::Raw2Local(hit,sector,row,pad1,time1);
510 R1 = sqrt(hit[0]*hit[0]+hit[1]*hit[1]);
511 delta1 = atan(hit[2]/R1);
512 hit[0] = hit[0] - AliL3Transform::Row2X(rowrange[0]);
514 for(Int_t i2=i+1; i2<=rowrange[1]; i2++)
516 Int_t rowindex2 = i2 - AliL3Transform::GetFirstRow(fCurrentPatch);
517 for(Int_t d2=0; d2<fData[rowindex2].npads; d2++)
519 pad2 = d2 + fData[rowindex2].minpad;
520 for(Int_t k=0; k<10; k++)
522 time2 = k + fData[rowindex2].mintime;
523 charge2 = fData[rowindex2].pads[d2][k];
524 if(charge2==0) continue;
525 AliL3Transform::Slice2Sector(0,i2,sector,row);
526 AliL3Transform::Raw2Local(hit2,sector,row,pad2,time2);
527 R2 = sqrt(hit2[0]*hit2[0]+hit2[1]*hit2[1]);
528 delta2 = atan(hit2[2]/R2);
529 delta = (charge1*delta1 + charge2*delta2)/(charge1+charge2);
530 hit2[0] = hit2[0] - AliL3Transform::Row2X(rowrange[0]);
532 theta = atan2(hit2[0]-hit[0],hit[1]-hit2[1]);
533 rho = hit[0]*cos(theta)+hit[1]*sin(theta);
534 hist->Fill(theta,rho,delta,charge1+charge2);
543 void AliL3HoughTest::TransformLines2Circle(TH3 *hist,AliL3TrackArray *tracks)
546 for(Int_t i=0; i<tracks->GetNTracks(); i++)
548 AliL3HoughTrack *tr = (AliL3HoughTrack*)tracks->GetCheckedTrack(i);
550 Int_t middlerow = (Int_t)(tr->GetFirstRow()+(tr->GetLastRow()-tr->GetFirstRow())/2);
552 tr->GetLineCrossingPoint(middlerow,hit);
553 hit[0] += AliL3Transform::Row2X(tr->GetFirstRow());
554 Float_t R = sqrt(hit[0]*hit[0] + hit[1]*hit[1]);
555 hit[2] = R*tr->GetTgl();
556 Float_t phi = atan2(hit[1],hit[0]);
557 Float_t theta = tr->GetPsiLine() - AliL3Transform::Pi()/2;
558 Float_t psi = 2*phi - theta;
559 Float_t kappa = 2/R*sin(phi-psi);
560 Float_t delta = atan(hit[2]/R);
561 hist->Fill(kappa,psi,delta,tr->GetWeight());
566 void AliL3HoughTest::Transform2Center(AliL3Histogram *hist)
568 //Choose parameter space to be center of curvature.
572 cerr<<"AliL3HoughTest::TransformC : No data"<<endl;
575 Int_t pad1,pad2,time1,time2,charge1,charge2,sector,row;
576 Float_t r1,r2,phi1,phi2,hit[3],hit2[3];
577 //Float_t phi_0,kappa;
578 for(Int_t i=AliL3Transform::GetFirstRow(fCurrentPatch); i<=AliL3Transform::GetLastRow(fCurrentPatch); i++)
580 Int_t rowindex1 = i - AliL3Transform::GetFirstRow(fCurrentPatch);
581 for(Int_t d1=0; d1<fData[rowindex1].npads; d1++)
583 pad1 = d1 + fData[rowindex1].minpad;
584 for(Int_t j=0; j<10; j++)
586 time1 = j + fData[rowindex1].mintime;
587 charge1 = fData[rowindex1].pads[d1][j];
588 if(charge1==0) continue;
589 AliL3Transform::Slice2Sector(0,i,sector,row);
590 AliL3Transform::Raw2Local(hit,sector,row,pad1,time1);
591 r1 = sqrt(hit[0]*hit[0]+hit[1]*hit[1])/2;
592 phi1 = atan2(hit[1],hit[0]);
594 for(Int_t j=i+1; j<=AliL3Transform::GetLastRow(fCurrentPatch); j++)
596 Int_t rowindex2 = j - AliL3Transform::GetFirstRow(fCurrentPatch);
597 for(Int_t d2=0; d2<fData[rowindex2].npads; d2++)
599 pad2 = d2 + fData[rowindex2].minpad;
600 for(Int_t k=0; k<10; k++)
602 time2 = k + fData[rowindex2].mintime;
603 charge2 = fData[rowindex2].pads[d2][k];
604 if(charge2==0) continue;
605 AliL3Transform::Slice2Sector(0,j,sector,row);
606 AliL3Transform::Raw2Local(hit2,sector,row,pad2,time2);
607 r2 = sqrt(hit2[0]*hit2[0]+hit2[1]*hit2[1])/2;
608 phi2 = atan2(hit2[1],hit2[0]);
609 Float_t yc = (r2-(r1/cos(phi1))*cos(phi2))/(sin(phi2)-tan(phi1)*cos(phi2));
610 Float_t xc = r1/cos(phi1) - (r2*tan(phi1)-r1*sin(phi1)*cos(phi2))/(sin(phi2)-tan(phi1)*cos(phi2));
611 hist->Fill(xc,yc,charge1+charge2);
621 void AliL3HoughTest::FindAbsMaxima(TH3 *hist,Int_t zsearch,Float_t &max_x,Float_t &max_y,Float_t &max_z,Int_t &maxvalue)
624 TH1 *h1 = hist->Project3D("z");
626 TAxis *z = hist->GetZaxis();
628 Int_t n=0,i,zbin[50];
629 for(i=z->GetFirst()+1; i<z->GetLast()-1; i++)
631 int bin1 = h1->GetBin(i-1);
632 int bin2 = h1->GetBin(i);
633 int bin3 = h1->GetBin(i+1);
634 if(h1->GetBinContent(bin2) > h1->GetBinContent(bin1) && h1->GetBinContent(bin2) > h1->GetBinContent(bin3))
637 zpeak[n++]=h1->GetBinCenter(bin2);
641 Int_t zrange[2] = {z->GetFirst(),z->GetLast()};
642 z->SetRange(zbin[0]-zsearch,zbin[0]+zsearch);
644 TH1 *h2 = hist->Project3D("yx");
645 z->SetRange(zrange[0],zrange[1]);
647 TAxis *x = h2->GetXaxis();
648 TAxis *y = h2->GetYaxis();
652 for(Int_t xbin=x->GetFirst(); xbin<=x->GetLast(); xbin++)
654 Float_t xvalue = x->GetBinCenter(xbin);
655 for(Int_t ybin=y->GetFirst(); ybin<=y->GetLast(); ybin++)
657 Float_t yvalue = y->GetBinCenter(ybin);
658 Int_t value = (Int_t)h2->GetBinContent(xbin,ybin);