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"
29 ClassImp(AliLegoGenerator)
31 //_______________________________________________________________________
32 AliLegoGenerator::AliLegoGenerator():
48 // Default Constructor
53 //_______________________________________________________________________
54 AliLegoGenerator::AliLegoGenerator(Int_t nc1, Float_t c1min,
55 Float_t c1max, Int_t nc2,
56 Float_t c2min, Float_t c2max,
57 Float_t rmin, Float_t rmax, Float_t zmax):
74 // Standard generator for Lego rays
77 SetCoor1Range(nc1, c1min, c1max);
78 SetCoor2Range(nc2, c2min, c2max);
81 //_______________________________________________________________________
82 void AliLegoGenerator::Generate()
84 // Create a geantino with kinematics corresponding to the current bins
85 // Here: Coor1 = theta
90 const Int_t kMpart = 0;
91 Float_t orig[3], pmom[3];
92 Float_t t, cost, sint, cosp, sinp;
93 if (fCoor1Bin==-1) fCoor1Bin=fNCoor1;
94 // Prepare for next step
95 if(fCoor1Bin>=fNCoor1-1)
96 if(fCoor2Bin>=fNCoor2-1) {
97 Warning("Generate","End of Lego Generation");
101 printf("Generating rays in phi bin:%d\n",fCoor2Bin);
105 fCurCoor1 = (fCoor1Min+(fCoor1Bin+0.5)*(fCoor1Max-fCoor1Min)/fNCoor1);
106 fCurCoor2 = (fCoor2Min+(fCoor2Bin+0.5)*(fCoor2Max-fCoor2Min)/fNCoor2);
107 cost = TMath::Cos(fCurCoor1 * TMath::Pi()/180.);
108 sint = TMath::Sin(fCurCoor1 * TMath::Pi()/180.);
109 cosp = TMath::Cos(fCurCoor2 * TMath::Pi()/180.);
110 sinp = TMath::Sin(fCurCoor2 * TMath::Pi()/180.);
116 // --- Where to start
117 orig[0] = orig[1] = orig[2] = 0;
118 Float_t dalicz = 3000;
120 t = PropagateCylinder(orig,pmom,fRadMin,dalicz);
124 if (TMath::Abs(orig[2]) > fZMax) return;
127 Float_t polar[3]={0.,0.,0.};
129 gAlice->GetMCApp()->PushTrack(1, -1, kMpart, pmom, orig, polar, 0, kPPrimary, ntr);
133 //_______________________________________________________________________
134 Float_t AliLegoGenerator::PropagateCylinder(Float_t *x, Float_t *v, Float_t r,
138 // Propagate to cylinder from inside
140 Double_t hnorm, sz, t, t1, t2, t3, sr;
142 const Float_t kSmall = 1e-8;
143 const Float_t kSmall2 = kSmall*kSmall;
145 // ---> Find intesection with Z planes
149 hnorm = TMath::Sqrt(1/(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]));
153 if (d[2] > kSmall) sz = (z-x[2])/d[2];
154 else if (d[2] < -kSmall) sz = -(z+x[2])/d[2];
155 else sz = 1.e10; // ---> Direction parallel to X-Y, no intersection
157 // ---> Intersection with cylinders
158 // Intersection point (x,y,z)
159 // (x,y,z) is on track : x=X(1)+t*D(1)
162 // (x,y,z) is on cylinder : x**2 + y**2 = R**2
164 // (D(1)**2+D(2)**2)*t**2
165 // +2.*(X(1)*D(1)+X(2)*D(2))*t
166 // +X(1)**2+X(2)**2-R**2=0
167 // ---> Solve second degree equation
168 t1 = d[0]*d[0] + d[1]*d[1];
170 t = sz; // ---> Track parallel to the z-axis, take distance to planes
172 t2 = x[0]*d[0] + x[1]*d[1];
173 t3 = x[0]*x[0] + x[1]*x[1];
174 // ---> It should be positive, but there may be numerical problems
175 sr = (-t2 +TMath::Sqrt(TMath::Max(t2*t2-(t3-r*r)*t1,0.)))/t1;
176 // ---> Find minimum distance between planes and cylinder
177 t = TMath::Min(sz,sr);