]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliGenerator.cxx
Introducing Header instead of Log
[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 /* $Header$ */
17
18 ///////////////////////////////////////////////////////////////////
19 //                                                               //
20 //    Generate the final state of the interaction as the input   //
21 //    to the MonteCarlo                                          //
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 "AliConfig.h"
40 #include "AliGenerator.h"
41 #include "AliCollisionGeometry.h"
42 #include "AliRun.h"
43 #include "AliStack.h"
44
45 ClassImp(AliGenerator)
46
47 TGenerator* AliGenerator::fgMCEvGen=0;
48
49 //_______________________________________________________________________
50 AliGenerator::AliGenerator():
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(kExternal),
69   fCutVertexZ(0),
70   fTrackIt(0),
71   fOrigin(3),
72   fOsigma(3),
73   fVertex(3),
74   fEventVertex(0),
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         gAlice->SetGenerator(this);
85     }
86
87     SetThetaRange(); ResetBit(kThetaRange);
88     SetPhiRange(); ResetBit(kPhiRange);
89     SetMomentumRange(); ResetBit(kMomentumRange);
90     SetPtRange(); ResetBit(kPtRange);
91     SetYRange(); ResetBit(kYRange);
92     SetNumberParticles();
93     SetTrackingFlag();
94     SetCutVertexZ();
95
96
97     fOrigin[0]=fOrigin[1]=fOrigin[2]=0;
98     fOsigma[0]=fOsigma[1]=fOsigma[2]=0;
99     fVertex[0]=fVertex[1]=fVertex[2]=0;
100
101     fVMin[0]=fVMin[1]=fVMin[2]=0;
102     fVMax[0]=fVMax[1]=fVMax[2]=10000;
103 }
104
105 //_______________________________________________________________________
106 AliGenerator::AliGenerator(Int_t npart):
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(kExternal),
125   fCutVertexZ(0),
126   fTrackIt(0),
127   fOrigin(3),
128   fOsigma(3),
129   fVertex(3),
130   fEventVertex(0),
131   fStack(0),
132   fCollisionGeometry(0)
133 {
134   //
135   // Standard constructor
136   //
137     if (gAlice) {
138         if (gAlice->GetDebug()>0)
139             printf("\n AliGenerator Constructor initializing number of particles \n\n");
140         gAlice->SetGenerator(this);
141     }
142     
143     SetThetaRange(); ResetBit(kThetaRange);
144     SetPhiRange(); ResetBit(kPhiRange);
145     SetMomentumRange(); ResetBit(kMomentumRange);
146     SetPtRange(); ResetBit(kPtRange);
147     SetYRange(); ResetBit(kYRange);
148     SetTrackingFlag();
149     SetCutVertexZ();
150
151     fOrigin[0]=fOrigin[1]=fOrigin[2]=0;
152     fOsigma[0]=fOsigma[1]=fOsigma[2]=0;
153     fVertex[0]=fVertex[1]=fVertex[2]=0;
154
155     fVMin[0]=fVMin[1]=fVMin[2]=0;
156     fVMax[0]=fVMax[1]=fVMax[2]=10000;
157
158     SetNumberParticles(npart);
159
160     AliConfig::Instance()->Add(this);
161 }
162
163 //_______________________________________________________________________
164 AliGenerator::AliGenerator(const AliGenerator &gen): 
165   TNamed(gen),
166   AliRndm(gen),
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(kExternal),
185   fCutVertexZ(0),
186   fTrackIt(0),
187   fOrigin(3),
188   fOsigma(3),
189   fVertex(3),
190   fEventVertex(0),
191   fStack(0)
192 {
193   //
194   // Copy constructor
195   //
196   gen.Copy(*this);
197 }
198
199 //_______________________________________________________________________
200 AliGenerator & AliGenerator::operator=(const AliGenerator &gen)
201 {
202   //
203   // Assignment operator
204   //
205   gen.Copy(*this);
206   return (*this);
207 }
208
209 //_______________________________________________________________________
210 void AliGenerator::Copy(AliGenerator &/* gen */) const
211 {
212   //
213   // Copy *this onto gen
214   //
215   Fatal("Copy","Not implemented!\n");
216 }
217
218 //_______________________________________________________________________
219 AliGenerator::~AliGenerator()
220 {
221   //
222   // Destructor
223   //
224   fOrigin.Set(0);
225   fOsigma.Set(0);
226   if (fgMCEvGen) {
227     delete fgMCEvGen;
228     fgMCEvGen=0;
229   }
230 }
231
232 //_______________________________________________________________________
233 void AliGenerator::Init()
234 {   
235   //
236   // Dummy initialisation
237   //
238 }
239
240 //_______________________________________________________________________
241 void AliGenerator::SetOrigin(Float_t ox, Float_t oy, Float_t oz)
242 {
243   //
244   // Set the vertex for the generated tracks
245   //
246   fOrigin[0]=ox;
247   fOrigin[1]=oy;
248   fOrigin[2]=oz;
249 }
250
251 //_______________________________________________________________________
252 void AliGenerator::SetOrigin(const TLorentzVector &o)
253 {
254   //
255   // Set the vertex for the generated tracks
256   //
257   fOrigin[0]=o[0];
258   fOrigin[1]=o[1];
259   fOrigin[2]=o[2];
260 }
261
262 //_______________________________________________________________________
263 void AliGenerator::SetSigma(Float_t sx, Float_t sy, Float_t sz)
264 {
265   //
266   // Set the spread of the vertex
267   //
268   fOsigma[0]=sx;
269   fOsigma[1]=sy;
270   fOsigma[2]=sz;
271 }
272
273 //_______________________________________________________________________
274 void AliGenerator::SetMomentumRange(Float_t pmin, Float_t pmax)
275 {
276   //
277   // Set the momentum range for the generated particles
278   //
279   fPMin = pmin;
280   fPMax = pmax;
281   SetBit(kMomentumRange);
282 }
283
284 //_______________________________________________________________________
285 void AliGenerator::SetPtRange(Float_t ptmin, Float_t ptmax)
286 {
287   //
288   // Set the Pt range for the generated particles
289   //
290   fPtMin = ptmin;
291   fPtMax = ptmax;
292   SetBit(kPtRange);
293 }
294
295 //_______________________________________________________________________
296 void AliGenerator::SetPhiRange(Float_t phimin, Float_t phimax)
297 {
298   //
299   // Set the Phi range for the generated particles
300   //
301   fPhiMin = TMath::Pi()*phimin/180;
302   fPhiMax = TMath::Pi()*phimax/180;
303   SetBit(kPhiRange);
304 }
305
306 //_______________________________________________________________________
307 void AliGenerator::SetYRange(Float_t ymin, Float_t ymax)
308 {
309   //
310   // Set the Rapidity range for the generated particles
311   //
312   fYMin=ymin;
313   fYMax=ymax;
314   SetBit(kYRange);
315 }
316
317 //_______________________________________________________________________
318 void AliGenerator::SetVRange(Float_t vxmin, Float_t vxmax,
319                              Float_t vymin, Float_t vymax,
320                              Float_t vzmin, Float_t vzmax)
321 {
322   //
323   // Set the vertex range for the generated particles
324   //
325   fVMin[0]=vxmin; fVMin[1]=vymin; fVMin[2]=vzmin;
326   fVMax[0]=vxmax; fVMax[1]=vymax; fVMax[2]=vzmax;
327   SetBit(kVertexRange);
328 }
329
330 //_______________________________________________________________________
331 void AliGenerator::SetThetaRange(Float_t thetamin, Float_t thetamax)
332 {
333   //
334   // Set the theta range for the generated particles
335   //
336   fThetaMin = TMath::Pi()*thetamin/180;
337   fThetaMax = TMath::Pi()*thetamax/180;
338   SetBit(kThetaRange);
339 }
340
341 void AliGenerator::Vertex()
342 {
343   //
344   // Obtain vertex for current event from external source or calculated (internal)
345   //
346     if (fVertexSource == kInternal) {
347         VertexInternal();
348     } else {
349         VertexExternal();
350     }
351 }
352
353 //_______________________________________________________________________
354 void AliGenerator::VertexExternal()
355 {
356     // Dummy !!!!!!
357     // Obtain vertex from external source 
358     //
359     // Should be something like fVertex = gAlice->GetVertex()
360     
361     fVertex[0]=fVertex[1]=fVertex[2]=0;  
362 }
363
364 //_______________________________________________________________________
365 void AliGenerator::VertexInternal()
366 {
367     // 
368     // Obtain calculated vertex 
369     // Default is gaussian smearing
370     Float_t random[6];
371     Rndm(random,6);
372     for (Int_t j = 0; j<3 ; j++) {
373         fVertex[j]=
374             fOrigin[j]+fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
375             TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
376     }
377 }
378
379 //_______________________________________________________________________
380 void  AliGenerator::SetTrack(Int_t done, Int_t parent, Int_t pdg,
381                                Float_t *pmom, Float_t *vpos, Float_t *polar,
382                                Float_t tof, TMCProcess mech, Int_t &ntr,
383                                Float_t weight, Int_t is)
384 {
385
386   if (fStack)
387     fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
388                      mech, ntr, weight, is);
389   else 
390     gAlice->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
391                      mech, ntr, weight, is);
392 }
393
394 //_______________________________________________________________________
395 void  AliGenerator::SetTrack(Int_t done, Int_t parent, Int_t pdg,
396                       Double_t px, Double_t py, Double_t pz, Double_t e,
397                       Double_t vx, Double_t vy, Double_t vz, Double_t tof,
398                       Double_t polx, Double_t poly, Double_t polz,
399                       TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
400 {
401   
402   if (fStack)
403      fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
404                       polx, poly, polz, mech, ntr, weight, is);
405   else 
406      gAlice->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
407                         polx, poly, polz, mech, ntr, weight, is);
408 }
409
410
411 //_______________________________________________________________________
412 void AliGenerator:: KeepTrack(Int_t itrack)
413 {
414   if (fStack)
415      fStack->KeepTrack(itrack);
416   else 
417      gAlice->KeepTrack(itrack);
418    
419 }
420
421 //_______________________________________________________________________
422 void AliGenerator:: SetHighWaterMark(Int_t nt)
423 {
424   if (fStack)
425      fStack->SetHighWaterMark(nt);
426   else 
427      gAlice->SetHighWaterMark(nt);
428    
429 }