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