]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RICH/AliRICHSegResV0.cxx
Macro for RICH diagnostics (JB, AM)
[u/mrichter/AliRoot.git] / RICH / AliRICHSegResV0.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   $Log$
18 */
19
20
21 #include "AliRICHSegResV0.h"
22 #include "AliRun.h"
23 #include "TParticle.h"
24 #include "TMath.h"
25 #include "TRandom.h"
26 #include "TArc.h"
27
28
29 ClassImp(AliRICHSegmentation)
30 ClassImp(AliRICHResponse)
31 ClassImp(AliRICHGeometry)
32 //___________________________________________
33 ClassImp(AliRICHSegmentationV0)
34
35 void AliRICHSegmentationV0::Init(AliRICHChamber* Chamber)
36 {
37     //fNpx=(Int_t) (Chamber->ROuter()/fDpx+1);
38     //fNpy=(Int_t) (Chamber->ROuter()/fDpy+1);
39   fNpx=160;
40   fNpy=144;
41   //fNpx=80;
42   //fNpy=48;
43   fSector=-1;
44 }
45
46
47 Float_t AliRICHSegmentationV0::GetAnod(Float_t xhit)
48 {
49     Float_t wire= (xhit>0)? Int_t(xhit/fWireD)+0.5:Int_t(xhit/fWireD)-0.5;
50     return fWireD*wire;
51 }
52
53 void AliRICHSegmentationV0::SetPadSize(Float_t p1, Float_t p2)
54 {
55     fDpx=p1;
56     fDpy=p2;
57 }
58 void AliRICHSegmentationV0::GetPadIxy(Float_t x, Float_t y, Int_t &ix, Int_t &iy)
59 {
60 //  returns pad coordinates (ix,iy) for given real coordinates (x,y)
61 //
62 // Please check origin of pad numbering !!!
63
64   
65   ix = (x>0)? Int_t(x/fDpx)+1 : Int_t(x/fDpx);
66   iy = (y>0)? Int_t(y/fDpy)+1 : Int_t(y/fDpy);
67   if (iy >  fNpy) iy= fNpy;
68   if (iy < -fNpy) iy=-fNpy;
69   if (ix >  fNpx) ix= fNpx;
70   if (ix < -fNpx) ix=-fNpx;
71 }
72 void AliRICHSegmentationV0::
73 GetPadCxy(Int_t ix, Int_t iy, Float_t &x, Float_t &y)
74 {
75 //  returns real coordinates (x,y) for given pad coordinates (ix,iy)
76 //
77
78   x = (ix>0) ? Float_t(ix*fDpx)-fDpx/2. : Float_t(ix*fDpx)-fDpx/2.;
79   y = (iy>0) ? Float_t(iy*fDpy)-fDpy/2. : Float_t(iy*fDpy)-fDpy/2.;
80 }
81
82 void AliRICHSegmentationV0::
83 SetHit(Float_t xhit, Float_t yhit)
84 {
85 //
86 // Find the wire position (center of charge distribution)
87 //    Float_t x0a=GetAnod(xhit);
88     fxhit=xhit;
89     fyhit=yhit;
90 }
91
92 void AliRICHSegmentationV0::
93 SetPad(Int_t ix, Int_t iy)
94 {
95     GetPadCxy(ix,iy,fx,fy);
96 }
97
98
99
100 void AliRICHSegmentationV0::
101 FirstPad(Float_t xhit, Float_t yhit, Float_t dx, Float_t dy)
102 {
103
104     //
105     // Find the wire position (center of charge distribution)
106     Float_t x0a=GetAnod(xhit);
107     fxhit=x0a;
108     fyhit=yhit;
109     //
110     // and take fNsigma*sigma around this center
111     Float_t x01=x0a  - dx;
112     Float_t x02=x0a  + dx;
113     Float_t y01=yhit - dy;
114     Float_t y02=yhit + dy;
115     //
116     // find the pads over which the charge distributes
117     GetPadIxy(x01,y01,fixmin,fiymin);
118     GetPadIxy(x02,y02,fixmax,fiymax);    
119     // 
120     // Set current pad to lower left corner
121     fix=fixmin;
122     fiy=fiymin;
123     GetPadCxy(fix,fiy,fx,fy);
124     
125     //if (fSector==2)
126       //printf("fix: %d, fiy: %d fx: %f, fy: %f\n",fix,fiy,fx,fy);
127 }
128
129 void AliRICHSegmentationV0::NextPad()
130 {
131     //printf("\n Next Pad \n");
132     
133     // 
134     // Step to next pad in integration region
135     if (fix <= fixmax) {
136 //      if (fix==-1) fix++;
137         fix++;
138     } else if (fiy <= fiymax) {
139 //      if (fiy==-1) fiy++;
140         fix=fixmin;
141         fiy++;
142     } else {
143         printf("\n Error: Stepping outside integration region\n ");
144     }
145     GetPadCxy(fix,fiy,fx,fy);
146 }
147
148 Int_t AliRICHSegmentationV0::MorePads()
149
150 //
151 // Are there more pads in the integration region
152 {
153     //printf("\n More  Pads ? \n");
154   
155   
156   if (fix >= fixmax && fiy >= fiymax) {
157     //printf("There are no more pads\n\n\n\n\n");
158     return 0;
159   } else {
160     //printf("There are more pads\n\n");
161     return 1;
162   }
163 }
164
165 void AliRICHSegmentationV0::SigGenInit(Float_t x,Float_t y,Float_t)
166 {
167 //
168 //  Initialises pad and wire position during stepping
169     fxt =x;
170     fyt =y;
171     GetPadIxy(x,y,fixt,fiyt);
172     fiwt= (x>0) ? Int_t(x/fWireD)+1 : Int_t(x/fWireD)-1 ;
173 }
174
175 Int_t AliRICHSegmentationV0::SigGenCond(Float_t x,Float_t y,Float_t)
176 {
177 //
178 //  Signal will be generated if particle crosses pad boundary or
179 //  boundary between two wires. 
180     Int_t ixt, iyt;
181     GetPadIxy(x,y,ixt,iyt);
182     Int_t iwt=(x>0) ? Int_t(x/fWireD)+1 : Int_t(x/fWireD)-1;
183     
184     if ((ixt != fixt) || (iyt !=fiyt) || (iwt != fiwt)) {
185       return 1;
186     } else {
187       return 0;
188     }
189 }
190 void AliRICHSegmentationV0::
191 IntegrationLimits(Float_t& x1,Float_t& x2,Float_t& y1, Float_t& y2)
192 {
193 /*
194   x1=fxt-fx-fDpx/2.;
195   x2=x1+fDpx;
196   y1=fyt-fy-fDpy/2.;
197   y2=y1+fDpy;    
198 */
199   x1=fxhit-fx-fDpx/2.;
200   x2=x1+fDpx;
201   y1=fyhit-fy-fDpy/2.;
202   y2=y1+fDpy;
203 }
204
205 void AliRICHSegmentationV0::
206 Neighbours(Int_t iX, Int_t iY, Int_t* Nlist, Int_t Xlist[7], Int_t Ylist[7])
207 {
208 //Is used for the cluster finder, include diagonal elements
209     
210     *Nlist=4;Xlist[0]=Xlist[1]=iX;Xlist[2]=iX-1;Xlist[3]=iX+1;
211     Ylist[0]=iY-1;Ylist[1]=iY+1;Ylist[2]=Ylist[3]=iY;
212 /*
213     *Nlist=8;
214     Xlist[0]=Xlist[1]=iX;
215     Xlist[2]=iX-1;
216     Xlist[3]=iX+1;
217     Ylist[0]=iY-1;
218     Ylist[1]=iY+1;
219     Ylist[2]=Ylist[3]=iY;
220
221    // Diagonal elements
222     Xlist[4]=iX+1;
223     Ylist[4]=iY+1;
224
225     Xlist[5]=iX-1;
226     Ylist[5]=iY-1;
227
228     Xlist[6]=iX-1;
229     Ylist[6]=iY+1;
230
231     Xlist[7]=iX+1;
232     Ylist[7]=iY-1;
233 */
234 }
235
236 Float_t AliRICHSegmentationV0::Distance2AndOffset(Int_t iX, Int_t iY, Float_t X, Float_t Y
237 , Int_t *dummy)
238 // Returns the square of the distance between 1 pad
239 // labelled by its Channel numbers and a coordinate
240 {
241   Float_t x,y;
242   GetPadCxy(iX,iY,x,y);
243   return (x-X)*(x-X) + (y-Y)*(y-Y);
244 }
245
246
247 void  AliRICHSegmentationV0::GiveTestPoints(Int_t &n, Float_t *x, Float_t *y)
248 {
249     n=1;
250     x[0]=0.;
251     y[0]=x[0];
252 }
253
254 void AliRICHSegmentationV0::Draw()
255 {
256 /*
257     TArc *circle;
258     Float_t scale=0.95/fRmax/2.;
259     
260
261     circle = new TArc(0.5,0.5,fRmax*scale,0.,360.);
262     circle->SetFillColor(2);
263     circle->Draw();
264
265     circle = new TArc(0.5,0.5,fRmin*scale,0.,360.);
266     circle->SetFillColor(1);
267     circle->Draw();
268 */
269     ;
270     
271 }
272
273
274 //___________________________________________
275 ClassImp(AliRICHResponseV0)
276
277 Float_t AliRICHResponseV0::IntPH(Float_t eloss)
278 {
279     // Get number of electrons and return charge
280     
281     Int_t nel;
282     nel= Int_t(eloss/fEIonisation);
283     
284     Float_t charge=0;
285     if (nel == 0) nel=1;
286     for (Int_t i=1;i<=nel;i++) {
287         charge -= fChargeSlope*TMath::Log(gRandom->Rndm());    
288     }
289     return charge;
290 }
291
292 Float_t AliRICHResponseV0::IntPH()
293 {
294     Float_t charge = -fChargeSlope*TMath::Log(gRandom->Rndm());
295     return charge;
296 }
297
298
299
300 // -------------------------------------------
301 Float_t AliRICHResponseV0::IntXY(AliRICHSegmentation * segmentation)
302 {
303     
304     const Float_t invpitch = 1/fPitch;
305     Float_t response;
306 //
307 //  Integration limits defined by segmentation model
308 //  
309     
310     Float_t xi1, xi2, yi1, yi2;
311     segmentation->IntegrationLimits(xi1,xi2,yi1,yi2);
312
313     xi1=xi1*invpitch;
314     xi2=xi2*invpitch;
315     yi1=yi1*invpitch;
316     yi2=yi2*invpitch;
317
318     //printf("Integration Limits: %f-%f, %f-%f\n",xi1,xi2,yi1,yi2);
319     
320     //printf("Invpitch:%f\n",invpitch);
321
322     //
323 // The Mathieson function 
324     Double_t ux1=fSqrtKx3*TMath::TanH(fKx2*xi1);
325     Double_t ux2=fSqrtKx3*TMath::TanH(fKx2*xi2);
326     
327     Double_t uy1=fSqrtKy3*TMath::TanH(fKy2*yi1);
328     Double_t uy2=fSqrtKy3*TMath::TanH(fKy2*yi2);
329
330     //printf("Integration Data: %f-%f, %f-%f\n",ux1,ux2,uy1,uy2);
331     
332     //printf("%f %f %f %f\n",fSqrtKx3,fKx2,fKy4,fKx4);
333     
334     response=4.*fKx4*(TMath::ATan(ux2)-TMath::ATan(ux1))*fKy4*(TMath::ATan(uy2)-TMath::ATan(uy1));
335
336     //printf("Response:%f\n",response);
337
338     return response;       
339     
340 }
341
342 Int_t AliRICHResponseV0::FeedBackPhotons(Float_t *source, Float_t qtot)
343 {
344   //
345   // Generate FeedBack photons
346   //
347   Int_t j, ipart, nt;
348     
349   Int_t sNfeed=0;
350   
351   
352   // Local variables 
353   Float_t cthf, ranf[2], phif, enfp = 0, sthf;
354   Int_t i, ifeed;
355   Float_t e1[3], e2[3], e3[3];
356   Float_t vmod, uswop;
357   Float_t fp, random;
358   Float_t dir[3], phi;
359   Int_t nfp;
360   Float_t pol[3], mom[3];
361   TLorentzVector position;
362   //
363   // Determine number of feedback photons
364
365   //  Get weight of current particle
366   TParticle *current = (TParticle*) 
367     (*gAlice->Particles())[gAlice->CurrentTrack()];
368     
369   ifeed = Int_t(current->GetWeight()/100+0.5);
370   ipart = gMC->TrackPid();
371   fp = fAlphaFeedback * qtot;
372   nfp = gRandom->Poisson(fp);
373   
374   // This call to fill the time of flight
375   gMC->TrackPosition(position);
376   //
377   // Generate photons
378   for (i = 0; i <nfp; i++) {
379         
380     // Direction
381     gMC->Rndm(ranf, 2);
382     cthf = ranf[0] * 2 - 1.;
383     if (cthf < 0)  continue;
384     sthf = TMath::Sqrt((1 - cthf) * (1 + cthf));
385     phif = ranf[1] * 2 * TMath::Pi();
386     //
387     gMC->Rndm(&random, 1);
388     if (random <= .57) {
389       enfp = 7.5e-9;
390     } else if (random <= .7) {
391       enfp = 6.4e-9;
392     } else {
393       enfp = 7.9e-9;
394     }
395
396     dir[0] = sthf * TMath::Sin(phif);
397     dir[1] = cthf;
398     dir[2] = sthf * TMath::Cos(phif);
399     gMC->Gdtom(dir, mom, 2);
400     mom[0]*=enfp;
401     mom[1]*=enfp;
402     mom[2]*=enfp;
403     
404     // Polarisation
405     e1[0] = 0;
406     e1[1] = -dir[2];
407     e1[2] = dir[1];
408     
409     e2[0] = -dir[1];
410     e2[1] = dir[0];
411     e2[2] = 0;
412     
413     e3[0] = dir[1];
414     e3[1] = 0;
415     e3[2] = -dir[0];
416     
417     vmod=0;
418     for(j=0;j<3;j++) vmod+=e1[j]*e1[j];
419     if (!vmod) for(j=0;j<3;j++) {
420       uswop=e1[j];
421       e1[j]=e3[j];
422       e3[j]=uswop;
423     }
424     vmod=0;
425     for(j=0;j<3;j++) vmod+=e2[j]*e2[j];
426     if (!vmod) for(j=0;j<3;j++) {
427       uswop=e2[j];
428       e2[j]=e3[j];
429       e3[j]=uswop;
430     }
431     
432     vmod=0;
433     for(j=0;j<3;j++) vmod+=e1[j]*e1[j];
434     vmod=TMath::Sqrt(1/vmod);
435     for(j=0;j<3;j++) e1[j]*=vmod;
436     
437     vmod=0;
438     for(j=0;j<3;j++) vmod+=e2[j]*e2[j];
439     vmod=TMath::Sqrt(1/vmod);
440     for(j=0;j<3;j++) e2[j]*=vmod;
441     
442     gMC->Rndm(ranf, 1);
443     phi = ranf[0] * 2 * TMath::Pi();
444     for(j=0;j<3;j++) pol[j]=e1[j]*TMath::Sin(phi)+e2[j]*TMath::Cos(phi);
445     gMC->Gdtom(pol, pol, 2);
446     
447     // Put photon on the stack and label it as feedback (51, 52) 
448     ++sNfeed;
449
450     gAlice->SetTrack(Int_t(1), gAlice->CurrentTrack(), Int_t(50000051),
451                      mom,source,pol,position[3],
452                      "Feedback", nt, 1.);
453   }
454   return(sNfeed);
455 }
456
457 //___________________________________________
458 ClassImp(AliRICHGeometryV0)