]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVGEN/AliGenMC.cxx
MakeLoader added.
[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()
105 {
106 // Destructor
107 }
108
109 void AliGenMC::Init()
110 {
111 //
112 //  Initialization
113     switch (fForceDecay) {
114     case kBSemiElectronic:
115     case kSemiElectronic:
116     case kDiElectron:
117     case kBJpsiDiElectron:
118     case kBPsiPrimeDiElectron:
119         fChildSelect[0] = kElectron;    
120         break;
121     case kHardMuons:    
122     case kBSemiMuonic:
123     case kSemiMuonic:
124     case kDiMuon:
125     case kBJpsiDiMuon:
126     case kBPsiPrimeDiMuon:
127     case kPiToMu:
128     case kKaToMu:
129     case kWToMuon:
130     case kWToCharmToMuon:
131     case kZDiMuon:
132         fChildSelect[0]=kMuonMinus;
133         break;
134     case kWToCharm:
135         break;
136     case kHadronicD:
137     case kHadronicDWithout4Bodies:
138         fChildSelect[0]=kPiPlus;
139         fChildSelect[1]=kKPlus;
140         break;
141     case kPhiKK:
142         fChildSelect[0]=kKPlus;
143         break;
144     case kBJpsi:
145         fChildSelect[0]=443;
146         break;
147     case kOmega:        
148     case kAll:
149     case kAllMuonic:
150     case kNoDecay:
151     case kNoDecayHeavy:
152     case kNeutralPion:
153         break;
154     }
155
156     if (fZTarget != 0 && fAProjectile != 0) 
157     {
158         fDyBoost    = - 0.5 * TMath::Log(Double_t(fZProjectile) * Double_t(fATarget) / 
159                                          (Double_t(fZTarget)    * Double_t(fAProjectile)));
160     }
161 }
162
163
164 Bool_t AliGenMC::ParentSelected(Int_t ip) const
165 {
166 // True if particle is in list of parent particles to be selected
167     for (Int_t i=0; i<8; i++)
168     {
169         if (fParentSelect.At(i) == ip) return kTRUE;
170     }
171     return kFALSE;
172 }
173
174 Bool_t AliGenMC::ChildSelected(Int_t ip) const
175 {
176 // True if particle is in list of decay products to be selected
177     for (Int_t i=0; i<5; i++)
178     {
179         if (fChildSelect.At(i) == ip) return kTRUE;
180     }
181     return kFALSE;
182 }
183
184 Bool_t AliGenMC::KinematicSelection(TParticle *particle, Int_t flag) const
185 {
186 // Perform kinematic selection
187     Float_t pz    = particle->Pz();
188     Float_t  e    = particle->Energy();
189     Float_t pt    = particle->Pt();
190     Float_t p     = particle->P();
191     Float_t theta = particle->Theta();
192     Float_t mass  = particle->GetCalcMass();
193     Float_t mt2   = pt * pt + mass * mass;
194     Float_t phi   = particle->Phi();
195     
196     Double_t y, y0;
197
198     if (TMath::Abs(pz) <  e) {
199         y = 0.5*TMath::Log((e+pz)/(e-pz));
200     } else {
201         y = 1.e10;
202     }
203     
204     if (mt2) {
205         y0 = 0.5*TMath::Log((e+TMath::Abs(pz))*(e+TMath::Abs(pz))/mt2);
206     } else {
207         if (TMath::Abs(y) < 1.e10) {
208             y0 = y;
209         } else {
210             y0 = 1.e10;
211         }
212     }
213       
214     y = (pz < 0) ? -y0 : y0;
215     
216     if (flag == 0) {
217 //
218 // Primary particle cuts
219 //
220 //  transverse momentum cut    
221         if (pt > fPtMax || pt < fPtMin) {
222 //          printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
223             return kFALSE;
224         }
225 //
226 // momentum cut
227         if (p > fPMax || p < fPMin) {
228 //          printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
229             return kFALSE;
230         }
231 //
232 // theta cut
233         if (theta > fThetaMax || theta < fThetaMin) {
234 //          printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
235             return kFALSE;
236         }
237 //
238 // rapidity cut
239         if (y > fYMax || y < fYMin) {
240 //          printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
241             return kFALSE;
242         }
243 //
244 // phi cut
245         if (phi > fPhiMax || phi < fPhiMin) {
246 //          printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
247             return kFALSE;
248         }
249     } else {
250 //
251 // Decay product cuts
252 //
253 //  transverse momentum cut    
254         if (pt > fChildPtMax || pt < fChildPtMin) {
255 //          printf("\n failed pt cut %f %f %f \n",pt,fChildPtMin,fChildPtMax);
256             return kFALSE;
257         }
258 //
259 // momentum cut
260         if (p > fChildPMax || p < fChildPMin) {
261 //          printf("\n failed p cut %f %f %f \n",p,fChildPMin,fChildPMax);
262             return kFALSE;
263         }
264 //
265 // theta cut
266         if (theta > fChildThetaMax || theta < fChildThetaMin) {
267 //          printf("\n failed theta cut %f %f %f \n",theta,fChildThetaMin,fChildThetaMax);
268             return kFALSE;
269         }
270 //
271 // rapidity cut
272         if (y > fChildYMax || y < fChildYMin) {
273 //          printf("\n failed y cut %f %f %f \n",y,fChildYMin,fChildYMax);
274             return kFALSE;
275         }
276 //
277 // phi cut
278         if (phi > fChildPhiMax || phi < fChildPhiMin) {
279 //          printf("\n failed phi cut %f %f %f \n",phi,fChildPhiMin,fChildPhiMax);
280             return kFALSE;
281         }
282     }
283     
284     return kTRUE;
285 }
286
287 Bool_t AliGenMC::CheckAcceptanceGeometry(Int_t np, TClonesArray* particles)
288 {
289 // Check the geometrical acceptance for particle.
290
291   Bool_t check ;  
292   Int_t numberOfPdgCodeParticleforAcceptanceCut = 0;
293   Int_t numberOfAcceptedPdgCodeParticleforAcceptanceCut = 0;
294   TParticle * particle;
295   Int_t i;
296   for (i = 0; i < np; i++) {
297     particle =  (TParticle *) particles->At(i);
298     if( TMath::Abs( particle->GetPdgCode() ) == TMath::Abs( fPdgCodeParticleforAcceptanceCut ) ) {
299       numberOfPdgCodeParticleforAcceptanceCut++;
300       if (fGeometryAcceptance->Impact(particle)) numberOfAcceptedPdgCodeParticleforAcceptanceCut++;
301     }   
302   }
303   if ( numberOfAcceptedPdgCodeParticleforAcceptanceCut > (fNumberOfAcceptedParticles-1) )
304     check = kTRUE;
305   else
306     check = kFALSE;
307
308   return check;
309 }
310
311 Int_t AliGenMC::CheckPDGCode(Int_t pdgcode) const
312 {
313 //
314 //  If the particle is in a diffractive state, then take action accordingly
315   switch (pdgcode) {
316   case 91:
317     return 92;
318   case 110:
319     //rho_diff0 -- difficult to translate, return rho0
320     return 113;
321   case 210:
322     //pi_diffr+ -- change to pi+
323     return 211;
324   case 220:
325     //omega_di0 -- change to omega0
326     return 223;
327   case 330:
328     //phi_diff0 -- return phi0
329     return 333;
330   case 440:
331     //J/psi_di0 -- return J/psi
332     return 443;
333   case 2110:
334     //n_diffr -- return neutron
335     return 2112;
336   case 2210:
337     //p_diffr+ -- return proton
338     return 2212;
339   }
340   //non diffractive state -- return code unchanged
341   return pdgcode;
342 }
343
344 void AliGenMC::Boost()
345 {
346 //
347 // Boost cms into LHC lab frame
348 //
349
350     Double_t beta  = TMath::TanH(fDyBoost);
351     Double_t gamma = 1./TMath::Sqrt(1.-beta*beta);
352     Double_t gb    = gamma * beta;
353
354     //    printf("\n Boosting particles to lab frame %f %f %f", fDyBoost, beta, gamma);
355     
356     Int_t i;
357     Int_t np = fParticles->GetEntriesFast();
358     for (i = 0; i < np; i++) 
359     {
360         TParticle* iparticle = (TParticle*) fParticles->At(i);
361
362         Double_t e   = iparticle->Energy();
363         Double_t px  = iparticle->Px();
364         Double_t py  = iparticle->Py();
365         Double_t pz  = iparticle->Pz();
366
367         Double_t eb  = gamma * e -      gb * pz;
368         Double_t pzb =   -gb * e +   gamma * pz;
369
370         iparticle->SetMomentum(px, py, pzb, eb);
371     }
372 }