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