]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RICH/AliRICH.cxx
f82dab15774a37c66ebd090fbcd4f74479f4c4fa
[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 <TArrayF.h>
17 #include <TBRIK.h>
18 #include <TFile.h>
19 #include <TGeometry.h>
20 #include <TNode.h> 
21 #include <TObjArray.h>
22 #include <TObject.h>
23 #include <TParticle.h>
24 #include <TPDGCode.h>
25 #include <TRandom.h> 
26 #include <TTUBE.h>
27 #include <TTree.h>
28 #include <TVector.h>
29 #include <AliMagF.h>
30 #include <AliPoints.h>
31 #include "AliRICH.h"
32 #include "AliRICHParam.h"
33 #include "AliRICHClusterFinder.h"
34 #include "AliRICHRawCluster.h"
35 #include "AliRICHRecHit1D.h"
36 #include "AliRICHRecHit3D.h"
37 #include "AliRICHSegmentationV0.h"
38 #include "AliRICHTransientDigit.h"
39 #include <AliRun.h>
40 #include <AliRunDigitizer.h>
41 #include "AliRICHSegmentationV1.h"
42 #include "AliRICHResponseV0.h"
43  
44 ClassImp(AliRICHhit)
45 //__________________________________________________________________________________________________
46 void AliRICHhit::Print(Option_t*)const
47 {
48   Info("","chamber=%2i, PID=%9i, TID=%6i, eloss=%9.3f eV",fChamber,fPid,fTrack,fEloss*1e9);
49 }//void AliRICHdigit::Print(Option_t *option)const
50 //__________________________________________________________________________________________________
51 ClassImp(AliRICHdigit)
52 //__________________________________________________________________________________________________
53 void AliRICHdigit::Print(Option_t*)const
54 {
55   Info("","ID=%6i, chamber=%2i, PadX=%3i, PadY=%3i, Qdc=%4i, TID1=%5i, TID2=%5i, TID3=%5i",
56          Id(),fChamber,fPadX,fPadY,fQdc,fTracks[0],fTracks[1],fTracks[2]);
57 }//void AliRICHdigit::Print(Option_t *option)const
58 //__________________________________________________________________________________________________
59
60 ClassImp(AliRICH)    
61 //__________________________________________________________________________________________________
62 // RICH manager class   
63 //BEGIN_HTML
64 /*
65   <img src="gif/alirich.gif">
66 */
67 //END_HTML
68 //__________________________________________________________________________________________________
69 AliRICH::AliRICH()
70         :AliDetector() 
71 {//Default ctor should not contain any new operators
72   fpParam     =0;
73   fChambers   =0;
74   
75   
76         //AliDetector ctor deals with Hits and Digits
77   
78   fSdigits    =0; fNsdigits   =0;
79   fDigitsNew  =0; for(int i=0;i<kNCH;i++) fNdigitsNew[i]  =0;
80   fClusters   =0; for(int i=0;i<kNCH;i++) fNclusters[i]=0;
81   
82   fCerenkovs  =0; fNcerenkovs =0;
83   fSpecials   =0; fNspecials  =0;  
84   fDchambers  =0; for(int i=0;i<kNCH;i++) fNdch[i]=0;
85   fRecHits1D  =0; for(int i=0;i<kNCH;i++) fNrechits1D[i]=0;
86   fRecHits3D  =0; for(int i=0;i<kNCH;i++) fNrechits3D[i]=0;
87   fRawClusters=0; for(int i=0;i<kNCH;i++) fNrawch[i]=0;  
88 }//AliRICH::AliRICH()
89 //__________________________________________________________________________________________________
90 AliRICH::AliRICH(const char *name, const char *title)
91         :AliDetector(name,title)
92 {//Named ctor
93   if(GetDebug())Info("named ctor","Start.");
94   fpParam     =   new AliRICHParam;
95   fChambers = 0;  CreateChambers();
96   
97         //AliDetector ctor deals with Hits and Digits (reset them to 0, does not create them)
98   fHits=       0;     CreateHits();          gAlice->AddHitList(fHits);
99   fSdigits=    0;
100   fDigitsNew=  0;
101   fClusters=   0;
102   
103   fCerenkovs=  0;     CreateCerenkovsOld();  gAlice->AddHitList(fCerenkovs);
104   fSpecials=   0;     CreateSpecialsOld();   
105   fDchambers=  0;   //CreateDigitsOld();
106   fRawClusters=0;   //CreateRawClustersOld();
107   fRecHits1D=  0;   //CreateRecos1Old();
108   fRecHits3D=  0;   //CreateRecos3Old();
109   
110   fCkovNumber=fFreonProd=0;  
111   if(GetDebug())Info("named ctor","Stop.");
112 }//AliRICH::AliRICH(const char *name, const char *title)
113 //__________________________________________________________________________________________________
114 AliRICH::~AliRICH()
115 {//dtor
116   if(GetDebug()) Info("dtor","Start.");
117
118   if(fpParam)    delete fpParam;
119   if(fChambers)  delete fChambers;
120   
121   if(fHits)      delete fHits;
122   if(fSdigits)   delete fSdigits;
123   if(fDigits)    delete fDigits;
124   if(fDigitsNew) {fDigitsNew->Delete();   delete fDigitsNew;}
125   if(fClusters)  {fClusters->Delete();    delete fClusters;}
126   
127   if(fCerenkovs) delete fCerenkovs;
128   if(fSpecials)  delete fSpecials;
129   if(fDchambers)   {fDchambers->Delete();     delete fDchambers;}
130   if(fRawClusters) {fRawClusters->Delete();   delete fRawClusters;}          
131   if(fRecHits1D) {fRecHits1D->Delete();       delete fRecHits1D;}
132   if(fRecHits3D) {fRecHits3D->Delete();       delete fRecHits3D;}                     
133   if(GetDebug()) Info("dtor","Stop.");    
134 }//AliRICH::~AliRICH()
135 //__________________________________________________________________________________________________
136 void AliRICH::Hits2SDigits()
137 {//Create a list of sdigits corresponding to list of hits. Every hit generates one or more sdigits.
138   if(GetDebug()) Info("Hit2SDigits","Start.");
139   
140   if(GetDebug()) Info("Hit2SDigits","Stop.");
141 }//void AliRICH::Hits2SDigits()
142 //__________________________________________________________________________________________________
143 void AliRICH::SDigits2Digits()
144 {//Generate digits from sdigits.
145   if(GetDebug()) Info("SDigits2Digits","Start.");
146     
147   if(GetDebug()) Info("SDigits2Digits","Stop.");
148 }//void AliRICH::SDigits2Digits()
149 //__________________________________________________________________________________________________
150 void AliRICH::Digits2Reco()
151 {//Generate clusters from digits then generate recos from clusters or digits
152   if(GetDebug()) Info("Digits2reco","Start.");
153
154 }//void AliRICH::Digits2Reco()  
155 //__________________________________________________________________________________________________
156 void AliRICH::AddRawCluster(Int_t id, const AliRICHRawCluster& c)
157 {// Add a RICH digit to the list
158    
159     TClonesArray &lrawcl = *((TClonesArray*)fRawClusters->At(id));
160     new(lrawcl[fNrawch[id]++]) AliRICHRawCluster(c);
161 }
162 //_____________________________________________________________________________
163 void AliRICH::AddRecHit1D(Int_t id, Float_t *rechit, Float_t *photons, Int_t *padsx, Int_t* padsy)
164 {// Add a RICH reconstructed hit to the list
165
166     TClonesArray &lrec1D = *((TClonesArray*)fRecHits1D->At(id));
167     new(lrec1D[fNrechits1D[id]++]) AliRICHRecHit1D(id,rechit,photons,padsx,padsy);
168 }
169 //_____________________________________________________________________________
170 void AliRICH::AddRecHit3D(Int_t id, Float_t *rechit, Float_t omega, Float_t theta, Float_t phi)
171 {// Add a RICH reconstructed hit to the list
172
173     TClonesArray &lrec3D = *((TClonesArray*)fRecHits3D->At(id));
174     new(lrec3D[fNrechits3D[id]++]) AliRICHRecHit3D(id,rechit,omega,theta,phi);
175 }
176 //______________________________________________________________________________
177 void AliRICH::BuildGeometry() 
178 {//Builds a TNode geometry for event display
179   if(GetDebug())Info("BuildGeometry","Start.");
180   
181   TNode *node, *subnode, *top;
182   top=gAlice->GetGeometry()->GetNode("alice");
183   
184   new TBRIK("S_RICH","S_RICH","void",71.09999,11.5,73.15);
185
186   Float_t wid=Param()->SectorSizeX();
187   Float_t len=Param()->SectorSizeY();
188   new TBRIK("PHOTO","PHOTO","void",wid/2,0.1,len/2);
189   
190   for(int i=1;i<=kNCH;i++){
191     top->cd();
192     node = new TNode(Form("RICH%i",i),Form("RICH%i",i),"S_RICH",C(i)->X(),C(i)->Y(),C(i)->Z(),C(i)->RotMatrixName());
193     node->SetLineColor(kRed);
194     node->cd();
195     subnode = new TNode("PHOTO1","PHOTO1","PHOTO",wid+Param()->DeadZone(),5,len/2+Param()->DeadZone()/2,"");
196     subnode->SetLineColor(kGreen);
197     fNodes->Add(subnode);
198     subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,5,len/2+Param()->DeadZone()/2,"");
199     subnode->SetLineColor(kGreen);
200     fNodes->Add(subnode);
201     subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-wid-Param()->DeadZone(),5,len/2+Param()->DeadZone()/2,"");
202     subnode->SetLineColor(kGreen);
203     fNodes->Add(subnode);
204     subnode = new TNode("PHOTO1","PHOTO1","PHOTO",wid+Param()->DeadZone(),5,-len/2-Param()->DeadZone()/2,"");
205     subnode->SetLineColor(kGreen);
206     fNodes->Add(subnode);
207     subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,5,-len/2 -Param()->DeadZone()/2,"");
208     subnode->SetLineColor(kGreen);
209     fNodes->Add(subnode);
210     subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-wid-Param()->DeadZone(),5,-len/2 - Param()->DeadZone()/2,"");
211     subnode->SetLineColor(kGreen);
212     fNodes->Add(subnode);
213     fNodes->Add(node);
214   }  
215   if(GetDebug())Info("BuildGeometry","Stop.");    
216 }//void AliRICH::BuildGeometry()
217
218 static Int_t kCSI=6;
219 static Int_t kGAP=9;
220 //______________________________________________________________________________
221 void AliRICH::CreateMaterials()
222 {
223     //
224     // *** DEFINITION OF AVAILABLE RICH MATERIALS *** 
225     // ORIGIN    : NICK VAN EIJNDHOVEN 
226     // Modified by:  N. Colonna (INFN - BARI, Nicola.Colonna@ba.infn.it) 
227     //               R.A. Fini  (INFN - BARI, Rosanna.Fini@ba.infn.it) 
228     //               R.A. Loconsole (Bari University, loco@riscom.ba.infn.it) 
229     //
230     Int_t i;
231     
232     //Photons energy intervals
233     Float_t ppckov[26];
234     for (i=0;i<26;i++) 
235     {
236         ppckov[i] = (Float_t(i)*0.1+5.5)*1e-9;
237     }
238     
239     
240     //Refraction index for quarz
241     Float_t rIndexQuarz[26];
242     Float_t  e1= 10.666;
243     Float_t  e2= 18.125;
244     Float_t  f1= 46.411;
245     Float_t  f2= 228.71;
246     for (i=0;i<26;i++)
247     {
248         Float_t ene=ppckov[i]*1e9;
249         Float_t a=f1/(e1*e1 - ene*ene);
250         Float_t b=f2/(e2*e2 - ene*ene);
251         rIndexQuarz[i] = TMath::Sqrt(1. + a + b );
252     } 
253     
254     //Refraction index for opaque quarz, methane and grid
255     Float_t rIndexOpaqueQuarz[26];
256     Float_t rIndexMethane[26];
257     Float_t rIndexGrid[26];
258     for (i=0;i<26;i++)
259     {
260         rIndexOpaqueQuarz[i]=1;
261         rIndexMethane[i]=1.000444;
262         rIndexGrid[i]=1;
263     } 
264     
265     //Absorption index for freon
266     Float_t abscoFreon[26] = {179.0987, 179.0987, 179.0987, 179.0987, 179.0987,  179.0987, 179.0987, 179.0987, 
267                                179.0987, 142.9206, 56.64957, 25.58622, 13.95293, 12.03905, 10.42953, 8.804196, 
268                                7.069031, 4.461292, 2.028366, 1.293013, .577267,   .40746,  .334964, 0., 0., 0.};
269     
270
271     Float_t abscoQuarz [26] = {105.8, 65.52, 48.58, 42.85, 35.79, 31.262, 28.598, 27.527, 25.007, 22.815, 21.004,
272                                 19.266, 17.525, 15.878, 14.177, 11.719, 9.282, 6.62, 4.0925, 2.601, 1.149, .667, .3627,
273                                 .192, .1497, .10857};
274     
275     //Absorption index for methane
276     Float_t abscoMethane[26];
277     for (i=0;i<26;i++) 
278     {
279         abscoMethane[i]=AbsoCH4(ppckov[i]*1e9); 
280     }
281     
282     //Absorption index for opaque quarz, csi and grid, efficiency for all and grid
283     Float_t abscoOpaqueQuarz[26];
284     Float_t abscoCsI[26];
285     Float_t abscoGrid[26];
286     Float_t efficAll[26];
287     Float_t efficGrid[26];
288     for (i=0;i<26;i++)
289     { 
290         abscoOpaqueQuarz[i]=1e-5; 
291         abscoCsI[i]=1e-4; 
292         abscoGrid[i]=1e-4; 
293         efficAll[i]=1; 
294         efficGrid[i]=1;
295     } 
296     
297     //Efficiency for csi 
298     
299     Float_t efficCsI[26] = {0.000199999995, 0.000600000028, 0.000699999975, 0.00499999989, 0.00749999983, 0.010125,
300                              0.0242999997, 0.0405000001, 0.0688500032, 0.105299994, 0.121500008, 0.141749993, 0.157949999,
301                              0.162, 0.166050002, 0.167669997, 0.174299985, 0.176789999, 0.179279998, 0.182599992, 0.18592,
302                              0.187579989, 0.189239994, 0.190899998, 0.207499996, 0.215799987};
303         
304     
305
306     //FRESNEL LOSS CORRECTION FOR PERPENDICULAR INCIDENCE AND
307     //UNPOLARIZED PHOTONS
308
309     for (i=0;i<26;i++)
310     {
311         efficCsI[i] = efficCsI[i]/(1.-Fresnel(ppckov[i]*1e9,1.,0)); 
312     }
313         
314     /*******************************************End of rich_media.f***************************************/
315     
316   Float_t rIndexFreon[26];
317     
318     
319     // --- Photon energy (GeV) 
320     // --- Refraction indexes 
321     for (i = 0; i < 26; ++i) {
322       rIndexFreon[i] = ppckov[i] * .0172 * 1e9 + 1.177;
323       //rIndexFreon[i] = 1;
324     }
325             
326       
327   Float_t a=0,z=0,den=0,radl=0,absl=0;
328   Float_t tmaxfd=-10.0, deemax=-0.2, stemax=-0.1,epsil=0.001, stmin=-0.001; 
329   Int_t   isxfld = gAlice->Field()->Integ();
330   Float_t sxmgmx = gAlice->Field()->Max();
331     
332   AliMaterial( 1, "Air     $",a=14.61,z=7.3, den=0.001205,radl=30420.0,absl=67500);//(Air)
333   AliMedium(1, "DEFAULT MEDIUM AIR$", 1, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
334   
335   AliMaterial( 6, "HON",      a=12.01,z=6.0, den=0.1,     radl=18.8,   absl=0);    //(C)-equivalent radl
336   AliMedium(2, "HONEYCOMB$", 6, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
337   
338   AliMaterial(16, "CSI",      a=12.01,z=6.0, den=0.1,     radl=18.8,   absl=0);    //CsI-radl equivalent
339   AliMedium(kCSI, "CSI$", 16, 1, isxfld, sxmgmx,tmaxfd, stemax, deemax, epsil, stmin);
340   
341   AliMaterial(11, "GRI",      a=63.54,z=29.0,den=8.96,    radl=1.43,   absl=0);    //anode grid (Cu) 
342   AliMedium(7, "GRIGLIA$", 11, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
343   
344   AliMaterial(50, "ALUM",     a=26.98,z=13.0,den=2.7,     radl=8.9,    absl=0);    //aluminium sheet (Al)
345   AliMedium(10, "ALUMINUM$", 50, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
346   
347   AliMaterial(31, "COPPER$",  a=63.54,z=29.0,den=8.96,    radl=1.4,    absl=0);    //(Cu)
348   AliMedium(12, "PCB_COPPER", 31, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
349   
350   Float_t  aQuartz[2]={28.09,16.0};  Float_t  zQuartz[2]={14.00, 8.0};  Float_t  wmatQuartz[2]={1,2};
351   AliMixture (20, "QUA",aQuartz,zQuartz,den=2.64,-2, wmatQuartz);//Quarz (SiO2) - trasnparent 
352   AliMedium(3, "QUARZO$", 20, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
353   
354   AliMixture (21, "QUAO",aQuartz, zQuartz, den=2.64, -2, wmatQuartz);//Quarz (SiO2) - opaque
355   AliMedium(8, "QUARZOO$", 21, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
356   
357   Float_t  aFreon[2]={12,19};  Float_t  zFreon[2]={6,9};  Float_t wmatFreon[2]={6,14};
358   AliMixture (30, "FRE",aFreon,zFreon,den=1.7,-2,wmatFreon);//Freon (C6F14) 
359   AliMedium(4, "FREON$", 30, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
360   
361   Float_t aMethane[2]={12.01,1}; Float_t zMethane[2]={6,1}; Float_t wmatMethane[2]={1,4};
362   AliMixture (40, "MET", aMethane, zMethane, den=7.17e-4,-2, wmatMethane);//methane (CH4)     
363   AliMedium(5, "METANO$", 40, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
364   
365   AliMixture (41, "METG", aMethane, zMethane, den=7.17e-4, -2, wmatMethane);
366   AliMedium(kGAP, "GAP$", 41, 1, isxfld, sxmgmx,tmaxfd, 0.1, -deemax, epsil, -stmin);
367   
368   Float_t aGlass[5]={12.01, 28.09, 16.,   10.8,  23.};
369   Float_t zGlass[5]={ 6.,   14.,    8.,    5.,   11.};
370   Float_t wGlass[5]={ 0.5,  0.105, 0.355, 0.03,  0.01};
371   AliMixture (32, "GLASS",aGlass, zGlass, den=1.74, 5, wGlass);//Glass 50%C+10.5%Si+35.5%O+3% + 1%
372   AliMedium(11, "GLASS", 32, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
373             
374   Int_t *idtmed = fIdtmed->GetArray()-999;
375   gMC->SetCerenkov(idtmed[1000], 26, ppckov, abscoMethane,     efficAll,  rIndexMethane);
376   gMC->SetCerenkov(idtmed[1001], 26, ppckov, abscoMethane,     efficAll,  rIndexMethane);
377   gMC->SetCerenkov(idtmed[1002], 26, ppckov, abscoQuarz,       efficAll,  rIndexQuarz);
378   gMC->SetCerenkov(idtmed[1003], 26, ppckov, abscoFreon,       efficAll,  rIndexFreon);
379   gMC->SetCerenkov(idtmed[1004], 26, ppckov, abscoMethane,     efficAll,  rIndexMethane);
380   gMC->SetCerenkov(idtmed[1005], 26, ppckov, abscoCsI,         efficCsI,  rIndexMethane);
381   gMC->SetCerenkov(idtmed[1006], 26, ppckov, abscoGrid,        efficGrid, rIndexGrid);
382   gMC->SetCerenkov(idtmed[1007], 26, ppckov, abscoOpaqueQuarz, efficAll,  rIndexOpaqueQuarz);
383   gMC->SetCerenkov(idtmed[1008], 26, ppckov, abscoMethane,     efficAll,  rIndexMethane);
384   gMC->SetCerenkov(idtmed[1009], 26, ppckov, abscoGrid,        efficGrid, rIndexGrid);
385   gMC->SetCerenkov(idtmed[1010], 26, ppckov, abscoOpaqueQuarz, efficAll,  rIndexOpaqueQuarz);
386 }//void AliRICH::CreateMaterials()
387 //__________________________________________________________________________________________________
388 Float_t AliRICH::Fresnel(Float_t ene,Float_t pdoti, Bool_t pola)
389 {
390
391     //ENE(EV), PDOTI=COS(INC.ANG.), PDOTR=COS(POL.PLANE ROT.ANG.)
392     
393     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,
394                       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,
395                       7.8,7.9,8.0,8.1,8.2,8.3,8.4,8.5};
396     Float_t csin[36] = {2.14,2.21,2.33,2.48,2.76,2.97,2.99,2.59,2.81,3.05,
397                         2.86,2.53,2.55,2.66,2.79,2.96,3.18,3.05,2.84,2.81,2.38,2.11,
398                         2.01,2.13,2.39,2.73,3.08,3.15,2.95,2.73,2.56,2.41,2.12,1.95,
399                         1.72,1.53};
400     Float_t csik[36] = {0.,0.,0.,0.,0.,0.196,0.408,0.208,0.118,0.49,0.784,0.543,
401                         0.424,0.404,0.371,0.514,0.922,1.102,1.139,1.376,1.461,1.253,0.878,
402                         0.69,0.612,0.649,0.824,1.347,1.571,1.678,1.763,1.857,1.824,1.824,
403                         1.714,1.498};
404     Float_t xe=ene;
405     Int_t  j=Int_t(xe*10)-49;
406     Float_t cn=csin[j]+((csin[j+1]-csin[j])/0.1)*(xe-en[j]);
407     Float_t ck=csik[j]+((csik[j+1]-csik[j])/0.1)*(xe-en[j]);
408
409     //FORMULAE FROM HANDBOOK OF OPTICS, 33.23 OR
410     //W.R. HUNTER, J.O.S.A. 54 (1964),15 , J.O.S.A. 55(1965),1197
411
412     Float_t sinin=TMath::Sqrt(1-pdoti*pdoti);
413     Float_t tanin=sinin/pdoti;
414
415     Float_t c1=cn*cn-ck*ck-sinin*sinin;
416     Float_t c2=4*cn*cn*ck*ck;
417     Float_t aO=TMath::Sqrt(0.5*(TMath::Sqrt(c1*c1+c2)+c1));
418     Float_t b2=0.5*(TMath::Sqrt(c1*c1+c2)-c1);
419     
420     Float_t rs=((aO-pdoti)*(aO-pdoti)+b2)/((aO+pdoti)*(aO+pdoti)+b2);
421     Float_t rp=rs*((aO-sinin*tanin)*(aO-sinin*tanin)+b2)/((aO+sinin*tanin)*(aO+sinin*tanin)+b2);
422     
423
424     //CORRECTION FACTOR FOR SURFACE ROUGHNESS
425     //B.J. STAGG  APPLIED OPTICS, 30(1991),4113
426
427     Float_t sigraf=18.;
428     Float_t lamb=1240/ene;
429     Float_t fresn;
430  
431     Float_t  rO=TMath::Exp(-(4*TMath::Pi()*pdoti*sigraf/lamb)*(4*TMath::Pi()*pdoti*sigraf/lamb));
432
433     if(pola)
434     {
435         Float_t pdotr=0.8;                                 //DEGREE OF POLARIZATION : 1->P , -1->S
436         fresn=0.5*(rp*(1+pdotr)+rs*(1-pdotr));
437     }
438     else
439         fresn=0.5*(rp+rs);
440       
441     fresn = fresn*rO;
442     return(fresn);
443 }//Float_t AliRICH::Fresnel(Float_t ene,Float_t pdoti, Bool_t pola)
444 //__________________________________________________________________________________________________
445 Float_t AliRICH::AbsoCH4(Float_t x)
446 {
447
448     //KLOSCH,SCH4(9),WL(9),EM(9),ALENGTH(31)
449     Float_t sch4[9] = {.12,.16,.23,.38,.86,2.8,7.9,28.,80.};              //MB X 10^22
450     //Float_t wl[9] = {153.,152.,151.,150.,149.,148.,147.,146.,145};
451     Float_t em[9] = {8.1,8.158,8.212,8.267,8.322,8.378,8.435,8.493,8.55};
452     const Float_t kLosch=2.686763E19;                                      // LOSCHMIDT NUMBER IN CM-3
453     const Float_t kIgas1=100, kIgas2=0, kOxy=10., kWater=5., kPressure=750.,kTemperature=283.;                                      
454     Float_t pn=kPressure/760.;
455     Float_t tn=kTemperature/273.16;
456     
457         
458 // ------- METHANE CROSS SECTION -----------------
459 // ASTROPH. J. 214, L47 (1978)
460         
461     Float_t sm=0;
462     if (x<7.75) 
463         sm=.06e-22;
464     
465     if(x>=7.75 && x<=8.1)
466     {
467         Float_t c0=-1.655279e-1;
468         Float_t c1=6.307392e-2;
469         Float_t c2=-8.011441e-3;
470         Float_t c3=3.392126e-4;
471         sm=(c0+c1*x+c2*x*x+c3*x*x*x)*1.e-18;
472     }
473     
474     if (x> 8.1)
475     {
476         Int_t j=0;
477         while (x<=em[j] && x>=em[j+1])
478         {
479             j++;
480             Float_t a=(sch4[j+1]-sch4[j])/(em[j+1]-em[j]);
481             sm=(sch4[j]+a*(x-em[j]))*1e-22;
482         }
483     }
484     
485     Float_t dm=(kIgas1/100.)*(1.-((kOxy+kWater)/1.e6))*kLosch*pn/tn;
486     Float_t abslm=1./sm/dm;
487     
488 //    ------- ISOBUTHANE CROSS SECTION --------------
489 //     i-C4H10 (ai) abs. length from curves in
490 //     Lu-McDonald paper for BARI RICH workshop .
491 //     -----------------------------------------------------------
492     
493     Float_t ai;
494     Float_t absli;
495     if (kIgas2 != 0) 
496     {
497         if (x<7.25)
498             ai=100000000.;
499         
500         if(x>=7.25 && x<7.375)
501             ai=24.3;
502         
503         if(x>=7.375)
504             ai=.0000000001;
505         
506         Float_t si = 1./(ai*kLosch*273.16/293.);                    // ISOB. CRO.SEC.IN CM2
507         Float_t di=(kIgas2/100.)*(1.-((kOxy+kWater)/1.e6))*kLosch*pn/tn;
508         absli =1./si/di;
509     }
510     else
511         absli=1.e18;
512 //    ---------------------------------------------------------
513 //
514 //       transmission of O2
515 //
516 //       y= path in cm, x=energy in eV
517 //       so= cross section for UV absorption in cm2
518 //       do= O2 molecular density in cm-3
519 //    ---------------------------------------------------------
520     
521     Float_t abslo;
522     Float_t so=0;
523     if(x>=6.0)
524     {
525         if(x>=6.0 && x<6.5)
526         {
527             so=3.392709e-13 * TMath::Exp(2.864104 *x);
528             so=so*1e-18;
529         }
530         
531         if(x>=6.5 && x<7.0) 
532         {
533             so=2.910039e-34 * TMath::Exp(10.3337*x);
534             so=so*1e-18;
535         }
536             
537
538         if (x>=7.0) 
539         {
540             Float_t a0=-73770.76;
541             Float_t a1=46190.69;
542             Float_t a2=-11475.44;
543             Float_t a3=1412.611;
544             Float_t a4=-86.07027;
545             Float_t a5=2.074234;
546             so= a0+(a1*x)+(a2*x*x)+(a3*x*x*x)+(a4*x*x*x*x)+(a5*x*x*x*x*x);
547             so=so*1e-18;
548         }
549         
550         Float_t dox=(kOxy/1e6)*kLosch*pn/tn;
551         abslo=1./so/dox;
552     }
553     else
554         abslo=1.e18;
555 //     ---------------------------------------------------------
556 //
557 //       transmission of H2O
558 //
559 //       y= path in cm, x=energy in eV
560 //       sw= cross section for UV absorption in cm2
561 //       dw= H2O molecular density in cm-3
562 //     ---------------------------------------------------------
563     
564     Float_t abslw;
565     
566     Float_t b0=29231.65;
567     Float_t b1=-15807.74;
568     Float_t b2=3192.926;
569     Float_t b3=-285.4809;
570     Float_t b4=9.533944;
571     
572     if(x>6.75)
573     {    
574         Float_t sw= b0+(b1*x)+(b2*x*x)+(b3*x*x*x)+(b4*x*x*x*x);
575         sw=sw*1e-18;
576         Float_t dw=(kWater/1e6)*kLosch*pn/tn;
577         abslw=1./sw/dw;
578     }
579     else
580         abslw=1.e18;
581             
582 //    ---------------------------------------------------------
583     
584     Float_t alength=1./(1./abslm+1./absli+1./abslo+1./abslw);
585     return (alength);
586 }
587 //__________________________________________________________________________________________________
588 void AliRICH::MakeBranch(Option_t* option)
589 {//Create Tree branches for the RICH.
590   if(GetDebug())Info("MakeBranch","Start with option= %s.",option);
591     
592   const Int_t kBufferSize = 4000;
593       
594   const char *cH = strstr(option,"H");
595   const char *cD = strstr(option,"D");
596   const char *cR = strstr(option,"R");
597   const char *cS = strstr(option,"S");
598
599   if(cH&&TreeH()){//H
600     CreateHits();      //branch will be created in AliDetector::MakeBranch
601     CreateCerenkovsOld(); MakeBranchInTree(TreeH(),"RICHCerenkov", &fCerenkovs, kBufferSize,0);
602     CreateSpecialsOld();  MakeBranchInTree(TreeH(),"RICHSpecials", &fSpecials,kBufferSize,0); 
603   }//H     
604   AliDetector::MakeBranch(option);//this is after cH because we need to guarantee that fHits array is created
605       
606   if(cS&&fLoader->TreeS()){//S  
607     CreateSdigits();   MakeBranchInTree(fLoader->TreeS(),"RICH",&fSdigits,kBufferSize,0) ;
608   }//S
609    
610   if(cD&&fLoader->TreeD()){//D
611     CreateDigitsOld();  
612     for(int i=0;i<kNCH;i++) 
613       MakeBranchInTree(fLoader->TreeD(),Form("%sDigits%d",GetName(),i+1),&((*fDchambers)[i]),kBufferSize,0);
614   }//D
615   
616   if(cR&&fLoader->TreeR()){//R
617     CreateRawClustersOld(); 
618     for(int i=0; i<kNCH ;i++)
619       MakeBranchInTree(fLoader->TreeR(),Form("%sRawClusters%d",GetName(),i+1), &((*fRawClusters)[i]), kBufferSize, 0);
620
621     CreateRecos1Old();   
622     for(int i=0; i<kNCH ;i++) 
623       MakeBranchInTree(fLoader->TreeR(),Form("%sRecHits1D%d",GetName(),i+1),&((*fRecHits1D)[i]),kBufferSize,0);
624     
625     CreateRecos3Old();   
626     for(int i=0; i<kNCH ;i++)
627       MakeBranchInTree(fLoader->TreeR(),Form("%sRecHits3D%d",GetName(),i+1), &((*fRecHits3D)[i]), kBufferSize, 0);
628    }//R
629   if(GetDebug())Info("MakeBranch","Stop.");   
630 }//void AliRICH::MakeBranch(Option_t* option)
631 //__________________________________________________________________________________________________
632 void AliRICH::SetTreeAddress()
633 {//Set branch address for the Hits and Digits Tree.
634   if(GetDebug())Info("SetTreeAddress","Start.");
635       
636   TBranch *branch;
637     
638   if(fLoader->TreeH()){//H
639     if(GetDebug())Info("SetTreeAddress","tree H is requested.");
640     CreateHits();//branch map will be in AliDetector::SetTreeAddress    
641     branch=fLoader->TreeH()->GetBranch("RICHCerenkov");   if(branch){CreateCerenkovsOld(); branch->SetAddress(&fCerenkovs);}       
642     branch=fLoader->TreeH()->GetBranch("RICHSpecials");   if(branch){CreateSpecialsOld();  branch->SetAddress(&fSpecials);}
643   }//H
644   AliDetector::SetTreeAddress();//this is after TreeH because we need to guarantee that fHits array is created
645
646   if(fLoader->TreeS()){//S
647     if(GetDebug())Info("SetTreeAddress","tree S is requested.");
648     branch=fLoader->TreeS()->GetBranch(GetName());        if(branch){CreateSdigits();   branch->SetAddress(&fSdigits);}
649   }//S
650     
651   if(fLoader->TreeD()){//D    
652     if(GetDebug())Info("SetTreeAddress","tree D is requested.");
653     for(int i=0;i<kNCH;i++){      
654       branch=fLoader->TreeD()->GetBranch(Form("%s%d",GetName(),i+1)); 
655       if(branch){CreateDigits(); branch->SetAddress(&((*fDigitsNew)[i]));}
656       
657       branch=fLoader->TreeD()->GetBranch(Form("%sDigits%d",GetName(),i+1)); 
658       if(branch){CreateDigitsOld(); branch->SetAddress(&((*fDchambers)[i]));}
659     }//for
660   }//D
661     
662   if(fLoader->TreeR()){//R
663     if(GetDebug())Info("SetTreeAddress","tree R is requested.");
664
665     for(int i=0;i<kNCH;i++){         
666       branch=fLoader->TreeR()->GetBranch(Form("%sClusters%d" ,GetName(),i+1));
667       if(branch){CreateClusters(); branch->SetAddress(&((*fRawClusters)[i]));}
668     }
669     
670     for(int i=0;i<kNCH;i++) {
671       branch=fLoader->TreeR()->GetBranch(Form("%sRawClusters%d" ,GetName(),i+1));
672       if(branch){CreateRawClustersOld(); branch->SetAddress(&((*fRawClusters)[i]));}
673       
674       branch=fLoader->TreeR()->GetBranch(Form("%sRecHits1D%d",GetName(),i+1));
675       if(branch){CreateRecos1Old(); branch->SetAddress(&((*fRecHits1D)[i]));}
676       
677       branch=fLoader->TreeR()->GetBranch(Form("%sRecHits3D%d",GetName(),i+1));
678       if(branch){CreateRecos3Old();branch->SetAddress(&((*fRecHits3D)[i]));}
679     }
680   }//R
681   if(GetDebug())Info("SetTreeAddress","Stop.");
682 }//void AliRICH::SetTreeAddress()
683 //__________________________________________________________________________________________________
684 void AliRICH::Print(Option_t *option)const
685 {
686   TObject::Print(option);
687   Param()->Dump();
688   fChambers->Print(option);  
689 }//void AliRICH::Print(Option_t *option)const
690 //__________________________________________________________________________________________________
691 void AliRICH::CreateGeometry()
692 {//Creates detailed geometry simulation (currently GEANT volumes tree)         
693   if(GetDebug())Info("CreateGeometry","Start.");
694 //???????? to be removed to AliRICHParam?
695   Param()->RadiatorToPads(Param()->FreonThickness()/2+Param()->QuartzThickness()+Param()->GapThickness());
696     
697 //Opaque quartz thickness
698   Float_t oqua_thickness = .5;
699 //CsI dimensions
700   Float_t pcX=Param()->PcSizeX();
701   Float_t pcY=Param()->PcSizeY();
702   
703   Int_t *idtmed = fIdtmed->GetArray()-999;
704     
705   Int_t i;
706   Float_t zs;
707   Int_t idrotm[1099];
708   Float_t par[3];
709     
710 //External aluminium box 
711   par[0]=68.8*kcm;par[1]=13*kcm;par[2]=70.86*kcm;  gMC->Gsvolu("RICH", "BOX ", idtmed[1009], par, 3);
712 //Air 
713   par[0]=66.3;   par[1] = 13; par[2] = 68.35;      gMC->Gsvolu("SRIC", "BOX ", idtmed[1000], par, 3); 
714 //Air 2 (cutting the lower part of the box)
715   par[0]=1.25;    par[1] = 3;    par[2] = 70.86;   gMC->Gsvolu("AIR2", "BOX ", idtmed[1000], par, 3);
716 //Air 3 (cutting the lower part of the box)
717   par[0]=66.3;    par[1] = 3;  par[2] = 1.2505;    gMC->Gsvolu("AIR3", "BOX ", idtmed[1000], par, 3);
718 //Honeycomb 
719   par[0]=66.3;par[1]=0.188;  par[2] = 68.35;       gMC->Gsvolu("HONE", "BOX ", idtmed[1001], par, 3);
720 //Aluminium sheet 
721   par[0]=66.3;par[1]=0.025;par[2]=68.35;           gMC->Gsvolu("ALUM", "BOX ", idtmed[1009], par, 3);
722   //par[0] = 66.5; par[1] = .025; par[2] = 63.1;
723 //Quartz 
724   par[0]=Param()->QuartzWidth()/2;par[1]=Param()->QuartzThickness()/2;par[2]=Param()->QuartzLength()/2;
725   gMC->Gsvolu("QUAR", "BOX ", idtmed[1002], par, 3);
726 //Spacers (cylinders) 
727   par[0]=0.;par[1]=.5;par[2]=Param()->FreonThickness()/2;  gMC->Gsvolu("SPAC", "TUBE", idtmed[1002], par, 3);    
728 //Feet (freon slabs supports)
729   par[0] = .7;  par[1] = .3;  par[2] = 1.9;        gMC->Gsvolu("FOOT", "BOX", idtmed[1009], par, 3);
730 //Opaque quartz 
731   par[0]=Param()->QuartzWidth()/2;par[1]= .2;par[2]=Param()->QuartzLength()/2;
732   gMC->Gsvolu("OQUA", "BOX ", idtmed[1007], par, 3);
733 //Frame of opaque quartz
734   par[0]=Param()->OuterFreonWidth()/2;par[1]=Param()->FreonThickness()/2;par[2]=Param()->OuterFreonLength()/2; 
735   gMC->Gsvolu("OQF1", "BOX ", idtmed[1007], par, 3);
736   par[0]=Param()->InnerFreonWidth()/2;par[1]=Param()->FreonThickness()/2;par[2]=Param()->InnerFreonLength()/2; 
737   gMC->Gsvolu("OQF2", "BOX ", idtmed[1007], par, 3);
738 //Freon 
739   par[0]=Param()->OuterFreonWidth()/2 - oqua_thickness;
740   par[1]=Param()->FreonThickness()/2;
741   par[2]=Param()->OuterFreonLength()/2 - 2*oqua_thickness; 
742   gMC->Gsvolu("FRE1", "BOX ", idtmed[1003], par, 3);
743
744   par[0]=Param()->InnerFreonWidth()/2 - oqua_thickness;
745   par[1]=Param()->FreonThickness()/2;
746   par[2]=Param()->InnerFreonLength()/2 - 2*oqua_thickness; 
747   gMC->Gsvolu("FRE2", "BOX ", idtmed[1003], par, 3);    
748 //Methane 
749   par[0]=pcX/2;par[1]=Param()->GapThickness()/2;par[2]=pcY/2;         gMC->Gsvolu("META","BOX ",idtmed[1004], par, 3);
750 //Methane gap 
751   par[0]=pcX/2;par[1]=Param()->ProximityGapThickness()/2;par[2]=pcY/2;gMC->Gsvolu("GAP ","BOX ",(*fIdtmed)[kGAP],par,3);
752 //CsI PC
753   par[0]=pcX/2;par[1]=.25;par[2]=pcY/2;  gMC->Gsvolu("CSI ", "BOX ", (*fIdtmed)[kCSI], par, 3);
754 //Anode grid 
755   par[0] = 0.;par[1] = .001;par[2] = 20.;  gMC->Gsvolu("GRID", "TUBE", idtmed[1006], par, 3);
756
757 //Wire supports
758 //Bar of metal
759   par[0]=pcX/2;par[1]=1.05;par[2]=1.05;  gMC->Gsvolu("WSMe", "BOX ", idtmed[1009], par, 3);
760 //Ceramic pick up (base)
761   par[0]=pcX/2;par[1]= .25;par[2]=1.05;  gMC->Gsvolu("WSG1", "BOX ", idtmed[1010], par, 3);
762 //Ceramic pick up (head)
763   par[0] = pcX/2;par[1] = .1;par[2] = .1;  gMC->Gsvolu("WSG2", "BOX ", idtmed[1010], par, 3);
764
765 //Aluminium supports for methane and CsI
766 //Short bar
767   par[0]=pcX/2;par[1]=Param()->GapThickness()/2 + .25; par[2] = (68.35 - pcY/2)/2;
768   gMC->Gsvolu("SMSH", "BOX", idtmed[1009], par, 3);
769 //Long bar
770   par[0]=(66.3 - pcX/2)/2;par[1]=Param()->GapThickness()/2+.25;par[2]=pcY/2+68.35-pcY/2;
771   gMC->Gsvolu("SMLG", "BOX", idtmed[1009], par, 3);
772     
773 //Aluminium supports for freon
774 //Short bar
775   par[0] = Param()->QuartzWidth()/2; par[1] = .3; par[2] = (68.35 - Param()->QuartzLength()/2)/2;
776   gMC->Gsvolu("SFSH", "BOX", idtmed[1009], par, 3);    
777 //Long bar
778   par[0] = (66.3 - Param()->QuartzWidth()/2)/2; par[1] = .3;
779   par[2] = Param()->QuartzLength()/2 + 68.35 - Param()->QuartzLength()/2;
780   gMC->Gsvolu("SFLG", "BOX", idtmed[1009], par, 3);    
781 //PCB backplane
782   par[0] = pcX/2;par[1] = .25; par[2] = pcY/4 -.5025;  gMC->Gsvolu("PCB ", "BOX", idtmed[1011], par, 3);
783
784 //Backplane supports
785 //Aluminium slab
786   par[0] = 33.15;par[1] = 2;par[2] = 21.65;  gMC->Gsvolu("BACK", "BOX", idtmed[1009], par, 3);    
787 //Big hole
788   par[0] = 9.05; par[1] = 2; par[2] = 4.4625;  gMC->Gsvolu("BKHL", "BOX", idtmed[1000], par, 3);
789 //Small hole
790   par[0] = 5.7;par[1] = 2;par[2] = 4.4625;  gMC->Gsvolu("BKHS", "BOX", idtmed[1000], par, 3);
791 //Place holes inside backplane support
792   gMC->Gspos("BKHS", 1, "BACK", .8 + 5.7,0., .6 + 4.4625, 0, "ONLY");
793   gMC->Gspos("BKHS", 2, "BACK", -.8 - 5.7,0., .6 + 4.4625, 0, "ONLY");
794   gMC->Gspos("BKHS", 3, "BACK", .8 + 5.7,0., -.6 - 4.4625, 0, "ONLY");
795   gMC->Gspos("BKHS", 4, "BACK", -.8 - 5.7,0., -.6 - 4.4625, 0, "ONLY");
796   gMC->Gspos("BKHS", 5, "BACK", .8 + 5.7,0., .6 + 8.925 + 1.2 + 4.4625, 0, "ONLY");
797   gMC->Gspos("BKHS", 6, "BACK", -.8 - 5.7,0., .6 + 8.925 + 1.2 + 4.4625, 0, "ONLY");
798   gMC->Gspos("BKHS", 7, "BACK", .8 + 5.7,0., -.6 - 8.925 - 1.2 - 4.4625, 0, "ONLY");
799   gMC->Gspos("BKHS", 8, "BACK", -.8 - 5.7,0., -.6 - 8.925 - 1.2 - 4.4625, 0, "ONLY");
800   gMC->Gspos("BKHL", 1, "BACK", .8 + 11.4 + 1.6 + 9.05, 0., .6 + 4.4625, 0, "ONLY");
801   gMC->Gspos("BKHL", 2, "BACK", -.8 - 11.4 - 1.6 - 9.05, 0., .6 + 4.4625, 0, "ONLY");
802   gMC->Gspos("BKHL", 3, "BACK", .8 + 11.4 + 1.6 + 9.05, 0., -.6 - 4.4625, 0, "ONLY");
803   gMC->Gspos("BKHL", 4, "BACK", -.8 - 11.4 - 1.6 - 9.05, 0., -.6 - 4.4625, 0, "ONLY");
804   gMC->Gspos("BKHL", 5, "BACK", .8 + 11.4+ 1.6 + 9.05, 0., .6 + 8.925 + 1.2 + 4.4625, 0, "ONLY");
805   gMC->Gspos("BKHL", 6, "BACK", -.8 - 11.4 - 1.6 - 9.05, 0., .6 + 8.925 + 1.2 + 4.4625, 0, "ONLY");
806   gMC->Gspos("BKHL", 7, "BACK", .8 + 11.4 + 1.6 + 9.05, 0., -.6 - 8.925 - 1.2 - 4.4625, 0, "ONLY");
807   gMC->Gspos("BKHL", 8, "BACK", -.8 - 11.4 - 1.6 - 9.05, 0., -.6 - 8.925 - 1.2 - 4.4625, 0, "ONLY");
808 //Place material inside RICH 
809   gMC->Gspos("SRIC", 1, "RICH", 0.,0., 0., 0, "ONLY");
810   gMC->Gspos("AIR2", 1, "RICH", 66.3 + 1.2505, 1.276-Param()->GapThickness()/2-Param()->QuartzThickness()-Param()->FreonThickness()- .4 - .6 - .05 - .376 -.5 - 3.35, 0., 0, "ONLY");
811   gMC->Gspos("AIR2", 2, "RICH", -66.3 - 1.2505,1.276-Param()->GapThickness()/2-Param()->QuartzThickness()-Param()->FreonThickness()- .4 - .6 - .05 - .376 -.5 - 3.35, 0., 0, "ONLY");
812   gMC->Gspos("AIR3", 1, "RICH", 0., 1.276-Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()- .4 - .6 - .05 - .376 -.5 - 3.35, -68.35 - 1.25, 0, "ONLY");
813   gMC->Gspos("AIR3", 2, "RICH", 0., 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()- .4 - .6 - .05 - .376 -.5 - 3.35,  68.35 + 1.25, 0, "ONLY");
814   gMC->Gspos("ALUM", 1, "SRIC", 0., 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()- .4 - .6 - .05 - .376 -.025, 0., 0, "ONLY");
815   gMC->Gspos("HONE", 1, "SRIC", 0., 1.276- Param()->GapThickness()/2  - Param()->QuartzThickness() - Param()->FreonThickness()- .4 - .6 - .05 - .188, 0., 0, "ONLY");
816   gMC->Gspos("ALUM", 2, "SRIC", 0., 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()- .4 - .6 - .025, 0., 0, "ONLY");
817   gMC->Gspos("FOOT", 1, "SRIC", 64.95, 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()- .4 - .3, 36.9, 0, "ONLY");
818   gMC->Gspos("FOOT", 2, "SRIC", 21.65, 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()- .4 - .3 , 36.9, 0, "ONLY");
819   gMC->Gspos("FOOT", 3, "SRIC", -21.65, 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()- .4 - .3, 36.9, 0, "ONLY");
820   gMC->Gspos("FOOT", 4, "SRIC", -64.95, 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()- .4 - .3, 36.9, 0, "ONLY");
821   gMC->Gspos("FOOT", 5, "SRIC", 64.95, 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()- .4 - .3, -36.9, 0, "ONLY");
822   gMC->Gspos("FOOT", 6, "SRIC", 21.65, 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()- .4 - .3, -36.9, 0, "ONLY");
823   gMC->Gspos("FOOT", 7, "SRIC", -21.65, 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()- .4 - .3, -36.9, 0, "ONLY");
824   gMC->Gspos("FOOT", 8, "SRIC", -64.95, 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()- .4 - .3, -36.9, 0, "ONLY");
825   gMC->Gspos("OQUA", 1, "SRIC", 0., 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()- .2, 0., 0, "ONLY");
826 // Methane supports
827   gMC->Gspos("SMLG", 1, "SRIC", pcX/2 + (66.3 - pcX/2)/2, 1.276 + .25, 0., 0, "ONLY");
828   gMC->Gspos("SMLG", 2, "SRIC", - pcX/2 - (66.3 - pcX/2)/2, 1.276 + .25, 0., 0, "ONLY");
829   gMC->Gspos("SMSH", 1, "SRIC", 0., 1.276 + .25, pcY/2 + (68.35 - pcY/2)/2, 0, "ONLY");
830   gMC->Gspos("SMSH", 2, "SRIC", 0., 1.276 + .25, - pcY/2 - (68.35 - pcY/2)/2, 0, "ONLY");
831 //Freon supports
832   Float_t supp_y = 1.276 - Param()->GapThickness()/2- Param()->QuartzThickness() -Param()->FreonThickness() - .2 + .3; //y position of freon supports
833   gMC->Gspos("SFLG", 1, "SRIC", Param()->QuartzWidth()/2 + (66.3 - Param()->QuartzWidth()/2)/2, supp_y, 0., 0, "ONLY");
834   gMC->Gspos("SFLG", 2, "SRIC", - Param()->QuartzWidth()/2 - (66.3 - Param()->QuartzWidth()/2)/2, supp_y, 0., 0, "ONLY");
835   gMC->Gspos("SFSH", 1, "SRIC", 0., supp_y, Param()->QuartzLength()/2 + (68.35 - Param()->QuartzLength()/2)/2, 0, "ONLY");
836   gMC->Gspos("SFSH", 2, "SRIC", 0., supp_y, - Param()->QuartzLength()/2 - (68.35 - Param()->QuartzLength()/2)/2, 0, "ONLY");
837   AliMatrix(idrotm[1019], 0., 0., 90., 0., 90., 90.);
838 //Place spacers
839   Int_t nspacers = 30;
840   for (i = 0; i < nspacers/3; i++) {
841     zs = -11.6/2 + (TMath::Abs(nspacers/6) - i) * 12.2;
842     gMC->Gspos("SPAC", i, "FRE1", 10.5, 0., zs, idrotm[1019], "ONLY");  //Original settings 
843   }
844   for (i = nspacers/3; i < (nspacers*2)/3; i++) {
845     zs = -11.6/2 + (nspacers/3 + TMath::Abs(nspacers/6) - i) * 12.2;
846     gMC->Gspos("SPAC", i, "FRE1", 0, 0., zs, idrotm[1019], "ONLY");  //Original settings 
847   }
848   for (i = (nspacers*2)/3; i < nspacers; ++i) {
849     zs = -11.6/2 + ((nspacers*2)/3 + TMath::Abs(nspacers/6) - i) * 12.2;
850     gMC->Gspos("SPAC", i, "FRE1", -10.5, 0., zs, idrotm[1019], "ONLY"); //Original settings  
851   }
852   for (i = 0; i < nspacers/3; i++) {
853     zs = -11.6/2 + (TMath::Abs(nspacers/6) - i) * 12.2;
854     gMC->Gspos("SPAC", i, "FRE2", 10.5, 0., zs, idrotm[1019], "ONLY");  //Original settings 
855   }
856   for (i = nspacers/3; i < (nspacers*2)/3; i++) {
857     zs = -11.6/2 + (nspacers/3 + TMath::Abs(nspacers/6) - i) * 12.2;
858     gMC->Gspos("SPAC", i, "FRE2", 0, 0., zs, idrotm[1019], "ONLY");  //Original settings 
859   }
860   for (i = (nspacers*2)/3; i < nspacers; ++i) {
861     zs = -11.6/2 + ((nspacers*2)/3 + TMath::Abs(nspacers/6) - i) * 12.2;
862     gMC->Gspos("SPAC", i, "FRE2", -10.5, 0., zs, idrotm[1019], "ONLY"); //Original settings  
863   }
864   gMC->Gspos("FRE1", 1, "OQF1", 0., 0., 0., 0, "ONLY");
865   gMC->Gspos("FRE2", 1, "OQF2", 0., 0., 0., 0, "ONLY");
866   gMC->Gspos("OQF1", 1, "SRIC", Param()->OuterFreonWidth()/2 + Param()->InnerFreonWidth()/2 + 2, 1.276 - Param()->GapThickness()/2- Param()->QuartzThickness() -Param()->FreonThickness()/2, 0., 0, "ONLY"); //Original settings (31.3)
867   gMC->Gspos("OQF2", 2, "SRIC", 0., 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()/2, 0., 0, "ONLY");          //Original settings 
868   gMC->Gspos("OQF1", 3, "SRIC", - (Param()->OuterFreonWidth()/2 + Param()->InnerFreonWidth()/2) - 2, 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness() - Param()->FreonThickness()/2, 0., 0, "ONLY");       //Original settings (-31.3)
869   gMC->Gspos("QUAR", 1, "SRIC", 0., 1.276 - Param()->GapThickness()/2 - Param()->QuartzThickness()/2, 0., 0, "ONLY");
870   gMC->Gspos("GAP ", 1, "META", 0., Param()->GapThickness()/2 - Param()->ProximityGapThickness()/2 - 0.0001, 0., 0, "ONLY");
871   gMC->Gspos("META", 1, "SRIC", 0., 1.276, 0., 0, "ONLY");
872   gMC->Gspos("CSI ", 1, "SRIC", 0., 1.276 + Param()->GapThickness()/2 + .25, 0., 0, "ONLY");
873 //Wire support placing
874   gMC->Gspos("WSG2", 1, "GAP ", 0., Param()->ProximityGapThickness()/2 - .1, 0., 0, "ONLY");
875   gMC->Gspos("WSG1", 1, "CSI ", 0., 0., 0., 0, "ONLY");
876   gMC->Gspos("WSMe", 1, "SRIC ", 0., 1.276 + Param()->GapThickness()/2 + .5 + 1.05, 0., 0, "ONLY");
877 //Backplane placing
878   gMC->Gspos("BACK", 1, "SRIC ", -33.15, 1.276 + Param()->GapThickness()/2 + .5 + 2.1 + 2, 43.3, 0, "ONLY");
879   gMC->Gspos("BACK", 2, "SRIC ", 33.15, 1.276 + Param()->GapThickness()/2 + .5 + 2.1 + 2 , 43.3, 0, "ONLY");
880   gMC->Gspos("BACK", 3, "SRIC ", -33.15, 1.276 + Param()->GapThickness()/2 + .5 + 2.1 + 2, 0., 0, "ONLY");
881   gMC->Gspos("BACK", 4, "SRIC ", 33.15, 1.276 + Param()->GapThickness()/2 + .5 + 2.1 + 2, 0., 0, "ONLY");
882   gMC->Gspos("BACK", 5, "SRIC ", 33.15, 1.276 + Param()->GapThickness()/2 + .5 + 2.1 + 2, -43.3, 0, "ONLY");
883   gMC->Gspos("BACK", 6, "SRIC ", -33.15, 1.276 + Param()->GapThickness()/2 + .5 + 2.1 + 2, -43.3, 0, "ONLY");
884 //PCB placing
885   gMC->Gspos("PCB ", 1, "SRIC ", 0.,  1.276 + Param()->GapThickness()/2 + .5 + 1.05, pcX/4 + .5025 + 2.5, 0, "ONLY");
886   gMC->Gspos("PCB ", 2, "SRIC ", 0.,  1.276 + Param()->GapThickness()/2 + .5 + 1.05, -pcX/4 - .5025 - 2.5, 0, "ONLY");
887
888 //place chambers into mother volume ALIC
889   for(int i=1;i<=kNCH;i++){
890     AliMatrix(idrotm[1000+i],C(i)->ThetaXd(),C(i)->PhiXd(),
891                              C(i)->ThetaYd(),C(i)->PhiYd(),
892                              C(i)->ThetaZd(),C(i)->PhiZd());
893     gMC->Gspos("RICH",i,"ALIC",C(i)->X(),C(i)->Y(),C(i)->Z(),idrotm[1000+i], "ONLY");
894   }
895
896   if(GetDebug())Info("CreateGeometry","Stop.");  
897 }//void AliRICH::CreateGeometry()
898 //__________________________________________________________________________________________________
899 void AliRICH::CreateChambers()
900 {//create all RICH Chambers, do nothing if already created.
901   if(fChambers) return;//
902   if(GetDebug())Info("CreateChambers","Creating RICH chambers.");
903   fChambers=new TObjArray(kNCH);
904   fChambers->SetOwner();
905   for(int i=0;i<kNCH;i++)  fChambers->AddAt(new AliRICHChamber(i+1,Param()),i);  
906 }//void AliRICH::CreateChambers()
907 //__________________________________________________________________________________________________
908 void AliRICH::GenerateFeedbacks(Int_t iChamber,Float_t eloss)
909 {// Generate FeedBack photons
910   Int_t j;
911   Float_t cthf, phif, enfp = 0, sthf;
912   Float_t e1[3], e2[3], e3[3];
913   Float_t vmod, uswop;
914   Float_t dir[3], phi;
915   Float_t pol[3], mom[4];
916 //Determine number of feedback photons
917   TLorentzVector x4;
918   gMC->TrackPosition(x4);  
919   Float_t charge=Param()->TotalCharge(gMC->TrackPid(),eloss,C(iChamber)->G2Ly(x4));//Total Charge
920   Int_t iNphotons=gMC->GetRandom()->Poisson(Param()->AlphaFeedback()*charge);    
921   Info("GenerateFeedbacks","N photons=%i",iNphotons);
922 //Generate photons
923   for(Int_t i=0;i<iNphotons;i++){
924     Double_t ranf[2];
925     gMC->GetRandom()->RndmArray(2,ranf);    //Sample direction
926     cthf=ranf[0]*2-1.0;
927     if(cthf<0) continue;
928     sthf = TMath::Sqrt((1 - cthf) * (1 + cthf));
929     phif = ranf[1] * 2 * TMath::Pi();
930     
931     if(Double_t randomNumber=gMC->GetRandom()->Rndm()<=0.57)
932       enfp = 7.5e-9;
933     else if(randomNumber<=0.7)
934       enfp = 6.4e-9;
935     else
936       enfp = 7.9e-9;
937     
938
939     dir[0] = sthf * TMath::Sin(phif);    dir[1] = cthf;    dir[2] = sthf * TMath::Cos(phif);
940     gMC->Gdtom(dir, mom, 2);
941     mom[0]*=enfp;    mom[1]*=enfp;    mom[2]*=enfp;
942     mom[3] = TMath::Sqrt(mom[0]*mom[0]+mom[1]*mom[1]+mom[2]*mom[2]);
943     
944     // Polarisation
945     e1[0]=      0;    e1[1]=-dir[2];    e1[2]= dir[1];
946     e2[0]=-dir[1];    e2[1]= dir[0];    e2[2]=      0;
947     e3[0]= dir[1];    e3[1]=      0;    e3[2]=-dir[0];
948     
949     vmod=0;
950     for(j=0;j<3;j++) vmod+=e1[j]*e1[j];
951     if (!vmod) for(j=0;j<3;j++) {
952       uswop=e1[j];
953       e1[j]=e3[j];
954       e3[j]=uswop;
955     }
956     vmod=0;
957     for(j=0;j<3;j++) vmod+=e2[j]*e2[j];
958     if (!vmod) for(j=0;j<3;j++) {
959       uswop=e2[j];
960       e2[j]=e3[j];
961       e3[j]=uswop;
962     }
963     
964     vmod=0;
965     for(j=0;j<3;j++) vmod+=e1[j]*e1[j];
966     vmod=TMath::Sqrt(1/vmod);
967     for(j=0;j<3;j++) e1[j]*=vmod;
968     
969     vmod=0;
970     for(j=0;j<3;j++) vmod+=e2[j]*e2[j];
971     vmod=TMath::Sqrt(1/vmod);
972     for(j=0;j<3;j++) e2[j]*=vmod;
973     
974     phi = gMC->GetRandom()->Rndm()* 2 * TMath::Pi();
975     for(j=0;j<3;j++) pol[j]=e1[j]*TMath::Sin(phi)+e2[j]*TMath::Cos(phi);
976     gMC->Gdtom(pol, pol, 2);
977     Int_t outputNtracksStored;    
978     gAlice->PushTrack(1,                             //do not transport
979                      gAlice->GetCurrentTrackNumber(),//parent track 
980                      kFeedback,                      //PID
981                      mom[0],mom[1],mom[2],mom[3],    //track momentum  
982                      x4.X(),x4.Y(),x4.Z(),x4.T(),    //track origin 
983                      pol[0],pol[1],pol[2],           //polarization
984                      kPFeedBackPhoton,outputNtracksStored,1.0);
985     
986   }
987 }//Int_t AliRICH::FeedBackPhotons()
988 //__________________________________________________________________________________________________