Get phi from iparticle.
[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
16/*
17$Log$
0b6d2cb3 18Revision 1.17 2003/04/30 14:48:21 hristov
19Changes related to the initialization of random numbers generators. Now one can use its own randoms for each module, particle generator, and/or tracking package. The interface with Fortran is simplified and some inter-library dependencies are avoided. Future improvements are welcome...
20
7cdba479 21Revision 1.16 2003/04/08 10:22:05 morsch
22Rapidity shift calculated in Init().
23
36d770d9 24Revision 1.15 2003/04/04 08:13:26 morsch
25Boost method added.
26
3b945a60 27Revision 1.14 2003/01/14 10:50:19 alibrary
28Cleanup of STEER coding conventions
29
116cbefd 30Revision 1.13 2002/10/14 14:55:35 hristov
31Merging the VirtualMC branch to the main development branch (HEAD)
32
b9d0a01d 33Revision 1.5.4.2 2002/07/24 08:56:28 alibrary
34Updating EVGEN on TVirtulaMC
35
36Revision 1.12 2002/07/19 11:42:33 morsch
37Use CalcMass()
38
cf01ee36 39Revision 1.11 2002/06/06 15:26:24 morsch
40Correct child-selection for kPhiKK
41
027677ae 42Revision 1.10 2002/06/05 14:05:46 morsch
43Decayer option kPhiKK for forced phi->K+K- decay added.
44
00cb2f27 45Revision 1.9 2002/05/30 14:58:29 morsch
46Add pointer to AliGeometry to handle geometrical acceptance. (G. MArtinez)
47
65de9f86 48Revision 1.8 2002/04/26 10:42:35 morsch
49Case kNoDecayHeavy added. (N. Carrer)
50
d5f86442 51Revision 1.7 2002/04/17 10:32:32 morsch
52Coding Rule violations corrected.
53
62d0ae06 54Revision 1.6 2002/03/26 14:19:36 morsch
55Saver calculation of rapdity.
56
fef61e14 57Revision 1.5 2002/03/12 17:02:20 morsch
58Change in calculation of rapidity, include case in which numerically e == pz.
59
95450c6d 60Revision 1.4 2001/11/27 13:13:07 morsch
61Maximum lifetime for long-lived particles to be put on the stack is parameter.
62It can be set via SetMaximumLifetime(..).
63
47fc6bd5 64Revision 1.3 2001/10/16 08:48:56 morsch
65Common vertex related code moved to base class AliGenerator.
66
b80a8e41 67Revision 1.2 2001/10/15 08:15:51 morsch
68Event vertex and vertex truncation setting moved into AliMC.
69
dba8ac91 70Revision 1.1 2001/07/13 10:56:00 morsch
71AliGenMC base class for AliGenParam and AliGenPythia commonalities.
72
e36044d6 73*/
74
62d0ae06 75// Base class for generators using external MC generators.
76// For example AliGenPythia using Pythia.
77// Provides basic functionality: setting of kinematic cuts on
78// decay products and particle selection.
79// andreas.morsch@cern.ch
80
65de9f86 81#include <TMath.h>
116cbefd 82#include <TPDGCode.h>
e36044d6 83#include <TParticle.h>
84
116cbefd 85#include "AliGenMC.h"
86
e36044d6 87 ClassImp(AliGenMC)
88
89AliGenMC::AliGenMC()
90 :AliGenerator()
91{
92// Default Constructor
93 SetCutOnChild();
94 SetChildMomentumRange();
95 SetChildPtRange();
96 SetChildPhiRange();
97 SetChildThetaRange();
98 SetChildYRange();
47fc6bd5 99 SetMaximumLifetime();
65de9f86 100 SetGeometryAcceptance();
101 SetPdgCodeParticleforAcceptanceCut();
102 SetNumberOfAcceptedParticles();
3b945a60 103 SetTarget();
104 SetProjectile();
e36044d6 105}
106
107AliGenMC::AliGenMC(Int_t npart)
108 :AliGenerator(npart)
109{
110// Constructor
111 SetCutOnChild();
112 SetChildMomentumRange();
113 SetChildPtRange();
114 SetChildPhiRange();
115 SetChildThetaRange();
116 SetChildYRange();
117//
118 fParentSelect.Set(8);
119 fChildSelect.Set(8);
120 for (Int_t i=0; i<8; i++) fParentSelect[i]=fChildSelect[i]=0;
47fc6bd5 121 SetMaximumLifetime();
65de9f86 122 SetGeometryAcceptance();
123 SetPdgCodeParticleforAcceptanceCut();
124 SetNumberOfAcceptedParticles();
3b945a60 125 SetTarget();
126 SetProjectile();
e36044d6 127}
128
129AliGenMC::AliGenMC(const AliGenMC & mc)
130{
131// copy constructor
132}
133
134AliGenMC::~AliGenMC()
135{
136// Destructor
137}
138
139void AliGenMC::Init()
140{
141//
142// Initialization
143 switch (fForceDecay) {
144 case kSemiElectronic:
145 case kDiElectron:
146 case kBJpsiDiElectron:
147 case kBPsiPrimeDiElectron:
47fc6bd5 148 fChildSelect[0] = kElectron;
e36044d6 149 break;
150 case kSemiMuonic:
151 case kDiMuon:
152 case kBJpsiDiMuon:
153 case kBPsiPrimeDiMuon:
154 case kPiToMu:
155 case kKaToMu:
156 fChildSelect[0]=kMuonMinus;
157 break;
158 case kHadronicD:
159 fChildSelect[0]=kPiPlus;
160 fChildSelect[1]=kKPlus;
161 break;
00cb2f27 162 case kPhiKK:
027677ae 163 fChildSelect[0]=kKPlus;
62d0ae06 164 case kOmega:
e36044d6 165 case kAll:
166 case kNoDecay:
d5f86442 167 case kNoDecayHeavy:
e36044d6 168 break;
169 }
36d770d9 170
171 if (fZTarget != 0 && fAProjectile != 0)
172 {
173 fDyBoost = - 0.5 * TMath::Log(Double_t(fZProjectile) * Double_t(fATarget) /
174 (Double_t(fZTarget) * Double_t(fAProjectile)));
175 }
e36044d6 176}
177
178
62d0ae06 179Bool_t AliGenMC::ParentSelected(Int_t ip) const
e36044d6 180{
181// True if particle is in list of parent particles to be selected
182 for (Int_t i=0; i<8; i++)
183 {
62d0ae06 184 if (fParentSelect.At(i) == ip) return kTRUE;
e36044d6 185 }
186 return kFALSE;
187}
188
62d0ae06 189Bool_t AliGenMC::ChildSelected(Int_t ip) const
e36044d6 190{
191// True if particle is in list of decay products to be selected
192 for (Int_t i=0; i<5; i++)
193 {
62d0ae06 194 if (fChildSelect.At(i) == ip) return kTRUE;
e36044d6 195 }
196 return kFALSE;
197}
198
62d0ae06 199Bool_t AliGenMC::KinematicSelection(TParticle *particle, Int_t flag) const
e36044d6 200{
201// Perform kinematic selection
e36044d6 202 Float_t pz = particle->Pz();
203 Float_t e = particle->Energy();
204 Float_t pt = particle->Pt();
205 Float_t p = particle->P();
206 Float_t theta = particle->Theta();
cf01ee36 207 Float_t mass = particle->GetCalcMass();
95450c6d 208 Float_t mt2 = pt * pt + mass * mass;
0b6d2cb3 209 Float_t phi = particle->Phi();
95450c6d 210
95450c6d 211 Double_t y, y0;
212
fef61e14 213 if (TMath::Abs(pz) < e) {
95450c6d 214 y = 0.5*TMath::Log((e+pz)/(e-pz));
215 } else {
216 y = 1.e10;
217 }
e36044d6 218
95450c6d 219 if (mt2) {
220 y0 = 0.5*TMath::Log((e+TMath::Abs(pz))*(e+TMath::Abs(pz))/mt2);
e36044d6 221 } else {
95450c6d 222 if (TMath::Abs(y) < 1.e10) {
223 y0 = y;
224 } else {
225 y0 = 1.e10;
226 }
e36044d6 227 }
95450c6d 228
229 y = (pz < 0) ? -y0 : y0;
e36044d6 230
231 if (flag == 0) {
232//
233// Primary particle cuts
234//
235// transverse momentum cut
236 if (pt > fPtMax || pt < fPtMin) {
237// printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
238 return kFALSE;
239 }
240//
241// momentum cut
242 if (p > fPMax || p < fPMin) {
243// printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
244 return kFALSE;
245 }
246//
247// theta cut
248 if (theta > fThetaMax || theta < fThetaMin) {
249// printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
250 return kFALSE;
251 }
252//
253// rapidity cut
254 if (y > fYMax || y < fYMin) {
255// printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
256 return kFALSE;
257 }
258//
259// phi cut
260 if (phi > fPhiMax || phi < fPhiMin) {
261// printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
262 return kFALSE;
263 }
264 } else {
265//
266// Decay product cuts
267//
268// transverse momentum cut
269 if (pt > fChildPtMax || pt < fChildPtMin) {
270// printf("\n failed pt cut %f %f %f \n",pt,fChildPtMin,fChildPtMax);
271 return kFALSE;
272 }
273//
274// momentum cut
275 if (p > fChildPMax || p < fChildPMin) {
276// printf("\n failed p cut %f %f %f \n",p,fChildPMin,fChildPMax);
277 return kFALSE;
278 }
279//
280// theta cut
281 if (theta > fChildThetaMax || theta < fChildThetaMin) {
282// printf("\n failed theta cut %f %f %f \n",theta,fChildThetaMin,fChildThetaMax);
283 return kFALSE;
284 }
285//
286// rapidity cut
287 if (y > fChildYMax || y < fChildYMin) {
288// printf("\n failed y cut %f %f %f \n",y,fChildYMin,fChildYMax);
289 return kFALSE;
290 }
291//
292// phi cut
293 if (phi > fChildPhiMax || phi < fChildPhiMin) {
294// printf("\n failed phi cut %f %f %f \n",phi,fChildPhiMin,fChildPhiMax);
295 return kFALSE;
296 }
297 }
298
e36044d6 299 return kTRUE;
300}
301
65de9f86 302Bool_t AliGenMC::CheckAcceptanceGeometry(Int_t np, TClonesArray* particles)
303{
304 Bool_t Check ; // All fPdgCodeParticleforAcceptanceCut particles are in in the fGeometryAcceptance acceptance
305 Int_t NumberOfPdgCodeParticleforAcceptanceCut=0;
306 Int_t NumberOfAcceptedPdgCodeParticleforAcceptanceCut=0;
307 TParticle * particle;
308 Int_t i;
309 for (i=0; i<np; i++) {
310 particle = (TParticle *) particles->At(i);
311 if( TMath::Abs( particle->GetPdgCode() ) == TMath::Abs( fPdgCodeParticleforAcceptanceCut ) ) {
312 NumberOfPdgCodeParticleforAcceptanceCut++;
313 if (fGeometryAcceptance->Impact(particle)) NumberOfAcceptedPdgCodeParticleforAcceptanceCut++;
314 }
315 }
316 if ( NumberOfAcceptedPdgCodeParticleforAcceptanceCut > (fNumberOfAcceptedParticles-1) )
317 Check = kTRUE;
318 else
319 Check = kFALSE;
320
321 return Check;
322}
323
62d0ae06 324Int_t AliGenMC::CheckPDGCode(Int_t pdgcode) const
e36044d6 325{
326//
327// If the particle is in a diffractive state, then take action accordingly
328 switch (pdgcode) {
329 case 91:
330 return 92;
331 case 110:
332 //rho_diff0 -- difficult to translate, return rho0
333 return 113;
334 case 210:
335 //pi_diffr+ -- change to pi+
336 return 211;
337 case 220:
338 //omega_di0 -- change to omega0
339 return 223;
340 case 330:
341 //phi_diff0 -- return phi0
342 return 333;
343 case 440:
344 //J/psi_di0 -- return J/psi
345 return 443;
346 case 2110:
347 //n_diffr -- return neutron
348 return 2112;
349 case 2210:
350 //p_diffr+ -- return proton
351 return 2212;
352 }
353 //non diffractive state -- return code unchanged
354 return pdgcode;
355}
3b945a60 356
36d770d9 357void AliGenMC::Boost()
3b945a60 358{
359//
360// Boost cms into LHC lab frame
361//
362
36d770d9 363 Double_t beta = TMath::TanH(fDyBoost);
3b945a60 364 Double_t gamma = 1./TMath::Sqrt(1.-beta*beta);
365 Double_t gb = gamma * beta;
366
7cdba479 367 // printf("\n Boosting particles to lab frame %f %f %f", fDyBoost, beta, gamma);
3b945a60 368
369 Int_t i;
370 Int_t np = fParticles->GetEntriesFast();
371 for (i = 0; i < np; i++)
372 {
373 TParticle* iparticle = (TParticle*) fParticles->At(i);
374
375 Double_t e = iparticle->Energy();
376 Double_t px = iparticle->Px();
377 Double_t py = iparticle->Py();
378 Double_t pz = iparticle->Pz();
379
380 Double_t eb = gamma * e - gb * pz;
381 Double_t pzb = -gb * e + gamma * pz;
382
383 iparticle->SetMomentum(px, py, pzb, eb);
384 }
385}
386
387
e36044d6 388
389AliGenMC& AliGenMC::operator=(const AliGenMC& rhs)
390{
391// Assignment operator
392 return *this;
393}
394