PatRec adapted to new IO
[u/mrichter/AliRoot.git] / RICH / AliRICHParam.cxx
1 #include "AliRICHParam.h"
2 #include <TMath.h>
3 #include <TRandom.h>
4  
5 ClassImp(AliRICHParam)
6
7 // RICH main parameters manipulator
8 //__________________________________________________________________________________________________
9 AliRICHParam::AliRICHParam():
10 fDeadZone(0),
11 fPadSizeX(0),fPadSizeY(0),
12 fCurrentPadX(0),fCurrentPadY(0),fCurrentWire(0),
13 fSizeZ(0),
14 fAngleRot(0),fAngleYZ(0),fAngleXY(0),
15 fOffset(0),
16 fGapThickness(0),
17 fProximityGapThickness(0),
18 fQuartzLength(0),
19 fQuartzWidth(0),
20 fQuartzThickness(0),
21 fOuterFreonLength(0),
22 fOuterFreonWidth(0),
23 fInnerFreonLength(0),
24 fInnerFreonWidth(0),
25 fFreonThickness(0),
26 fRadiatorToPads(0),
27 fChargeSlope(0),
28 fChargeSpreadX(0),
29 fChargeSpreadY(0),
30 fSigmaIntegration(0),
31 fAlphaFeedback(0),
32 fEIonisation(0),
33 fMaxAdc(0),
34 fSqrtKx3(0),
35 fKx2(0),
36 fKx4(0),
37 fSqrtKy3(0),
38 fKy2(0),
39 fKy4(0),
40 fPitch(0),
41 fWireSag(0),
42 fVoltage(0)
43 {//defines the default parameters
44   DeadZone             (3);                 //spacer between PC planes
45   PadSize              (0.84,0.80);     
46
47   Size                 (132.6*kcm,26*kcm,136.7*kcm);  //full length, not GEANT half notation
48   AngleRot             (-60);                         //rotation of the whole RICH around Z, deg
49   Angles               (20,19.5);                     //XY angle, YZ angle  deg  
50   Offset               (490*kcm+1.267*kcm);           //1.267???????cm distance from IP to the center of module 
51   GapThickness         (8*kcm);              
52   ProximityGapThickness(0.4*kcm);            
53   QuartzLength         (133*kcm);            
54   QuartzWidth          (127.9*kcm);          
55   QuartzThickness      (0.5*kcm);            
56   OuterFreonLength     (133*kcm);            
57   OuterFreonWidth      (41.3*kcm);           
58   InnerFreonLength     (133*kcm);            
59   InnerFreonWidth      (41.3*kcm);           
60   FreonThickness       (1.5*kcm);            
61   RadiatorToPads       (80*kmm);                 
62   
63   ChargeSlope(27.);
64   ChargeSpreadX(0.18);ChargeSpreadY(0.18);
65   SigmaIntegration(5.);
66   MaxAdc(4096);
67   AlphaFeedback(0.036);
68   EIonisation(26.e-9);
69   SqrtKx3(0.77459667);
70   Kx2(0.962);
71   Kx4(0.379);
72   SqrtKy3(0.77459667);
73   Ky2(0.962);
74   Ky4(0.379);
75   Pitch(0.25);
76   WireSag(1);                 // 1->On, 0->Off
77   Voltage(2150);              // Should only be 2000, 2050, 2100 or 2150  
78 }//AliRICHParam::named ctor 
79 //__________________________________________________________________________________________________
80 Int_t AliRICHParam::Local2Sector(Float_t &x, Float_t &y)const
81 {//Determines sector for a given hit (x,y) and trasform this point to the local system of that sector.
82   Int_t sector=kBad;  
83   Float_t x1=-0.5*PcSizeX();      Float_t x2=-0.5*SectorSizeX()-DeadZone();  Float_t x3=-0.5*SectorSizeX();
84   Float_t x4= 0.5*SectorSizeX();  Float_t x5= 0.5*SectorSizeX()+DeadZone();  Float_t x6= 0.5*PcSizeX();
85
86   if     (x>=x1&&x<=x2)    {sector=1;x+=0.5*PcSizeX();}
87   else if(x>=x3&&x<=x4)    {sector=2;x+=0.5*SectorSizeX();}
88   else if(x>=x5&&x<=x6)    {sector=3;x-=0.5*SectorSizeX()+DeadZone();}
89   else if(x< x1||x> x6)    {Error("Sector","given x position is out of PC area");return kBad;}
90   else                                                        {return kBad;} //in dead zone
91
92   if     (y>=-0.5*PcSizeY()   &&y<=-0.5*DeadZone())  {y+=0.5*PcSizeY();  return -sector;}
93   else if(y> -0.5*DeadZone()  &&y<  0.5*DeadZone())  {return kBad;} //in dead zone
94   else if(y>= 0.5*DeadZone()  &&y<= 0.5*PcSizeY())   {y-=0.5*DeadZone(); return  sector;}
95   else                                            {Error("Sector","given y position is out of PC area");return kBad;}
96 }//Int_t AliRICHParam::Local2Sector(Float_t x, Float_t y)
97 //__________________________________________________________________________________________________
98 Int_t AliRICHParam::Pad2Sector(Int_t &padx, Int_t &pady)const
99 {//Determines sector for a given pad (padx,pady) and trasform this point to the local system of that sector.
100   Int_t sector=kBad;      
101   if     (padx>=1            &&padx<=NpadsXsec())      {sector=1;}
102   else if(padx> NpadsXsec()  &&padx<=NpadsXsec()*2)    {sector=2;padx-=NpadsXsec();}
103   else if(padx> NpadsXsec()*2&&padx<=NpadsX())         {sector=3;padx-=NpadsXsec()*2;}
104   else                                   {Error("Sector","given padx position is out of PC area");return kBad;}
105
106   if     (pady>=1         &&pady<= NpadsYsec())     {return -sector;}
107   else if(pady>NpadsYsec()&&pady<= NpadsY())        {pady-=NpadsYsec();return sector;} 
108   else                                              {Error("Sector","given y position is out of PC area");return kBad;}
109 }//Local2Sector()
110 //__________________________________________________________________________________________________
111 Int_t AliRICHParam::Local2Pad(Float_t x, Float_t y, Int_t &padx, Int_t &pady)const
112 {//returns pad numbers (iPadX,iPadY) for given point in local coordinates (x,y) 
113  //count starts in lower left corner from 1,1 to 144,180
114   
115   padx=pady=kBad;
116   Int_t sector=Local2Sector(x,y);
117   if(sector==kBad) return sector;
118   
119   padx=Int_t(x/PadSizeX())+1; 
120   if(padx>NpadsXsec())            padx= NpadsXsec();
121   if(sector==2||sector==-2)       padx+=NpadsXsec();
122   else if(sector==3||sector==-3)  padx+=NpadsXsec()*2;
123   
124   pady=Int_t(y/PadSizeY())+1;
125   if(pady>NpadsYsec())            padx= NpadsYsec();
126   if(sector>0)                    pady+=NpadsYsec();    
127
128   return sector;
129 }//Local2Pad()
130 //__________________________________________________________________________________________________
131 void AliRICHParam::Pad2Local(Int_t padx,Int_t pady,Float_t &x,Float_t &y)
132 {
133   Int_t sector=Pad2Sector(padx,pady);  
134   if(sector>0)
135     y=0.5*DeadZone()+pady*PadSizeY()-0.5*PadSizeY();
136   else{
137     sector=-sector;
138     y=-0.5*PcSizeY()+pady*PadSizeY()-0.5*PadSizeY();
139   }
140   if(sector==1)
141     x=-0.5*PcSizeX()+padx*PadSizeX()-0.5*PadSizeX();
142   else if(sector==2)
143     x=-0.5*SectorSizeX()+padx*PadSizeX()-0.5*PadSizeX();
144   else
145     x= 0.5*SectorSizeX()+DeadZone()+padx*PadSizeX()-0.5*PadSizeX();
146   return;
147 }//Pad2Local()
148 //__________________________________________________________________________________________________
149 Float_t AliRICHParam::Gain(Float_t y)
150 {//Calculates the gain
151   if(fWireSag){
152     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;
153     Float_t gain = (ChargeSlope()+ChargeSlope()*gainK/100)*0.9;
154     return -gain*TMath::Log(gRandom->Rndm());
155   }else     
156     return -ChargeSlope()*TMath::Log(gRandom->Rndm());
157 }//Float_t AliRICHParam::IntPH(Float_t yhit)
158 //__________________________________________________________________________________________________
159 Float_t AliRICHParam::TotalCharge(Int_t iPID,Float_t eloss,Float_t y)
160 {//Get number of electrons and return charge
161     
162   if(iPID>50000)//it's photon no more then 1 electron after photoelectron conversion
163     return Gain(y);
164   else{  
165     Int_t iNelectrons=Int_t(eloss/fEIonisation);if(iNelectrons==0) iNelectrons=1;
166     Float_t charge=0;
167     for(Int_t i=1;i<=iNelectrons;i++)
168       charge+=Gain(y);
169     return charge;
170   }
171 }//Float_t AliRICHParam::TotalCharge(Int_t iPID,Float_t eloss, Float_t y)
172 //__________________________________________________________________________________________________
173 void AliRICHParam::FirstPad(Float_t x,Float_t y)
174 {
175   Int_t padx,pady;
176   Local2Pad(x,y,padx,pady);
177 }//void AliRICHParam::FirstPad(Float_t x,Float_t y)