New Global2Local
[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
16 #include <Riostream.h> 
17 #include <TMath.h>
18 #include <TRandom.h>
19
20 #include "AliRICHParam.h"
21
22 ClassImp(AliRICHParam)
23
24 Float_t AliRICHParam::fgAngleRot=-60;
25
26 // RICH main parameters manipulator
27 //__________________________________________________________________________________________________
28 AliRICHParam::AliRICHParam():
29 fCurrentPadX(0),fCurrentPadY(0),fCurrentWire(0),
30 fSizeZ(0),
31 fProximityGapThickness(0),
32 fQuartzLength(0),
33 fQuartzWidth(0),
34 fOuterFreonLength(0),
35 fOuterFreonWidth(0),
36 fInnerFreonLength(0),
37 fInnerFreonWidth(0),
38 fChargeSlope(0),
39 fChargeSpreadX(0),
40 fChargeSpreadY(0),
41 fSigmaIntegration(0),
42 fAlphaFeedback(0),
43 fEIonisation(0),
44 fMaxAdc(0),
45 fWireSag(0),
46 fVoltage(0)
47 {//defines the default parameters
48   Size                 (132.6*kcm,26*kcm,136.7*kcm);  //full length, not GEANT half notation
49   
50   ProximityGapThickness(0.4*kcm);            
51   QuartzLength         (133*kcm);            
52   QuartzWidth          (127.9*kcm);          
53   OuterFreonLength     (133*kcm);            
54   OuterFreonWidth      (41.3*kcm);           
55   InnerFreonLength     (133*kcm);            
56   InnerFreonWidth      (41.3*kcm);           
57   
58   ChargeSlope(27.);
59   ChargeSpreadX(0.18);ChargeSpreadY(0.18);
60   SigmaIntegration(5.);
61   MaxAdc(4096);
62   AlphaFeedback(0.036);
63   EIonisation(26.e-9);
64   WireSag(1);                 // 1->On, 0->Off
65   Voltage(2150);              // Should only be 2000, 2050, 2100 or 2150  
66 }//AliRICHParam::named ctor 
67 //__________________________________________________________________________________________________
68 Int_t AliRICHParam::Local2Sector(Float_t &x, Float_t &y)
69 {//Determines sector for a given hit (x,y) and trasform this point to the local system of that sector.
70   Int_t sector=kBad;  
71   Float_t x1=-0.5*PcSizeX();      Float_t x2=-0.5*SectorSizeX()-DeadZone();  Float_t x3=-0.5*SectorSizeX();
72   Float_t x4= 0.5*SectorSizeX();  Float_t x5= 0.5*SectorSizeX()+DeadZone();  Float_t x6= 0.5*PcSizeX();
73
74   if     (x>=x1&&x<=x2)    {sector=1;x+=0.5*PcSizeX();}
75   else if(x>=x3&&x<=x4)    {sector=2;x+=0.5*SectorSizeX();}
76   else if(x>=x5&&x<=x6)    {sector=3;x-=0.5*SectorSizeX()+DeadZone();}
77   else if(x< x1||x> x6)    {return kBad;}
78   else                                                        {return kBad;} //in dead zone
79
80   if     (y>=-0.5*PcSizeY()   &&y<=-0.5*DeadZone())  {y+=0.5*PcSizeY();  return -sector;}
81   else if(y> -0.5*DeadZone()  &&y<  0.5*DeadZone())  {return kBad;} //in dead zone
82   else if(y>= 0.5*DeadZone()  &&y<= 0.5*PcSizeY())   {y-=0.5*DeadZone(); return  sector;}
83   else                                               {return kBad;}
84 }//Int_t AliRICHParam::Local2Sector(Float_t x, Float_t y)
85 //__________________________________________________________________________________________________
86 Int_t AliRICHParam::Pad2Sector(Int_t &padx, Int_t &pady)
87 {//Determines sector for a given pad (padx,pady) and trasform this point to the local system of that sector.
88   Int_t sector=kBad;      
89   if     (padx>=1            &&padx<=NpadsXsec())      {sector=1;}
90   else if(padx> NpadsXsec()  &&padx<=NpadsXsec()*2)    {sector=2;padx-=NpadsXsec();}
91   else if(padx> NpadsXsec()*2&&padx<=NpadsX())         {sector=3;padx-=NpadsXsec()*2;}
92   else                                                 {return kBad;}
93
94   if     (pady>=1         &&pady<= NpadsYsec())     {return -sector;}
95   else if(pady>NpadsYsec()&&pady<= NpadsY())        {pady-=NpadsYsec();return sector;} 
96   else                                              {return kBad;}
97 }//Local2Sector()
98 //__________________________________________________________________________________________________
99 Int_t AliRICHParam::Local2Pad(Float_t x, Float_t y, Int_t &padx, Int_t &pady)
100 {//returns pad numbers (iPadX,iPadY) for given point in local coordinates (x,y) 
101  //count starts in lower left corner from 1,1 to 144,180
102   
103   padx=pady=kBad;
104   Int_t sector=Local2Sector(x,y);
105   if(sector==kBad) return sector;
106   
107   padx=Int_t(x/PadSizeX())+1; 
108   if(padx>NpadsXsec())            padx= NpadsXsec();
109   if(sector==2||sector==-2)       padx+=NpadsXsec();
110   else if(sector==3||sector==-3)  padx+=NpadsXsec()*2;
111   
112   pady=Int_t(y/PadSizeY())+1;
113   if(pady>NpadsYsec())            padx= NpadsYsec();
114   if(sector>0)                    pady+=NpadsYsec();    
115
116   return sector;
117 }//Local2Pad()
118 //__________________________________________________________________________________________________
119 void AliRICHParam::Pad2Local(Int_t padx,Int_t pady,Float_t &x,Float_t &y)
120 {
121   Int_t sector=Pad2Sector(padx,pady);  
122   if(sector>0)
123     y=0.5*DeadZone()+pady*PadSizeY()-0.5*PadSizeY();
124   else{
125     sector=-sector;
126     y=-0.5*PcSizeY()+pady*PadSizeY()-0.5*PadSizeY();
127   }
128   if(sector==1)
129     x=-0.5*PcSizeX()+padx*PadSizeX()-0.5*PadSizeX();
130   else if(sector==2)
131     x=-0.5*SectorSizeX()+padx*PadSizeX()-0.5*PadSizeX();
132   else
133     x= 0.5*SectorSizeX()+DeadZone()+padx*PadSizeX()-0.5*PadSizeX();
134   return;
135 }//Pad2Local()
136 //__________________________________________________________________________________________________
137 Float_t AliRICHParam::Gain(Float_t y)
138 {//Calculates the gain
139   if(fWireSag){
140     Float_t gainK=9e-6*TMath::Power(y,4)+2e-7*TMath::Power(y,3)-0.0316*TMath::Power(y,2)-3e-4*y+25.367;
141     Float_t gain = (ChargeSlope()+ChargeSlope()*gainK/100)*0.9;
142     return -gain*TMath::Log(gRandom->Rndm());
143   }else     
144     return -ChargeSlope()*TMath::Log(gRandom->Rndm());
145 }//Float_t AliRICHParam::IntPH(Float_t yhit)
146 //__________________________________________________________________________________________________
147 Float_t AliRICHParam::TotalCharge(Int_t iPID,Float_t eloss,Float_t y)
148 {//Get number of electrons and return charge
149     
150   if(iPID>50000)//it's photon no more then 1 electron after photoelectron conversion
151     return Gain(y);
152   else{  
153     Int_t iNelectrons=Int_t(eloss/fEIonisation);if(iNelectrons==0) iNelectrons=1;
154     Float_t charge=0;
155     for(Int_t i=1;i<=iNelectrons;i++)
156       charge+=Gain(y);
157     return charge;
158   }
159 }//Float_t AliRICHParam::TotalCharge(Int_t iPID,Float_t eloss, Float_t y)
160 //__________________________________________________________________________________________________
161 void AliRICHParam::FirstPad(Float_t x,Float_t y)
162 {
163   Int_t padx,pady;
164   Local2Pad(x,y,padx,pady);
165 }//void AliRICHParam::FirstPad(Float_t x,Float_t y)
166 //__________________________________________________________________________________________________
167 Float_t AliRICHParam::AssignChargeToPad(Float_t hitx,Float_t hity,Int_t padx,Int_t pady)
168 {//
169   Float_t padXcenter=0,padYcenter=0;
170   Pad2Local(padx,pady,padXcenter,padYcenter);
171   
172   Float_t xi1=hitx-padXcenter-PadSizeX()/2;
173   Float_t xi2=hitx-padXcenter+PadSizeX()/2; 
174   Float_t yi1=hity-padYcenter-PadSizeY()/2;
175   Float_t yi2=hity-padYcenter+PadSizeY()/2;
176   xi1/=AnodeCathodeGap();
177   xi2/=AnodeCathodeGap();
178   yi1/=AnodeCathodeGap();
179   yi2/=AnodeCathodeGap();
180 // The Mathieson function 
181   Double_t ux1=SqrtKx3()*TMath::TanH(Kx2()*xi1);
182   Double_t ux2=SqrtKx3()*TMath::TanH(Kx2()*xi2);    
183   Double_t uy1=SqrtKy3()*TMath::TanH(Ky2()*yi1);
184   Double_t uy2=SqrtKy3()*TMath::TanH(Ky2()*yi2);
185   return 4.*Kx4()*(TMath::ATan(ux2)-TMath::ATan(ux1))*Ky4()*(TMath::ATan(uy2)-TMath::ATan(uy1));
186 }//AssignChargeToPad()
187 //__________________________________________________________________________________________________