]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PYTHIA6/AliGenPythiaJets.cxx
Bug fixes, warnings only in case of debug option, more comments (P.Skowronski)
[u/mrichter/AliRoot.git] / PYTHIA6 / AliGenPythiaJets.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 //
19 // Generator using the TPythia interface (via AliPythia)
20 // to generate jets in pp collisions.
21 // Using SetNuclei() also nuclear modifications to the structure functions
22 // can be taken into account. 
23 // Using SetQuenchingFactor(f) quenched jets can be modelled by superimposing 
24 // two jets with energies e * f and e * (1-f)
25 //
26 // andreas.morsch@cern.ch
27 //
28
29
30 #include "AliGenPythiaJets.h"
31 #include "AliRun.h"
32 #include <TParticle.h>
33
34 ClassImp(AliGenPythiaJets)
35
36 AliGenPythiaJets::AliGenPythiaJets()
37                  :AliGenPythia()
38 {
39 // Default Constructor
40 }
41
42 AliGenPythiaJets::AliGenPythiaJets(Int_t npart)
43                  :AliGenPythia(npart)
44 {
45     fName = "PythiaJets";
46     fTitle= "Jet Generator using PYTHIA";
47 }
48
49 AliGenPythiaJets::AliGenPythiaJets(const AliGenPythiaJets & Pythia)
50 {
51 // copy constructor
52     Pythia.Copy(*this);
53 }
54
55 AliGenPythiaJets::~AliGenPythiaJets()
56 {
57 // Destructor
58 }
59
60 void AliGenPythiaJets::Init()
61 {
62 // Initialization
63 //
64     printf("AliGenPythiaJets::Init() \n");
65     
66     AliGenPythia::Init();
67     
68     if (fQuench > 0.) {
69          fEtMinJetQ[0]  = fEtMinJet  * fQuench;  
70          fEtMaxJetQ[0]  = fEtMaxJet  * fQuench;  
71          fEtMinJetQ[1]  = fEtMinJet  * (1. - fQuench);  
72          fEtMaxJetQ[1]  = fEtMaxJet  * (1. - fQuench);
73          fPtHardMinQ[0] = fPtHardMin * fQuench;  
74          fPtHardMaxQ[0] = fPtHardMax * fQuench;  
75          fPtHardMinQ[1] = fPtHardMin * (1. - fQuench);  
76          fPtHardMaxQ[1] = fPtHardMax * (1. - fQuench);  
77     }
78 }
79
80 void AliGenPythiaJets::Generate()
81 {
82 // Generate one event
83     fDecayer->ForceDecay();
84
85     Float_t polar[3]   =   {0,0,0};
86     Float_t origin[3]  =   {0,0,0};
87     Float_t p[3];
88 //  converts from mm/c to s
89     const Float_t kconv=0.001/2.999792458e8;
90 //
91     Int_t nt  = 0;
92     Int_t nc  = 0;
93     Int_t jev = 0;
94     Int_t j, kf, iparent;
95     fTrials=0;
96 //
97 //  Set collision vertex position 
98     if(fVertexSmear==kPerEvent) {
99         fPythia->SetMSTP(151,1);
100         for (j=0;j<3;j++) {
101             fPythia->SetPARP(151+j, fOsigma[j]*10.);
102         }
103     } else if (fVertexSmear==kPerTrack) {
104         fPythia->SetMSTP(151,0);
105     }
106 //  Event loop    
107     while(1)
108     {
109         if (fQuench > 0.) {
110             fPythia->SetCKIN(3,fPtHardMinQ[jev]);
111             fPythia->SetCKIN(4,fPtHardMaxQ[jev]);
112             fEtMinJet = fEtMinJetQ[jev];
113             fEtMaxJet = fEtMaxJetQ[jev];            
114         }
115         
116         fPythia->Pyevnt();
117         if (gAlice->GetEvNumber()>=fDebugEventFirst &&
118             gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
119         fTrials++;
120         //
121         // Has this jet triggered
122         //
123         if ((fEtMinJet != -1) && ! CheckTrigger()) continue;
124 //
125         fPythia->ImportParticles(fParticles,"All");
126         Int_t i;
127         Int_t np = fParticles->GetEntriesFast();
128         if (np == 0 ) continue;
129 // Get event vertex and discard the event if the z coord. is too big    
130         TParticle *iparticle = (TParticle *) fParticles->At(0);
131         Float_t distz = iparticle->Vz()/10.;
132         if(TMath::Abs(distz)>fCutVertexZ*fOsigma[2]) continue;
133 //
134 //
135         fVertex[0] = iparticle->Vx()/10.+fOrigin.At(0);
136         fVertex[1] = iparticle->Vy()/10.+fOrigin.At(1);
137         fVertex[2] = iparticle->Vz()/10.+fOrigin.At(2);
138
139         Int_t* pParent = new Int_t[np];
140         for (i=0; i< np; i++) pParent[i] = -1;
141         
142
143         //
144         for (i = 0; i<np; i++) {
145             Int_t trackIt = 0;
146             TParticle *  iparticle = (TParticle *) fParticles->At(i);
147             kf = CheckPDGCode(iparticle->GetPdgCode());
148             Int_t ks = iparticle->GetStatusCode();
149             Int_t km = iparticle->GetFirstMother();
150             if ((ks == 1  && kf !=0 && KinematicSelection(iparticle, 0)) ||
151                 (ks != 1) ||
152                 (fProcess == kPyJets && ks == 21 && km == 0 && i > 1)) {
153                 nc++;
154                 if (ks == 1) trackIt = 1;
155                 Int_t ipa = iparticle->GetFirstMother() - 1;
156                 iparent = (ipa > -1) ? pParent[ipa] : -1;
157 //
158 // Store track information
159 //
160                 p[0] = iparticle->Px();
161                 p[1] = iparticle->Py();
162                 p[2] = iparticle->Pz();
163                 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
164                 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
165                 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
166                 Float_t tof=kconv*iparticle->T();
167                 PushTrack(fTrackIt*trackIt, iparent, kf, p, origin, polar,
168                          tof, kPPrimary, nt, 1., ks);
169                 KeepTrack(nt);
170                 pParent[i] = nt;
171             } // select particle
172         } // particle loop 
173         
174         if (pParent) delete[] pParent;
175         printf("\n AliGenPythiaJets: I've put %i particles on the stack \n",nc);
176         if (nc > 0) {
177             jev += 1;
178             if ((fQuench <= 0.) || (fQuench > 0. && jev == 2)) {
179                 fKineBias=Float_t(fNpart)/Float_t(fTrials);
180                 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
181                 fNev++;
182                 MakeHeader();
183                 break;
184             }
185         }
186     }
187     SetHighWaterMark(nt);
188 //  Get cross-section
189     fXsection=fPythia->GetPARI(1);
190 }
191
192 Bool_t AliGenPythiaJets::CheckTrigger()
193 {
194 // Check the kinematic trigger condition
195 //
196     Bool_t   triggered = kFALSE;
197     Int_t njets = 0;
198     Int_t ntrig = 0;
199     Float_t jets[4][10];
200 //
201 // Use Pythia clustering on parton level to determine jet axis
202 //
203     GetJets(njets, ntrig, jets);
204     
205     if (ntrig) {
206         triggered = kTRUE;
207         Float_t px   = jets[0][0];
208         Float_t py   = jets[1][0];
209         Float_t pz   = jets[2][0];
210         Float_t e    = jets[3][0];
211         Float_t beta = pz/e;
212         Float_t phi  =  TMath::Pi()+TMath::ATan2(-py,-px);
213         TransformEvent(beta, -2. * TMath::Pi() / 3. + phi);
214     }
215     return triggered;
216 }
217           
218 AliGenPythiaJets& AliGenPythiaJets::operator=(const  AliGenPythiaJets& rhs)
219 {
220 // Assignment operator
221     return *this;
222 }
223
224 void  AliGenPythiaJets::TransformEvent(Float_t beta, Float_t phi)
225 {
226 //
227 // Perform Lorentz Transformation and Rotation
228 //
229     Float_t gamma = 1./TMath::Sqrt(1. - beta * beta);
230     Int_t npart = (fPythia->GetPyjets())->N;
231
232     for (Int_t part = 0; part < npart; part++) {
233         Float_t px   =  (fPythia->GetPyjets())->P[0][part];
234         Float_t py   =  (fPythia->GetPyjets())->P[1][part];
235         Float_t pz   =  (fPythia->GetPyjets())->P[2][part];
236         Float_t e    =  (fPythia->GetPyjets())->P[3][part];
237         //
238         // Lorentz Transform
239         //
240         Float_t pzt =  gamma * pz        - gamma * beta * e;
241         Float_t et  = -gamma * beta * pz + gamma        * e;
242         //
243         // Rotation
244         //
245         Float_t pxt =   TMath::Cos(phi) * px +  TMath::Sin(phi) * py;
246         Float_t pyt = - TMath::Sin(phi) * px +  TMath::Cos(phi) * py;
247         //
248         //
249         (fPythia->GetPyjets())->P[0][part] = pxt;
250         (fPythia->GetPyjets())->P[1][part] = pyt;
251         (fPythia->GetPyjets())->P[2][part] = pzt;
252         (fPythia->GetPyjets())->P[3][part] = et;
253     }
254 }
255