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.2 2000/06/12 15:19:30 jbarbosa
21 Revision 1.1 2000/04/19 13:05:14 morsch
22 J. Barbosa's spot reconstruction algorithm.
28 #include "AliRICHPoints.h"
29 #include "AliRICHDetect.h"
30 #include "AliRICHHit.h"
31 #include "AliRICHDigit.h"
33 #include "TParticle.h"
39 ClassImp(AliRICHDetect)
40 //___________________________________________
41 AliRICHDetect::AliRICHDetect() : TObject()
44 // Default constructor
49 //___________________________________________
50 AliRICHDetect::AliRICHDetect(const char *name, const char *title)
56 /*fChambers = new TObjArray(7);
57 for (Int_t i=0; i<7; i++) {
59 (*fChambers)[i] = new AliRICHchamber();
65 void AliRICHDetect::Detect()
69 // Detection algorithm
72 //printf("Detection started!\n");
73 Float_t omega,steptheta,stepphi,x,y,cx,cy,l,aux1,aux2,aux3,maxi,maxj,maxk,max;
74 //Float_t theta,phi,realomega,realtheta;
77 //const Float_t Noise_Level=0; //Noise Level in percentage of mesh points
78 //const Float_t t=0.6; //Softening of Noise Correction (factor)
80 const Float_t kPi=3.1415927;
82 const Float_t kHeight=10; //Distance from Radiator to Pads in pads
85 const Int_t kDimensionTheta=100; //Matrix dimension for angle Detection
86 const Int_t kDimensionPhi=100;
87 const Int_t kDimensionOmega=100;
89 //const Float_t SPOTp=.2; //Percentage of spot action
90 //const Int_t np=500; //Number of points to reconstruct elipse
91 const Float_t kMaxOmega=65*kPi/180; //Maximum Cherenkov angle to identify
93 Int_t point[kDimensionTheta][kDimensionPhi][kDimensionOmega];
94 //Int_t point1[kDimensionTheta][kDimensionPhi][kDimensionOmega];
96 steptheta=kPi/kDimensionTheta;
97 stepphi=kPi/kDimensionPhi;
99 AliRICHChamber* iChamber;
101 AliRICH *pRICH = (AliRICH*)gAlice->GetDetector("RICH");
102 Int_t ntracks = (Int_t)gAlice->TreeH()->GetEntries();
103 //Int_t ntrks = gAlice->GetNtrack();
105 Float_t trackglob[3];
108 //printf("Got ntracks:%d\n",ntracks);
109 /*TVector *xp = new TVector(1000);
110 TVector *yp = new TVector(1000);
111 TVector *zp = new TVector(1000);
112 TVector *ptrk = new TVector(1000);
113 TVector *phit = new TVector(1000);*/
115 //printf("Area de uma elipse com teta 0 e Omega 45:%f",Area(0,45));
118 for (Int_t track=0; track<ntracks;track++) {
120 gAlice->TreeH()->GetEvent(track);
121 TClonesArray *pHits = pRICH->Hits();
122 if (pHits == 0) return;
123 Int_t nhits = pHits->GetEntriesFast();
124 if (nhits == 0) continue;
125 Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
126 gAlice->TreeD()->GetEvent(nent-1);
127 AliRICHHit *mHit = 0;
128 AliRICHDigit *points = 0;
133 for(i=0;i<kDimensionTheta;i++)
135 for(j=0;j<kDimensionPhi;j++)
137 for(k=0;k<kDimensionOmega;k++)
141 //printf("Dimensions theta:%d, phi:%d, omega:%d",kDimensionTheta,kDimensionPhi,kDimensionOmega);
142 //printf("Resetting %d %d %d, time %d\n",i,j,k,counter);
143 //-Noise_Level*(Area(i*kPi/(18*dimension),k*kMaxOmega/dimension)-Area((i-1)*kPi/(18*dimension),(k-1)*kMaxOmega/dimension));
144 //printf("n-%f",-Noise_Level*(Area(i*kPi/(18*dimension),k*kMaxOmega/dimension)-Area((i-1)*kPi/(18*dimension),(k-1)*kMaxOmega/dimension)));
148 mHit = (AliRICHHit*) pHits->UncheckedAt(0);
149 //printf("Aqui vou eu\n");
150 Int_t nch = mHit->fChamber;
151 //printf("Aqui fui eu\n");
152 trackglob[0] = mHit->fX;
153 trackglob[1] = mHit->fY;
154 trackglob[2] = mHit->fZ;
160 //printf("Chamber processed:%d\n",nch);
161 printf("Center processed: %3.1f %3.1f %3.1f\n",trackglob[0],trackglob[1],trackglob[2]);
163 iChamber = &(pRICH->Chamber(nch-1));
165 //printf("Nch:%d\n",nch);
167 iChamber->GlobaltoLocal(trackglob,trackloc);
169 //printf("Transformation 1: %3.1f %3.1f %3.1f\n",trackloc[0],trackloc[1],trackloc[2]);
172 iChamber->LocaltoGlobal(trackloc,trackglob);
174 //printf("Transformation 2: %3.1f %3.1f %3.1f\n",trackglob[0],trackglob[1],trackglob[2]);
179 TClonesArray *pDigits = pRICH->DigitsAddress(nch-1);
180 Int_t ndigits = pDigits->GetEntriesFast();
182 //printf("Got %d digits\n",ndigits);
184 //printf("Starting calculations\n");
186 for(Float_t theta=0;theta<kPi/18;theta+=steptheta)
188 for(Float_t phi=0;phi<=kPi/3;phi+=stepphi)
190 for (Int_t dig=0;dig<ndigits;dig++)
192 points=(AliRICHDigit*) pDigits->UncheckedAt(dig);
196 //printf("Loaded digit %d with coordinates x:%f, y%f\n",dig,x,y);
197 //cout<<"x="<<x<<" y="<<y<<endl;
199 if (sqrt(pow(x,2)+pow(y,2))<kHeight*tan(theta+kMaxOmega)*3/4)
202 l=kHeight/cos(theta);
204 aux1=-y*sin(phi)+x*cos(phi);
205 aux2=y*cos(phi)+x*sin(phi);
206 aux3=( pow(aux1,2)+pow(cos(theta)*aux2 ,2))/pow(sin(theta)*aux2+l,2);
207 //cout<<"aux1="<<aux1<<" aux2="<<aux2<<" aux3="<<aux3;
209 omega=atan(sqrt(aux3));
210 //printf("Omega: %f\n",omega);
212 //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;
213 //{Int_t lixo;cin>>lixo;}
214 if(omega<kMaxOmega)point[Int_t(2*theta*kDimensionTheta/kPi)][Int_t(2*phi*kDimensionPhi/kPi)][Int_t(omega*kDimensionOmega/kMaxOmega)]+=1;
215 //if(omega<kMaxOmega)point[Int_t(theta)][Int_t(phi)][Int_t(omega)]+=1;
227 for(i=0;i<=kDimensionTheta;i++)
228 for(j=0;j<=kDimensionPhi;j++)
229 for(k=0;k<=kDimensionOmega;k++)
230 point1[i][j][k]=point[i][j][k];
232 cout<<"COM SPOT!"<<endl;{Int_t lixo;cin>>lixo;}
234 for(i=1;i<kDimensionTheta;i++)
235 for(j=1;j<kDimensionPhi;j++)
236 for(k=1;k<kDimensionOmega;k++)
238 if((point[i][k][j]>point[i-1][k][j])&&(point[i][k][j]>point[i+1][k][j])&&
239 (point[i][k][j]>point[i][k-1][j])&&(point[i][k][j]>point[i][k+1][j])&&
240 (point[i][k][j]>point[i][k][j-1])&&(point[i][k][j]>point[i][k][j+1]))
242 //cout<<"SPOT"<<endl;
243 //Execute SPOT on point
244 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]));
245 point1[i-1][k][j]=int(SPOTp*point[i-1][k][j]);
246 point1[i+1][k][j]=Int_t(SPOTp*point[i+1][k][j]);
247 point1[i][k-1][j]=Int_t(SPOTp*point[i][k-1][j]);
248 point1[i][k+1][j]=Int_t(SPOTp*point[i][k+1][j]);
249 point1[i][k][j-1]=Int_t(SPOTp*point[i][k][j-1]);
250 point1[i][k][j+1]=Int_t(SPOTp*point[i][k][j+1]);
253 //copy from buffer copy
254 for(i=1;i<kDimensionTheta;i++)
255 for(j=1;j<kDimensionPhi;j++)
256 for(k=1;k<kDimensionOmega;k++)
257 point[i][j][k]=point1[i][j][k];
262 //Identification is equivalent to maximum determination
263 max=0;maxi=0;maxj=0;maxk=0;
265 //cout<<"Proceeding to Identification"<<endl;
267 for(i=1;i<kDimensionTheta-3;i++)
268 for(j=1;j<=kDimensionPhi-3;j++)
269 for(k=0;k<=kDimensionOmega;k++)
270 if(point[i][j][k]>max)
272 //cout<<"maxi="<<i*90/dimension<<" maxj="<<j*90/dimension<<" maxk="<<k*kMaxOmega/dimension*180/kPi<<" max="<<max<<endl;
273 maxi=i;maxj=j;maxk=k;
275 //printf("Max Omega %f, Max Theta %f, Max Phi %f\n",maxk,maxi,maxj);
278 //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",h,cx,cy,maxk*kPi/(kDimensionTheta*4));
279 //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",kHeight,cx,cy,maxk);
282 //fscanf(omegas,"%f",&realomega);
283 //fscanf(thetas,"%f",&realtheta);
284 //printf("Real Omega: %f",realomega);
285 //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;
287 //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));
290 pointpp(maxj*90/kDimensionTheta,maxi*90/kDimensionPhi,maxk*kMaxOmega/kDimensionOmega*180/kPi,cx,cy);//Generates a point on the elipse*/
293 //Start filling rec. hits
297 rechit[0] = (Float_t)( maxi*kPi/(kDimensionTheta*4));
298 rechit[1] = (Float_t)( maxj*kPi/(kDimensionPhi*4));
299 rechit[2] = (Float_t)( maxk*kPi/(kDimensionOmega*4));
300 //rechit[0] = (Float_t)( maxi);
301 //rechit[1] = (Float_t)( maxj);
302 //rechit[2] = (Float_t)( maxk);
306 //printf ("track %d, theta %f, phi %f, omega %f\n\n\n",track,rechit[0],rechit[1],rechit[2]);
309 pRICH->AddRecHit(nch-1,rechit);
311 //printf("\n\n\n\n");
312 gAlice->TreeR()->Fill();
313 //TTree *TR=gAlice->TreeR();
314 //Stat_t ndig=TR->GetEntries();
316 for (i=0;i<kNCH;i++) {
317 fRec=pRICH->RecHitsAddress(i);
318 int ndig=fRec->GetEntriesFast();
319 printf ("Chamber %d, rings %d\n",i,ndig);
321 //printf("Number of rec. hits: %d",ndig);
322 pRICH->ResetRecHits();
324 //sprintf(hname,"TreeR%d",track);
325 //gAlice->TreeR()->Write(hname);
329 Float_t AliRICHDetect:: Area(Float_t theta,Float_t omega)
333 // Calculates area of an ellipse for given incidence angles
337 const Float_t kHeight=9.25; //Distance from Radiator to Pads in pads
339 area=TMath::Pi()*pow(kHeight*tan(omega),2)/pow(pow(cos(theta),2)-pow(tan(omega)*sin(theta),2),3/2);
344 /*Int_t ***AliRICHDetect::i3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
345 // allocate a Float_t 3tensor with range t[nrl..nrh][ncl..nch][ndl..ndh]
347 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
350 // allocate pointers to pointers to rows
351 t=(Int_t ***) malloc((size_t)((nrow+NR_END)*sizeof(Int_t**)));
352 if (!t) printf("allocation failure 1 in f3tensor()");
356 // allocate pointers to rows and set pointers to them
357 t[nrl]=(Int_t **) malloc((size_t)((nrow*ncol+NR_END)*sizeof(Int_t*)));
358 if (!t[nrl]) printf("allocation failure 2 in f3tensor()");
362 // allocate rows and set pointers to them
363 t[nrl][ncl]=(Int_t *) malloc((size_t)((nrow*ncol*ndep+NR_END)*sizeof(Int_t)));
364 if (!t[nrl][ncl]) printf("allocation failure 3 in f3tensor()");
365 t[nrl][ncl] += NR_END;
368 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
369 for(i=nrl+1;i<=nrh;i++) {
371 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
372 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
375 // return pointer to array of pointers to rows
379 /*void pointpp(Float_t alfa,Float_t theta,Float_t omega,Float_t cx,Float_t cy)
382 Float_t fiducial=h*tan((omega+theta)*kPi/180),l=h/cos(theta*kPi/180),xtrial,y,c0,c1,c2;
384 //cout<<"fiducial="<<fiducial<<endl;
387 while((c1*c1-4*c2*c0)<=0)
389 //Choose which side to go...
390 if(aleat(1)>.5) s=1; else s=-1;
393 Float_t alfa1=alfa*kPi/180;
394 Float_t theta1=theta*kPi/180;
395 Float_t omega1=omega*kPi/180;
396 //Solve the eq for a trial x
397 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);
398 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);
399 c2=-pow(cos(alfa1),2)-pow(cos(theta1)*sin(alfa1),2)+pow(sin(alfa1)*sin(theta1)*tan(omega1),2);
400 //cout<<"Trial: y="<<y<<"c0="<<c0<<" c1="<<c1<<" c2="<<c2<<endl;
402 //Choose which side to go...
403 if(aleat(1)>.5) s=1; else s=-1;
404 xtrial=cx+(-c1+s*sqrt(c1*c1-4*c2*c0))/(2*c2);
405 //cout<<"x="<<xtrial<<" y="<<cy+y<<endl;
406 fprintf(final,"%f %f\n",xtrial,cy+y);