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