]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RICH/AliRICHParam.cxx
e9f2a2cb9576a4f759fc6f29f300b839b6c52874
[u/mrichter/AliRoot.git] / RICH / AliRICHParam.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 #include "AliRICHParam.h" //class header
16 #include "AliESD.h"
17 #include <TCanvas.h>      //TestXXX() 
18 #include <TLatex.h>
19 #include <THStack.h>
20 #include <TLegend.h>
21 #include <TView.h>
22 #include <TPolyMarker3D.h>
23 #include <TPolyLine3D.h>
24 #include <TPolyLine.h>
25 #include <TSystem.h>
26 #include <TVector2.h>
27 #include <TVector3.h>
28 #include <TRotation.h>
29 #include <AliCDBManager.h> //CdbRead()
30 #include <AliCDBStorage.h> //CdbRead()
31 #include <AliCDBEntry.h>   //CdbRead()
32 #include <AliRunLoader.h>  //Stack()
33 #include <AliStack.h>      //Stack()
34 #include <TParticle.h>     //Stack()    
35 #include "AliRICHHelix.h"  //TestTrans()
36
37 ClassImp(AliRICHParam)
38 AliRICHParam * AliRICHParam::fgInstance             =0x0;     //singleton pointer               
39 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
40 AliRICHParam::AliRICHParam():TNamed("RichParam","default version") 
41 {
42 // Here all the intitializition is taken place when AliRICHParam::Instance() is invoked for the first time.
43 // In particulare, matrices to be used for LORS<->MARS trasnformations are initialized from TGeo structure.    
44 // Note that TGeoManager should be already initialized from geometry.root file  
45   for(Int_t iCh=0;iCh<kNchambers;iCh++) fMatrix[iCh]=(TGeoHMatrix*)gGeoManager->GetVolume("ALIC")->GetNode(Form("RICH_%i",iCh+1))->GetMatrix();
46   CdbRead(0,0);
47   fgInstance=this; 
48 }//ctor
49 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
50 Float_t AliRICHParam::AbsCH4(Float_t eV)
51 {
52 // Evaluate the absorbtion lenght of CH4 for a photon of energy eV in electron-volts
53   const Float_t kLoschmidt=2.686763e19;                                      // LOSCHMIDT NUMBER IN CM-3
54   const Float_t kPressure=750.0;          //mm of Hg
55   const Float_t kTemperature=283.0;       //K (10 grad C)                               
56   const Float_t kPn=kPressure/760.;
57   const Float_t kTn=kTemperature/273.16;
58   const Float_t kC0=-1.655279e-1;
59   const Float_t kC1= 6.307392e-2;
60   const Float_t kC2=-8.011441e-3;
61   const Float_t kC3= 3.392126e-4;
62                 
63   Float_t crossSection=0;                        
64   if (eV<7.75) 
65     crossSection=0.06e-22;
66   else                 //------ METHANE CROSS SECTION cm-2 ASTROPH. J. 214, L47 (1978)                                               
67     crossSection=(kC0+kC1*eV+kC2*eV*eV+kC3*eV*eV*eV)*1.e-18;
68     
69     Float_t density=kLoschmidt*kPn/kTn; //CH4 molecular concentration (cm^-3)
70     return 1.0/(density*crossSection);
71 }//AbsoCH4()
72 //__________________________________________________________________________________________________sss
73 void AliRICHParam::CdbRead(Int_t run,Int_t version)
74 {
75 // This methode read all the calibration information and initialise corresponding fields for requested run number
76 // Arguments: run - run number for which to retrieve calibration
77 //            version- version number   
78 //   Returns: none      
79
80   AliCDBEntry *pEntry=AliCDBManager::Instance()->Get("RICH/RICHConfig/RefIdxC6F14",run,0,version); //try to get from common local storage  
81   if(pEntry){
82     fIdxC6F14=(TF2*)pEntry->GetObject(); 
83     if(!(AliCDBManager::Instance()->GetCacheFlag())) delete pEntry;
84   }else{
85     AliWarning("No valid calibarion, the hardcoded will be used!");
86     fIdxC6F14=new TF2("RidxC4F14","sqrt(1+0.554*(1239.84e-9/x)^2/((1239.84e-9/x)^2-5796)-0.0005*(y-20))",5.5e-9,8.5e-9,0,50); //DiMauro mail
87     fIdxC6F14->SetUniqueID(20);//T=20 deg C
88   }
89 }//CdbRead()
90 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
91 void AliRICHParam::Print(Option_t* opt) const
92 {
93 // print some usefull (hopefully) info on some internal guts of RICH parametrisation 
94   Printf("Pads in chamber (%3i,%3i) in sector (%2i,%2i) pad size (%4.2f,%4.2f)",NpadsX(),NpadsY(),NpadsXsec(),NpadsYsec(),PadSizeX(),PadSizeY());
95   
96   for(Int_t i=0;i<kNchambers;i++) fMatrix[i]->Print(opt);
97 }//Print()
98 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
99 void AliRICHParam::TestSeg()
100 {
101 // Provides a set of pictures to test segementation currently in use.    
102 // Arguments: none
103 //   Returns: none    
104   new TCanvas("pads","PC segmentation - pads display",700,600);
105   gPad->Range(-5,-5,PcSizeX()+5,PcSizeY()+15);
106   TVector p(2);   TVector2 c;    TVector2 b;   //current: pad, pad center, pad boundary
107 // list of corners:
108   Double_t x0=0,x1=SecSizeX(),x2=SecSizeX()+DeadZone()                                                      ,x3=PcSizeX();  
109   Double_t y0=0,y1=SecSizeY(),y2=SecSizeY()+DeadZone(),y3=2*SecSizeY()+DeadZone(),y4=PcSizeY()-SecSizeY(),y5=PcSizeY();  
110   DrawSectors();
111 //header 
112   TLatex t;
113   t.SetTextSize(0.02); t.SetTextColor(kBlack); t.SetTextAlign(11);
114   t.DrawLatex(0,PcSizeY()+10,Form("IP in front of this page. pad size %.2fx%.2fcm   dead zone %.2fcm",PadSizeX(),PadSizeY(),DeadZone()));
115   t.DrawLatex(0,PcSizeY()+ 5,Form("Pc  %.2fx%.2f cm %ix%i pads               Sec %.2fx%.2f cm %ix%i pads",
116                                          PcSizeX()     , PcSizeY()     , NpadsX()    , NpadsY()                                 ,
117                                          SecSizeX() , SecSizeY() , NpadsXsec() , NpadsYsec()                              ));
118 //sectors  
119   t.SetTextSize(0.015); t.SetTextColor(kRed); t.SetTextAlign(22);
120   c=Pad2Loc( 40, 24); t.DrawText(c.X(),c.Y(),Form("sec 1 (%.2f,%.2f)",c.X(),c.Y()  ));  
121   c=Pad2Loc( 40, 75); t.DrawText(c.X(),c.Y(),Form("sec 3 (%.2f,%.2f)",c.X(),c.Y()  ));  
122   c=Pad2Loc( 40,121); t.DrawText(c.X(),c.Y(),Form("sec 5 (%.2f,%.2f)",c.X(),c.Y()  ));  
123   c=Pad2Loc(120, 24); t.DrawText(c.X(),c.Y(),Form("sec 2 (%.2f,%.2f)",c.X(),c.Y()  ));  
124   c=Pad2Loc(120, 75); t.DrawText(c.X(),c.Y(),Form("sec 4 (%.2f,%.2f)",c.X(),c.Y()  ));  
125   c=Pad2Loc(120,121); t.DrawText(c.X(),c.Y(),Form("sec 6 (%.2f,%.2f)",c.X(),c.Y()  ));  
126 //coners  
127   t.SetTextSize(0.015); t.SetTextColor(kBlue);
128
129   b.Set(x0,y0);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(11);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
130   b.Set(x0,y1);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(13);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
131   b.Set(x0,y2);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(11);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
132   b.Set(x0,y3);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(13);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
133   b.Set(x0,y4);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(11);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
134   b.Set(x0,y5);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(13);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
135   
136   b.Set(x1,y0);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(31);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
137   b.Set(x1,y1);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(33);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
138   b.Set(x1,y2);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(31);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
139   b.Set(x1,y3);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(33);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
140   b.Set(x1,y4);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(31);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
141   b.Set(x1,y5);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(33);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
142   
143   b.Set(x2,y0);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(11);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
144   b.Set(x2,y1);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(13);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
145   b.Set(x2,y2);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(11);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
146   b.Set(x2,y3);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(13);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
147   b.Set(x2,y4);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(11);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
148   b.Set(x2,y5);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(13);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
149   
150   b.Set(x3,y0);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(31);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
151   b.Set(x3,y1);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(33);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
152   b.Set(x3,y2);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(31);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
153   b.Set(x3,y3);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(33);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
154   b.Set(x3,y4);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(31);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
155   b.Set(x3,y5);p=Loc2Pad(b);c=Pad2Loc(p);t.SetTextAlign(33);t.DrawText(c.X(),c.Y(),Form("(%.2f,%.2f)-(%.0f,%.0f)-(%.2f,%.2f)",b.X(),b.Y(),p(0),p(1),c.X(),c.Y()));
156 }//TestSeg()
157 //__________________________________________________________________________________________________
158 void AliRICHParam::TestResp()
159 {
160 // Provides a set of plot to check the response parametrisation currently in use.  
161 // Arguments: none
162 //   Returns: none    
163   TCanvas *pC=new TCanvas("c","Amplification test",900,800);
164   pC->Divide(1,2);
165   
166   
167   const Int_t kNpoints=8;
168   THStack *pStackPhot=new THStack("StackPhot","photons");
169   THStack *pStackMip =new THStack("StackMip","mips");
170   TLegend *pLeg=new TLegend(0.6,0.2,0.9,0.5,"legend");    
171   TH1F *apHphot[kNpoints];
172   TH1F *apHmip[kNpoints];
173   
174   Double_t starty=0;
175   Double_t deltay=AliRICHParam::SecSizeY()/kNpoints;
176   
177   for(int i=0;i<kNpoints;i++){
178     apHphot[i]=new TH1F(Form("hphot%i",i),"Qdc for Photon;QDC;Counts",500,0,500); apHphot[i]->SetLineColor(i);pStackPhot->Add(apHphot[i]);                 
179     apHmip[i] =new TH1F(Form("hmip%i",i),"Qdc for Mip;QDC;Counts",4000,0,4000);   apHmip[i]->SetLineColor(i);pStackMip->Add(apHmip[i]);                 
180     
181     pLeg->AddEntry(apHphot[i],Form("@(10,%5.2f->%5.2f)",starty+i*deltay,starty+i*deltay-SecSizeY()/2));
182   }
183         
184   
185   TVector2 x2(0,0);  
186   for(Int_t i=0;i<10000;i++){//events loop
187     for(int j=0;j<kNpoints;j++){
188       x2.Set(10,starty+j*deltay);
189       apHphot[j]->Fill(TotQdc(x2,0));
190       apHmip[j]->Fill(TotQdc(x2,gRandom->Landau(600,150)*1e-9));
191     }
192   }
193   
194   pC->cd(1);  pStackMip->Draw("nostack");
195   pC->cd(2);  pStackPhot->Draw("nostack"); pLeg->Draw();
196 }//TestResp()
197 //__________________________________________________________________________________________________
198 void AliRICHParam::TestTrans()
199 {
200 // Tests transformation methods
201 // Arguments: none
202 //   Returns: none    
203   
204   AliRICHParam *pParam=AliRICHParam::Instance();
205   Int_t iNpointsX=50,iNpointsY=50;  
206   new TCanvas("trasform","Test LORS-MARS transform"); TLatex t; t.SetTextSize(0.02);
207   
208   TView *pView=new TView(1);  pView->SetRange(-400,-400,-400,400,400,400);
209   DrawAxis();  
210   for(Int_t iCham=1;iCham<=7;iCham++){//chamber loop
211     AliRICHHelix helix(2.5,Norm(iCham).Theta()*TMath::RadToDeg(),Norm(iCham).Phi()*TMath::RadToDeg());
212     helix.RichIntersect(AliRICHParam::Instance());
213     TPolyMarker3D *pChamber=new TPolyMarker3D(iNpointsX*iNpointsY);
214     Int_t i=0;
215     for(Double_t x=0;x<PcSizeX();x+=PcSizeX()/iNpointsX)
216       for(Double_t y=0;y<PcSizeY();y+=PcSizeY()/iNpointsY){//step loop
217         TVector3 v3=pParam->Lors2Mars(iCham,x,y,kPc); TVector2 v2=pParam->Mars2Lors(iCham,v3,kPc);//LORS->MARS->LORS
218         Double_t dx=v2.X()-x , dy=v2.Y()-y; 
219         if(dx>0.000001 || dy>0.000001) Printf("Problem in MARS<->LORS transformations dx=%f dy=%f!!!",dx,dy);
220         pChamber->SetPoint(i++,v3.X(),v3.Y(),v3.Z());//Pc plane point in MARS
221       }//step loop
222     pChamber->SetMarkerSize(1);
223     pChamber->SetMarkerColor(iCham);
224     pChamber->Draw();  
225     helix.Draw();
226     t.SetNDC();t.SetTextColor(iCham); t.DrawText(0.1,iCham*0.1,Form("Chamber %i",iCham));    
227   }//chambers loop   
228 }//TestTrans()
229 //__________________________________________________________________________________________________
230 void AliRICHParam::DrawAxis()
231 {
232 // This utility methode draws axis on geometry scene  
233 // Arguments: none
234 //   Returns: none    
235   Double_t x[6]={0,0,0,300,0,0};  Double_t y[6]={0,0,0,0,300,0};  Double_t z[6]={0,0,0,0,0,300};  
236   TPolyLine3D *pXaxis=new TPolyLine3D(2,x);pXaxis->SetLineColor(kRed);   pXaxis->Draw();
237   TPolyLine3D *pYaxis=new TPolyLine3D(2,y);pYaxis->SetLineColor(kGreen); pYaxis->Draw();
238   TPolyLine3D *pZaxis=new TPolyLine3D(2,z);pZaxis->SetLineColor(kBlue);  pZaxis->Draw();  
239 }
240 //__________________________________________________________________________________________________
241 void AliRICHParam::DrawSectors() 
242
243 // Utility methode draws RICH chamber sectors on event display.
244 // Arguments: none
245 //   Returns: none      
246   Double_t xLeft[5]  = {0,0,SecSizeX(),SecSizeX(),0};
247   Double_t xRight[5] = {SecSizeX()+DeadZone(),SecSizeX()+DeadZone(),PcSizeX(),PcSizeX(),SecSizeX()+DeadZone()};
248   
249   Double_t yDown[5]   = {0,SecSizeY(),SecSizeY(),0,0};
250   Double_t yCenter[5] = {  SecSizeY()+DeadZone(),2*SecSizeY()+DeadZone(),2*SecSizeY()+DeadZone(),
251                            SecSizeY()+DeadZone(),SecSizeY()+DeadZone()};  
252   Double_t yUp[5]     = {2*SecSizeY()+2*DeadZone(),PcSizeY(),PcSizeY(),2*SecSizeY()+2*DeadZone(),2*SecSizeY()+2*DeadZone()};
253   
254   TPolyLine *sec1 = new TPolyLine(5,xLeft ,yDown);    sec1->SetLineColor(21);  sec1->Draw();
255   TPolyLine *sec2 = new TPolyLine(5,xRight,yDown);    sec2->SetLineColor(21);  sec2->Draw();
256   TPolyLine *sec3 = new TPolyLine(5,xLeft ,yCenter);  sec3->SetLineColor(21);  sec3->Draw();
257   TPolyLine *sec4 = new TPolyLine(5,xRight,yCenter);  sec4->SetLineColor(21);  sec4->Draw();
258   TPolyLine *sec5 = new TPolyLine(5,xLeft, yUp);      sec5->SetLineColor(21);  sec5->Draw();
259   TPolyLine *sec6 = new TPolyLine(5,xRight,yUp);      sec6->SetLineColor(21);  sec6->Draw();
260 }//DrawSectors()
261 //__________________________________________________________________________________________________
262 TVector3 AliRICHParam::ForwardTracing(TVector3 entranceTrackPoint, TVector3 vectorTrack, Double_t thetaC, Double_t phiC)
263 {
264 // Trace a single Ckov photon from a given emission point up to photocathode taking into account ref indexes of materials it travereses
265   TVector3 vBad(-999,-999,-999);
266   TVector3 nPlane(0,0,1);
267   Double_t planeZposition = 0.5*RadThick();
268   TVector3 planePoint(0,0,0.5*RadThick()); //this is plane parallel to window which contains emission point 
269   TVector3 emissionPoint = PlaneIntersect(vectorTrack,entranceTrackPoint,nPlane,planePoint);
270   Double_t thetaout,phiout;
271   AnglesInDRS(vectorTrack.Theta(),vectorTrack.Phi(),thetaC,phiC,thetaout,phiout);
272   TVector3 vectorPhotonInC6F14;  
273   vectorPhotonInC6F14.SetMagThetaPhi(1,thetaout,phiout);
274   planeZposition=RadThick();
275   planePoint.SetXYZ(0,0,planeZposition);
276   TVector3 entranceToSiO2Point = PlaneIntersect(vectorPhotonInC6F14,emissionPoint,nPlane,planePoint);
277
278   Double_t photonEn = EckovMean();
279   Double_t angleInSiO2 = SnellAngle(IdxC6F14(EckovMean()),IdxSiO2(EckovMean()),vectorPhotonInC6F14.Theta());if(angleInSiO2<0) return vBad;
280   TVector3 vectorPhotonInSiO2;
281   vectorPhotonInSiO2.SetMagThetaPhi(1,angleInSiO2,phiout);
282 //  planeZposition+=AliRICHParam::SiO2Thickness();
283   planeZposition+=WinThick();
284   planePoint.SetXYZ(0,0,planeZposition);
285   TVector3 entranceToCH4 = PlaneIntersect(vectorPhotonInSiO2,entranceToSiO2Point,nPlane,planePoint);
286 //  entranceToCH4.Dump();
287
288   //  Double_t angleInCH4 = SnellAngle(AliRICHParam::IndOfRefSiO2(6.755),AliRICHParam::IndOfRefCH4,angleInSiO2);
289   Double_t angleInCH4 = SnellAngle(IdxSiO2(photonEn),IdxCH4(photonEn),vectorPhotonInSiO2.Theta());if(angleInCH4<0) return vBad;
290   TVector3 vectorPhotonInCH4;
291   vectorPhotonInCH4.SetMagThetaPhi(1,angleInCH4,phiout);
292 //  planeZposition+=AliRICHParam::GapProx();
293   planeZposition+=Pc2Win();
294   planePoint.SetXYZ(0,0,planeZposition);
295   TVector3 impactToPC = PlaneIntersect(vectorPhotonInCH4,entranceToCH4,nPlane,planePoint);
296 //  impactToPC.Dump();
297   return impactToPC;
298 }//FowardTracing
299 //__________________________________________________________________________________________________
300 TVector3 AliRICHParam::PlaneIntersect(const TVector3 &lineDir,const TVector3 &linePoint,const TVector3 &planeNorm,const TVector3 &planePoint)
301 {
302 // Finds an intersection point between a line and plane.
303 // Arguments:  lineDir,linePoint    - vector along the line and any point of the line
304 //             planeNorm,planePoint - vector normal to the plane and any point of the plane
305 //   Returns:  point of intersection if any
306   if(planeNorm*lineDir==0) return   TVector3(-999,-999,-999);
307   TVector3 diff=planePoint-linePoint;
308   Double_t sint=(planeNorm*diff)/(planeNorm*lineDir);
309   return linePoint+sint*lineDir;
310 }//PlaneIntersect
311 //__________________________________________________________________________________________________ 
312 Double_t AliRICHParam::SnellAngle(Float_t n1, Float_t n2, Float_t theta1)
313 {
314 // Compute the angle of refraction out of Snell law
315 // Arguments: n1 - ref idx of first substance  
316 //            n2 - ref idx of second substance  
317 //            n1 - photon impact angle in the first substance i.e. angle between the photon direction and vector normal to the surface (radians)
318 //   Returns: photon refraction angle, i.e. angle in the second substance (radians)
319   Double_t sinref=(n1/n2)*TMath::Sin(theta1);
320   if(sinref>1.)    return -999;  
321   else             return TMath::ASin(sinref);
322 }//SnellAngle
323 //__________________________________________________________________________________________________
324 void AliRICHParam::AnglesInDRS(Double_t trackTheta,Double_t trackPhi,Double_t thetaCerenkov,Double_t phiCerenkov,Double_t &tout,Double_t &pout)
325 {
326 // Setup the rotation matrix of the track...
327
328   TRotation mtheta;
329   TRotation mphi;
330   TRotation minv;
331   TRotation mrot;
332   
333   mtheta.RotateY(trackTheta);
334   mphi.RotateZ(trackPhi);
335   
336   mrot = mphi * mtheta;
337     //  minv = mrot.Inverse();
338
339   TVector3 photonInRadiator(1,1,1);
340
341   photonInRadiator.SetTheta(thetaCerenkov);
342   photonInRadiator.SetPhi(phiCerenkov);
343   photonInRadiator = mrot * photonInRadiator;
344   tout=photonInRadiator.Theta();
345   pout=photonInRadiator.Phi();
346 }//AnglesInDRS
347 /*
348 void DrawRing()
349 {
350
351   //  Float_t xGraph[1000],yGraph[1000];
352
353   Float_t type;
354   Float_t MassOfParticle;
355   Float_t beta;
356   Float_t nfreon;
357
358   Float_t ThetaCerenkov;
359
360   Float_t Xtoentr = GetEntranceX();
361   Float_t Ytoentr = GetEntranceY();
362
363   Float_t pmod = GetTrackMomentum();
364   Float_t TrackTheta = GetTrackTheta();
365   Float_t TrackPhi = GetTrackPhi();
366
367   SetPhotonEnergy(AliRICHParam::MeanCkovEnergy());
368   SetFreonRefractiveIndex();
369
370   SetEmissionPoint(RadiatorWidth/2.);
371
372   ThetaCerenkov = GetThetaCerenkov();
373   FindBetaFromTheta(ThetaCerenkov);
374   nfreon = GetFreonRefractiveIndex();
375   
376   Int_t nPoints = 100;
377
378   Int_t nPointsToDraw = 0;
379   for(Int_t i=0;i<nPoints;i++)
380     {
381       Float_t phpad = 2*TMath::Pi()*i/nPoints;
382       SetThetaPhotonInTRS(thetacer);
383       SetPhiPhotonInTRS(phpad);
384       FindPhotonAnglesInDRS();
385       Float_t Radius = FromEmissionToCathode();
386       if (Radius == 999.) continue;
387       xGraph[nPointsToDraw] = GetXPointOnCathode() + GetShiftX();
388       yGraph[nPointsToDraw] = GetYPointOnCathode() + GetShiftY();
389       nPointsToDraw++;
390     }
391   gra = new TGraph(nPointsToDraw,xGraph,yGraph);
392   gra->Draw("AC"); 
393 }
394 //__________________________________________________________________________________________________
395 */
396 void AliRICHParam::TestHit2SDigs(Double_t x,Double_t y,Double_t e,Bool_t isNew)
397 {
398 //Test  hit->sdigits procedures
399 //Arguments: isNew - if true use new (abs pad) procedure else use old one (TVector)
400 //  Returns: none
401   TClonesArray *pSDigLst=new TClonesArray("AliRICHDigit");
402   Int_t iQtot=-1;
403   if(isNew){
404     iQtot=Hit2SDigs(10101,e,pSDigLst);        //new technique
405   }else{
406     iQtot=Hit2SDigs(TVector2(x,y),e,pSDigLst);//old technique
407   }
408   pSDigLst->Print();
409   Double_t dQsum=0;
410   for(Int_t i=0;i<pSDigLst->GetEntriesFast();i++)
411     dQsum+=((AliRICHDigit*)pSDigLst->At(i))->Qdc();
412   Printf("Qtot=%i Qsum=%.2f ",iQtot,dQsum);
413 }
414 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
415 Int_t AliRICHParam::Stack(Int_t evt,Int_t tid)
416 {
417 // Prints some usefull info from stack
418 // Arguments: evt - event number. if not -1 print info only for that event
419 //            tid - track id. if not -1 then print it and all it's mothers if any   
420 //   Returns: mother tid of the given tid if any
421   AliRunLoader *pAL=AliRunLoader::Open(); 
422   if(pAL->LoadHeader()) return -1;
423   if(pAL->LoadKinematics()) return -1;
424   
425   Int_t mtid=-1;
426   Int_t iNevt=pAL->GetNumberOfEvents();     Printf("This session contains %i event(s)",iNevt);
427   
428   for(Int_t iEvt=0;iEvt<iNevt;iEvt++){//events loop
429     if(evt!=-1 && evt!=iEvt) continue; //in case one needs to print the requested event, ignore all others
430     pAL->GetEvent(iEvt);    
431     AliStack *pStack=pAL->Stack();  
432     if(tid==-1){                        //print all tids for this event
433       for(Int_t i=0;i<pStack->GetNtrack();i++) pStack->Particle(i)->Print();
434       Printf("totally %i tracks including %i primaries for event %i out of %i event(s)",pStack->GetNtrack(),pStack->GetNprimary(),iEvt,iNevt);
435     }else{                              //print only this tid and it;s mothers
436       if(tid<0 || tid>pStack->GetNtrack()) {Printf("Wrong tid, valid tid range for event %i is 0-%i",iEvt,pStack->GetNtrack());break;}
437       TParticle *pTrack=pStack->Particle(tid); mtid=pTrack->GetFirstMother();
438       TString str=pTrack->GetName();
439       while((tid=pTrack->GetFirstMother()) >= 0){
440         pTrack=pStack->Particle(tid);
441         str+=" from ";str+=pTrack->GetName();
442       } 
443       Printf("%s",str.Data());       
444     }//if(tid==-1)      
445   }//events loop
446   pAL->UnloadHeader();  pAL->UnloadKinematics();
447   return mtid;
448 }
449 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
450 Int_t AliRICHParam::StackCount(Int_t pid,Int_t evt)
451 {
452 // Counts total number of particles of given sort (including secondary) for a given event
453   AliRunLoader *pAL=AliRunLoader::Open(); 
454   pAL->GetEvent(evt);    
455   if(pAL->LoadHeader()) return 0;
456   if(pAL->LoadKinematics()) return 0;
457   AliStack *pStack=pAL->Stack();
458   
459   Int_t iCnt=0;
460   for(Int_t i=0;i<pStack->GetNtrack();i++) if(pStack->Particle(i)->GetPdgCode()==pid) iCnt++;
461   
462   pAL->UnloadHeader();  pAL->UnloadKinematics();
463   return iCnt;
464 }
465 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++