]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RICH/AliRICHDetect.cxx
Rotation Angle is +60 deg.
[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$
6e585aa2 18 Revision 1.15 2001/10/21 18:31:23 hristov
19 Several pointers were set to zero in the default constructors to avoid memory management problems
20
2685bf00 21 Revision 1.14 2001/05/14 13:25:54 hristov
22 stdlib.h included (for Alpha)
23
29803c51 24 Revision 1.13 2001/05/10 12:26:31 jbarbosa
25 Totally reworked version of reconstruction algorithm.
26
ac6e04fc 27 Revision 1.12 2001/02/27 22:15:03 jbarbosa
28 Removed compiler warning.
29
2966f600 30 Revision 1.11 2001/02/27 15:21:46 jbarbosa
31 Transition to SDigits.
32
b251a2b5 33 Revision 1.10 2001/02/13 20:39:06 jbarbosa
34 Changes to make it work with new IO.
35
a5886574 36 Revision 1.9 2001/01/22 21:39:11 jbarbosa
37 Several tune-ups
38
eb1ee126 39 Revision 1.8 2000/11/15 15:52:53 jbarbosa
40 Turned on spot algorithm.
41
ceccff49 42 Revision 1.7 2000/11/01 15:37:05 jbarbosa
43 Updated to use its own rec. point object.
44
4a5c8776 45 Revision 1.6 2000/10/02 21:28:12 fca
46 Removal of useless dependecies via forward declarations
47
94de3818 48 Revision 1.5 2000/06/30 16:30:28 dibari
49 Disabled writing to rechits.
50
a366fdbe 51 Revision 1.4 2000/06/15 15:46:59 jbarbosa
52 Corrected compilation errors on HP-UX (replaced pow with TMath::Power)
53
00df6e79 54 Revision 1.3 2000/06/13 13:15:41 jbarbosa
55 Still some code cleanup done (variable names)
56
3a3df9e3 57 Revision 1.2 2000/06/12 15:19:30 jbarbosa
58 Cleaned up version.
59
237c933d 60 Revision 1.1 2000/04/19 13:05:14 morsch
61 J. Barbosa's spot reconstruction algorithm.
62
c1076715 63*/
64
29803c51 65#include <stdlib.h>
66
c1076715 67
68#include "AliRICH.h"
69#include "AliRICHPoints.h"
70#include "AliRICHDetect.h"
237c933d 71#include "AliRICHHit.h"
72#include "AliRICHDigit.h"
ac6e04fc 73#include "AliRICHSegmentationV0.h"
c1076715 74#include "AliRun.h"
75#include "TParticle.h"
94de3818 76#include "TTree.h"
c1076715 77#include "TMath.h"
78#include "TRandom.h"
ac6e04fc 79#include "TH3.h"
80#include "TH2.h"
81#include "TCanvas.h"
c1076715 82
ac6e04fc 83#include "malloc.h"
c1076715 84
85
86ClassImp(AliRICHDetect)
87//___________________________________________
88AliRICHDetect::AliRICHDetect() : TObject()
89{
237c933d 90
91// Default constructor
92
2685bf00 93 fc1 = 0;
94 fc2 = 0;
95 fc3 = 0;
96
c1076715 97}
98
99//___________________________________________
100AliRICHDetect::AliRICHDetect(const char *name, const char *title)
101 : TObject()
102{
237c933d 103
ac6e04fc 104
105 fc1= new TCanvas("c1","Reconstructed points",50,50,300,350);
106 fc1->Divide(2,2);
107 fc2= new TCanvas("c2","Reconstructed points after SPOT",50,50,300,350);
108 fc2->Divide(2,2);
109 fc3= new TCanvas("c3","Used Digits",50,50,300,350);
110 //fc3->Divide(2,1);
111
112}
113
114//___________________________________________
115AliRICHDetect::~AliRICHDetect()
116{
c1076715 117
ac6e04fc 118// Destructor
119
c1076715 120}
121
122
ac6e04fc 123void AliRICHDetect::Detect(Int_t nev)
c1076715 124{
125
237c933d 126//
127// Detection algorithm
128
129
c1076715 130 //printf("Detection started!\n");
ac6e04fc 131 Float_t omega,omega1,theta1,steptheta,stepphi,x,y,z,cx,cy,l,aux1,aux2,aux3,max,radius=0,meanradius=0;
132 Int_t maxi,maxj,maxk;
c1076715 133 //Float_t theta,phi,realomega,realtheta;
ac6e04fc 134 Float_t binomega, bintheta, binphi;
135 Int_t intomega, inttheta, intphi;
c1076715 136 Int_t i,j,k;
ac6e04fc 137
138 AliRICH *pRICH = (AliRICH*)gAlice->GetDetector("RICH");
139 AliRICHSegmentationV0* segmentation;
140 AliRICHChamber* iChamber;
141 AliRICHGeometry* geometry;
142
143 iChamber = &(pRICH->Chamber(0));
144 segmentation=(AliRICHSegmentationV0*) iChamber->GetSegmentationModel(0);
145 geometry=iChamber->GetGeometryModel();
ceccff49 146
c1076715 147
ac6e04fc 148 //const Float_t Noise_Level=0; //Noise Level in percentage of mesh points
149 //const Float_t t=0.6; //Softening of Noise Correction (factor)
c1076715 150
ac6e04fc 151 const Float_t kPi=TMath::Pi();
c1076715 152
ac6e04fc 153 const Float_t kHeight=geometry->GetRadiatorToPads(); //Distance from Radiator to Pads in centimeters
154 //printf("Distance to Pads:%f\n",kHeight);
ceccff49 155
ac6e04fc 156 const Int_t kSpot=0; //number of passes with spot algorithm
c1076715 157
ac6e04fc 158 const Int_t kDimensionTheta=30; //Matrix dimension for angle Detection
159 const Int_t kDimensionPhi=45;
160 const Int_t kDimensionOmega=100;
c1076715 161
ac6e04fc 162 const Float_t SPOTp=1; //Percentage of spot action
163 const Float_t kMinOmega=20*kPi/180;
164 const Float_t kMaxOmega=70*kPi/180; //Maximum Cherenkov angle to identify
165 const Float_t kMinTheta=0;
166 const Float_t kMaxTheta=15*kPi/180;
167 //const Float_t kMaxTheta=0.1;
168 const Float_t kMinPhi=0;
169 const Float_t kMaxPhi=360*kPi/180;
170
eb1ee126 171
ac6e04fc 172 Float_t kCorr=0.61; //Correction factor, accounting for aberration, refractive index, etc.
173 //const Float_t kCorr=.9369; //from 0 incidence
174 //const Float_t kCorr=1;
175
176 //TRandom* random=0;
177
178 Float_t rechit[6]; //Reconstructed point data
179
c1076715 180
c1076715 181
ac6e04fc 182 //printf("Creating matrices\n");
183 //Float_t point[kDimensionTheta][kDimensionPhi][kDimensionOmega];
184 //Float_t point1[kDimensionTheta][kDimensionPhi][kDimensionOmega];
185 //printf("Created matrices\n");
186
187 Int_t ***point = i3tensor(0,kDimensionTheta,0,kDimensionPhi,0,kDimensionOmega);
188 Int_t ***point1 = i3tensor(0,kDimensionTheta,0,kDimensionPhi,0,kDimensionOmega);
c1076715 189
ac6e04fc 190 //Int_t **point = new Int_t[kDimensionTheta][kDimensionPhi][kDimensionOmega];
191 //Int_t **point1 = new Int_t[kDimensionTheta][kDimensionPhi][kDimensionOmega];
192
193 steptheta=(kMaxTheta-kMinTheta)/kDimensionTheta;
194 stepphi=(kMaxPhi-kMinPhi)/kDimensionPhi;
195
196 static TH3F *Points = new TH3F("Points","Reconstructed points 3D",kDimensionTheta,0,kDimensionTheta,kDimensionPhi,0,kDimensionPhi,kDimensionOmega,0,kDimensionOmega);
197 static TH2F *ThetaPhi = new TH2F("ThetaPhi","Theta-Phi projection",kDimensionTheta,0,kDimensionTheta,kDimensionPhi,0,kDimensionPhi);
198 static TH2F *OmegaTheta = new TH2F("OmegaTheta","Omega-Theta projection",kDimensionTheta,0,kDimensionTheta,kDimensionOmega,0,kDimensionOmega);
199 static TH2F *OmegaPhi = new TH2F("OmegaPhi","Omega-Phi projection",kDimensionPhi,0,kDimensionPhi,kDimensionOmega,0,kDimensionOmega);
200 static TH3F *SpotPoints = new TH3F("Points","Reconstructed points 3D, spot",kDimensionTheta,0,kDimensionTheta,kDimensionPhi,0,kDimensionPhi,kDimensionOmega,0,kDimensionOmega);
201 static TH2F *SpotThetaPhi = new TH2F("ThetaPhi","Theta-Phi projection, spot",kDimensionTheta,0,kDimensionTheta,kDimensionPhi,0,kDimensionPhi);
202 static TH2F *SpotOmegaTheta = new TH2F("OmegaTheta","Omega-Theta projection, spot",kDimensionTheta,0,kDimensionTheta,kDimensionOmega,0,kDimensionOmega);
203 static TH2F *SpotOmegaPhi = new TH2F("OmegaPhi","Omega-Phi projection, spot",kDimensionPhi,0,kDimensionPhi,kDimensionOmega,0,kDimensionOmega);
204 static TH2F *DigitsXY = new TH2F("DigitsXY","Pads used for reconstruction",150,-25,25,150,-25,25);
205 Points->SetXTitle("theta");
206 Points->SetYTitle("phi");
207 Points->SetZTitle("omega");
208 ThetaPhi->SetXTitle("theta");
209 ThetaPhi->SetYTitle("phi");
210 OmegaTheta->SetXTitle("theta");
211 OmegaTheta->SetYTitle("omega");
212 OmegaPhi->SetXTitle("phi");
213 OmegaPhi->SetYTitle("omega");
214 SpotPoints->SetXTitle("theta");
215 SpotPoints->SetYTitle("phi");
216 SpotPoints->SetZTitle("omega");
217 SpotThetaPhi->SetXTitle("theta");
218 SpotThetaPhi->SetYTitle("phi");
219 SpotOmegaTheta->SetXTitle("theta");
220 SpotOmegaTheta->SetYTitle("omega");
221 SpotOmegaPhi->SetXTitle("phi");
222 SpotOmegaPhi->SetYTitle("omega");
223
c1076715 224 Int_t ntracks = (Int_t)gAlice->TreeH()->GetEntries();
225 //Int_t ntrks = gAlice->GetNtrack();
226
227 Float_t trackglob[3];
228 Float_t trackloc[3];
229
c1076715 230 //printf("Area de uma elipse com teta 0 e Omega 45:%f",Area(0,45));
231
4a5c8776 232 Int_t track;
c1076715 233
4a5c8776 234 for (track=0; track<ntracks;track++) {
c1076715 235 gAlice->ResetHits();
236 gAlice->TreeH()->GetEvent(track);
3a3df9e3 237 TClonesArray *pHits = pRICH->Hits();
238 if (pHits == 0) return;
239 Int_t nhits = pHits->GetEntriesFast();
c1076715 240 if (nhits == 0) continue;
2966f600 241 //Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
ac6e04fc 242 gAlice->TreeD()->GetEvent(0);
c1076715 243 AliRICHHit *mHit = 0;
244 AliRICHDigit *points = 0;
245 //Int_t npoints=0;
246
ac6e04fc 247 Int_t counter=0, counter1=0;
c1076715 248 //Initialization
3a3df9e3 249 for(i=0;i<kDimensionTheta;i++)
c1076715 250 {
3a3df9e3 251 for(j=0;j<kDimensionPhi;j++)
c1076715 252 {
3a3df9e3 253 for(k=0;k<kDimensionOmega;k++)
c1076715 254 {
255 counter++;
3a3df9e3 256 point[i][j][k]=0;
257 //printf("Dimensions theta:%d, phi:%d, omega:%d",kDimensionTheta,kDimensionPhi,kDimensionOmega);
c1076715 258 //printf("Resetting %d %d %d, time %d\n",i,j,k,counter);
3a3df9e3 259 //-Noise_Level*(Area(i*kPi/(18*dimension),k*kMaxOmega/dimension)-Area((i-1)*kPi/(18*dimension),(k-1)*kMaxOmega/dimension));
260 //printf("n-%f",-Noise_Level*(Area(i*kPi/(18*dimension),k*kMaxOmega/dimension)-Area((i-1)*kPi/(18*dimension),(k-1)*kMaxOmega/dimension)));
c1076715 261 }
262 }
263 }
3a3df9e3 264 mHit = (AliRICHHit*) pHits->UncheckedAt(0);
c1076715 265 //printf("Aqui vou eu\n");
6e585aa2 266 Int_t nch = mHit->Chamber();
c1076715 267 //printf("Aqui fui eu\n");
94de3818 268 trackglob[0] = mHit->X();
269 trackglob[1] = mHit->Y();
270 trackglob[2] = mHit->Z();
c1076715 271
ac6e04fc 272 printf("Chamber processed:%d\n",nch);
ceccff49 273
ac6e04fc 274 printf("Reconstructing particle at (global coordinates): %3.1f %3.1f %3.1f,\n",trackglob[0],trackglob[1],trackglob[2]);
c1076715 275
3a3df9e3 276 iChamber = &(pRICH->Chamber(nch-1));
c1076715 277
278 //printf("Nch:%d\n",nch);
279
280 iChamber->GlobaltoLocal(trackglob,trackloc);
281
ac6e04fc 282 printf("Reconstructing particle at (local coordinates) : %3.1f %3.1f %3.1f\n",trackloc[0],trackloc[1],trackloc[2]);
c1076715 283
284
285 iChamber->LocaltoGlobal(trackloc,trackglob);
286
3a3df9e3 287 //printf("Transformation 2: %3.1f %3.1f %3.1f\n",trackglob[0],trackglob[1],trackglob[2]);
c1076715 288
ac6e04fc 289 cx=trackloc[0];
290 cy=trackloc[2];
c1076715 291
292
3a3df9e3 293 TClonesArray *pDigits = pRICH->DigitsAddress(nch-1);
294 Int_t ndigits = pDigits->GetEntriesFast();
c1076715 295
296 //printf("Got %d digits\n",ndigits);
297
ac6e04fc 298 counter=0;
299 printf("Starting calculations\n");
300 for(Float_t theta=0;theta<kMaxTheta;theta+=steptheta)
301 {
302 //printf(".");
303 for(Float_t phi=0;phi<=kMaxPhi;phi+=stepphi)
304 {
305 //printf("Phi:%3.1f\n", phi*180/kPi);
306 counter1=0;
c1076715 307 for (Int_t dig=0;dig<ndigits;dig++)
308 {
3a3df9e3 309 points=(AliRICHDigit*) pDigits->UncheckedAt(dig);
6e585aa2 310 segmentation->GetPadC(points->PadX(), points->PadY(),x, y, z);
ac6e04fc 311 x=x-cx;
312 y=y-cy;
313 radius=TMath::Sqrt(TMath::Power(x,2)+TMath::Power(y,2));
314
315 if(radius>4)
c1076715 316 {
ac6e04fc 317 //if(theta==0 && phi==0)
318 //{
319 //printf("Radius: %f, Max Radius: %f\n",radius,kCorr*kHeight*tan(theta+kMaxOmega)*3/4);
320 meanradius+=radius;
321 counter++;
322 //}
c1076715 323
ac6e04fc 324 if (radius<2*kHeight*tan(theta+kMaxOmega)*3/4)
eb1ee126 325 {
ac6e04fc 326
327 if(phi==0)
328 {
329 //printf("Radius: %f, Max Radius: %f\n",radius,2*kHeight*tan(theta+kMaxOmega)*3/4);
330 //printf("Loaded digit %d with coordinates x:%f, y%f\n",dig,x,y);
331 //printf("Using digit %d, for theta %f\n",dig,theta);
332 }
333
334 counter1++;
335
336 l=kHeight/cos(theta);
337
338 //x=x*kCorr;
339 //y=y*kCorr;
340 /*if(SnellAngle(theta+omega)<999)
341 {
342 //printf("(Angle)/(Snell angle):%f\n",(theta+omega)/SnellAngle(theta+omega));
343 x=x*(theta+omega)/SnellAngle(theta+omega);
344 y=y*(theta+omega)/SnellAngle(theta+omega);
345 }
346 else
347 {
348 x=0;
349 y=0;
350 }*/
351
352 //main calculation
353
354 DigitsXY->Fill(x,y,(float) 1);
355
356 theta1=SnellAngle(theta)*1.5;
357
358 aux1=-y*sin(phi)+x*cos(phi);
359 aux2=y*cos(phi)+x*sin(phi);
360 aux3=( TMath::Power(aux1,2)+TMath::Power(cos(theta1)*aux2 ,2))/TMath::Power(sin(theta1)*aux2+l,2);
361 omega=atan(sqrt(aux3));
362
363 //omega is distorted, theta1 is distorted
364
365 if(InvSnellAngle(theta+omega)<999)
366 {
367 omega1=InvSnellAngle(omega+theta1) - theta;
368 //theta1=InvSnellAngle(omega+theta) - omega1;
369 //omega1=kCorr*omega;
370
371 kCorr=InvSnellAngle(omega+theta)/(omega+theta);
372 theta1=kCorr*theta/1.4;
373 //if(phi==0)
374 //printf("Omega:%f Theta:%f Omega1:%f Theta1:%f ISA(o+t):%f ISA(t):%f\n",omega*180/kPi,theta*180/kPi,omega1*180/kPi,theta1*180/kPi,InvSnellAngle(omega+theta)*180/kPi,InvSnellAngle(theta)*180/kPi);
375 }
376 else
377 {
378 omega1=0;
379 theta1=0;
380 }
381
382 //printf("Omega:%f\n",omega);
383
384
385 //if(SnellAngle(theta+omega)<999)
386 //printf("(Angle)/(Snell angle):%f\n",(theta+omega)/SnellAngle(theta+omega));
387 if(theta==0 && phi==0)
388 {
389 //printf("Omega: %f Corrected Omega: %f\n",omega, omega/kCorr);
390 //omega=omega/kCorr;
391 }
392
393 //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;
394 //{Int_t lixo;cin>>lixo;}
395 if(omega1<kMaxOmega && omega1>kMinOmega)
396 {
397 //printf("Omega found:%f\n",omega);
398 omega1=omega1-kMinOmega;
399
400 //printf("Omega: %f Theta: %3.1f Phi:%3.1f\n",omega, theta*180/kPi, phi*180/kPi);
401
402 bintheta=theta1*kDimensionTheta/kMaxTheta;
403 binphi=phi*kDimensionPhi/kMaxPhi;
404 binomega=omega1*kDimensionOmega/(kMaxOmega-kMinOmega);
405
406 if(Int_t(bintheta+0.5)==Int_t(bintheta))
407 inttheta=Int_t(bintheta);
408 else
409 inttheta=Int_t(bintheta+0.5);
410
411 if(Int_t(binomega+0.5)==Int_t(binomega))
412 intomega=Int_t(binomega);
413 else
414 intomega=Int_t(binomega+0.5);
415
416 if(Int_t(binphi+0.5)==Int_t(binphi))
417 intphi=Int_t(binphi);
418 else
419 intphi=Int_t(binphi+0.5);
420
421 //printf("Point added at %d %d %d\n",inttheta,intphi,intomega);
422 point[inttheta][intphi][intomega]+=1;
423 //printf("Omega stored:%d\n",intomega);
424 Points->Fill(inttheta,intphi,intomega,(float) 1);
425 ThetaPhi->Fill(inttheta,intphi,(float) 1);
426 OmegaTheta->Fill(inttheta,intomega,(float) 1);
427 OmegaPhi->Fill(intphi,intomega,(float) 1);
428 //printf("Filling at %d %d %d\n",Int_t(theta*kDimensionTheta/kMaxTheta),Int_t(phi*kDimensionPhi/kMaxPhi),Int_t(omega*kDimensionOmega/kMaxOmega));
429 }
430 //if(omega<kMaxOmega)point[Int_t(theta)][Int_t(phi)][Int_t(omega)]+=1;
eb1ee126 431 }
c1076715 432 }
ac6e04fc 433 }
c1076715 434 }
ac6e04fc 435 //printf("Used %d digits for theta %3.1f\n",counter1, theta*180/kPi);
436 }
437
438 meanradius=meanradius/counter;
439 printf("Mean radius:%f, counter:%d\n",meanradius,counter);
440 rechit[5]=meanradius;
441 printf("Used %d digits\n",counter1);
442 //printf("\n");
443
444 if(nev<20)
445 {
446 if(nev==0)
447 {
448 fc1->cd(1);
449 Points->Draw();
450 fc1->cd(2);
451 ThetaPhi->Draw();
452 fc1->cd(3);
453 OmegaTheta->Draw();
454 fc1->cd(4);
455 OmegaPhi->Draw();
456 fc3->cd();
457 DigitsXY->Draw();
458 }
459 else
460 {
461 //fc1->cd(1);
462 //Points->Draw("same");
463 //fc1->cd(2);
464 //ThetaPhi->Draw("same");
465 //fc1->cd(3);
466 //OmegaTheta->Draw("same");
467 //fc1->cd(4);
468 //OmegaPhi->Draw("same");
469 }
470 }
471
c1076715 472
c1076715 473 //SPOT execute twice
ceccff49 474 for(Int_t s=0;s<kSpot;s++)
c1076715 475 {
ceccff49 476 printf(" Applying Spot algorithm, pass %d\n", s);
477
c1076715 478 //buffer copy
3a3df9e3 479 for(i=0;i<=kDimensionTheta;i++)
ceccff49 480 {
481 for(j=0;j<=kDimensionPhi;j++)
482 {
483 for(k=0;k<=kDimensionOmega;k++)
484 {
485 point1[i][j][k]=point[i][j][k];
486 }
487 }
488 }
489
c1076715 490 //SPOT algorithm
ac6e04fc 491 for(i=1;i<kDimensionTheta-1;i++)
ceccff49 492 {
ac6e04fc 493 for(j=1;j<kDimensionPhi-1;j++)
c1076715 494 {
ac6e04fc 495 for(k=1;k<kDimensionOmega-1;k++)
c1076715 496 {
ceccff49 497 if((point[i][k][j]>point[i-1][k][j])&&(point[i][k][j]>point[i+1][k][j])&&
498 (point[i][k][j]>point[i][k-1][j])&&(point[i][k][j]>point[i][k+1][j])&&
499 (point[i][k][j]>point[i][k][j-1])&&(point[i][k][j]>point[i][k][j+1]))
500 {
501 //cout<<"SPOT"<<endl;
502 //Execute SPOT on point
503 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]));
504 point1[i-1][k][j]=Int_t(SPOTp*point[i-1][k][j]);
505 point1[i+1][k][j]=Int_t(SPOTp*point[i+1][k][j]);
506 point1[i][k-1][j]=Int_t(SPOTp*point[i][k-1][j]);
507 point1[i][k+1][j]=Int_t(SPOTp*point[i][k+1][j]);
508 point1[i][k][j-1]=Int_t(SPOTp*point[i][k][j-1]);
509 point1[i][k][j+1]=Int_t(SPOTp*point[i][k][j+1]);
510 }
c1076715 511 }
512 }
ceccff49 513 }
514
c1076715 515 //copy from buffer copy
ac6e04fc 516 counter1=0;
3a3df9e3 517 for(i=1;i<kDimensionTheta;i++)
ceccff49 518 {
519 for(j=1;j<kDimensionPhi;j++)
520 {
521 for(k=1;k<kDimensionOmega;k++)
522 {
523 point[i][j][k]=point1[i][j][k];
ac6e04fc 524 if(nev<20)
525 {
526 if(s==kSpot-1)
527 {
528 if(point1[i][j][k] != 0)
529 {
530 SpotPoints->Fill(i,j,k,(float) point1[i][j][k]);
531 //printf("Random number %f\n",random->Rndm(2));
532 //if(random->Rndm() < .2)
533 //{
534 SpotThetaPhi->Fill(i,j,(float) point1[i][j][k]);
535 SpotOmegaTheta->Fill(i,k,(float) point1[i][j][k]);
536 SpotOmegaPhi->Fill(j,k,(float) point1[i][j][k]);
537 counter1++;
538 //}
539 //printf("Filling at %d %d %d value %f\n",i,j,k,(float) point1[i][j][k]);
540 }
541 }
542 }
ceccff49 543 //if(point1[i][j][k] != 0)
544 //printf("Last transfer point: %d, point1, %d\n",point[i][j][k],point1[i][j][k]);
545 }
546 }
547 }
548 }
c1076715 549
ac6e04fc 550 //printf("Filled %d cells\n",counter1);
551
552 if(nev<20)
553 {
554 if(nev==0)
555 {
556 fc2->cd(1);
557 SpotPoints->Draw();
558 fc2->cd(2);
559 SpotThetaPhi->Draw();
560 fc2->cd(3);
561 SpotOmegaTheta->Draw();
562 fc2->cd(4);
563 SpotOmegaPhi->Draw();
564 }
565 else
566 {
567 //fc2->cd(1);
568 //SpotPoints->Draw("same");
569 //fc2->cd(2);
570 //SpotThetaPhi->Draw("same");
571 //fc2->cd(3);
572 //SpotOmegaTheta->Draw("same");
573 //fc2->cd(4);
574 //SpotOmegaPhi->Draw("same");
575 }
576 }
577
c1076715 578
579 //Identification is equivalent to maximum determination
580 max=0;maxi=0;maxj=0;maxk=0;
581
ceccff49 582 printf(" Proceeding to identification");
c1076715 583
ac6e04fc 584 for(i=0;i<kDimensionTheta;i++)
585 for(j=0;j<kDimensionPhi;j++)
586 for(k=0;k<kDimensionOmega;k++)
ceccff49 587 if(point[i][j][k]>max)
588 {
589 //cout<<"maxi="<<i*90/dimension<<" maxj="<<j*90/dimension<<" maxk="<<k*kMaxOmega/dimension*180/kPi<<" max="<<max<<endl;
590 maxi=i;maxj=j;maxk=k;
591 max=point[i][j][k];
592 printf(".");
ac6e04fc 593 //printf("Max Omega %d, Max Theta %d, Max Phi %d (%d counts)\n",maxk,maxi,maxj,max);
ceccff49 594 }
595 printf("\n");
c1076715 596
ac6e04fc 597 Float_t FinalOmega = maxk*(kMaxOmega-kMinOmega)/kDimensionOmega;
598 Float_t FinalTheta = maxi*kMaxTheta/kDimensionTheta;
599 Float_t FinalPhi = maxj*kMaxPhi/kDimensionPhi;
eb1ee126 600
ac6e04fc 601 FinalOmega += kMinOmega;
eb1ee126 602
3a3df9e3 603 //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",h,cx,cy,maxk*kPi/(kDimensionTheta*4));
ac6e04fc 604 printf(" Indentified angles: cerenkov - %f, theta - %3.1f, phi - %3.1f (%f activation)\n", FinalOmega, FinalTheta*180/kPi, FinalPhi*180/kPi, max);
3a3df9e3 605 //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",kHeight,cx,cy,maxk);
c1076715 606
c1076715 607 //fscanf(omegas,"%f",&realomega);
608 //fscanf(thetas,"%f",&realtheta);
609 //printf("Real Omega: %f",realomega);
3a3df9e3 610 //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 611
3a3df9e3 612 //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 613
614 /*for(j=0;j<np;j++)
3a3df9e3 615 pointpp(maxj*90/kDimensionTheta,maxi*90/kDimensionPhi,maxk*kMaxOmega/kDimensionOmega*180/kPi,cx,cy);//Generates a point on the elipse*/
c1076715 616
617
618 //Start filling rec. hits
619
ac6e04fc 620 rechit[0] = FinalTheta;
621 rechit[1] = 90*kPi/180 + FinalPhi;
622 rechit[2] = FinalOmega;
c1076715 623 rechit[3] = cx;
624 rechit[4] = cy;
ac6e04fc 625
626 //CreatePoints(FinalTheta, 270*kPi/180 + FinalPhi, FinalOmega, kHeight);
627
c1076715 628 //printf ("track %d, theta %f, phi %f, omega %f\n\n\n",track,rechit[0],rechit[1],rechit[2]);
629
630 // fill rechits
4a5c8776 631 pRICH->AddRecHit3D(nch-1,rechit);
ac6e04fc 632 //printf("rechit %f %f %f %f %f\n",rechit[0],rechit[1],rechit[2],rechit[3],rechit[4]);
ceccff49 633 //printf("Chamber:%d",nch);
c1076715 634 }
635 //printf("\n\n\n\n");
636 gAlice->TreeR()->Fill();
c1076715 637 TClonesArray *fRec;
237c933d 638 for (i=0;i<kNCH;i++) {
4a5c8776 639 fRec=pRICH->RecHitsAddress3D(i);
c1076715 640 int ndig=fRec->GetEntriesFast();
ac6e04fc 641 printf ("Chamber %d, rings %d\n",i+1,ndig);
c1076715 642 }
4a5c8776 643 pRICH->ResetRecHits3D();
ac6e04fc 644
645 free_i3tensor(point,0,kDimensionTheta,0,kDimensionPhi,0,kDimensionOmega);
646 free_i3tensor(point1,0,kDimensionTheta,0,kDimensionPhi,0,kDimensionOmega);
c1076715 647}
648
ac6e04fc 649
650
3a3df9e3 651Float_t AliRICHDetect:: Area(Float_t theta,Float_t omega)
c1076715 652{
237c933d 653
654//
655// Calculates area of an ellipse for given incidence angles
656
657
c1076715 658 Float_t area;
3a3df9e3 659 const Float_t kHeight=9.25; //Distance from Radiator to Pads in pads
c1076715 660
00df6e79 661 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 662
663 return (area);
664}
665
c1076715 666
ac6e04fc 667Int_t ***AliRICHDetect::i3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
668// allocate a Int_t 3tensor with range t[nrl..nrh][ncl..nch][ndl..ndh]
669{
670 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
671 Int_t ***t;
672
673 int NR_END=1;
c1076715 674
ac6e04fc 675 // allocate pointers to pointers to rows
676 t=(Int_t ***) malloc((size_t)((nrow+NR_END)*sizeof(Int_t**)));
677 if (!t) printf("allocation failure 1 in f3tensor()");
678 t += NR_END;
679 t -= nrl;
680
681 // allocate pointers to rows and set pointers to them
682 t[nrl]=(Int_t **) malloc((size_t)((nrow*ncol+NR_END)*sizeof(Int_t*)));
683 if (!t[nrl]) printf("allocation failure 2 in f3tensor()");
684 t[nrl] += NR_END;
685 t[nrl] -= ncl;
c1076715 686
ac6e04fc 687 // allocate rows and set pointers to them
688 t[nrl][ncl]=(Int_t *) malloc((size_t)((nrow*ncol*ndep+NR_END)*sizeof(Int_t)));
689 if (!t[nrl][ncl]) printf("allocation failure 3 in f3tensor()");
690 t[nrl][ncl] += NR_END;
691 t[nrl][ncl] -= ndl;
c1076715 692
ac6e04fc 693 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
694 for(i=nrl+1;i<=nrh;i++) {
695 t[i]=t[i-1]+ncol;
696 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
697 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
c1076715 698 }
ac6e04fc 699
700 // return pointer to array of pointers to rows
701 return t;
702}
703
704void AliRICHDetect::free_i3tensor(int ***t, long nrl, long nrh, long ncl, long nch,long ndl, long ndh)
705// free a Int_t f3tensor allocated by i3tensor()
706{
707 int NR_END=1;
708
709 free((char*) (t[nrl][ncl]+ndl-NR_END));
710 free((char*) (t[nrl]+ncl-NR_END));
711 free((char*) (t+nrl-NR_END));
712}
713
714
715Float_t AliRICHDetect:: SnellAngle(Float_t iangle)
716{
717
718// Compute the Snell angle
719
720 Float_t nfreon = 1.295;
721 Float_t nquartz = 1.585;
722 Float_t ngas = 1;
723
724 Float_t sinrangle;
725 Float_t rangle;
726 Float_t a1, a2;
727
728 a1=nfreon/nquartz;
729 a2=nquartz/ngas;
730
731 sinrangle = a1*a2*sin(iangle);
732
733 if(sinrangle>1.) {
734 rangle = 999.;
735 return rangle;
736 }
737
738 rangle = asin(sinrangle);
739 return rangle;
740}
741
742Float_t AliRICHDetect:: InvSnellAngle(Float_t rangle)
743{
744
745// Compute the inverse Snell angle
c1076715 746
ac6e04fc 747 Float_t nfreon = 1.295;
748 Float_t nquartz = 1.585;
749 Float_t ngas = 1;
c1076715 750
ac6e04fc 751 Float_t siniangle;
752 Float_t iangle;
753 Float_t a1,a2;
c1076715 754
ac6e04fc 755 a1=nfreon/nquartz;
756 a2=nquartz/ngas;
c1076715 757
ac6e04fc 758 siniangle = sin(rangle)/(a1*a2);
759 iangle = asin(siniangle);
760
761 if(siniangle>1.) {
762 iangle = 999.;
763 return iangle;
764 }
765
766 iangle = asin(siniangle);
767 return iangle;
768}
c1076715 769
770
ac6e04fc 771
772//________________________________________________________________________________
773void AliRICHDetect::CreatePoints(Float_t theta, Float_t phi, Float_t omega, Float_t h)
774{
775
776 // Create points along the ellipse equation
777
778 Int_t s1,s2;
779 Float_t fiducial=h*TMath::Tan(omega+theta), l=h/TMath::Cos(theta), xtrial, y=0, c0, c1, c2;
780 //TRandom *random=new TRandom();
781
782 static TH2F *REllipse = new TH2F("REllipse","Reconstructed ellipses",150,-25,25,150,-25,25);
783
784 for(Float_t i=0;i<1000;i++)
785 {
786
787 Float_t counter=0;
788
789 c0=0;c1=0;c2=0;
790 while((c1*c1-4*c2*c0)<=0 && counter<1000)
791 {
792 //Choose which side to go...
793 if(i>250 && i<750) s1=1;
794 //if (gRandom->Rndm(1)>.5) s1=1;
795 else s1=-1;
796 //printf("s1:%d\n",s1);
797 //Trial a y
798 y=s1*i*gRandom->Rndm(Int_t(fiducial/50));
799 //printf("Fiducial %f for omega:%f theta:%f phi:%f\n",fiducial,omega,theta,fphi);
800 Float_t alfa1=theta;
801 Float_t theta1=phi;
802 Float_t omega1=omega;
803
804 //Solve the eq for a trial x
805 c0=-TMath::Power(y*TMath::Cos(alfa1)*TMath::Cos(theta1),2)-TMath::Power(y*TMath::Sin(alfa1),2)+TMath::Power(l*TMath::Tan(omega1),2)+2*l*y*TMath::Cos(alfa1)*TMath::Sin(theta1)*TMath::Power(TMath::Tan(omega1),2)+TMath::Power(y*TMath::Cos(alfa1)*TMath::Sin(theta1)*TMath::Tan(omega1),2);
806 c1=2*y*TMath::Cos(alfa1)*TMath::Sin(alfa1)-2*y*TMath::Cos(alfa1)*TMath::Power(TMath::Cos(theta1),2)*TMath::Sin(alfa1)+2*l*TMath::Sin(alfa1)*TMath::Sin(theta1)*TMath::Power(TMath::Tan(omega1),2)+2*y*TMath::Cos(alfa1)*TMath::Sin(alfa1)*TMath::Power(TMath::Sin(theta1),2)*TMath::Power(TMath::Tan(omega1),2);
807 c2=-TMath::Power(TMath::Cos(alfa1),2)-TMath::Power(TMath::Cos(theta1)*TMath::Sin(alfa1),2)+TMath::Power(TMath::Sin(alfa1)*TMath::Sin(theta1)*TMath::Tan(omega1),2);
808 //cout<<"Trial: y="<<y<<"c0="<<c0<<" c1="<<c1<<" c2="<<c2<<endl;
809 //printf("Result:%f\n\n",c1*c1-4*c2*c0);
810 //i+=.01;
811 counter +=1;
812 }
813
814 if (counter>=1000)
815 y=0;
816
817 //Choose which side to go...
818 //if(gRandom->Rndm(1)>.5) s=1;
819 //else s=-1;
820 if(i>500) s2=1;
821 //if (gRandom->Rndm(1)>.5) s2=1;
822 else s2=-1;
823 xtrial=(-c1+s2*TMath::Sqrt(c1*c1-4*c2*c0))/(2*c2);
824 //cout<<"x="<<xtrial<<" y="<<cy+y<<endl;
825 //printf("Coordinates: %f %f\n",xtrial,fCy+y);
826
827 REllipse->Fill(xtrial,y);
828
829 //printf("Coordinates: %f %f %f\n",vectorGlob[0],vectorGlob[1],vectorGlob[2]);
830 }
831
832 fc3->cd(2);
833 REllipse->Draw();
834}