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