Transition to NewIO
[u/mrichter/AliRoot.git] / RICH / AliRICHDetectV1.cxx
CommitLineData
02b30ae7 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$
88cb7938 18 Revision 1.1.4.2 2003/04/16 07:51:47 hristov
19 Removing malloc.h
20
21 Revision 1.1.4.1 2002/11/26 16:59:29 hristov
22 Merging NewIO with v3-09-04
23
24 Revision 1.1 2002/10/29 14:09:45 morsch
25 Second reconstruction algorithm. (J. Barbosa)
26
02b30ae7 27
28*/
29
88cb7938 30#include <stdlib.h>
02b30ae7 31
32#include "AliRICHDetectV1.h"
33#include "AliRICH.h"
34#include "AliRICHPoints.h"
35#include "AliRICHDetect.h"
36#include "AliRICHHit.h"
37#include "AliRICHDigit.h"
38#include "AliRICHRawCluster.h"
39#include "AliRICHCerenkov.h"
40#include "AliRICHSegmentationV0.h"
41#include "AliRun.h"
42#include "TParticle.h"
43#include "TTree.h"
44#include "TMath.h"
45#include "TRandom.h"
46#include "TH3.h"
47#include "TH2.h"
48#include "TCanvas.h"
49#include <TStyle.h>
50
51
02b30ae7 52
53ClassImp(AliRICHDetectV1)
54
55
56//___________________________________________
57AliRICHDetectV1::AliRICHDetectV1() : AliRICHDetect()
58{
59
60// Default constructor
61
62 fc1 = 0;
63 fc2 = 0;
64 fc3 = 0;
65
66}
67
68//___________________________________________
69AliRICHDetectV1::AliRICHDetectV1(const char *name, const char *title)
70 : AliRICHDetect()
71{
72
73 TStyle *mystyle=new TStyle("Plain","mystyle");
74 mystyle->SetPalette(1,0);
75 mystyle->cd();
76
77
78 fc1= new TCanvas("c1","Reconstructed points",50,50,300,350);
79 fc1->Divide(2,2);
80 fc2= new TCanvas("c2","Reconstructed points after SPOT",370,50,300,350);
81 fc2->Divide(2,2);
82 fc3= new TCanvas("c3","Used Digits",690,50,300,350);
83 fc4= new TCanvas("c4","Mesh activation data",50,430,600,350);
84 fc4->Divide(2,1);
85
86
87}
88
89//___________________________________________
90AliRICHDetectV1::~AliRICHDetectV1()
91{
92
93// Destructor
94
95}
96
97
98void AliRICHDetectV1::Detect(Int_t nev, Int_t type)
99{
100
101//
102// Detection algorithm
103
104
105 //printf("Detection started!\n");
106 Float_t omega,omega1,theta1,x,y,q=0,z,cx,cy,max,radius=0,meanradius=0;
107 Int_t maxi,maxj,maxk;
108 Float_t originalOmega, originalPhi, originalTheta;
109 Float_t steptheta,stepphi,stepomega;
110 Float_t binomega, bintheta, binphi;
111 Int_t intomega, inttheta, intphi;
112 Float_t maxRadius,minRadius,eccentricity,angularadius,offset,phi_relative;
113 Int_t i,j,k;
114
115 AliRICH *pRICH = (AliRICH*)gAlice->GetDetector("RICH");
116 AliRICHSegmentationV0* segmentation;
117 AliRICHChamber* iChamber;
118 AliRICHGeometry* geometry;
119
120 iChamber = &(pRICH->Chamber(0));
121 segmentation=(AliRICHSegmentationV0*) iChamber->GetSegmentationModel(0);
122 geometry=iChamber->GetGeometryModel();
123
124
125 //const Float_t Noise_Level=0; //Noise Level in percentage of mesh points
126 //const Float_t t=0.6; //Softening of Noise Correction (factor)
127
128 const Float_t kPi=TMath::Pi();
129
130 const Float_t kHeight=geometry->GetRadiatorToPads(); //Distance from Radiator to Pads in centimeters
131 //printf("Distance to Pads:%f\n",kHeight);
132
133 const Int_t kSpot=2; //number of passes with spot algorithm
134 const Int_t activ_tresh=0; //activation treshold to identify a track
135
136 const Int_t kDimensionTheta=2; //Matrix dimension for angle Detection
137 const Int_t kDimensionPhi=2;
138 const Int_t kDimensionOmega=50;
139
140 const Float_t SPOTp=.25; //Percentage of spot action
141 const Float_t kMinOmega=.6;
142 const Float_t kMaxOmega=.7; //Maximum Cherenkov angle to identify
143 const Float_t kMinTheta=0;
144 const Float_t kMaxTheta=0.5*kPi/180;
145 const Float_t kMinPhi=0;
146 const Float_t kMaxPhi=20*kPi/180;
147
148 const Float_t sigma=0.5; //half thickness of fiducial band in cm
149
150 Float_t rechit[6]; //Reconstructed point data
151
152 Int_t ***point = i3tensor(0,kDimensionTheta,0,kDimensionPhi,0,kDimensionOmega);
153 Int_t ***point1 = i3tensor(0,kDimensionTheta,0,kDimensionPhi,0,kDimensionOmega);
154
155 steptheta=(kMaxTheta-kMinTheta)/kDimensionTheta;
156 stepphi=(kMaxPhi-kMinPhi)/kDimensionPhi;
157 stepomega=(kMaxOmega-kMinOmega)/kDimensionOmega;
158
159 static TH3F *Points = new TH3F("Points","Reconstructed points 3D",kDimensionTheta,0,kDimensionTheta,kDimensionPhi,0,kDimensionPhi,kDimensionOmega,0,kDimensionOmega);
160 static TH2F *ThetaPhi = new TH2F("ThetaPhi","Theta-Phi projection",kDimensionTheta,0,kDimensionTheta,kDimensionPhi,0,kDimensionPhi);
161 static TH2F *OmegaTheta = new TH2F("OmegaTheta","Omega-Theta projection",kDimensionTheta,0,kDimensionTheta,kDimensionOmega,0,kDimensionOmega);
162 static TH2F *OmegaPhi = new TH2F("OmegaPhi","Omega-Phi projection",kDimensionPhi,0,kDimensionPhi,kDimensionOmega,0,kDimensionOmega);
163 static TH3F *SpotPoints = new TH3F("Points","Reconstructed points 3D, spot",kDimensionTheta,0,kDimensionTheta,kDimensionPhi,0,kDimensionPhi,kDimensionOmega,0,kDimensionOmega);
164 static TH2F *SpotThetaPhi = new TH2F("ThetaPhi","Theta-Phi projection, spot",kDimensionTheta,0,kDimensionTheta,kDimensionPhi,0,kDimensionPhi);
165 static TH2F *SpotOmegaTheta = new TH2F("OmegaTheta","Omega-Theta projection, spot",kDimensionTheta,0,kDimensionTheta,kDimensionOmega,0,kDimensionOmega);
166 static TH2F *SpotOmegaPhi = new TH2F("OmegaPhi","Omega-Phi projection, spot",kDimensionPhi,0,kDimensionPhi,kDimensionOmega,0,kDimensionOmega);
167 static TH2F *DigitsXY = new TH2F("DigitsXY","Pads used for reconstruction",150,-25,25,150,-25,25);
168 static TH1F *AngleAct = new TH1F("AngleAct","Activation per angle",100,.45,1);
169 static TH1F *Activation = new TH1F("Activation","Activation per ring",100,0,25);
170 Points->SetXTitle("theta");
171 Points->SetYTitle("phi");
172 Points->SetZTitle("omega");
173 ThetaPhi->SetXTitle("theta");
174 ThetaPhi->SetYTitle("phi");
175 OmegaTheta->SetXTitle("theta");
176 OmegaTheta->SetYTitle("omega");
177 OmegaPhi->SetXTitle("phi");
178 OmegaPhi->SetYTitle("omega");
179 SpotPoints->SetXTitle("theta");
180 SpotPoints->SetYTitle("phi");
181 SpotPoints->SetZTitle("omega");
182 SpotThetaPhi->SetXTitle("theta");
183 SpotThetaPhi->SetYTitle("phi");
184 SpotOmegaTheta->SetXTitle("theta");
185 SpotOmegaTheta->SetYTitle("omega");
186 SpotOmegaPhi->SetXTitle("phi");
187 SpotOmegaPhi->SetYTitle("omega");
188 AngleAct->SetFillColor(5);
189 AngleAct->SetXTitle("rad");
190 AngleAct->SetYTitle("activation");
191 Activation->SetFillColor(5);
192 Activation->SetXTitle("activation");
193
88cb7938 194 Int_t ntracks = (Int_t)pRICH->TreeH()->GetEntries();
02b30ae7 195
196 Float_t trackglob[3];
197 Float_t trackloc[3];
198
199 //printf("Area de uma elipse com teta 0 e Omega 45:%f",Area(0,45));
200
201 Int_t track;
202
203 for (track=0; track<ntracks;track++) {
204 gAlice->ResetHits();
88cb7938 205 pRICH->TreeH()->GetEvent(track);
02b30ae7 206 TClonesArray *pHits = pRICH->Hits();
207 if (pHits == 0) return;
208 Int_t nhits = pHits->GetEntriesFast();
209 if (nhits == 0) continue;
210 //Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
211 AliRICHHit *mHit = 0;
212 //Int_t npoints=0;
213
214 Int_t counter=0, counter1=0;
215 //Initialization
216 for(i=0;i<kDimensionTheta;i++)
217 {
218 for(j=0;j<kDimensionPhi;j++)
219 {
220 for(k=0;k<kDimensionOmega;k++)
221 {
222 counter++;
223 point[i][j][k]=0;
224 //printf("Dimensions theta:%d, phi:%d, omega:%d",kDimensionTheta,kDimensionPhi,kDimensionOmega);
225 //printf("Resetting %d %d %d, time %d\n",i,j,k,counter);
226 //-Noise_Level*(Area(i*kPi/(18*dimension),k*kMaxOmega/dimension)-Area((i-1)*kPi/(18*dimension),(k-1)*kMaxOmega/dimension));
227 //printf("n-%f",-Noise_Level*(Area(i*kPi/(18*dimension),k*kMaxOmega/dimension)-Area((i-1)*kPi/(18*dimension),(k-1)*kMaxOmega/dimension)));
228 }
229 }
230 }
231
232 Int_t ncerenkovs = pRICH->Cerenkovs()->GetEntriesFast();
233
234
235 originalOmega = 0;
236 counter = 0;
237
238 for (Int_t hit=0;hit<ncerenkovs;hit++) {
239 AliRICHCerenkov* cHit = (AliRICHCerenkov*) pRICH->Cerenkovs()->UncheckedAt(hit);
240 Float_t loss = cHit->fLoss; //did it hit the CsI?
241 Float_t production = cHit->fProduction; //was it produced in freon?
242 Float_t cherenkov = cHit->fCerenkovAngle; //production cerenkov angle
243 if (loss == 4 && production == 1)
244 {
245 counter +=1;
246 originalOmega += cherenkov;
247 //printf("%f\n",cherenkov);
248 }
249 }
250
251 originalOmega = originalOmega/counter;
252
253 //printf("Cerenkovs : %d\n",counter);
254
255 mHit = (AliRICHHit*) pHits->UncheckedAt(0);
256 Int_t nch = mHit->Chamber();
257 originalTheta = mHit->Theta();
258 originalPhi = mHit->Phi();
259 trackglob[0] = mHit->X();
260 trackglob[1] = mHit->Y();
261 trackglob[2] = mHit->Z();
262
263
264 printf("\n--------------------------------------\n");
265 printf("Chamber %d, track %d\n", nch, track);
266 printf("Original omega: %f\n",originalOmega);
267
268 iChamber = &(pRICH->Chamber(nch-1));
269
270 printf("Nch:%d x:%f y:%f\n",nch,trackglob[0],trackglob[2]);
271
272 iChamber->GlobaltoLocal(trackglob,trackloc);
273
274 iChamber->LocaltoGlobal(trackloc,trackglob);
275
276
277 cx=trackloc[0];
278 cy=trackloc[2];
279
280 printf("cy:%f ", cy);
281
282 if(counter != 0) //if there are cerenkovs
283 {
284
285 AliRICHDigit *points = 0;
286 TClonesArray *pDigits = pRICH->DigitsAddress(nch-1);
287
288 AliRICHRawCluster *cluster =0;
289 TClonesArray *pClusters = pRICH->RawClustAddress(nch-1);
290
291 Int_t maxcycle=0;
292
293 //digitize from digits
294
295 if(type==0)
296 {
297 gAlice->TreeD()->GetEvent(0);
298 Int_t ndigits = pDigits->GetEntriesFast();
299 maxcycle=ndigits;
300 //printf("Got %d digits\n",ndigits);
301 }
302
303 //digitize from clusters
304
305 if(type==1)
306 {
307 Int_t nent=(Int_t)gAlice->TreeR()->GetEntries();
308 gAlice->TreeR()->GetEvent(nent-1);
309 Int_t nclusters = pClusters->GetEntriesFast();
310 maxcycle=nclusters;
311 //printf("Got %d clusters\n",nclusters);
312 }
313
314
315
316
317 counter=0;
318 printf("Starting calculations\n");
319 printf(" Start Finish\n");
320 printf("Progress: ");
321
322
323 for(Float_t theta=0;theta<kMaxTheta;theta+=steptheta)
324 {
325 printf(".");
326 for(Float_t phi=0;phi<=kMaxPhi;phi+=stepphi)
327 {
328 for(omega=kMinOmega;omega<=kMaxOmega;omega+=stepomega)
329 {
330 //printf("Entering angle cycle\n");
331 omega1=SnellAngle(omega);
332 theta1=SnellAngle(theta);
333
334 maxRadius = kHeight*(tan(omega1+theta1)+tan(omega1-theta1))/2;
335 minRadius = kHeight*tan(omega1);
336 eccentricity = sqrt(1-(minRadius*minRadius)/(maxRadius*maxRadius));
337
338
339
340 offset = kHeight*(tan(omega1+theta1)-tan(omega1-theta1))/2;
341
342 //printf("phi:%f theta:%f omega:%f \n", phi,theta,omega);
343
344 //printf("offset:%f cx:%f cy:%f \n", offset,cx,cy);
345
346 Float_t cxn = cx + offset * sin(phi);
347 Float_t cyn = cy + offset * cos(phi);
348
349 //printf("cxn:%f cyn:%f\n", cxn, cyn);
350
351 for (Int_t cycle=0;cycle<maxcycle;cycle++)
352 {
353 //printf("Entering point cycle");
354 if(type==0)
355 {
356 points=(AliRICHDigit*) pDigits->UncheckedAt(cycle);
357 segmentation->GetPadC(points->PadX(), points->PadY(),x, y, z);
358 }
359
360 if(type==1)
361 {
362 cluster=(AliRICHRawCluster*) pClusters->UncheckedAt(cycle);
363 x=cluster->fX;
364 y=cluster->fY;
365 q=cluster->fQ;
366 }
367
368 if(type ==0 || q > 100)
369
370 {
371
372 x=x-cxn;
373 y=y-cyn;
374 radius=TMath::Sqrt(TMath::Power(x,2)+TMath::Power(y,2));
375
376 phi_relative = asin(y/radius);
377 phi_relative = TMath::Abs(phi_relative - phi);
378
379 angularadius = maxRadius*sqrt((1-eccentricity*eccentricity)/(1-eccentricity*eccentricity*cos(phi_relative)*cos(phi_relative)));
380
381 //printf("omega:%f min:%f rad:%f max:%f\n",omega, angularadius-sigma,radius,angularadius+sigma);
382
383
384 if((angularadius-sigma)<radius && (angularadius+sigma)>radius)
385 {
386 printf("omega:%f min:%f rad:%f max:%f\n",omega, angularadius-sigma,radius,angularadius+sigma);
387
388 bintheta=theta*kDimensionTheta/kMaxTheta;
389 binphi=phi*kDimensionPhi/kMaxPhi;
390 binomega=omega*kDimensionOmega/(kMaxOmega-kMinOmega);
391
392 if(Int_t(bintheta+0.5)==Int_t(bintheta))
393 inttheta=Int_t(bintheta);
394 else
395 inttheta=Int_t(bintheta+0.5);
396
397 if(Int_t(binomega+0.5)==Int_t(binomega))
398 intomega=Int_t(binomega);
399 else
400 intomega=Int_t(binomega+0.5);
401
402 if(Int_t(binphi+0.5)==Int_t(binphi))
403 intphi=Int_t(binphi);
404 else
405 intphi=Int_t(binphi+0.5);
406
407 //printf("Point added at %d %d %d\n",inttheta,intphi,intomega);
408
409 //if(type==0)
410 point[inttheta][intphi][intomega]+=1;
411 //if(type==1)
412 //point[inttheta][intphi][intomega]+=(Int_t)(q);
413
414 //printf("Omega stored:%d\n",intomega);
415 Points->Fill(inttheta,intphi,intomega,(float) 1);
416 ThetaPhi->Fill(inttheta,intphi,(float) 1);
417 OmegaTheta->Fill(inttheta,intomega,(float) 1);
418 OmegaPhi->Fill(intphi,intomega,(float) 1);
419 //printf("Filling at %d %d %d\n",Int_t(theta*kDimensionTheta/kMaxTheta),Int_t(phi*kDimensionPhi/kMaxPhi),Int_t(omega*kDimensionOmega/kMaxOmega));
420 }
421 //if(omega<kMaxOmega)point[Int_t(theta)][Int_t(phi)][Int_t(omega)]+=1;
422 }
423 }
424 }
425 }
426
427 }
428 //printf("Used %d digits for theta %3.1f\n",counter1, theta*180/kPi);
429
430 printf("\n");
431
432 meanradius=meanradius/counter;
433 //printf("Mean radius:%f, counter:%d\n",meanradius,counter);
434 rechit[5]=meanradius;
435 //printf("Used %d digits\n",counter1);
436 //printf("\n");
437
438 if(nev<2)
439 {
440 if(nev==0)
441 {
442 fc1->cd(1);
443 Points->Draw("colz");
444 fc1->cd(2);
445 ThetaPhi->Draw("colz");
446 fc1->cd(3);
447 OmegaTheta->Draw("colz");
448 fc1->cd(4);
449 OmegaPhi->Draw("colz");
450 fc3->cd();
451 DigitsXY->Draw("colz");
452 }
453 else
454 {
455 //fc1->cd(1);
456 //Points->Draw("same");
457 //fc1->cd(2);
458 //ThetaPhi->Draw("same");
459 //fc1->cd(3);
460 //OmegaTheta->Draw("same");
461 //fc1->cd(4);
462 //OmegaPhi->Draw("same");
463 }
464 }
465
466
467 //SPOT execute twice
468 for(Int_t s=0;s<kSpot;s++)
469 {
470 printf(" Applying Spot algorithm, pass %d\n", s);
471
472 //buffer copy
473 for(i=0;i<=kDimensionTheta;i++)
474 {
475 for(j=0;j<=kDimensionPhi;j++)
476 {
477 for(k=0;k<=kDimensionOmega;k++)
478 {
479 point1[i][j][k]=point[i][j][k];
480 }
481 }
482 }
483
484 //SPOT algorithm
485 for(i=1;i<kDimensionTheta-1;i++)
486 {
487 for(j=1;j<kDimensionPhi-1;j++)
488 {
489 for(k=1;k<kDimensionOmega-1;k++)
490 {
491 if((point[i][k][j]>point[i-1][k][j])&&(point[i][k][j]>point[i+1][k][j])&&
492 (point[i][k][j]>point[i][k-1][j])&&(point[i][k][j]>point[i][k+1][j])&&
493 (point[i][k][j]>point[i][k][j-1])&&(point[i][k][j]>point[i][k][j+1]))
494 {
495 //cout<<"SPOT"<<endl;
496 //Execute SPOT on point
497 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]));
498 point1[i-1][k][j]=Int_t(SPOTp*point[i-1][k][j]);
499 point1[i+1][k][j]=Int_t(SPOTp*point[i+1][k][j]);
500 point1[i][k-1][j]=Int_t(SPOTp*point[i][k-1][j]);
501 point1[i][k+1][j]=Int_t(SPOTp*point[i][k+1][j]);
502 point1[i][k][j-1]=Int_t(SPOTp*point[i][k][j-1]);
503 point1[i][k][j+1]=Int_t(SPOTp*point[i][k][j+1]);
504 }
505 }
506 }
507 }
508
509 //copy from buffer copy
510 counter1=0;
511 for(i=1;i<kDimensionTheta;i++)
512 {
513 for(j=1;j<kDimensionPhi;j++)
514 {
515 for(k=1;k<kDimensionOmega;k++)
516 {
517 point[i][j][k]=point1[i][j][k];
518 if(nev<20)
519 {
520 if(s==kSpot-1)
521 {
522 if(point1[i][j][k] != 0)
523 {
524 SpotPoints->Fill(i,j,k,(float) point1[i][j][k]);
525 //printf("Random number %f\n",random->Rndm(2));
526 //if(random->Rndm() < .2)
527 //{
528 SpotThetaPhi->Fill(i,j,(float) point1[i][j][k]);
529 SpotOmegaTheta->Fill(i,k,(float) point1[i][j][k]);
530 SpotOmegaPhi->Fill(j,k,(float) point1[i][j][k]);
531 counter1++;
532 //}
533 //printf("Filling at %d %d %d value %f\n",i,j,k,(float) point1[i][j][k]);
534 }
535 }
536 }
537 //if(point1[i][j][k] != 0)
538 //printf("Last transfer point: %d, point1, %d\n",point[i][j][k],point1[i][j][k]);
539 }
540 }
541 }
542 }
543
544 //printf("Filled %d cells\n",counter1);
545
546 if(nev<2)
547 {
548 if(nev==0)
549 {
550 fc2->cd(1);
551 SpotPoints->Draw("colz");
552 fc2->cd(2);
553 SpotThetaPhi->Draw("colz");
554 fc2->cd(3);
555 SpotOmegaTheta->Draw("colz");
556 fc2->cd(4);
557 SpotOmegaPhi->Draw("colz");
558 }
559 else
560 {
561 //fc2->cd(1);
562 //SpotPoints->Draw("same");
563 //fc2->cd(2);
564 //SpotThetaPhi->Draw("same");
565 //fc2->cd(3);
566 //SpotOmegaTheta->Draw("same");
567 //fc2->cd(4);
568 //SpotOmegaPhi->Draw("same");
569 }
570 }
571
572
573 //Identification is equivalent to maximum determination
574 max=0;maxi=0;maxj=0;maxk=0;
575
576 printf(" Proceeding to identification");
577
578 for(i=0;i<kDimensionTheta;i++)
579 for(j=0;j<kDimensionPhi;j++)
580 for(k=0;k<kDimensionOmega;k++)
581 if(point[i][j][k]>max)
582 {
583 //cout<<"maxi="<<i*90/dimension<<" maxj="<<j*90/dimension<<" maxk="<<k*kMaxOmega/dimension*180/kPi<<" max="<<max<<endl;
584 maxi=i;maxj=j;maxk=k;
585 max=point[i][j][k];
586 printf(".");
587 //printf("Max Omega %d, Max Theta %d, Max Phi %d (%d counts)\n",maxk,maxi,maxj,max);
588 }
589 printf("\n");
590
591 Float_t FinalOmega;
592 Float_t FinalTheta;
593 Float_t FinalPhi;
594
595
596 if(max>activ_tresh)
597 {
598 FinalOmega = maxk*(kMaxOmega-kMinOmega)/kDimensionOmega;
599 FinalTheta = maxi*kMaxTheta/kDimensionTheta;
600 FinalPhi = maxj*kMaxPhi/kDimensionPhi;
601
602 FinalOmega += kMinOmega;
603 }
604 else
605 {
606 FinalOmega = 0;
607 FinalTheta = 0;
608 FinalPhi = 0;
609
610 printf(" Ambiguous data!\n");
611 }
612
613
614
615 //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",h,cx,cy,maxk*kPi/(kDimensionTheta*4));
616 printf(" Indentified angles: cerenkov - %f, theta - %3.1f, phi - %3.1f (%f activation)\n", FinalOmega, FinalTheta*180/kPi, FinalPhi*180/kPi, max);
617 //printf("Detected angle for height %3.1f and for center %3.1f %3.1f:%f\n",kHeight,cx,cy,maxk);
618
619 AngleAct->Fill(FinalOmega, (float) max);
620 Activation->Fill(max, (float) 1);
621
622 //fscanf(omegas,"%f",&realomega);
623 //fscanf(thetas,"%f",&realtheta);
624 //printf("Real Omega: %f",realomega);
625 //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;
626
627 //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));
628
629 /*for(j=0;j<np;j++)
630 pointpp(maxj*90/kDimensionTheta,maxi*90/kDimensionPhi,maxk*kMaxOmega/kDimensionOmega*180/kPi,cx,cy);//Generates a point on the elipse*/
631
632
633 //Start filling rec. hits
634
635 rechit[0] = FinalTheta;
636 rechit[1] = 90*kPi/180 + FinalPhi;
637 rechit[2] = FinalOmega;
638 rechit[3] = cx;
639 rechit[4] = cy;
640
641 //CreatePoints(FinalTheta, 270*kPi/180 + FinalPhi, FinalOmega, kHeight);
642
643 //printf ("track %d, theta %f, phi %f, omega %f\n\n\n",track,rechit[0],rechit[1],rechit[2]);
644 //printf("rechit %f %f %f %f %f\n",rechit[0],rechit[1],rechit[2],rechit[3],rechit[4]);
645 //printf("Chamber:%d",nch);
646
647
648 }
649
650 else //if no cerenkovs
651
652 {
653
654 rechit[0] = 0;
655 rechit[1] = 0;
656 rechit[2] = 0;
657 rechit[3] = 0;
658 rechit[4] = 0;
659 originalOmega = 0;
660 originalTheta = 0;
661 originalPhi =0;
662 }
663
664
665 // fill rechits
666 pRICH->AddRecHit3D(nch-1,rechit,originalOmega, originalTheta, originalPhi);
667 printf("track %d, theta r:%f o:%f, phi r:%f o:%f, omega r:%f o:%f cx:%f cy%f\n\n\n", track, rechit[0], originalTheta, rechit[1], originalPhi, rechit[2], originalOmega, cx, cy);
668
669 }
670
671 if(type==1) //reco from clusters
672 {
673 pRICH->ResetRawClusters();
674 //Int_t nent=(Int_t)gAlice->TreeR()->GetEntries();
675 //gAlice->TreeR()->GetEvent(track);
676 //printf("Going to branch %d\n",track);
677 //gAlice->GetEvent(nev);
678 }
679
680
681 //printf("\n\n\n\n");
682 gAlice->TreeR()->Fill();
683 TClonesArray *fRec;
684 for (i=0;i<kNCH;i++) {
685 fRec=pRICH->RecHitsAddress3D(i);
686 int ndig=fRec->GetEntriesFast();
687 printf ("Chamber %d, rings %d\n",i+1,ndig);
688 }
689
690 fc4->cd(1);
691 AngleAct->Draw();
692 fc4->cd(2);
693 Activation->Draw();
694
695 pRICH->ResetRecHits3D();
696
697 free_i3tensor(point,0,kDimensionTheta,0,kDimensionPhi,0,kDimensionOmega);
698 free_i3tensor(point1,0,kDimensionTheta,0,kDimensionPhi,0,kDimensionOmega);
699
700
701}
702
703Int_t ***AliRICHDetectV1::i3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
704// allocate a Int_t 3tensor with range t[nrl..nrh][ncl..nch][ndl..ndh]
705{
706 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
707 Int_t ***t;
708
709 int NR_END=1;
710
711 // allocate pointers to pointers to rows
712 t=(Int_t ***) malloc((size_t)((nrow+NR_END)*sizeof(Int_t**)));
713 if (!t) printf("allocation failure 1 in f3tensor()");
714 t += NR_END;
715 t -= nrl;
716
717 // allocate pointers to rows and set pointers to them
718 t[nrl]=(Int_t **) malloc((size_t)((nrow*ncol+NR_END)*sizeof(Int_t*)));
719 if (!t[nrl]) printf("allocation failure 2 in f3tensor()");
720 t[nrl] += NR_END;
721 t[nrl] -= ncl;
722
723 // allocate rows and set pointers to them
724 t[nrl][ncl]=(Int_t *) malloc((size_t)((nrow*ncol*ndep+NR_END)*sizeof(Int_t)));
725 if (!t[nrl][ncl]) printf("allocation failure 3 in f3tensor()");
726 t[nrl][ncl] += NR_END;
727 t[nrl][ncl] -= ndl;
728
729 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
730 for(i=nrl+1;i<=nrh;i++) {
731 t[i]=t[i-1]+ncol;
732 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
733 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
734 }
735
736 // return pointer to array of pointers to rows
737 return t;
738}
739
740
741void AliRICHDetectV1::free_i3tensor(int ***t, long nrl, long nrh, long ncl, long nch,long ndl, long ndh)
742// free a Int_t f3tensor allocated by i3tensor()
743{
744 int NR_END=1;
745
746 free((char*) (t[nrl][ncl]+ndl-NR_END));
747 free((char*) (t[nrl]+ncl-NR_END));
748 free((char*) (t+nrl-NR_END));
749}