]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliGenerator.cxx
Possibility to run without compilation (T.Kuhr)
[u/mrichter/AliRoot.git] / STEER / AliGenerator.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
acd84897 16/* $Id$ */
4c039060 17
5d8718b8 18//-----------------------------------------------------------------
19// Generate the final state of the interaction as the input
20// to the MonteCarlo
21// Author: A.Morsch
22//-----------------------------------------------------------------
fe4da5cc 23//Begin_Html
24/*
1439f98e 25<img src="picts/AliGeneratorClass.gif">
fe4da5cc 26</pre>
27<br clear=left>
28<font size=+2 color=red>
29<p>The responsible person for this module is
30<a href="mailto:andreas.morsch@cern.ch">Andreas Morsch</a>.
31</font>
32<pre>
33*/
34//End_Html
35// //
36///////////////////////////////////////////////////////////////////
116cbefd 37#include <TGenerator.h>
fe4da5cc 38
116cbefd 39#include "AliCollisionGeometry.h"
e2afb3b6 40#include "AliConfig.h"
fe4da5cc 41#include "AliGenerator.h"
42#include "AliRun.h"
69a313ec 43#include "AliStack.h"
5d12ce38 44#include "AliMC.h"
14248849 45#include "AliVertexGenerator.h"
69a313ec 46
fe4da5cc 47ClassImp(AliGenerator)
48
fe4da5cc 49
e2afb3b6 50//_______________________________________________________________________
51AliGenerator::AliGenerator():
f559aa82 52 fMCEvGen(0),
e2afb3b6 53 fThetaMin(0),
54 fThetaMax(0),
55 fPhiMin(0),
56 fPhiMax(0),
57 fPMin(0),
58 fPMax(0),
59 fPtMin(0),
60 fPtMax(0),
61 fYMin(0),
62 fYMax(0),
63 fVMin(3),
64 fVMax(3),
65 fNpart(0),
66 fParentWeight(0),
67 fChildWeight(0),
68 fAnalog(0),
69 fVertexSmear(kNoSmear),
0b910a04 70 fVertexSource(kInternal),
e2afb3b6 71 fCutVertexZ(0),
72 fTrackIt(0),
73 fOrigin(3),
74 fOsigma(3),
75 fVertex(3),
2c5b3727 76 fStack(0),
77 fCollisionGeometry(0)
fe4da5cc 78{
aee8290b 79 //
80 // Default constructor
81 //
f98e49f0 82 if (gAlice) {
83 if (gAlice->GetDebug()>0)
84 printf("\n AliGenerator Default Constructor\n\n");
5d12ce38 85 AliMC * mc = gAlice->GetMCApp();
86 if (mc) mc->SetGenerator(this);
f98e49f0 87 }
88
de6d59e3 89 SetThetaRange(); ResetBit(kThetaRange);
90 SetPhiRange(); ResetBit(kPhiRange);
91 SetMomentumRange(); ResetBit(kMomentumRange);
92 SetPtRange(); ResetBit(kPtRange);
93 SetYRange(); ResetBit(kYRange);
fe4da5cc 94 SetNumberParticles();
4a3ba9d2 95 SetTrackingFlag();
f98e49f0 96 SetCutVertexZ();
97
de6d59e3 98
fe4da5cc 99 fOrigin[0]=fOrigin[1]=fOrigin[2]=0;
100 fOsigma[0]=fOsigma[1]=fOsigma[2]=0;
f89cabfe 101 fVertex[0]=fVertex[1]=fVertex[2]=0;
102
de6d59e3 103 fVMin[0]=fVMin[1]=fVMin[2]=0;
de6d59e3 104 fVMax[0]=fVMax[1]=fVMax[2]=10000;
fe4da5cc 105}
106
e2afb3b6 107//_______________________________________________________________________
108AliGenerator::AliGenerator(Int_t npart):
f559aa82 109 fMCEvGen(0),
e2afb3b6 110 fThetaMin(0),
111 fThetaMax(0),
112 fPhiMin(0),
113 fPhiMax(0),
114 fPMin(0),
115 fPMax(0),
116 fPtMin(0),
117 fPtMax(0),
118 fYMin(0),
119 fYMax(0),
120 fVMin(3),
121 fVMax(3),
122 fNpart(0),
123 fParentWeight(0),
124 fChildWeight(0),
125 fAnalog(0),
126 fVertexSmear(kNoSmear),
0b910a04 127 fVertexSource(kInternal),
e2afb3b6 128 fCutVertexZ(0),
129 fTrackIt(0),
130 fOrigin(3),
131 fOsigma(3),
132 fVertex(3),
2c5b3727 133 fStack(0),
134 fCollisionGeometry(0)
fe4da5cc 135{
aee8290b 136 //
137 // Standard constructor
138 //
f98e49f0 139 if (gAlice) {
140 if (gAlice->GetDebug()>0)
141 printf("\n AliGenerator Constructor initializing number of particles \n\n");
5d12ce38 142 AliMC * mc = gAlice->GetMCApp();
143 if (mc) mc->SetGenerator(this);
f98e49f0 144 }
145
de6d59e3 146 SetThetaRange(); ResetBit(kThetaRange);
147 SetPhiRange(); ResetBit(kPhiRange);
148 SetMomentumRange(); ResetBit(kMomentumRange);
149 SetPtRange(); ResetBit(kPtRange);
150 SetYRange(); ResetBit(kYRange);
4a3ba9d2 151 SetTrackingFlag();
f98e49f0 152 SetCutVertexZ();
de6d59e3 153
fe4da5cc 154 fOrigin[0]=fOrigin[1]=fOrigin[2]=0;
155 fOsigma[0]=fOsigma[1]=fOsigma[2]=0;
f89cabfe 156 fVertex[0]=fVertex[1]=fVertex[2]=0;
157
fe4da5cc 158 fVMin[0]=fVMin[1]=fVMin[2]=0;
fe4da5cc 159 fVMax[0]=fVMax[1]=fVMax[2]=10000;
de6d59e3 160
161 SetNumberParticles(npart);
9e1a0ddb 162
69a313ec 163 AliConfig::Instance()->Add(this);
fe4da5cc 164}
165
e2afb3b6 166//_______________________________________________________________________
167AliGenerator::AliGenerator(const AliGenerator &gen):
168 TNamed(gen),
169 AliRndm(gen),
f559aa82 170 fMCEvGen(0),
e2afb3b6 171 fThetaMin(0),
172 fThetaMax(0),
173 fPhiMin(0),
174 fPhiMax(0),
175 fPMin(0),
176 fPMax(0),
177 fPtMin(0),
178 fPtMax(0),
179 fYMin(0),
180 fYMax(0),
181 fVMin(3),
182 fVMax(3),
183 fNpart(0),
184 fParentWeight(0),
185 fChildWeight(0),
186 fAnalog(0),
187 fVertexSmear(kNoSmear),
0b910a04 188 fVertexSource(kInternal),
e2afb3b6 189 fCutVertexZ(0),
190 fTrackIt(0),
191 fOrigin(3),
192 fOsigma(3),
193 fVertex(3),
e2afb3b6 194 fStack(0)
aee8290b 195{
196 //
197 // Copy constructor
198 //
199 gen.Copy(*this);
200}
201
e2afb3b6 202//_______________________________________________________________________
aee8290b 203AliGenerator & AliGenerator::operator=(const AliGenerator &gen)
204{
205 //
206 // Assignment operator
207 //
208 gen.Copy(*this);
209 return (*this);
210}
211
e2afb3b6 212//_______________________________________________________________________
6c4904c2 213void AliGenerator::Copy(TObject &/* gen */) const
aee8290b 214{
215 //
216 // Copy *this onto gen
217 //
218 Fatal("Copy","Not implemented!\n");
219}
220
e2afb3b6 221//_______________________________________________________________________
fe4da5cc 222AliGenerator::~AliGenerator()
223{
aee8290b 224 //
225 // Destructor
226 //
fe4da5cc 227 fOrigin.Set(0);
228 fOsigma.Set(0);
a08cd31a 229 if (fMCEvGen) {
230 delete fMCEvGen;
231 fMCEvGen=0;
475e6235 232 }
fe4da5cc 233}
234
e2afb3b6 235//_______________________________________________________________________
fe4da5cc 236void AliGenerator::Init()
237{
aee8290b 238 //
239 // Dummy initialisation
240 //
fe4da5cc 241}
242
94de3818 243//_______________________________________________________________________
244void AliGenerator::SetOrigin(Float_t ox, Float_t oy, Float_t oz)
245{
246 //
247 // Set the vertex for the generated tracks
248 //
249 fOrigin[0]=ox;
250 fOrigin[1]=oy;
251 fOrigin[2]=oz;
252}
253
254//_______________________________________________________________________
255void AliGenerator::SetOrigin(const TLorentzVector &o)
256{
257 //
258 // Set the vertex for the generated tracks
259 //
260 fOrigin[0]=o[0];
261 fOrigin[1]=o[1];
262 fOrigin[2]=o[2];
263}
264
265//_______________________________________________________________________
266void AliGenerator::SetSigma(Float_t sx, Float_t sy, Float_t sz)
267{
268 //
269 // Set the spread of the vertex
270 //
271 fOsigma[0]=sx;
272 fOsigma[1]=sy;
273 fOsigma[2]=sz;
274}
275
276//_______________________________________________________________________
277void AliGenerator::SetMomentumRange(Float_t pmin, Float_t pmax)
278{
279 //
280 // Set the momentum range for the generated particles
281 //
282 fPMin = pmin;
283 fPMax = pmax;
284 SetBit(kMomentumRange);
285}
286
287//_______________________________________________________________________
288void AliGenerator::SetPtRange(Float_t ptmin, Float_t ptmax)
289{
290 //
291 // Set the Pt range for the generated particles
292 //
293 fPtMin = ptmin;
294 fPtMax = ptmax;
295 SetBit(kPtRange);
296}
297
298//_______________________________________________________________________
299void AliGenerator::SetPhiRange(Float_t phimin, Float_t phimax)
300{
301 //
302 // Set the Phi range for the generated particles
303 //
304 fPhiMin = TMath::Pi()*phimin/180;
c34578e7 305 fPhiMax = TMath::Pi()*phimax/180;
306 SetBit(kPhiRange);
94de3818 307}
308
309//_______________________________________________________________________
ca3a341c 310void AliGenerator::SetYRange(Float_t ymin, Float_t ymax)
94de3818 311{
312 //
313 // Set the Rapidity range for the generated particles
314 //
315 fYMin=ymin;
316 fYMax=ymax;
317 SetBit(kYRange);
318}
319
320//_______________________________________________________________________
321void AliGenerator::SetVRange(Float_t vxmin, Float_t vxmax,
322 Float_t vymin, Float_t vymax,
323 Float_t vzmin, Float_t vzmax)
324{
325 //
326 // Set the vertex range for the generated particles
327 //
328 fVMin[0]=vxmin; fVMin[1]=vymin; fVMin[2]=vzmin;
329 fVMax[0]=vxmax; fVMax[1]=vymax; fVMax[2]=vzmax;
330 SetBit(kVertexRange);
331}
fe4da5cc 332
94de3818 333//_______________________________________________________________________
334void AliGenerator::SetThetaRange(Float_t thetamin, Float_t thetamax)
335{
336 //
337 // Set the theta range for the generated particles
338 //
339 fThetaMin = TMath::Pi()*thetamin/180;
c34578e7 340 fThetaMax = TMath::Pi()*thetamax/180;
341 SetBit(kThetaRange);
94de3818 342}
f89cabfe 343
344void AliGenerator::Vertex()
345{
346 //
347 // Obtain vertex for current event from external source or calculated (internal)
348 //
349 if (fVertexSource == kInternal) {
350 VertexInternal();
0b910a04 351 } else if (fVertexSource == kContainer) {
352 ;
353 } else if (fVertexSource == kExternal) {
f89cabfe 354 VertexExternal();
355 }
356}
357
e2afb3b6 358//_______________________________________________________________________
f89cabfe 359void AliGenerator::VertexExternal()
360{
f89cabfe 361 //
14248849 362 // Obtain vertex from external source (vertex generator)
363 //
364 TVector3 vertex = fVertexGenerator->GetVertex();
365 fVertex[0] = vertex.X();
366 fVertex[1] = vertex.Y();
367 fVertex[2] = vertex.Z();
f89cabfe 368}
369
e2afb3b6 370//_______________________________________________________________________
f89cabfe 371void AliGenerator::VertexInternal()
372{
373 //
374 // Obtain calculated vertex
375 // Default is gaussian smearing
376 Float_t random[6];
0b910a04 377 Float_t dv[3];
378 Int_t j;
0b910a04 379 dv[2] = 1.e10;
c1f70070 380 if (!TestBit(kVertexRange)) {
381 while(TMath::Abs(dv[2]) > fCutVertexZ*fOsigma[2]) {
382 Rndm(random,6);
383 for (j=0; j < 3; j++) {
384 dv[j] = fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
385 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
386 }
0b910a04 387 }
c1f70070 388 for (j=0; j < 3; j++) fVertex[j] = fOrigin[j] + dv[j];
389 } else {
390 Rndm(random,3);
391 for (j=0; j < 3; j++)
392 fVertex[j] = fVMin[j] + random[j] * (fVMax[j] - fVMin[j]);
f89cabfe 393 }
394}
395
e2afb3b6 396//_______________________________________________________________________
642f15cf 397void AliGenerator::PushTrack(Int_t done, Int_t parent, Int_t pdg,
69a313ec 398 Float_t *pmom, Float_t *vpos, Float_t *polar,
98490ea9 399 Float_t tof, TMCProcess mech, Int_t &ntr,
47c8bcbe 400 Float_t weight, Int_t is)
69a313ec 401{
116cbefd 402 //
403 // Loads one track on the stack
404 //
69a313ec 405
406 if (fStack)
642f15cf 407 fStack->PushTrack(done, parent, pdg, pmom, vpos, polar, tof,
47c8bcbe 408 mech, ntr, weight, is);
69a313ec 409 else
5d12ce38 410 gAlice->GetMCApp()->PushTrack(done, parent, pdg, pmom, vpos, polar, tof,
47c8bcbe 411 mech, ntr, weight, is);
69a313ec 412}
e2afb3b6 413
414//_______________________________________________________________________
642f15cf 415void AliGenerator::PushTrack(Int_t done, Int_t parent, Int_t pdg,
69a313ec 416 Double_t px, Double_t py, Double_t pz, Double_t e,
417 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
418 Double_t polx, Double_t poly, Double_t polz,
98490ea9 419 TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
69a313ec 420{
116cbefd 421 //
422 // Loads one track on the stack
423 //
69a313ec 424
425 if (fStack)
642f15cf 426 fStack->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
47c8bcbe 427 polx, poly, polz, mech, ntr, weight, is);
69a313ec 428 else
5d12ce38 429 gAlice->GetMCApp()->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
47c8bcbe 430 polx, poly, polz, mech, ntr, weight, is);
69a313ec 431}
f89cabfe 432
69a313ec 433
e2afb3b6 434//_______________________________________________________________________
69a313ec 435void AliGenerator:: KeepTrack(Int_t itrack)
436{
116cbefd 437 //
438 // Declare a track permanent on the stack
439 //
69a313ec 440 if (fStack)
441 fStack->KeepTrack(itrack);
442 else
5d12ce38 443 gAlice->GetMCApp()->KeepTrack(itrack);
69a313ec 444
445}
446
e2afb3b6 447//_______________________________________________________________________
69a313ec 448void AliGenerator:: SetHighWaterMark(Int_t nt)
449{
116cbefd 450 //
451 // Internal function to set the maximum index used in the stack
452 //
69a313ec 453 if (fStack)
454 fStack->SetHighWaterMark(nt);
455 else
5d12ce38 456 gAlice->GetMCApp()->SetHighWaterMark(nt);
69a313ec 457
458}
0b910a04 459void AliGenerator::FinishRun()
460{
461 ;
462}