]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RICH/AliRICH.cxx
all old staff moved to v3
[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
17 #include <strings.h>
18
19 #include <TArrayF.h>
20 #include <TBRIK.h>
21 #include <TFile.h>
22 #include <TGeometry.h>
23 #include <TNode.h> 
24 #include <TObjArray.h>
25 #include <TObject.h>
26 #include <TParticle.h>
27 #include <TPDGCode.h>
28 #include <TRandom.h> 
29 #include <TTUBE.h>
30 #include <TTree.h>
31 #include <TVector.h>
32 #include "AliMagF.h"
33 #include "AliPoints.h"
34 #include "AliRICH.h"
35 #include "AliRICHParam.h"
36 #include "AliRICHClusterFinder.h"
37 #include "AliRICHDigitizer.h"
38 #include "AliRICHHitMapA1.h"
39 #include "AliRICHMerger.h"
40 #include "AliRICHRawCluster.h"
41 #include "AliRICHRecHit1D.h"
42 #include "AliRICHRecHit3D.h"
43 #include "AliRICHSDigit.h"
44 #include "AliRICHSegmentationV0.h"
45 #include "AliRICHTransientDigit.h"
46 #include "AliRun.h"
47 #include "AliRunDigitizer.h"
48 #include "AliRICHSegmentationV1.h"
49 #include "AliRICHResponseV0.h"
50  
51 ClassImp(AliRICHhit)
52 ClassImp(AliRICHdigit)
53 ClassImp(AliRICH)
54     
55 //___________________________________________
56 // RICH manager class   
57 //Begin_Html
58 /*
59   <img src="gif/alirich.gif">
60 */
61 //End_Html
62
63 AliRICH::AliRICH()
64 {//Default ctor should not contain any new operators
65   fIshunt     = 0;
66   fHits       = 0;
67   fSDigits    = 0;
68   fNsdigits   = 0;
69   fNcerenkovs = 0;
70   fDchambers  = 0;
71   fRecHits1D = 0;
72   fRecHits3D = 0;
73   fRawClusters = 0;
74   fChambers = 0;
75   fCerenkovs  = 0;
76   for (Int_t i=0; i<kNCH; i++){
77       fNdch[i]       = 0;
78       fNrawch[i]     = 0;
79       fNrechits1D[i] = 0;
80       fNrechits3D[i] = 0;
81   }
82   fpParam=0;
83 }//AliRICH::AliRICH()
84 //__________________________________________________________________________________________________
85 AliRICH::AliRICH(const char *name, const char *title)
86         :AliDetector(name,title)
87 {//Named ctor
88   if(GetDebug())Info("named ctor","Start.");
89   fpParam     =new AliRICHParam;
90   fNcerenkovs =fNsdigits   =0;//fNhits and fNdigits reset in AliDetector ctor
91   fHits       =new TClonesArray("AliRICHhit",1000  ); gAlice->AddHitList(fHits);//hits
92   fCerenkovs  =new TClonesArray("AliRICHCerenkov",1000);gAlice->AddHitList(fCerenkovs);//cerenkovs ??? to be removed    
93   fSDigits    =new TClonesArray("AliRICHdigit",100000);//sdigits
94   fDigits     =new TClonesArray("AliRICHdigit",100000);//digits
95   
96   fIshunt     =0;
97   fDchambers  =new TObjArray(kNCH);//digits             ??? to be removed
98   fRawClusters=new TObjArray(kNCH);//clusters
99   fRecHits1D  =new TObjArray(kNCH);//recos Bari
100   fRecHits3D  =new TObjArray(kNCH);//recos Lisbon
101   for(int i=0;i<kNCH;i++) {
102     fNdch[i]=fNrawch[i]=0;
103     fDchambers  ->AddAt(new TClonesArray("AliRICHDigit",10000), i); //??? to be removed
104     fRawClusters->AddAt(new TClonesArray("AliRICHRawCluster",10000), i); 
105     fRecHits1D  ->AddAt(new TClonesArray("AliRICHRecHit1D",1000), i);
106     fRecHits3D  ->AddAt(new TClonesArray("AliRICHRecHit3D",1000), i);
107   }
108   SetMarkerColor(kRed);
109   fCkovNumber=fFreonProd=0;
110   CreateChambers();
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     fIshunt  = 0;
119     delete fHits;
120     delete fSDigits;
121     delete fCerenkovs;
122     
123     //PH Delete TObjArrays
124     if (fChambers) {
125       fChambers->Delete();
126       delete fChambers;
127     }
128     if (fDchambers) {
129       fDchambers->Delete();
130       delete fDchambers;
131     }
132     if (fRawClusters) {
133       fRawClusters->Delete();
134       delete fRawClusters;
135     }
136     if (fRecHits1D) {
137       fRecHits1D->Delete();
138       delete fRecHits1D;
139     }
140     if (fRecHits3D) {
141       fRecHits3D->Delete();
142       delete fRecHits3D;
143     }                     
144   if(GetDebug()) Info("dtor","Stop.");    
145 }//AliRICH::~AliRICH()
146 //__________________________________________________________________________________________________
147 void AliRICH::Hits2SDigits()
148 {//Create a list of sdigits corresponding to list of hits. Every hit generates sdigit.
149   if(GetDebug()) Info("Hit2SDigits","Start.");
150   
151   for(Int_t iEventN=0;iEventN<gAlice->GetEventsPerRun();iEventN++){//events loop
152     fLoader->GetRunLoader()->GetEvent(iEventN);
153   
154     if(!fLoader->TreeH()) fLoader->LoadHits();
155     if(!fLoader->TreeS()) fLoader->MakeTree("S");
156     MakeBranch("S");
157     
158     AliRICHSegmentationV1 *pSeg=new AliRICHSegmentationV1;
159     AliRICHResponseV0     *pRes=new AliRICHResponseV0;
160     
161     Float_t dx=Param()->SigmaIntegration()*Param()->ChargeSpreadX();
162     Float_t dy=Param()->SigmaIntegration()*Param()->ChargeSpreadY();
163     Float_t charge;
164     
165     for(int iPrimN=0;iPrimN<TreeH()->GetEntries();iPrimN++){//prims loop
166       fLoader->TreeH()->GetEntry(iPrimN); 
167       for(Int_t iHitN=0;iHitN<Hits()->GetEntries();iHitN++){//hits loop
168         AliRICHhit *pHit=(AliRICHhit*)Hits()->At(iHitN);//get current hit
169         
170         if(pHit->Y()>0)
171           charge=Param()->TotalCharge(pHit->Particle(),pHit->Eloss(),pHit->Y()-Param()->SectorSizeY());
172         else
173           charge=Param()->TotalCharge(pHit->Particle(),pHit->Eloss(),pHit->Y()+Param()->SectorSizeY());
174                   
175         for(pSeg->FirstPad(pHit->X(),pHit->Y(),0,dx,dy);pSeg->MorePads();pSeg->NextPad()){//pads loop
176             
177           AddSDigit(pHit->Chamber(),pSeg->Ix(),pSeg->Iy(),
178                                     Int_t(charge*TMath::Abs(pRes->IntXY(pSeg))),
179                 iPrimN);//chamber-xpad-ypad-qdc-track1-2-3
180         }//pads loop
181       }//hits loop
182     }//prims loop
183     
184     delete pSeg;
185     
186     fLoader->TreeS()->Fill();
187     fLoader->WriteSDigits("OVERWRITE");
188   }//events loop
189   
190   fLoader->UnloadHits();
191   fLoader->UnloadSDigits();  
192   if(GetDebug()) Info("Hit2SDigits","Stop.");
193 }//void AliRICH::Hits2SDigits()
194 //__________________________________________________________________________________________________
195 void AliRICH::SDigits2Digits()
196 {//Generate digits from sdigits.
197   if(GetDebug()) Info("SDigits2Digits","Start.");
198     
199   AliRunDigitizer *pManager = new AliRunDigitizer(1,1);
200   pManager->SetInputStream(0,"galice.root");
201   pManager->Exec("deb");
202   if(GetDebug()) Info("SDigits2Digits","Stop.");
203 }//void AliRICH::SDigits2Digits()
204 //__________________________________________________________________________________________________
205 void AliRICH::Digits2Reco()
206 {
207 // Generate clusters
208 // Called from alirun, single event only.     
209   if(GetDebug()) Info("Digits2Reco","Start.");
210
211   int nparticles = gAlice->GetNtrack();
212   cout << "Particles (RICH):" <<nparticles<<endl;
213   if (nparticles > 0) FindClusters(0);
214
215 }//void AliRICH::Digits2Reco()  
216 //__________________________________________________________________________________________________
217
218
219 void AliRICH::AddDigits(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
220 {// Add a RICH digit to the list   
221
222    TClonesArray &ldigits = *((TClonesArray*)fDchambers->At(id));
223    new(ldigits[fNdch[id]++]) AliRICHDigit(tracks,charges,digits);
224 }
225
226 void AliRICH::AddRawCluster(Int_t id, const AliRICHRawCluster& c)
227 {// Add a RICH digit to the list
228    
229     TClonesArray &lrawcl = *((TClonesArray*)fRawClusters->At(id));
230     new(lrawcl[fNrawch[id]++]) AliRICHRawCluster(c);
231 }
232 //_____________________________________________________________________________
233 void AliRICH::AddRecHit1D(Int_t id, Float_t *rechit, Float_t *photons, Int_t *padsx, Int_t* padsy)
234 {// Add a RICH reconstructed hit to the list
235
236     TClonesArray &lrec1D = *((TClonesArray*)fRecHits1D->At(id));
237     new(lrec1D[fNrechits1D[id]++]) AliRICHRecHit1D(id,rechit,photons,padsx,padsy);
238 }
239 //_____________________________________________________________________________
240 void AliRICH::AddRecHit3D(Int_t id, Float_t *rechit, Float_t omega, Float_t theta, Float_t phi)
241 {// Add a RICH reconstructed hit to the list
242
243     TClonesArray &lrec3D = *((TClonesArray*)fRecHits3D->At(id));
244     new(lrec3D[fNrechits3D[id]++]) AliRICHRecHit3D(id,rechit,omega,theta,phi);
245 }
246 //______________________________________________________________________________
247 void AliRICH::BuildGeometry() 
248 {//Builds a TNode geometry for event display
249   if(GetDebug())Info("BuildGeometry","Start.");
250   
251   TNode *node, *subnode, *top;
252   top=gAlice->GetGeometry()->GetNode("alice");
253   
254   new TBRIK("S_RICH","S_RICH","void",71.09999,11.5,73.15);
255
256   Float_t wid=fpParam->SectorSizeX();
257   Float_t len=fpParam->SectorSizeY();
258   new TBRIK("PHOTO","PHOTO","void",wid/2,0.1,len/2);
259   
260   for(int i=1;i<=kNCH;i++){
261     top->cd();
262     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());
263     node->SetLineColor(kRed);
264     node->cd();
265     subnode = new TNode("PHOTO1","PHOTO1","PHOTO",wid+fpParam->DeadZone(),5,len/2+fpParam->DeadZone()/2,"");
266     subnode->SetLineColor(kGreen);
267     fNodes->Add(subnode);
268     subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,5,len/2+fpParam->DeadZone()/2,"");
269     subnode->SetLineColor(kGreen);
270     fNodes->Add(subnode);
271     subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-wid-fpParam->DeadZone(),5,len/2+fpParam->DeadZone()/2,"");
272     subnode->SetLineColor(kGreen);
273     fNodes->Add(subnode);
274     subnode = new TNode("PHOTO1","PHOTO1","PHOTO",wid+fpParam->DeadZone(),5,-len/2-fpParam->DeadZone()/2,"");
275     subnode->SetLineColor(kGreen);
276     fNodes->Add(subnode);
277     subnode = new TNode("PHOTO1","PHOTO1","PHOTO",0,5,-len/2 -fpParam->DeadZone()/2,"");
278     subnode->SetLineColor(kGreen);
279     fNodes->Add(subnode);
280     subnode = new TNode("PHOTO1","PHOTO1","PHOTO",-wid-fpParam->DeadZone(),5,-len/2 - fpParam->DeadZone()/2,"");
281     subnode->SetLineColor(kGreen);
282     fNodes->Add(subnode);
283     fNodes->Add(node);
284   }  
285   if(GetDebug())Info("BuildGeometry","Stop.");    
286 }//void AliRICH::BuildGeometry()
287 //______________________________________________________________________________
288 void AliRICH::CreateMaterials()
289 {
290     //
291     // *** DEFINITION OF AVAILABLE RICH MATERIALS *** 
292     // ORIGIN    : NICK VAN EIJNDHOVEN 
293     // Modified by:  N. Colonna (INFN - BARI, Nicola.Colonna@ba.infn.it) 
294     //               R.A. Fini  (INFN - BARI, Rosanna.Fini@ba.infn.it) 
295     //               R.A. Loconsole (Bari University, loco@riscom.ba.infn.it) 
296     //
297     Int_t   isxfld = gAlice->Field()->Integ();
298     Float_t sxmgmx = gAlice->Field()->Max();
299     Int_t i;
300
301     /************************************Antonnelo's Values (14-vectors)*****************************************/
302     /*
303     Float_t ppckov[14] = { 5.63e-9,5.77e-9,5.9e-9,6.05e-9,6.2e-9,6.36e-9,6.52e-9,
304                            6.7e-9,6.88e-9,7.08e-9,7.3e-9,7.51e-9,7.74e-9,8e-9 };
305     Float_t rIndexQuarz[14] = { 1.528309,1.533333,
306                                  1.538243,1.544223,1.550568,1.55777,
307                                  1.565463,1.574765,1.584831,1.597027,
308                                1.611858,1.6277,1.6472,1.6724 };
309     Float_t rIndexOpaqueQuarz[14] = { 1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1. };
310     Float_t rIndexMethane[14] = { 1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1. };
311     Float_t rIndexGrid[14] = { 1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1. };
312     Float_t abscoFreon[14] = { 179.0987,179.0987,
313                                 179.0987,179.0987,179.0987,142.92,56.65,13.95,10.43,7.07,2.03,.5773,.33496,0. };
314     //Float_t abscoFreon[14] = { 1e-5,1e-5,1e-5,1e-5,1e-5,1e-5,1e-5,1e-5,1e-5,
315         //                       1e-5,1e-5,1e-5,1e-5,1e-5 };
316     Float_t abscoQuarz[14] = { 64.035,39.98,35.665,31.262,27.527,22.815,21.04,17.52,
317                                 14.177,9.282,4.0925,1.149,.3627,.10857 };
318     Float_t abscoOpaqueQuarz[14] = { 1e-5,1e-5,1e-5,1e-5,1e-5,1e-5,1e-5,1e-5,1e-5,
319                                  1e-5,1e-5,1e-5,1e-5,1e-5 };
320     Float_t abscoCsI[14] = { 1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,
321                               1e-4,1e-4,1e-4,1e-4 };
322     Float_t abscoMethane[14] = { 1e6,1e6,1e6,1e6,1e6,1e6,1e6,1e6,1e6,1e6,1e6,
323                                   1e6,1e6,1e6 };
324     Float_t abscoGrid[14] = { 1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,1e-4,
325                               1e-4,1e-4,1e-4,1e-4 };
326     Float_t efficAll[14] = { 1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1. };
327     Float_t efficCsI[14] = { 6e-4,.005,.0075,.01125,.045,.117,.135,.16575,
328                               .17425,.1785,.1836,.1904,.1938,.221 };
329     Float_t efficGrid[14] = { 1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1. };
330     */
331    
332     
333     /**********************************End of Antonnelo's Values**********************************/
334     
335     /**********************************Values from rich_media.f (31-vectors)**********************************/
336     
337
338     //Photons energy intervals
339     Float_t ppckov[26];
340     for (i=0;i<26;i++) 
341     {
342         ppckov[i] = (Float_t(i)*0.1+5.5)*1e-9;
343     }
344     
345     
346     //Refraction index for quarz
347     Float_t rIndexQuarz[26];
348     Float_t  e1= 10.666;
349     Float_t  e2= 18.125;
350     Float_t  f1= 46.411;
351     Float_t  f2= 228.71;
352     for (i=0;i<26;i++)
353     {
354         Float_t ene=ppckov[i]*1e9;
355         Float_t a=f1/(e1*e1 - ene*ene);
356         Float_t b=f2/(e2*e2 - ene*ene);
357         rIndexQuarz[i] = TMath::Sqrt(1. + a + b );
358     } 
359     
360     //Refraction index for opaque quarz, methane and grid
361     Float_t rIndexOpaqueQuarz[26];
362     Float_t rIndexMethane[26];
363     Float_t rIndexGrid[26];
364     for (i=0;i<26;i++)
365     {
366         rIndexOpaqueQuarz[i]=1;
367         rIndexMethane[i]=1.000444;
368         rIndexGrid[i]=1;
369     } 
370     
371     //Absorption index for freon
372     Float_t abscoFreon[26] = {179.0987, 179.0987, 179.0987, 179.0987, 179.0987,  179.0987, 179.0987, 179.0987, 
373                                179.0987, 142.9206, 56.64957, 25.58622, 13.95293, 12.03905, 10.42953, 8.804196, 
374                                7.069031, 4.461292, 2.028366, 1.293013, .577267,   .40746,  .334964, 0., 0., 0.};
375     
376     //Absorption index for quarz
377     /*Float_t Qzt [21] = {.0,.0,.005,.04,.35,.647,.769,.808,.829,.844,.853,.858,.869,.887,.903,.902,.902,
378                         .906,.907,.907,.907};
379     Float_t Wavl2[] = {150.,155.,160.0,165.0,170.0,175.0,180.0,185.0,190.0,195.0,200.0,205.0,210.0,
380                        215.0,220.0,225.0,230.0,235.0,240.0,245.0,250.0};                                 
381     Float_t abscoQuarz[31];          
382     for (Int_t i=0;i<31;i++)
383     {
384         Float_t Xlam = 1237.79 / (ppckov[i]*1e9);
385         if (Xlam <= 160) abscoQuarz[i] = 0;
386         if (Xlam > 250) abscoQuarz[i] = 1;
387         else 
388         {
389             for (Int_t j=0;j<21;j++)
390             {
391                 if (Xlam > Wavl2[j] && Xlam < Wavl2[j+1])
392                 {
393                     Float_t Dabs = (Qzt[j+1] - Qzt[j])/(Wavl2[j+1] - Wavl2[j]);
394                     Float_t Abso = Qzt[j] + Dabs*(Xlam - Wavl2[j]);
395                     abscoQuarz[i] = -5.0/(TMath::Log(Abso));
396                 } 
397             }
398         }
399     }*/
400
401     /*Float_t abscoQuarz[31] = {49.64211, 48.41296, 47.46989, 46.50492, 45.13682, 44.47883, 43.1929 , 41.30922, 40.5943 ,
402                                39.82956, 38.98623, 38.6247 , 38.43448, 37.41084, 36.22575, 33.74852, 30.73901, 24.25086, 
403                                17.94531, 11.88753, 5.99128,  3.83503,  2.36661,  1.53155, 1.30582, 1.08574, .8779708, 
404                                .675275, 0., 0., 0.};
405     
406     for (Int_t i=0;i<31;i++)
407     {
408         abscoQuarz[i] = abscoQuarz[i]/10;
409     }*/
410
411     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,
412                                 19.266, 17.525, 15.878, 14.177, 11.719, 9.282, 6.62, 4.0925, 2.601, 1.149, .667, .3627,
413                                 .192, .1497, .10857};
414     
415     //Absorption index for methane
416     Float_t abscoMethane[26];
417     for (i=0;i<26;i++) 
418     {
419         abscoMethane[i]=AbsoCH4(ppckov[i]*1e9); 
420     }
421     
422     //Absorption index for opaque quarz, csi and grid, efficiency for all and grid
423     Float_t abscoOpaqueQuarz[26];
424     Float_t abscoCsI[26];
425     Float_t abscoGrid[26];
426     Float_t efficAll[26];
427     Float_t efficGrid[26];
428     for (i=0;i<26;i++)
429     { 
430         abscoOpaqueQuarz[i]=1e-5; 
431         abscoCsI[i]=1e-4; 
432         abscoGrid[i]=1e-4; 
433         efficAll[i]=1; 
434         efficGrid[i]=1;
435     } 
436     
437     //Efficiency for csi 
438     
439     Float_t efficCsI[26] = {0.000199999995, 0.000600000028, 0.000699999975, 0.00499999989, 0.00749999983, 0.010125,
440                              0.0242999997, 0.0405000001, 0.0688500032, 0.105299994, 0.121500008, 0.141749993, 0.157949999,
441                              0.162, 0.166050002, 0.167669997, 0.174299985, 0.176789999, 0.179279998, 0.182599992, 0.18592,
442                              0.187579989, 0.189239994, 0.190899998, 0.207499996, 0.215799987};
443         
444     
445
446     //FRESNEL LOSS CORRECTION FOR PERPENDICULAR INCIDENCE AND
447     //UNPOLARIZED PHOTONS
448
449     for (i=0;i<26;i++)
450     {
451         efficCsI[i] = efficCsI[i]/(1.-Fresnel(ppckov[i]*1e9,1.,0)); 
452     }
453         
454     /*******************************************End of rich_media.f***************************************/
455
456   
457
458     
459     
460     
461     Float_t afre[2], agri, amet[2], aqua[2], ahon, zfre[2], zgri, zhon, 
462     zmet[2], zqua[2];
463     Int_t nlmatfre;
464     Float_t densquao;
465     Int_t nlmatmet, nlmatqua;
466     Float_t wmatquao[2], rIndexFreon[26];
467     Float_t aquao[2], epsil, stmin, zquao[2];
468     Int_t nlmatquao;
469     Float_t radlal, densal, tmaxfd, deemax, stemax;
470     Float_t aal, zal, radlgri, densfre, radlhon, densgri, denshon,densqua, densmet, wmatfre[2], wmatmet[2], wmatqua[2];
471     
472     Int_t *idtmed = fIdtmed->GetArray()-999;
473     
474     // --- Photon energy (GeV) 
475     // --- Refraction indexes 
476     for (i = 0; i < 26; ++i) {
477       rIndexFreon[i] = ppckov[i] * .0172 * 1e9 + 1.177;
478       //rIndexFreon[i] = 1;
479     }
480             
481     // --- Detection efficiencies (quantum efficiency for CsI) 
482     // --- Define parameters for honeycomb. 
483     //     Used carbon of equivalent rad. lenght 
484     
485     ahon    = 12.01;
486     zhon    = 6.;
487     denshon = 0.1;
488     radlhon = 18.8;
489     
490     // --- Parameters to include in GSMIXT, relative to Quarz (SiO2) 
491     
492     aqua[0]    = 28.09;
493     aqua[1]    = 16.;
494     zqua[0]    = 14.;
495     zqua[1]    = 8.;
496     densqua    = 2.64;
497     nlmatqua   = -2;
498     wmatqua[0] = 1.;
499     wmatqua[1] = 2.;
500     
501     // --- Parameters to include in GSMIXT, relative to opaque Quarz (SiO2) 
502     
503     aquao[0]    = 28.09;
504     aquao[1]    = 16.;
505     zquao[0]    = 14.;
506     zquao[1]    = 8.;
507     densquao    = 2.64;
508     nlmatquao   = -2;
509     wmatquao[0] = 1.;
510     wmatquao[1] = 2.;
511     
512     // --- Parameters to include in GSMIXT, relative to Freon (C6F14) 
513     
514     afre[0]    = 12.;
515     afre[1]    = 19.;
516     zfre[0]    = 6.;
517     zfre[1]    = 9.;
518     densfre    = 1.7;
519     nlmatfre   = -2;
520     wmatfre[0] = 6.;
521     wmatfre[1] = 14.;
522     
523     // --- Parameters to include in GSMIXT, relative to methane (CH4) 
524     
525     amet[0]    = 12.01;
526     amet[1]    = 1.;
527     zmet[0]    = 6.;
528     zmet[1]    = 1.;
529     densmet    = 7.17e-4;
530     nlmatmet   = -2;
531     wmatmet[0] = 1.;
532     wmatmet[1] = 4.;
533     
534     // --- Parameters to include in GSMIXT, relative to anode grid (Cu) 
535   
536     agri    = 63.54;
537     zgri    = 29.;
538     densgri = 8.96;
539     radlgri = 1.43;
540     
541     // --- Parameters to include in GSMATE related to aluminium sheet 
542     
543     aal    = 26.98;
544     zal    = 13.;
545     densal = 2.7;
546     radlal = 8.9;
547
548     // --- Glass parameters
549
550     Float_t aglass[5]={12.01, 28.09, 16.,   10.8,  23.};
551     Float_t zglass[5]={ 6.,   14.,    8.,    5.,   11.};
552     Float_t wglass[5]={ 0.5,  0.105, 0.355, 0.03,  0.01};
553     Float_t dglass=1.74;
554
555     
556     AliMaterial(1, "Air     $", 14.61, 7.3, .001205, 30420., 67500);
557     AliMaterial(6, "HON", ahon, zhon, denshon, radlhon, 0);
558     AliMaterial(16, "CSI", ahon, zhon, denshon, radlhon, 0);
559     AliMixture(20, "QUA", aqua, zqua, densqua, nlmatqua, wmatqua);
560     AliMixture(21, "QUAO", aquao, zquao, densquao, nlmatquao, wmatquao);
561     AliMixture(30, "FRE", afre, zfre, densfre, nlmatfre, wmatfre);
562     AliMixture(40, "MET", amet, zmet, densmet, nlmatmet, wmatmet);
563     AliMixture(41, "METG", amet, zmet, densmet, nlmatmet, wmatmet);
564     AliMaterial(11, "GRI", agri, zgri, densgri, radlgri, 0);
565     AliMaterial(50, "ALUM", aal, zal, densal, radlal, 0);
566     AliMixture(32, "GLASS",aglass, zglass, dglass, 5, wglass);
567     AliMaterial(31, "COPPER$",   63.54,    29.,   8.96,  1.4, 0.);
568     
569     tmaxfd = -10.;
570     stemax = -.1;
571     deemax = -.2;
572     epsil  = .001;
573     stmin  = -.001;
574     
575     AliMedium(1, "DEFAULT MEDIUM AIR$", 1, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
576     AliMedium(2, "HONEYCOMB$", 6, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
577     AliMedium(3, "QUARZO$", 20, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
578     AliMedium(4, "FREON$", 30, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
579     AliMedium(5, "METANO$", 40, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
580     AliMedium(6, "CSI$", 16, 1, isxfld, sxmgmx,tmaxfd, stemax, deemax, epsil, stmin);
581     AliMedium(7, "GRIGLIA$", 11, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
582     AliMedium(8, "QUARZOO$", 21, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
583     AliMedium(9, "GAP$", 41, 1, isxfld, sxmgmx,tmaxfd, .1, -deemax, epsil, -stmin);
584     AliMedium(10, "ALUMINUM$", 50, 1, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
585     AliMedium(11, "GLASS", 32, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
586     AliMedium(12, "PCB_COPPER", 31, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
587     
588
589     gMC->SetCerenkov(idtmed[1000], 26, ppckov, abscoMethane, efficAll, rIndexMethane);
590     gMC->SetCerenkov(idtmed[1001], 26, ppckov, abscoMethane, efficAll, rIndexMethane);
591     gMC->SetCerenkov(idtmed[1002], 26, ppckov, abscoQuarz, efficAll,rIndexQuarz);
592     gMC->SetCerenkov(idtmed[1003], 26, ppckov, abscoFreon, efficAll,rIndexFreon);
593     gMC->SetCerenkov(idtmed[1004], 26, ppckov, abscoMethane, efficAll, rIndexMethane);
594     gMC->SetCerenkov(idtmed[1005], 26, ppckov, abscoCsI, efficCsI, rIndexMethane);
595     gMC->SetCerenkov(idtmed[1006], 26, ppckov, abscoGrid, efficGrid, rIndexGrid);
596     gMC->SetCerenkov(idtmed[1007], 26, ppckov, abscoOpaqueQuarz, efficAll, rIndexOpaqueQuarz);
597     gMC->SetCerenkov(idtmed[1008], 26, ppckov, abscoMethane, efficAll, rIndexMethane);
598     gMC->SetCerenkov(idtmed[1009], 26, ppckov, abscoGrid, efficGrid, rIndexGrid);
599     gMC->SetCerenkov(idtmed[1010], 26, ppckov, abscoOpaqueQuarz, efficAll, rIndexOpaqueQuarz);
600 }
601 //__________________________________________________________________________________________________
602 Float_t AliRICH::Fresnel(Float_t ene,Float_t pdoti, Bool_t pola)
603 {
604
605     //ENE(EV), PDOTI=COS(INC.ANG.), PDOTR=COS(POL.PLANE ROT.ANG.)
606     
607     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,
608                       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,
609                       7.8,7.9,8.0,8.1,8.2,8.3,8.4,8.5};
610     Float_t csin[36] = {2.14,2.21,2.33,2.48,2.76,2.97,2.99,2.59,2.81,3.05,
611                         2.86,2.53,2.55,2.66,2.79,2.96,3.18,3.05,2.84,2.81,2.38,2.11,
612                         2.01,2.13,2.39,2.73,3.08,3.15,2.95,2.73,2.56,2.41,2.12,1.95,
613                         1.72,1.53};
614     Float_t csik[36] = {0.,0.,0.,0.,0.,0.196,0.408,0.208,0.118,0.49,0.784,0.543,
615                         0.424,0.404,0.371,0.514,0.922,1.102,1.139,1.376,1.461,1.253,0.878,
616                         0.69,0.612,0.649,0.824,1.347,1.571,1.678,1.763,1.857,1.824,1.824,
617                         1.714,1.498};
618     Float_t xe=ene;
619     Int_t  j=Int_t(xe*10)-49;
620     Float_t cn=csin[j]+((csin[j+1]-csin[j])/0.1)*(xe-en[j]);
621     Float_t ck=csik[j]+((csik[j+1]-csik[j])/0.1)*(xe-en[j]);
622
623     //FORMULAE FROM HANDBOOK OF OPTICS, 33.23 OR
624     //W.R. HUNTER, J.O.S.A. 54 (1964),15 , J.O.S.A. 55(1965),1197
625
626     Float_t sinin=TMath::Sqrt(1-pdoti*pdoti);
627     Float_t tanin=sinin/pdoti;
628
629     Float_t c1=cn*cn-ck*ck-sinin*sinin;
630     Float_t c2=4*cn*cn*ck*ck;
631     Float_t aO=TMath::Sqrt(0.5*(TMath::Sqrt(c1*c1+c2)+c1));
632     Float_t b2=0.5*(TMath::Sqrt(c1*c1+c2)-c1);
633     
634     Float_t rs=((aO-pdoti)*(aO-pdoti)+b2)/((aO+pdoti)*(aO+pdoti)+b2);
635     Float_t rp=rs*((aO-sinin*tanin)*(aO-sinin*tanin)+b2)/((aO+sinin*tanin)*(aO+sinin*tanin)+b2);
636     
637
638     //CORRECTION FACTOR FOR SURFACE ROUGHNESS
639     //B.J. STAGG  APPLIED OPTICS, 30(1991),4113
640
641     Float_t sigraf=18.;
642     Float_t lamb=1240/ene;
643     Float_t fresn;
644  
645     Float_t  rO=TMath::Exp(-(4*TMath::Pi()*pdoti*sigraf/lamb)*(4*TMath::Pi()*pdoti*sigraf/lamb));
646
647     if(pola)
648     {
649         Float_t pdotr=0.8;                                 //DEGREE OF POLARIZATION : 1->P , -1->S
650         fresn=0.5*(rp*(1+pdotr)+rs*(1-pdotr));
651     }
652     else
653         fresn=0.5*(rp+rs);
654       
655     fresn = fresn*rO;
656     return(fresn);
657 }//Float_t AliRICH::Fresnel(Float_t ene,Float_t pdoti, Bool_t pola)
658 //__________________________________________________________________________________________________
659 Float_t AliRICH::AbsoCH4(Float_t x)
660 {
661
662     //KLOSCH,SCH4(9),WL(9),EM(9),ALENGTH(31)
663     Float_t sch4[9] = {.12,.16,.23,.38,.86,2.8,7.9,28.,80.};              //MB X 10^22
664     //Float_t wl[9] = {153.,152.,151.,150.,149.,148.,147.,146.,145};
665     Float_t em[9] = {8.1,8.158,8.212,8.267,8.322,8.378,8.435,8.493,8.55};
666     const Float_t kLosch=2.686763E19;                                      // LOSCHMIDT NUMBER IN CM-3
667     const Float_t kIgas1=100, kIgas2=0, kOxy=10., kWater=5., kPressure=750.,kTemperature=283.;                                      
668     Float_t pn=kPressure/760.;
669     Float_t tn=kTemperature/273.16;
670     
671         
672 // ------- METHANE CROSS SECTION -----------------
673 // ASTROPH. J. 214, L47 (1978)
674         
675     Float_t sm=0;
676     if (x<7.75) 
677         sm=.06e-22;
678     
679     if(x>=7.75 && x<=8.1)
680     {
681         Float_t c0=-1.655279e-1;
682         Float_t c1=6.307392e-2;
683         Float_t c2=-8.011441e-3;
684         Float_t c3=3.392126e-4;
685         sm=(c0+c1*x+c2*x*x+c3*x*x*x)*1.e-18;
686     }
687     
688     if (x> 8.1)
689     {
690         Int_t j=0;
691         while (x<=em[j] && x>=em[j+1])
692         {
693             j++;
694             Float_t a=(sch4[j+1]-sch4[j])/(em[j+1]-em[j]);
695             sm=(sch4[j]+a*(x-em[j]))*1e-22;
696         }
697     }
698     
699     Float_t dm=(kIgas1/100.)*(1.-((kOxy+kWater)/1.e6))*kLosch*pn/tn;
700     Float_t abslm=1./sm/dm;
701     
702 //    ------- ISOBUTHANE CROSS SECTION --------------
703 //     i-C4H10 (ai) abs. length from curves in
704 //     Lu-McDonald paper for BARI RICH workshop .
705 //     -----------------------------------------------------------
706     
707     Float_t ai;
708     Float_t absli;
709     if (kIgas2 != 0) 
710     {
711         if (x<7.25)
712             ai=100000000.;
713         
714         if(x>=7.25 && x<7.375)
715             ai=24.3;
716         
717         if(x>=7.375)
718             ai=.0000000001;
719         
720         Float_t si = 1./(ai*kLosch*273.16/293.);                    // ISOB. CRO.SEC.IN CM2
721         Float_t di=(kIgas2/100.)*(1.-((kOxy+kWater)/1.e6))*kLosch*pn/tn;
722         absli =1./si/di;
723     }
724     else
725         absli=1.e18;
726 //    ---------------------------------------------------------
727 //
728 //       transmission of O2
729 //
730 //       y= path in cm, x=energy in eV
731 //       so= cross section for UV absorption in cm2
732 //       do= O2 molecular density in cm-3
733 //    ---------------------------------------------------------
734     
735     Float_t abslo;
736     Float_t so=0;
737     if(x>=6.0)
738     {
739         if(x>=6.0 && x<6.5)
740         {
741             so=3.392709e-13 * TMath::Exp(2.864104 *x);
742             so=so*1e-18;
743         }
744         
745         if(x>=6.5 && x<7.0) 
746         {
747             so=2.910039e-34 * TMath::Exp(10.3337*x);
748             so=so*1e-18;
749         }
750             
751
752         if (x>=7.0) 
753         {
754             Float_t a0=-73770.76;
755             Float_t a1=46190.69;
756             Float_t a2=-11475.44;
757             Float_t a3=1412.611;
758             Float_t a4=-86.07027;
759             Float_t a5=2.074234;
760             so= a0+(a1*x)+(a2*x*x)+(a3*x*x*x)+(a4*x*x*x*x)+(a5*x*x*x*x*x);
761             so=so*1e-18;
762         }
763         
764         Float_t dox=(kOxy/1e6)*kLosch*pn/tn;
765         abslo=1./so/dox;
766     }
767     else
768         abslo=1.e18;
769 //     ---------------------------------------------------------
770 //
771 //       transmission of H2O
772 //
773 //       y= path in cm, x=energy in eV
774 //       sw= cross section for UV absorption in cm2
775 //       dw= H2O molecular density in cm-3
776 //     ---------------------------------------------------------
777     
778     Float_t abslw;
779     
780     Float_t b0=29231.65;
781     Float_t b1=-15807.74;
782     Float_t b2=3192.926;
783     Float_t b3=-285.4809;
784     Float_t b4=9.533944;
785     
786     if(x>6.75)
787     {    
788         Float_t sw= b0+(b1*x)+(b2*x*x)+(b3*x*x*x)+(b4*x*x*x*x);
789         sw=sw*1e-18;
790         Float_t dw=(kWater/1e6)*kLosch*pn/tn;
791         abslw=1./sw/dw;
792     }
793     else
794         abslw=1.e18;
795             
796 //    ---------------------------------------------------------
797     
798     Float_t alength=1./(1./abslm+1./absli+1./abslo+1./abslw);
799     return (alength);
800 }
801 //__________________________________________________________________________________________________
802 void AliRICH::ResetDigits()
803 {//Reset number of digits and the digits array for this detector
804   for ( int i=0;i<kNCH;i++ ) {
805     if (fDchambers && fDchambers->At(i))   fDchambers->At(i)->Clear();
806     if (fNdch)  fNdch[i]=0;
807   }
808 }
809 //__________________________________________________________________________________________________
810 void AliRICH::ResetRawClusters()
811 {//Reset number of raw clusters and the raw clust array for this detector
812   for ( int i=0;i<kNCH;i++ ) {
813     if (fRawClusters->At(i))    ((TClonesArray*)fRawClusters->At(i))->Clear();
814     if (fNrawch)  fNrawch[i]=0;
815   }
816 }
817 //__________________________________________________________________________________________________
818 void AliRICH::ResetRecHits1D()
819 {//Reset number of raw clusters and the raw clust array for this detector
820   for ( int i=0;i<kNCH;i++ ) {
821     if (fRecHits1D->At(i))    ((TClonesArray*)fRecHits1D->At(i))->Clear();
822     if (fNrechits1D)  fNrechits1D[i]=0;
823   }
824 }
825
826 //__________________________________________________________________________________________________
827 void AliRICH::ResetRecHits3D()
828 {// Reset number of raw clusters and the raw clust array for this detector
829   for ( int i=0;i<kNCH;i++ ) {
830     if (fRecHits3D->At(i))    ((TClonesArray*)fRecHits3D->At(i))->Clear();
831     if (fNrechits3D)  fNrechits3D[i]=0;
832   }
833 }
834 //__________________________________________________________________________________________________
835 void AliRICH::FindClusters(Int_t nev /*kir,Int_t lastEntry*/)
836 {// Loop on chambers and on cathode planes
837     for (Int_t icat=1;icat<2;icat++) {
838         gAlice->ResetDigits();
839         gAlice->TreeD()->GetEvent(0);
840         for (Int_t ich=0;ich<kNCH;ich++) {
841           AliRICHChamber* iChamber=(AliRICHChamber*)fChambers->At(ich);
842           TClonesArray *pRICHdigits  = this->DigitsAddress(ich);
843           if (pRICHdigits == 0)       
844               continue;
845           //
846           // Get ready the current chamber stuff
847           //
848           AliRICHResponse* response = iChamber->GetResponseModel();
849           AliSegmentation*  seg = iChamber->GetSegmentationModel();
850           AliRICHClusterFinder* rec = iChamber->GetReconstructionModel();
851           if (seg) {      
852               rec->SetSegmentation(seg);
853               rec->SetResponse(response);
854               rec->SetDigits(pRICHdigits);
855               rec->SetChamber(ich);
856               if (nev==0) rec->CalibrateCOG(); 
857               rec->FindRawClusters();
858           }  
859           TClonesArray *fRch;
860           fRch=RawClustAddress(ich);
861           fRch->Sort();
862         } // for ich
863
864         gAlice->TreeR()->Fill();
865         TClonesArray *fRch;
866         for (int i=0;i<kNCH;i++) {
867             fRch=RawClustAddress(i);
868             fRch->GetEntriesFast();
869         }
870         
871         ResetRawClusters();
872         
873     } // for icat
874     
875     char hname[30];
876     sprintf(hname,"TreeR%d",nev);
877     gAlice->TreeR()->Write(hname,kOverwrite,0);
878     gAlice->TreeR()->Reset();    
879 }//void AliRICH::FindClusters(Int_t nev)
880 //__________________________________________________________________________________________________
881 void AliRICH::MakeBranchInTreeD(TTree *treeD, const char *file)
882 {// Create TreeD branches for the RICH.
883   if(GetDebug())Info("MakeBranchInTreeD","Start.");
884
885   const Int_t kBufferSize = 4000;
886   char branchname[30];
887     
888   //
889   // one branch for digits per chamber
890   // 
891   for (Int_t i=0; i<kNCH ;i++) {
892     sprintf(branchname,"%sDigits%d",GetName(),i+1);     
893     if (fDchambers && treeD) {
894       MakeBranchInTree(treeD,branchname, &((*fDchambers)[i]), kBufferSize, file);
895 //      printf("Making Branch %s for digits in chamber %d\n",branchname,i+1);
896     }
897   }
898 }
899 //__________________________________________________________________________________________________
900 void AliRICH::MakeBranch(Option_t* option)
901 {//Create Tree branches for the RICH.
902   if(GetDebug())Info("MakeBranch","Start with option= %s.",option);
903     
904   const Int_t kBufferSize = 4000;
905   char branchname[20];
906       
907    
908   const char *cH = strstr(option,"H");
909   const char *cD = strstr(option,"D");
910   const char *cR = strstr(option,"R");
911   const char *cS = strstr(option,"S");
912
913   if(cH&&TreeH()){
914     if(!fHits) fHits=new TClonesArray("AliRICHhit",1000  );
915     if(!fCerenkovs) fCerenkovs  = new TClonesArray("AliRICHCerenkov",1000);
916     MakeBranchInTree(TreeH(),"RICHCerenkov", &fCerenkovs, kBufferSize, 0) ;
917
918     //kir if(!fSDigits) fSDigits    = new TClonesArray("AliRICHdigit",100000);
919     //kir MakeBranchInTree(TreeH(),"RICHSDigits", &fSDigits, kBufferSize, 0) ;
920   }     
921   AliDetector::MakeBranch(option);//this is after cH because we need to guarantee that fHits array is created
922       
923   if(cS&&fLoader->TreeS()){  
924     if(!fSDigits) fSDigits=new TClonesArray("AliRICHdigit",100000);
925     MakeBranchInTree(fLoader->TreeS(),"RICH",&fSDigits,kBufferSize,0) ;
926   }
927    
928   int i;
929   if (cD&&fLoader->TreeD()){
930     if(!fDchambers){
931       fDchambers=new TObjArray(kNCH);    // one branch for digits per chamber
932       for(i=0;i<kNCH;i++){ 
933         fDchambers->AddAt(new TClonesArray("AliRICHDigit",10000), i); 
934       }       
935     }
936     for (i=0; i<kNCH ;i++) 
937       {
938         sprintf(branchname,"%sDigits%d",GetName(),i+1); 
939         MakeBranchInTree(fLoader->TreeD(),branchname, &((*fDchambers)[i]), kBufferSize, 0);
940       }
941    }
942
943   if (cR&&gAlice->TreeR()){//one branch for raw clusters per chamber
944     Int_t i;
945     if (fRawClusters == 0x0 ) 
946      {
947        fRawClusters = new TObjArray(kNCH);
948        for (i=0; i<kNCH ;i++) 
949          {
950            fRawClusters->AddAt(new TClonesArray("AliRICHRawCluster",10000), i); 
951          }
952      }
953      
954     if (fRecHits1D == 0x0) 
955      {
956         fRecHits1D = new TObjArray(kNCH);
957         for (i=0; i<kNCH ;i++) 
958          {
959           fRecHits1D->AddAt(new TClonesArray("AliRICHRecHit1D",1000), i);
960          }
961      }
962
963     if (fRecHits3D == 0x0) 
964      {
965         fRecHits3D = new TObjArray(kNCH);
966         for (i=0; i<kNCH ;i++) 
967          {
968           fRecHits3D->AddAt(new TClonesArray("AliRICHRecHit3D",1000), i);
969          }
970      }
971        
972     for (i=0; i<kNCH ;i++){
973        sprintf(branchname,"%sRawClusters%d",GetName(),i+1);      
974        MakeBranchInTree(gAlice->TreeR(),branchname, &((*fRawClusters)[i]), kBufferSize, 0);
975        sprintf(branchname,"%sRecHits1D%d",GetName(),i+1);
976        MakeBranchInTree(fLoader->TreeR(),branchname, &((*fRecHits1D)[i]), kBufferSize, 0);
977        sprintf(branchname,"%sRecHits3D%d",GetName(),i+1);  
978        MakeBranchInTree(fLoader->TreeR(),branchname, &((*fRecHits3D)[i]), kBufferSize, 0);
979      }
980    }//if (cR && gAlice->TreeR())
981   if(GetDebug())Info("MakeBranch","Stop.");   
982 }//void AliRICH::MakeBranch(Option_t* option)
983 //______________________________________________________________________________
984 void AliRICH::SetTreeAddress()
985 {//Set branch address for the Hits and Digits Tree.
986   if(GetDebug())Info("SetTreeAddress","Start.");
987   
988   char branchname[20];
989   Int_t i;
990
991     
992   TBranch *branch;
993   TTree *treeH = fLoader->TreeH();
994   TTree *treeD = fLoader->TreeD();
995   TTree *treeR = fLoader->TreeR();
996     
997   if(treeH){
998     if(GetDebug())Info("SetTreeAddress","tree H is requested.");
999     if(fHits==0x0) fHits=new TClonesArray("AliRICHhit",1000); 
1000     
1001     branch = treeH->GetBranch("RICHCerenkov");
1002     if(branch){
1003       if (fCerenkovs == 0x0) fCerenkovs  = new TClonesArray("AliRICHCerenkov",1000); 
1004         branch->SetAddress(&fCerenkovs);
1005     }
1006        
1007 //kir      branch = treeH->GetBranch("RICHSDigits");
1008 //kir      if (branch) 
1009 //kir       {
1010 //kir         if (fSDigits == 0x0) fSDigits    = new TClonesArray("AliRICHdigit",100000);
1011 //kir         branch->SetAddress(&fSDigits);
1012 //kir       }
1013   }//if(treeH)
1014  
1015   AliDetector::SetTreeAddress();//this is after TreeH because we need to guarantee that fHits array is created
1016
1017     
1018   if(fLoader->TreeS()){
1019     if(GetDebug())Info("SetTreeAddress","tree S is requested.");
1020     if(!fSDigits) fSDigits=new TClonesArray("AliRICHdigit",100000);
1021     fLoader->TreeS()->GetBranch("RICH")->SetAddress(&fSDigits);
1022   }
1023     
1024     
1025   if(treeD){
1026     if(GetDebug())Info("SetTreeAddress","tree D is requested.");
1027
1028       if (fDchambers == 0x0) 
1029         {
1030            fDchambers = new TObjArray(kNCH);
1031            for (i=0; i<kNCH ;i++) 
1032              {
1033                fDchambers->AddAt(new TClonesArray("AliRICHDigit",10000), i); 
1034              }
1035         }
1036       
1037       for (i=0; i<kNCH; i++) {
1038         sprintf(branchname,"%sDigits%d",GetName(),i+1);
1039         if (fDchambers) {
1040            branch = treeD->GetBranch(branchname);
1041            if (branch) branch->SetAddress(&((*fDchambers)[i]));
1042         }
1043       }
1044     }
1045     
1046   if(treeR){
1047     if(GetDebug())Info("SetTreeAddress","tree R is requested.");
1048
1049     if (fRawClusters == 0x0 ) 
1050      {
1051        fRawClusters = new TObjArray(kNCH);
1052        for (i=0; i<kNCH ;i++) 
1053          {
1054            fRawClusters->AddAt(new TClonesArray("AliRICHRawCluster",10000), i); 
1055          }
1056      }
1057      
1058     if (fRecHits1D == 0x0) 
1059      {
1060         fRecHits1D = new TObjArray(kNCH);
1061         for (i=0; i<kNCH ;i++) 
1062          {
1063           fRecHits1D->AddAt(new TClonesArray("AliRICHRecHit1D",1000), i);
1064          }
1065      }
1066
1067     if (fRecHits3D == 0x0) 
1068      {
1069         fRecHits3D = new TObjArray(kNCH);
1070         for (i=0; i<kNCH ;i++) 
1071          {
1072           fRecHits3D->AddAt(new TClonesArray("AliRICHRecHit3D",1000), i);
1073          }
1074      }
1075     
1076     for (i=0; i<kNCH; i++) {
1077           sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
1078           if (fRawClusters) {
1079               branch = treeR->GetBranch(branchname);
1080               if (branch) branch->SetAddress(&((*fRawClusters)[i]));
1081           }
1082     }
1083       
1084     for (i=0; i<kNCH; i++) {
1085         sprintf(branchname,"%sRecHits1D%d",GetName(),i+1);
1086         if (fRecHits1D) {
1087           branch = treeR->GetBranch(branchname);
1088           if (branch) branch->SetAddress(&((*fRecHits1D)[i]));
1089           }
1090      }
1091       
1092      for (i=0; i<kNCH; i++) {
1093         sprintf(branchname,"%sRecHits3D%d",GetName(),i+1);
1094         if (fRecHits3D) {
1095           branch = treeR->GetBranch(branchname);
1096           if (branch) branch->SetAddress(&((*fRecHits3D)[i]));
1097           }
1098       } 
1099       
1100   }//if(treeR)
1101   if(GetDebug())Info("SetTreeAddress","Stop.");
1102 }//void AliRICH::SetTreeAddress()
1103 //__________________________________________________________________________________________________
1104 void AliRICH::Print(Option_t *option)const
1105 {
1106   TObject::Print(option);
1107   fpParam->Dump();
1108   fChambers->Print(option);  
1109 }//void AliRICH::Print(Option_t *option)const
1110 //__________________________________________________________________________________________________
1111 void AliRICH::CreateGeometry()
1112 {//Creates detailed geometry simulation (currently GEANT volumes tree)         
1113   if(GetDebug())Info("CreateGeometry","Start.");
1114 //???????? to be removed to AliRICHParam?
1115   fpParam->RadiatorToPads(fpParam->FreonThickness()/2+fpParam->QuartzThickness()+fpParam->GapThickness());
1116     
1117 //Opaque quartz thickness
1118   Float_t oqua_thickness = .5;
1119 //CsI dimensions
1120   Float_t csi_width =fpParam->Nx()*fpParam->PadSizeX()+fpParam->DeadZone();
1121   Float_t csi_length=fpParam->Ny()*fpParam->PadSizeY()+2*fpParam->DeadZone();
1122   
1123   Int_t *idtmed = fIdtmed->GetArray()-999;
1124     
1125   Int_t i;
1126   Float_t zs;
1127   Int_t idrotm[1099];
1128   Float_t par[3];
1129     
1130 //External aluminium box 
1131   par[0]=68.8*cm;par[1]=13*cm;par[2]=70.86*cm;//Original Settings
1132   gMC->Gsvolu("RICH", "BOX ", idtmed[1009], par, 3);
1133 //Air 
1134   par[0]=66.3;   par[1] = 13; par[2] = 68.35; //Original Settings
1135   gMC->Gsvolu("SRIC", "BOX ", idtmed[1000], par, 3); 
1136 //Air 2 (cutting the lower part of the box)
1137   par[0]=1.25;    par[1] = 3;    par[2] = 70.86; //Original Settings
1138   gMC->Gsvolu("AIR2", "BOX ", idtmed[1000], par, 3);
1139 //Air 3 (cutting the lower part of the box)
1140   par[0]=66.3;    par[1] = 3;  par[2] = 1.2505; //Original Settings
1141   gMC->Gsvolu("AIR3", "BOX ", idtmed[1000], par, 3);
1142 //Honeycomb 
1143   par[0]=66.3;par[1]=0.188;  par[2] = 68.35;  //Original Settings
1144   gMC->Gsvolu("HONE", "BOX ", idtmed[1001], par, 3);
1145 //Aluminium sheet 
1146   par[0]=66.3;par[1]=0.025;par[2]=68.35; //Original Settings
1147   //par[0] = 66.5; par[1] = .025; par[2] = 63.1;
1148   gMC->Gsvolu("ALUM", "BOX ", idtmed[1009], par, 3);
1149 //Quartz 
1150   par[0]=fpParam->QuartzWidth()/2;par[1]=fpParam->QuartzThickness()/2;par[2]=fpParam->QuartzLength()/2;
1151   gMC->Gsvolu("QUAR", "BOX ", idtmed[1002], par, 3);
1152 //Spacers (cylinders) 
1153   par[0]=0.;par[1]=.5;par[2]=fpParam->FreonThickness()/2;
1154   gMC->Gsvolu("SPAC", "TUBE", idtmed[1002], par, 3);    
1155 //Feet (freon slabs supports)
1156   par[0] = .7;  par[1] = .3;  par[2] = 1.9;
1157   gMC->Gsvolu("FOOT", "BOX", idtmed[1009], par, 3);
1158 //Opaque quartz 
1159   par[0]=fpParam->QuartzWidth()/2;par[1]= .2;par[2]=fpParam->QuartzLength()/2;
1160   gMC->Gsvolu("OQUA", "BOX ", idtmed[1007], par, 3);
1161 //Frame of opaque quartz
1162   par[0]=fpParam->OuterFreonWidth()/2;par[1]=fpParam->FreonThickness()/2;par[2]=fpParam->OuterFreonLength()/2; 
1163   gMC->Gsvolu("OQF1", "BOX ", idtmed[1007], par, 3);
1164   par[0]=fpParam->InnerFreonWidth()/2;par[1]=fpParam->FreonThickness()/2;par[2]=fpParam->InnerFreonLength()/2; 
1165   gMC->Gsvolu("OQF2", "BOX ", idtmed[1007], par, 3);
1166 //Freon 
1167   par[0]=fpParam->OuterFreonWidth()/2 - oqua_thickness;
1168   par[1]=fpParam->FreonThickness()/2;
1169   par[2]=fpParam->OuterFreonLength()/2 - 2*oqua_thickness; 
1170   gMC->Gsvolu("FRE1", "BOX ", idtmed[1003], par, 3);
1171
1172   par[0]=fpParam->InnerFreonWidth()/2 - oqua_thickness;
1173   par[1]=fpParam->FreonThickness()/2;
1174   par[2]=fpParam->InnerFreonLength()/2 - 2*oqua_thickness; 
1175   gMC->Gsvolu("FRE2", "BOX ", idtmed[1003], par, 3);    
1176 //Methane 
1177   par[0]=csi_width/2;par[1]=fpParam->GapThickness()/2;par[2]=csi_length/2;
1178   gMC->Gsvolu("META", "BOX ", idtmed[1004], par, 3);
1179 //Methane gap 
1180   par[0]=csi_width/2;par[1]=fpParam->ProximityGapThickness()/2;par[2] = csi_length/2;
1181   gMC->Gsvolu("GAP ", "BOX ", idtmed[1008], par, 3);
1182 //CsI photocathode 
1183   par[0]=csi_width/2;par[1]=.25;par[2]=csi_length/2;
1184   gMC->Gsvolu("CSI ", "BOX ", idtmed[1005], par, 3);
1185 //Anode grid 
1186   par[0] = 0.;par[1] = .001;par[2] = 20.;
1187   gMC->Gsvolu("GRID", "TUBE", idtmed[1006], par, 3);
1188
1189 //Wire supports
1190 //Bar of metal
1191   par[0]=csi_width/2;par[1]=1.05;par[2]=1.05;
1192   gMC->Gsvolu("WSMe", "BOX ", idtmed[1009], par, 3);
1193 //Ceramic pick up (base)
1194   par[0]=csi_width/2;par[1]= .25;par[2]=1.05;
1195   gMC->Gsvolu("WSG1", "BOX ", idtmed[1010], par, 3);
1196 //Ceramic pick up (head)
1197   par[0] = csi_width/2;par[1] = .1;par[2] = .1;
1198   gMC->Gsvolu("WSG2", "BOX ", idtmed[1010], par, 3);
1199
1200 //Aluminium supports for methane and CsI
1201 //Short bar
1202   par[0]=csi_width/2;par[1]=fpParam->GapThickness()/2 + .25; par[2] = (68.35 - csi_length/2)/2;
1203   gMC->Gsvolu("SMSH", "BOX", idtmed[1009], par, 3);
1204 //Long bar
1205   par[0]=(66.3 - csi_width/2)/2;par[1]=fpParam->GapThickness()/2+.25;par[2]=csi_length/2+68.35-csi_length/2;
1206   gMC->Gsvolu("SMLG", "BOX", idtmed[1009], par, 3);
1207     
1208 //Aluminium supports for freon
1209 //Short bar
1210   par[0] = fpParam->QuartzWidth()/2; par[1] = .3; par[2] = (68.35 - fpParam->QuartzLength()/2)/2;
1211   gMC->Gsvolu("SFSH", "BOX", idtmed[1009], par, 3);    
1212 //Long bar
1213   par[0] = (66.3 - fpParam->QuartzWidth()/2)/2; par[1] = .3;
1214   par[2] = fpParam->QuartzLength()/2 + 68.35 - fpParam->QuartzLength()/2;
1215   gMC->Gsvolu("SFLG", "BOX", idtmed[1009], par, 3);    
1216 //PCB backplane
1217   par[0] = csi_width/2;par[1] = .25; par[2] = csi_length/4 -.5025;
1218   gMC->Gsvolu("PCB ", "BOX", idtmed[1011], par, 3);
1219
1220 //Backplane supports
1221 //Aluminium slab
1222   par[0] = 33.15;par[1] = 2;par[2] = 21.65;
1223   gMC->Gsvolu("BACK", "BOX", idtmed[1009], par, 3);    
1224 //Big hole
1225   par[0] = 9.05; par[1] = 2; par[2] = 4.4625;
1226   gMC->Gsvolu("BKHL", "BOX", idtmed[1000], par, 3);
1227 //Small hole
1228   par[0] = 5.7;par[1] = 2;par[2] = 4.4625;
1229   gMC->Gsvolu("BKHS", "BOX", idtmed[1000], par, 3);
1230 //Place holes inside backplane support
1231   gMC->Gspos("BKHS", 1, "BACK", .8 + 5.7,0., .6 + 4.4625, 0, "ONLY");
1232   gMC->Gspos("BKHS", 2, "BACK", -.8 - 5.7,0., .6 + 4.4625, 0, "ONLY");
1233   gMC->Gspos("BKHS", 3, "BACK", .8 + 5.7,0., -.6 - 4.4625, 0, "ONLY");
1234   gMC->Gspos("BKHS", 4, "BACK", -.8 - 5.7,0., -.6 - 4.4625, 0, "ONLY");
1235   gMC->Gspos("BKHS", 5, "BACK", .8 + 5.7,0., .6 + 8.925 + 1.2 + 4.4625, 0, "ONLY");
1236   gMC->Gspos("BKHS", 6, "BACK", -.8 - 5.7,0., .6 + 8.925 + 1.2 + 4.4625, 0, "ONLY");
1237   gMC->Gspos("BKHS", 7, "BACK", .8 + 5.7,0., -.6 - 8.925 - 1.2 - 4.4625, 0, "ONLY");
1238   gMC->Gspos("BKHS", 8, "BACK", -.8 - 5.7,0., -.6 - 8.925 - 1.2 - 4.4625, 0, "ONLY");
1239   gMC->Gspos("BKHL", 1, "BACK", .8 + 11.4 + 1.6 + 9.05, 0., .6 + 4.4625, 0, "ONLY");
1240   gMC->Gspos("BKHL", 2, "BACK", -.8 - 11.4 - 1.6 - 9.05, 0., .6 + 4.4625, 0, "ONLY");
1241   gMC->Gspos("BKHL", 3, "BACK", .8 + 11.4 + 1.6 + 9.05, 0., -.6 - 4.4625, 0, "ONLY");
1242   gMC->Gspos("BKHL", 4, "BACK", -.8 - 11.4 - 1.6 - 9.05, 0., -.6 - 4.4625, 0, "ONLY");
1243   gMC->Gspos("BKHL", 5, "BACK", .8 + 11.4+ 1.6 + 9.05, 0., .6 + 8.925 + 1.2 + 4.4625, 0, "ONLY");
1244   gMC->Gspos("BKHL", 6, "BACK", -.8 - 11.4 - 1.6 - 9.05, 0., .6 + 8.925 + 1.2 + 4.4625, 0, "ONLY");
1245   gMC->Gspos("BKHL", 7, "BACK", .8 + 11.4 + 1.6 + 9.05, 0., -.6 - 8.925 - 1.2 - 4.4625, 0, "ONLY");
1246   gMC->Gspos("BKHL", 8, "BACK", -.8 - 11.4 - 1.6 - 9.05, 0., -.6 - 8.925 - 1.2 - 4.4625, 0, "ONLY");
1247 //Place material inside RICH 
1248   gMC->Gspos("SRIC", 1, "RICH", 0.,0., 0., 0, "ONLY");
1249   gMC->Gspos("AIR2", 1, "RICH", 66.3 + 1.2505, 1.276-fpParam->GapThickness()/2-fpParam->QuartzThickness()-fpParam->FreonThickness()- .4 - .6 - .05 - .376 -.5 - 3.35, 0., 0, "ONLY");
1250   gMC->Gspos("AIR2", 2, "RICH", -66.3 - 1.2505,1.276-fpParam->GapThickness()/2-fpParam->QuartzThickness()-fpParam->FreonThickness()- .4 - .6 - .05 - .376 -.5 - 3.35, 0., 0, "ONLY");
1251   gMC->Gspos("AIR3", 1, "RICH", 0., 1.276-fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()- .4 - .6 - .05 - .376 -.5 - 3.35, -68.35 - 1.25, 0, "ONLY");
1252   gMC->Gspos("AIR3", 2, "RICH", 0., 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()- .4 - .6 - .05 - .376 -.5 - 3.35,  68.35 + 1.25, 0, "ONLY");
1253   gMC->Gspos("ALUM", 1, "SRIC", 0., 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()- .4 - .6 - .05 - .376 -.025, 0., 0, "ONLY");
1254   gMC->Gspos("HONE", 1, "SRIC", 0., 1.276- fpParam->GapThickness()/2  - fpParam->QuartzThickness() - fpParam->FreonThickness()- .4 - .6 - .05 - .188, 0., 0, "ONLY");
1255   gMC->Gspos("ALUM", 2, "SRIC", 0., 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()- .4 - .6 - .025, 0., 0, "ONLY");
1256   gMC->Gspos("FOOT", 1, "SRIC", 64.95, 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()- .4 - .3, 36.9, 0, "ONLY");
1257   gMC->Gspos("FOOT", 2, "SRIC", 21.65, 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()- .4 - .3 , 36.9, 0, "ONLY");
1258   gMC->Gspos("FOOT", 3, "SRIC", -21.65, 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()- .4 - .3, 36.9, 0, "ONLY");
1259   gMC->Gspos("FOOT", 4, "SRIC", -64.95, 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()- .4 - .3, 36.9, 0, "ONLY");
1260   gMC->Gspos("FOOT", 5, "SRIC", 64.95, 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()- .4 - .3, -36.9, 0, "ONLY");
1261   gMC->Gspos("FOOT", 6, "SRIC", 21.65, 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()- .4 - .3, -36.9, 0, "ONLY");
1262   gMC->Gspos("FOOT", 7, "SRIC", -21.65, 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()- .4 - .3, -36.9, 0, "ONLY");
1263   gMC->Gspos("FOOT", 8, "SRIC", -64.95, 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()- .4 - .3, -36.9, 0, "ONLY");
1264   gMC->Gspos("OQUA", 1, "SRIC", 0., 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()- .2, 0., 0, "ONLY");
1265 // Methane supports
1266   gMC->Gspos("SMLG", 1, "SRIC", csi_width/2 + (66.3 - csi_width/2)/2, 1.276 + .25, 0., 0, "ONLY");
1267   gMC->Gspos("SMLG", 2, "SRIC", - csi_width/2 - (66.3 - csi_width/2)/2, 1.276 + .25, 0., 0, "ONLY");
1268   gMC->Gspos("SMSH", 1, "SRIC", 0., 1.276 + .25, csi_length/2 + (68.35 - csi_length/2)/2, 0, "ONLY");
1269   gMC->Gspos("SMSH", 2, "SRIC", 0., 1.276 + .25, - csi_length/2 - (68.35 - csi_length/2)/2, 0, "ONLY");
1270 //Freon supports
1271   Float_t supp_y = 1.276 - fpParam->GapThickness()/2- fpParam->QuartzThickness() -fpParam->FreonThickness() - .2 + .3; //y position of freon supports
1272   gMC->Gspos("SFLG", 1, "SRIC", fpParam->QuartzWidth()/2 + (66.3 - fpParam->QuartzWidth()/2)/2, supp_y, 0., 0, "ONLY");
1273   gMC->Gspos("SFLG", 2, "SRIC", - fpParam->QuartzWidth()/2 - (66.3 - fpParam->QuartzWidth()/2)/2, supp_y, 0., 0, "ONLY");
1274   gMC->Gspos("SFSH", 1, "SRIC", 0., supp_y, fpParam->QuartzLength()/2 + (68.35 - fpParam->QuartzLength()/2)/2, 0, "ONLY");
1275   gMC->Gspos("SFSH", 2, "SRIC", 0., supp_y, - fpParam->QuartzLength()/2 - (68.35 - fpParam->QuartzLength()/2)/2, 0, "ONLY");
1276   AliMatrix(idrotm[1019], 0., 0., 90., 0., 90., 90.);
1277 //Place spacers
1278   Int_t nspacers = 30;
1279   for (i = 0; i < nspacers/3; i++) {
1280     zs = -11.6/2 + (TMath::Abs(nspacers/6) - i) * 12.2;
1281     gMC->Gspos("SPAC", i, "FRE1", 10.5, 0., zs, idrotm[1019], "ONLY");  //Original settings 
1282   }
1283   for (i = nspacers/3; i < (nspacers*2)/3; i++) {
1284     zs = -11.6/2 + (nspacers/3 + TMath::Abs(nspacers/6) - i) * 12.2;
1285     gMC->Gspos("SPAC", i, "FRE1", 0, 0., zs, idrotm[1019], "ONLY");  //Original settings 
1286   }
1287   for (i = (nspacers*2)/3; i < nspacers; ++i) {
1288     zs = -11.6/2 + ((nspacers*2)/3 + TMath::Abs(nspacers/6) - i) * 12.2;
1289     gMC->Gspos("SPAC", i, "FRE1", -10.5, 0., zs, idrotm[1019], "ONLY"); //Original settings  
1290   }
1291   for (i = 0; i < nspacers/3; i++) {
1292     zs = -11.6/2 + (TMath::Abs(nspacers/6) - i) * 12.2;
1293     gMC->Gspos("SPAC", i, "FRE2", 10.5, 0., zs, idrotm[1019], "ONLY");  //Original settings 
1294   }
1295   for (i = nspacers/3; i < (nspacers*2)/3; i++) {
1296     zs = -11.6/2 + (nspacers/3 + TMath::Abs(nspacers/6) - i) * 12.2;
1297     gMC->Gspos("SPAC", i, "FRE2", 0, 0., zs, idrotm[1019], "ONLY");  //Original settings 
1298   }
1299   for (i = (nspacers*2)/3; i < nspacers; ++i) {
1300     zs = -11.6/2 + ((nspacers*2)/3 + TMath::Abs(nspacers/6) - i) * 12.2;
1301     gMC->Gspos("SPAC", i, "FRE2", -10.5, 0., zs, idrotm[1019], "ONLY"); //Original settings  
1302   }
1303   gMC->Gspos("FRE1", 1, "OQF1", 0., 0., 0., 0, "ONLY");
1304   gMC->Gspos("FRE2", 1, "OQF2", 0., 0., 0., 0, "ONLY");
1305   gMC->Gspos("OQF1", 1, "SRIC", fpParam->OuterFreonWidth()/2 + fpParam->InnerFreonWidth()/2 + 2, 1.276 - fpParam->GapThickness()/2- fpParam->QuartzThickness() -fpParam->FreonThickness()/2, 0., 0, "ONLY"); //Original settings (31.3)
1306   gMC->Gspos("OQF2", 2, "SRIC", 0., 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()/2, 0., 0, "ONLY");          //Original settings 
1307   gMC->Gspos("OQF1", 3, "SRIC", - (fpParam->OuterFreonWidth()/2 + fpParam->InnerFreonWidth()/2) - 2, 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness() - fpParam->FreonThickness()/2, 0., 0, "ONLY");       //Original settings (-31.3)
1308   gMC->Gspos("QUAR", 1, "SRIC", 0., 1.276 - fpParam->GapThickness()/2 - fpParam->QuartzThickness()/2, 0., 0, "ONLY");
1309   gMC->Gspos("GAP ", 1, "META", 0., fpParam->GapThickness()/2 - fpParam->ProximityGapThickness()/2 - 0.0001, 0., 0, "ONLY");
1310   gMC->Gspos("META", 1, "SRIC", 0., 1.276, 0., 0, "ONLY");
1311   gMC->Gspos("CSI ", 1, "SRIC", 0., 1.276 + fpParam->GapThickness()/2 + .25, 0., 0, "ONLY");
1312 //Wire support placing
1313   gMC->Gspos("WSG2", 1, "GAP ", 0., fpParam->ProximityGapThickness()/2 - .1, 0., 0, "ONLY");
1314   gMC->Gspos("WSG1", 1, "CSI ", 0., 0., 0., 0, "ONLY");
1315   gMC->Gspos("WSMe", 1, "SRIC ", 0., 1.276 + fpParam->GapThickness()/2 + .5 + 1.05, 0., 0, "ONLY");
1316 //Backplane placing
1317   gMC->Gspos("BACK", 1, "SRIC ", -33.15, 1.276 + fpParam->GapThickness()/2 + .5 + 2.1 + 2, 43.3, 0, "ONLY");
1318   gMC->Gspos("BACK", 2, "SRIC ", 33.15, 1.276 + fpParam->GapThickness()/2 + .5 + 2.1 + 2 , 43.3, 0, "ONLY");
1319   gMC->Gspos("BACK", 3, "SRIC ", -33.15, 1.276 + fpParam->GapThickness()/2 + .5 + 2.1 + 2, 0., 0, "ONLY");
1320   gMC->Gspos("BACK", 4, "SRIC ", 33.15, 1.276 + fpParam->GapThickness()/2 + .5 + 2.1 + 2, 0., 0, "ONLY");
1321   gMC->Gspos("BACK", 5, "SRIC ", 33.15, 1.276 + fpParam->GapThickness()/2 + .5 + 2.1 + 2, -43.3, 0, "ONLY");
1322   gMC->Gspos("BACK", 6, "SRIC ", -33.15, 1.276 + fpParam->GapThickness()/2 + .5 + 2.1 + 2, -43.3, 0, "ONLY");
1323 //PCB placing
1324   gMC->Gspos("PCB ", 1, "SRIC ", 0.,  1.276 + fpParam->GapThickness()/2 + .5 + 1.05, csi_width/4 + .5025 + 2.5, 0, "ONLY");
1325   gMC->Gspos("PCB ", 2, "SRIC ", 0.,  1.276 + fpParam->GapThickness()/2 + .5 + 1.05, -csi_width/4 - .5025 - 2.5, 0, "ONLY");
1326
1327 //place chambers into mother volume ALIC
1328   for(int i=1;i<=kNCH;i++){
1329     AliMatrix(idrotm[1000+i],C(i)->ThetaXd(),C(i)->PhiXd(),
1330                              C(i)->ThetaYd(),C(i)->PhiYd(),
1331                              C(i)->ThetaZd(),C(i)->PhiZd());
1332     gMC->Gspos("RICH",i,"ALIC",C(i)->X(),C(i)->Y(),C(i)->Z(),idrotm[1000+i], "ONLY");
1333   }
1334
1335   if(GetDebug())Info("CreateGeometry","Stop.");  
1336 }//void AliRICH::CreateGeometry()
1337 //______________________________________________________________________________
1338 void AliRICH::CreateChambers()
1339 {//(re)create all RICH Chambers
1340   if(GetDebug())Info("CreateChambers","Start.");
1341
1342   if(fChambers) delete fChambers;//recreate chambers
1343   fChambers=new TObjArray(kNCH);
1344   fChambers->SetOwner();
1345   for(int i=0;i<kNCH;i++){
1346     fChambers->AddAt(new AliRICHChamber(i+1,fpParam),i);
1347   }
1348
1349   if(GetDebug())Info("CreateChambers","Stop.");
1350 }//void AliRICH::CreateChambers()
1351 //__________________________________________________________________________________________________
1352 void AliRICH::GenerateFeedbacks(Float_t eloss)
1353 {// Generate FeedBack photons
1354   Int_t j;
1355   Float_t cthf, phif, enfp = 0, sthf;
1356   Float_t e1[3], e2[3], e3[3];
1357   Float_t vmod, uswop;
1358   Float_t dir[3], phi;
1359   Float_t pol[3], mom[4];
1360 //Determine number of feedback photons
1361   TLorentzVector x4;
1362   gMC->TrackPosition(x4);//This sould return the current track position
1363   Float_t charge=Param()->TotalCharge(gMC->TrackPid(),eloss,5*cm);//??? Totsl Charge
1364   Int_t iNphotons=gMC->GetRandom()->Poisson(Param()->AlphaFeedback()*charge);    
1365   Info("GenerateFeedbacks","N photons=%i",iNphotons);
1366 //Generate photons
1367   for(Int_t i=0;i<iNphotons;i++){
1368     Double_t ranf[2];
1369     gMC->GetRandom()->RndmArray(2,ranf);    //Sample direction
1370     cthf=ranf[0]*2-1.0;
1371     if(cthf<0) continue;
1372     sthf = TMath::Sqrt((1 - cthf) * (1 + cthf));
1373     phif = ranf[1] * 2 * TMath::Pi();
1374     
1375     if(Double_t randomNumber=gMC->GetRandom()->Rndm()<=0.57)
1376       enfp = 7.5e-9;
1377     else if(randomNumber<=0.7)
1378       enfp = 6.4e-9;
1379     else
1380       enfp = 7.9e-9;
1381     
1382
1383     dir[0] = sthf * TMath::Sin(phif);    dir[1] = cthf;    dir[2] = sthf * TMath::Cos(phif);
1384     gMC->Gdtom(dir, mom, 2);
1385     mom[0]*=enfp;    mom[1]*=enfp;    mom[2]*=enfp;
1386     mom[3] = TMath::Sqrt(mom[0]*mom[0]+mom[1]*mom[1]+mom[2]*mom[2]);
1387     
1388     // Polarisation
1389     e1[0]=      0;    e1[1]=-dir[2];    e1[2]= dir[1];
1390     e2[0]=-dir[1];    e2[1]= dir[0];    e2[2]=      0;
1391     e3[0]= dir[1];    e3[1]=      0;    e3[2]=-dir[0];
1392     
1393     vmod=0;
1394     for(j=0;j<3;j++) vmod+=e1[j]*e1[j];
1395     if (!vmod) for(j=0;j<3;j++) {
1396       uswop=e1[j];
1397       e1[j]=e3[j];
1398       e3[j]=uswop;
1399     }
1400     vmod=0;
1401     for(j=0;j<3;j++) vmod+=e2[j]*e2[j];
1402     if (!vmod) for(j=0;j<3;j++) {
1403       uswop=e2[j];
1404       e2[j]=e3[j];
1405       e3[j]=uswop;
1406     }
1407     
1408     vmod=0;
1409     for(j=0;j<3;j++) vmod+=e1[j]*e1[j];
1410     vmod=TMath::Sqrt(1/vmod);
1411     for(j=0;j<3;j++) e1[j]*=vmod;
1412     
1413     vmod=0;
1414     for(j=0;j<3;j++) vmod+=e2[j]*e2[j];
1415     vmod=TMath::Sqrt(1/vmod);
1416     for(j=0;j<3;j++) e2[j]*=vmod;
1417     
1418     phi = gMC->GetRandom()->Rndm()* 2 * TMath::Pi();
1419     for(j=0;j<3;j++) pol[j]=e1[j]*TMath::Sin(phi)+e2[j]*TMath::Cos(phi);
1420     gMC->Gdtom(pol, pol, 2);
1421     Int_t outputNtracksStored;    
1422     gAlice->PushTrack(1,                             //do not transport
1423                      gAlice->GetCurrentTrackNumber(),//parent track 
1424                      kFeedback,                      //PID
1425                      mom[0],mom[1],mom[2],mom[3],    //track momentum  
1426                      x4.X(),x4.Y(),x4.Z(),x4.T(),    //track origin 
1427                      pol[0],pol[1],pol[2],           //polarization
1428                      kPFeedBackPhoton,outputNtracksStored,1.0);
1429     
1430   }
1431 }//Int_t AliRICH::FeedBackPhotons()
1432 //__________________________________________________________________________________________________
1433 static Int_t sMaxIterPad=0;    // Static variables for the pad-hit iterator routines
1434 static Int_t sCurIterPad=0;
1435
1436 //__________________________________________________________________________________________________
1437 AliRICHSDigit* AliRICH::FirstPad(AliRICHhit*  hit,TClonesArray *clusters ) 
1438 {// Initialise the pad iterator Return the address of the first sdigit for hit
1439     TClonesArray *theClusters = clusters;
1440     Int_t nclust = theClusters->GetEntriesFast();
1441     if (nclust && hit->PHlast() > 0) {
1442         sMaxIterPad=Int_t(hit->PHlast());
1443         sCurIterPad=Int_t(hit->PHfirst());
1444         return (AliRICHSDigit*) clusters->UncheckedAt(sCurIterPad-1);
1445     } else {
1446         return 0;
1447     }
1448     
1449 }
1450 //__________________________________________________________________________________________________
1451 AliRICHSDigit* AliRICH::NextPad(TClonesArray *clusters) 
1452 {// Iterates over pads
1453   
1454     sCurIterPad++;
1455     if (sCurIterPad <= sMaxIterPad) {
1456         return (AliRICHSDigit*) clusters->UncheckedAt(sCurIterPad-1);
1457     } else {
1458         return 0;
1459     }
1460 }
1461 //__________________________________________________________________________________________________