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