kBSemiElectronic and kBSemiMuonic 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:
e36044d6 150 break;
151 }
36d770d9 152
153 if (fZTarget != 0 && fAProjectile != 0)
154 {
155 fDyBoost = - 0.5 * TMath::Log(Double_t(fZProjectile) * Double_t(fATarget) /
156 (Double_t(fZTarget) * Double_t(fAProjectile)));
157 }
e36044d6 158}
159
160
62d0ae06 161Bool_t AliGenMC::ParentSelected(Int_t ip) const
e36044d6 162{
163// True if particle is in list of parent particles to be selected
164 for (Int_t i=0; i<8; i++)
165 {
62d0ae06 166 if (fParentSelect.At(i) == ip) return kTRUE;
e36044d6 167 }
168 return kFALSE;
169}
170
62d0ae06 171Bool_t AliGenMC::ChildSelected(Int_t ip) const
e36044d6 172{
173// True if particle is in list of decay products to be selected
174 for (Int_t i=0; i<5; i++)
175 {
62d0ae06 176 if (fChildSelect.At(i) == ip) return kTRUE;
e36044d6 177 }
178 return kFALSE;
179}
180
62d0ae06 181Bool_t AliGenMC::KinematicSelection(TParticle *particle, Int_t flag) const
e36044d6 182{
183// Perform kinematic selection
e36044d6 184 Float_t pz = particle->Pz();
185 Float_t e = particle->Energy();
186 Float_t pt = particle->Pt();
187 Float_t p = particle->P();
188 Float_t theta = particle->Theta();
cf01ee36 189 Float_t mass = particle->GetCalcMass();
95450c6d 190 Float_t mt2 = pt * pt + mass * mass;
0b6d2cb3 191 Float_t phi = particle->Phi();
95450c6d 192
95450c6d 193 Double_t y, y0;
194
fef61e14 195 if (TMath::Abs(pz) < e) {
95450c6d 196 y = 0.5*TMath::Log((e+pz)/(e-pz));
197 } else {
198 y = 1.e10;
199 }
e36044d6 200
95450c6d 201 if (mt2) {
202 y0 = 0.5*TMath::Log((e+TMath::Abs(pz))*(e+TMath::Abs(pz))/mt2);
e36044d6 203 } else {
95450c6d 204 if (TMath::Abs(y) < 1.e10) {
205 y0 = y;
206 } else {
207 y0 = 1.e10;
208 }
e36044d6 209 }
95450c6d 210
211 y = (pz < 0) ? -y0 : y0;
e36044d6 212
213 if (flag == 0) {
214//
215// Primary particle cuts
216//
217// transverse momentum cut
218 if (pt > fPtMax || pt < fPtMin) {
219// printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
220 return kFALSE;
221 }
222//
223// momentum cut
224 if (p > fPMax || p < fPMin) {
225// printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
226 return kFALSE;
227 }
228//
229// theta cut
230 if (theta > fThetaMax || theta < fThetaMin) {
231// printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
232 return kFALSE;
233 }
234//
235// rapidity cut
236 if (y > fYMax || y < fYMin) {
237// printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
238 return kFALSE;
239 }
240//
241// phi cut
242 if (phi > fPhiMax || phi < fPhiMin) {
243// printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
244 return kFALSE;
245 }
246 } else {
247//
248// Decay product cuts
249//
250// transverse momentum cut
251 if (pt > fChildPtMax || pt < fChildPtMin) {
252// printf("\n failed pt cut %f %f %f \n",pt,fChildPtMin,fChildPtMax);
253 return kFALSE;
254 }
255//
256// momentum cut
257 if (p > fChildPMax || p < fChildPMin) {
258// printf("\n failed p cut %f %f %f \n",p,fChildPMin,fChildPMax);
259 return kFALSE;
260 }
261//
262// theta cut
263 if (theta > fChildThetaMax || theta < fChildThetaMin) {
264// printf("\n failed theta cut %f %f %f \n",theta,fChildThetaMin,fChildThetaMax);
265 return kFALSE;
266 }
267//
268// rapidity cut
269 if (y > fChildYMax || y < fChildYMin) {
270// printf("\n failed y cut %f %f %f \n",y,fChildYMin,fChildYMax);
271 return kFALSE;
272 }
273//
274// phi cut
275 if (phi > fChildPhiMax || phi < fChildPhiMin) {
276// printf("\n failed phi cut %f %f %f \n",phi,fChildPhiMin,fChildPhiMax);
277 return kFALSE;
278 }
279 }
280
e36044d6 281 return kTRUE;
282}
283
65de9f86 284Bool_t AliGenMC::CheckAcceptanceGeometry(Int_t np, TClonesArray* particles)
285{
e033748b 286// Check the geometrical acceptance for particle.
287
288 Bool_t check ;
289 Int_t numberOfPdgCodeParticleforAcceptanceCut = 0;
290 Int_t numberOfAcceptedPdgCodeParticleforAcceptanceCut = 0;
65de9f86 291 TParticle * particle;
292 Int_t i;
e033748b 293 for (i = 0; i < np; i++) {
65de9f86 294 particle = (TParticle *) particles->At(i);
295 if( TMath::Abs( particle->GetPdgCode() ) == TMath::Abs( fPdgCodeParticleforAcceptanceCut ) ) {
e033748b 296 numberOfPdgCodeParticleforAcceptanceCut++;
297 if (fGeometryAcceptance->Impact(particle)) numberOfAcceptedPdgCodeParticleforAcceptanceCut++;
65de9f86 298 }
299 }
e033748b 300 if ( numberOfAcceptedPdgCodeParticleforAcceptanceCut > (fNumberOfAcceptedParticles-1) )
301 check = kTRUE;
65de9f86 302 else
e033748b 303 check = kFALSE;
65de9f86 304
e033748b 305 return check;
65de9f86 306}
307
62d0ae06 308Int_t AliGenMC::CheckPDGCode(Int_t pdgcode) const
e36044d6 309{
310//
311// If the particle is in a diffractive state, then take action accordingly
312 switch (pdgcode) {
313 case 91:
314 return 92;
315 case 110:
316 //rho_diff0 -- difficult to translate, return rho0
317 return 113;
318 case 210:
319 //pi_diffr+ -- change to pi+
320 return 211;
321 case 220:
322 //omega_di0 -- change to omega0
323 return 223;
324 case 330:
325 //phi_diff0 -- return phi0
326 return 333;
327 case 440:
328 //J/psi_di0 -- return J/psi
329 return 443;
330 case 2110:
331 //n_diffr -- return neutron
332 return 2112;
333 case 2210:
334 //p_diffr+ -- return proton
335 return 2212;
336 }
337 //non diffractive state -- return code unchanged
338 return pdgcode;
339}
3b945a60 340
36d770d9 341void AliGenMC::Boost()
3b945a60 342{
343//
344// Boost cms into LHC lab frame
345//
346
36d770d9 347 Double_t beta = TMath::TanH(fDyBoost);
3b945a60 348 Double_t gamma = 1./TMath::Sqrt(1.-beta*beta);
349 Double_t gb = gamma * beta;
350
7cdba479 351 // printf("\n Boosting particles to lab frame %f %f %f", fDyBoost, beta, gamma);
3b945a60 352
353 Int_t i;
354 Int_t np = fParticles->GetEntriesFast();
355 for (i = 0; i < np; i++)
356 {
357 TParticle* iparticle = (TParticle*) fParticles->At(i);
358
359 Double_t e = iparticle->Energy();
360 Double_t px = iparticle->Px();
361 Double_t py = iparticle->Py();
362 Double_t pz = iparticle->Pz();
363
364 Double_t eb = gamma * e - gb * pz;
365 Double_t pzb = -gb * e + gamma * pz;
366
367 iparticle->SetMomentum(px, py, pzb, eb);
368 }
369}