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