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