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