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