]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RICH/AliRICHDetect.cxx
Dummy padplane dimensions
[u/mrichter/AliRoot.git] / RICH / AliRICHDetect.cxx
CommitLineData
c1076715 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
17 $Log$
ceccff49 18 Revision 1.7 2000/11/01 15:37:05 jbarbosa
19 Updated to use its own rec. point object.
20
4a5c8776 21 Revision 1.6 2000/10/02 21:28:12 fca
22 Removal of useless dependecies via forward declarations
23
94de3818 24 Revision 1.5 2000/06/30 16:30:28 dibari
25 Disabled writing to rechits.
26
a366fdbe 27 Revision 1.4 2000/06/15 15:46:59 jbarbosa
28 Corrected compilation errors on HP-UX (replaced pow with TMath::Power)
29
00df6e79 30 Revision 1.3 2000/06/13 13:15:41 jbarbosa
31 Still some code cleanup done (variable names)
32
3a3df9e3 33 Revision 1.2 2000/06/12 15:19:30 jbarbosa
34 Cleaned up version.
35
237c933d 36 Revision 1.1 2000/04/19 13:05:14 morsch
37 J. Barbosa's spot reconstruction algorithm.
38
c1076715 39*/
40
41
42#include "AliRICH.h"
43#include "AliRICHPoints.h"
44#include "AliRICHDetect.h"
237c933d 45#include "AliRICHHit.h"
46#include "AliRICHDigit.h"
c1076715 47#include "AliRun.h"
48#include "TParticle.h"
94de3818 49#include "TTree.h"
c1076715 50#include "TMath.h"
51#include "TRandom.h"
52
53
54
55ClassImp(AliRICHDetect)
56//___________________________________________
57AliRICHDetect::AliRICHDetect() : TObject()
58{
237c933d 59
60// Default constructor
61
c1076715 62 //fChambers = 0;
63}
64
65//___________________________________________
66AliRICHDetect::AliRICHDetect(const char *name, const char *title)
67 : TObject()
68{
69
237c933d 70// Constructor
71
c1076715 72 /*fChambers = new TObjArray(7);
73 for (Int_t i=0; i<7; i++) {
74
75 (*fChambers)[i] = new AliRICHchamber();
76
77 } */
78}
79
80
81void AliRICHDetect::Detect()
82{
83
237c933d 84//
85// Detection algorithm
86
87
c1076715 88 //printf("Detection started!\n");
3a3df9e3 89 Float_t omega,steptheta,stepphi,x,y,cx,cy,l,aux1,aux2,aux3,maxi,maxj,maxk,max;
c1076715 90 //Float_t theta,phi,realomega,realtheta;
91 Int_t i,j,k;
ceccff49 92
c1076715 93
94 //const Float_t Noise_Level=0; //Noise Level in percentage of mesh points
95 //const Float_t t=0.6; //Softening of Noise Correction (factor)
96
3a3df9e3 97 const Float_t kPi=3.1415927;
c1076715 98
3a3df9e3 99 const Float_t kHeight=10; //Distance from Radiator to Pads in pads
ceccff49 100
101 const Int_t kSpot=3; //number of passes with spot algorithm
c1076715 102
ceccff49 103 const Int_t kDimensionTheta=50; //Matrix dimension for angle Detection
104 const Int_t kDimensionPhi=50;
105 const Int_t kDimensionOmega=50;
c1076715 106
ceccff49 107 const Float_t SPOTp=.2; //Percentage of spot action
108 //const Int_t np=500; //Number of points to reconstruct elipse
3a3df9e3 109 const Float_t kMaxOmega=65*kPi/180; //Maximum Cherenkov angle to identify
c1076715 110
3a3df9e3 111 Int_t point[kDimensionTheta][kDimensionPhi][kDimensionOmega];
ceccff49 112 Int_t point1[kDimensionTheta][kDimensionPhi][kDimensionOmega];
c1076715 113
3a3df9e3 114 steptheta=kPi/kDimensionTheta;
115 stepphi=kPi/kDimensionPhi;
c1076715 116
117 AliRICHChamber* iChamber;
118
3a3df9e3 119 AliRICH *pRICH = (AliRICH*)gAlice->GetDetector("RICH");
c1076715 120 Int_t ntracks = (Int_t)gAlice->TreeH()->GetEntries();
121 //Int_t ntrks = gAlice->GetNtrack();
122
123 Float_t trackglob[3];
124 Float_t trackloc[3];
125
126 //printf("Got ntracks:%d\n",ntracks);
127 /*TVector *xp = new TVector(1000);
128 TVector *yp = new TVector(1000);
129 TVector *zp = new TVector(1000);
130 TVector *ptrk = new TVector(1000);
131 TVector *phit = new TVector(1000);*/
132
133 //printf("Area de uma elipse com teta 0 e Omega 45:%f",Area(0,45));
134
4a5c8776 135 Int_t track;
c1076715 136
4a5c8776 137 for (track=0; track<ntracks;track++) {
c1076715 138 gAlice->ResetHits();
139 gAlice->TreeH()->GetEvent(track);
3a3df9e3 140 TClonesArray *pHits = pRICH->Hits();
141 if (pHits == 0) return;
142 Int_t nhits = pHits->GetEntriesFast();
c1076715 143 if (nhits == 0) continue;
144 Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
145 gAlice->TreeD()->GetEvent(nent-1);
146 AliRICHHit *mHit = 0;
147 AliRICHDigit *points = 0;
148 //Int_t npoints=0;
149
150 Int_t counter=0;
151 //Initialization
3a3df9e3 152 for(i=0;i<kDimensionTheta;i++)
c1076715 153 {
3a3df9e3 154 for(j=0;j<kDimensionPhi;j++)
c1076715 155 {
3a3df9e3 156 for(k=0;k<kDimensionOmega;k++)
c1076715 157 {
158 counter++;
3a3df9e3 159 point[i][j][k]=0;
160 //printf("Dimensions theta:%d, phi:%d, omega:%d",kDimensionTheta,kDimensionPhi,kDimensionOmega);
c1076715 161 //printf("Resetting %d %d %d, time %d\n",i,j,k,counter);
3a3df9e3 162 //-Noise_Level*(Area(i*kPi/(18*dimension),k*kMaxOmega/dimension)-Area((i-1)*kPi/(18*dimension),(k-1)*kMaxOmega/dimension));
163 //printf("n-%f",-Noise_Level*(Area(i*kPi/(18*dimension),k*kMaxOmega/dimension)-Area((i-1)*kPi/(18*dimension),(k-1)*kMaxOmega/dimension)));
c1076715 164 }
165 }
166 }
3a3df9e3 167 mHit = (AliRICHHit*) pHits->UncheckedAt(0);
c1076715 168 //printf("Aqui vou eu\n");
169 Int_t nch = mHit->fChamber;
170 //printf("Aqui fui eu\n");
94de3818 171 trackglob[0] = mHit->X();
172 trackglob[1] = mHit->Y();
173 trackglob[2] = mHit->Z();
c1076715 174
175 cx=trackglob[0];
176 cy=trackglob[2];
177
178
179 //printf("Chamber processed:%d\n",nch);
ceccff49 180
181 printf("\nChamber %d, particle at: %3.1f %3.1f,\n",nch,trackglob[0],trackglob[2]);
c1076715 182
3a3df9e3 183 iChamber = &(pRICH->Chamber(nch-1));
c1076715 184
185 //printf("Nch:%d\n",nch);
186
187 iChamber->GlobaltoLocal(trackglob,trackloc);
188
3a3df9e3 189 //printf("Transformation 1: %3.1f %3.1f %3.1f\n",trackloc[0],trackloc[1],trackloc[2]);
c1076715 190
191
192 iChamber->LocaltoGlobal(trackloc,trackglob);
193
3a3df9e3 194 //printf("Transformation 2: %3.1f %3.1f %3.1f\n",trackglob[0],trackglob[1],trackglob[2]);
c1076715 195
196
197
198
3a3df9e3 199 TClonesArray *pDigits = pRICH->DigitsAddress(nch-1);
200 Int_t ndigits = pDigits->GetEntriesFast();
c1076715 201
202 //printf("Got %d digits\n",ndigits);
203
204 //printf("Starting calculations\n");
205
3a3df9e3 206 for(Float_t theta=0;theta<kPi/18;theta+=steptheta)
c1076715 207 {
3a3df9e3 208 for(Float_t phi=0;phi<=kPi/3;phi+=stepphi)
c1076715 209 {
210 for (Int_t dig=0;dig<ndigits;dig++)
211 {
3a3df9e3 212 points=(AliRICHDigit*) pDigits->UncheckedAt(dig);
c1076715 213
214 x=points->fPadX-cx;
215 y=points->fPadY-cy;
216 //printf("Loaded digit %d with coordinates x:%f, y%f\n",dig,x,y);
217 //cout<<"x="<<x<<" y="<<y<<endl;
218
00df6e79 219 if (sqrt(TMath::Power(x,2)+TMath::Power(y,2))<kHeight*tan(theta+kMaxOmega)*3/4)
c1076715 220 {
221
3a3df9e3 222 l=kHeight/cos(theta);
c1076715 223
224 aux1=-y*sin(phi)+x*cos(phi);
225 aux2=y*cos(phi)+x*sin(phi);
00df6e79 226 aux3=( TMath::Power(aux1,2)+TMath::Power(cos(theta)*aux2 ,2))/TMath::Power(sin(theta)*aux2+l,2);
c1076715 227 //cout<<"aux1="<<aux1<<" aux2="<<aux2<<" aux3="<<aux3;
228
3a3df9e3 229 omega=atan(sqrt(aux3));
230 //printf("Omega: %f\n",omega);
c1076715 231
3a3df9e3 232 //cout<<"\ni="<<i<<" theta="<<Int_t(2*theta*dimension/kPi)<<" phi="<<Int_t(2*phi*dimension/kPi)<<" omega="<<Int_t(2*omega*dimension/kPi)<<endl<<endl;
c1076715 233 //{Int_t lixo;cin>>lixo;}
3a3df9e3 234 if(omega<kMaxOmega)point[Int_t(2*theta*kDimensionTheta/kPi)][Int_t(2*phi*kDimensionPhi/kPi)][Int_t(omega*kDimensionOmega/kMaxOmega)]+=1;
235 //if(omega<kMaxOmega)point[Int_t(theta)][Int_t(phi)][Int_t(omega)]+=1;
c1076715 236 }
237 }
238 }
239 }
240
241
c1076715 242 //SPOT execute twice
ceccff49 243 for(Int_t s=0;s<kSpot;s++)
c1076715 244 {
ceccff49 245 printf(" Applying Spot algorithm, pass %d\n", s);
246
c1076715 247 //buffer copy
3a3df9e3 248 for(i=0;i<=kDimensionTheta;i++)
ceccff49 249 {
250 for(j=0;j<=kDimensionPhi;j++)
251 {
252 for(k=0;k<=kDimensionOmega;k++)
253 {
254 point1[i][j][k]=point[i][j][k];
255 }
256 }
257 }
258
c1076715 259 //SPOT algorithm
3a3df9e3 260 for(i=1;i<kDimensionTheta;i++)
ceccff49 261 {
262 for(j=1;j<kDimensionPhi;j++)
c1076715 263 {
ceccff49 264 for(k=1;k<kDimensionOmega;k++)
c1076715 265 {
ceccff49 266 if((point[i][k][j]>point[i-1][k][j])&&(point[i][k][j]>point[i+1][k][j])&&
267 (point[i][k][j]>point[i][k-1][j])&&(point[i][k][j]>point[i][k+1][j])&&
268 (point[i][k][j]>point[i][k][j-1])&&(point[i][k][j]>point[i][k][j+1]))
269 {
270 //cout<<"SPOT"<<endl;
271 //Execute SPOT on point
272 point1[i][j][k]+=Int_t(SPOTp*(point[i-1][k][j]+point[i+1][k][j]+point[i][k-1][j]+point[i][k+1][j]+point[i][k][j-1]+point[i][k][j+1]));
273 point1[i-1][k][j]=Int_t(SPOTp*point[i-1][k][j]);
274 point1[i+1][k][j]=Int_t(SPOTp*point[i+1][k][j]);
275 point1[i][k-1][j]=Int_t(SPOTp*point[i][k-1][j]);
276 point1[i][k+1][j]=Int_t(SPOTp*point[i][k+1][j]);
277 point1[i][k][j-1]=Int_t(SPOTp*point[i][k][j-1]);
278 point1[i][k][j+1]=Int_t(SPOTp*point[i][k][j+1]);
279 }
c1076715 280 }
281 }
ceccff49 282 }
283
c1076715 284 //copy from buffer copy
3a3df9e3 285 for(i=1;i<kDimensionTheta;i++)
ceccff49 286 {
287 for(j=1;j<kDimensionPhi;j++)
288 {
289 for(k=1;k<kDimensionOmega;k++)
290 {
291 point[i][j][k]=point1[i][j][k];
292 //if(point1[i][j][k] != 0)
293 //printf("Last transfer point: %d, point1, %d\n",point[i][j][k],point1[i][j][k]);
294 }
295 }
296 }
297 }
c1076715 298
299
300 //Identification is equivalent to maximum determination
301 max=0;maxi=0;maxj=0;maxk=0;
302
ceccff49 303 printf(" Proceeding to identification");
c1076715 304
3a3df9e3 305 for(i=1;i<kDimensionTheta-3;i++)
306 for(j=1;j<=kDimensionPhi-3;j++)
307 for(k=0;k<=kDimensionOmega;k++)
ceccff49 308 if(point[i][j][k]>max)
309 {
310 //cout<<"maxi="<<i*90/dimension<<" maxj="<<j*90/dimension<<" maxk="<<k*kMaxOmega/dimension*180/kPi<<" max="<<max<<endl;
311 maxi=i;maxj=j;maxk=k;
312 max=point[i][j][k];
313 printf(".");
314 //printf("Max Omega %f, Max Theta %f, Max Phi %f\n",maxk,maxi,maxj);
315 }
316 printf("\n");
c1076715 317
3a3df9e3 318 //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",h,cx,cy,maxk*kPi/(kDimensionTheta*4));
ceccff49 319 printf(" Indentified cerenkov angle: %f\n", maxk*kPi/(kDimensionTheta*4));
3a3df9e3 320 //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",kHeight,cx,cy,maxk);
c1076715 321
322
323 //fscanf(omegas,"%f",&realomega);
324 //fscanf(thetas,"%f",&realtheta);
325 //printf("Real Omega: %f",realomega);
3a3df9e3 326 //cout<<"Detected:theta="<<maxi*90/kDimensionTheta<<"phi="<<maxj*90/kDimensionPhi<<"omega="<<maxk*kMaxOmega/kDimensionOmega*180/kPi<<" OmegaError="<<fabs(maxk*kMaxOmega/kDimensionOmega*180/kPi-realomega)<<" ThetaError="<<fabs(maxi*90/kDimensionTheta-realtheta)<<endl<<endl;
c1076715 327
3a3df9e3 328 //fprintf(results,"Center Coordinates, cx=%6.2f cy=%6.2f, Real Omega=%6.2f, Detected Omega=%6.2f, Omega Error=%6.2f Theta Error=%6.2f\n",cx,cy,realomega,maxk*kMaxOmega/kDimensionOmega*180/kPi,fabs(maxk*kMaxOmega/kDimensionOmega*180/kPi-realomega),fabs(maxi*90/kDimensionTheta-realtheta));
c1076715 329
330 /*for(j=0;j<np;j++)
3a3df9e3 331 pointpp(maxj*90/kDimensionTheta,maxi*90/kDimensionPhi,maxk*kMaxOmega/kDimensionOmega*180/kPi,cx,cy);//Generates a point on the elipse*/
c1076715 332
333
334 //Start filling rec. hits
335
a366fdbe 336 Float_t rechit[6];
c1076715 337
3a3df9e3 338 rechit[0] = (Float_t)( maxi*kPi/(kDimensionTheta*4));
339 rechit[1] = (Float_t)( maxj*kPi/(kDimensionPhi*4));
340 rechit[2] = (Float_t)( maxk*kPi/(kDimensionOmega*4));
c1076715 341 //rechit[0] = (Float_t)( maxi);
342 //rechit[1] = (Float_t)( maxj);
343 //rechit[2] = (Float_t)( maxk);
344 rechit[3] = cx;
345 rechit[4] = cy;
a366fdbe 346 rechit[5] = 0.5;
c1076715 347
348 //printf ("track %d, theta %f, phi %f, omega %f\n\n\n",track,rechit[0],rechit[1],rechit[2]);
349
350 // fill rechits
4a5c8776 351 pRICH->AddRecHit3D(nch-1,rechit);
ceccff49 352 //printf("Chamber:%d",nch);
c1076715 353 }
354 //printf("\n\n\n\n");
355 gAlice->TreeR()->Fill();
356 //TTree *TR=gAlice->TreeR();
357 //Stat_t ndig=TR->GetEntries();
358 TClonesArray *fRec;
237c933d 359 for (i=0;i<kNCH;i++) {
4a5c8776 360 fRec=pRICH->RecHitsAddress3D(i);
c1076715 361 int ndig=fRec->GetEntriesFast();
362 printf ("Chamber %d, rings %d\n",i,ndig);
363 }
364 //printf("Number of rec. hits: %d",ndig);
4a5c8776 365 pRICH->ResetRecHits3D();
c1076715 366 //char hname[30];
367 //sprintf(hname,"TreeR%d",track);
368 //gAlice->TreeR()->Write(hname);
369
370}
371
3a3df9e3 372Float_t AliRICHDetect:: Area(Float_t theta,Float_t omega)
c1076715 373{
237c933d 374
375//
376// Calculates area of an ellipse for given incidence angles
377
378
c1076715 379 Float_t area;
3a3df9e3 380 const Float_t kHeight=9.25; //Distance from Radiator to Pads in pads
c1076715 381
00df6e79 382 area=TMath::Pi()*TMath::Power(kHeight*tan(omega),2)/TMath::Power(TMath::Power(cos(theta),2)-TMath::Power(tan(omega)*sin(theta),2),3/2);
c1076715 383
384 return (area);
385}
386
387/*Int_t ***AliRICHDetect::i3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
388// allocate a Float_t 3tensor with range t[nrl..nrh][ncl..nch][ndl..ndh]
389{
390long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
391Int_t ***t;
392
393// allocate pointers to pointers to rows
394t=(Int_t ***) malloc((size_t)((nrow+NR_END)*sizeof(Int_t**)));
395if (!t) printf("allocation failure 1 in f3tensor()");
396t += NR_END;
397t -= nrl;
398
399// allocate pointers to rows and set pointers to them
400t[nrl]=(Int_t **) malloc((size_t)((nrow*ncol+NR_END)*sizeof(Int_t*)));
401if (!t[nrl]) printf("allocation failure 2 in f3tensor()");
402t[nrl] += NR_END;
403t[nrl] -= ncl;
404
405// allocate rows and set pointers to them
406t[nrl][ncl]=(Int_t *) malloc((size_t)((nrow*ncol*ndep+NR_END)*sizeof(Int_t)));
407if (!t[nrl][ncl]) printf("allocation failure 3 in f3tensor()");
408t[nrl][ncl] += NR_END;
409t[nrl][ncl] -= ndl;
410
411for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
412for(i=nrl+1;i<=nrh;i++) {
413t[i]=t[i-1]+ncol;
414t[i][ncl]=t[i-1][ncl]+ncol*ndep;
415for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
416}
417
418// return pointer to array of pointers to rows
419return t;
420}*/
421
3a3df9e3 422/*void pointpp(Float_t alfa,Float_t theta,Float_t omega,Float_t cx,Float_t cy)
c1076715 423 {
424 Int_t s;
3a3df9e3 425 Float_t fiducial=h*tan((omega+theta)*kPi/180),l=h/cos(theta*kPi/180),xtrial,y,c0,c1,c2;
c1076715 426
427 //cout<<"fiducial="<<fiducial<<endl;
428
429 c0=0;c1=0;c2=0;
430 while((c1*c1-4*c2*c0)<=0)
431 {
432 //Choose which side to go...
433 if(aleat(1)>.5) s=1; else s=-1;
434 //Trial a y
435 y=s*aleat(fiducial);
3a3df9e3 436 Float_t alfa1=alfa*kPi/180;
437 Float_t theta1=theta*kPi/180;
438 Float_t omega1=omega*kPi/180;
c1076715 439 //Solve the eq for a trial x
00df6e79 440 c0=-TMath::Power(y*cos(alfa1)*cos(theta1),2)-TMath::Power(y*sin(alfa1),2)+TMath::Power(l*tan(omega1),2)+2*l*y*cos(alfa1)*sin(theta1)*TMath::Power(tan(omega1),2)+TMath::Power(y*cos(alfa1)*sin(theta1)*tan(omega1),2);
441 c1=2*y*cos(alfa1)*sin(alfa1)-2*y*cos(alfa1)*TMath::Power(cos(theta1),2)*sin(alfa1)+2*l*sin(alfa1)*sin(theta1)*TMath::Power(tan(omega1),2)+2*y*cos(alfa1)*sin(alfa1)*TMath::Power(sin(theta1),2)*TMath::Power(tan(omega1),2);
442 c2=-TMath::Power(cos(alfa1),2)-TMath::Power(cos(theta1)*sin(alfa1),2)+TMath::Power(sin(alfa1)*sin(theta1)*tan(omega1),2);
c1076715 443 //cout<<"Trial: y="<<y<<"c0="<<c0<<" c1="<<c1<<" c2="<<c2<<endl;
444 }
445 //Choose which side to go...
446 if(aleat(1)>.5) s=1; else s=-1;
447 xtrial=cx+(-c1+s*sqrt(c1*c1-4*c2*c0))/(2*c2);
448 //cout<<"x="<<xtrial<<" y="<<cy+y<<endl;
449 fprintf(final,"%f %f\n",xtrial,cy+y);
450 }*/
451
452
453
454
455
456