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