]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVGEN/AliGenMC.cxx
correct mask for V0 charge decoding in STU payload
[u/mrichter/AliRoot.git] / EVGEN / AliGenMC.cxx
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 /* $Id$ */
17
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
24 #include <TClonesArray.h>
25 #include <TMath.h>
26 #include <TPDGCode.h>
27 #include <TParticle.h>
28 #include <TLorentzVector.h>
29 #include <TVector3.h>
30
31 #include "AliGenMC.h"
32 #include "AliRun.h"
33 #include "AliGeometry.h"
34 #include "AliDecayer.h"
35
36 ClassImp(AliGenMC)
37
38 AliGenMC::AliGenMC()
39     :AliGenerator(),
40      fParticles("TParticle", 1000),
41      fParentSelect(8),
42      fChildSelect(8),
43      fCutOnChild(0),
44      fChildPtMin(0.),
45      fChildPtMax(1.e10),
46      fChildPMin(0.),
47      fChildPMax(1.e10),
48      fChildPhiMin(0.),
49      fChildPhiMax(2. * TMath::Pi()),
50      fChildThetaMin(0.),
51      fChildThetaMax(TMath::Pi()),
52      fChildYMin(-12.),
53      fChildYMax(12.),
54      fXingAngleX(0.),
55      fXingAngleY(0.),
56      fForceDecay(kAll),
57      fMaxLifeTime(1.e-15),
58      fDyBoost(0.),
59      fGeometryAcceptance(0),
60      fPdgCodeParticleforAcceptanceCut(0),
61      fNumberOfAcceptedParticles(0),
62      fNprimaries(0)
63 {
64 // Default Constructor
65   fAProjectile = 1;
66   fZProjectile = 1;
67   fATarget = 1;
68   fZTarget = 1;
69   fProjectile = "P";
70   fTarget = "P";
71 }
72
73 AliGenMC::AliGenMC(Int_t npart)
74     :AliGenerator(npart),
75      fParticles("TParticle", 1000),
76      fParentSelect(8),
77      fChildSelect(8),
78      fCutOnChild(0),
79      fChildPtMin(0.),
80      fChildPtMax(1.e10),
81      fChildPMin(0.),
82      fChildPMax(1.e10),
83      fChildPhiMin(0.),
84      fChildPhiMax(2. * TMath::Pi()),
85      fChildThetaMin(0.),
86      fChildThetaMax(TMath::Pi()),
87      fChildYMin(-12.),
88      fChildYMax(12.),
89      fXingAngleX(0.),
90      fXingAngleY(0.),
91      fForceDecay(kAll),
92      fMaxLifeTime(1.e-15),
93      fDyBoost(0.),
94      fGeometryAcceptance(0),
95      fPdgCodeParticleforAcceptanceCut(0),
96      fNumberOfAcceptedParticles(0),
97      fNprimaries(0)
98 {
99 //  Constructor
100 // 
101   fAProjectile = 1;
102   fZProjectile = 1;
103   fATarget = 1;
104   fZTarget = 1;
105   fProjectile = "P";
106   fTarget = "P";
107   for (Int_t i=0; i<8; i++) fParentSelect[i]=fChildSelect[i]=0;
108 }
109
110 AliGenMC::~AliGenMC()
111 {
112 // Destructor
113 }
114
115 void AliGenMC::Init()
116 {
117 //
118 //  Initialization
119     switch (fForceDecay) {
120     case kBSemiElectronic:
121     case kSemiElectronic:
122     case kDiElectron:
123     case kBJpsiDiElectron:
124     case kBPsiPrimeDiElectron:
125     case kElectronEM:
126     case kDiElectronEM:
127         fChildSelect[0] = kElectron;    
128         break;
129     case kHardMuons:    
130     case kBSemiMuonic:
131     case kSemiMuonic:
132     case kDiMuon:
133     case kJpsiDiMuon:
134     case kBJpsiDiMuon:
135     case kBPsiPrimeDiMuon:
136     case kPiToMu:
137     case kKaToMu:
138     case kWToMuon:
139     case kWToCharmToMuon:
140     case kZDiMuon:
141     case kZDiElectron:
142         fChildSelect[0]=kMuonMinus;
143         break;
144     case kWToCharm:
145         break;
146     case kHadronicD:
147     case kHadronicDWithout4Bodies:
148         fChildSelect[0]=kPiPlus;
149         fChildSelect[1]=kKPlus;
150         break;
151     case kPhiKK:
152         fChildSelect[0]=kKPlus;
153         break;
154     case kBJpsi:
155         fChildSelect[0]= 443;
156         break;
157    case kChiToJpsiGammaToMuonMuon:
158         fChildSelect[0]= 22;
159         fChildSelect[1]= 13;
160         break;
161     case kChiToJpsiGammaToElectronElectron:
162         fChildSelect[0]= 22;
163         fChildSelect[1]= 11;
164         break;
165     case kLambda:       
166         fChildSelect[0]= kProton;
167         fChildSelect[1]= 211;
168         break;
169     case kPsiPrimeJpsiDiElectron:
170         fChildSelect[0]= 211;
171         fChildSelect[1]= 11;
172         break;
173     case kGammaEM:
174         fChildSelect[0] = kGamma;       
175         break;
176     case kOmega:
177     case kAll:
178     case kAllMuonic:
179     case kNoDecay:
180     case kNoDecayHeavy:
181     case kNoDecayBeauty:
182     case kNeutralPion:
183         break;
184     }
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     }
191 }
192
193
194 Bool_t AliGenMC::ParentSelected(Int_t ip) const
195 {
196 // True if particle is in list of parent particles to be selected
197     for (Int_t i=0; i<8; i++)
198     {
199         if (fParentSelect.At(i) == ip) return kTRUE;
200     }
201     return kFALSE;
202 }
203
204 Bool_t AliGenMC::ChildSelected(Int_t ip) const
205 {
206 // True if particle is in list of decay products to be selected
207     for (Int_t i=0; i<5; i++)
208     {
209         if (fChildSelect.At(i) == ip) return kTRUE;
210     }
211     return kFALSE;
212 }
213
214 Bool_t AliGenMC::KinematicSelection(const TParticle *particle, Int_t flag) const
215 {
216 // Perform kinematic selection
217     Double_t pz    = particle->Pz();
218     Double_t pt    = particle->Pt();
219     Double_t p     = particle->P();
220     Double_t theta = particle->Theta();
221     Double_t mass  = particle->GetCalcMass();
222     Double_t mt2   = pt * pt + mass * mass;
223     Double_t phi   = particle->Phi();
224     Double_t e     = particle->Energy();
225     
226     if (e == 0.)     
227         e = TMath::Sqrt(p * p + mass * mass);
228
229     
230     Double_t y, y0;
231
232     if (TMath::Abs(pz) <  e) {
233         y = 0.5*TMath::Log((e+pz)/(e-pz));
234     } else {
235         y = 1.e10;
236     }
237     
238     if (mt2) {
239         y0 = 0.5*TMath::Log((e+TMath::Abs(pz))*(e+TMath::Abs(pz))/mt2);
240     } else {
241         if (TMath::Abs(y) < 1.e10) {
242             y0 = y;
243         } else {
244             y0 = 1.e10;
245         }
246     }
247       
248     y = (pz < 0) ? -y0 : y0;
249     
250     if (flag == 0) {
251 //
252 // Primary particle cuts
253 //
254 //  transverse momentum cut    
255         if (pt > fPtMax || pt < fPtMin) {
256 //          printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
257             return kFALSE;
258         }
259 //
260 // momentum cut
261         if (p > fPMax || p < fPMin) {
262 //          printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
263             return kFALSE;
264         }
265 //
266 // theta cut
267         if (theta > fThetaMax || theta < fThetaMin) {
268 //          printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
269             return kFALSE;
270         }
271 //
272 // rapidity cut
273         if (y > fYMax || y < fYMin) {
274 //          printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
275             return kFALSE;
276         }
277 //
278 // phi cut
279         if (phi > fPhiMax || phi < fPhiMin) {
280 //          printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
281             return kFALSE;
282         }
283     } else {
284 //
285 // Decay product cuts
286 //
287 //  transverse momentum cut    
288         if (pt > fChildPtMax || pt < fChildPtMin) {
289 //          printf("\n failed pt cut %f %f %f \n",pt,fChildPtMin,fChildPtMax);
290             return kFALSE;
291         }
292 //
293 // momentum cut
294         if (p > fChildPMax || p < fChildPMin) {
295 //          printf("\n failed p cut %f %f %f \n",p,fChildPMin,fChildPMax);
296             return kFALSE;
297         }
298 //
299 // theta cut
300         if (theta > fChildThetaMax || theta < fChildThetaMin) {
301 //          printf("\n failed theta cut %f %f %f \n",theta,fChildThetaMin,fChildThetaMax);
302             return kFALSE;
303         }
304 //
305 // rapidity cut
306         if (y > fChildYMax || y < fChildYMin) {
307 //          printf("\n failed y cut %f %f %f \n",y,fChildYMin,fChildYMax);
308             return kFALSE;
309         }
310 //
311 // phi cut
312         if (phi > fChildPhiMax || phi < fChildPhiMin) {
313 //          printf("\n failed phi cut %f %f %f \n",phi,fChildPhiMin,fChildPhiMax);
314             return kFALSE;
315         }
316     }
317     
318     return kTRUE;
319 }
320
321 Bool_t AliGenMC::CheckAcceptanceGeometry(Int_t np, TClonesArray* particles)
322 {
323 // Check the geometrical acceptance for particle.
324
325   Bool_t check ;  
326   Int_t numberOfPdgCodeParticleforAcceptanceCut = 0;
327   Int_t numberOfAcceptedPdgCodeParticleforAcceptanceCut = 0;
328   TParticle * particle;
329   Int_t i;
330   for (i = 0; i < np; i++) {
331     particle =  (TParticle *) particles->At(i);
332     if( TMath::Abs( particle->GetPdgCode() ) == TMath::Abs( fPdgCodeParticleforAcceptanceCut ) ) {
333       numberOfPdgCodeParticleforAcceptanceCut++;
334       if (fGeometryAcceptance->Impact(particle)) numberOfAcceptedPdgCodeParticleforAcceptanceCut++;
335     }   
336   }
337   if ( numberOfAcceptedPdgCodeParticleforAcceptanceCut > (fNumberOfAcceptedParticles-1) )
338     check = kTRUE;
339   else
340     check = kFALSE;
341
342   return check;
343 }
344
345 Int_t AliGenMC::CheckPDGCode(Int_t pdgcode) const
346 {
347 //
348 //  If the particle is in a diffractive state, then take action accordingly
349   switch (pdgcode) {
350   case 91:
351     return 92;
352   case 110:
353     //rho_diff0 -- difficult to translate, return rho0
354     return 113;
355   case 210:
356     //pi_diffr+ -- change to pi+
357     return 211;
358   case 220:
359     //omega_di0 -- change to omega0
360     return 223;
361   case 330:
362     //phi_diff0 -- return phi0
363     return 333;
364   case 440:
365     //J/psi_di0 -- return J/psi
366     return 443;
367   case 2110:
368     //n_diffr -- return neutron
369     return 2112;
370   case 2210:
371     //p_diffr+ -- return proton
372     return 2212;
373   }
374   //non diffractive state -- return code unchanged
375   return pdgcode;
376 }
377
378 void AliGenMC::Boost()
379 {
380 //
381 // Boost cms into LHC lab frame
382 //
383
384     Double_t beta  = TMath::TanH(fDyBoost);
385     Double_t gamma = 1./TMath::Sqrt((1.-beta)*(1.+beta));
386     Double_t gb    = gamma * beta;
387
388     //    printf("\n Boosting particles to lab frame %f %f %f", fDyBoost, beta, gamma);
389     
390     Int_t i;
391     Int_t np = fParticles.GetEntriesFast();
392     for (i = 0; i < np; i++) 
393     {
394         TParticle* iparticle = (TParticle*) fParticles.At(i);
395
396         Double_t e   = iparticle->Energy();
397         Double_t px  = iparticle->Px();
398         Double_t py  = iparticle->Py();
399         Double_t pz  = iparticle->Pz();
400
401         Double_t eb  = gamma * e -      gb * pz;
402         Double_t pzb =   -gb * e +   gamma * pz;
403
404         iparticle->SetMomentum(px, py, pzb, eb);
405     }
406 }
407
408 void AliGenMC::BeamCrossAngle()
409 {
410   // Applies a boost in the y-direction in order to take into account the 
411   // beam crossing angle
412
413   Double_t thetaPr0, phiPr0, pyPr2, pzPr2;
414   TVector3 beta;
415   
416   thetaPr0 = fXingAngleY / 2.;
417   phiPr0 = 0;
418
419   // Momentum of the CMS system
420   pyPr2 = TMath::Sqrt(fEnergyCMS * fEnergyCMS/ 4 - 0.938 * 0.938) * TMath::Sin(thetaPr0); 
421   pzPr2 = TMath::Sqrt(fEnergyCMS * fEnergyCMS/ 4 - 0.938 * 0.938) * TMath::Cos(thetaPr0);
422
423   TLorentzVector proj1Vect, proj2Vect, projVect;
424   proj1Vect.SetPxPyPzE(0., pyPr2, pzPr2, fEnergyCMS/2);
425   proj2Vect.SetPxPyPzE(0., pyPr2,-pzPr2, fEnergyCMS/2);
426   projVect = proj1Vect + proj2Vect;
427   beta=(1. / projVect.E()) * (projVect.Vect());
428
429   Int_t i;
430   Int_t np = fParticles.GetEntriesFast();
431   for (i = 0; i < np; i++) 
432     {
433       TParticle* iparticle = (TParticle*) fParticles.At(i);
434
435       Double_t e   = iparticle->Energy();
436       Double_t px  = iparticle->Px();
437       Double_t py  = iparticle->Py();
438       Double_t pz  = iparticle->Pz();
439       
440       TLorentzVector partIn;
441       partIn.SetPxPyPzE(px,py,pz,e);
442       partIn.Boost(beta);
443       iparticle->SetMomentum(partIn.Px(),partIn.Py(),partIn.Pz(),partIn.E());
444     }
445 }
446
447
448 void AliGenMC::AddHeader(AliGenEventHeader* header)
449 {
450     // Passes header either to the container or to gAlice
451     if (fContainer) {
452         fContainer->AddHeader(header);
453     } else {
454         gAlice->SetGenEventHeader(header);      
455     }
456 }