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