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.3 2000/10/26 14:15:54 morsch
20 - Change from theta, phi to general coordinates Coor1, Coor2
21 - PropagateCylinder: bug in calculation of distance to limiting radius corrected.
23 Revision 1.2 2000/07/13 16:19:09 fca
24 Mainly coding conventions + some small bug fixes
26 Revision 1.1 2000/07/12 08:56:25 fca
27 Coding convention correction and warning removal
29 Revision 1.16 2000/05/26 08:35:03 fca
30 Move the check on z after z has been retrieved
32 Revision 1.15 2000/05/16 13:10:40 fca
33 New method IsNewTrack and fix for a problem in Father-Daughter relations
35 Revision 1.14 2000/04/27 10:38:21 fca
36 Correct termination of Lego Run and introduce Lego getter in AliRun
38 Revision 1.13 2000/04/26 10:17:31 fca
39 Changes in Lego for G4 compatibility
41 Revision 1.12 2000/04/07 11:12:33 fca
42 G4 compatibility changes
44 Revision 1.11 2000/03/22 13:42:26 fca
45 SetGenerator does not replace an existing generator, ResetGenerator does
47 Revision 1.10 2000/02/23 16:25:22 fca
48 AliVMC and AliGeant3 classes introduced
49 ReadEuclid moved from AliRun to AliModule
51 Revision 1.9 1999/12/03 10:54:01 fca
54 Revision 1.8 1999/10/01 09:54:33 fca
55 Correct logics for Lego StepManager
57 Revision 1.7 1999/09/29 09:24:29 fca
58 Introduction of the Copyright and cvs Log
61 #include "AliLegoGenerator.h"
64 ClassImp(AliLegoGenerator)
66 //___________________________________________
68 AliLegoGenerator::AliLegoGenerator()
71 // Default Constructor
75 fCoor1Bin = fCoor2Bin = -1;
76 fCurCoor1 = fCurCoor2 = 0;
79 AliLegoGenerator::AliLegoGenerator(Int_t nc1, Float_t c1min,
80 Float_t c1max, Int_t nc2,
81 Float_t c2min, Float_t c2max,
82 Float_t rmin, Float_t rmax, Float_t zmax) :
83 AliGenerator(0), fRadMin(rmin), fRadMax(rmax), fZMax(zmax), fNCoor1(nc1),
84 fNCoor2(nc2), fCoor1Bin(nc1), fCoor2Bin(-1), fCurCoor1(0), fCurCoor2(0)
88 // Standard generator for Lego rays
90 SetCoor1Range(nc1, c1min, c1max);
91 SetCoor2Range(nc2, c2min, c2max);
95 //___________________________________________
96 void AliLegoGenerator::Generate()
98 // Create a geantino with kinematics corresponding to the current bins
99 // Here: Coor1 = theta
104 const Int_t kMpart = 0;
105 Float_t orig[3], pmom[3];
106 Float_t t, cost, sint, cosp, sinp;
107 if (fCoor1Bin==-1) fCoor1Bin=fNCoor1;
108 // Prepare for next step
109 if(fCoor1Bin>=fNCoor1-1)
110 if(fCoor2Bin>=fNCoor2-1) {
111 Warning("Generate","End of Lego Generation");
115 printf("Generating rays in phi bin:%d\n",fCoor2Bin);
119 fCurCoor1 = (fCoor1Min+(fCoor1Bin+0.5)*(fCoor1Max-fCoor1Min)/fNCoor1);
120 fCurCoor2 = (fCoor2Min+(fCoor2Bin+0.5)*(fCoor2Max-fCoor2Min)/fNCoor2);
121 cost = TMath::Cos(fCurCoor1 * TMath::Pi()/180.);
122 sint = TMath::Sin(fCurCoor1 * TMath::Pi()/180.);
123 cosp = TMath::Cos(fCurCoor2 * TMath::Pi()/180.);
124 sinp = TMath::Sin(fCurCoor2 * TMath::Pi()/180.);
130 // --- Where to start
131 orig[0] = orig[1] = orig[2] = 0;
132 Float_t dalicz = 3000;
134 t = PropagateCylinder(orig,pmom,fRadMin,dalicz);
138 if (TMath::Abs(orig[2]) > fZMax) return;
141 Float_t polar[3]={0.,0.,0.};
143 gAlice->SetTrack(1, 0, kMpart, pmom, orig, polar, 0, kPPrimary, ntr);
147 //___________________________________________
148 Float_t AliLegoGenerator::PropagateCylinder(Float_t *x, Float_t *v, Float_t r, Float_t z)
150 // Propagate to cylinder from inside
152 Double_t hnorm, sz, t, t1, t2, t3, sr;
154 const Float_t kSmall = 1e-8;
155 const Float_t kSmall2 = kSmall*kSmall;
157 // ---> Find intesection with Z planes
161 hnorm = TMath::Sqrt(1/(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]));
165 if (d[2] > kSmall) sz = (z-x[2])/d[2];
166 else if (d[2] < -kSmall) sz = -(z+x[2])/d[2];
167 else sz = 1.e10; // ---> Direction parallel to X-Y, no intersection
169 // ---> Intersection with cylinders
170 // Intersection point (x,y,z)
171 // (x,y,z) is on track : x=X(1)+t*D(1)
174 // (x,y,z) is on cylinder : x**2 + y**2 = R**2
176 // (D(1)**2+D(2)**2)*t**2
177 // +2.*(X(1)*D(1)+X(2)*D(2))*t
178 // +X(1)**2+X(2)**2-R**2=0
179 // ---> Solve second degree equation
180 t1 = d[0]*d[0] + d[1]*d[1];
182 t = sz; // ---> Track parallel to the z-axis, take distance to planes
184 t2 = x[0]*d[0] + x[1]*d[1];
185 t3 = x[0]*x[0] + x[1]*x[1];
186 // ---> It should be positive, but there may be numerical problems
187 sr = (-t2 +TMath::Sqrt(TMath::Max(t2*t2-(t3-r*r)*t1,0.)))/t1;
188 // ---> Find minimum distance between planes and cylinder
189 t = TMath::Min(sz,sr);