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