]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PYTHIA6/AliGenPythia.cxx
- LoadEvent with stack as argument.
[u/mrichter/AliRoot.git] / PYTHIA6 / AliGenPythia.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 pp collisions.
21 // Using SetNuclei() also nuclear modifications to the structure functions
22 // can be taken into account. This makes, of course, only sense for the
23 // generation of the products of hard processes (heavy flavor, jets ...)
24 //
25 // andreas.morsch@cern.ch
26 //
27
28 #include <TDatabasePDG.h>
29 #include <TParticle.h>
30 #include <TPDGCode.h>
31 #include <TSystem.h>
32 #include <TTree.h>
33
34 #include "AliConst.h"
35 #include "AliDecayerPythia.h"
36 #include "AliGenPythia.h"
37 #include "AliGenPythiaEventHeader.h"
38 #include "AliPythia.h"
39 #include "AliPythiaRndm.h"
40 #include "AliRun.h"
41 #include "AliStack.h"
42 #include "AliRunLoader.h"
43 #include "AliMC.h"
44
45 ClassImp(AliGenPythia)
46
47 AliGenPythia::AliGenPythia()
48                  :AliGenMC()
49 {
50 // Default Constructor
51   fParticles = 0;
52   fPythia    = 0;
53   fHeader = 0;
54   fDecayer   = new AliDecayerPythia();
55   SetEventListRange();
56   SetJetPhiRange();
57   SetJetEtaRange();
58   SetJetEtRange();
59   SetGammaPhiRange();
60   SetGammaEtaRange();
61   SetPtKick();
62   SetQuench();
63   
64   fSetNuclei = kFALSE;
65   if (!AliPythiaRndm::GetPythiaRandom()) 
66     AliPythiaRndm::SetPythiaRandom(GetRandom());
67 }
68
69 AliGenPythia::AliGenPythia(Int_t npart)
70                  :AliGenMC(npart)
71 {
72 // default charm production at 5. 5 TeV
73 // semimuonic decay
74 // structure function GRVHO
75 //
76     fName = "Pythia";
77     fTitle= "Particle Generator using PYTHIA";
78     fXsection  = 0.;
79     SetProcess();
80     SetStrucFunc();
81     SetForceDecay();
82     SetPtHard();
83     SetYHard();
84     SetEnergyCMS();
85     fDecayer = new AliDecayerPythia();
86     // Set random number generator 
87     if (!AliPythiaRndm::GetPythiaRandom()) 
88       AliPythiaRndm::SetPythiaRandom(GetRandom());
89     fFlavorSelect   = 0;
90     // Produced particles  
91     fParticles = new TClonesArray("TParticle",1000);
92     fHeader = 0;
93     SetEventListRange();
94     SetJetPhiRange();
95     SetJetEtaRange();
96     SetJetEtRange();
97     SetGammaPhiRange();
98     SetGammaEtaRange();
99     SetJetReconstructionMode();
100     SetQuench();
101     SetPtKick();
102     // Options determining what to keep in the stack (Heavy flavour generation)
103     fStackFillOpt = kFlavorSelection; // Keep particle with selected flavor
104     fFeedDownOpt = kTRUE;             // allow feed down from higher family
105     // Fragmentation on/off
106     fFragmentation = kTRUE;
107     // Default counting mode
108     fCountMode = kCountAll;
109     // Pycel
110     SetPycellParameters();
111     fSetNuclei = kFALSE;
112 }
113
114 AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
115     :AliGenMC(Pythia)
116 {
117 // copy constructor
118     Pythia.Copy(*this);
119 }
120
121 AliGenPythia::~AliGenPythia()
122 {
123 // Destructor
124 }
125
126 void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
127                                        Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
128 {
129 // Set pycell parameters
130     fPycellEtaMax    =  etamax;
131     fPycellNEta      =  neta;
132     fPycellNPhi      =  nphi;
133     fPycellThreshold =  thresh;
134     fPycellEtSeed    =  etseed;
135     fPycellMinEtJet  =  minet;
136     fPycellMaxRadius =  r;
137 }
138
139
140
141 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
142 {
143   // Set a range of event numbers, for which a table
144   // of generated particle will be printed
145   fDebugEventFirst = eventFirst;
146   fDebugEventLast  = eventLast;
147   if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
148 }
149
150 void AliGenPythia::Init()
151 {
152 // Initialisation
153     
154     SetMC(AliPythia::Instance());
155     fPythia=(AliPythia*) fMCEvGen;
156     
157 //
158     fParentWeight=1./Float_t(fNpart);
159 //
160 //  Forward Paramters to the AliPythia object
161     fDecayer->SetForceDecay(fForceDecay);    
162     fDecayer->Init();
163
164
165     fPythia->SetCKIN(3,fPtHardMin);
166     fPythia->SetCKIN(4,fPtHardMax);
167     fPythia->SetCKIN(7,fYHardMin);
168     fPythia->SetCKIN(8,fYHardMax);
169     
170     if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);  
171     // Fragmentation?
172     if (fFragmentation) {
173       fPythia->SetMSTP(111,1);
174     } else {
175       fPythia->SetMSTP(111,0);
176     }
177
178
179 //  initial state radiation   
180     fPythia->SetMSTP(61,fGinit);
181 //  final state radiation
182     fPythia->SetMSTP(71,fGfinal);
183 //  pt - kick
184     if (fPtKick > 0.) {
185         fPythia->SetMSTP(91,1);
186         fPythia->SetPARP(91,fPtKick);
187     } else {
188         fPythia->SetMSTP(91,0);
189     }
190
191  //   fPythia->SetMSTJ(1,2);
192  //
193     fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
194
195 //  Parent and Children Selection
196     switch (fProcess) 
197     {
198     case kPyCharm:
199     case kPyCharmUnforced:
200     case kPyCharmPbPbMNR:
201     case kPyCharmppMNR:
202     case kPyCharmpPbMNR:
203         fParentSelect[0] =   411;
204         fParentSelect[1] =   421;
205         fParentSelect[2] =   431;
206         fParentSelect[3] =  4122;
207         fFlavorSelect    =  4;  
208         break;
209     case kPyD0PbPbMNR:
210     case kPyD0pPbMNR:
211     case kPyD0ppMNR:
212         fParentSelect[0] =   421;
213         fFlavorSelect    =   4; 
214         break;
215     case kPyBeauty:
216     case kPyBeautyPbPbMNR:
217     case kPyBeautypPbMNR:
218     case kPyBeautyppMNR:
219         fParentSelect[0]=  511;
220         fParentSelect[1]=  521;
221         fParentSelect[2]=  531;
222         fParentSelect[3]= 5122;
223         fParentSelect[4]= 5132;
224         fParentSelect[5]= 5232;
225         fParentSelect[6]= 5332;
226         fFlavorSelect   = 5;    
227         break;
228     case kPyBeautyUnforced:
229         fParentSelect[0] =  511;
230         fParentSelect[1] =  521;
231         fParentSelect[2] =  531;
232         fParentSelect[3] = 5122;
233         fParentSelect[4] = 5132;
234         fParentSelect[5] = 5232;
235         fParentSelect[6] = 5332;
236         fFlavorSelect    = 5;   
237         break;
238     case kPyJpsiChi:
239     case kPyJpsi:
240         fParentSelect[0] = 443;
241         break;
242     case kPyMb:
243     case kPyMbNonDiffr:
244     case kPyJets:
245     case kPyDirectGamma:
246         break;
247     }
248 //
249 //
250 //  JetFinder for Trigger
251 //
252 //  Configure detector (EMCAL like)
253 //
254         fPythia->SetPARU(51, fPycellEtaMax);
255         fPythia->SetMSTU(51, fPycellNEta);
256         fPythia->SetMSTU(52, fPycellNPhi);
257 //
258 //  Configure Jet Finder
259 //  
260         fPythia->SetPARU(58,  fPycellThreshold);
261         fPythia->SetPARU(52,  fPycellEtSeed);
262         fPythia->SetPARU(53,  fPycellMinEtJet);
263         fPythia->SetPARU(54,  fPycellMaxRadius);
264         fPythia->SetMSTU(54,  2);
265 //
266 //  This counts the total number of calls to Pyevnt() per run.
267     fTrialsRun = 0;
268     fQ         = 0.;
269     fX1        = 0.;
270     fX2        = 0.;    
271     fNev       = 0 ;
272 //    
273 //
274 //
275     AliGenMC::Init();
276 //
277 //
278 //  
279     if (fSetNuclei) {
280         fDyBoost = 0;
281         Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
282     }
283
284     if (fQuench) {
285         fPythia->InitQuenching(0., 0.1, 1., 8., 0);
286     }
287     
288 }
289
290 void AliGenPythia::Generate()
291 {
292 // Generate one event
293     
294     fDecayer->ForceDecay();
295
296     Float_t polar[3]   =   {0,0,0};
297     Float_t origin[3]  =   {0,0,0};
298     Float_t p[4];
299 //  converts from mm/c to s
300     const Float_t kconv=0.001/2.999792458e8;
301 //
302     Int_t nt=0;
303     Int_t jev=0;
304     Int_t j, kf;
305     fTrials=0;
306     
307
308     //  Set collision vertex position 
309     if (fVertexSmear == kPerEvent) Vertex();
310     
311 //  event loop    
312     while(1)
313     {
314 //
315 // If quenching option has been selected switch off fragmentation first
316 //
317         if (fQuench) {
318             fPythia->SetMSTJ(1, 0);
319         }
320 //
321 // Produce event
322 //
323         fPythia->Pyevnt();
324         if (fQuench) {
325 //
326 //  Run quenching routine 
327 //
328             fPythia->Quench();
329 //
330 // Switch fragmentation on
331             fPythia->SetMSTJ(1, 1);
332 //
333 // .. and perform fragmentation
334             fPythia->Pyexec();
335
336         }
337         
338         if (gAlice) {
339             if (gAlice->GetEvNumber()>=fDebugEventFirst &&
340                 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
341         }
342         
343         fTrials++;
344         fPythia->ImportParticles(fParticles,"All");
345         Boost();
346 //
347 //
348 //
349         Int_t i;
350         
351         Int_t np = fParticles->GetEntriesFast();
352         if (np == 0 ) continue;
353 //
354         
355 //
356         Int_t* pParent   = new Int_t[np];
357         Int_t* pSelected = new Int_t[np];
358         Int_t* trackIt   = new Int_t[np];
359         for (i=0; i< np; i++) {
360             pParent[i]   = -1;
361             pSelected[i] =  0;
362             trackIt[i]   =  0;
363         }
364
365         Int_t nc = 0;        // Total n. of selected particles
366         Int_t nParents = 0;  // Selected parents
367         Int_t nTkbles = 0;   // Trackable particles
368         if (fProcess != kPyMb && fProcess != kPyJets && 
369             fProcess != kPyDirectGamma &&
370             fProcess != kPyMbNonDiffr) {
371             
372             for (i = 0; i<np; i++) {
373                 TParticle* iparticle = (TParticle *) fParticles->At(i);
374                 Int_t ks = iparticle->GetStatusCode();
375                 kf = CheckPDGCode(iparticle->GetPdgCode());
376 // No initial state partons
377                 if (ks==21) continue;
378 //
379 // Heavy Flavor Selection
380 //
381                 // quark ?
382                 kf = TMath::Abs(kf);
383                 Int_t kfl = kf;
384                 // meson ?
385                 if  (kfl > 10) kfl/=100;
386                 // baryon
387                 if (kfl > 10) kfl/=10;
388                 if (kfl > 10) kfl/=10;
389
390                 Int_t ipa = iparticle->GetFirstMother()-1;
391                 Int_t kfMo = 0;
392                 
393                 if (ipa > -1) {
394                     TParticle *  mother = (TParticle *) fParticles->At(ipa);
395                     kfMo = TMath::Abs(mother->GetPdgCode());
396                 }
397                 // What to keep in Stack?
398                 Bool_t flavorOK = kFALSE;
399                 Bool_t selectOK = kFALSE;
400                 if (fFeedDownOpt) {
401                     if (kfl >= fFlavorSelect) flavorOK = kTRUE;
402                 } else {
403                     if (kfl > fFlavorSelect) {
404                         nc = -1;
405                         break;
406                     }
407                     if (kfl == fFlavorSelect) flavorOK = kTRUE;
408                 }
409                 switch (fStackFillOpt) {
410                 case kFlavorSelection:
411                     selectOK = kTRUE;
412                     break;
413                 case kParentSelection:
414                     if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
415                     break;
416                 }
417                 if (flavorOK && selectOK) { 
418 //
419 // Heavy flavor hadron or quark
420 //
421 // Kinematic seletion on final state heavy flavor mesons
422                     if (ParentSelected(kf) && !KinematicSelection(iparticle, 0)) 
423                     {
424                       continue;
425                     }
426                     pSelected[i] = 1;
427                     if (ParentSelected(kf)) ++nParents; // Update parent count
428 //                  printf("\n particle (HF)  %d %d %d", i, pSelected[i], kf);
429                 } else {
430 // Kinematic seletion on decay products
431                     if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf) 
432                         && !KinematicSelection(iparticle, 1))
433                     {
434                       continue;
435                     }
436 //
437 // Decay products 
438 // Select if mother was selected and is not tracked
439
440                     if (pSelected[ipa] && 
441                         !trackIt[ipa]  &&     // mother will be  tracked ?
442                         kfMo !=  5 &&         // mother is b-quark, don't store fragments          
443                         kfMo !=  4 &&         // mother is c-quark, don't store fragments 
444                         kf   != 92)           // don't store string
445                     {
446 //
447 // Semi-stable or de-selected: diselect decay products:
448 // 
449 //
450                         if (pSelected[i] == -1 ||  fDecayer->GetLifetime(kf) > fMaxLifeTime)
451                         {
452                             Int_t ipF = iparticle->GetFirstDaughter();
453                             Int_t ipL = iparticle->GetLastDaughter();   
454                             if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
455                         }
456 //                      printf("\n particle (decay)  %d %d %d", i, pSelected[i], kf);
457                         pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
458                     }
459                 }
460                 if (pSelected[i] == -1) pSelected[i] = 0;
461                 if (!pSelected[i]) continue;
462                 // Count quarks only if you did not include fragmentation
463                 if (fFragmentation && kf <= 10) continue;
464                 nc++;
465 // Decision on tracking
466                 trackIt[i] = 0;
467 //
468 // Track final state particle
469                 if (ks == 1) trackIt[i] = 1;
470 // Track semi-stable particles
471                 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime))  trackIt[i] = 1;
472 // Track particles selected by process if undecayed. 
473                 if (fForceDecay == kNoDecay) {
474                     if (ParentSelected(kf)) trackIt[i] = 1;
475                 } else {
476                     if (ParentSelected(kf)) trackIt[i] = 0;
477                 }
478                 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
479 //
480 //
481
482             } // particle selection loop
483             if (nc > 0) {
484                 for (i = 0; i<np; i++) {
485                     if (!pSelected[i]) continue;
486                     TParticle *  iparticle = (TParticle *) fParticles->At(i);
487                     kf = CheckPDGCode(iparticle->GetPdgCode());
488                     Int_t ks = iparticle->GetStatusCode();  
489                     p[0] = iparticle->Px();
490                     p[1] = iparticle->Py();
491                     p[2] = iparticle->Pz();
492                     p[3] = iparticle->Energy();
493                     
494                     origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
495                     origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
496                     origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
497                     
498                     Float_t tof   = kconv*iparticle->T();
499                     Int_t ipa     = iparticle->GetFirstMother()-1;
500                     Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
501  
502                     PushTrack(fTrackIt*trackIt[i], iparent, kf, 
503                               p[0], p[1], p[2], p[3], 
504                               origin[0], origin[1], origin[2], tof, 
505                               polar[0], polar[1], polar[2],
506                               kPPrimary, nt, 1., ks);
507                     pParent[i] = nt;
508                     KeepTrack(nt); 
509                 } //  PushTrack loop
510             }
511         } else {
512             nc = GenerateMB();
513         } // mb ?
514
515         if (pParent)   delete[] pParent;
516         if (pSelected) delete[] pSelected;
517         if (trackIt)   delete[] trackIt;
518
519         if (nc > 0) {
520           switch (fCountMode) {
521           case kCountAll:
522             // printf(" Count all \n");
523             jev += nc;
524             break;
525           case kCountParents:
526             // printf(" Count parents \n");
527             jev += nParents;
528             break;
529           case kCountTrackables:
530             // printf(" Count trackable \n");
531             jev += nTkbles;
532             break;
533           }
534             if (jev >= fNpart || fNpart == -1) {
535                 fKineBias=Float_t(fNpart)/Float_t(fTrials);
536                 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
537
538                 fQ  += fPythia->GetVINT(51);
539                 fX1 += fPythia->GetVINT(41);
540                 fX2 += fPythia->GetVINT(42);
541                 fTrialsRun += fTrials;
542                 fNev++;
543                 MakeHeader();
544                 break;
545             }
546         }
547     } // event loop
548     SetHighWaterMark(nt);
549 //  adjust weight due to kinematic selection
550 //    AdjustWeights();
551 //  get cross-section
552     fXsection=fPythia->GetPARI(1);
553 }
554
555 Int_t  AliGenPythia::GenerateMB()
556 {
557 //
558 // Min Bias selection and other global selections
559 //
560     Int_t i, kf, nt, iparent;
561     Int_t nc = 0;
562     Float_t p[4];
563     Float_t polar[3]   =   {0,0,0};
564     Float_t origin[3]  =   {0,0,0};
565 //  converts from mm/c to s
566     const Float_t kconv=0.001/2.999792458e8;
567     
568     Int_t np = fParticles->GetEntriesFast();
569     Int_t* pParent = new Int_t[np];
570     for (i=0; i< np; i++) pParent[i] = -1;
571     if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
572         TParticle* jet1 = (TParticle *) fParticles->At(6);
573         TParticle* jet2 = (TParticle *) fParticles->At(7);
574         if (!CheckTrigger(jet1, jet2)) return 0;
575     }
576     
577     for (i = 0; i<np; i++) {
578         Int_t trackIt = 0;
579         TParticle *  iparticle = (TParticle *) fParticles->At(i);
580         kf = CheckPDGCode(iparticle->GetPdgCode());
581         Int_t ks = iparticle->GetStatusCode();
582         Int_t km = iparticle->GetFirstMother();
583         if ((ks == 1  && kf!=0 && KinematicSelection(iparticle, 0)) ||
584             (ks != 1) ||
585             (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
586             nc++;
587             if (ks == 1) trackIt = 1;
588             Int_t ipa = iparticle->GetFirstMother()-1;
589             
590             iparent = (ipa > -1) ? pParent[ipa] : -1;
591             
592 //
593 // store track information
594             p[0] = iparticle->Px();
595             p[1] = iparticle->Py();
596             p[2] = iparticle->Pz();
597             p[3] = iparticle->Energy();
598             
599             origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
600             origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
601             origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
602             
603             Float_t tof=kconv*iparticle->T();
604
605             PushTrack(fTrackIt*trackIt, iparent, kf, 
606                       p[0], p[1], p[2], p[3], 
607                       origin[0], origin[1], origin[2], tof, 
608                       polar[0], polar[1], polar[2],
609                       kPPrimary, nt, 1., ks);
610             KeepTrack(nt);
611             pParent[i] = nt;
612         } // select particle
613     } // particle loop 
614
615     if (pParent) delete[] pParent;
616     
617     printf("\n I've put %i particles on the stack \n",nc);
618     return nc;
619 }
620
621
622 void AliGenPythia::FinishRun()
623 {
624 // Print x-section summary
625     fPythia->Pystat(1);
626     fQ  /= fNev;
627     fX1 /= fNev;
628     fX2 /= fNev;    
629     printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
630     printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
631     
632
633 }
634
635 void AliGenPythia::AdjustWeights()
636 {
637 // Adjust the weights after generation of all events
638 //
639     if (gAlice) {
640         TParticle *part;
641         Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
642         for (Int_t i=0; i<ntrack; i++) {
643             part= gAlice->GetMCApp()->Particle(i);
644             part->SetWeight(part->GetWeight()*fKineBias);
645         }
646     }
647 }
648     
649 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
650 {
651 // Treat protons as inside nuclei with mass numbers a1 and a2  
652
653     fAProjectile = a1;
654     fATarget     = a2;
655     fSetNuclei   = kTRUE;
656 }
657
658
659 void AliGenPythia::MakeHeader()
660 {
661 // Builds the event header, to be called after each event
662     if (fHeader) delete fHeader;
663     fHeader = new AliGenPythiaEventHeader("Pythia");
664 //
665 // Event type  
666     ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
667 //
668 // Number of trials
669     ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
670 //
671 // Event Vertex 
672     fHeader->SetPrimaryVertex(fVertex);
673 //
674 // Jets that have triggered
675     if (fProcess == kPyJets)
676     {
677         Int_t ntrig, njet;
678         Float_t jets[4][10];
679         GetJets(njet, ntrig, jets);
680         
681         for (Int_t i = 0; i < ntrig; i++) {
682             ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i], 
683                                                         jets[3][i]);
684         }
685     }
686     if (gAlice) gAlice->SetGenEventHeader(fHeader);
687 }
688         
689
690 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
691 {
692 // Check the kinematic trigger condition
693 //
694     Double_t eta[2];
695     eta[0] = jet1->Eta();
696     eta[1] = jet2->Eta();
697     Double_t phi[2];
698     phi[0] = jet1->Phi();
699     phi[1] = jet2->Phi();
700     Int_t    pdg[2]; 
701     pdg[0] = jet1->GetPdgCode();
702     pdg[1] = jet2->GetPdgCode();    
703     Bool_t   triggered = kFALSE;
704
705     if (fProcess == kPyJets) {
706         Int_t njets = 0;
707         Int_t ntrig = 0;
708         Float_t jets[4][10];
709 //
710 // Use Pythia clustering on parton level to determine jet axis
711 //
712         GetJets(njets, ntrig, jets);
713         
714         if (ntrig) triggered = kTRUE;
715 //
716     } else {
717         Int_t ij = 0;
718         Int_t ig = 1;
719         if (pdg[0] == kGamma) {
720             ij = 1;
721             ig = 0;
722         }
723         //Check eta range first...
724         if ((eta[ij] < fEtaMaxJet   && eta[ij] > fEtaMinJet) &&
725             (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
726         {
727             //Eta is okay, now check phi range
728             if ((phi[ij] < fPhiMaxJet   && phi[ij] > fPhiMinJet) &&
729                 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
730             {
731                 triggered = kTRUE;
732             }
733         }
734     }
735     return triggered;
736 }
737           
738 AliGenPythia& AliGenPythia::operator=(const  AliGenPythia& rhs)
739 {
740 // Assignment operator
741     rhs.Copy(*this);
742     return *this;
743 }
744
745 void  AliGenPythia::LoadEvent(AliStack* stack, Int_t flag)
746 {
747 //
748 // Load event into Pythia Common Block
749 //
750  
751 //    AliRunLoader* rl = AliRunLoader::GetRunLoader();
752     Int_t npart = stack -> GetNprimary();
753     Int_t n0 = 0;
754     
755     if (!flag) {
756         (fPythia->GetPyjets())->N = npart;
757     } else {
758         n0 = (fPythia->GetPyjets())->N;
759         (fPythia->GetPyjets())->N = n0 + npart;
760     }
761     
762     
763     for (Int_t part = 0; part < npart; part++) {
764         TParticle *MPart = stack->Particle(part);
765         
766         Int_t kf     = MPart->GetPdgCode();
767         Int_t ks     = MPart->GetStatusCode();
768         
769         Float_t px = MPart->Px();
770         Float_t py = MPart->Py();
771         Float_t pz = MPart->Pz();
772         Float_t e  = MPart->Energy();
773         Float_t m  = MPart->GetCalcMass();
774         
775         
776         (fPythia->GetPyjets())->P[0][part+n0] = px;
777         (fPythia->GetPyjets())->P[1][part+n0] = py;
778         (fPythia->GetPyjets())->P[2][part+n0] = pz;
779         (fPythia->GetPyjets())->P[3][part+n0] = e;
780         (fPythia->GetPyjets())->P[4][part+n0] = m;
781         
782         (fPythia->GetPyjets())->K[1][part+n0] = kf;
783         (fPythia->GetPyjets())->K[0][part+n0] = ks;
784     }
785 }
786
787 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
788 {
789 //
790 //  Calls the Pythia jet finding algorithm to find jets in the current event
791 //
792 //
793 //
794 //  Save jets
795     Int_t n     = fPythia->GetN();
796
797 //
798 //  Run Jet Finder
799     fPythia->Pycell(njets);
800     Int_t i;
801     for (i = 0; i < njets; i++) {
802         Float_t px    = (fPythia->GetPyjets())->P[0][n+i];
803         Float_t py    = (fPythia->GetPyjets())->P[1][n+i];
804         Float_t pz    = (fPythia->GetPyjets())->P[2][n+i];
805         Float_t e     = (fPythia->GetPyjets())->P[3][n+i];
806
807         jets[0][i] = px;
808         jets[1][i] = py;
809         jets[2][i] = pz;
810         jets[3][i] = e;
811     }
812 }
813
814
815
816 void  AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
817 {
818 //
819 //  Calls the Pythia clustering algorithm to find jets in the current event
820 //
821     Int_t n     = fPythia->GetN();
822     nJets       = 0;
823     nJetsTrig   = 0;
824     if (fJetReconstruction == kCluster) {
825 //
826 //  Configure cluster algorithm
827 //    
828         fPythia->SetPARU(43, 2.);
829         fPythia->SetMSTU(41, 1);
830 //
831 //  Call cluster algorithm
832 //    
833         fPythia->Pyclus(nJets);
834 //
835 //  Loading jets from common block
836 //
837     } else {
838
839 //
840 //  Run Jet Finder
841         fPythia->Pycell(nJets);
842     }
843
844     Int_t i;
845     for (i = 0; i < nJets; i++) {
846         Float_t px    = (fPythia->GetPyjets())->P[0][n+i];
847         Float_t py    = (fPythia->GetPyjets())->P[1][n+i];
848         Float_t pz    = (fPythia->GetPyjets())->P[2][n+i];
849         Float_t e     = (fPythia->GetPyjets())->P[3][n+i];
850         Float_t pt    = TMath::Sqrt(px * px + py * py);
851         Float_t phi   = TMath::Pi() + TMath::ATan2(-py, -px);  
852         Float_t theta = TMath::ATan2(pt,pz);
853         Float_t et    = e * TMath::Sin(theta);
854         Float_t eta   = -TMath::Log(TMath::Tan(theta / 2.));
855
856         if (
857             eta > fEtaMinJet && eta < fEtaMaxJet && 
858             phi > fPhiMinJet && phi < fPhiMaxJet &&
859             et  > fEtMinJet  && et  < fEtMaxJet     
860             ) 
861         {
862             jets[0][nJetsTrig] = px;
863             jets[1][nJetsTrig] = py;
864             jets[2][nJetsTrig] = pz;
865             jets[3][nJetsTrig] = e;
866             nJetsTrig++;
867             
868         } else {
869 //          printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
870         }
871     }
872 }
873
874
875 #ifdef never
876 void AliGenPythia::Streamer(TBuffer &R__b)
877 {
878    // Stream an object of class AliGenPythia.
879
880    if (R__b.IsReading()) {
881       Version_t R__v = R__b.ReadVersion(); if (R__v) { }
882       AliGenerator::Streamer(R__b);
883       R__b >> (Int_t&)fProcess;
884       R__b >> (Int_t&)fStrucFunc;
885       R__b >> (Int_t&)fForceDecay;
886       R__b >> fEnergyCMS;
887       R__b >> fKineBias;
888       R__b >> fTrials;
889       fParentSelect.Streamer(R__b);
890       fChildSelect.Streamer(R__b);
891       R__b >> fXsection;
892 //      (AliPythia::Instance())->Streamer(R__b);
893       R__b >> fPtHardMin;
894       R__b >> fPtHardMax;
895 //      if (fDecayer) fDecayer->Streamer(R__b);
896    } else {
897       R__b.WriteVersion(AliGenPythia::IsA());
898       AliGenerator::Streamer(R__b);
899       R__b << (Int_t)fProcess;
900       R__b << (Int_t)fStrucFunc;
901       R__b << (Int_t)fForceDecay;
902       R__b << fEnergyCMS;
903       R__b << fKineBias;
904       R__b << fTrials;
905       fParentSelect.Streamer(R__b);
906       fChildSelect.Streamer(R__b);
907       R__b << fXsection;
908 //      R__b << fPythia;
909       R__b << fPtHardMin;
910       R__b << fPtHardMax;
911       //     fDecayer->Streamer(R__b);
912    }
913 }
914 #endif
915