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 Revision 1.1 2000/07/12 08:56:25 fca
19 Coding convention correction and warning removal
21 Revision 1.16 2000/05/26 08:35:03 fca
22 Move the check on z after z has been retrieved
24 Revision 1.15 2000/05/16 13:10:40 fca
25 New method IsNewTrack and fix for a problem in Father-Daughter relations
27 Revision 1.14 2000/04/27 10:38:21 fca
28 Correct termination of Lego Run and introduce Lego getter in AliRun
30 Revision 1.13 2000/04/26 10:17:31 fca
31 Changes in Lego for G4 compatibility
33 Revision 1.12 2000/04/07 11:12:33 fca
34 G4 compatibility changes
36 Revision 1.11 2000/03/22 13:42:26 fca
37 SetGenerator does not replace an existing generator, ResetGenerator does
39 Revision 1.10 2000/02/23 16:25:22 fca
40 AliVMC and AliGeant3 classes introduced
41 ReadEuclid moved from AliRun to AliModule
43 Revision 1.9 1999/12/03 10:54:01 fca
46 Revision 1.8 1999/10/01 09:54:33 fca
47 Correct logics for Lego StepManager
49 Revision 1.7 1999/09/29 09:24:29 fca
50 Introduction of the Copyright and cvs Log
54 #include "AliLegoGenerator.h"
57 ClassImp(AliLegoGenerator)
59 //___________________________________________
60 AliLegoGenerator::AliLegoGenerator(Int_t ntheta, Float_t themin,
61 Float_t themax, Int_t nphi,
62 Float_t phimin, Float_t phimax,
63 Float_t rmin, Float_t rmax, Float_t zmax) :
64 AliGenerator(0), fRadMin(rmin), fRadMax(rmax), fZMax(zmax), fNtheta(ntheta),
65 fNphi(nphi), fThetaBin(ntheta), fPhiBin(-1), fCurTheta(0), fCurPhi(0)
69 // Standard generator for Lego rays
71 SetPhiRange(phimin,phimax);
72 SetThetaRange(themin,themax);
77 //___________________________________________
78 void AliLegoGenerator::Generate()
80 // Create a geantino with kinematics corresponding to the current
81 // bins in theta and phi.
85 const Int_t kMpart = 0;
86 Float_t orig[3], pmom[3];
87 Float_t t, cost, sint, cosp, sinp;
89 // Prepare for next step
90 if(fThetaBin>=fNtheta-1)
91 if(fPhiBin>=fNphi-1) {
92 Warning("Generate","End of Lego Generation");
96 printf("Generating rays in phi bin:%d\n",fPhiBin);
100 fCurTheta = (fThetaMin+(fThetaBin+0.5)*(fThetaMax-fThetaMin)/fNtheta);
101 fCurPhi = (fPhiMin+(fPhiBin+0.5)*(fPhiMax-fPhiMin)/fNphi);
102 cost = TMath::Cos(fCurTheta);
103 sint = TMath::Sin(fCurTheta);
104 cosp = TMath::Cos(fCurPhi);
105 sinp = TMath::Sin(fCurPhi);
111 // --- Where to start
112 orig[0] = orig[1] = orig[2] = 0;
113 Float_t dalicz = 3000;
115 t = PropagateCylinder(orig,pmom,fRadMin,dalicz);
119 if (TMath::Abs(orig[2]) > fZMax) return;
122 Float_t polar[3]={0.,0.,0.};
124 gAlice->SetTrack(1, 0, kMpart, pmom, orig, polar, 0, "LEGO ray", ntr);
128 //___________________________________________
129 Float_t AliLegoGenerator::PropagateCylinder(Float_t *x, Float_t *v, Float_t r, Float_t z)
131 // Propagate to cylinder from inside
133 Double_t hnorm, sz, t, t1, t2, t3, sr;
135 const Float_t kSmall = 1e-8;
136 const Float_t kSmall2 = kSmall*kSmall;
138 // ---> Find intesection with Z planes
142 hnorm = TMath::Sqrt(1/(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]));
146 if (d[2] > kSmall) sz = (z-x[2])/d[2];
147 else if (d[2] < -kSmall) sz = -(z+x[2])/d[2];
148 else sz = 1.e10; // ---> Direction parallel to X-Y, no intersection
150 // ---> Intersection with cylinders
151 // Intersection point (x,y,z)
152 // (x,y,z) is on track : x=X(1)+t*D(1)
155 // (x,y,z) is on cylinder : x**2 + y**2 = R**2
157 // (D(1)**2+D(2)**2)*t**2
158 // +2.*(X(1)*D(1)+X(2)*D(2))*t
159 // +X(1)**2+X(2)**2-R**2=0
160 // ---> Solve second degree equation
161 t1 = d[0]*d[0] + d[1]*d[1];
163 t = sz; // ---> Track parallel to the z-axis, take distance to planes
165 t2 = x[0]*d[0] + x[1]*d[1];
166 t3 = x[0]*x[0] + x[1]*x[1];
167 // ---> It should be positive, but there may be numerical problems
168 sr = (t2 +TMath::Sqrt(TMath::Max(t2*t2-(t3-r*r)*t1,0.)))/t1;
169 // ---> Find minimum distance between planes and cylinder
170 t = TMath::Min(sz,sr);