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