]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliLego.cxx
Correct dtor, thanks to J.Belikov
[u/mrichter/AliRoot.git] / STEER / AliLego.cxx
CommitLineData
4c039060 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/*
17$Log$
838edcaf 18Revision 1.13 2000/04/26 10:17:31 fca
19Changes in Lego for G4 compatibility
20
dffd31ef 21Revision 1.12 2000/04/07 11:12:33 fca
22G4 compatibility changes
23
875c717b 24Revision 1.11 2000/03/22 13:42:26 fca
25SetGenerator does not replace an existing generator, ResetGenerator does
26
ee1dd322 27Revision 1.10 2000/02/23 16:25:22 fca
28AliVMC and AliGeant3 classes introduced
29ReadEuclid moved from AliRun to AliModule
30
b13db077 31Revision 1.9 1999/12/03 10:54:01 fca
32Fix lego summary
33
00719c1b 34Revision 1.8 1999/10/01 09:54:33 fca
35Correct logics for Lego StepManager
36
f059c84a 37Revision 1.7 1999/09/29 09:24:29 fca
38Introduction of the Copyright and cvs Log
39
4c039060 40*/
41
fe4da5cc 42//////////////////////////////////////////////////////////////
43//////////////////////////////////////////////////////////////
44//
45// Utility class to evaluate the material budget from
46// a given radius to the surface of an arbitrary cylinder
47// along radial directions from the centre:
48//
49// - radiation length
50// - Interaction length
51// - g/cm2
52//
53// Geantinos are shot in the bins in the fNtheta bins in theta
54// and fNphi bins in phi with specified rectangular limits.
55// The statistics are accumulated per
56// fRadMin < r < fRadMax and <0 < z < fZMax
57//
58// To activate this option, you can do:
59// Root > gAlice.RunLego();
60// or Root > .x menu.C then select menu item "RunLego"
61// Note that when calling gAlice->RunLego, an optional list
62// of arguments may be specified.
63//
64//Begin_Html
65/*
1439f98e 66<img src="picts/alilego.gif">
fe4da5cc 67*/
68//End_Html
69//
70//////////////////////////////////////////////////////////////
71
72#include "TMath.h"
1578254f 73#include "AliLego.h"
fe4da5cc 74#include "AliRun.h"
75#include "AliConst.h"
875c717b 76#include "AliMC.h"
fe4da5cc 77
78ClassImp(AliLego)
79
80
81//___________________________________________
82AliLego::AliLego()
83{
84 fHistRadl = 0;
85 fHistAbso = 0;
86 fHistGcm2 = 0;
87 fHistReta = 0;
88}
89
90//___________________________________________
b13db077 91AliLego::AliLego(const char *title, Int_t ntheta, Float_t themin, Float_t themax,
92 Int_t nphi, Float_t phimin, Float_t phimax,
93 Float_t rmin, Float_t rmax, Float_t zmax)
94 : TNamed("Lego Generator",title)
fe4da5cc 95{
b13db077 96// specify the angular limits and the size of the rectangular box
97
98 fGener = new AliLegoGenerator(ntheta, themin, themax,
99 nphi, phimin, phimax, rmin, rmax, zmax);
100
ee1dd322 101 gAlice->ResetGenerator(fGener);
b13db077 102
103 Float_t etamin = -TMath::Log(TMath::Tan(TMath::Min((Double_t)themax*kDegrad/2,TMath::Pi()/2-1.e-10)));
104 Float_t etamax = -TMath::Log(TMath::Tan(TMath::Max((Double_t)themin*kDegrad/2, 1.e-10)));
105
106 fHistRadl = new TH2F("hradl","Radiation length map",
107 nphi,phimin,phimax,ntheta,themin,themax);
108 fHistAbso = new TH2F("habso","Interaction length map",
109 nphi,phimin,phimax,ntheta,themin,themax);
110 fHistGcm2 = new TH2F("hgcm2","g/cm2 length map",
111 nphi,phimin,phimax,ntheta,themin,themax);
112 fHistReta = new TH2F("hetar","Radiation length vs. eta",
113 nphi,phimin,phimax,ntheta,etamin,etamax);
114
fe4da5cc 115}
116
117//___________________________________________
118AliLego::~AliLego()
119{
120 delete fHistRadl;
121 delete fHistAbso;
122 delete fHistGcm2;
123 delete fHistReta;
838edcaf 124 gAlice->ResetGenerator(0);
125 delete fGener;
fe4da5cc 126}
127
b13db077 128//___________________________________________
dffd31ef 129void AliLego::BeginEvent()
b13db077 130{
b13db077 131// --- Set to 0 radiation length, absorption length and g/cm2 ---
dffd31ef 132 fTotRadl = 0;
133 fTotAbso = 0;
134 fTotGcm2 = 0;
135}
136
137//___________________________________________
138void AliLego::FinishEvent()
139{
140 Double_t thed, phid, eta;
141 thed = fGener->CurTheta()*kRaddeg;
142 phid = fGener->CurPhi()*kRaddeg;
143 eta = -TMath::Log(TMath::Tan(TMath::Max(
b13db077 144 TMath::Min((Double_t)(fGener->CurTheta())/2,
145 TMath::Pi()/2-1.e-10),1.e-10)));
146
dffd31ef 147 fHistRadl->Fill(phid,thed,fTotRadl);
148 fHistAbso->Fill(phid,thed,fTotAbso);
149 fHistGcm2->Fill(phid,thed,fTotGcm2);
150 fHistReta->Fill(phid,eta,fTotRadl);
b13db077 151}
152
dffd31ef 153//___________________________________________
154void AliLego::FinishRun()
155{
156 // Store histograms in current Root file
157 fHistRadl->Write();
158 fHistAbso->Write();
159 fHistGcm2->Write();
160 fHistReta->Write();
161
162 // Delete histograms from memory
163 fHistRadl->Delete(); fHistRadl=0;
164 fHistAbso->Delete(); fHistAbso=0;
165 fHistGcm2->Delete(); fHistGcm2=0;
166 fHistReta->Delete(); fHistReta=0;
167
168}
169
170
b13db077 171//___________________________________________
172void AliLego::StepManager()
173{
174// called from AliRun::Stepmanager from gustep.
175// Accumulate the 3 parameters step by step
176
177 static Float_t t;
178 Float_t a,z,dens,radl,absl;
179 Int_t i;
180
181 Float_t step = gMC->TrackStep();
182
183 Float_t vect[3], dir[3];
184 TLorentzVector pos, mom;
185
186 gMC->TrackPosition(pos);
187 gMC->TrackMomentum(mom);
188 gMC->CurrentMaterial(a,z,dens,radl,absl);
189
190 if (z < 1) return;
191
192// --- See if we have to stop now
193 if (TMath::Abs(pos[2]) > fGener->ZMax() ||
194 pos[0]*pos[0] +pos[1]*pos[1] > fGener->RadMax()*fGener->RadMax()) {
195 if (gMC->TrackLength()) {
196 // Not the first step, add past contribution
197 fTotAbso += t/absl;
198 fTotRadl += t/radl;
199 fTotGcm2 += t*dens;
200 }
201 gMC->StopTrack();
202 return;
203 }
204
205// --- See how long we have to go
206 for(i=0;i<3;++i) {
207 vect[i]=pos[i];
208 dir[i]=mom[i];
209 }
210
211 t = fGener->PropagateCylinder(vect,dir,fGener->RadMax(),fGener->ZMax());
212
213 if(step) {
214 fTotAbso += step/absl;
215 fTotRadl += step/radl;
216 fTotGcm2 += step*dens;
217 }
218}
219
220ClassImp(AliLegoGenerator)
221
222//___________________________________________
223AliLegoGenerator::AliLegoGenerator(Int_t ntheta, Float_t themin,
224 Float_t themax, Int_t nphi,
225 Float_t phimin, Float_t phimax,
226 Float_t rmin, Float_t rmax, Float_t zmax) :
227 AliGenerator(0), fRadMin(rmin), fRadMax(rmax), fZMax(zmax), fNtheta(ntheta),
228 fNphi(nphi), fThetaBin(ntheta), fPhiBin(-1), fCurTheta(0), fCurPhi(0)
229
230{
231 SetPhiRange(phimin,phimax);
232 SetThetaRange(themin,themax);
233 SetName("Lego");
234}
235
236
fe4da5cc 237//___________________________________________
b13db077 238void AliLegoGenerator::Generate()
fe4da5cc 239{
240// Create a geantino with kinematics corresponding to the current
241// bins in theta and phi.
242
1578254f 243 //
244 // Rootinos are 0
245 const Int_t mpart = 0;
fe4da5cc 246 Float_t orig[3], pmom[3];
247 Float_t t, cost, sint, cosp, sinp;
248
b13db077 249 // Prepare for next step
250 if(fThetaBin>=fNtheta-1)
251 if(fPhiBin>=fNphi-1) {
252 Warning("Generate","End of Lego Generation");
253 return;
254 } else {
255 fPhiBin++;
256 printf("Generating rays in phi bin:%d\n",fPhiBin);
257 fThetaBin=0;
258 } else fThetaBin++;
fe4da5cc 259
b13db077 260 fCurTheta = (fThetaMin+(fThetaBin+0.5)*(fThetaMax-fThetaMin)/fNtheta);
261 fCurPhi = (fPhiMin+(fPhiBin+0.5)*(fPhiMax-fPhiMin)/fNphi);
fe4da5cc 262 cost = TMath::Cos(fCurTheta);
263 sint = TMath::Sin(fCurTheta);
264 cosp = TMath::Cos(fCurPhi);
265 sinp = TMath::Sin(fCurPhi);
b13db077 266
fe4da5cc 267 pmom[0] = cosp*sint;
268 pmom[1] = sinp*sint;
269 pmom[2] = cost;
b13db077 270
271 // --- Where to start
fe4da5cc 272 orig[0] = orig[1] = orig[2] = 0;
273 Float_t dalicz = 3000;
274 if (fRadMin > 0) {
b13db077 275 t = PropagateCylinder(orig,pmom,fRadMin,dalicz);
276 orig[0] = pmom[0]*t;
277 orig[1] = pmom[1]*t;
278 orig[2] = pmom[2]*t;
279 if (TMath::Abs(orig[2]) > fZMax) return;
fe4da5cc 280 }
b13db077 281
fe4da5cc 282 Float_t polar[3]={0.,0.,0.};
283 Int_t ntr;
284 gAlice->SetTrack(1, 0, mpart, pmom, orig, polar, 0, "LEGO ray", ntr);
fe4da5cc 285
286}
287
288//___________________________________________
b13db077 289Float_t AliLegoGenerator::PropagateCylinder(Float_t *x, Float_t *v, Float_t r, Float_t z)
fe4da5cc 290{
291// Propagate to cylinder from inside
292
293 Double_t hnorm, sz, t, t1, t2, t3, sr;
294 Double_t d[3];
295 const Float_t kSmall = 1e-8;
296 const Float_t kSmall2 = kSmall*kSmall;
297
298// ---> Find intesection with Z planes
299 d[0] = v[0];
300 d[1] = v[1];
301 d[2] = v[2];
302 hnorm = TMath::Sqrt(1/(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]));
303 d[0] *= hnorm;
304 d[1] *= hnorm;
305 d[2] *= hnorm;
306 if (d[2] > kSmall) sz = (z-x[2])/d[2];
307 else if (d[2] < -kSmall) sz = -(z+x[2])/d[2];
308 else sz = 1.e10; // ---> Direction parallel to X-Y, no intersection
309
310// ---> Intersection with cylinders
311// Intersection point (x,y,z)
312// (x,y,z) is on track : x=X(1)+t*D(1)
313// y=X(2)+t*D(2)
314// z=X(3)+t*D(3)
315// (x,y,z) is on cylinder : x**2 + y**2 = R**2
316//
317// (D(1)**2+D(2)**2)*t**2
318// +2.*(X(1)*D(1)+X(2)*D(2))*t
319// +X(1)**2+X(2)**2-R**2=0
320// ---> Solve second degree equation
321 t1 = d[0]*d[0] + d[1]*d[1];
322 if (t1 <= kSmall2) {
323 t = sz; // ---> Track parallel to the z-axis, take distance to planes
324 } else {
325 t2 = x[0]*d[0] + x[1]*d[1];
326 t3 = x[0]*x[0] + x[1]*x[1];
327 // ---> It should be positive, but there may be numerical problems
328 sr = (t2 +TMath::Sqrt(TMath::Max(t2*t2-(t3-r*r)*t1,0.)))/t1;
329 // ---> Find minimum distance between planes and cylinder
330 t = TMath::Min(sz,sr);
331 }
332 return t;
333}
334