]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliGenerator.cxx
Inheritance from TObject. Automatic streamers.
[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 /*
17 $Log$
18 Revision 1.18  2002/02/18 19:23:00  hristov
19 Put protection in the destructor
20
21 Revision 1.17  2001/11/26 15:46:35  morsch
22 Set default value for vertex truncation in constructor.
23
24 Revision 1.16  2001/10/16 08:45:37  morsch
25 All vertex truncation and event vertex moved here.
26
27 Revision 1.15  2001/07/28 10:43:41  hristov
28 Default argument initialised once
29
30 Revision 1.14  2001/07/27 17:13:12  morsch
31 - SetTrack, KeepTrack and SetHighWaterMark methods added to delegate to local
32 stack or stack owned by AliRun. (Piotr Skowronski, A.M.)
33 - Changes needed for afterburners (Piotr Skowronski)
34
35 Revision 1.13  2001/05/16 14:57:22  alibrary
36 New files for folders and Stack
37
38 Revision 1.12  2001/02/02 11:12:50  morsch
39 Add Vertex() method that allows to get vertex from merging manager, if needed.
40
41 Revision 1.11  2001/01/26 19:58:48  hristov
42 Major upgrade of AliRoot code
43
44 Revision 1.10  2000/12/21 15:30:18  fca
45 Correcting coding convention violations
46
47 Revision 1.9  2000/10/04 10:08:01  fca
48 Correction of minor typing mistakes
49
50 Revision 1.8  2000/10/02 21:28:14  fca
51 Removal of useless dependecies via forward declarations
52
53 Revision 1.7  2000/07/12 08:56:25  fca
54 Coding convention correction and warning removal
55
56 Revision 1.6  2000/07/11 18:24:59  fca
57 Coding convention corrections + few minor bug fixes
58
59 Revision 1.5  2000/06/08 13:34:50  fca
60 Better control of momentum range in GenBox
61
62 Revision 1.4  1999/09/29 09:24:29  fca
63 Introduction of the Copyright and cvs Log
64
65 */
66
67 ///////////////////////////////////////////////////////////////////
68 //                                                               //
69 //    Generate the final state of the interaction as the input   //
70 //    to the MonteCarlo                                          //
71 //
72 //Begin_Html
73 /*
74 <img src="picts/AliGeneratorClass.gif">
75 </pre>
76 <br clear=left>
77 <font size=+2 color=red>
78 <p>The responsible person for this module is
79 <a href="mailto:andreas.morsch@cern.ch">Andreas Morsch</a>.
80 </font>
81 <pre>
82 */
83 //End_Html
84 //                                                               //
85 ///////////////////////////////////////////////////////////////////
86
87 #include "AliGenerator.h"
88 #include "TGenerator.h"
89 #include "AliRun.h"
90 #include "AliConfig.h"
91 #include "AliStack.h"
92
93
94 ClassImp(AliGenerator)
95
96 TGenerator* AliGenerator::fgMCEvGen=0;
97
98 //____________________________________________________________
99 AliGenerator::AliGenerator()
100 {
101   //
102   // Default constructor
103   //
104     if (gAlice) {
105         if (gAlice->GetDebug()>0)
106             printf("\n AliGenerator Default Constructor\n\n");
107         gAlice->SetGenerator(this);
108     }
109
110     SetThetaRange(); ResetBit(kThetaRange);
111     SetPhiRange(); ResetBit(kPhiRange);
112     SetMomentumRange(); ResetBit(kMomentumRange);
113     SetPtRange(); ResetBit(kPtRange);
114     SetYRange(); ResetBit(kYRange);
115     SetNumberParticles();
116     SetTrackingFlag();
117     SetCutVertexZ();
118
119
120     fOrigin.Set(3);
121     fOsigma.Set(3);
122     fVertex.Set(3);
123
124     fOrigin[0]=fOrigin[1]=fOrigin[2]=0;
125     fOsigma[0]=fOsigma[1]=fOsigma[2]=0;
126     fVertex[0]=fVertex[1]=fVertex[2]=0;
127
128     fVMin.Set(3);
129     fVMin[0]=fVMin[1]=fVMin[2]=0;
130     fVMax.Set(3);
131     fVMax[0]=fVMax[1]=fVMax[2]=10000;
132     fStack = 0;
133 }
134
135 //____________________________________________________________
136 AliGenerator::AliGenerator(Int_t npart)
137     : TNamed(" "," ")
138 {
139   //
140   // Standard constructor
141   //
142     if (gAlice) {
143         if (gAlice->GetDebug()>0)
144             printf("\n AliGenerator Constructor initializing number of particles \n\n");
145         gAlice->SetGenerator(this);
146     }
147     
148     SetThetaRange(); ResetBit(kThetaRange);
149     SetPhiRange(); ResetBit(kPhiRange);
150     SetMomentumRange(); ResetBit(kMomentumRange);
151     SetPtRange(); ResetBit(kPtRange);
152     SetYRange(); ResetBit(kYRange);
153     SetTrackingFlag();
154     SetCutVertexZ();
155
156     fOrigin.Set(3);
157     fOsigma.Set(3);
158     fVertex.Set(3);
159
160     fOrigin[0]=fOrigin[1]=fOrigin[2]=0;
161     fOsigma[0]=fOsigma[1]=fOsigma[2]=0;
162     fVertex[0]=fVertex[1]=fVertex[2]=0;
163
164     fVMin.Set(3);
165     fVMin[0]=fVMin[1]=fVMin[2]=0;
166     fVMax.Set(3);
167     fVMax[0]=fVMax[1]=fVMax[2]=10000;
168
169     SetNumberParticles(npart);
170
171     AliConfig::Instance()->Add(this);
172     fStack = 0;    
173 }
174
175 //____________________________________________________________
176 AliGenerator::AliGenerator(const AliGenerator &gen) : TNamed(" "," ")
177 {
178   //
179   // Copy constructor
180   //
181   gen.Copy(*this);
182 }
183
184 //____________________________________________________________
185 AliGenerator & AliGenerator::operator=(const AliGenerator &gen)
186 {
187   //
188   // Assignment operator
189   //
190   gen.Copy(*this);
191   return (*this);
192 }
193
194 //____________________________________________________________
195 void AliGenerator::Copy(AliGenerator &/* gen */) const
196 {
197   //
198   // Copy *this onto gen
199   //
200   Fatal("Copy","Not implemented!\n");
201 }
202
203 //____________________________________________________________
204 AliGenerator::~AliGenerator()
205 {
206   //
207   // Destructor
208   //
209   fOrigin.Set(0);
210   fOsigma.Set(0);
211   if (fgMCEvGen) {
212     delete fgMCEvGen;
213     fgMCEvGen=0;
214   }
215 }
216
217 void AliGenerator::Init()
218 {   
219   //
220   // Dummy initialisation
221   //
222 }
223
224 //_______________________________________________________________________
225 void AliGenerator::SetOrigin(Float_t ox, Float_t oy, Float_t oz)
226 {
227   //
228   // Set the vertex for the generated tracks
229   //
230   fOrigin[0]=ox;
231   fOrigin[1]=oy;
232   fOrigin[2]=oz;
233 }
234
235 //_______________________________________________________________________
236 void AliGenerator::SetOrigin(const TLorentzVector &o)
237 {
238   //
239   // Set the vertex for the generated tracks
240   //
241   fOrigin[0]=o[0];
242   fOrigin[1]=o[1];
243   fOrigin[2]=o[2];
244 }
245
246 //_______________________________________________________________________
247 void AliGenerator::SetSigma(Float_t sx, Float_t sy, Float_t sz)
248 {
249   //
250   // Set the spread of the vertex
251   //
252   fOsigma[0]=sx;
253   fOsigma[1]=sy;
254   fOsigma[2]=sz;
255 }
256
257 //_______________________________________________________________________
258 void AliGenerator::SetMomentumRange(Float_t pmin, Float_t pmax)
259 {
260   //
261   // Set the momentum range for the generated particles
262   //
263   fPMin = pmin;
264   fPMax = pmax;
265   SetBit(kMomentumRange);
266 }
267
268 //_______________________________________________________________________
269 void AliGenerator::SetPtRange(Float_t ptmin, Float_t ptmax)
270 {
271   //
272   // Set the Pt range for the generated particles
273   //
274   fPtMin = ptmin;
275   fPtMax = ptmax;
276   SetBit(kPtRange);
277 }
278
279 //_______________________________________________________________________
280 void AliGenerator::SetPhiRange(Float_t phimin, Float_t phimax)
281 {
282   //
283   // Set the Phi range for the generated particles
284   //
285   fPhiMin = TMath::Pi()*phimin/180;
286   fPhiMax = TMath::Pi()*phimax/180;
287   SetBit(kPhiRange);
288 }
289
290 //_______________________________________________________________________
291 void AliGenerator::SetYRange(Float_t ymin, Float_t ymax)
292 {
293   //
294   // Set the Rapidity range for the generated particles
295   //
296   fYMin=ymin;
297   fYMax=ymax;
298   SetBit(kYRange);
299 }
300
301 //_______________________________________________________________________
302 void AliGenerator::SetVRange(Float_t vxmin, Float_t vxmax,
303                              Float_t vymin, Float_t vymax,
304                              Float_t vzmin, Float_t vzmax)
305 {
306   //
307   // Set the vertex range for the generated particles
308   //
309   fVMin[0]=vxmin; fVMin[1]=vymin; fVMin[2]=vzmin;
310   fVMax[0]=vxmax; fVMax[1]=vymax; fVMax[2]=vzmax;
311   SetBit(kVertexRange);
312 }
313
314 //_______________________________________________________________________
315 void AliGenerator::SetThetaRange(Float_t thetamin, Float_t thetamax)
316 {
317   //
318   // Set the theta range for the generated particles
319   //
320   fThetaMin = TMath::Pi()*thetamin/180;
321   fThetaMax = TMath::Pi()*thetamax/180;
322   SetBit(kThetaRange);
323 }
324
325 void AliGenerator::Vertex()
326 {
327   //
328   // Obtain vertex for current event from external source or calculated (internal)
329   //
330     if (fVertexSource == kInternal) {
331         VertexInternal();
332     } else {
333         VertexExternal();
334     }
335 }
336
337
338 void AliGenerator::VertexExternal()
339 {
340     // Dummy !!!!!!
341     // Obtain vertex from external source 
342     //
343     // Should be something like fVertex = gAlice->GetVertex()
344     
345     fVertex[0]=fVertex[1]=fVertex[2]=0;  
346 }
347
348 void AliGenerator::VertexInternal()
349 {
350     // 
351     // Obtain calculated vertex 
352     // Default is gaussian smearing
353     Float_t random[6];
354     Rndm(random,6);
355     for (Int_t j = 0; j<3 ; j++) {
356         fVertex[j]=
357             fOrigin[j]+fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
358             TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
359     }
360 }
361
362 void  AliGenerator::SetTrack(Int_t done, Int_t parent, Int_t pdg,
363                                Float_t *pmom, Float_t *vpos, Float_t *polar,
364                                Float_t tof, AliMCProcess mech, Int_t &ntr,
365                                Float_t weight, Int_t is)
366 {
367
368   if (fStack)
369     fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
370                      mech, ntr, weight, is);
371   else 
372     gAlice->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
373                      mech, ntr, weight, is);
374 }
375 void  AliGenerator::SetTrack(Int_t done, Int_t parent, Int_t pdg,
376                       Double_t px, Double_t py, Double_t pz, Double_t e,
377                       Double_t vx, Double_t vy, Double_t vz, Double_t tof,
378                       Double_t polx, Double_t poly, Double_t polz,
379                       AliMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
380 {
381   
382   if (fStack)
383      fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
384                       polx, poly, polz, mech, ntr, weight, is);
385   else 
386      gAlice->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
387                         polx, poly, polz, mech, ntr, weight, is);
388 }
389
390
391 void AliGenerator:: KeepTrack(Int_t itrack)
392 {
393   if (fStack)
394      fStack->KeepTrack(itrack);
395   else 
396      gAlice->KeepTrack(itrack);
397    
398 }
399
400 void AliGenerator:: SetHighWaterMark(Int_t nt)
401 {
402   if (fStack)
403      fStack->SetHighWaterMark(nt);
404   else 
405      gAlice->SetHighWaterMark(nt);
406    
407 }