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