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