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