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 **************************************************************************/
22 #include "AliRICHPoints.h"
23 #include "AliRICHDetect.h"
24 #include "DataStructures.h"
26 #include "TParticle.h"
32 ClassImp(AliRICHDetect)
33 //___________________________________________
34 AliRICHDetect::AliRICHDetect() : TObject()
39 //___________________________________________
40 AliRICHDetect::AliRICHDetect(const char *name, const char *title)
44 /*fChambers = new TObjArray(7);
45 for (Int_t i=0; i<7; i++) {
47 (*fChambers)[i] = new AliRICHchamber();
53 void AliRICHDetect::Detect()
56 //printf("Detection started!\n");
57 Float_t OMEGA,steptheta,stepphi,x,y,cx,cy,l,aux1,aux2,aux3,maxi,maxj,maxk,max;
58 //Float_t theta,phi,realomega,realtheta;
61 //const Float_t Noise_Level=0; //Noise Level in percentage of mesh points
62 //const Float_t t=0.6; //Softening of Noise Correction (factor)
64 const Float_t Pii=3.1415927;
66 const Float_t h=10; //Distance from Radiator to Pads in pads
69 const Int_t dimensiontheta=100; //Matrix dimension for angle Detection
70 const Int_t dimensionphi=100;
71 const Int_t dimensionOMEGA=100;
73 //const Float_t SPOTp=.2; //Percentage of spot action
74 //const Int_t np=500; //Number of points to reconstruct elipse
75 const Float_t maxOMEGA=65*Pii/180; //Maximum Cherenkov angle to identify
77 Int_t Point[dimensiontheta][dimensionphi][dimensionOMEGA];
78 //Int_t Point1[dimensiontheta][dimensionphi][dimensionOMEGA];
80 steptheta=Pii/dimensiontheta;
81 stepphi=Pii/dimensionphi;
83 AliRICHChamber* iChamber;
85 AliRICH *RICH = (AliRICH*)gAlice->GetDetector("RICH");
86 Int_t ntracks = (Int_t)gAlice->TreeH()->GetEntries();
87 //Int_t ntrks = gAlice->GetNtrack();
92 //printf("Got ntracks:%d\n",ntracks);
93 /*TVector *xp = new TVector(1000);
94 TVector *yp = new TVector(1000);
95 TVector *zp = new TVector(1000);
96 TVector *ptrk = new TVector(1000);
97 TVector *phit = new TVector(1000);*/
99 //printf("Area de uma elipse com teta 0 e Omega 45:%f",Area(0,45));
102 for (Int_t track=0; track<ntracks;track++) {
104 gAlice->TreeH()->GetEvent(track);
105 TClonesArray *Hits = RICH->Hits();
106 if (Hits == 0) return;
107 Int_t nhits = Hits->GetEntriesFast();
108 if (nhits == 0) continue;
109 Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
110 gAlice->TreeD()->GetEvent(nent-1);
111 AliRICHHit *mHit = 0;
112 AliRICHDigit *points = 0;
117 for(i=0;i<dimensiontheta;i++)
119 for(j=0;j<dimensionphi;j++)
121 for(k=0;k<dimensionOMEGA;k++)
125 //printf("Dimensions theta:%d, phi:%d, omega:%d",dimensiontheta,dimensionphi,dimensionOMEGA);
126 //printf("Resetting %d %d %d, time %d\n",i,j,k,counter);
127 //-Noise_Level*(Area(i*Pii/(18*dimension),k*maxOMEGA/dimension)-Area((i-1)*Pii/(18*dimension),(k-1)*maxOMEGA/dimension));
128 //printf("n-%f",-Noise_Level*(Area(i*Pii/(18*dimension),k*maxOMEGA/dimension)-Area((i-1)*Pii/(18*dimension),(k-1)*maxOMEGA/dimension)));
132 mHit = (AliRICHHit*) Hits->UncheckedAt(0);
133 //printf("Aqui vou eu\n");
134 Int_t nch = mHit->fChamber;
135 //printf("Aqui fui eu\n");
136 trackglob[0] = mHit->fX;
137 trackglob[1] = mHit->fY;
138 trackglob[2] = mHit->fZ;
144 //printf("Chamber processed:%d\n",nch);
145 printf("Center processed: %3.1f %3.1f %3.1f\n",trackglob[0],trackglob[1],trackglob[2]);
147 iChamber = &(RICH->Chamber(nch-1));
149 //printf("Nch:%d\n",nch);
151 iChamber->GlobaltoLocal(trackglob,trackloc);
153 printf("Transformation 1: %3.1f %3.1f %3.1f\n",trackloc[0],trackloc[1],trackloc[2]);
156 iChamber->LocaltoGlobal(trackloc,trackglob);
158 printf("Transformation 2: %3.1f %3.1f %3.1f\n",trackglob[0],trackglob[1],trackglob[2]);
163 TClonesArray *Digits = RICH->DigitsAddress(nch-1);
164 Int_t ndigits = Digits->GetEntriesFast();
166 //printf("Got %d digits\n",ndigits);
168 //printf("Starting calculations\n");
170 for(Float_t theta=0;theta<Pii/18;theta+=steptheta)
172 for(Float_t phi=0;phi<=Pii/3;phi+=stepphi)
174 for (Int_t dig=0;dig<ndigits;dig++)
176 points=(AliRICHDigit*) Digits->UncheckedAt(dig);
180 //printf("Loaded digit %d with coordinates x:%f, y%f\n",dig,x,y);
181 //cout<<"x="<<x<<" y="<<y<<endl;
183 if (sqrt(pow(x,2)+pow(y,2))<h*tan(theta+maxOMEGA)*3/4)
188 aux1=-y*sin(phi)+x*cos(phi);
189 aux2=y*cos(phi)+x*sin(phi);
190 aux3=( pow(aux1,2)+pow(cos(theta)*aux2 ,2))/pow(sin(theta)*aux2+l,2);
191 //cout<<"aux1="<<aux1<<" aux2="<<aux2<<" aux3="<<aux3;
193 OMEGA=atan(sqrt(aux3));
194 //printf("Omega: %f\n",OMEGA);
196 //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;
197 //{Int_t lixo;cin>>lixo;}
198 if(OMEGA<maxOMEGA)Point[Int_t(2*theta*dimensiontheta/Pii)][Int_t(2*phi*dimensionphi/Pii)][Int_t(OMEGA*dimensionOMEGA/maxOMEGA)]+=1;
199 //if(OMEGA<maxOMEGA)Point[Int_t(theta)][Int_t(phi)][Int_t(OMEGA)]+=1;
211 for(i=0;i<=dimensiontheta;i++)
212 for(j=0;j<=dimensionphi;j++)
213 for(k=0;k<=dimensionOMEGA;k++)
214 Point1[i][j][k]=Point[i][j][k];
216 cout<<"COM SPOT!"<<endl;{Int_t lixo;cin>>lixo;}
218 for(i=1;i<dimensiontheta;i++)
219 for(j=1;j<dimensionphi;j++)
220 for(k=1;k<dimensionOMEGA;k++)
222 if((Point[i][k][j]>Point[i-1][k][j])&&(Point[i][k][j]>Point[i+1][k][j])&&
223 (Point[i][k][j]>Point[i][k-1][j])&&(Point[i][k][j]>Point[i][k+1][j])&&
224 (Point[i][k][j]>Point[i][k][j-1])&&(Point[i][k][j]>Point[i][k][j+1]))
226 //cout<<"SPOT"<<endl;
227 //Execute SPOT on point
228 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]));
229 Point1[i-1][k][j]=int(SPOTp*Point[i-1][k][j]);
230 Point1[i+1][k][j]=Int_t(SPOTp*Point[i+1][k][j]);
231 Point1[i][k-1][j]=Int_t(SPOTp*Point[i][k-1][j]);
232 Point1[i][k+1][j]=Int_t(SPOTp*Point[i][k+1][j]);
233 Point1[i][k][j-1]=Int_t(SPOTp*Point[i][k][j-1]);
234 Point1[i][k][j+1]=Int_t(SPOTp*Point[i][k][j+1]);
237 //copy from buffer copy
238 for(i=1;i<dimensiontheta;i++)
239 for(j=1;j<dimensionphi;j++)
240 for(k=1;k<dimensionOMEGA;k++)
241 Point[i][j][k]=Point1[i][j][k];
246 //Identification is equivalent to maximum determination
247 max=0;maxi=0;maxj=0;maxk=0;
249 //cout<<"Proceeding to Identification"<<endl;
251 for(i=1;i<dimensiontheta-3;i++)
252 for(j=1;j<=dimensionphi-3;j++)
253 for(k=0;k<=dimensionOMEGA;k++)
254 if(Point[i][j][k]>max)
256 //cout<<"maxi="<<i*90/dimension<<" maxj="<<j*90/dimension<<" maxk="<<k*maxOMEGA/dimension*180/Pii<<" max="<<max<<endl;
257 maxi=i;maxj=j;maxk=k;
259 //printf("Max Omega %f, Max Theta %f, Max Phi %f\n",maxk,maxi,maxj);
262 //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",h,cx,cy,maxk*Pii/(dimensiontheta*4));
263 //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",h,cx,cy,maxk);
266 //fscanf(omegas,"%f",&realomega);
267 //fscanf(thetas,"%f",&realtheta);
268 //printf("Real Omega: %f",realomega);
269 //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;
271 //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));
274 Pointpp(maxj*90/dimensiontheta,maxi*90/dimensionphi,maxk*maxOMEGA/dimensionOMEGA*180/Pii,cx,cy);//Generates a point on the elipse*/
277 //Start filling rec. hits
281 rechit[0] = (Float_t)( maxi*Pii/(dimensiontheta*4));
282 rechit[1] = (Float_t)( maxj*Pii/(dimensionphi*4));
283 rechit[2] = (Float_t)( maxk*Pii/(dimensionOMEGA*4));
284 //rechit[0] = (Float_t)( maxi);
285 //rechit[1] = (Float_t)( maxj);
286 //rechit[2] = (Float_t)( maxk);
290 //printf ("track %d, theta %f, phi %f, omega %f\n\n\n",track,rechit[0],rechit[1],rechit[2]);
293 RICH->AddRecHit(nch-1,rechit);
295 //printf("\n\n\n\n");
296 gAlice->TreeR()->Fill();
297 //TTree *TR=gAlice->TreeR();
298 //Stat_t ndig=TR->GetEntries();
301 fRec=RICH->RecHitsAddress(i);
302 int ndig=fRec->GetEntriesFast();
303 printf ("Chamber %d, rings %d\n",i,ndig);
305 //printf("Number of rec. hits: %d",ndig);
306 RICH->ResetRecHits();
308 //sprintf(hname,"TreeR%d",track);
309 //gAlice->TreeR()->Write(hname);
313 Float_t AliRICHDetect:: Area(Float_t theta,Float_t OMEGA)
317 const Float_t h=9.25; //Distance from Radiator to Pads in pads
319 area=TMath::Pi()*pow(h*tan(OMEGA),2)/pow(pow(cos(theta),2)-pow(tan(OMEGA)*sin(theta),2),3/2);
324 /*Int_t ***AliRICHDetect::i3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
325 // allocate a Float_t 3tensor with range t[nrl..nrh][ncl..nch][ndl..ndh]
327 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
330 // allocate pointers to pointers to rows
331 t=(Int_t ***) malloc((size_t)((nrow+NR_END)*sizeof(Int_t**)));
332 if (!t) printf("allocation failure 1 in f3tensor()");
336 // allocate pointers to rows and set pointers to them
337 t[nrl]=(Int_t **) malloc((size_t)((nrow*ncol+NR_END)*sizeof(Int_t*)));
338 if (!t[nrl]) printf("allocation failure 2 in f3tensor()");
342 // allocate rows and set pointers to them
343 t[nrl][ncl]=(Int_t *) malloc((size_t)((nrow*ncol*ndep+NR_END)*sizeof(Int_t)));
344 if (!t[nrl][ncl]) printf("allocation failure 3 in f3tensor()");
345 t[nrl][ncl] += NR_END;
348 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
349 for(i=nrl+1;i<=nrh;i++) {
351 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
352 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
355 // return pointer to array of pointers to rows
359 /*void Pointpp(Float_t alfa,Float_t theta,Float_t OMEGA,Float_t cx,Float_t cy)
362 Float_t fiducial=h*tan((OMEGA+theta)*Pii/180),l=h/cos(theta*Pii/180),xtrial,y,c0,c1,c2;
364 //cout<<"fiducial="<<fiducial<<endl;
367 while((c1*c1-4*c2*c0)<=0)
369 //Choose which side to go...
370 if(aleat(1)>.5) s=1; else s=-1;
373 Float_t alfa1=alfa*Pii/180;
374 Float_t theta1=theta*Pii/180;
375 Float_t OMEGA1=OMEGA*Pii/180;
376 //Solve the eq for a trial x
377 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);
378 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);
379 c2=-pow(cos(alfa1),2)-pow(cos(theta1)*sin(alfa1),2)+pow(sin(alfa1)*sin(theta1)*tan(OMEGA1),2);
380 //cout<<"Trial: y="<<y<<"c0="<<c0<<" c1="<<c1<<" c2="<<c2<<endl;
382 //Choose which side to go...
383 if(aleat(1)>.5) s=1; else s=-1;
384 xtrial=cx+(-c1+s*sqrt(c1*c1-4*c2*c0))/(2*c2);
385 //cout<<"x="<<xtrial<<" y="<<cy+y<<endl;
386 fprintf(final,"%f %f\n",xtrial,cy+y);