Updated VZERO source
[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$
00cb2f27 18Revision 1.9 2002/05/30 14:58:29 morsch
19Add pointer to AliGeometry to handle geometrical acceptance. (G. MArtinez)
20
65de9f86 21Revision 1.8 2002/04/26 10:42:35 morsch
22Case kNoDecayHeavy added. (N. Carrer)
23
d5f86442 24Revision 1.7 2002/04/17 10:32:32 morsch
25Coding Rule violations corrected.
26
62d0ae06 27Revision 1.6 2002/03/26 14:19:36 morsch
28Saver calculation of rapdity.
29
fef61e14 30Revision 1.5 2002/03/12 17:02:20 morsch
31Change in calculation of rapidity, include case in which numerically e == pz.
32
95450c6d 33Revision 1.4 2001/11/27 13:13:07 morsch
34Maximum lifetime for long-lived particles to be put on the stack is parameter.
35It can be set via SetMaximumLifetime(..).
36
47fc6bd5 37Revision 1.3 2001/10/16 08:48:56 morsch
38Common vertex related code moved to base class AliGenerator.
39
b80a8e41 40Revision 1.2 2001/10/15 08:15:51 morsch
41Event vertex and vertex truncation setting moved into AliMC.
42
dba8ac91 43Revision 1.1 2001/07/13 10:56:00 morsch
44AliGenMC base class for AliGenParam and AliGenPythia commonalities.
45
e36044d6 46*/
47
62d0ae06 48// Base class for generators using external MC generators.
49// For example AliGenPythia using Pythia.
50// Provides basic functionality: setting of kinematic cuts on
51// decay products and particle selection.
52// andreas.morsch@cern.ch
53
e36044d6 54#include "AliGenMC.h"
55#include "AliPDG.h"
65de9f86 56#include <TMath.h>
e36044d6 57#include <TParticle.h>
58
59 ClassImp(AliGenMC)
60
61AliGenMC::AliGenMC()
62 :AliGenerator()
63{
64// Default Constructor
65 SetCutOnChild();
66 SetChildMomentumRange();
67 SetChildPtRange();
68 SetChildPhiRange();
69 SetChildThetaRange();
70 SetChildYRange();
47fc6bd5 71 SetMaximumLifetime();
65de9f86 72 SetGeometryAcceptance();
73 SetPdgCodeParticleforAcceptanceCut();
74 SetNumberOfAcceptedParticles();
e36044d6 75}
76
77AliGenMC::AliGenMC(Int_t npart)
78 :AliGenerator(npart)
79{
80// Constructor
81 SetCutOnChild();
82 SetChildMomentumRange();
83 SetChildPtRange();
84 SetChildPhiRange();
85 SetChildThetaRange();
86 SetChildYRange();
87//
88 fParentSelect.Set(8);
89 fChildSelect.Set(8);
90 for (Int_t i=0; i<8; i++) fParentSelect[i]=fChildSelect[i]=0;
47fc6bd5 91 SetMaximumLifetime();
65de9f86 92 SetGeometryAcceptance();
93 SetPdgCodeParticleforAcceptanceCut();
94 SetNumberOfAcceptedParticles();
e36044d6 95}
96
97AliGenMC::AliGenMC(const AliGenMC & mc)
98{
99// copy constructor
100}
101
102AliGenMC::~AliGenMC()
103{
104// Destructor
105}
106
107void AliGenMC::Init()
108{
109//
110// Initialization
111 switch (fForceDecay) {
112 case kSemiElectronic:
113 case kDiElectron:
114 case kBJpsiDiElectron:
115 case kBPsiPrimeDiElectron:
47fc6bd5 116 fChildSelect[0] = kElectron;
e36044d6 117 break;
118 case kSemiMuonic:
119 case kDiMuon:
120 case kBJpsiDiMuon:
121 case kBPsiPrimeDiMuon:
122 case kPiToMu:
123 case kKaToMu:
124 fChildSelect[0]=kMuonMinus;
125 break;
126 case kHadronicD:
127 fChildSelect[0]=kPiPlus;
128 fChildSelect[1]=kKPlus;
129 break;
00cb2f27 130 case kPhiKK:
62d0ae06 131 case kOmega:
e36044d6 132 case kAll:
133 case kNoDecay:
d5f86442 134 case kNoDecayHeavy:
e36044d6 135 break;
136 }
137}
138
139
62d0ae06 140Bool_t AliGenMC::ParentSelected(Int_t ip) const
e36044d6 141{
142// True if particle is in list of parent particles to be selected
143 for (Int_t i=0; i<8; i++)
144 {
62d0ae06 145 if (fParentSelect.At(i) == ip) return kTRUE;
e36044d6 146 }
147 return kFALSE;
148}
149
62d0ae06 150Bool_t AliGenMC::ChildSelected(Int_t ip) const
e36044d6 151{
152// True if particle is in list of decay products to be selected
153 for (Int_t i=0; i<5; i++)
154 {
62d0ae06 155 if (fChildSelect.At(i) == ip) return kTRUE;
e36044d6 156 }
157 return kFALSE;
158}
159
62d0ae06 160Bool_t AliGenMC::KinematicSelection(TParticle *particle, Int_t flag) const
e36044d6 161{
162// Perform kinematic selection
163 Float_t px = particle->Px();
164 Float_t py = particle->Py();
165 Float_t pz = particle->Pz();
166 Float_t e = particle->Energy();
167 Float_t pt = particle->Pt();
168 Float_t p = particle->P();
169 Float_t theta = particle->Theta();
95450c6d 170 Float_t mass = particle->GetMass();
171 Float_t mt2 = pt * pt + mass * mass;
172
e36044d6 173 Float_t phi = Float_t(TMath::ATan2(Double_t(py),Double_t(px)));
95450c6d 174 Double_t y, y0;
175
fef61e14 176 if (TMath::Abs(pz) < e) {
95450c6d 177 y = 0.5*TMath::Log((e+pz)/(e-pz));
178 } else {
179 y = 1.e10;
180 }
e36044d6 181
95450c6d 182 if (mt2) {
183 y0 = 0.5*TMath::Log((e+TMath::Abs(pz))*(e+TMath::Abs(pz))/mt2);
e36044d6 184 } else {
95450c6d 185 if (TMath::Abs(y) < 1.e10) {
186 y0 = y;
187 } else {
188 y0 = 1.e10;
189 }
e36044d6 190 }
95450c6d 191
192 y = (pz < 0) ? -y0 : y0;
e36044d6 193
194 if (flag == 0) {
195//
196// Primary particle cuts
197//
198// transverse momentum cut
199 if (pt > fPtMax || pt < fPtMin) {
200// printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
201 return kFALSE;
202 }
203//
204// momentum cut
205 if (p > fPMax || p < fPMin) {
206// printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
207 return kFALSE;
208 }
209//
210// theta cut
211 if (theta > fThetaMax || theta < fThetaMin) {
212// printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
213 return kFALSE;
214 }
215//
216// rapidity cut
217 if (y > fYMax || y < fYMin) {
218// printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
219 return kFALSE;
220 }
221//
222// phi cut
223 if (phi > fPhiMax || phi < fPhiMin) {
224// printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
225 return kFALSE;
226 }
227 } else {
228//
229// Decay product cuts
230//
231// transverse momentum cut
232 if (pt > fChildPtMax || pt < fChildPtMin) {
233// printf("\n failed pt cut %f %f %f \n",pt,fChildPtMin,fChildPtMax);
234 return kFALSE;
235 }
236//
237// momentum cut
238 if (p > fChildPMax || p < fChildPMin) {
239// printf("\n failed p cut %f %f %f \n",p,fChildPMin,fChildPMax);
240 return kFALSE;
241 }
242//
243// theta cut
244 if (theta > fChildThetaMax || theta < fChildThetaMin) {
245// printf("\n failed theta cut %f %f %f \n",theta,fChildThetaMin,fChildThetaMax);
246 return kFALSE;
247 }
248//
249// rapidity cut
250 if (y > fChildYMax || y < fChildYMin) {
251// printf("\n failed y cut %f %f %f \n",y,fChildYMin,fChildYMax);
252 return kFALSE;
253 }
254//
255// phi cut
256 if (phi > fChildPhiMax || phi < fChildPhiMin) {
257// printf("\n failed phi cut %f %f %f \n",phi,fChildPhiMin,fChildPhiMax);
258 return kFALSE;
259 }
260 }
261
e36044d6 262 return kTRUE;
263}
264
65de9f86 265Bool_t AliGenMC::CheckAcceptanceGeometry(Int_t np, TClonesArray* particles)
266{
267 Bool_t Check ; // All fPdgCodeParticleforAcceptanceCut particles are in in the fGeometryAcceptance acceptance
268 Int_t NumberOfPdgCodeParticleforAcceptanceCut=0;
269 Int_t NumberOfAcceptedPdgCodeParticleforAcceptanceCut=0;
270 TParticle * particle;
271 Int_t i;
272 for (i=0; i<np; i++) {
273 particle = (TParticle *) particles->At(i);
274 if( TMath::Abs( particle->GetPdgCode() ) == TMath::Abs( fPdgCodeParticleforAcceptanceCut ) ) {
275 NumberOfPdgCodeParticleforAcceptanceCut++;
276 if (fGeometryAcceptance->Impact(particle)) NumberOfAcceptedPdgCodeParticleforAcceptanceCut++;
277 }
278 }
279 if ( NumberOfAcceptedPdgCodeParticleforAcceptanceCut > (fNumberOfAcceptedParticles-1) )
280 Check = kTRUE;
281 else
282 Check = kFALSE;
283
284 return Check;
285}
286
62d0ae06 287Int_t AliGenMC::CheckPDGCode(Int_t pdgcode) const
e36044d6 288{
289//
290// If the particle is in a diffractive state, then take action accordingly
291 switch (pdgcode) {
292 case 91:
293 return 92;
294 case 110:
295 //rho_diff0 -- difficult to translate, return rho0
296 return 113;
297 case 210:
298 //pi_diffr+ -- change to pi+
299 return 211;
300 case 220:
301 //omega_di0 -- change to omega0
302 return 223;
303 case 330:
304 //phi_diff0 -- return phi0
305 return 333;
306 case 440:
307 //J/psi_di0 -- return J/psi
308 return 443;
309 case 2110:
310 //n_diffr -- return neutron
311 return 2112;
312 case 2210:
313 //p_diffr+ -- return proton
314 return 2212;
315 }
316 //non diffractive state -- return code unchanged
317 return pdgcode;
318}
319
320AliGenMC& AliGenMC::operator=(const AliGenMC& rhs)
321{
322// Assignment operator
323 return *this;
324}
325