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