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