]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliLegoGenerator.cxx
simplify syntax, introduce dependency from module.tpl
[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$
9e1a0ddb 18Revision 1.4 2000/11/30 07:12:49 alibrary
19Introducing new Rndm and QA classes
20
65fb704d 21Revision 1.3 2000/10/26 14:15:54 morsch
22- Base class now
23- Change from theta, phi to general coordinates Coor1, Coor2
24- PropagateCylinder: bug in calculation of distance to limiting radius corrected.
25
34915916 26Revision 1.2 2000/07/13 16:19:09 fca
27Mainly coding conventions + some small bug fixes
28
ef42d733 29Revision 1.1 2000/07/12 08:56:25 fca
30Coding convention correction and warning removal
31
8918e700 32Revision 1.16 2000/05/26 08:35:03 fca
33Move the check on z after z has been retrieved
34
35Revision 1.15 2000/05/16 13:10:40 fca
36New method IsNewTrack and fix for a problem in Father-Daughter relations
37
38Revision 1.14 2000/04/27 10:38:21 fca
39Correct termination of Lego Run and introduce Lego getter in AliRun
40
41Revision 1.13 2000/04/26 10:17:31 fca
42Changes in Lego for G4 compatibility
43
44Revision 1.12 2000/04/07 11:12:33 fca
45G4 compatibility changes
46
47Revision 1.11 2000/03/22 13:42:26 fca
48SetGenerator does not replace an existing generator, ResetGenerator does
49
50Revision 1.10 2000/02/23 16:25:22 fca
51AliVMC and AliGeant3 classes introduced
52ReadEuclid moved from AliRun to AliModule
53
54Revision 1.9 1999/12/03 10:54:01 fca
55Fix lego summary
56
57Revision 1.8 1999/10/01 09:54:33 fca
58Correct logics for Lego StepManager
59
60Revision 1.7 1999/09/29 09:24:29 fca
61Introduction of the Copyright and cvs Log
8918e700 62*/
63
64#include "AliLegoGenerator.h"
65#include "AliRun.h"
66
67ClassImp(AliLegoGenerator)
68
69//___________________________________________
34915916 70
71AliLegoGenerator::AliLegoGenerator()
72{
73 //
74 // Default Constructor
75 //
76 SetName("Lego");
77
78 fCoor1Bin = fCoor2Bin = -1;
79 fCurCoor1 = fCurCoor2 = 0;
80}
81
82AliLegoGenerator::AliLegoGenerator(Int_t nc1, Float_t c1min,
83 Float_t c1max, Int_t nc2,
84 Float_t c2min, Float_t c2max,
8918e700 85 Float_t rmin, Float_t rmax, Float_t zmax) :
34915916 86 AliGenerator(0), fRadMin(rmin), fRadMax(rmax), fZMax(zmax), fNCoor1(nc1),
87 fNCoor2(nc2), fCoor1Bin(nc1), fCoor2Bin(-1), fCurCoor1(0), fCurCoor2(0)
8918e700 88
89{
ef42d733 90 //
91 // Standard generator for Lego rays
92 //
34915916 93 SetCoor1Range(nc1, c1min, c1max);
94 SetCoor2Range(nc2, c2min, c2max);
8918e700 95 SetName("Lego");
96}
97
8918e700 98//___________________________________________
99void AliLegoGenerator::Generate()
100{
34915916 101// Create a geantino with kinematics corresponding to the current bins
102// Here: Coor1 = theta
103// Coor2 = phi.
8918e700 104
105 //
106 // Rootinos are 0
107 const Int_t kMpart = 0;
108 Float_t orig[3], pmom[3];
109 Float_t t, cost, sint, cosp, sinp;
34915916 110 if (fCoor1Bin==-1) fCoor1Bin=fNCoor1;
8918e700 111 // Prepare for next step
34915916 112 if(fCoor1Bin>=fNCoor1-1)
113 if(fCoor2Bin>=fNCoor2-1) {
8918e700 114 Warning("Generate","End of Lego Generation");
115 return;
116 } else {
34915916 117 fCoor2Bin++;
118 printf("Generating rays in phi bin:%d\n",fCoor2Bin);
119 fCoor1Bin=0;
120 } else fCoor1Bin++;
121
122 fCurCoor1 = (fCoor1Min+(fCoor1Bin+0.5)*(fCoor1Max-fCoor1Min)/fNCoor1);
123 fCurCoor2 = (fCoor2Min+(fCoor2Bin+0.5)*(fCoor2Max-fCoor2Min)/fNCoor2);
124 cost = TMath::Cos(fCurCoor1 * TMath::Pi()/180.);
125 sint = TMath::Sin(fCurCoor1 * TMath::Pi()/180.);
126 cosp = TMath::Cos(fCurCoor2 * TMath::Pi()/180.);
127 sinp = TMath::Sin(fCurCoor2 * TMath::Pi()/180.);
8918e700 128
129 pmom[0] = cosp*sint;
130 pmom[1] = sinp*sint;
131 pmom[2] = cost;
132
133 // --- Where to start
134 orig[0] = orig[1] = orig[2] = 0;
135 Float_t dalicz = 3000;
136 if (fRadMin > 0) {
34915916 137 t = PropagateCylinder(orig,pmom,fRadMin,dalicz);
138 orig[0] = pmom[0]*t;
139 orig[1] = pmom[1]*t;
140 orig[2] = pmom[2]*t;
141 if (TMath::Abs(orig[2]) > fZMax) return;
8918e700 142 }
143
144 Float_t polar[3]={0.,0.,0.};
145 Int_t ntr;
9e1a0ddb 146 gAlice->SetTrack(1, -1, kMpart, pmom, orig, polar, 0, kPPrimary, ntr);
34915916 147
8918e700 148}
149
150//___________________________________________
151Float_t AliLegoGenerator::PropagateCylinder(Float_t *x, Float_t *v, Float_t r, Float_t z)
152{
153// Propagate to cylinder from inside
154
155 Double_t hnorm, sz, t, t1, t2, t3, sr;
156 Double_t d[3];
157 const Float_t kSmall = 1e-8;
158 const Float_t kSmall2 = kSmall*kSmall;
159
160// ---> Find intesection with Z planes
161 d[0] = v[0];
162 d[1] = v[1];
163 d[2] = v[2];
164 hnorm = TMath::Sqrt(1/(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]));
165 d[0] *= hnorm;
166 d[1] *= hnorm;
167 d[2] *= hnorm;
168 if (d[2] > kSmall) sz = (z-x[2])/d[2];
169 else if (d[2] < -kSmall) sz = -(z+x[2])/d[2];
170 else sz = 1.e10; // ---> Direction parallel to X-Y, no intersection
171
172// ---> Intersection with cylinders
173// Intersection point (x,y,z)
174// (x,y,z) is on track : x=X(1)+t*D(1)
175// y=X(2)+t*D(2)
176// z=X(3)+t*D(3)
177// (x,y,z) is on cylinder : x**2 + y**2 = R**2
178//
179// (D(1)**2+D(2)**2)*t**2
180// +2.*(X(1)*D(1)+X(2)*D(2))*t
181// +X(1)**2+X(2)**2-R**2=0
182// ---> Solve second degree equation
183 t1 = d[0]*d[0] + d[1]*d[1];
184 if (t1 <= kSmall2) {
185 t = sz; // ---> Track parallel to the z-axis, take distance to planes
186 } else {
187 t2 = x[0]*d[0] + x[1]*d[1];
188 t3 = x[0]*x[0] + x[1]*x[1];
189 // ---> It should be positive, but there may be numerical problems
34915916 190 sr = (-t2 +TMath::Sqrt(TMath::Max(t2*t2-(t3-r*r)*t1,0.)))/t1;
8918e700 191 // ---> Find minimum distance between planes and cylinder
192 t = TMath::Min(sz,sr);
193 }
194 return t;
195}
196
34915916 197