AliRoot Core  3dc7879 (3dc7879)
AliGenerator.cxx
Go to the documentation of this file.
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 /* $Id$ */
17 
18 //-----------------------------------------------------------------
19 // Generate the final state of the interaction as the input
20 // to the MonteCarlo
21 // Author: A.Morsch
22 //-----------------------------------------------------------------
23 //Begin_Html
24 /*
25 <img src="picts/AliGeneratorClass.gif">
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 // //
37 #include <TGenerator.h>
38 #include <TMCProcess.h>
39 
40 #include "AliLog.h"
41 #include "AliCollisionGeometry.h"
42 #include "AliConfig.h"
43 #include "AliGenerator.h"
44 #include "AliRun.h"
45 #include "AliStack.h"
46 #include "AliMC.h"
47 #include "AliVertexGenerator.h"
48 
49 ClassImp(AliGenerator)
50 
51 
52 //_______________________________________________________________________
54  TNamed(),
55  AliRndm(),
56  fMCEvGen(0),
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),
74  fVertexSource(kInternal),
75  fCutVertexZ(0),
76  fPileUpTimeWindow(-1.),
77  fTrackIt(0),
78  fVertexGenerator(0),
79  fOrigin(3),
80  fOsigma(3),
81  fVertex(3),
82  fTimeOrigin(0.),
83  fTime(0.),
84  fEvPlane(0),
85  fStack(0),
86  fContainer(0),
87  fCollisionGeometry(0),
88  fEnergyCMS(0),
89  fAProjectile(0),
90  fZProjectile(0),
91  fATarget(0),
92  fZTarget(0),
93  fProjectile(""),
94  fTarget("")
95 {
96  //
97  // Default constructor
98  //
99  if (gAlice) {
100  AliDebug(1, "AliGenerator Default Constructor");
101  AliMC * mc = gAlice->GetMCApp();
102  if (mc) mc->SetGenerator(this);
103  }
104 
105  SetThetaRange(); ResetBit(kThetaRange);
106  SetPhiRange(); ResetBit(kPhiRange);
107  SetMomentumRange(); ResetBit(kMomentumRange);
108  SetPtRange(); ResetBit(kPtRange);
109  SetYRange(); ResetBit(kYRange);
110  SetNumberParticles();
111  SetTrackingFlag();
112  SetCutVertexZ();
113 
114 
115  fOrigin[0]=fOrigin[1]=fOrigin[2]=0;
116  fOsigma[0]=fOsigma[1]=fOsigma[2]=0;
117  fVertex[0]=fVertex[1]=fVertex[2]=0;
118 
119  fVMin[0]=fVMin[1]=fVMin[2]=0;
120  fVMax[0]=fVMax[1]=fVMax[2]=10000;
121 }
122 
123 //_______________________________________________________________________
125  TNamed(),
126  AliRndm(),
127  fMCEvGen(0),
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),
145  fVertexSource(kInternal),
146  fCutVertexZ(0),
147  fPileUpTimeWindow(-1.),
148  fTrackIt(0),
149  fVertexGenerator(0),
150  fOrigin(3),
151  fOsigma(3),
152  fVertex(3),
153  fTimeOrigin(0.),
154  fTime(0.),
155  fEvPlane(0),
156  fStack(0),
157  fContainer(0),
158  fCollisionGeometry(0),
159  fEnergyCMS(0),
160  fAProjectile(0),
161  fZProjectile(0),
162  fATarget(0),
163  fZTarget(0),
164  fProjectile(""),
165  fTarget("")
166 {
167  //
168  // Standard constructor
169  //
170  if (gAlice) {
171  AliDebug(1, "AliGenerator Constructor initializing number of particles");
172  AliMC * mc = gAlice->GetMCApp();
173  if (mc) mc->SetGenerator(this);
174  }
175 
176  SetThetaRange(); ResetBit(kThetaRange);
177  SetPhiRange(); ResetBit(kPhiRange);
178  SetMomentumRange(); ResetBit(kMomentumRange);
179  SetPtRange(); ResetBit(kPtRange);
180  SetYRange(); ResetBit(kYRange);
181  SetTrackingFlag();
182  SetCutVertexZ();
183 
184  fOrigin[0]=fOrigin[1]=fOrigin[2]=0;
185  fOsigma[0]=fOsigma[1]=fOsigma[2]=0;
186  fVertex[0]=fVertex[1]=fVertex[2]=0;
187 
188  fVMin[0]=fVMin[1]=fVMin[2]=0;
189  fVMax[0]=fVMax[1]=fVMax[2]=10000;
190 
191  SetNumberParticles(npart);
192 
193  AliConfig::Instance()->Add(this);
194 }
195 
196 //_______________________________________________________________________
198 {
199  //
200  // Destructor
201  //
202  fOrigin.Set(0);
203  fOsigma.Set(0);
204  if (fMCEvGen) {
205  delete fMCEvGen;
206  fMCEvGen=0;
207  }
208 }
209 
210 //_______________________________________________________________________
212 {
213  //
214  // Dummy initialisation
215  //
216 }
217 
218 //_______________________________________________________________________
220 {
221 //
222 // Run generator n times
223 // Used by AliGenCocktail for adding extra signals in proportion to
224 // multiplicity/centrality
225 // By default generates one AliGenHeader for each call to Generate()
226 // Can be overloaded (e.g. AliGenBox and AliGenParam) to consolidate headers
227 //
228  for (Int_t i=0; i < ntimes; i++) {
229  Generate();
230  }
231 }
232 //_______________________________________________________________________
233 void AliGenerator::SetOrigin(Float_t ox, Float_t oy, Float_t oz)
234 {
235  //
236  // Set the vertex for the generated tracks
237  //
238  fOrigin[0]=ox;
239  fOrigin[1]=oy;
240  fOrigin[2]=oz;
241 }
242 
243 //_______________________________________________________________________
244 void AliGenerator::SetOrigin(const TLorentzVector &o)
245 {
246  //
247  // Set the vertex for the generated tracks
248  //
249  fOrigin[0]=o[0];
250  fOrigin[1]=o[1];
251  fOrigin[2]=o[2];
252 }
253 
254 //_______________________________________________________________________
255 void AliGenerator::SetSigma(Float_t sx, Float_t sy, Float_t sz)
256 {
257  //
258  // Set the spread of the vertex
259  //
260  fOsigma[0]=sx;
261  fOsigma[1]=sy;
262  fOsigma[2]=sz;
263 }
264 
265 //_______________________________________________________________________
266 void AliGenerator::SetMomentumRange(Float_t pmin, Float_t pmax)
267 {
268  //
269  // Set the momentum range for the generated particles
270  //
271  fPMin = pmin;
272  fPMax = pmax;
273  SetBit(kMomentumRange);
274 }
275 
276 //_______________________________________________________________________
277 void AliGenerator::SetPtRange(Float_t ptmin, Float_t ptmax)
278 {
279  //
280  // Set the Pt range for the generated particles
281  //
282  fPtMin = ptmin;
283  fPtMax = ptmax;
284  SetBit(kPtRange);
285 }
286 
287 //_______________________________________________________________________
288 void AliGenerator::SetPhiRange(Float_t phimin, Float_t phimax)
289 {
290  //
291  // Set the Phi range for the generated particles
292  //
293  fPhiMin = TMath::Pi()*phimin/180;
294  fPhiMax = TMath::Pi()*phimax/180;
295  SetBit(kPhiRange);
296 }
297 
298 //_______________________________________________________________________
299 void AliGenerator::SetYRange(Float_t ymin, Float_t ymax)
300 {
301  //
302  // Set the Rapidity range for the generated particles
303  //
304  fYMin=ymin;
305  fYMax=ymax;
306  SetBit(kYRange);
307 }
308 
309 //_______________________________________________________________________
310 void AliGenerator::SetVRange(Float_t vxmin, Float_t vxmax,
311  Float_t vymin, Float_t vymax,
312  Float_t vzmin, Float_t vzmax)
313 {
314  //
315  // Set the vertex range for the generated particles
316  //
317  fVMin[0]=vxmin; fVMin[1]=vymin; fVMin[2]=vzmin;
318  fVMax[0]=vxmax; fVMax[1]=vymax; fVMax[2]=vzmax;
319  SetBit(kVertexRange);
320 }
321 
322 //_______________________________________________________________________
323 void AliGenerator::SetThetaRange(Float_t thetamin, Float_t thetamax)
324 {
325  //
326  // Set the theta range for the generated particles
327  //
328  fThetaMin = TMath::Pi()*thetamin/180;
329  fThetaMax = TMath::Pi()*thetamax/180;
330  SetBit(kThetaRange);
331 }
332 
334 {
335  //
336  // Obtain vertex for current event from external source or calculated (internal)
337  //
338  if (fVertexSource == kInternal) {
339  VertexInternal();
340  } else if (fVertexSource == kContainer) {
341  ;
342  } else if (fVertexSource == kExternal) {
343  VertexExternal();
344  }
345 }
346 
347 //_______________________________________________________________________
349 {
350  //
351  // Obtain vertex from external source (vertex generator)
352  //
353  TVector3 vertex = fVertexGenerator->GetVertex();
354  fVertex[0] = vertex.X();
355  fVertex[1] = vertex.Y();
356  fVertex[2] = vertex.Z();
358 }
359 
360 //_______________________________________________________________________
362 {
363  //
364  // Obtain calculated vertex
365  // Default is gaussian smearing
366  Float_t random[6];
367  Float_t dv[3];
368  Int_t j;
369  dv[2] = 1.e10;
370  if (!TestBit(kVertexRange)) {
371  while(TMath::Abs(dv[2]) > fCutVertexZ*fOsigma[2]) {
372  Rndm(random,6);
373  for (j=0; j < 3; j++) {
374  dv[j] = fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
375  TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
376  }
377  }
378  for (j=0; j < 3; j++) fVertex[j] = fOrigin[j] + dv[j];
379 
380  // In case of gaussian smearing we smear also the event/collision time
381  Rndm(random,2);
382  fTime = fTimeOrigin + fOsigma[2]/TMath::Ccgs()*
383  TMath::Cos(2*random[0]*TMath::Pi())*
384  TMath::Sqrt(-2*TMath::Log(random[1]));
385 
386  } else {
387  Rndm(random,3);
388  for (j=0; j < 3; j++)
389  fVertex[j] = fVMin[j] + random[j] * (fVMax[j] - fVMin[j]);
390  fTime = 0.;
391  }
392 }
393 
394 //_______________________________________________________________________
395 void AliGenerator::PushTrack(Int_t done, Int_t parent, Int_t pdg,
396  Float_t *pmom, Float_t *vpos, Float_t *polar,
397  Float_t tof, TMCProcess mech, Int_t &ntr,
398  Float_t weight, Int_t is)
399 {
400  //
401  // Loads one track on the stack
402  //
403 
404  if (fStack)
405  fStack->PushTrack(done, parent, pdg, pmom, vpos, polar, tof,
406  mech, ntr, weight, is);
407  else
408  gAlice->GetMCApp()->PushTrack(done, parent, pdg, pmom, vpos, polar, tof,
409  mech, ntr, weight, is);
410 }
411 
412 //_______________________________________________________________________
413 void AliGenerator::PushTrack(Int_t done, Int_t parent, Int_t pdg,
414  Double_t px, Double_t py, Double_t pz, Double_t e,
415  Double_t vx, Double_t vy, Double_t vz, Double_t tof,
416  Double_t polx, Double_t poly, Double_t polz,
417  TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
418 {
419  //
420  // Loads one track on the stack
421  //
422 
423  if (fStack)
424  fStack->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
425  polx, poly, polz, mech, ntr, weight, is);
426  else
427  gAlice->GetMCApp()->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
428  polx, poly, polz, mech, ntr, weight, is);
429 }
430 
431 
432 //_______________________________________________________________________
433 void AliGenerator:: KeepTrack(Int_t itrack)
434 {
435  //
436  // Declare a track permanent on the stack
437  //
438  if (fStack)
439  fStack->KeepTrack(itrack);
440  else
441  gAlice->GetMCApp()->KeepTrack(itrack);
442 
443 }
444 
445 //_______________________________________________________________________
447 {
448  //
449  // Internal function to set the maximum index used in the stack
450  //
451  if (fStack)
453  else
455 
456 }
458 {
459  ;
460 }
461 
462 //_______________________________________________________________________
464 {
465  //
466  // function to set the seed in the random number generator used by this generator
467  //
468  GetRandom()->SetSeed(seed);
469 }
Float_t fThetaMax
Definition: fastMUONSim.C:57
virtual Float_t GetLastVertexTime()
void SetHighWaterMark(Int_t hgwmk)
Definition: AliStack.cxx:676
virtual void GenerateN(Int_t ntimes)
Float_t fThetaMin
Pointer to the generator.
Definition: AliGenerator.h:129
virtual void SetSeed(UInt_t seed)
const Int_t nt
Definition: pdfIO.C:2
Float_t fYMin
Definition: AliGenerator.h:137
Float_t fPMin
Definition: AliGenerator.h:133
virtual void SetPtRange(Float_t ptmin=0, Float_t ptmax=1.e10)
virtual void FinishRun()
virtual void SetNumberParticles(Int_t npart=100)
Definition: AliGenerator.h:53
virtual void SetMomentumRange(Float_t pmin=0, Float_t pmax=1.e10)
TGenerator * fMCEvGen
Definition: AliGenerator.h:128
Float_t fPhiMax
Definition: AliGenerator.h:132
TVectorD vz
Definition: driftITSTPC.C:87
Float_t fCutVertexZ
Definition: AliGenerator.h:148
virtual ~AliGenerator()
virtual void SetHighWaterMark(Int_t nt)
Float_t fThetaMin
Definition: fastMUONSim.C:57
TArrayF fVMax
Definition: AliGenerator.h:140
virtual void SetCutVertexZ(Float_t cut=999999.)
Definition: AliGenerator.h:62
void Add(TDatabasePDG *pdg)
Definition: AliConfig.cxx:180
Float_t fYMax
Definition: AliGenerator.h:138
Float_t fPhiMin
Definition: AliGenerator.h:131
void VertexExternal()
virtual void KeepTrack(Int_t itra) const
Definition: AliMC.cxx:1966
VertexSource_t fVertexSource
Definition: AliGenerator.h:147
TArrayF fVMin
Definition: AliGenerator.h:139
Float_t fTime
Definition: AliGenerator.h:157
virtual void SetOrigin(Float_t ox, Float_t oy, Float_t oz)
virtual Float_t Rndm() const
Definition: AliRndm.h:35
void polar()
Definition: polar.C:2
virtual void KeepTrack(Int_t itrack)
AliRun * gAlice
Definition: AliRun.cxx:62
virtual void SetPhiRange(Float_t phimin=0., Float_t phimax=360.)
Float_t fThetaMax
Definition: AliGenerator.h:130
const int ntimes
Definition: kNNSpeed.C:14
void KeepTrack(Int_t itrack)
Definition: AliStack.cxx:627
Float_t fPtMax
Definition: AliGenerator.h:136
virtual void PushTrack(Int_t done, Int_t parent, Int_t pdg, const Float_t *pmom, const Float_t *vpos, const Float_t *polar, Float_t tof, TMCProcess mech, Int_t &ntr, Float_t weight=1, Int_t is=0) const
Definition: AliMC.cxx:1925
virtual void SetVRange(Float_t vxmin, Float_t vxmax, Float_t vymin, Float_t vymax, Float_t vzmin, Float_t vzmax)
static UInt_t seed
Definition: pdc06_config.C:131
virtual void SetHighWaterMark(Int_t nt) const
Definition: AliMC.cxx:1955
Definition: AliMC.h:30
virtual TRandom * GetRandom() const
Definition: AliRndm.h:30
virtual void SetYRange(Float_t ymin=-100, Float_t ymax=100)
virtual TVector3 GetVertex()=0
virtual void PushTrack(Int_t done, Int_t parent, Int_t pdg, const Float_t *pmom, const Float_t *vpos, const Float_t *polar, Float_t tof, TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
Definition: AliStack.cxx:138
virtual void Generate()=0
AliVertexGenerator * fVertexGenerator
Definition: AliGenerator.h:151
TArrayF fVertex
Definition: AliGenerator.h:154
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
virtual void SetTrackingFlag(Int_t flag=1)
Definition: AliGenerator.h:75
Float_t fPtMin
Definition: AliGenerator.h:135
virtual void SetGenerator(AliGenerator *generator)
Definition: AliMC.cxx:1123
virtual void Init()
virtual void SetSigma(Float_t sx, Float_t sy, Float_t sz)
virtual void SetThetaRange(Float_t thetamin=0, Float_t thetamax=180)
TArrayF fOrigin
Generator for the vertex.
Definition: AliGenerator.h:152
TArrayF fOsigma
Definition: AliGenerator.h:153
virtual void VertexInternal()
Float_t fTimeOrigin
Vertex of current event.
Definition: AliGenerator.h:156
Float_t fPMax
Definition: AliGenerator.h:134
AliStack * fStack
Definition: AliGenerator.h:160
static AliConfig * Instance()
Definition: AliConfig.cxx:87
AliMC * GetMCApp() const
Definition: AliRun.h:53
virtual void PushTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom, Float_t *vpos, Float_t *polar, Float_t tof, TMCProcess mech, Int_t &ntr, Float_t weight=1, Int_t is=0)