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