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