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