]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVGEN/AliGenMC.cxx
20-jan-2007 NvE AliMath extended with Nfac(), LnNfac() and LogNfac() facilities.
[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 /* $Id$ */
17
18 // Base class for generators using external MC generators.
19 // For example AliGenPythia using Pythia.
20 // Provides basic functionality: setting of kinematic cuts on 
21 // decay products and particle selection.
22 // andreas.morsch@cern.ch
23
24 #include <TClonesArray.h>
25 #include <TMath.h>
26 #include <TPDGCode.h>
27 #include <TParticle.h>
28
29 #include "AliGenMC.h"
30 #include "AliGeometry.h"
31
32 ClassImp(AliGenMC)
33
34 AliGenMC::AliGenMC()
35     :AliGenerator(),
36      fParticles(0),
37      fParentSelect(8),
38      fChildSelect(8),
39      fCutOnChild(0),
40      fChildPtMin(0.),
41      fChildPtMax(1.e10),
42      fChildPMin(0.),
43      fChildPMax(1.e10),
44      fChildPhiMin(0.),
45      fChildPhiMax(2. * TMath::Pi()),
46      fChildThetaMin(0.),
47      fChildThetaMax(TMath::Pi()),
48      fChildYMin(-12.),
49      fChildYMax(12.),
50      fXingAngleX(0.),
51      fXingAngleY(0.),
52      fForceDecay(kAll),
53      fMaxLifeTime(1.e-15),
54      fAProjectile(1),
55      fZProjectile(1),
56      fATarget(1),
57      fZTarget(1),
58      fProjectile("P"),
59      fTarget("P"),    
60      fDyBoost(0.),
61      fGeometryAcceptance(0),
62      fPdgCodeParticleforAcceptanceCut(0),
63      fNumberOfAcceptedParticles(2)
64 {
65 // Default Constructor
66 }
67
68 AliGenMC::AliGenMC(Int_t npart)
69     :AliGenerator(npart),
70      fParticles(0),
71      fParentSelect(8),
72      fChildSelect(8),
73      fCutOnChild(0),
74      fChildPtMin(0.),
75      fChildPtMax(1.e10),
76      fChildPMin(0.),
77      fChildPMax(1.e10),
78      fChildPhiMin(0.),
79      fChildPhiMax(2. * TMath::Pi()),
80      fChildThetaMin(0.),
81      fChildThetaMax(TMath::Pi()),
82      fChildYMin(-12.),
83      fChildYMax(12.),
84      fXingAngleX(0.),
85      fXingAngleY(0.),
86      fForceDecay(kAll),
87      fMaxLifeTime(1.e-15),
88      fAProjectile(1),
89      fZProjectile(1),
90      fATarget(1),
91      fZTarget(1),
92      fProjectile("P"),
93      fTarget("P"),    
94      fDyBoost(0.),
95      fGeometryAcceptance(0),
96      fPdgCodeParticleforAcceptanceCut(0),
97      fNumberOfAcceptedParticles(2)
98 {
99 //  Constructor
100 // 
101     for (Int_t i=0; i<8; i++) fParentSelect[i]=fChildSelect[i]=0;
102 }
103
104 AliGenMC::AliGenMC(const AliGenMC & mc):
105     AliGenerator(mc),
106     fParticles(0),
107     fParentSelect(8),
108     fChildSelect(8),
109     fCutOnChild(0),
110     fChildPtMin(0.),
111     fChildPtMax(1.e10),
112     fChildPMin(0.),
113     fChildPMax(1.e10),
114     fChildPhiMin(0.),
115     fChildPhiMax(2. * TMath::Pi()),
116     fChildThetaMin(0.),
117     fChildThetaMax(TMath::Pi()),
118     fChildYMin(-12.),
119     fChildYMax(12.),
120     fXingAngleX(0.),
121     fXingAngleY(0.),
122     fForceDecay(kAll),
123     fMaxLifeTime(1.e-15),
124     fAProjectile(1),
125     fZProjectile(1),
126     fATarget(1),
127     fZTarget(1),
128     fProjectile("P"),
129     fTarget("P"),    
130     fDyBoost(0.),
131     fGeometryAcceptance(0),
132     fPdgCodeParticleforAcceptanceCut(0),
133     fNumberOfAcceptedParticles(2)
134 {
135 // Copy constructor
136     mc.Copy(*this);
137 }
138
139 AliGenMC::~AliGenMC()
140 {
141 // Destructor
142 }
143
144 void AliGenMC::Init()
145 {
146 //
147 //  Initialization
148     switch (fForceDecay) {
149     case kSemiElectronic:
150     case kDiElectron:
151     case kBJpsiDiElectron:
152     case kBPsiPrimeDiElectron:
153         fChildSelect[0] = kElectron;    
154         break;
155     case kHardMuons:    
156     case kSemiMuonic:
157     case kDiMuon:
158     case kBJpsiDiMuon:
159     case kBPsiPrimeDiMuon:
160     case kPiToMu:
161     case kKaToMu:
162     case kWToMuon:
163     case kWToCharmToMuon:
164     case kZDiMuon:
165         fChildSelect[0]=kMuonMinus;
166         break;
167     case kWToCharm:
168         break;
169     case kHadronicD:
170         fChildSelect[0]=kPiPlus;
171         fChildSelect[1]=kKPlus;
172         break;
173     case kPhiKK:
174         fChildSelect[0]=kKPlus;
175         break;
176     case kBJpsi:
177         fChildSelect[0]=443;
178         break;
179     case kOmega:        
180     case kAll:
181     case kNoDecay:
182     case kNoDecayHeavy:
183         break;
184     }
185
186     if (fZTarget != 0 && fAProjectile != 0) 
187     {
188         fDyBoost    = - 0.5 * TMath::Log(Double_t(fZProjectile) * Double_t(fATarget) / 
189                                          (Double_t(fZTarget)    * Double_t(fAProjectile)));
190     }
191 }
192
193
194 Bool_t AliGenMC::ParentSelected(Int_t ip) const
195 {
196 // True if particle is in list of parent particles to be selected
197     for (Int_t i=0; i<8; i++)
198     {
199         if (fParentSelect.At(i) == ip) return kTRUE;
200     }
201     return kFALSE;
202 }
203
204 Bool_t AliGenMC::ChildSelected(Int_t ip) const
205 {
206 // True if particle is in list of decay products to be selected
207     for (Int_t i=0; i<5; i++)
208     {
209         if (fChildSelect.At(i) == ip) return kTRUE;
210     }
211     return kFALSE;
212 }
213
214 Bool_t AliGenMC::KinematicSelection(TParticle *particle, Int_t flag) const
215 {
216 // Perform kinematic selection
217     Float_t pz    = particle->Pz();
218     Float_t  e    = particle->Energy();
219     Float_t pt    = particle->Pt();
220     Float_t p     = particle->P();
221     Float_t theta = particle->Theta();
222     Float_t mass  = particle->GetCalcMass();
223     Float_t mt2   = pt * pt + mass * mass;
224     Float_t phi   = particle->Phi();
225     
226     Double_t y, y0;
227
228     if (TMath::Abs(pz) <  e) {
229         y = 0.5*TMath::Log((e+pz)/(e-pz));
230     } else {
231         y = 1.e10;
232     }
233     
234     if (mt2) {
235         y0 = 0.5*TMath::Log((e+TMath::Abs(pz))*(e+TMath::Abs(pz))/mt2);
236     } else {
237         if (TMath::Abs(y) < 1.e10) {
238             y0 = y;
239         } else {
240             y0 = 1.e10;
241         }
242     }
243       
244     y = (pz < 0) ? -y0 : y0;
245     
246     if (flag == 0) {
247 //
248 // Primary particle cuts
249 //
250 //  transverse momentum cut    
251         if (pt > fPtMax || pt < fPtMin) {
252 //          printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
253             return kFALSE;
254         }
255 //
256 // momentum cut
257         if (p > fPMax || p < fPMin) {
258 //          printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
259             return kFALSE;
260         }
261 //
262 // theta cut
263         if (theta > fThetaMax || theta < fThetaMin) {
264 //          printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
265             return kFALSE;
266         }
267 //
268 // rapidity cut
269         if (y > fYMax || y < fYMin) {
270 //          printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
271             return kFALSE;
272         }
273 //
274 // phi cut
275         if (phi > fPhiMax || phi < fPhiMin) {
276 //          printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
277             return kFALSE;
278         }
279     } else {
280 //
281 // Decay product cuts
282 //
283 //  transverse momentum cut    
284         if (pt > fChildPtMax || pt < fChildPtMin) {
285 //          printf("\n failed pt cut %f %f %f \n",pt,fChildPtMin,fChildPtMax);
286             return kFALSE;
287         }
288 //
289 // momentum cut
290         if (p > fChildPMax || p < fChildPMin) {
291 //          printf("\n failed p cut %f %f %f \n",p,fChildPMin,fChildPMax);
292             return kFALSE;
293         }
294 //
295 // theta cut
296         if (theta > fChildThetaMax || theta < fChildThetaMin) {
297 //          printf("\n failed theta cut %f %f %f \n",theta,fChildThetaMin,fChildThetaMax);
298             return kFALSE;
299         }
300 //
301 // rapidity cut
302         if (y > fChildYMax || y < fChildYMin) {
303 //          printf("\n failed y cut %f %f %f \n",y,fChildYMin,fChildYMax);
304             return kFALSE;
305         }
306 //
307 // phi cut
308         if (phi > fChildPhiMax || phi < fChildPhiMin) {
309 //          printf("\n failed phi cut %f %f %f \n",phi,fChildPhiMin,fChildPhiMax);
310             return kFALSE;
311         }
312     }
313     
314     return kTRUE;
315 }
316
317 Bool_t AliGenMC::CheckAcceptanceGeometry(Int_t np, TClonesArray* particles)
318 {
319 // Check the geometrical acceptance for particle.
320
321   Bool_t check ;  
322   Int_t numberOfPdgCodeParticleforAcceptanceCut = 0;
323   Int_t numberOfAcceptedPdgCodeParticleforAcceptanceCut = 0;
324   TParticle * particle;
325   Int_t i;
326   for (i = 0; i < np; i++) {
327     particle =  (TParticle *) particles->At(i);
328     if( TMath::Abs( particle->GetPdgCode() ) == TMath::Abs( fPdgCodeParticleforAcceptanceCut ) ) {
329       numberOfPdgCodeParticleforAcceptanceCut++;
330       if (fGeometryAcceptance->Impact(particle)) numberOfAcceptedPdgCodeParticleforAcceptanceCut++;
331     }   
332   }
333   if ( numberOfAcceptedPdgCodeParticleforAcceptanceCut > (fNumberOfAcceptedParticles-1) )
334     check = kTRUE;
335   else
336     check = kFALSE;
337
338   return check;
339 }
340
341 Int_t AliGenMC::CheckPDGCode(Int_t pdgcode) const
342 {
343 //
344 //  If the particle is in a diffractive state, then take action accordingly
345   switch (pdgcode) {
346   case 91:
347     return 92;
348   case 110:
349     //rho_diff0 -- difficult to translate, return rho0
350     return 113;
351   case 210:
352     //pi_diffr+ -- change to pi+
353     return 211;
354   case 220:
355     //omega_di0 -- change to omega0
356     return 223;
357   case 330:
358     //phi_diff0 -- return phi0
359     return 333;
360   case 440:
361     //J/psi_di0 -- return J/psi
362     return 443;
363   case 2110:
364     //n_diffr -- return neutron
365     return 2112;
366   case 2210:
367     //p_diffr+ -- return proton
368     return 2212;
369   }
370   //non diffractive state -- return code unchanged
371   return pdgcode;
372 }
373
374 void AliGenMC::Boost()
375 {
376 //
377 // Boost cms into LHC lab frame
378 //
379
380     Double_t beta  = TMath::TanH(fDyBoost);
381     Double_t gamma = 1./TMath::Sqrt(1.-beta*beta);
382     Double_t gb    = gamma * beta;
383
384     //    printf("\n Boosting particles to lab frame %f %f %f", fDyBoost, beta, gamma);
385     
386     Int_t i;
387     Int_t np = fParticles->GetEntriesFast();
388     for (i = 0; i < np; i++) 
389     {
390         TParticle* iparticle = (TParticle*) fParticles->At(i);
391
392         Double_t e   = iparticle->Energy();
393         Double_t px  = iparticle->Px();
394         Double_t py  = iparticle->Py();
395         Double_t pz  = iparticle->Pz();
396
397         Double_t eb  = gamma * e -      gb * pz;
398         Double_t pzb =   -gb * e +   gamma * pz;
399
400         iparticle->SetMomentum(px, py, pzb, eb);
401     }
402 }
403
404
405           
406 AliGenMC& AliGenMC::operator=(const  AliGenMC& rhs)
407 {
408 // Assignment operator
409     rhs.Copy(*this);
410     return *this;
411 }
412
413 void AliGenMC::Copy(TObject&) const
414 {
415     //
416     // Copy 
417     //
418     Fatal("Copy","Not implemented!\n");
419 }
420
421