1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //------------------------------------------------------------------------
19 // Generic Lego generator code
20 // Uses geantino rays to check the material distributions and detector's
23 //------------------------------------------------------------------------
25 #include "AliLegoGenerator.h"
30 ClassImp(AliLegoGenerator)
32 //_______________________________________________________________________
33 AliLegoGenerator::AliLegoGenerator():
49 // Default Constructor
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):
75 // Standard generator for Lego rays
78 SetCoor1Range(nc1, c1min, c1max);
79 SetCoor2Range(nc2, c2min, c2max);
82 //_______________________________________________________________________
83 void AliLegoGenerator::Generate()
85 // Create a geantino with kinematics corresponding to the current bins
86 // Here: Coor1 = theta
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");
102 AliDebug(1, Form("Generating rays in phi bin:%d",fCoor2Bin));
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.);
117 // --- Where to start
118 orig[0] = orig[1] = orig[2] = 0;
119 Float_t dalicz = 3000;
121 t = PropagateCylinder(orig,pmom,fRadMin,dalicz);
125 if (TMath::Abs(orig[2]) > fZMax) return;
128 Float_t polar[3]={0.,0.,0.};
130 gAlice->GetMCApp()->PushTrack(1, -1, kMpart, pmom, orig, polar, 0, kPPrimary, ntr);
134 //_______________________________________________________________________
135 Float_t AliLegoGenerator::PropagateCylinder(Float_t *x, Float_t *v, Float_t r,
139 // Propagate to cylinder from inside
141 Double_t hnorm, sz, t, t1, t2, t3, sr;
143 const Float_t kSmall = 1e-8;
144 const Float_t kSmall2 = kSmall*kSmall;
146 // ---> Find intesection with Z planes
150 hnorm = TMath::Sqrt(1/(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]));
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
158 // ---> Intersection with cylinders
159 // Intersection point (x,y,z)
160 // (x,y,z) is on track : x=X(1)+t*D(1)
163 // (x,y,z) is on cylinder : x**2 + y**2 = R**2
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];
171 t = sz; // ---> Track parallel to the z-axis, take distance to planes
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);