]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PYTHIA6/AliGenPythia.cxx
Corrected size of array
[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
285 void AliGenPythia::Generate()
286 {
287 // Generate one event
288     
289     fDecayer->ForceDecay();
290
291     Float_t polar[3]   =   {0,0,0};
292     Float_t origin[3]  =   {0,0,0};
293     Float_t p[4];
294 //  converts from mm/c to s
295     const Float_t kconv=0.001/2.999792458e8;
296 //
297     Int_t nt=0;
298     Int_t jev=0;
299     Int_t j, kf;
300     fTrials=0;
301
302     //  Set collision vertex position 
303     if(fVertexSmear==kPerEvent) {
304         fPythia->SetMSTP(151,1);
305         for (j=0;j<3;j++) {
306             fPythia->SetPARP(151+j, fOsigma[j]*10.);
307         }
308     } else if (fVertexSmear==kPerTrack) {
309         fPythia->SetMSTP(151,0);
310     }
311 //  event loop    
312     while(1)
313     {
314         if (fQuench) {
315             fPythia->SetMSTJ(1, 0);
316         }
317         fPythia->Pyevnt();
318
319         if (fQuench) {
320             fPythia->Quench();
321             fPythia->SetMSTJ(1, 1);
322             fPythia->Pyexec();
323         }
324         
325         if (gAlice) {
326             if (gAlice->GetEvNumber()>=fDebugEventFirst &&
327                 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
328         }
329         
330         fTrials++;
331         fPythia->ImportParticles(fParticles,"All");
332
333         Boost();
334 //
335 //
336 //
337         Int_t i;
338         
339         Int_t np = fParticles->GetEntriesFast();
340         if (np == 0 ) continue;
341 // Get event vertex and discard the event if the Z coord. is too big    
342         TParticle *iparticle = (TParticle *) fParticles->At(0);
343         Float_t distz = iparticle->Vz()/10.;
344         if(TMath::Abs(distz)>fCutVertexZ*fOsigma[2]) continue;
345 //
346         fVertex[0] = iparticle->Vx()/10.+fOrigin.At(0);
347         fVertex[1] = iparticle->Vy()/10.+fOrigin.At(1);
348         fVertex[2] = iparticle->Vz()/10.+fOrigin.At(2);
349 //
350         Int_t* pParent   = new Int_t[np];
351         Int_t* pSelected = new Int_t[np];
352         Int_t* trackIt   = new Int_t[np];
353         for (i=0; i< np; i++) {
354             pParent[i]   = -1;
355             pSelected[i] =  0;
356             trackIt[i]   =  0;
357         }
358
359         Int_t nc = 0;        // Total n. of selected particles
360         Int_t nParents = 0;  // Selected parents
361         Int_t nTkbles = 0;   // Trackable particles
362         if (fProcess != kPyMb && fProcess != kPyJets && 
363             fProcess != kPyDirectGamma &&
364             fProcess != kPyMbNonDiffr) {
365             
366             for (i = 0; i<np; i++) {
367                 iparticle = (TParticle *) fParticles->At(i);
368                 Int_t ks = iparticle->GetStatusCode();
369                 kf = CheckPDGCode(iparticle->GetPdgCode());
370 // No initial state partons
371                 if (ks==21) continue;
372 //
373 // Heavy Flavor Selection
374 //
375                 // quark ?
376                 kf = TMath::Abs(kf);
377                 Int_t kfl = kf;
378                 // meson ?
379                 if  (kfl > 10) kfl/=100;
380                 // baryon
381                 if (kfl > 10) kfl/=10;
382                 if (kfl > 10) kfl/=10;
383
384                 Int_t ipa = iparticle->GetFirstMother()-1;
385                 Int_t kfMo = 0;
386                 
387                 if (ipa > -1) {
388                     TParticle *  mother = (TParticle *) fParticles->At(ipa);
389                     kfMo = TMath::Abs(mother->GetPdgCode());
390                 }
391                 // What to keep in Stack?
392                 Bool_t flavorOK = kFALSE;
393                 Bool_t selectOK = kFALSE;
394                 if (fFeedDownOpt) {
395                   if (kfl >= fFlavorSelect) flavorOK = kTRUE;
396                 } else {
397                   if (kfl > fFlavorSelect) {
398                     nc = -1;
399                     break;
400                   }
401                   if (kfl == fFlavorSelect) flavorOK = kTRUE;
402                 }
403                 switch (fStackFillOpt) {
404                 case kFlavorSelection:
405                   selectOK = kTRUE;
406                   break;
407                 case kParentSelection:
408                   if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
409                   break;
410                 }
411                 if (flavorOK && selectOK) { 
412 //
413 // Heavy flavor hadron or quark
414 //
415 // Kinematic seletion on final state heavy flavor mesons
416                     if (ParentSelected(kf) && !KinematicSelection(iparticle, 0)) 
417                     {
418                       continue;
419                     }
420                     pSelected[i] = 1;
421                     if (ParentSelected(kf)) ++nParents; // Update parent count
422 //                  printf("\n particle (HF)  %d %d %d", i, pSelected[i], kf);
423                 } else {
424 // Kinematic seletion on decay products
425                     if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf) 
426                         && !KinematicSelection(iparticle, 1))
427                     {
428                       continue;
429                     }
430 //
431 // Decay products 
432 // Select if mother was selected and is not tracked
433
434                     if (pSelected[ipa] && 
435                         !trackIt[ipa]  &&     // mother will be  tracked ?
436                         kfMo !=  5 &&         // mother is b-quark, don't store fragments          
437                         kfMo !=  4 &&         // mother is c-quark, don't store fragments 
438                         kf   != 92)           // don't store string
439                     {
440 //
441 // Semi-stable or de-selected: diselect decay products:
442 // 
443 //
444                         if (pSelected[i] == -1 ||  fDecayer->GetLifetime(kf) > fMaxLifeTime)
445                         {
446                             Int_t ipF = iparticle->GetFirstDaughter();
447                             Int_t ipL = iparticle->GetLastDaughter();   
448                             if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
449                         }
450 //                      printf("\n particle (decay)  %d %d %d", i, pSelected[i], kf);
451                         pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
452                     }
453                 }
454                 if (pSelected[i] == -1) pSelected[i] = 0;
455                 if (!pSelected[i]) continue;
456                 // Count quarks only if you did not include fragmentation
457                 if (fFragmentation && kf <= 10) continue;
458                 nc++;
459 // Decision on tracking
460                 trackIt[i] = 0;
461 //
462 // Track final state particle
463                 if (ks == 1) trackIt[i] = 1;
464 // Track semi-stable particles
465                 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime))  trackIt[i] = 1;
466 // Track particles selected by process if undecayed. 
467                 if (fForceDecay == kNoDecay) {
468                     if (ParentSelected(kf)) trackIt[i] = 1;
469                 } else {
470                     if (ParentSelected(kf)) trackIt[i] = 0;
471                 }
472                 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
473 //
474 //
475
476             } // particle selection loop
477             if (nc > 0) {
478                 for (i = 0; i<np; i++) {
479                     if (!pSelected[i]) continue;
480                     TParticle *  iparticle = (TParticle *) fParticles->At(i);
481                     kf = CheckPDGCode(iparticle->GetPdgCode());
482                     Int_t ks = iparticle->GetStatusCode();  
483                     p[0] = iparticle->Px();
484                     p[1] = iparticle->Py();
485                     p[2] = iparticle->Pz();
486                     p[3] = iparticle->Energy();
487                     
488                     origin[0] = fOrigin[0]+iparticle->Vx()/10.;
489                     origin[1] = fOrigin[1]+iparticle->Vy()/10.;
490                     origin[2] = fOrigin[2]+iparticle->Vz()/10.;
491                     Float_t tof   = kconv*iparticle->T();
492                     Int_t ipa     = iparticle->GetFirstMother()-1;
493                     Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
494  
495                     PushTrack(fTrackIt*trackIt[i], iparent, kf, 
496                               p[0], p[1], p[2], p[3], 
497                               origin[0], origin[1], origin[2], tof, 
498                               polar[0], polar[1], polar[2],
499                               kPPrimary, nt, 1., ks);
500                     pParent[i] = nt;
501                     KeepTrack(nt); 
502                 } //  PushTrack loop
503             }
504         } else {
505             nc = GenerateMB();
506         } // mb ?
507
508         if (pParent)   delete[] pParent;
509         if (pSelected) delete[] pSelected;
510         if (trackIt)   delete[] trackIt;
511
512         if (nc > 0) {
513           switch (fCountMode) {
514           case kCountAll:
515             // printf(" Count all \n");
516             jev += nc;
517             break;
518           case kCountParents:
519             // printf(" Count parents \n");
520             jev += nParents;
521             break;
522           case kCountTrackables:
523             // printf(" Count trackable \n");
524             jev += nTkbles;
525             break;
526           }
527             if (jev >= fNpart || fNpart == -1) {
528                 fKineBias=Float_t(fNpart)/Float_t(fTrials);
529                 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
530
531                 fQ  += fPythia->GetVINT(51);
532                 fX1 += fPythia->GetVINT(41);
533                 fX2 += fPythia->GetVINT(42);
534                 fTrialsRun += fTrials;
535                 fNev++;
536                 MakeHeader();
537                 break;
538             }
539         }
540     } // event loop
541     SetHighWaterMark(nt);
542 //  adjust weight due to kinematic selection
543 //    AdjustWeights();
544 //  get cross-section
545     fXsection=fPythia->GetPARI(1);
546 }
547
548 Int_t  AliGenPythia::GenerateMB()
549 {
550 //
551 // Min Bias selection and other global selections
552 //
553     Int_t i, kf, nt, iparent;
554     Int_t nc = 0;
555     Float_t p[4];
556     Float_t polar[3]   =   {0,0,0};
557     Float_t origin[3]  =   {0,0,0};
558 //  converts from mm/c to s
559     const Float_t kconv=0.001/2.999792458e8;
560     
561     Int_t np = fParticles->GetEntriesFast();
562     Int_t* pParent = new Int_t[np];
563     for (i=0; i< np; i++) pParent[i] = -1;
564     if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
565         TParticle* jet1 = (TParticle *) fParticles->At(6);
566         TParticle* jet2 = (TParticle *) fParticles->At(7);
567         if (!CheckTrigger(jet1, jet2)) return 0;
568     }
569     
570     for (i = 0; i<np; i++) {
571         Int_t trackIt = 0;
572         TParticle *  iparticle = (TParticle *) fParticles->At(i);
573         kf = CheckPDGCode(iparticle->GetPdgCode());
574         Int_t ks = iparticle->GetStatusCode();
575         Int_t km = iparticle->GetFirstMother();
576         if ((ks == 1  && kf!=0 && KinematicSelection(iparticle, 0)) ||
577             (ks != 1) ||
578             (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
579             nc++;
580             if (ks == 1) trackIt = 1;
581             Int_t ipa = iparticle->GetFirstMother()-1;
582             
583             iparent = (ipa > -1) ? pParent[ipa] : -1;
584             
585 //
586 // store track information
587             p[0] = iparticle->Px();
588             p[1] = iparticle->Py();
589             p[2] = iparticle->Pz();
590             p[3] = iparticle->Energy();
591             
592             origin[0] = fOrigin[0]+iparticle->Vx()/10.;
593             origin[1] = fOrigin[1]+iparticle->Vy()/10.;
594             origin[2] = fOrigin[2]+iparticle->Vz()/10.;
595             Float_t tof=kconv*iparticle->T();
596
597             PushTrack(fTrackIt*trackIt, iparent, kf, 
598                       p[0], p[1], p[2], p[3], 
599                       origin[0], origin[1], origin[2], tof, 
600                       polar[0], polar[1], polar[2],
601                       kPPrimary, nt, 1., ks);
602             KeepTrack(nt);
603             pParent[i] = nt;
604         } // select particle
605     } // particle loop 
606
607     if (pParent) delete[] pParent;
608     
609     printf("\n I've put %i particles on the stack \n",nc);
610     return nc;
611 }
612
613
614 void AliGenPythia::FinishRun()
615 {
616 // Print x-section summary
617     fPythia->Pystat(1);
618     fQ  /= fNev;
619     fX1 /= fNev;
620     fX2 /= fNev;    
621     printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
622     printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
623     
624
625 }
626
627 void AliGenPythia::AdjustWeights()
628 {
629 // Adjust the weights after generation of all events
630 //
631     if (gAlice) {
632         TParticle *part;
633         Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
634         for (Int_t i=0; i<ntrack; i++) {
635             part= gAlice->GetMCApp()->Particle(i);
636             part->SetWeight(part->GetWeight()*fKineBias);
637         }
638     }
639 }
640     
641 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
642 {
643 // Treat protons as inside nuclei with mass numbers a1 and a2  
644
645     fAProjectile = a1;
646     fATarget     = a2;
647     fSetNuclei   = kTRUE;
648 }
649
650
651 void AliGenPythia::MakeHeader()
652 {
653 // Builds the event header, to be called after each event
654     if (fHeader) delete fHeader;
655     fHeader = new AliGenPythiaEventHeader("Pythia");
656 //
657 // Event type  
658     ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
659 //
660 // Number of trials
661     ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
662 //
663 // Event Vertex 
664     fHeader->SetPrimaryVertex(fVertex);
665 //
666 // Jets that have triggered
667     if (fProcess == kPyJets)
668     {
669         Int_t ntrig, njet;
670         Float_t jets[4][10];
671         GetJets(njet, ntrig, jets);
672         
673         for (Int_t i = 0; i < ntrig; i++) {
674             ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i], 
675                                                         jets[3][i]);
676         }
677     }
678     if (gAlice) gAlice->SetGenEventHeader(fHeader);
679 }
680         
681
682 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
683 {
684 // Check the kinematic trigger condition
685 //
686     Double_t eta[2];
687     eta[0] = jet1->Eta();
688     eta[1] = jet2->Eta();
689     Double_t phi[2];
690     phi[0] = jet1->Phi();
691     phi[1] = jet2->Phi();
692     Int_t    pdg[2]; 
693     pdg[0] = jet1->GetPdgCode();
694     pdg[1] = jet2->GetPdgCode();    
695     Bool_t   triggered = kFALSE;
696
697     if (fProcess == kPyJets) {
698         Int_t njets = 0;
699         Int_t ntrig = 0;
700         Float_t jets[4][10];
701 //
702 // Use Pythia clustering on parton level to determine jet axis
703 //
704         GetJets(njets, ntrig, jets);
705         
706         if (ntrig) triggered = kTRUE;
707 //
708     } else {
709         Int_t ij = 0;
710         Int_t ig = 1;
711         if (pdg[0] == kGamma) {
712             ij = 1;
713             ig = 0;
714         }
715         //Check eta range first...
716         if ((eta[ij] < fEtaMaxJet   && eta[ij] > fEtaMinJet) &&
717             (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
718         {
719             //Eta is okay, now check phi range
720             if ((phi[ij] < fPhiMaxJet   && phi[ij] > fPhiMinJet) &&
721                 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
722             {
723                 triggered = kTRUE;
724             }
725         }
726     }
727     return triggered;
728 }
729           
730 AliGenPythia& AliGenPythia::operator=(const  AliGenPythia& rhs)
731 {
732 // Assignment operator
733     rhs.Copy(*this);
734     return *this;
735 }
736
737 void  AliGenPythia::LoadEvent()
738 {
739 //
740 // Load event into Pythia Common Block
741 //
742  
743     AliRunLoader* rl = AliRunLoader::GetRunLoader();
744     Int_t npart = (rl->Stack())-> GetNprimary();
745    (fPythia->GetPyjets())->N = npart;
746
747     for (Int_t part = 0; part < npart; part++) {
748         TParticle *MPart = (rl->Stack())->Particle(part);
749         Int_t kf     = MPart->GetPdgCode();
750         Int_t ks     = MPart->GetStatusCode();
751         Float_t px = MPart->Px();
752         Float_t py = MPart->Py();
753         Float_t pz = MPart->Pz();
754         Float_t e  = MPart->Energy();
755         Float_t m  = MPart->GetCalcMass();
756         
757         
758         (fPythia->GetPyjets())->P[0][part] = px;
759         (fPythia->GetPyjets())->P[1][part] = py;
760         (fPythia->GetPyjets())->P[2][part] = pz;
761         (fPythia->GetPyjets())->P[3][part] = e;
762         (fPythia->GetPyjets())->P[4][part] = m;
763         
764         (fPythia->GetPyjets())->K[1][part] = kf;
765         (fPythia->GetPyjets())->K[0][part] = ks;
766     }
767 }
768
769 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
770 {
771 //
772 //  Calls the Pythia jet finding algorithm to find jets in the current event
773 //
774 //
775 //
776 //  Save jets
777     Int_t n     = fPythia->GetN();
778
779 //
780 //  Run Jet Finder
781     fPythia->Pycell(njets);
782     Int_t i;
783     for (i = 0; i < njets; i++) {
784         Float_t px    = (fPythia->GetPyjets())->P[0][n+i];
785         Float_t py    = (fPythia->GetPyjets())->P[1][n+i];
786         Float_t pz    = (fPythia->GetPyjets())->P[2][n+i];
787         Float_t e     = (fPythia->GetPyjets())->P[3][n+i];
788
789         jets[0][i] = px;
790         jets[1][i] = py;
791         jets[2][i] = pz;
792         jets[3][i] = e;
793     }
794 }
795
796
797
798 void  AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
799 {
800 //
801 //  Calls the Pythia clustering algorithm to find jets in the current event
802 //
803     Int_t n     = fPythia->GetN();
804     nJets       = 0;
805     nJetsTrig   = 0;
806     if (fJetReconstruction == kCluster) {
807 //
808 //  Configure cluster algorithm
809 //    
810         fPythia->SetPARU(43, 2.);
811         fPythia->SetMSTU(41, 1);
812 //
813 //  Call cluster algorithm
814 //    
815         fPythia->Pyclus(nJets);
816 //
817 //  Loading jets from common block
818 //
819     } else {
820
821 //
822 //  Run Jet Finder
823         fPythia->Pycell(nJets);
824     }
825
826     Int_t i;
827     for (i = 0; i < nJets; i++) {
828         Float_t px    = (fPythia->GetPyjets())->P[0][n+i];
829         Float_t py    = (fPythia->GetPyjets())->P[1][n+i];
830         Float_t pz    = (fPythia->GetPyjets())->P[2][n+i];
831         Float_t e     = (fPythia->GetPyjets())->P[3][n+i];
832         Float_t pt    = TMath::Sqrt(px * px + py * py);
833         Float_t phi   = TMath::Pi() + TMath::ATan2(-py, -px);  
834         Float_t theta = TMath::ATan2(pt,pz);
835         Float_t et    = e * TMath::Sin(theta);
836         Float_t eta   = -TMath::Log(TMath::Tan(theta / 2.));
837
838         if (
839             eta > fEtaMinJet && eta < fEtaMaxJet && 
840             phi > fPhiMinJet && phi < fPhiMaxJet &&
841             et  > fEtMinJet  && et  < fEtMaxJet     
842             ) 
843         {
844             jets[0][nJetsTrig] = px;
845             jets[1][nJetsTrig] = py;
846             jets[2][nJetsTrig] = pz;
847             jets[3][nJetsTrig] = e;
848             nJetsTrig++;
849             
850         } else {
851 //          printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
852         }
853     }
854 }
855
856
857 #ifdef never
858 void AliGenPythia::Streamer(TBuffer &R__b)
859 {
860    // Stream an object of class AliGenPythia.
861
862    if (R__b.IsReading()) {
863       Version_t R__v = R__b.ReadVersion(); if (R__v) { }
864       AliGenerator::Streamer(R__b);
865       R__b >> (Int_t&)fProcess;
866       R__b >> (Int_t&)fStrucFunc;
867       R__b >> (Int_t&)fForceDecay;
868       R__b >> fEnergyCMS;
869       R__b >> fKineBias;
870       R__b >> fTrials;
871       fParentSelect.Streamer(R__b);
872       fChildSelect.Streamer(R__b);
873       R__b >> fXsection;
874 //      (AliPythia::Instance())->Streamer(R__b);
875       R__b >> fPtHardMin;
876       R__b >> fPtHardMax;
877 //      if (fDecayer) fDecayer->Streamer(R__b);
878    } else {
879       R__b.WriteVersion(AliGenPythia::IsA());
880       AliGenerator::Streamer(R__b);
881       R__b << (Int_t)fProcess;
882       R__b << (Int_t)fStrucFunc;
883       R__b << (Int_t)fForceDecay;
884       R__b << fEnergyCMS;
885       R__b << fKineBias;
886       R__b << fTrials;
887       fParentSelect.Streamer(R__b);
888       fChildSelect.Streamer(R__b);
889       R__b << fXsection;
890 //      R__b << fPythia;
891       R__b << fPtHardMin;
892       R__b << fPtHardMax;
893       //     fDecayer->Streamer(R__b);
894    }
895 }
896 #endif
897