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