]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliLegoGenerator.cxx
Introducing Header instead of Log
[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
fb17acd4 16/* $Header$ */
8918e700 17
18#include "AliLegoGenerator.h"
19#include "AliRun.h"
20
21ClassImp(AliLegoGenerator)
22
e2afb3b6 23//_______________________________________________________________________
24AliLegoGenerator::AliLegoGenerator():
25 fRadMin(0),
26 fRadMax(0),
27 fZMax(0),
28 fNCoor1(0),
29 fNCoor2(0),
30 fCoor1Min(0),
31 fCoor1Max(0),
32 fCoor2Min(0),
33 fCoor2Max(0),
34 fCoor1Bin(-1),
35 fCoor2Bin(-1),
36 fCurCoor1(0),
37 fCurCoor2(0)
34915916 38{
39 //
40 // Default Constructor
41 //
42 SetName("Lego");
34915916 43}
44
e2afb3b6 45//_______________________________________________________________________
34915916 46AliLegoGenerator::AliLegoGenerator(Int_t nc1, Float_t c1min,
e2afb3b6 47 Float_t c1max, Int_t nc2,
48 Float_t c2min, Float_t c2max,
49 Float_t rmin, Float_t rmax, Float_t zmax):
50 AliGenerator(0),
51 fRadMin(rmin),
52 fRadMax(rmax),
53 fZMax(zmax),
54 fNCoor1(nc1),
55 fNCoor2(nc2),
56 fCoor1Min(0),
57 fCoor1Max(0),
58 fCoor2Min(0),
59 fCoor2Max(0),
60 fCoor1Bin(nc1),
61 fCoor2Bin(-1),
62 fCurCoor1(0),
63 fCurCoor2(0)
8918e700 64{
ef42d733 65 //
66 // Standard generator for Lego rays
67 //
e2afb3b6 68 SetName("Lego");
34915916 69 SetCoor1Range(nc1, c1min, c1max);
70 SetCoor2Range(nc2, c2min, c2max);
8918e700 71}
72
e2afb3b6 73//_______________________________________________________________________
8918e700 74void AliLegoGenerator::Generate()
75{
e2afb3b6 76 // Create a geantino with kinematics corresponding to the current bins
77 // Here: Coor1 = theta
78 // Coor2 = phi.
79
8918e700 80 //
81 // Rootinos are 0
82 const Int_t kMpart = 0;
83 Float_t orig[3], pmom[3];
84 Float_t t, cost, sint, cosp, sinp;
34915916 85 if (fCoor1Bin==-1) fCoor1Bin=fNCoor1;
8918e700 86 // Prepare for next step
34915916 87 if(fCoor1Bin>=fNCoor1-1)
88 if(fCoor2Bin>=fNCoor2-1) {
8918e700 89 Warning("Generate","End of Lego Generation");
90 return;
91 } else {
34915916 92 fCoor2Bin++;
93 printf("Generating rays in phi bin:%d\n",fCoor2Bin);
94 fCoor1Bin=0;
95 } else fCoor1Bin++;
96
97 fCurCoor1 = (fCoor1Min+(fCoor1Bin+0.5)*(fCoor1Max-fCoor1Min)/fNCoor1);
98 fCurCoor2 = (fCoor2Min+(fCoor2Bin+0.5)*(fCoor2Max-fCoor2Min)/fNCoor2);
99 cost = TMath::Cos(fCurCoor1 * TMath::Pi()/180.);
100 sint = TMath::Sin(fCurCoor1 * TMath::Pi()/180.);
101 cosp = TMath::Cos(fCurCoor2 * TMath::Pi()/180.);
102 sinp = TMath::Sin(fCurCoor2 * TMath::Pi()/180.);
8918e700 103
104 pmom[0] = cosp*sint;
105 pmom[1] = sinp*sint;
106 pmom[2] = cost;
107
108 // --- Where to start
109 orig[0] = orig[1] = orig[2] = 0;
110 Float_t dalicz = 3000;
111 if (fRadMin > 0) {
34915916 112 t = PropagateCylinder(orig,pmom,fRadMin,dalicz);
113 orig[0] = pmom[0]*t;
114 orig[1] = pmom[1]*t;
115 orig[2] = pmom[2]*t;
116 if (TMath::Abs(orig[2]) > fZMax) return;
8918e700 117 }
118
119 Float_t polar[3]={0.,0.,0.};
120 Int_t ntr;
9e1a0ddb 121 gAlice->SetTrack(1, -1, kMpart, pmom, orig, polar, 0, kPPrimary, ntr);
34915916 122
8918e700 123}
124
e2afb3b6 125//_______________________________________________________________________
126Float_t AliLegoGenerator::PropagateCylinder(Float_t *x, Float_t *v, Float_t r,
127 Float_t z)
8918e700 128{
e2afb3b6 129 //
130 // Propagate to cylinder from inside
131 //
8918e700 132 Double_t hnorm, sz, t, t1, t2, t3, sr;
133 Double_t d[3];
134 const Float_t kSmall = 1e-8;
135 const Float_t kSmall2 = kSmall*kSmall;
136
137// ---> Find intesection with Z planes
138 d[0] = v[0];
139 d[1] = v[1];
140 d[2] = v[2];
141 hnorm = TMath::Sqrt(1/(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]));
142 d[0] *= hnorm;
143 d[1] *= hnorm;
144 d[2] *= hnorm;
145 if (d[2] > kSmall) sz = (z-x[2])/d[2];
146 else if (d[2] < -kSmall) sz = -(z+x[2])/d[2];
147 else sz = 1.e10; // ---> Direction parallel to X-Y, no intersection
148
149// ---> Intersection with cylinders
150// Intersection point (x,y,z)
151// (x,y,z) is on track : x=X(1)+t*D(1)
152// y=X(2)+t*D(2)
153// z=X(3)+t*D(3)
154// (x,y,z) is on cylinder : x**2 + y**2 = R**2
155//
156// (D(1)**2+D(2)**2)*t**2
157// +2.*(X(1)*D(1)+X(2)*D(2))*t
158// +X(1)**2+X(2)**2-R**2=0
159// ---> Solve second degree equation
160 t1 = d[0]*d[0] + d[1]*d[1];
161 if (t1 <= kSmall2) {
162 t = sz; // ---> Track parallel to the z-axis, take distance to planes
163 } else {
164 t2 = x[0]*d[0] + x[1]*d[1];
165 t3 = x[0]*x[0] + x[1]*x[1];
166 // ---> It should be positive, but there may be numerical problems
34915916 167 sr = (-t2 +TMath::Sqrt(TMath::Max(t2*t2-(t3-r*r)*t1,0.)))/t1;
8918e700 168 // ---> Find minimum distance between planes and cylinder
169 t = TMath::Min(sz,sr);
170 }
171 return t;
172}
173
34915916 174