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