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