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