]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVGEN/AliGenMC.cxx
20-jan-2007 NvE AliMath extended with Nfac(), LnNfac() and LogNfac() facilities.
[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
198bb1c7 104AliGenMC::AliGenMC(const AliGenMC & mc):
1c56e311 105 AliGenerator(mc),
106 fParticles(0),
107 fParentSelect(8),
108 fChildSelect(8),
109 fCutOnChild(0),
110 fChildPtMin(0.),
111 fChildPtMax(1.e10),
112 fChildPMin(0.),
113 fChildPMax(1.e10),
114 fChildPhiMin(0.),
115 fChildPhiMax(2. * TMath::Pi()),
116 fChildThetaMin(0.),
117 fChildThetaMax(TMath::Pi()),
118 fChildYMin(-12.),
119 fChildYMax(12.),
120 fXingAngleX(0.),
121 fXingAngleY(0.),
122 fForceDecay(kAll),
123 fMaxLifeTime(1.e-15),
124 fAProjectile(1),
125 fZProjectile(1),
126 fATarget(1),
127 fZTarget(1),
128 fProjectile("P"),
129 fTarget("P"),
130 fDyBoost(0.),
131 fGeometryAcceptance(0),
132 fPdgCodeParticleforAcceptanceCut(0),
133 fNumberOfAcceptedParticles(2)
e36044d6 134{
198bb1c7 135// Copy constructor
136 mc.Copy(*this);
e36044d6 137}
138
139AliGenMC::~AliGenMC()
140{
141// Destructor
142}
143
144void AliGenMC::Init()
145{
146//
147// Initialization
148 switch (fForceDecay) {
149 case kSemiElectronic:
150 case kDiElectron:
151 case kBJpsiDiElectron:
152 case kBPsiPrimeDiElectron:
47fc6bd5 153 fChildSelect[0] = kElectron;
e36044d6 154 break;
2dcb5874 155 case kHardMuons:
e36044d6 156 case kSemiMuonic:
157 case kDiMuon:
158 case kBJpsiDiMuon:
159 case kBPsiPrimeDiMuon:
160 case kPiToMu:
161 case kKaToMu:
cd159249 162 case kWToMuon:
163 case kWToCharmToMuon:
2f299526 164 case kZDiMuon:
e36044d6 165 fChildSelect[0]=kMuonMinus;
166 break;
cd159249 167 case kWToCharm:
168 break;
e36044d6 169 case kHadronicD:
170 fChildSelect[0]=kPiPlus;
171 fChildSelect[1]=kKPlus;
172 break;
00cb2f27 173 case kPhiKK:
027677ae 174 fChildSelect[0]=kKPlus;
56d47239 175 break;
176 case kBJpsi:
177 fChildSelect[0]=443;
178 break;
62d0ae06 179 case kOmega:
e36044d6 180 case kAll:
181 case kNoDecay:
d5f86442 182 case kNoDecayHeavy:
e36044d6 183 break;
184 }
36d770d9 185
186 if (fZTarget != 0 && fAProjectile != 0)
187 {
188 fDyBoost = - 0.5 * TMath::Log(Double_t(fZProjectile) * Double_t(fATarget) /
189 (Double_t(fZTarget) * Double_t(fAProjectile)));
190 }
e36044d6 191}
192
193
62d0ae06 194Bool_t AliGenMC::ParentSelected(Int_t ip) const
e36044d6 195{
196// True if particle is in list of parent particles to be selected
197 for (Int_t i=0; i<8; i++)
198 {
62d0ae06 199 if (fParentSelect.At(i) == ip) return kTRUE;
e36044d6 200 }
201 return kFALSE;
202}
203
62d0ae06 204Bool_t AliGenMC::ChildSelected(Int_t ip) const
e36044d6 205{
206// True if particle is in list of decay products to be selected
207 for (Int_t i=0; i<5; i++)
208 {
62d0ae06 209 if (fChildSelect.At(i) == ip) return kTRUE;
e36044d6 210 }
211 return kFALSE;
212}
213
62d0ae06 214Bool_t AliGenMC::KinematicSelection(TParticle *particle, Int_t flag) const
e36044d6 215{
216// Perform kinematic selection
e36044d6 217 Float_t pz = particle->Pz();
218 Float_t e = particle->Energy();
219 Float_t pt = particle->Pt();
220 Float_t p = particle->P();
221 Float_t theta = particle->Theta();
cf01ee36 222 Float_t mass = particle->GetCalcMass();
95450c6d 223 Float_t mt2 = pt * pt + mass * mass;
0b6d2cb3 224 Float_t phi = particle->Phi();
95450c6d 225
95450c6d 226 Double_t y, y0;
227
fef61e14 228 if (TMath::Abs(pz) < e) {
95450c6d 229 y = 0.5*TMath::Log((e+pz)/(e-pz));
230 } else {
231 y = 1.e10;
232 }
e36044d6 233
95450c6d 234 if (mt2) {
235 y0 = 0.5*TMath::Log((e+TMath::Abs(pz))*(e+TMath::Abs(pz))/mt2);
e36044d6 236 } else {
95450c6d 237 if (TMath::Abs(y) < 1.e10) {
238 y0 = y;
239 } else {
240 y0 = 1.e10;
241 }
e36044d6 242 }
95450c6d 243
244 y = (pz < 0) ? -y0 : y0;
e36044d6 245
246 if (flag == 0) {
247//
248// Primary particle cuts
249//
250// transverse momentum cut
251 if (pt > fPtMax || pt < fPtMin) {
252// printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
253 return kFALSE;
254 }
255//
256// momentum cut
257 if (p > fPMax || p < fPMin) {
258// printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
259 return kFALSE;
260 }
261//
262// theta cut
263 if (theta > fThetaMax || theta < fThetaMin) {
264// printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
265 return kFALSE;
266 }
267//
268// rapidity cut
269 if (y > fYMax || y < fYMin) {
270// printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
271 return kFALSE;
272 }
273//
274// phi cut
275 if (phi > fPhiMax || phi < fPhiMin) {
276// printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
277 return kFALSE;
278 }
279 } else {
280//
281// Decay product cuts
282//
283// transverse momentum cut
284 if (pt > fChildPtMax || pt < fChildPtMin) {
285// printf("\n failed pt cut %f %f %f \n",pt,fChildPtMin,fChildPtMax);
286 return kFALSE;
287 }
288//
289// momentum cut
290 if (p > fChildPMax || p < fChildPMin) {
291// printf("\n failed p cut %f %f %f \n",p,fChildPMin,fChildPMax);
292 return kFALSE;
293 }
294//
295// theta cut
296 if (theta > fChildThetaMax || theta < fChildThetaMin) {
297// printf("\n failed theta cut %f %f %f \n",theta,fChildThetaMin,fChildThetaMax);
298 return kFALSE;
299 }
300//
301// rapidity cut
302 if (y > fChildYMax || y < fChildYMin) {
303// printf("\n failed y cut %f %f %f \n",y,fChildYMin,fChildYMax);
304 return kFALSE;
305 }
306//
307// phi cut
308 if (phi > fChildPhiMax || phi < fChildPhiMin) {
309// printf("\n failed phi cut %f %f %f \n",phi,fChildPhiMin,fChildPhiMax);
310 return kFALSE;
311 }
312 }
313
e36044d6 314 return kTRUE;
315}
316
65de9f86 317Bool_t AliGenMC::CheckAcceptanceGeometry(Int_t np, TClonesArray* particles)
318{
e033748b 319// Check the geometrical acceptance for particle.
320
321 Bool_t check ;
322 Int_t numberOfPdgCodeParticleforAcceptanceCut = 0;
323 Int_t numberOfAcceptedPdgCodeParticleforAcceptanceCut = 0;
65de9f86 324 TParticle * particle;
325 Int_t i;
e033748b 326 for (i = 0; i < np; i++) {
65de9f86 327 particle = (TParticle *) particles->At(i);
328 if( TMath::Abs( particle->GetPdgCode() ) == TMath::Abs( fPdgCodeParticleforAcceptanceCut ) ) {
e033748b 329 numberOfPdgCodeParticleforAcceptanceCut++;
330 if (fGeometryAcceptance->Impact(particle)) numberOfAcceptedPdgCodeParticleforAcceptanceCut++;
65de9f86 331 }
332 }
e033748b 333 if ( numberOfAcceptedPdgCodeParticleforAcceptanceCut > (fNumberOfAcceptedParticles-1) )
334 check = kTRUE;
65de9f86 335 else
e033748b 336 check = kFALSE;
65de9f86 337
e033748b 338 return check;
65de9f86 339}
340
62d0ae06 341Int_t AliGenMC::CheckPDGCode(Int_t pdgcode) const
e36044d6 342{
343//
344// If the particle is in a diffractive state, then take action accordingly
345 switch (pdgcode) {
346 case 91:
347 return 92;
348 case 110:
349 //rho_diff0 -- difficult to translate, return rho0
350 return 113;
351 case 210:
352 //pi_diffr+ -- change to pi+
353 return 211;
354 case 220:
355 //omega_di0 -- change to omega0
356 return 223;
357 case 330:
358 //phi_diff0 -- return phi0
359 return 333;
360 case 440:
361 //J/psi_di0 -- return J/psi
362 return 443;
363 case 2110:
364 //n_diffr -- return neutron
365 return 2112;
366 case 2210:
367 //p_diffr+ -- return proton
368 return 2212;
369 }
370 //non diffractive state -- return code unchanged
371 return pdgcode;
372}
3b945a60 373
36d770d9 374void AliGenMC::Boost()
3b945a60 375{
376//
377// Boost cms into LHC lab frame
378//
379
36d770d9 380 Double_t beta = TMath::TanH(fDyBoost);
3b945a60 381 Double_t gamma = 1./TMath::Sqrt(1.-beta*beta);
382 Double_t gb = gamma * beta;
383
7cdba479 384 // printf("\n Boosting particles to lab frame %f %f %f", fDyBoost, beta, gamma);
3b945a60 385
386 Int_t i;
387 Int_t np = fParticles->GetEntriesFast();
388 for (i = 0; i < np; i++)
389 {
390 TParticle* iparticle = (TParticle*) fParticles->At(i);
391
392 Double_t e = iparticle->Energy();
393 Double_t px = iparticle->Px();
394 Double_t py = iparticle->Py();
395 Double_t pz = iparticle->Pz();
396
397 Double_t eb = gamma * e - gb * pz;
398 Double_t pzb = -gb * e + gamma * pz;
399
400 iparticle->SetMomentum(px, py, pzb, eb);
401 }
402}
403
404
e36044d6 405
406AliGenMC& AliGenMC::operator=(const AliGenMC& rhs)
407{
408// Assignment operator
198bb1c7 409 rhs.Copy(*this);
e36044d6 410 return *this;
411}
412
dc1d768c 413void AliGenMC::Copy(TObject&) const
198bb1c7 414{
415 //
416 // Copy
417 //
418 Fatal("Copy","Not implemented!\n");
419}
420
421