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