Add tools in RichMenu
[u/mrichter/AliRoot.git] / RICH / AliRICH.cxx
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 #include "AliRICH.h"
17 #include "AliRICHParam.h"
18 #include "AliRICHChamber.h"
19 #include "AliRICHTracker.h"
20 #include "AliRICHHelix.h"
21 //#include <TArrayF.h>
22 #include <TGeometry.h>
23 #include <TBRIK.h>
24 #include <TTUBE.h>
25 #include <TFile.h>
26 #include <TNode.h> 
27 #include <TObjArray.h>
28 #include <TParticle.h>
29 #include <AliStack.h>
30 #include <AliMagF.h>
31 #include <AliRun.h>
32 #include <AliRunDigitizer.h>
33 #include <AliMC.h>
34 #include <AliESD.h>
35 #include <TVirtualMC.h>
36 #include <TH1F.h>
37 #include <TH2F.h>
38 #include <TBenchmark.h>
39 #include <AliLog.h>
40 #include <TNtupleD.h>
41 #include <AliTracker.h>
42 #include <AliRawDataHeader.h>
43 #include <TLatex.h> //Display()
44 #include <TCanvas.h> //Display()
45 #include <TGraph.h> //Display()
46 #include <TStyle.h> //Display()
47 #include <TMarker.h> //Display()
48  
49 ClassImp(AliRICH)    
50 //__________________________________________________________________________________________________
51 // RICH manager class   
52 //BEGIN_HTML
53 /*
54   <img src="gif/alirich.gif">
55 */
56 //END_HTML
57 //__________________________________________________________________________________________________
58 AliRICH::AliRICH():AliDetector(),fParam(0),  fSdigits(0),fNsdigits(0),fDigs(0),fClus(0) 
59 {
60 //Default ctor should not contain any new operators
61 //AliDetector ctor deals with Hits and Digits  
62   for(int i=0;i<kNchambers;i++) fNdigs[i]  =0;
63   for(int i=0;i<kNchambers;i++) fNclus[i]=0;
64 //  fCounters.ResizeTo(20); fCounters.Zero();
65 }//AliRICH::AliRICH()
66 //__________________________________________________________________________________________________
67 AliRICH::AliRICH(const char *name, const char *title)
68         :AliDetector(name,title),fParam(new AliRICHParam),fSdigits(0),fNsdigits(0),fDigs(0),fClus(0)
69 {
70 //Named ctor
71   AliDebug(1,"Start.");
72 //AliDetector ctor deals with Hits and Digits (reset them to 0, does not create them)
73   HitsCreate();          gAlice->GetMCApp()->AddHitList(fHits);
74   fCounters.ResizeTo(20); fCounters.Zero();
75   AliDebug(1,"Stop.");
76 }//AliRICH::AliRICH(const char *name, const char *title)
77 //__________________________________________________________________________________________________
78 AliRICH::~AliRICH()
79 {
80 //dtor
81   AliDebug(1,"Start.");
82
83   if(fParam)     delete fParam;
84   
85   if(fHits)      delete fHits;
86   if(fSdigits)   delete fSdigits;
87   if(fDigits)    delete fDigits;
88   if(fDigs)      {fDigs->Delete();   delete fDigs;}
89   if(fClus)      {fClus->Delete();   delete fClus;}
90   AliDebug(1,"Stop.");    
91 }//AliRICH::~AliRICH()
92 //__________________________________________________________________________________________________
93 void AliRICH::Hits2SDigits()
94 {
95 // Create a list of sdigits corresponding to list of hits. Every hit generates one or more sdigits.
96   AliDebug(1,"Start.");
97   for(Int_t iEventN=0;iEventN<GetLoader()->GetRunLoader()->GetAliRun()->GetEventsPerRun();iEventN++){//events loop
98     GetLoader()->GetRunLoader()->GetEvent(iEventN);//get next event
99   
100     if(!GetLoader()->TreeH()) GetLoader()->LoadHits();    GetLoader()->GetRunLoader()->LoadHeader(); 
101     if(!GetLoader()->GetRunLoader()->TreeK())             GetLoader()->GetRunLoader()->LoadKinematics();//from
102     if(!GetLoader()->TreeS()) GetLoader()->MakeTree("S"); MakeBranch("S");//to
103           
104     for(Int_t iPrimN=0;iPrimN<GetLoader()->TreeH()->GetEntries();iPrimN++){//prims loop
105       GetLoader()->TreeH()->GetEntry(iPrimN);
106       for(Int_t iHitN=0;iHitN<Hits()->GetEntries();iHitN++){//hits loop 
107         AliRICHHit *pHit=(AliRICHHit*)Hits()->At(iHitN);//get current hit                
108         TVector2 x2 = C(pHit->C())->Mrs2Anod(0.5*(pHit->InX3()+pHit->OutX3()));//hit position in the anod plane
109         Int_t iTotQdc=P()->TotQdc(x2,pHit->Eloss());//total charge produced by hit, 0 if hit in dead zone
110         if(iTotQdc==0) continue;
111         //
112         //need to quantize the anod....
113         TVector padHit=AliRICHParam::Loc2Pad(x2);
114         TVector2 padHitXY=AliRICHParam::Pad2Loc(padHit);
115         TVector2 anod;
116         if((x2.Y()-padHitXY.Y())>0) anod.Set(x2.X(),padHitXY.Y()+AliRICHParam::PitchAnod()/2);
117         else anod.Set(x2.X(),padHitXY.Y()-AliRICHParam::PitchAnod()/2);
118         //end to quantize anod
119         //
120         TVector area=P()->Loc2Area(anod);//determine affected pads, dead zones analysed inside
121         AliDebug(1,Form("hitanod(%6.2f,%6.2f)->area(%3.0f,%3.0f)-(%3.0f,%3.0f) QDC=%4i",anod.X(),anod.Y(),area[0],area[1],area[2],area[3],iTotQdc));
122         TVector pad(2);
123         for(pad[1]=area[1];pad[1]<=area[3];pad[1]++)//affected pads loop
124           for(pad[0]=area[0];pad[0]<=area[2];pad[0]++){                    
125             Double_t padQdc=iTotQdc*P()->FracQdc(anod,pad);
126             AliDebug(1,Form("current pad(%3.0f,%3.0f) with QDC  =%6.2f",pad[0],pad[1],padQdc));
127             if(padQdc>0.1) SDigitAdd(pHit->C(),pad,padQdc,GetLoader()->GetRunLoader()->Stack()->Particle(pHit->GetTrack())->GetPdgCode(),pHit->GetTrack());
128           }//affected pads loop 
129       }//hits loop
130     }//prims loop
131     GetLoader()->TreeS()->Fill();
132     GetLoader()->WriteSDigits("OVERWRITE");
133     SDigitsReset();
134   }//events loop  
135   GetLoader()->UnloadHits(); GetLoader()->GetRunLoader()->UnloadHeader(); GetLoader()->GetRunLoader()->UnloadKinematics();
136   GetLoader()->UnloadSDigits();  
137   AliDebug(1,"Stop.");
138 }//Hits2SDigits()
139 //__________________________________________________________________________________________________
140 void AliRICH::Digits2Raw()
141 {
142 //Loops over all digits and creates raw data files in DDL format. GetEvent() is done outside (AliSimulation)
143 //RICH has 2 DDL per chamber, even number for right part(2-4-6) odd number for left part(1-3-5) 
144 //RICH has no any propriate header just uses the common one
145 //Each PC is divided by 8 rows counted from 1 to 8 from top to bottom for left PCs(1-3-5) and from bottom to top for right PCc(2-4-6)     (denoted  rrrrr 5 bits 32 values)
146 //Each raw is composed from 10 DILOGIC chips counted from left to right from 1 to 10                                                      (denoted   dddd 4 bits 16 values)
147 //Each DILOGIC chip serves 48 channels counted from 0 to 47                                                                               (denoted aaaaaa 6 bits 64 values)
148 //So RICH info word is  32 bits word with structure:   0000 0rrr rrdd ddaa aaaa qqqq qqqq qqqq (five 0 five r six a twelve q) with QDC    (denoted q...q 12 bits 4096 values)
149   AliDebug(1,"Start.");
150   GetLoader()->LoadDigits();
151   GetLoader()->TreeD()->GetEntry(0);
152   
153   Int_t kRichOffset=0x700; //currently one DDL per 3 sectors
154   
155   ofstream file135,file246;//output streams 2 DDL per chamber
156   AliRawDataHeader header;//empty DDL miniheader
157   UInt_t word32=1;        //32 bits data word 
158   
159   for(Int_t iChN=1;iChN<=kNchambers;iChN++){ //2 DDL per chamber open both in parallel   
160     file135.open(Form("RICH_%4i.ddl",kRichOffset+2*iChN-1));   //left part of chamber; sectors 1-3-5 odd DDL number
161     file246.open(Form("RICH_%4i.ddl",kRichOffset+2*iChN));     //right part of chamber; sectors 2-4-6 even DDL number
162 //common DDL header defined by standart, now dummy as the total number of bytes is not yet known    
163     file135.write((char*)&header,sizeof(header)); //dummy header just place holder
164     file246.write((char*)&header,sizeof(header)); //actual will be written later
165     
166     Int_t counter135=0,counter246=0;//counts total number of records per DDL 
167     
168     for(Int_t iDigN=0;iDigN<Digits(iChN)->GetEntriesFast();iDigN++){//digits loop for a given chamber
169       AliRICHDigit *pDig=(AliRICHDigit*)Digits(iChN)->At(iDigN);
170       word32=UInt_t (pDig->Q()+0x400*pDig->X()+0x4000*pDig->Y());  //arbitrary structure
171       switch(pDig->S()){//readout by vertical sectors: 1,3,5-left DDL 2,4,6-right DDL
172         case 1: case 3: case 5: file135.write((char*)&word32,sizeof(word32)); counter135++; break;
173         case 2: case 4: case 6: file246.write((char*)&word32,sizeof(word32)); counter246++; break;
174       }//switch sector  
175     }//digits loop for a given chamber
176 //now count total byte number for each DDL file and rewrite actual header    
177     header.fSize=sizeof(header)+counter135*sizeof(word32);   header.SetAttribute(0); file135.seekp(0); file135.write((char*)&header,sizeof(header));
178     header.fSize=sizeof(header)+counter246*sizeof(word32);   header.SetAttribute(0); file246.seekp(0); file246.write((char*)&header,sizeof(header));
179     file135.close(); file246.close();
180   }//chambers loop  
181   GetLoader()->UnloadDigits();
182   AliDebug(1,"Stop.");      
183 }//Digits2Raw()
184 //__________________________________________________________________________________________________
185 void AliRICH::BuildGeometry() 
186 {
187 //Builds a TNode geometry for event display
188   AliInfo("Start.");
189   
190   TNode *node, *subnode, *top;
191   top=gAlice->GetGeometry()->GetNode("alice");
192
193   Float_t widx =P()->SectorSizeX();
194   Float_t leny =P()->SectorSizeY();
195   Float_t dz   =P()->Zfreon()+P()->Zwin()+P()->Pc2Win();
196   Float_t dead =P()->DeadZone();
197
198   new TBRIK("RICH","RICH","void",widx+dead/2,leny+leny/2+dead,dz+0.1); //RICH chamber
199   new TBRIK("RPC" ,"RPC" ,"void",widx/2,leny/2,0.01);                  //RICH sector 
200
201   for(int i=1;i<=P()->Nchambers();i++){
202     top->cd();
203     node = new TNode(Form("RICH%i",i),Form("RICH%i",i),"RICH",C(i)->Center().X(),C(i)->Center().Y(),C(i)->Center().Z(),C(i)->RotMatrixName());
204     node->SetLineColor(kRed);
205     node->cd();
206     subnode = new TNode("PHOTO1","PHOTO1","RPC",-widx/2-dead/2,-leny-dead/2,dz,"");
207     subnode->SetLineColor(kGreen);
208     fNodes->Add(subnode);
209     subnode = new TNode("PHOTO1","PHOTO1","RPC", widx/2+dead/2,-leny-dead/2,dz,"");
210     subnode->SetLineColor(kGreen);
211     fNodes->Add(subnode);
212     subnode = new TNode("PHOTO1","PHOTO1","RPC",-widx/2-dead/2,           0,dz,"");
213     subnode->SetLineColor(kGreen);
214     fNodes->Add(subnode);
215     subnode = new TNode("PHOTO1","PHOTO1","RPC", widx/2+dead/2,           0,dz,"");
216     subnode->SetLineColor(kGreen);
217     fNodes->Add(subnode);
218     subnode = new TNode("PHOTO1","PHOTO1","RPC",-widx/2-dead/2, leny+dead/2,dz,"");
219     subnode->SetLineColor(kGreen);
220     fNodes->Add(subnode);
221     subnode = new TNode("PHOTO1","PHOTO1","RPC", widx/2+dead/2, leny+dead/2,dz,"");
222     subnode->SetLineColor(kGreen);
223     fNodes->Add(subnode);
224     fNodes->Add(node);
225   }
226
227   AliDebug(1,"Stop.");    
228 }//void AliRICH::BuildGeometry()
229 //__________________________________________________________________________________________________
230 void AliRICH::CreateMaterials()
231 {
232 // Definition of available RICH materials  
233         
234   Int_t   material=0; //tmp material id number
235   Float_t a=0,z=0,den=0,radl=0,absl=0; //tmp material parameters
236   
237   Float_t tmaxfd=-10.0, deemax=-0.2, stemax=-0.1,epsil=0.001, stmin=-0.001; 
238   Int_t   isxfld = gAlice->Field()->Integ();
239   Float_t sxmgmx = gAlice->Field()->Max();
240     
241   Float_t aAir[4]={12,14,16,36};  Float_t zAir[4]={6,7,8,18}; Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};//total 0.9999999
242   AliMixture(++material, "RichAir",aAir,zAir,den=0.00120479,4,wAir);                                          //1 (Air) 0.01% C 75% N  23% O 1% Ar
243   AliMedium(kAir, "RichAir",material, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
244   
245   AliMixture(++material, "RichAerogel",aAir,zAir,den=P()->DenGel(),4,wAir);                     //Aerogel represented by Air
246   AliMedium(kGel, "RichAerogel",material, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
247   
248   AliMixture(++material, "RichAerogelReflector",aAir,zAir,den=P()->DenGel(),4,wAir);           //Aerogel reflector represented by Air
249   AliMedium(kReflector, "RichAerogelReflector",material, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
250   
251   AliMaterial(++material, "RichRohacell", a=12.01,z=6.0, den=0.1,     radl=18.8,   absl=0);                   //2 Rohacell 51 C-equiv radl rad cover
252   AliMedium(kRoha, "RichRohacell", material, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
253   
254   Float_t  aQuartz[2]={28.09,16.0};  Float_t  zQuartz[2]={14.00, 8.0};  Float_t  wQuartz[2]={1,2};
255   AliMixture(++material, "RichSiO2",aQuartz,zQuartz,den=2.64,-2, wQuartz);                                    //3 Quarz (SiO2) -trasparent rad window
256   AliMedium(kSiO2, "RichSiO2",material, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
257   
258   Float_t  aFreon[2]={12,19};  Float_t  zFreon[2]={6,9};  Float_t wmatFreon[2]={6,14};                        // C12-6 F19-9   
259   AliMixture(++material, "RichC6F14",aFreon,zFreon,den=1.68,-2,wmatFreon);                                    //4 Freon (C6F14) 
260   AliMedium(kC6F14, "RichC6F14",material, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
261   
262   Float_t aMethane[2]={12.01,1}; Float_t zMethane[2]={6,1}; Float_t wMethane[2]={1,4};
263   AliMixture (++material, "RichCH4", aMethane, zMethane, den=7.17e-4,-2, wMethane);                        //5,9 methane (CH4) normal and for Gap    
264   AliMedium(kCH4, "RichCH4"   , material, 1, isxfld, sxmgmx, tmaxfd, stemax,  deemax, epsil,  stmin);  
265   AliMixture (++material, "RichCH4gap", aMethane, zMethane, den=7.17e-4,-2, wMethane);                      //5,9 methane (CH4) normal and for Gap    
266   AliMedium(kGap, "RichCH4gap", material, 1, isxfld, sxmgmx, tmaxfd, 0.1   , -deemax, epsil, -stmin);
267     
268   AliMaterial(++material, "RichCsI",      a=12.01,z=6.0, den=0.1,     radl=18.8,   absl=0);                   //6 CsI-radl equivalent
269   AliMedium(kCsI, "RichCsI", material, 1, isxfld, sxmgmx,tmaxfd, stemax, deemax, epsil, stmin);
270   
271   AliMaterial(++material, "RichGridCu",    a=63.54,z=29.0,den=8.96,    radl=1.43,   absl=0);                   //7 anode grid (Cu) 
272   AliMedium(kGridCu, "RichGridCu", material, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
273     
274   AliMaterial(++material, "RichPcbCu",     a=63.54,z=29.0,den=8.96,    radl=1.4,    absl=0);                   //12 Cu
275   AliMedium(kCu, "RichPcbCu", material, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
276   
277   AliMixture (++material, "RichOpSiO2",aQuartz, zQuartz, den=2.64, -2, wQuartz);                             //8 Quarz (SiO2) - opaque
278   AliMedium(kOpSiO2, "RichOpSiO2",material, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
279   
280   AliMaterial(++material, "RichAl",     a=26.98,z=13.0,den=2.699,     radl=8.9,    absl=0);                 //10 aluminium sheet (Al)
281   AliMedium(kAl, "RichAl", material, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
282   
283   Float_t aGlass[5]={12.01,28.09,16,10.8,23}; Float_t zGlass[5]={6,14,8,5,11};  Float_t wGlass[5]={0.5,0.105,0.355,0.03,0.01};
284   AliMixture(++material,"RichGlass",aGlass, zGlass, den=1.74, 5, wGlass);                                    //11 Glass 50%-C 10.5%-Si 35.5%-O 3%-B 1%-Na
285   AliMedium(kGlass, "RichGlass", material, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
286   
287   AliMaterial(++material, "RichW",  a=183.84,z=74.0,den=19.3,    radl=0.35,    absl=185.0/den);              //13 W - anod wires
288   AliMedium(kW, "RichW", material, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
289   
290   
291   if(P()->IsRadioSrc()){
292     AliInfo("Special radioactive source materials");
293     AliMaterial(++material, "RichSteel",  a=55.845,z=26.0,den=7.87,    radl=1.76,    absl=131.9/den);        //14 Steel (Fe)
294     AliMedium(kSteel, "RichSteel", material, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
295   
296     AliMaterial(++material, "RichPerpex",  a=63.54,z=29.0,den=8.96,    radl=1.4,    absl=0);                 //15 Perpex
297     AliMedium(kPerpex, "RichPerpex", material, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
298     
299     AliMaterial(++material, "RichSr90",  a=87.62,z=38.0,den=2.54,    radl=4.24,    absl=0);                  //16 Sr90
300     AliMedium(kSr90, "RichSr90", material, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
301     
302     Float_t aMylar[5]={12.01,1,16}; Float_t zMylar[5]={6,1,8};  Float_t wMylar[5]={5,4,5};                  //17 Mylar C5H4O5
303     AliMixture(++material,"RichMylar",aMylar, zMylar, den=1.39, -3, wMylar); 
304     AliMedium(kMylar, "RichMylar", material, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
305   }
306   
307 //Optical properties:
308 #include "Opticals.h"
309   gMC->SetCerenkov((*fIdtmed)[kAir]      , kNbins, aPckov, aAbsCH4    , aQeAll, aIdxCH4);       //1 Air
310   gMC->SetCerenkov((*fIdtmed)[kRoha]     , kNbins, aPckov, aAbsCH4    , aQeAll, aIdxCH4);       //2 Honeycomb  
311   gMC->SetCerenkov((*fIdtmed)[kSiO2]     , kNbins, aPckov, aAbsSiO2   , aQeAll, aIdxSiO2);      //3 Quartz SiO2 
312   gMC->SetCerenkov((*fIdtmed)[kC6F14]    , kNbins, aPckov, aAbsC6F14  , aQeAll, aIdxC6F14);     //4 Freon C6F14
313   gMC->SetCerenkov((*fIdtmed)[kCH4]      , kNbins, aPckov, aAbsCH4    , aQeAll, aIdxCH4);       //5 Methane CH4 
314   gMC->SetCerenkov((*fIdtmed)[kCsI]      , kNbins, aPckov, aAbsCsI    , aQeCsI, aIdxCH4);       //6 CsI
315   gMC->SetCerenkov((*fIdtmed)[kGridCu]   , kNbins, aPckov, aAbsGrid   , aQeAll, aIdxMetal);     //7 grid Cu
316   gMC->SetCerenkov((*fIdtmed)[kOpSiO2]   , kNbins, aPckov, aAbsOpSiO2 , aQeAll, aIdxMetal);     //8 Opaque quartz SiO2
317   gMC->SetCerenkov((*fIdtmed)[kGap]      , kNbins, aPckov, aAbsCH4    , aQeAll, aIdxCH4);       //9 Special methane gap
318   gMC->SetCerenkov((*fIdtmed)[kAl]       , kNbins, aPckov, aAbsGrid   , aQeAll, aIdxMetal);     //10 Aluminium
319   gMC->SetCerenkov((*fIdtmed)[kGlass]    , kNbins, aPckov, aAbsOpSiO2 , aQeAll, aIdxMetal);     //11 Glass    
320   gMC->SetCerenkov((*fIdtmed)[kGel]      , kNbins, aPckov, aAbsGel    , aQeAll, aIdxGel);       //12 Aerogel
321   gMC->SetCerenkov((*fIdtmed)[kReflector], kNbins, aPckov, aAbsRef    , aQeAll, aIdxMetal);     //13 Aerogel reflector
322 }//void AliRICH::CreateMaterials()
323 //__________________________________________________________________________________________________
324 Float_t AliRICH::Fresnel(Float_t ene,Float_t pdoti, Bool_t pola)
325 {
326
327     //ENE(EV), PDOTI=COS(INC.ANG.), PDOTR=COS(POL.PLANE ROT.ANG.)
328     
329     Float_t en[36] = {5.0,5.1,5.2,5.3,5.4,5.5,5.6,5.7,5.8,5.9,6.0,6.1,6.2,
330                       6.3,6.4,6.5,6.6,6.7,6.8,6.9,7.0,7.1,7.2,7.3,7.4,7.5,7.6,7.7,
331                       7.8,7.9,8.0,8.1,8.2,8.3,8.4,8.5};
332     Float_t csin[36] = {2.14,2.21,2.33,2.48,2.76,2.97,2.99,2.59,2.81,3.05,
333                         2.86,2.53,2.55,2.66,2.79,2.96,3.18,3.05,2.84,2.81,2.38,2.11,
334                         2.01,2.13,2.39,2.73,3.08,3.15,2.95,2.73,2.56,2.41,2.12,1.95,
335                         1.72,1.53};
336     Float_t csik[36] = {0.,0.,0.,0.,0.,0.196,0.408,0.208,0.118,0.49,0.784,0.543,
337                         0.424,0.404,0.371,0.514,0.922,1.102,1.139,1.376,1.461,1.253,0.878,
338                         0.69,0.612,0.649,0.824,1.347,1.571,1.678,1.763,1.857,1.824,1.824,
339                         1.714,1.498};
340     Float_t xe=ene;
341     Int_t  j=Int_t(xe*10)-49;
342     Float_t cn=csin[j]+((csin[j+1]-csin[j])/0.1)*(xe-en[j]);
343     Float_t ck=csik[j]+((csik[j+1]-csik[j])/0.1)*(xe-en[j]);
344
345     //FORMULAE FROM HANDBOOK OF OPTICS, 33.23 OR
346     //W.R. HUNTER, J.O.S.A. 54 (1964),15 , J.O.S.A. 55(1965),1197
347
348     Float_t sinin=TMath::Sqrt(1-pdoti*pdoti);
349     Float_t tanin=sinin/pdoti;
350
351     Float_t c1=cn*cn-ck*ck-sinin*sinin;
352     Float_t c2=4*cn*cn*ck*ck;
353     Float_t aO=TMath::Sqrt(0.5*(TMath::Sqrt(c1*c1+c2)+c1));
354     Float_t b2=0.5*(TMath::Sqrt(c1*c1+c2)-c1);
355     
356     Float_t rs=((aO-pdoti)*(aO-pdoti)+b2)/((aO+pdoti)*(aO+pdoti)+b2);
357     Float_t rp=rs*((aO-sinin*tanin)*(aO-sinin*tanin)+b2)/((aO+sinin*tanin)*(aO+sinin*tanin)+b2);
358     
359
360     //CORRECTION FACTOR FOR SURFACE ROUGHNESS
361     //B.J. STAGG  APPLIED OPTICS, 30(1991),4113
362
363     Float_t sigraf=18.;
364     Float_t lamb=1240/ene;
365     Float_t fresn;
366  
367     Float_t  rO=TMath::Exp(-(4*TMath::Pi()*pdoti*sigraf/lamb)*(4*TMath::Pi()*pdoti*sigraf/lamb));
368
369     if(pola)
370     {
371         Float_t pdotr=0.8;                                 //DEGREE OF POLARIZATION : 1->P , -1->S
372         fresn=0.5*(rp*(1+pdotr)+rs*(1-pdotr));
373     }
374     else
375         fresn=0.5*(rp+rs);
376       
377     fresn = fresn*rO;
378     return(fresn);
379 }//Fresnel()
380 //__________________________________________________________________________________________________
381 void AliRICH::MakeBranch(Option_t* option)
382 {
383 //Create Tree branches for the RICH.
384   AliDebug(1,Form("Start with option= %s.",option));
385     
386   const Int_t kBufferSize = 4000;
387       
388   const char *cH = strstr(option,"H");
389   const char *cD = strstr(option,"D");
390   const char *cR = strstr(option,"R");
391   const char *cS = strstr(option,"S");
392
393   if(cH&&TreeH()){//H
394     HitsCreate();      //branch will be created in AliDetector::MakeBranch
395   }//H     
396   AliDetector::MakeBranch(option);//this is after cH because we need to guarantee that fHits array is created
397       
398   if(cS&&fLoader->TreeS()){//S  
399     SDigitsCreate();   MakeBranchInTree(fLoader->TreeS(),"RICH",&fSdigits,kBufferSize,0) ;
400   }//S
401    
402   if(cD&&fLoader->TreeD()){//D
403     DigitsCreate();
404     for(Int_t i=0;i<kNchambers;i++){ 
405       MakeBranchInTree(fLoader->TreeD(),Form("%s%d",GetName(),i+1),&((*fDigs)[i]),kBufferSize,0);
406     }
407   }//D
408   
409   if(cR&&fLoader->TreeR()){//R
410     ClustersCreate();
411     for(Int_t i=0;i<kNchambers;i++)
412       MakeBranchInTree(fLoader->TreeR(),Form("%sClusters%d",GetName(),i+1), &((*fClus)[i]), kBufferSize, 0);    
413   }//R
414   AliDebug(1,"Stop.");   
415 }//void AliRICH::MakeBranch(Option_t* option)
416 //__________________________________________________________________________________________________
417 void AliRICH::SetTreeAddress()
418 {
419 //Set branch address for the Hits and Digits Tree.
420   AliDebug(1,"Start.");
421       
422   TBranch *branch;
423     
424   if(fLoader->TreeH()){//H
425     AliDebug(1,"tree H is requested.");
426     HitsCreate();//branch map will be in AliDetector::SetTreeAddress    
427   }//H
428   AliDetector::SetTreeAddress();//this is after TreeH because we need to guarantee that fHits array is created
429
430   if(fLoader->TreeS()){//S
431     AliDebug(1,"tree S is requested.");
432     branch=fLoader->TreeS()->GetBranch(GetName());        if(branch){SDigitsCreate();   branch->SetAddress(&fSdigits);}
433   }//S
434     
435   if(fLoader->TreeD()){//D    
436     AliDebug(1,"tree D is requested.");
437     for(int i=0;i<kNchambers;i++){      
438       branch=fLoader->TreeD()->GetBranch(Form("%s%d",GetName(),i+1)); 
439       if(branch){DigitsCreate(); branch->SetAddress(&((*fDigs)[i]));}
440     }
441   }//D
442     
443   if(fLoader->TreeR()){//R
444     AliDebug(1,"tree R is requested.");
445     for(int i=0;i<kNchambers;i++){         
446       branch=fLoader->TreeR()->GetBranch(Form("%sClusters%d" ,GetName(),i+1));
447       if(branch){ClustersCreate(); branch->SetAddress(&((*fClus)[i]));}
448     }
449   }//R
450   AliDebug(1,"Stop.");
451 }//void AliRICH::SetTreeAddress()
452 //__________________________________________________________________________________________________
453 void AliRICH::Print(Option_t *option)const
454 {
455 //Debug printout
456   TObject::Print(option);
457   P()->Print();
458   fCounters.Print();
459 }//void AliRICH::Print(Option_t *option)const
460 //__________________________________________________________________________________________________
461 void AliRICH::ControlPlots()
462
463 //Creates a set of QA hists to control the results of simulation. Hists are in file $HOME/RCP.root     
464   TH1F             *pElecP=0 ,*pMuonP=0 ,*pPionP=0 ,*pKaonP=0 ,*pProtP=0,  //stack particles
465                    *pHxD=0,*pHyD=0,*pHxSd=0,*pHySd=0,      //diff hit position - digit sdigit position 
466                    *pNumClusH1=0,
467                    *pQdcH1=0,       *pSizeH1=0,
468                    *pPureMipQdcH1=0,*pPureMipSizeH1=0,
469                    *pPureCerQdcH1=0,*pPureCerSizeH1=0,
470                    *pPureFeeQdcH1=0,*pPureFeeSizeH1=0,
471                    *pMipQdcH1=0,    *pPhotQdcH1=0;  
472   TH2F *pMapH2=0,*pPureMipMapH2=0,*pPureCerMapH2=0,*pPureFeeMapH2=0;
473   TH1F *pelecRadius=0,*pprotRadius=0,*pprotbarRadius=0;
474 //load all information  
475                  GetLoader()->GetRunLoader()->LoadHeader();  
476                  GetLoader()->GetRunLoader()->LoadKinematics();  
477                  GetLoader()->LoadHits();  
478   Bool_t isSdig=0;//!GetLoader()->LoadSDigits();
479   Bool_t isDig =0;//!GetLoader()->LoadDigits();
480   Bool_t isClus=!GetLoader()->LoadRecPoints();
481
482   gBenchmark->Start("ControlPlots");
483     
484   TFile *pFile = new TFile("$(HOME)/RCP.root","RECREATE");   
485   
486   pElecP=new TH1F("Pelec","Electrons made hit in RICH;p [GeV]",1000,-30,30); 
487   pMuonP=new TH1F("Pmuon","Muons made hit in RICH;p [GeV]",1000,-30,30); 
488   pPionP=new TH1F("Ppion","Pions made hit in RICH;p [GeV]",1000,-30,30); 
489   pKaonP=new TH1F("Pkaon","Kaon made hit in RICH;p [GeV]",1000,-30,30); 
490   pProtP=new TH1F("Pprot","Protons made hit in RICH;p [GeV]",1000,-30,30); 
491   pelecRadius=new TH1F("elecRadius","elec",600,0.,600.);  
492   pprotRadius=new TH1F("protRadius","elec",600,0.,600.);  
493   pprotbarRadius=new TH1F("protbarRadius","elec",600,0.,600.);
494     
495   if(isSdig){
496     AliInfo("SDigits available");
497     pHxSd=new TH1F("DiffHitSDigitX","Hit-SDigit diff X all chambers;diff [cm]",300,-10,10); 
498     pHySd=new TH1F("DiffHitSDigitY","Hit-SDigit diff Y all chambers;diff [cm]",300,-10,10); 
499   }//isSdig
500   
501   if(isDig){
502     AliInfo("Digits available");
503     pHxD=new TH1F("DiffHitDigitX","Hit-Digit diff X all chambers;diff [cm]",300,-10,10); 
504     pHyD=new TH1F("DiffHitDigitY","Hit-Digit diff Y all chambers;diff [cm]",300,-10,10); 
505   }//isDig
506   
507   if(isClus){ 
508     AliInfo("Clusters available");
509     pNumClusH1=new TH1F("NumClusPerEvent","Number of clusters per event;number",50,0,49);
510     
511     pQdcH1        =new TH1F("ClusQdc",   "Cluster Charge all chambers;q [QDC]",P()->MaxQdc(),0,P()->MaxQdc());
512     pSizeH1       =new TH1F("ClusSize",  "Cluster size all chambers;size [number of pads in cluster]",100,0,100);
513     pMapH2        =new TH2F("ClusMap",   "Cluster map;x [cm];y [cm]",1000,0,P()->PcSizeX(),1000,0,P()->PcSizeY());
514   
515     pMipQdcH1     =new TH1F("QdcMip"      ,"MIP Cluster Charge all chambers;q [QDC]",P()->MaxQdc(),0,P()->MaxQdc());
516     pPhotQdcH1    =new TH1F("QdcPhot"     ,"Cer+Fee Cluster Charge all chambers;q [QDC]",P()->MaxQdc(),0,P()->MaxQdc());
517         
518     pPureMipQdcH1 =new TH1F("QdcPureMip"  ,"MIP only Cluster Charge all chambers;q [QDC]",P()->MaxQdc(),0,P()->MaxQdc());
519     pPureMipSizeH1=new TH1F("SizePureMip" ,"MIP only Cluster size all chambers;size [number of pads in cluster]",100,0,100);
520     pPureMipMapH2 =new TH2F("MapPureMip"  ,"MIP only Cluster map;x [cm];y [cm]",1000,0,P()->PcSizeX(),1000,0,P()->PcSizeY());
521   
522     pPureCerQdcH1 =new TH1F("QdcPureCer"  ,"Cerenkov only Cluster Charge all chambers;q [QDC]",P()->MaxQdc(),0,P()->MaxQdc());
523     pPureCerSizeH1=new TH1F("SizePureCer" ,"Cernekov only Cluster size all chambers;size [number of pads in cluster]",100,0,100);
524     pPureCerMapH2 =new TH2F("MapPureCer"  ,"Cerenkov only Cluster map;x [cm];y [cm]",1000,0,P()->PcSizeX(),1000,0,P()->PcSizeY());
525     
526     pPureFeeQdcH1 =new TH1F("QdcPureFee"  ,"Feedback only Cluster Charge all chambers;q [QDC]",P()->MaxQdc(),0,P()->MaxQdc());
527     pPureFeeSizeH1=new TH1F("SizePureFee" ,"Feedback only Cluster size all chambers;size [number of pads in cluster]",100,0,100);
528     pPureFeeMapH2 =new TH2F("MapPureFee"  ,"Feedback only Cluster map;x [cm];y [cm]",1000,0,P()->PcSizeX(),1000,0,P()->PcSizeY());
529
530   }//isClus
531 //end of hists booking  
532   for(Int_t iEvtN=0;iEvtN < GetLoader()->GetRunLoader()->GetAliRun()->GetEventsPerRun();iEvtN++){//events loop
533     GetLoader()->GetRunLoader()->GetEvent(iEvtN);    //get current event
534     
535     for(Int_t iPrimN=0;iPrimN < GetLoader()->TreeH()->GetEntries();iPrimN++){//hit tree loop
536       GetLoader()->TreeH()->GetEntry(iPrimN);      
537       for(Int_t j=0;j<Hits()->GetEntries();j++){//hits loop
538         AliRICHHit *pHit = (AliRICHHit*)Hits()->At(j);
539         TParticle *pParticle = GetLoader()->GetRunLoader()->Stack()->Particle(pHit->GetTrack());//get particle produced this hit
540         Double_t dRadius = TMath::Sqrt(pParticle->Vx()*pParticle->Vx()+pParticle->Vy()*pParticle->Vy()+pParticle->Vz()*pParticle->Vz());
541         switch(pParticle->GetPdgCode()){
542           case kPositron : pElecP->Fill( pParticle->P());pelecRadius->Fill(dRadius); break;
543           case kElectron : pElecP->Fill(-pParticle->P());pelecRadius->Fill(dRadius); break;
544           
545           case kMuonPlus : pMuonP->Fill( pParticle->P()); break;
546           case kMuonMinus: pMuonP->Fill(-pParticle->P()); break;
547                     
548           case kPiPlus   : pPionP->Fill( pParticle->P()); break;
549           case kPiMinus  : pPionP->Fill(-pParticle->P()); break;
550           
551           case kKPlus    : pKaonP->Fill( pParticle->P()); break;
552           case kKMinus   : pKaonP->Fill(-pParticle->P()); break;
553           
554           case kProton   : pProtP->Fill( pParticle->P()); pprotRadius->Fill(dRadius); break;
555           case kProtonBar: pProtP->Fill(-pParticle->P()); pprotbarRadius->Fill(dRadius); break;
556               
557         }//switch PdgCode
558             
559       }//hits loop
560     }//hit tree loop
561     
562     if(isSdig){
563       GetLoader()->TreeS()->GetEntry(0);  
564       for(Int_t iSdigN=0;iSdigN<SDigits()->GetEntries();iSdigN++){//sdigits loop 
565         AliRICHDigit *pSdig=(AliRICHDigit*)SDigits()->At(iSdigN); //get current sdigit pointer  
566         AliRICHHit   *pHit=Hit(pSdig->GetTrack(0));               //get hit of this sdigit (always one)
567         TVector2 hit2 =C(pHit->C())->Mrs2Pc(pHit->OutX3());       //this hit position  in local system
568         TVector2 sdig2=P()->Pad2Loc(pSdig->Pad());                //center of pad for this sdigit
569         pHxSd->Fill(hit2.X()-sdig2.X());        
570         pHySd->Fill(hit2.Y()-sdig2.Y());      
571       }//sdigits loop
572     }//if(isSdig)
573         
574     if(isDig)  GetLoader()->TreeD()->GetEntry(0);  
575     if(isClus) GetLoader()->TreeR()->GetEntry(0);
576     
577     for(Int_t iChamN=1;iChamN<=7;iChamN++){//chambers loop
578       if(isDig){
579         for(Int_t iDigN=0;iDigN<Digits(iChamN)->GetEntries();iDigN++){//digits loop
580           AliRICHDigit *pDig=(AliRICHDigit*)Digits(iChamN)->At(iDigN);
581           AliRICHHit   *pHit=Hit(pDig->GetTrack(0));           //get first hit of this digit
582           TVector2 hitV2=C(iChamN)->Mrs2Pc(pHit->OutX3()); 
583           TVector2 digV2=P()->Pad2Loc(pDig->Pad());            //center of pad for this digit
584           pHxD->Fill(hitV2.X()-digV2.X());        pHyD->Fill(hitV2.Y()-digV2.Y());
585         }//digits loop
586       }//isDig
587       if(isClus){
588         Int_t iNclusCham=Clusters(iChamN)->GetEntries(); if(iNclusCham) pNumClusH1->Fill(iNclusCham);//number of clusters per event
589         for(Int_t iClusN=0;iClusN<iNclusCham;iClusN++){//clusters loop
590           AliRICHCluster *pClus=(AliRICHCluster*)Clusters(iChamN)->At(iClusN);
591                                        pQdcH1        ->Fill(pClus->Q());   
592                                        pSizeH1       ->Fill(pClus->Size());  
593                                        pMapH2        ->Fill(pClus->X(),pClus->Y()); //common
594                                        
595            if(pClus->IsSingleMip())     {pPureMipQdcH1 ->Fill(pClus->Q());
596                                        pPureMipSizeH1->Fill(pClus->Size());
597                                        pPureMipMapH2 ->Fill(pClus->X(),pClus->Y());}//Pure Mips
598                                        
599            if(pClus->IsSingleCerenkov()){pPureCerQdcH1 ->Fill(pClus->Q());
600                                        pPureCerSizeH1->Fill(pClus->Size());
601                                        pPureCerMapH2 ->Fill(pClus->X(),pClus->Y());}//Pure Cerenkovs
602                                        
603            if(pClus->IsSingleFeedback()){pPureFeeQdcH1 ->Fill(pClus->Q());
604                                        pPureFeeSizeH1->Fill(pClus->Size());
605                                        pPureFeeMapH2 ->Fill(pClus->X(),pClus->Y());}//Pure Feedbacks
606            
607            if(pClus->IsMip()) {pMipQdcH1 ->Fill(pClus->Q());} //MIP+ other contributions
608            if(!pClus->IsPureMip())     pPhotQdcH1->Fill(pClus->Q());  //not MIP
609         }//clusters loop
610       }//isClus
611     }//chambers loop
612     Info("ControlPlots","Event %i processed.",iEvtN);
613   }//events loop 
614              GetLoader()->UnloadHits();
615   if(isSdig) GetLoader()->UnloadSDigits();
616   if(isDig)  GetLoader()->UnloadDigits();
617   if(isClus) GetLoader()->UnloadRecPoints();
618   
619   GetLoader()->GetRunLoader()->UnloadHeader();  
620   GetLoader()->GetRunLoader()->UnloadKinematics();  
621   
622   pFile->Write(); delete pFile;
623   
624   gBenchmark->Show("ControlPlots");
625 }//ControlPlots()
626 //__________________________________________________________________________________________________
627 AliRICHHit* AliRICH::Hit(Int_t tid)const
628 {
629 //defines which hit provided by given tid for the currently loaded event
630   GetLoader()->LoadHits();
631   for(Int_t iPrimN=0;iPrimN<GetLoader()->TreeH()->GetEntries();iPrimN++){//prims loop      
632     GetLoader()->TreeH()->GetEntry(iPrimN);
633     for(Int_t iHitN=0;iHitN<Hits()->GetEntries();iHitN++){
634       AliRICHHit *pHit=(AliRICHHit*)Hits()->At(iHitN);
635       if(tid==pHit->Track()) {GetLoader()->UnloadHits();return pHit;}
636     }//hits
637   }//prims loop
638   GetLoader()->UnloadHits();
639   return 0;
640 }
641 //__________________________________________________________________________________________________
642 void AliRICH::HitsPrint(Int_t iEvtN)const
643 {
644 //Prints a list of RICH hits for a given event. Default is event number 0.
645   if(GetLoader()->GetRunLoader()->GetEvent(iEvtN)) return;    
646   AliInfo(Form("List of RICH hits for event %i",iEvtN));
647   if(GetLoader()->LoadHits()) return;
648   
649   Int_t iTotalHits=0;
650   for(Int_t iPrimN=0;iPrimN<GetLoader()->TreeH()->GetEntries();iPrimN++){//prims loop
651     GetLoader()->TreeH()->GetEntry(iPrimN);      
652     Hits()->Print();
653     iTotalHits+=Hits()->GetEntries();
654   }
655   GetLoader()->UnloadHits();
656   AliInfo(Form("totally %i hits",iTotalHits));
657 }
658 //__________________________________________________________________________________________________
659 void AliRICH::SDigitsPrint(Int_t iEvtN)const
660 {
661 //prints a list of RICH sdigits  for a given event
662   if(GetLoader()->GetRunLoader()->GetEvent(iEvtN)) return;    
663   Info("PrintSDigits","List of RICH sdigits for event %i",iEvtN);
664   if(GetLoader()->LoadSDigits()) return;
665   
666   GetLoader()->TreeS()->GetEntry(0);
667   SDigits()->Print();
668   GetLoader()->UnloadSDigits();
669   Info("PrintSDigits","totally %i sdigits",SDigits()->GetEntries());
670 }
671 //__________________________________________________________________________________________________
672 void AliRICH::DigitsPrint(Int_t iEvtN)const
673 {
674 //prints a list of RICH digits  for a given event
675   if(GetLoader()->GetRunLoader()->GetEvent(iEvtN)) return;    
676   Info("PrintDigits","List of RICH digits for event %i",iEvtN);
677   if(GetLoader()->LoadDigits()) return;
678   
679   Int_t iTotalDigits=0;
680   GetLoader()->TreeD()->GetEntry(0);
681   for(Int_t iChamber=1;iChamber<=kNchambers;iChamber++){
682     Digits(iChamber)->Print();
683     iTotalDigits+=Digits(iChamber)->GetEntries();
684   }
685   GetLoader()->UnloadDigits();
686   Info("PrintDigits","totally %i Digits",iTotalDigits);
687 }
688 //__________________________________________________________________________________________________
689 void AliRICH::OccupancyPrint(Int_t iEvtN)const
690 {
691 //prints occupancy for each chamber in a given event
692   if(GetLoader()->GetRunLoader()->GetEvent(iEvtN)) return;    
693   Info("Occupancy","for event %i",iEvtN);
694   if(GetLoader()->LoadDigits()) return;
695
696   Int_t totPadsPerChamber = AliRICHParam::NpadsX()*AliRICHParam::NpadsY();  
697   GetLoader()->TreeD()->GetEntry(0);
698   for(Int_t iChamber=1;iChamber<=kNchambers;iChamber++){
699     Double_t occupancy = (Double_t)Digits(iChamber)->GetEntries()/(Double_t)totPadsPerChamber;
700     Info("Occupancy","for chamber %i = %4.2f per cent",iChamber,occupancy*100.);
701   }
702   GetLoader()->UnloadDigits();
703 }
704 //__________________________________________________________________________________________________
705 void AliRICH::ClustersPrint(Int_t iEvtN)const
706 {
707 //prints a list of RICH clusters  for a given event
708   AliInfo(Form("List of RICH clusters for event %i",iEvtN));
709   GetLoader()->GetRunLoader()->GetEvent(iEvtN);    
710   if(GetLoader()->LoadRecPoints()) return;
711   
712   Int_t iTotalClusters=0;
713   GetLoader()->TreeR()->GetEntry(0);
714   for(Int_t iChamber=1;iChamber<=kNchambers;iChamber++){
715     Clusters(iChamber)->Print();
716     iTotalClusters+=Clusters(iChamber)->GetEntries();
717   }
718   GetLoader()->UnloadRecPoints();
719   AliInfo(Form("totally %i clusters for event %i",iTotalClusters,iEvtN));
720 }
721 //__________________________________________________________________________________________________
722 void AliRICH::PrintTracks(Int_t iEvtN)
723 {
724 //prints a list of tracks (including secondary) for a given event
725   AliInfo(Form("List of all tracks for event %i",iEvtN));
726   GetLoader()->GetRunLoader()->GetEvent(iEvtN);    
727   if(GetLoader()->GetRunLoader()->LoadHeader()) return;
728   if(GetLoader()->GetRunLoader()->LoadKinematics()) return;
729   AliStack *pStack=GetLoader()->GetRunLoader()->Stack();
730   
731   for(Int_t i=0;i<pStack->GetNtrack();i++) pStack->Particle(i)->Print();
732   
733   AliInfo(Form("totally %i tracks including %i primaries for event %i",pStack->GetNtrack(),pStack->GetNprimary(),iEvtN));
734   GetLoader()->GetRunLoader()->UnloadHeader();
735   GetLoader()->GetRunLoader()->UnloadKinematics();
736 }
737 //__________________________________________________________________________________________________
738 void AliRICH::GeomPadPanelFrame()const
739 {
740 //Pad Panel frame  6 sectors
741   Double_t cm=1,mm=0.1*cm;//default is cm
742   Float_t par[3];
743   
744   par[0]=648*mm/2;par[1]=  411*mm/2;par[2]=40  *mm/2;gMC->Gsvolu("RPPF","BOX ",(*fIdtmed)[kAl]  ,par,3);//PPF 2001P2 inner size of the slab by 1mm more
745   par[0]=181*mm/2;par[1]=89.25*mm/2;par[2]=38.3*mm/2;gMC->Gsvolu("PPFL","BOX ",(*fIdtmed)[kAir] ,par,3);//large whole
746   par[0]=114*mm/2;par[1]=89.25*mm/2;par[2]=38.3*mm/2;gMC->Gsvolu("PPFS","BOX ",(*fIdtmed)[kAir] ,par,3);//small whole
747   par[0]=644*mm/2;par[1]=  407*mm/2;par[2]= 1.7*mm/2;gMC->Gsvolu("RPC ","BOX ",(*fIdtmed)[kCsI] ,par,3);//by 0.2 mm more then actual size (PCB 2006P1)
748   
749   gMC->Gspos("RPPF",1,"RICH",    -335*mm,      -433*mm,  8*cm+20*mm,  0,"ONLY");//F1 2040P1 z p.84 TDR
750   gMC->Gspos("RPPF",2,"RICH",    +335*mm,      -433*mm,  8*cm+20*mm,  0,"ONLY");
751   gMC->Gspos("RPPF",3,"RICH",    -335*mm,         0*mm,  8*cm+20*mm,  0,"ONLY");
752   gMC->Gspos("RPPF",4,"RICH",    +335*mm,         0*mm,  8*cm+20*mm,  0,"ONLY");
753   gMC->Gspos("RPPF",5,"RICH",    -335*mm,      +433*mm,  8*cm+20*mm,  0,"ONLY");
754   gMC->Gspos("RPPF",6,"RICH",    +335*mm,      +433*mm,  8*cm+20*mm,  0,"ONLY");  
755     gMC->Gspos("RPC ",1,"RPPF",       0*mm,         0*mm,   -19.15*mm,  0,"ONLY");//PPF 2001P2 
756     gMC->Gspos("PPFL",1,"RPPF",  -224.5*mm,  -151.875*mm,     0.85*mm,  0,"ONLY");
757     gMC->Gspos("PPFL",2,"RPPF",  -224.5*mm,  - 50.625*mm,     0.85*mm,  0,"ONLY");
758     gMC->Gspos("PPFL",3,"RPPF",  -224.5*mm,  + 50.625*mm,     0.85*mm,  0,"ONLY");
759     gMC->Gspos("PPFL",4,"RPPF",  -224.5*mm,  +151.875*mm,     0.85*mm,  0,"ONLY");
760     gMC->Gspos("PPFS",1,"RPPF",  - 65.0*mm,  -151.875*mm,     0.85*mm,  0,"ONLY");
761     gMC->Gspos("PPFS",2,"RPPF",  - 65.0*mm,  - 50.625*mm,     0.85*mm,  0,"ONLY");
762     gMC->Gspos("PPFS",3,"RPPF",  - 65.0*mm,  + 50.625*mm,     0.85*mm,  0,"ONLY");
763     gMC->Gspos("PPFS",4,"RPPF",  - 65.0*mm,  +151.875*mm,     0.85*mm,  0,"ONLY");
764     gMC->Gspos("PPFS",5,"RPPF",  + 65.0*mm,  -151.875*mm,     0.85*mm,  0,"ONLY");
765     gMC->Gspos("PPFS",6,"RPPF",  + 65.0*mm,  - 50.625*mm,     0.85*mm,  0,"ONLY");
766     gMC->Gspos("PPFS",7,"RPPF",  + 65.0*mm,  + 50.625*mm,     0.85*mm,  0,"ONLY");
767     gMC->Gspos("PPFS",8,"RPPF",  + 65.0*mm,  +151.875*mm,     0.85*mm,  0,"ONLY"); 
768     gMC->Gspos("PPFL",5,"RPPF",  +224.5*mm,  -151.875*mm,     0.85*mm,  0,"ONLY");
769     gMC->Gspos("PPFL",6,"RPPF",  +224.5*mm,  - 50.625*mm,     0.85*mm,  0,"ONLY");
770     gMC->Gspos("PPFL",7,"RPPF",  +224.5*mm,  + 50.625*mm,     0.85*mm,  0,"ONLY");
771     gMC->Gspos("PPFL",8,"RPPF",  +224.5*mm,  +151.875*mm,     0.85*mm,  0,"ONLY");
772 }//GeomPadPanelFrame()
773 //__________________________________________________________________________________________________
774 void AliRICH::GeomAmpGap()const
775 {
776 //Gap - anod wires 6 copies to RICH
777   Double_t cm=1,mm=0.1*cm,mkm=0.001*mm;//default is cm
778   Int_t matrixIdReturn=0; //matrix id returned by AliMatrix
779   Float_t par[3];
780   
781   par[0]=648*mm/2;par[1]=  411*mm/2 ;par[2]=4.45*mm/2;gMC->Gsvolu("RGAP ","BOX ",(*fIdtmed)[kCH4] ,par,3);//xy as PPF 2001P2 z WP 2099P1
782   par[0]=  0*mm  ;par[1]=  20*mkm/2 ;par[2]= 648*mm/2;gMC->Gsvolu("RANO","TUBE",(*fIdtmed)[kW]   ,par,3);//WP 2099P1 z = gap x PPF 2001P2
783   AliMatrix(matrixIdReturn,180,0, 90,90, 90,0); //wires along x
784   
785   gMC->Gspos("RGAP",1,"RICH",    -335*mm,      -433*mm,8*cm-2.225*mm, 0,"ONLY"); //F1 2040P1 z WP 2099P1
786   gMC->Gspos("RGAP",2,"RICH",    +335*mm,      -433*mm,8*cm-2.225*mm, 0,"ONLY"); 
787   gMC->Gspos("RGAP",3,"RICH",    -335*mm,         0*mm,8*cm-2.225*mm, 0,"ONLY"); 
788   gMC->Gspos("RGAP",4,"RICH",    +335*mm,         0*mm,8*cm-2.225*mm, 0,"ONLY"); 
789   gMC->Gspos("RGAP",5,"RICH",    -335*mm,      +433*mm,8*cm-2.225*mm, 0,"ONLY"); 
790   gMC->Gspos("RGAP",6,"RICH",    +335*mm,      +433*mm,8*cm-2.225*mm, 0,"ONLY"); 
791   for(int i=1;i<=96;i++)
792     gMC->Gspos("RANO",i,"RGAP",     0*mm, -411/2*mm+i*4*mm, 0.185*mm, matrixIdReturn,"ONLY"); //WP 2099P1  
793 }//GeomAmpGap()
794 //__________________________________________________________________________________________________
795 void AliRICH::GeomRadiators()const
796 {
797 //Defines radiators geometry  
798   Double_t mm=0.1;//default is cm
799   Float_t par[3];
800   par[0]=1330*mm/2 ;par[1]= 413*mm/2  ;par[2]=  24*mm/2;  gMC->Gsvolu("RRAD","BOX ",(*fIdtmed)[kC6F14]     ,par,3); // Rad 2011P1
801   par[0]=1330*mm/2 ;par[1]= 413*mm/2  ;par[2]=   4*mm/2;  gMC->Gsvolu("RRFR","BOX ",(*fIdtmed)[kRoha]      ,par,3); //front 
802   par[0]=1330*mm/2 ;par[1]= 413*mm/2  ;par[2]=   5*mm/2;  gMC->Gsvolu("RRWI","BOX ",(*fIdtmed)[kSiO2]      ,par,3); //window
803   par[0]=1330*mm/2 ;par[1]=   5*mm/2  ;par[2]=  15*mm/2;  gMC->Gsvolu("RRLO","BOX ",(*fIdtmed)[kRoha]      ,par,3); //long side  
804   par[0]=  10*mm/2 ;par[1]= 403*mm/2  ;par[2]=  15*mm/2;  gMC->Gsvolu("RRSH","BOX ",(*fIdtmed)[kRoha]      ,par,3); //short side 
805   par[0]=   0      ;par[1]=  10*mm/2  ;par[2]=  15*mm/2;  gMC->Gsvolu("RRSP","TUBE",(*fIdtmed)[kSiO2]      ,par,3); //spacer        
806     
807   gMC->Gspos("RRAD",1,"RICH",   0*mm,-434*mm,   -12*mm,  0,"ONLY"); //3 radiators to RICH
808   gMC->Gspos("RRAD",2,"RICH",   0*mm,   0*mm,   -12*mm,  0,"ONLY"); 
809   gMC->Gspos("RRAD",3,"RICH",   0*mm,+434*mm,   -12*mm,  0,"ONLY"); 
810     gMC->Gspos("RRFR",1,"RRAD",   0*mm,   0*mm, -10.0*mm,  0,"ONLY"); //front cover 
811     gMC->Gspos("RRWI",1,"RRAD",   0*mm,   0*mm,   9.5*mm,  0,"ONLY"); //quartz window (back cover)
812     gMC->Gspos("RRLO",1,"RRAD",   0*mm,-204*mm,  -0.5*mm,  0,"ONLY"); //long side
813     gMC->Gspos("RRLO",2,"RRAD",   0*mm,+204*mm,  -0.5*mm,  0,"ONLY"); //long side
814     gMC->Gspos("RRSH",1,"RRAD",-660*mm,   0*mm,  -0.5*mm,  0,"ONLY"); //short side
815     gMC->Gspos("RRSH",2,"RRAD",+660*mm,   0*mm,  -0.5*mm,  0,"ONLY"); //short side 
816     for(int i=0;i<3;i++)
817       for(int j=0;j<10;j++)
818         gMC->Gspos("RRSP",10*i+j,"RRAD",-1330*mm/2+116*mm+j*122*mm,(i-1)*105*mm,-0.5*mm,0,"ONLY");//spacers
819 }//GeomRadiators()
820 //__________________________________________________________________________________________________
821 void AliRICH::GeomSandBox()const
822 {
823 //Defines SandBox geometry
824   Double_t mm=0.1;//default is cm
825   Float_t par[3];
826   par[0]=1419*mm/2 ;par[1]=1378*mm/2;par[2]=50.5*mm/2; gMC->Gsvolu("RSNB","BOX ",(*fIdtmed)[kAir]  ,par,3);  //2072P1   
827   par[0]=1419*mm/2 ;par[1]=1378*mm/2;par[2]= 0.5*mm/2; gMC->Gsvolu("RSCO","BOX ",(*fIdtmed)[kAl]   ,par,3);  //cover
828   par[0]=1359*mm/2 ;par[1]=1318*mm/2;par[2]=49.5*mm/2; gMC->Gsvolu("RSHO","BOX ",(*fIdtmed)[kRoha] ,par,3); //honeycomb structure 
829   
830   gMC->Gspos("RSNB",1,"RICH",   0*mm, 0*mm, -73.75*mm, 0,"ONLY"); //p.84 TDR sandbox to rich
831     gMC->Gspos("RSHO",1,"RSNB", 0*mm, 0*mm,      0*mm, 0,"ONLY"); //2072P1 honeycomv to sandbox
832     gMC->Gspos("RSCO",1,"RSNB", 0*mm, 0*mm,    +25*mm, 0,"ONLY"); //cover to sandbox
833     gMC->Gspos("RSCO",2,"RSNB", 0*mm, 0*mm,    -25*mm, 0,"ONLY"); //cover to sandbox
834 }//GeomSandBox()
835 //__________________________________________________________________________________________________
836 void AliRICH::GeomRadioSrc()const
837 {
838 // Defines geometry for radioactive source  
839   Double_t cm=1,mm=0.1*cm,mkm=0.001*cm;
840   Float_t par[3];
841   
842   par[0]=0 ;par[1]= 70*mm/2  ;par[2]=  30*mm/2;      gMC->Gsvolu("RSRC","TUBE",(*fIdtmed)[kCH4]    ,par,3); //top src container
843     par[0]=0 ;par[1]= 38*mm/2  ;par[2]=  21.8*mm/2;  gMC->Gsvolu("RSAG","TUBE",(*fIdtmed)[kAl]     ,par,3); //Al glass
844       par[0]=0 ;par[1]= 34*mm/2  ;par[2]=  20*mm/2;  gMC->Gsvolu("RSPP","TUBE",(*fIdtmed)[kPerpex] ,par,3); //perpex plug
845         par[0]=0 ;par[1]= 5*mm/2  ;par[2]=  15*mm/2; gMC->Gsvolu("RSSC","TUBE",(*fIdtmed)[kSteel]  ,par,3); //steel screw in center of perpex
846         par[0]=0 ;par[1]= 2*mm/2  ;par[2]=  10*mm/2; gMC->Gsvolu("RSSS","TUBE",(*fIdtmed)[kSteel]  ,par,3); //Steel screw to support Sr90 
847           par[0]=0 ;par[1]= 1*mm/2  ;par[2]= 1*mm/2; gMC->Gsvolu("RSSR","TUBE",(*fIdtmed)[kSr90]   ,par,3); //Sr90 source
848         par[0]=0 ;par[1]= 4*mm/2  ;par[2]= 10*mm/2;  gMC->Gsvolu("RSWP","TUBE",(*fIdtmed)[kAir]    ,par,3); //Air hole in perpex plug      
849       par[0]=0 ;par[1]= 5*mm/2  ;par[2]= 1.8*mm/2;   gMC->Gsvolu("RSWA","TUBE",(*fIdtmed)[kAir]    ,par,3); //Air hole in Al glass bottom
850     par[0]=0 ;par[1]= 30*mm/2  ;par[2]= 50*mkm/2;    gMC->Gsvolu("RSMF","TUBE",(*fIdtmed)[kMylar]  ,par,3); //Mylar foil                
851     
852   gMC->Gspos("RSRC",1,"RICH",       30*cm,        0,     1*cm, 0,"ONLY"); //source to RICH
853     gMC->Gspos("RSMF",1,"RSRC",         0,        0,21.8*mm/2+50*mkm/2, 0,"ONLY");//mylar foil to top src volume
854     gMC->Gspos("RSAG",1,"RSRC",         0,        0,        0, 0,"ONLY");//Al glass to fake Src volume 
855       gMC->Gspos("RSWA",1,"RSAG",    6*mm,        0,   -10*mm, 0,"ONLY");//air whole in al glass bottom
856       gMC->Gspos("RSPP",1,"RSAG",       0,        0,   0.9*mm, 0,"ONLY");//perpex plug to Al glass
857         gMC->Gspos("RSWP",1,"RSPP",  6*mm,        0,    -5*mm, 0,"ONLY");//air whole in perpex plug
858         gMC->Gspos("RSSC",1,"RSPP",     0,        0,   2.5*mm, 0,"ONLY");//steel screw in center of perpex plug
859         gMC->Gspos("RSSS",1,"RSPP",  6*mm,        0,     5*mm, 0,"ONLY");//steel screw to support Sr90  in perpex plug
860           gMC->Gspos("RSSR",1,"RSSS",   0,        0,  -4.5*mm, 0,"ONLY");//Sr90  in support steel screw
861 }//GeomSr90()
862 //__________________________________________________________________________________________________
863 void AliRICH::GeomAerogel()const
864 {
865 //Creates detailed geometry for aerogel study.
866   AliDebug(1,"Start.");
867   Double_t cm=1;
868   Float_t par[3]; //tmp array for volume dimentions
869        
870   par[0]=10.1*cm/2;par[1]=10.1*cm/2;par[2]=10.1*cm/2;
871   gMC->Gsvolu("RREF","BOX ",(*fIdtmed)[kReflector],par,3);//reflector box
872   gMC->Gspos("RREF",1,"RICH",0,0,0,0, "ONLY");            //put it to RICH volume
873   
874   par[0]=10*cm/2;par[1]=10*cm/2;par[2]=10*cm/2;
875   gMC->Gsvolu("RGEL","BOX ",(*fIdtmed)[kGel],par,3);//10x10x10 cm^3 cubic of aerogel
876   gMC->Gspos("RGEL",1,"RREF",0,0,0,0,"ONLY");//put gel cell to reflector
877   AliDebug(1,"Stop.");  
878 }//GeomAerogel()
879 //__________________________________________________________________________________________________
880 void AliRICH::CreateGeometry()
881 {
882 //Creates detailed geometry simulation (currently GEANT volumes tree)         
883   AliDebug(1,"Start main.");
884   Double_t mm=0.1;//default is cm
885   Float_t par[3];
886   Int_t matrixIdReturn=0; //matrix id returned by AliMatrix
887        
888 //place chambers into mother volume ALIC
889   par[0]=(6*mm+1681*mm+6*mm)/2;par[1]=(6*mm+1466*mm+6*mm)/2;par[2]=(80*mm+40*mm)*2/2;
890   gMC->Gsvolu("RICH","BOX ",(*fIdtmed)[kCH4],par,3);//2033P1  z p84 TDR
891   for(int i=1;i<=P()->Nchambers();i++){ //test configuration with single chamber is taken into account automaticaly in AliRICHParam
892     AliMatrix(matrixIdReturn,
893                    C(i)->ThetaXd(),C(i)->PhiXd(),  
894                    C(i)->ThetaYd(),C(i)->PhiYd(),  
895                    C(i)->ThetaZd(),C(i)->PhiZd());
896     gMC->Gspos("RICH",i,"ALIC",C(i)->Center().X(),
897                                C(i)->Center().Y(),
898                                C(i)->Center().Z(),matrixIdReturn, "ONLY");
899   }
900   
901   if(P()->IsAerogel()) 
902     GeomAerogel();
903   else{
904     GeomPadPanelFrame();
905     GeomAmpGap();
906     if(P()->IsRadioSrc())    GeomRadioSrc(); else GeomRadiators(); 
907     GeomSandBox();           
908   }
909   AliDebug(1,"Stop main.");  
910 }//CreateGeometry()
911 //__________________________________________________________________________________________________
912 void AliRICH::CheckPR()const
913 {
914 //Pattern recognition with stack particles
915   TFile *pFile = new TFile("$(HOME)/RPR.root","RECREATE","RICH Pattern Recognition");
916   TNtupleD *hn = new TNtupleD("hn","ntuple","Pmod:Charge:TrackTheta:TrackPhi:TrackX:TrackY:MinX:MinY:ChargeMIP:ThetaCerenkov:NPhotons:MipIndex:Chamber:Particle");
917 //  printf("\n\n");
918 //  printf("Pattern Recognition done for event %5i",0);
919   AliMagF * magf = gAlice->Field();
920   AliTracker::SetFieldMap(magf);
921   for(Int_t iEvtN=0;iEvtN<GetLoader()->GetRunLoader()->GetNumberOfEvents();iEvtN++) {
922     GetLoader()->GetRunLoader()->GetEvent(iEvtN);
923     AliRICHTracker *tr = new AliRICHTracker();
924     tr->RecWithStack(hn);
925     Info("CheckPR","Pattern Recognition done for event %i \b",iEvtN);
926 //    printf("\b\b\b\b\b%5i",iEvtN+1);
927   }
928   printf("\n\n");
929   pFile->Write();pFile->Close();
930 }
931 //__________________________________________________________________________________________________
932 void AliRICH::DisplayEvent(Int_t iEvtNmin,Int_t iEvtNmax)const
933 {
934   TH2F *pDigitsH2[8];
935
936   Bool_t isDigits  =!GetLoader()->LoadDigits();
937   if(!isDigits){Error("ShoEvent","No digits. Nothing to display.");return;}
938   
939   TCanvas *canvas = new TCanvas("RICHDisplay","RICH Display",0,0,1226,900);     
940   gStyle->SetPalette(1);
941
942   
943   for(Int_t iChamber=1;iChamber<=7;iChamber++) {
944     pDigitsH2[iChamber] = new TH2F(Form("pDigitsH2_%i",iChamber),Form("Chamber %i",iChamber),165,0,P()->PcSizeX(),144,0,P()->PcSizeY());
945     pDigitsH2[iChamber]->SetMarkerColor(kGreen); 
946     pDigitsH2[iChamber]->SetMarkerStyle(29); 
947     pDigitsH2[iChamber]->SetMarkerSize(0.4);
948     pDigitsH2[iChamber]->SetStats(kFALSE);
949     pDigitsH2[iChamber]->SetMaximum(300);
950   }
951   
952   if(iEvtNmax>gAlice->GetEventsPerRun()||iEvtNmax==0) iEvtNmax=gAlice->GetEventsPerRun()-1;
953
954   TLatex t;  t.SetTextSize(0.1);
955   for(Int_t iEventN=iEvtNmin;iEventN<=iEvtNmax;iEventN++) {//events loop
956     canvas->Divide(3,3);    
957     canvas->cd(1);
958     t.DrawText(0.2,0.4,Form("Event Number %i",iEventN));        
959
960     GetLoader()->GetRunLoader()->GetEvent(iEventN); //get event
961     GetLoader()->TreeD()->GetEntry(0);              //get list of digits 
962     for(Int_t iChamber=1;iChamber<=7;iChamber++) {//chambers loop
963       pDigitsH2[iChamber]->Reset();    
964       for(Int_t j=0;j<Digits(iChamber)->GetEntries();j++) {//digits loop
965         AliRICHDigit *pDig = (AliRICHDigit*)Digits(iChamber)->At(j);
966         TVector2 x2=AliRICHParam::Pad2Loc(pDig->Pad());
967         pDigitsH2[iChamber]->Fill(x2.X(),x2.Y(),pDig->Q());
968       }//digits loop
969       if(iChamber==1) canvas->cd(7);
970       if(iChamber==2) canvas->cd(8);
971       if(iChamber==3) canvas->cd(4);
972       if(iChamber==4) canvas->cd(5);
973       if(iChamber==5) canvas->cd(6);
974       if(iChamber==6) canvas->cd(2);
975       if(iChamber==7) canvas->cd(3);
976       pDigitsH2[iChamber]->Draw("col");
977       ReadESD(iEventN,iChamber);
978       AliRICHParam::DrawSectors();
979     }//chambers loop
980     canvas->Update();
981     canvas->Modified();
982
983     if(iEventN<iEvtNmax) {gPad->WaitPrimitive();canvas->Clear();}
984   }//events loop
985 }//ShowEvent()
986 //__________________________________________________________________________________________________
987 void AliRICH::Display()const
988 {
989 //Provides fast event display
990 //For RICH only, full display is .x Display.C    
991   Bool_t isHits    =!GetLoader()->LoadHits();
992   Bool_t isDigits  =!GetLoader()->LoadDigits();
993   Bool_t isClusters=!GetLoader()->LoadRecPoints();
994   
995   if(!isHits && !isDigits && !isClusters){Error("Exec","No hits digits and clusters. Nothing to display.");return;}
996   
997   TCanvas *pCanvas = new TCanvas("Display","RICH Display",0,0,600,600);
998   
999   TH2F *pHitsH2=0,*pDigitsH2=0,*pClustersH2=0;
1000   
1001   if(isHits)     pHitsH2     = new TH2F("pHitsH2"  ,  "Event Display;x,cm;y,cm",165,0,AliRICHParam::PcSizeX(),
1002                                                                                 144,0,AliRICHParam::PcSizeY());
1003   if(pHitsH2)    pHitsH2->SetStats(kFALSE);
1004   
1005   if(isDigits)   pDigitsH2   = new TH2F("pDigitsH2"  ,"Event Display",165,0,AliRICHParam::PcSizeX(),
1006                                                                       144,0,AliRICHParam::PcSizeY());
1007   if(isClusters) pClustersH2 = new TH2F("pClustersH2","Event Display",165,0,AliRICHParam::PcSizeX(),
1008                                                                       144,0,AliRICHParam::PcSizeY());
1009   
1010   for(Int_t iEventN=0;iEventN<gAlice->GetEventsPerRun();iEventN++){//events Loop
1011     GetLoader()->GetRunLoader()->GetEvent(iEventN);  
1012 //display all the staff on chamber by chamber basis           
1013     for(Int_t iChamber=1;iChamber<=7;iChamber++){//chambers loop       
1014       if(isHits)     pHitsH2    ->Reset();     
1015       if(isDigits)   pDigitsH2  ->Reset();     
1016       if(isClusters) pClustersH2->Reset();
1017 //deals with hits
1018       for(Int_t i=0;i<GetLoader()->TreeH()->GetEntries();i++){//TreeH loop
1019         GetLoader()->TreeH()->GetEntry(i);
1020         for(Int_t j=0;j<Hits()->GetEntries();j++){//hits loop
1021           AliRICHHit *pHit = (AliRICHHit*)Hits()->At(j);
1022           if(pHit->C()==iChamber){
1023             TVector3 hitGlobX3= pHit->OutX3();
1024             TVector2 hitLocX2 = C(iChamber)->Mrs2Pc(hitGlobX3);
1025             pHitsH2->Fill(hitLocX2.X(),hitLocX2.Y(),200);
1026           }//if
1027         }//hits loop         
1028       }//TreeH loop
1029       pHitsH2->SetTitle(Form("event %i chamber %2i",iEventN,iChamber));
1030       pHitsH2->SetMarkerColor(kRed); pHitsH2->SetMarkerStyle(29); pHitsH2->SetMarkerSize(0.4);
1031       ReadESD(iEventN,iChamber);
1032       pHitsH2->Draw();
1033       ReadESD(iEventN,iChamber);
1034       AliRICHParam::DrawSectors();
1035       TLatex l; l.SetNDC(); l.SetTextSize(0.02);
1036       if(!isHits)     {l.SetTextColor(kRed)  ;l.DrawLatex(0.1,0.01,"No Hits"    );}
1037       if(!isDigits)   {l.SetTextColor(kGreen);l.DrawLatex(0.4,0.01,"No DIGITS"  );}
1038       if(!isClusters) {l.SetTextColor(kBlue) ;l.DrawLatex(0.8,0.01,"No CLUSTERS");}
1039       pCanvas->Update();        pCanvas->Modified();       gPad->WaitPrimitive();
1040 //deals with digits      
1041       if(isDigits){
1042         GetLoader()->TreeD()->GetEntry(0);
1043         for(Int_t j=0;j<Digits(iChamber)->GetEntries();j++){//digits loop
1044           AliRICHDigit *pDig = (AliRICHDigit*)Digits(iChamber)->At(j);
1045           TVector2 x2=AliRICHParam::Pad2Loc(pDig->Pad());
1046           pDigitsH2->Fill(x2.X(),x2.Y(),100);
1047         }//digits loop
1048         pDigitsH2->SetMarkerColor(kGreen); pDigitsH2->SetMarkerStyle(29); pDigitsH2->SetMarkerSize(0.4);
1049         pDigitsH2->Draw("same");
1050         pCanvas->Update();        pCanvas->Modified();       gPad->WaitPrimitive();
1051       }//if(isDigits)      
1052 //deals with clusters      
1053       if(isClusters){
1054         GetLoader()->TreeR()->GetEntry(0);
1055         for(Int_t j=0;j<Clusters(iChamber)->GetEntries();j++){//clusters loop
1056           AliRICHCluster *pClus = (AliRICHCluster*)Clusters(iChamber)->At(j);
1057           pClustersH2->Fill(pClus->X(),pClus->Y(),50);
1058         }//clusters loop
1059         pClustersH2->SetMarkerColor(kBlue); pClustersH2->SetMarkerStyle(29);  pClustersH2->SetMarkerSize(0.4);
1060         pClustersH2->Draw("same");
1061         pCanvas->Update();        pCanvas->Modified();       gPad->WaitPrimitive();
1062       }//if(isClusters)
1063     }//chambers loop
1064   }//events Loop
1065   
1066   delete pCanvas;
1067   GetLoader()->UnloadHits();
1068   if(isDigits)   GetLoader()->UnloadDigits();
1069   if(isClusters) GetLoader()->UnloadRecPoints();
1070 }//Display()
1071 //__________________________________________________________________________________________________
1072 Int_t AliRICH::Nparticles(Int_t iPartID,Int_t iEvtN,AliRunLoader *pRL)
1073 {
1074 //counts total number of particles of given type (including secondary) for a given event
1075   pRL->GetEvent(iEvtN);    
1076   if(pRL->LoadHeader()) return 0;
1077   if(pRL->LoadKinematics()) return 0;
1078   AliStack *pStack=pRL->Stack();
1079   
1080   Int_t iCounter=0;
1081   for(Int_t i=0;i<pStack->GetNtrack();i++){
1082     if(pStack->Particle(i)->GetPdgCode()==iPartID) iCounter++;
1083   }
1084   
1085   pRL->UnloadHeader();
1086   pRL->UnloadKinematics();
1087   return iCounter;
1088 }
1089 //__________________________________________________________________________________________________
1090 void AliRICH::ReadESD(Int_t iEventN, Int_t iChamber)const
1091 {
1092 //
1093   AliInfo("Start.");
1094   TFile *pFile=TFile::Open("AliESDs.root","read");
1095   if(!pFile || !pFile->IsOpen()) {AliInfo("ESD file not open.");return;}      //open AliESDs.root                                                                    
1096   TTree *pTree = (TTree*) pFile->Get("esdTree");
1097   if(!pTree){AliInfo("ESD not found.");return;}                               //get ESD tree
1098   
1099   AliInfo("ESD found. Try to draw ring");
1100                                                                  
1101   AliESD *pESD=new AliESD;  pTree->SetBranchAddress("ESD", &pESD);
1102   
1103   pTree->GetEvent(iEventN);
1104   
1105   Double_t b = pESD->GetMagneticField()/10.;
1106   
1107   Int_t iNtracks=pESD->GetNumberOfTracks();    
1108   
1109   for(Int_t iTrackN=0;iTrackN<iNtracks;iTrackN++){//ESD tracks loop
1110     AliESDtrack *pTrack = pESD->GetTrack(iTrackN);// get next reconstructed track
1111     Int_t charge = (Int_t)(-TMath::Sign(1.,pTrack->GetSign()*b));
1112     AliRICHHelix helix(pTrack->X3(),pTrack->P3(),charge,b);
1113     Int_t iChamberOnRICH=helix.RichIntersect(P());        
1114     if(iChamberOnRICH==iChamber) {
1115 //
1116       TMarker *trackImpact = new TMarker(helix.PosPc().X(),helix.PosPc().Y(),kStar);
1117       trackImpact->SetMarkerColor(kRed);
1118       trackImpact->Draw();
1119 //
1120       Int_t iChamberRecon = pTrack->GetRICHcluster()/100000;
1121       if(iChamberRecon==iChamber) {
1122         Double_t thetaCer = pTrack->GetRICHsignal();
1123         if(thetaCer<0) continue;
1124         TVector3 entrance(helix.PosRad().X(),helix.PosRad().Y(),0);
1125         Double_t thetaTrack,phiTrack;
1126         pTrack->GetRICHthetaPhi(thetaTrack,phiTrack);
1127         TVector3 vectorTrack;
1128         vectorTrack.SetMagThetaPhi(pTrack->GetP(),thetaTrack,phiTrack);
1129         AliInfo(Form("Draw ring started for track %i on chamber %i",iTrackN,iChamber));
1130         AliInfo(Form("ThetaCer %f TrackTheta %f TrackPhi %f Momentum %f",thetaCer,thetaTrack,phiTrack,pTrack->GetP()));
1131         Double_t dx,dy;
1132         pTrack->GetRICHdxdy(dx,dy);
1133         AliInfo(Form("dx %f dy %f ",dx,dy));
1134         DrawRing(entrance,vectorTrack,thetaCer);
1135       }
1136     }
1137   }
1138   delete pESD;  pFile->Close();//close AliESDs.root
1139   AliInfo("Stop.");
1140 }
1141 //__________________________________________________________________________________________________
1142 void AliRICH::DrawRing(TVector3 entrance,TVector3 vectorTrack,Double_t thetaCer)const
1143 {
1144   Double_t xGraph[100],yGraph[100];
1145   Int_t nPointsToDraw = 0;
1146   for(Int_t i=0;i<100;i++) {
1147     Double_t phiCer = 2*TMath::Pi()*i/100;
1148     TVector3 pos = AliRICHParam::ForwardTracing(entrance,vectorTrack,thetaCer,phiCer);
1149     if(pos.X()==-999) continue;
1150     xGraph[nPointsToDraw] = pos.X();yGraph[nPointsToDraw] = pos.Y();nPointsToDraw++;
1151   }
1152 //  AliInfo(Form("Npoints per ring %i",nPointsToDraw));
1153   TGraph *gra = new TGraph(nPointsToDraw,xGraph,yGraph);
1154   gra->Draw("C");  
1155 }