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