]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVGEN/AliGenMC.cxx
Get phi from iparticle.
[u/mrichter/AliRoot.git] / EVGEN / AliGenMC.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.17  2003/04/30 14:48:21  hristov
19 Changes related to the initialization of random numbers generators. Now one can use its own randoms for each module, particle generator, and/or tracking package. The interface with Fortran is simplified and some inter-library dependencies are avoided. Future improvements are welcome...
20
21 Revision 1.16  2003/04/08 10:22:05  morsch
22 Rapidity shift calculated in Init().
23
24 Revision 1.15  2003/04/04 08:13:26  morsch
25 Boost method added.
26
27 Revision 1.14  2003/01/14 10:50:19  alibrary
28 Cleanup of STEER coding conventions
29
30 Revision 1.13  2002/10/14 14:55:35  hristov
31 Merging the VirtualMC branch to the main development branch (HEAD)
32
33 Revision 1.5.4.2  2002/07/24 08:56:28  alibrary
34 Updating EVGEN on TVirtulaMC
35
36 Revision 1.12  2002/07/19 11:42:33  morsch
37 Use CalcMass()
38
39 Revision 1.11  2002/06/06 15:26:24  morsch
40 Correct child-selection for kPhiKK
41
42 Revision 1.10  2002/06/05 14:05:46  morsch
43 Decayer option kPhiKK for forced phi->K+K- decay added.
44
45 Revision 1.9  2002/05/30 14:58:29  morsch
46 Add pointer to AliGeometry to handle geometrical acceptance. (G. MArtinez)
47
48 Revision 1.8  2002/04/26 10:42:35  morsch
49 Case kNoDecayHeavy added. (N. Carrer)
50
51 Revision 1.7  2002/04/17 10:32:32  morsch
52 Coding Rule violations corrected.
53
54 Revision 1.6  2002/03/26 14:19:36  morsch
55 Saver calculation of rapdity.
56
57 Revision 1.5  2002/03/12 17:02:20  morsch
58 Change in calculation of rapidity, include case in which numerically e == pz.
59
60 Revision 1.4  2001/11/27 13:13:07  morsch
61 Maximum lifetime for long-lived particles to be put on the stack is parameter.
62 It can be set via SetMaximumLifetime(..).
63
64 Revision 1.3  2001/10/16 08:48:56  morsch
65 Common vertex related code moved to base class AliGenerator.
66
67 Revision 1.2  2001/10/15 08:15:51  morsch
68 Event vertex and vertex truncation setting moved into AliMC.
69
70 Revision 1.1  2001/07/13 10:56:00  morsch
71 AliGenMC base class for AliGenParam and AliGenPythia commonalities.
72
73 */
74
75 // Base class for generators using external MC generators.
76 // For example AliGenPythia using Pythia.
77 // Provides basic functionality: setting of kinematic cuts on 
78 // decay products and particle selection.
79 // andreas.morsch@cern.ch
80
81 #include <TMath.h>
82 #include <TPDGCode.h>
83 #include <TParticle.h>
84
85 #include "AliGenMC.h"
86
87  ClassImp(AliGenMC)
88
89 AliGenMC::AliGenMC()
90                  :AliGenerator()
91 {
92 // Default Constructor
93     SetCutOnChild();
94     SetChildMomentumRange();
95     SetChildPtRange();
96     SetChildPhiRange();
97     SetChildThetaRange(); 
98     SetChildYRange(); 
99     SetMaximumLifetime();
100     SetGeometryAcceptance();
101     SetPdgCodeParticleforAcceptanceCut();
102     SetNumberOfAcceptedParticles();
103     SetTarget();
104     SetProjectile();
105 }
106
107 AliGenMC::AliGenMC(Int_t npart)
108                  :AliGenerator(npart)
109 {
110 //  Constructor
111     SetCutOnChild();
112     SetChildMomentumRange();
113     SetChildPtRange();
114     SetChildPhiRange();
115     SetChildThetaRange();
116     SetChildYRange(); 
117 // 
118     fParentSelect.Set(8);
119     fChildSelect.Set(8);
120     for (Int_t i=0; i<8; i++) fParentSelect[i]=fChildSelect[i]=0;
121     SetMaximumLifetime();
122     SetGeometryAcceptance();
123     SetPdgCodeParticleforAcceptanceCut();
124     SetNumberOfAcceptedParticles();
125     SetTarget();
126     SetProjectile();
127 }
128
129 AliGenMC::AliGenMC(const AliGenMC & mc)
130 {
131 // copy constructor
132 }
133
134 AliGenMC::~AliGenMC()
135 {
136 // Destructor
137 }
138
139 void AliGenMC::Init()
140 {
141 //
142 //  Initialization
143     switch (fForceDecay) {
144     case kSemiElectronic:
145     case kDiElectron:
146     case kBJpsiDiElectron:
147     case kBPsiPrimeDiElectron:
148         fChildSelect[0] = kElectron;    
149         break;
150     case kSemiMuonic:
151     case kDiMuon:
152     case kBJpsiDiMuon:
153     case kBPsiPrimeDiMuon:
154     case kPiToMu:
155     case kKaToMu:
156         fChildSelect[0]=kMuonMinus;
157         break;
158     case kHadronicD:
159         fChildSelect[0]=kPiPlus;
160         fChildSelect[1]=kKPlus;
161         break;
162     case kPhiKK:
163         fChildSelect[0]=kKPlus;
164     case kOmega:        
165     case kAll:
166     case kNoDecay:
167     case kNoDecayHeavy:
168         break;
169     }
170
171     if (fZTarget != 0 && fAProjectile != 0) 
172     {
173         fDyBoost    = - 0.5 * TMath::Log(Double_t(fZProjectile) * Double_t(fATarget) / 
174                                          (Double_t(fZTarget)    * Double_t(fAProjectile)));
175     }
176 }
177
178
179 Bool_t AliGenMC::ParentSelected(Int_t ip) const
180 {
181 // True if particle is in list of parent particles to be selected
182     for (Int_t i=0; i<8; i++)
183     {
184         if (fParentSelect.At(i) == ip) return kTRUE;
185     }
186     return kFALSE;
187 }
188
189 Bool_t AliGenMC::ChildSelected(Int_t ip) const
190 {
191 // True if particle is in list of decay products to be selected
192     for (Int_t i=0; i<5; i++)
193     {
194         if (fChildSelect.At(i) == ip) return kTRUE;
195     }
196     return kFALSE;
197 }
198
199 Bool_t AliGenMC::KinematicSelection(TParticle *particle, Int_t flag) const
200 {
201 // Perform kinematic selection
202     Float_t pz    = particle->Pz();
203     Float_t  e    = particle->Energy();
204     Float_t pt    = particle->Pt();
205     Float_t p     = particle->P();
206     Float_t theta = particle->Theta();
207     Float_t mass  = particle->GetCalcMass();
208     Float_t mt2   = pt * pt + mass * mass;
209     Float_t phi   = particle->Phi();
210     
211     Double_t y, y0;
212
213     if (TMath::Abs(pz) <  e) {
214         y = 0.5*TMath::Log((e+pz)/(e-pz));
215     } else {
216         y = 1.e10;
217     }
218     
219     if (mt2) {
220         y0 = 0.5*TMath::Log((e+TMath::Abs(pz))*(e+TMath::Abs(pz))/mt2);
221     } else {
222         if (TMath::Abs(y) < 1.e10) {
223             y0 = y;
224         } else {
225             y0 = 1.e10;
226         }
227     }
228       
229     y = (pz < 0) ? -y0 : y0;
230     
231     if (flag == 0) {
232 //
233 // Primary particle cuts
234 //
235 //  transverse momentum cut    
236         if (pt > fPtMax || pt < fPtMin) {
237 //          printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
238             return kFALSE;
239         }
240 //
241 // momentum cut
242         if (p > fPMax || p < fPMin) {
243 //          printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
244             return kFALSE;
245         }
246 //
247 // theta cut
248         if (theta > fThetaMax || theta < fThetaMin) {
249 //          printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
250             return kFALSE;
251         }
252 //
253 // rapidity cut
254         if (y > fYMax || y < fYMin) {
255 //          printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
256             return kFALSE;
257         }
258 //
259 // phi cut
260         if (phi > fPhiMax || phi < fPhiMin) {
261 //          printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
262             return kFALSE;
263         }
264     } else {
265 //
266 // Decay product cuts
267 //
268 //  transverse momentum cut    
269         if (pt > fChildPtMax || pt < fChildPtMin) {
270 //          printf("\n failed pt cut %f %f %f \n",pt,fChildPtMin,fChildPtMax);
271             return kFALSE;
272         }
273 //
274 // momentum cut
275         if (p > fChildPMax || p < fChildPMin) {
276 //          printf("\n failed p cut %f %f %f \n",p,fChildPMin,fChildPMax);
277             return kFALSE;
278         }
279 //
280 // theta cut
281         if (theta > fChildThetaMax || theta < fChildThetaMin) {
282 //          printf("\n failed theta cut %f %f %f \n",theta,fChildThetaMin,fChildThetaMax);
283             return kFALSE;
284         }
285 //
286 // rapidity cut
287         if (y > fChildYMax || y < fChildYMin) {
288 //          printf("\n failed y cut %f %f %f \n",y,fChildYMin,fChildYMax);
289             return kFALSE;
290         }
291 //
292 // phi cut
293         if (phi > fChildPhiMax || phi < fChildPhiMin) {
294 //          printf("\n failed phi cut %f %f %f \n",phi,fChildPhiMin,fChildPhiMax);
295             return kFALSE;
296         }
297     }
298     
299     return kTRUE;
300 }
301
302 Bool_t AliGenMC::CheckAcceptanceGeometry(Int_t np, TClonesArray* particles)
303 {
304   Bool_t Check ;  // All fPdgCodeParticleforAcceptanceCut particles are in in the fGeometryAcceptance acceptance
305   Int_t NumberOfPdgCodeParticleforAcceptanceCut=0;
306   Int_t NumberOfAcceptedPdgCodeParticleforAcceptanceCut=0;
307   TParticle * particle;
308   Int_t i;
309   for (i=0; i<np; i++) {
310     particle =  (TParticle *) particles->At(i);
311     if( TMath::Abs( particle->GetPdgCode() ) == TMath::Abs( fPdgCodeParticleforAcceptanceCut ) ) {
312       NumberOfPdgCodeParticleforAcceptanceCut++;
313       if (fGeometryAcceptance->Impact(particle)) NumberOfAcceptedPdgCodeParticleforAcceptanceCut++;
314     }   
315   }
316   if ( NumberOfAcceptedPdgCodeParticleforAcceptanceCut > (fNumberOfAcceptedParticles-1) )
317     Check = kTRUE;
318   else
319     Check = kFALSE;
320
321   return Check;
322 }
323
324 Int_t AliGenMC::CheckPDGCode(Int_t pdgcode) const
325 {
326 //
327 //  If the particle is in a diffractive state, then take action accordingly
328   switch (pdgcode) {
329   case 91:
330     return 92;
331   case 110:
332     //rho_diff0 -- difficult to translate, return rho0
333     return 113;
334   case 210:
335     //pi_diffr+ -- change to pi+
336     return 211;
337   case 220:
338     //omega_di0 -- change to omega0
339     return 223;
340   case 330:
341     //phi_diff0 -- return phi0
342     return 333;
343   case 440:
344     //J/psi_di0 -- return J/psi
345     return 443;
346   case 2110:
347     //n_diffr -- return neutron
348     return 2112;
349   case 2210:
350     //p_diffr+ -- return proton
351     return 2212;
352   }
353   //non diffractive state -- return code unchanged
354   return pdgcode;
355 }
356
357 void AliGenMC::Boost()
358 {
359 //
360 // Boost cms into LHC lab frame
361 //
362
363     Double_t beta  = TMath::TanH(fDyBoost);
364     Double_t gamma = 1./TMath::Sqrt(1.-beta*beta);
365     Double_t gb    = gamma * beta;
366
367     //    printf("\n Boosting particles to lab frame %f %f %f", fDyBoost, beta, gamma);
368     
369     Int_t i;
370     Int_t np = fParticles->GetEntriesFast();
371     for (i = 0; i < np; i++) 
372     {
373         TParticle* iparticle = (TParticle*) fParticles->At(i);
374
375         Double_t e   = iparticle->Energy();
376         Double_t px  = iparticle->Px();
377         Double_t py  = iparticle->Py();
378         Double_t pz  = iparticle->Pz();
379
380         Double_t eb  = gamma * e -      gb * pz;
381         Double_t pzb =   -gb * e +   gamma * pz;
382
383         iparticle->SetMomentum(px, py, pzb, eb);
384     }
385 }
386
387
388           
389 AliGenMC& AliGenMC::operator=(const  AliGenMC& rhs)
390 {
391 // Assignment operator
392     return *this;
393 }
394