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