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