]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVGEN/AliGenMC.cxx
Transform method can copy the covariance matrix into the space-point if flag is set...
[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     case kZDiElectron:
136         fChildSelect[0]=kMuonMinus;
137         break;
138     case kWToCharm:
139         break;
140     case kHadronicD:
141     case kHadronicDWithout4Bodies:
142         fChildSelect[0]=kPiPlus;
143         fChildSelect[1]=kKPlus;
144         break;
145     case kPhiKK:
146         fChildSelect[0]=kKPlus;
147         break;
148     case kBJpsi:
149         fChildSelect[0]=443;
150         break;
151     case kOmega:        
152     case kAll:
153     case kAllMuonic:
154     case kNoDecay:
155     case kNoDecayHeavy:
156     case kNeutralPion:
157         break;
158     }
159
160     if (fZTarget != 0 && fAProjectile != 0) 
161     {
162         fDyBoost    = - 0.5 * TMath::Log(Double_t(fZProjectile) * Double_t(fATarget) / 
163                                          (Double_t(fZTarget)    * Double_t(fAProjectile)));
164     }
165 }
166
167
168 Bool_t AliGenMC::ParentSelected(Int_t ip) const
169 {
170 // True if particle is in list of parent particles to be selected
171     for (Int_t i=0; i<8; i++)
172     {
173         if (fParentSelect.At(i) == ip) return kTRUE;
174     }
175     return kFALSE;
176 }
177
178 Bool_t AliGenMC::ChildSelected(Int_t ip) const
179 {
180 // True if particle is in list of decay products to be selected
181     for (Int_t i=0; i<5; i++)
182     {
183         if (fChildSelect.At(i) == ip) return kTRUE;
184     }
185     return kFALSE;
186 }
187
188 Bool_t AliGenMC::KinematicSelection(TParticle *particle, Int_t flag) const
189 {
190 // Perform kinematic selection
191     Float_t pz    = particle->Pz();
192     Float_t  e    = particle->Energy();
193     Float_t pt    = particle->Pt();
194     Float_t p     = particle->P();
195     Float_t theta = particle->Theta();
196     Float_t mass  = particle->GetCalcMass();
197     Float_t mt2   = pt * pt + mass * mass;
198     Float_t phi   = particle->Phi();
199     
200     Double_t y, y0;
201
202     if (TMath::Abs(pz) <  e) {
203         y = 0.5*TMath::Log((e+pz)/(e-pz));
204     } else {
205         y = 1.e10;
206     }
207     
208     if (mt2) {
209         y0 = 0.5*TMath::Log((e+TMath::Abs(pz))*(e+TMath::Abs(pz))/mt2);
210     } else {
211         if (TMath::Abs(y) < 1.e10) {
212             y0 = y;
213         } else {
214             y0 = 1.e10;
215         }
216     }
217       
218     y = (pz < 0) ? -y0 : y0;
219     
220     if (flag == 0) {
221 //
222 // Primary particle cuts
223 //
224 //  transverse momentum cut    
225         if (pt > fPtMax || pt < fPtMin) {
226 //          printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
227             return kFALSE;
228         }
229 //
230 // momentum cut
231         if (p > fPMax || p < fPMin) {
232 //          printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
233             return kFALSE;
234         }
235 //
236 // theta cut
237         if (theta > fThetaMax || theta < fThetaMin) {
238 //          printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
239             return kFALSE;
240         }
241 //
242 // rapidity cut
243         if (y > fYMax || y < fYMin) {
244 //          printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
245             return kFALSE;
246         }
247 //
248 // phi cut
249         if (phi > fPhiMax || phi < fPhiMin) {
250 //          printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
251             return kFALSE;
252         }
253     } else {
254 //
255 // Decay product cuts
256 //
257 //  transverse momentum cut    
258         if (pt > fChildPtMax || pt < fChildPtMin) {
259 //          printf("\n failed pt cut %f %f %f \n",pt,fChildPtMin,fChildPtMax);
260             return kFALSE;
261         }
262 //
263 // momentum cut
264         if (p > fChildPMax || p < fChildPMin) {
265 //          printf("\n failed p cut %f %f %f \n",p,fChildPMin,fChildPMax);
266             return kFALSE;
267         }
268 //
269 // theta cut
270         if (theta > fChildThetaMax || theta < fChildThetaMin) {
271 //          printf("\n failed theta cut %f %f %f \n",theta,fChildThetaMin,fChildThetaMax);
272             return kFALSE;
273         }
274 //
275 // rapidity cut
276         if (y > fChildYMax || y < fChildYMin) {
277 //          printf("\n failed y cut %f %f %f \n",y,fChildYMin,fChildYMax);
278             return kFALSE;
279         }
280 //
281 // phi cut
282         if (phi > fChildPhiMax || phi < fChildPhiMin) {
283 //          printf("\n failed phi cut %f %f %f \n",phi,fChildPhiMin,fChildPhiMax);
284             return kFALSE;
285         }
286     }
287     
288     return kTRUE;
289 }
290
291 Bool_t AliGenMC::CheckAcceptanceGeometry(Int_t np, TClonesArray* particles)
292 {
293 // Check the geometrical acceptance for particle.
294
295   Bool_t check ;  
296   Int_t numberOfPdgCodeParticleforAcceptanceCut = 0;
297   Int_t numberOfAcceptedPdgCodeParticleforAcceptanceCut = 0;
298   TParticle * particle;
299   Int_t i;
300   for (i = 0; i < np; i++) {
301     particle =  (TParticle *) particles->At(i);
302     if( TMath::Abs( particle->GetPdgCode() ) == TMath::Abs( fPdgCodeParticleforAcceptanceCut ) ) {
303       numberOfPdgCodeParticleforAcceptanceCut++;
304       if (fGeometryAcceptance->Impact(particle)) numberOfAcceptedPdgCodeParticleforAcceptanceCut++;
305     }   
306   }
307   if ( numberOfAcceptedPdgCodeParticleforAcceptanceCut > (fNumberOfAcceptedParticles-1) )
308     check = kTRUE;
309   else
310     check = kFALSE;
311
312   return check;
313 }
314
315 Int_t AliGenMC::CheckPDGCode(Int_t pdgcode) const
316 {
317 //
318 //  If the particle is in a diffractive state, then take action accordingly
319   switch (pdgcode) {
320   case 91:
321     return 92;
322   case 110:
323     //rho_diff0 -- difficult to translate, return rho0
324     return 113;
325   case 210:
326     //pi_diffr+ -- change to pi+
327     return 211;
328   case 220:
329     //omega_di0 -- change to omega0
330     return 223;
331   case 330:
332     //phi_diff0 -- return phi0
333     return 333;
334   case 440:
335     //J/psi_di0 -- return J/psi
336     return 443;
337   case 2110:
338     //n_diffr -- return neutron
339     return 2112;
340   case 2210:
341     //p_diffr+ -- return proton
342     return 2212;
343   }
344   //non diffractive state -- return code unchanged
345   return pdgcode;
346 }
347
348 void AliGenMC::Boost()
349 {
350 //
351 // Boost cms into LHC lab frame
352 //
353
354     Double_t beta  = TMath::TanH(fDyBoost);
355     Double_t gamma = 1./TMath::Sqrt(1.-beta*beta);
356     Double_t gb    = gamma * beta;
357
358     //    printf("\n Boosting particles to lab frame %f %f %f", fDyBoost, beta, gamma);
359     
360     Int_t i;
361     Int_t np = fParticles->GetEntriesFast();
362     for (i = 0; i < np; i++) 
363     {
364         TParticle* iparticle = (TParticle*) fParticles->At(i);
365
366         Double_t e   = iparticle->Energy();
367         Double_t px  = iparticle->Px();
368         Double_t py  = iparticle->Py();
369         Double_t pz  = iparticle->Pz();
370
371         Double_t eb  = gamma * e -      gb * pz;
372         Double_t pzb =   -gb * e +   gamma * pz;
373
374         iparticle->SetMomentum(px, py, pzb, eb);
375     }
376 }
377
378 void AliGenMC::AddHeader(AliGenEventHeader* header)
379 {
380     // Passes header either to the container or to gAlice
381     if (fContainer) {
382         fContainer->AddHeader(header);
383     } else {
384         gAlice->SetGenEventHeader(header);      
385     }
386 }