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