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