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