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