1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //------------------------------------------------------------------------
20 // Generic Lego generator code
22 //------------------------------------------------------------------------
24 #include "AliLegoGenerator.h"
27 ClassImp(AliLegoGenerator)
29 //_______________________________________________________________________
30 AliLegoGenerator::AliLegoGenerator():
46 // Default Constructor
51 //_______________________________________________________________________
52 AliLegoGenerator::AliLegoGenerator(Int_t nc1, Float_t c1min,
53 Float_t c1max, Int_t nc2,
54 Float_t c2min, Float_t c2max,
55 Float_t rmin, Float_t rmax, Float_t zmax):
72 // Standard generator for Lego rays
75 SetCoor1Range(nc1, c1min, c1max);
76 SetCoor2Range(nc2, c2min, c2max);
79 //_______________________________________________________________________
80 void AliLegoGenerator::Generate()
82 // Create a geantino with kinematics corresponding to the current bins
83 // Here: Coor1 = theta
88 const Int_t kMpart = 0;
89 Float_t orig[3], pmom[3];
90 Float_t t, cost, sint, cosp, sinp;
91 if (fCoor1Bin==-1) fCoor1Bin=fNCoor1;
92 // Prepare for next step
93 if(fCoor1Bin>=fNCoor1-1)
94 if(fCoor2Bin>=fNCoor2-1) {
95 Warning("Generate","End of Lego Generation");
99 printf("Generating rays in phi bin:%d\n",fCoor2Bin);
103 fCurCoor1 = (fCoor1Min+(fCoor1Bin+0.5)*(fCoor1Max-fCoor1Min)/fNCoor1);
104 fCurCoor2 = (fCoor2Min+(fCoor2Bin+0.5)*(fCoor2Max-fCoor2Min)/fNCoor2);
105 cost = TMath::Cos(fCurCoor1 * TMath::Pi()/180.);
106 sint = TMath::Sin(fCurCoor1 * TMath::Pi()/180.);
107 cosp = TMath::Cos(fCurCoor2 * TMath::Pi()/180.);
108 sinp = TMath::Sin(fCurCoor2 * TMath::Pi()/180.);
114 // --- Where to start
115 orig[0] = orig[1] = orig[2] = 0;
116 Float_t dalicz = 3000;
118 t = PropagateCylinder(orig,pmom,fRadMin,dalicz);
122 if (TMath::Abs(orig[2]) > fZMax) return;
125 Float_t polar[3]={0.,0.,0.};
127 gAlice->SetTrack(1, -1, kMpart, pmom, orig, polar, 0, kPPrimary, ntr);
131 //_______________________________________________________________________
132 Float_t AliLegoGenerator::PropagateCylinder(Float_t *x, Float_t *v, Float_t r,
136 // Propagate to cylinder from inside
138 Double_t hnorm, sz, t, t1, t2, t3, sr;
140 const Float_t kSmall = 1e-8;
141 const Float_t kSmall2 = kSmall*kSmall;
143 // ---> Find intesection with Z planes
147 hnorm = TMath::Sqrt(1/(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]));
151 if (d[2] > kSmall) sz = (z-x[2])/d[2];
152 else if (d[2] < -kSmall) sz = -(z+x[2])/d[2];
153 else sz = 1.e10; // ---> Direction parallel to X-Y, no intersection
155 // ---> Intersection with cylinders
156 // Intersection point (x,y,z)
157 // (x,y,z) is on track : x=X(1)+t*D(1)
160 // (x,y,z) is on cylinder : x**2 + y**2 = R**2
162 // (D(1)**2+D(2)**2)*t**2
163 // +2.*(X(1)*D(1)+X(2)*D(2))*t
164 // +X(1)**2+X(2)**2-R**2=0
165 // ---> Solve second degree equation
166 t1 = d[0]*d[0] + d[1]*d[1];
168 t = sz; // ---> Track parallel to the z-axis, take distance to planes
170 t2 = x[0]*d[0] + x[1]*d[1];
171 t3 = x[0]*x[0] + x[1]*x[1];
172 // ---> It should be positive, but there may be numerical problems
173 sr = (-t2 +TMath::Sqrt(TMath::Max(t2*t2-(t3-r*r)*t1,0.)))/t1;
174 // ---> Find minimum distance between planes and cylinder
175 t = TMath::Min(sz,sr);