1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.1 2000/04/19 13:05:14 morsch
19 J. Barbosa's spot reconstruction algorithm.
25 #include "AliRICHPoints.h"
26 #include "AliRICHDetect.h"
27 #include "AliRICHHit.h"
28 #include "AliRICHDigit.h"
30 #include "TParticle.h"
36 ClassImp(AliRICHDetect)
37 //___________________________________________
38 AliRICHDetect::AliRICHDetect() : TObject()
41 // Default constructor
46 //___________________________________________
47 AliRICHDetect::AliRICHDetect(const char *name, const char *title)
53 /*fChambers = new TObjArray(7);
54 for (Int_t i=0; i<7; i++) {
56 (*fChambers)[i] = new AliRICHchamber();
62 void AliRICHDetect::Detect()
66 // Detection algorithm
69 //printf("Detection started!\n");
70 Float_t OMEGA,steptheta,stepphi,x,y,cx,cy,l,aux1,aux2,aux3,maxi,maxj,maxk,max;
71 //Float_t theta,phi,realomega,realtheta;
74 //const Float_t Noise_Level=0; //Noise Level in percentage of mesh points
75 //const Float_t t=0.6; //Softening of Noise Correction (factor)
77 const Float_t Pii=3.1415927;
79 const Float_t h=10; //Distance from Radiator to Pads in pads
82 const Int_t dimensiontheta=100; //Matrix dimension for angle Detection
83 const Int_t dimensionphi=100;
84 const Int_t dimensionOMEGA=100;
86 //const Float_t SPOTp=.2; //Percentage of spot action
87 //const Int_t np=500; //Number of points to reconstruct elipse
88 const Float_t maxOMEGA=65*Pii/180; //Maximum Cherenkov angle to identify
90 Int_t Point[dimensiontheta][dimensionphi][dimensionOMEGA];
91 //Int_t Point1[dimensiontheta][dimensionphi][dimensionOMEGA];
93 steptheta=Pii/dimensiontheta;
94 stepphi=Pii/dimensionphi;
96 AliRICHChamber* iChamber;
98 AliRICH *RICH = (AliRICH*)gAlice->GetDetector("RICH");
99 Int_t ntracks = (Int_t)gAlice->TreeH()->GetEntries();
100 //Int_t ntrks = gAlice->GetNtrack();
102 Float_t trackglob[3];
105 //printf("Got ntracks:%d\n",ntracks);
106 /*TVector *xp = new TVector(1000);
107 TVector *yp = new TVector(1000);
108 TVector *zp = new TVector(1000);
109 TVector *ptrk = new TVector(1000);
110 TVector *phit = new TVector(1000);*/
112 //printf("Area de uma elipse com teta 0 e Omega 45:%f",Area(0,45));
115 for (Int_t track=0; track<ntracks;track++) {
117 gAlice->TreeH()->GetEvent(track);
118 TClonesArray *Hits = RICH->Hits();
119 if (Hits == 0) return;
120 Int_t nhits = Hits->GetEntriesFast();
121 if (nhits == 0) continue;
122 Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
123 gAlice->TreeD()->GetEvent(nent-1);
124 AliRICHHit *mHit = 0;
125 AliRICHDigit *points = 0;
130 for(i=0;i<dimensiontheta;i++)
132 for(j=0;j<dimensionphi;j++)
134 for(k=0;k<dimensionOMEGA;k++)
138 //printf("Dimensions theta:%d, phi:%d, omega:%d",dimensiontheta,dimensionphi,dimensionOMEGA);
139 //printf("Resetting %d %d %d, time %d\n",i,j,k,counter);
140 //-Noise_Level*(Area(i*Pii/(18*dimension),k*maxOMEGA/dimension)-Area((i-1)*Pii/(18*dimension),(k-1)*maxOMEGA/dimension));
141 //printf("n-%f",-Noise_Level*(Area(i*Pii/(18*dimension),k*maxOMEGA/dimension)-Area((i-1)*Pii/(18*dimension),(k-1)*maxOMEGA/dimension)));
145 mHit = (AliRICHHit*) Hits->UncheckedAt(0);
146 //printf("Aqui vou eu\n");
147 Int_t nch = mHit->fChamber;
148 //printf("Aqui fui eu\n");
149 trackglob[0] = mHit->fX;
150 trackglob[1] = mHit->fY;
151 trackglob[2] = mHit->fZ;
157 //printf("Chamber processed:%d\n",nch);
158 printf("Center processed: %3.1f %3.1f %3.1f\n",trackglob[0],trackglob[1],trackglob[2]);
160 iChamber = &(RICH->Chamber(nch-1));
162 //printf("Nch:%d\n",nch);
164 iChamber->GlobaltoLocal(trackglob,trackloc);
166 printf("Transformation 1: %3.1f %3.1f %3.1f\n",trackloc[0],trackloc[1],trackloc[2]);
169 iChamber->LocaltoGlobal(trackloc,trackglob);
171 printf("Transformation 2: %3.1f %3.1f %3.1f\n",trackglob[0],trackglob[1],trackglob[2]);
176 TClonesArray *Digits = RICH->DigitsAddress(nch-1);
177 Int_t ndigits = Digits->GetEntriesFast();
179 //printf("Got %d digits\n",ndigits);
181 //printf("Starting calculations\n");
183 for(Float_t theta=0;theta<Pii/18;theta+=steptheta)
185 for(Float_t phi=0;phi<=Pii/3;phi+=stepphi)
187 for (Int_t dig=0;dig<ndigits;dig++)
189 points=(AliRICHDigit*) Digits->UncheckedAt(dig);
193 //printf("Loaded digit %d with coordinates x:%f, y%f\n",dig,x,y);
194 //cout<<"x="<<x<<" y="<<y<<endl;
196 if (sqrt(pow(x,2)+pow(y,2))<h*tan(theta+maxOMEGA)*3/4)
201 aux1=-y*sin(phi)+x*cos(phi);
202 aux2=y*cos(phi)+x*sin(phi);
203 aux3=( pow(aux1,2)+pow(cos(theta)*aux2 ,2))/pow(sin(theta)*aux2+l,2);
204 //cout<<"aux1="<<aux1<<" aux2="<<aux2<<" aux3="<<aux3;
206 OMEGA=atan(sqrt(aux3));
207 //printf("Omega: %f\n",OMEGA);
209 //cout<<"\ni="<<i<<" theta="<<Int_t(2*theta*dimension/Pii)<<" phi="<<Int_t(2*phi*dimension/Pii)<<" OMEGA="<<Int_t(2*OMEGA*dimension/Pii)<<endl<<endl;
210 //{Int_t lixo;cin>>lixo;}
211 if(OMEGA<maxOMEGA)Point[Int_t(2*theta*dimensiontheta/Pii)][Int_t(2*phi*dimensionphi/Pii)][Int_t(OMEGA*dimensionOMEGA/maxOMEGA)]+=1;
212 //if(OMEGA<maxOMEGA)Point[Int_t(theta)][Int_t(phi)][Int_t(OMEGA)]+=1;
224 for(i=0;i<=dimensiontheta;i++)
225 for(j=0;j<=dimensionphi;j++)
226 for(k=0;k<=dimensionOMEGA;k++)
227 Point1[i][j][k]=Point[i][j][k];
229 cout<<"COM SPOT!"<<endl;{Int_t lixo;cin>>lixo;}
231 for(i=1;i<dimensiontheta;i++)
232 for(j=1;j<dimensionphi;j++)
233 for(k=1;k<dimensionOMEGA;k++)
235 if((Point[i][k][j]>Point[i-1][k][j])&&(Point[i][k][j]>Point[i+1][k][j])&&
236 (Point[i][k][j]>Point[i][k-1][j])&&(Point[i][k][j]>Point[i][k+1][j])&&
237 (Point[i][k][j]>Point[i][k][j-1])&&(Point[i][k][j]>Point[i][k][j+1]))
239 //cout<<"SPOT"<<endl;
240 //Execute SPOT on point
241 Point1[i][j][k]+=int(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]));
242 Point1[i-1][k][j]=int(SPOTp*Point[i-1][k][j]);
243 Point1[i+1][k][j]=Int_t(SPOTp*Point[i+1][k][j]);
244 Point1[i][k-1][j]=Int_t(SPOTp*Point[i][k-1][j]);
245 Point1[i][k+1][j]=Int_t(SPOTp*Point[i][k+1][j]);
246 Point1[i][k][j-1]=Int_t(SPOTp*Point[i][k][j-1]);
247 Point1[i][k][j+1]=Int_t(SPOTp*Point[i][k][j+1]);
250 //copy from buffer copy
251 for(i=1;i<dimensiontheta;i++)
252 for(j=1;j<dimensionphi;j++)
253 for(k=1;k<dimensionOMEGA;k++)
254 Point[i][j][k]=Point1[i][j][k];
259 //Identification is equivalent to maximum determination
260 max=0;maxi=0;maxj=0;maxk=0;
262 //cout<<"Proceeding to Identification"<<endl;
264 for(i=1;i<dimensiontheta-3;i++)
265 for(j=1;j<=dimensionphi-3;j++)
266 for(k=0;k<=dimensionOMEGA;k++)
267 if(Point[i][j][k]>max)
269 //cout<<"maxi="<<i*90/dimension<<" maxj="<<j*90/dimension<<" maxk="<<k*maxOMEGA/dimension*180/Pii<<" max="<<max<<endl;
270 maxi=i;maxj=j;maxk=k;
272 //printf("Max Omega %f, Max Theta %f, Max Phi %f\n",maxk,maxi,maxj);
275 //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",h,cx,cy,maxk*Pii/(dimensiontheta*4));
276 //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",h,cx,cy,maxk);
279 //fscanf(omegas,"%f",&realomega);
280 //fscanf(thetas,"%f",&realtheta);
281 //printf("Real Omega: %f",realomega);
282 //cout<<"Detected:theta="<<maxi*90/dimensiontheta<<"phi="<<maxj*90/dimensionphi<<"OMEGA="<<maxk*maxOMEGA/dimensionOMEGA*180/Pii<<" OmegaError="<<fabs(maxk*maxOMEGA/dimensionOMEGA*180/Pii-realomega)<<" ThetaError="<<fabs(maxi*90/dimensiontheta-realtheta)<<endl<<endl;
284 //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*maxOMEGA/dimensionOMEGA*180/Pii,fabs(maxk*maxOMEGA/dimensionOMEGA*180/Pii-realomega),fabs(maxi*90/dimensiontheta-realtheta));
287 Pointpp(maxj*90/dimensiontheta,maxi*90/dimensionphi,maxk*maxOMEGA/dimensionOMEGA*180/Pii,cx,cy);//Generates a point on the elipse*/
290 //Start filling rec. hits
294 rechit[0] = (Float_t)( maxi*Pii/(dimensiontheta*4));
295 rechit[1] = (Float_t)( maxj*Pii/(dimensionphi*4));
296 rechit[2] = (Float_t)( maxk*Pii/(dimensionOMEGA*4));
297 //rechit[0] = (Float_t)( maxi);
298 //rechit[1] = (Float_t)( maxj);
299 //rechit[2] = (Float_t)( maxk);
303 //printf ("track %d, theta %f, phi %f, omega %f\n\n\n",track,rechit[0],rechit[1],rechit[2]);
306 RICH->AddRecHit(nch-1,rechit);
308 //printf("\n\n\n\n");
309 gAlice->TreeR()->Fill();
310 //TTree *TR=gAlice->TreeR();
311 //Stat_t ndig=TR->GetEntries();
313 for (i=0;i<kNCH;i++) {
314 fRec=RICH->RecHitsAddress(i);
315 int ndig=fRec->GetEntriesFast();
316 printf ("Chamber %d, rings %d\n",i,ndig);
318 //printf("Number of rec. hits: %d",ndig);
319 RICH->ResetRecHits();
321 //sprintf(hname,"TreeR%d",track);
322 //gAlice->TreeR()->Write(hname);
326 Float_t AliRICHDetect:: Area(Float_t theta,Float_t OMEGA)
330 // Calculates area of an ellipse for given incidence angles
334 const Float_t h=9.25; //Distance from Radiator to Pads in pads
336 area=TMath::Pi()*pow(h*tan(OMEGA),2)/pow(pow(cos(theta),2)-pow(tan(OMEGA)*sin(theta),2),3/2);
341 /*Int_t ***AliRICHDetect::i3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
342 // allocate a Float_t 3tensor with range t[nrl..nrh][ncl..nch][ndl..ndh]
344 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
347 // allocate pointers to pointers to rows
348 t=(Int_t ***) malloc((size_t)((nrow+NR_END)*sizeof(Int_t**)));
349 if (!t) printf("allocation failure 1 in f3tensor()");
353 // allocate pointers to rows and set pointers to them
354 t[nrl]=(Int_t **) malloc((size_t)((nrow*ncol+NR_END)*sizeof(Int_t*)));
355 if (!t[nrl]) printf("allocation failure 2 in f3tensor()");
359 // allocate rows and set pointers to them
360 t[nrl][ncl]=(Int_t *) malloc((size_t)((nrow*ncol*ndep+NR_END)*sizeof(Int_t)));
361 if (!t[nrl][ncl]) printf("allocation failure 3 in f3tensor()");
362 t[nrl][ncl] += NR_END;
365 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
366 for(i=nrl+1;i<=nrh;i++) {
368 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
369 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
372 // return pointer to array of pointers to rows
376 /*void Pointpp(Float_t alfa,Float_t theta,Float_t OMEGA,Float_t cx,Float_t cy)
379 Float_t fiducial=h*tan((OMEGA+theta)*Pii/180),l=h/cos(theta*Pii/180),xtrial,y,c0,c1,c2;
381 //cout<<"fiducial="<<fiducial<<endl;
384 while((c1*c1-4*c2*c0)<=0)
386 //Choose which side to go...
387 if(aleat(1)>.5) s=1; else s=-1;
390 Float_t alfa1=alfa*Pii/180;
391 Float_t theta1=theta*Pii/180;
392 Float_t OMEGA1=OMEGA*Pii/180;
393 //Solve the eq for a trial x
394 c0=-pow(y*cos(alfa1)*cos(theta1),2)-pow(y*sin(alfa1),2)+pow(l*tan(OMEGA1),2)+2*l*y*cos(alfa1)*sin(theta1)*pow(tan(OMEGA1),2)+pow(y*cos(alfa1)*sin(theta1)*tan(OMEGA1),2);
395 c1=2*y*cos(alfa1)*sin(alfa1)-2*y*cos(alfa1)*pow(cos(theta1),2)*sin(alfa1)+2*l*sin(alfa1)*sin(theta1)*pow(tan(OMEGA1),2)+2*y*cos(alfa1)*sin(alfa1)*pow(sin(theta1),2)*pow(tan(OMEGA1),2);
396 c2=-pow(cos(alfa1),2)-pow(cos(theta1)*sin(alfa1),2)+pow(sin(alfa1)*sin(theta1)*tan(OMEGA1),2);
397 //cout<<"Trial: y="<<y<<"c0="<<c0<<" c1="<<c1<<" c2="<<c2<<endl;
399 //Choose which side to go...
400 if(aleat(1)>.5) s=1; else s=-1;
401 xtrial=cx+(-c1+s*sqrt(c1*c1-4*c2*c0))/(2*c2);
402 //cout<<"x="<<xtrial<<" y="<<cy+y<<endl;
403 fprintf(final,"%f %f\n",xtrial,cy+y);