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