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