]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliGenerator.cxx
Access to the stack using AliRunLoader (Yu.Belikov)
[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
39 #include "AliCollisionGeometry.h"
40 #include "AliConfig.h"
41 #include "AliGenerator.h"
42 #include "AliRun.h"
43 #include "AliStack.h"
44 #include "AliMC.h"
45
46 ClassImp(AliGenerator)
47
48
49 //_______________________________________________________________________
50 AliGenerator::AliGenerator():
51   fMCEvGen(0),
52   fThetaMin(0),
53   fThetaMax(0),
54   fPhiMin(0),
55   fPhiMax(0),
56   fPMin(0),
57   fPMax(0),
58   fPtMin(0),
59   fPtMax(0),
60   fYMin(0),
61   fYMax(0),
62   fVMin(3),
63   fVMax(3),
64   fNpart(0),
65   fParentWeight(0),
66   fChildWeight(0),
67   fAnalog(0),
68   fVertexSmear(kNoSmear),
69   fVertexSource(kInternal),
70   fCutVertexZ(0),
71   fTrackIt(0),
72   fOrigin(3),
73   fOsigma(3),
74   fVertex(3),
75   fStack(0),
76   fCollisionGeometry(0)
77 {
78   //
79   // Default constructor
80   //
81     if (gAlice) {
82         if (gAlice->GetDebug()>0)
83             printf("\n AliGenerator Default Constructor\n\n");
84         AliMC * mc = gAlice->GetMCApp();
85         if (mc) mc->SetGenerator(this);
86     }
87
88     SetThetaRange(); ResetBit(kThetaRange);
89     SetPhiRange(); ResetBit(kPhiRange);
90     SetMomentumRange(); ResetBit(kMomentumRange);
91     SetPtRange(); ResetBit(kPtRange);
92     SetYRange(); ResetBit(kYRange);
93     SetNumberParticles();
94     SetTrackingFlag();
95     SetCutVertexZ();
96
97
98     fOrigin[0]=fOrigin[1]=fOrigin[2]=0;
99     fOsigma[0]=fOsigma[1]=fOsigma[2]=0;
100     fVertex[0]=fVertex[1]=fVertex[2]=0;
101
102     fVMin[0]=fVMin[1]=fVMin[2]=0;
103     fVMax[0]=fVMax[1]=fVMax[2]=10000;
104 }
105
106 //_______________________________________________________________________
107 AliGenerator::AliGenerator(Int_t npart):
108   fMCEvGen(0),
109   fThetaMin(0),
110   fThetaMax(0),
111   fPhiMin(0),
112   fPhiMax(0),
113   fPMin(0),
114   fPMax(0),
115   fPtMin(0),
116   fPtMax(0),
117   fYMin(0),
118   fYMax(0),
119   fVMin(3),
120   fVMax(3),
121   fNpart(0),
122   fParentWeight(0),
123   fChildWeight(0),
124   fAnalog(0),
125   fVertexSmear(kNoSmear),
126   fVertexSource(kInternal),
127   fCutVertexZ(0),
128   fTrackIt(0),
129   fOrigin(3),
130   fOsigma(3),
131   fVertex(3),
132   fStack(0),
133   fCollisionGeometry(0)
134 {
135   //
136   // Standard constructor
137   //
138     if (gAlice) {
139         if (gAlice->GetDebug()>0)
140             printf("\n AliGenerator Constructor initializing number of particles \n\n");
141         AliMC * mc = gAlice->GetMCApp();
142         if (mc) mc->SetGenerator(this);
143     }
144     
145     SetThetaRange(); ResetBit(kThetaRange);
146     SetPhiRange(); ResetBit(kPhiRange);
147     SetMomentumRange(); ResetBit(kMomentumRange);
148     SetPtRange(); ResetBit(kPtRange);
149     SetYRange(); ResetBit(kYRange);
150     SetTrackingFlag();
151     SetCutVertexZ();
152
153     fOrigin[0]=fOrigin[1]=fOrigin[2]=0;
154     fOsigma[0]=fOsigma[1]=fOsigma[2]=0;
155     fVertex[0]=fVertex[1]=fVertex[2]=0;
156
157     fVMin[0]=fVMin[1]=fVMin[2]=0;
158     fVMax[0]=fVMax[1]=fVMax[2]=10000;
159
160     SetNumberParticles(npart);
161
162     AliConfig::Instance()->Add(this);
163 }
164
165 //_______________________________________________________________________
166 AliGenerator::AliGenerator(const AliGenerator &gen): 
167   TNamed(gen),
168   AliRndm(gen),
169   fMCEvGen(0),
170   fThetaMin(0),
171   fThetaMax(0),
172   fPhiMin(0),
173   fPhiMax(0),
174   fPMin(0),
175   fPMax(0),
176   fPtMin(0),
177   fPtMax(0),
178   fYMin(0),
179   fYMax(0),
180   fVMin(3),
181   fVMax(3),
182   fNpart(0),
183   fParentWeight(0),
184   fChildWeight(0),
185   fAnalog(0),
186   fVertexSmear(kNoSmear),
187   fVertexSource(kInternal),
188   fCutVertexZ(0),
189   fTrackIt(0),
190   fOrigin(3),
191   fOsigma(3),
192   fVertex(3),
193   fStack(0)
194 {
195   //
196   // Copy constructor
197   //
198   gen.Copy(*this);
199 }
200
201 //_______________________________________________________________________
202 AliGenerator & AliGenerator::operator=(const AliGenerator &gen)
203 {
204   //
205   // Assignment operator
206   //
207   gen.Copy(*this);
208   return (*this);
209 }
210
211 //_______________________________________________________________________
212 void AliGenerator::Copy(AliGenerator &/* gen */) const
213 {
214   //
215   // Copy *this onto gen
216   //
217   Fatal("Copy","Not implemented!\n");
218 }
219
220 //_______________________________________________________________________
221 AliGenerator::~AliGenerator()
222 {
223   //
224   // Destructor
225   //
226   fOrigin.Set(0);
227   fOsigma.Set(0);
228   if (fMCEvGen) {
229     delete fMCEvGen;
230     fMCEvGen=0;
231   }
232 }
233
234 //_______________________________________________________________________
235 void AliGenerator::Init()
236 {   
237   //
238   // Dummy initialisation
239   //
240 }
241
242 //_______________________________________________________________________
243 void AliGenerator::SetOrigin(Float_t ox, Float_t oy, Float_t oz)
244 {
245   //
246   // Set the vertex for the generated tracks
247   //
248   fOrigin[0]=ox;
249   fOrigin[1]=oy;
250   fOrigin[2]=oz;
251 }
252
253 //_______________________________________________________________________
254 void AliGenerator::SetOrigin(const TLorentzVector &o)
255 {
256   //
257   // Set the vertex for the generated tracks
258   //
259   fOrigin[0]=o[0];
260   fOrigin[1]=o[1];
261   fOrigin[2]=o[2];
262 }
263
264 //_______________________________________________________________________
265 void AliGenerator::SetSigma(Float_t sx, Float_t sy, Float_t sz)
266 {
267   //
268   // Set the spread of the vertex
269   //
270   fOsigma[0]=sx;
271   fOsigma[1]=sy;
272   fOsigma[2]=sz;
273 }
274
275 //_______________________________________________________________________
276 void AliGenerator::SetMomentumRange(Float_t pmin, Float_t pmax)
277 {
278   //
279   // Set the momentum range for the generated particles
280   //
281   fPMin = pmin;
282   fPMax = pmax;
283   SetBit(kMomentumRange);
284 }
285
286 //_______________________________________________________________________
287 void AliGenerator::SetPtRange(Float_t ptmin, Float_t ptmax)
288 {
289   //
290   // Set the Pt range for the generated particles
291   //
292   fPtMin = ptmin;
293   fPtMax = ptmax;
294   SetBit(kPtRange);
295 }
296
297 //_______________________________________________________________________
298 void AliGenerator::SetPhiRange(Float_t phimin, Float_t phimax)
299 {
300   //
301   // Set the Phi range for the generated particles
302   //
303   fPhiMin = TMath::Pi()*phimin/180;
304   fPhiMax = TMath::Pi()*phimax/180;
305   SetBit(kPhiRange);
306 }
307
308 //_______________________________________________________________________
309 void AliGenerator::SetYRange(Float_t ymin, Float_t ymax)
310 {
311   //
312   // Set the Rapidity range for the generated particles
313   //
314   fYMin=ymin;
315   fYMax=ymax;
316   SetBit(kYRange);
317 }
318
319 //_______________________________________________________________________
320 void AliGenerator::SetVRange(Float_t vxmin, Float_t vxmax,
321                              Float_t vymin, Float_t vymax,
322                              Float_t vzmin, Float_t vzmax)
323 {
324   //
325   // Set the vertex range for the generated particles
326   //
327   fVMin[0]=vxmin; fVMin[1]=vymin; fVMin[2]=vzmin;
328   fVMax[0]=vxmax; fVMax[1]=vymax; fVMax[2]=vzmax;
329   SetBit(kVertexRange);
330 }
331
332 //_______________________________________________________________________
333 void AliGenerator::SetThetaRange(Float_t thetamin, Float_t thetamax)
334 {
335   //
336   // Set the theta range for the generated particles
337   //
338   fThetaMin = TMath::Pi()*thetamin/180;
339   fThetaMax = TMath::Pi()*thetamax/180;
340   SetBit(kThetaRange);
341 }
342
343 void AliGenerator::Vertex()
344 {
345   //
346   // Obtain vertex for current event from external source or calculated (internal)
347   //
348     if (fVertexSource == kInternal) {
349         VertexInternal();
350     } else if (fVertexSource == kContainer) {
351         ;
352     } else if (fVertexSource == kExternal) {
353         VertexExternal();
354     }
355 }
356
357 //_______________________________________________________________________
358 void AliGenerator::VertexExternal()
359 {
360     // Dummy !!!!!!
361     // Obtain vertex from external source 
362     //
363     // Should be something like fVertex = gAlice->GetVertex()
364     
365     fVertex[0]=fVertex[1]=fVertex[2]=0;  
366 }
367
368 //_______________________________________________________________________
369 void AliGenerator::VertexInternal()
370 {
371     // 
372     // Obtain calculated vertex 
373     // Default is gaussian smearing
374     Float_t random[6];
375     Float_t dv[3];
376     Int_t j;
377     dv[2] = 1.e10;
378     if (!TestBit(kVertexRange)) {
379         while(TMath::Abs(dv[2]) > fCutVertexZ*fOsigma[2]) {
380             Rndm(random,6);
381             for (j=0; j < 3; j++) {
382                 dv[j] = fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
383                     TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
384             }
385         }
386         for (j=0; j < 3; j++) fVertex[j] = fOrigin[j] + dv[j];
387     } else {
388         Rndm(random,3);
389         for (j=0; j < 3; j++)
390             fVertex[j] =  fVMin[j] + random[j] * (fVMax[j] - fVMin[j]);
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 //_______________________________________________________________________
446 void AliGenerator:: SetHighWaterMark(Int_t nt)
447 {
448   //
449   // Internal function to set the maximum index used in the stack
450   //
451   if (fStack)
452      fStack->SetHighWaterMark(nt);
453   else 
454      gAlice->GetMCApp()->SetHighWaterMark(nt);
455    
456 }
457 void AliGenerator::FinishRun()
458 {
459     ;
460 }