]> git.uio.no Git - u/mrichter/AliRoot.git/blob - THijing/AliGenHijing.cxx
Merging two methods, no longer needed to be separated after the death of TreeT
[u/mrichter/AliRoot.git] / THijing / AliGenHijing.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 // Generator using HIJING as an external generator
19 // The main HIJING options are accessable for the user through this interface.
20 // Uses the THijing implementation of TGenerator.
21 // Author:
22 // Andreas Morsch    (andreas.morsch@cern.ch)
23 //
24
25 #include <TClonesArray.h>
26 #include <TGraph.h>
27 #include <THijing.h>
28 #include <TLorentzVector.h>
29 #include <TPDGCode.h>
30 #include <TParticle.h>
31
32 #include "AliGenHijing.h"
33 #include "AliGenHijingEventHeader.h"
34 #include "AliRun.h"
35 #include "AliHijingRndm.h"
36
37 ClassImp(AliGenHijing)
38
39 AliGenHijing::AliGenHijing()
40     :AliGenMC(),
41      fFrame("CMS"),
42      fMinImpactParam(0.),
43      fMaxImpactParam(5.),
44      fKeep(0),
45      fQuench(1),
46      fShadowing(1),
47      fDecaysOff(1),
48      fTrigger(0),     
49      fEvaluate(0),
50      fSelectAll(0),
51      fFlavor(0),
52      fEnergyCMS(5500.),
53      fKineBias(0.),
54      fTrials(0),
55      fXsection(0.),
56      fHijing(0),
57      fPtHardMin(0.),
58      fPtHardMax(1.e4),
59      fSpectators(1),
60      fDsigmaDb(0),
61      fDnDb(0),
62      fPtMinJet(-2.5),
63      fEtaMinJet(-20.),
64      fEtaMaxJet(+20.),
65      fPhiMinJet(0.),
66      fPhiMaxJet(2. * TMath::Pi()),
67      fRadiation(3),
68      fSimpleJet(kFALSE),
69      fNoGammas(kFALSE),
70      fProjectileSpecn(0),
71      fProjectileSpecp(0),
72      fTargetSpecn(0),
73      fTargetSpecp(0),
74      fLHC(kFALSE),
75      fRandomPz(kFALSE),
76      fNoHeavyQuarks(kFALSE)
77 {
78 // Constructor
79     fParticles = 0;
80     AliHijingRndm::SetHijingRandom(GetRandom());
81 }
82
83 AliGenHijing::AliGenHijing(Int_t npart)
84     :AliGenMC(npart),
85      fFrame("CMS"),
86      fMinImpactParam(0.),
87      fMaxImpactParam(5.),
88      fKeep(0),
89      fQuench(1),
90      fShadowing(1),
91      fDecaysOff(1),
92      fTrigger(0),     
93      fEvaluate(0),
94      fSelectAll(0),
95      fFlavor(0),
96      fEnergyCMS(5500.),
97      fKineBias(0.),
98      fTrials(0),
99      fXsection(0.),
100      fHijing(0),
101      fPtHardMin(0.),
102      fPtHardMax(1.e4),
103      fSpectators(1),
104      fDsigmaDb(0),
105      fDnDb(0),
106      fPtMinJet(-2.5),
107      fEtaMinJet(-20.),
108      fEtaMaxJet(+20.),
109      fPhiMinJet(0.),
110      fPhiMaxJet(2. * TMath::Pi()),
111      fRadiation(3),
112      fSimpleJet(kFALSE),
113      fNoGammas(kFALSE),
114      fProjectileSpecn(0),
115      fProjectileSpecp(0),
116      fTargetSpecn(0),
117      fTargetSpecp(0),
118      fLHC(kFALSE),
119      fRandomPz(kFALSE),
120      fNoHeavyQuarks(kFALSE)
121 {
122 // Default PbPb collisions at 5. 5 TeV
123 //
124     fName = "Hijing";
125     fTitle= "Particle Generator using HIJING";
126 //
127     fParticles = new TClonesArray("TParticle",10000);    
128 //
129 // Set random number generator   
130     AliHijingRndm::SetHijingRandom(GetRandom());
131 }
132
133 AliGenHijing::~AliGenHijing()
134 {
135 // Destructor
136     if ( fDsigmaDb) delete  fDsigmaDb;  
137     if ( fDnDb)     delete  fDnDb;  
138     delete fParticles;
139 }
140
141 void AliGenHijing::Init()
142 {
143 // Initialisation
144     fFrame.Resize(8);
145     fTarget.Resize(8);
146     fProjectile.Resize(8);
147     
148     SetMC(new THijing(fEnergyCMS, fFrame, fProjectile, fTarget, 
149                       fAProjectile, fZProjectile, fATarget, fZTarget, 
150                       fMinImpactParam, fMaxImpactParam));
151
152     fHijing=(THijing*) fMCEvGen;
153     fHijing->SetIHPR2(2,  fRadiation);
154     fHijing->SetIHPR2(3,  fTrigger);
155     fHijing->SetIHPR2(6,  fShadowing);
156     fHijing->SetIHPR2(12, fDecaysOff);    
157     fHijing->SetIHPR2(21, fKeep);
158     fHijing->SetHIPR1(10, fPtMinJet);   
159     fHijing->SetHIPR1(50, fSimpleJet);
160 //
161 //  Quenching
162 //
163 //
164 //  fQuench = 0:  no quenching
165 //  fQuench = 1:  hijing default
166 //  fQuench = 2:  new LHC  parameters for HIPR1(11) and HIPR1(14)
167 //  fQuench = 3:  new RHIC parameters for HIPR1(11) and HIPR1(14)
168 //  fQuench = 4:  new LHC  parameters with log(e) dependence
169 //  fQuench = 5:  new RHIC parameters with log(e) dependence
170     fHijing->SetIHPR2(50, 0);
171     if (fQuench > 0) 
172         fHijing->SetIHPR2(4,  1);
173     else
174         fHijing->SetIHPR2(4,  0);
175 // New LHC parameters from Xin-Nian Wang
176     if (fQuench == 2) {
177         fHijing->SetHIPR1(14, 1.1);
178         fHijing->SetHIPR1(11, 3.7);
179     } else if (fQuench == 3) {
180         fHijing->SetHIPR1(14, 0.20);
181         fHijing->SetHIPR1(11, 2.5);
182     } else if (fQuench == 4) {
183         fHijing->SetIHPR2(50, 1);
184         fHijing->SetHIPR1(14, 4.*0.34);
185         fHijing->SetHIPR1(11, 3.7);
186     } else if (fQuench == 5) {
187         fHijing->SetIHPR2(50, 1);
188         fHijing->SetHIPR1(14, 0.34);
189         fHijing->SetHIPR1(11, 2.5);
190     }
191     
192 //
193 // Heavy quarks
194 //    
195     if (fNoHeavyQuarks) {
196         fHijing->SetIHPR2(49, 1);
197     } else {
198         fHijing->SetIHPR2(49, 0);
199     }
200     
201     
202     AliGenMC::Init();
203     
204 //
205 //  Initialize Hijing  
206 //    
207     fHijing->Initialize();
208 //
209     if (fEvaluate) EvaluateCrossSections();
210 //
211 }
212
213 void AliGenHijing::Generate()
214 {
215 // Generate one event
216
217   Float_t polar[3]    =   {0,0,0};
218   Float_t origin[3]   =   {0,0,0};
219   Float_t origin0[3]  =   {0,0,0};
220   Float_t p[3];
221   Float_t tof;
222
223 //  converts from mm/c to s
224   const Float_t kconv = 0.001/2.99792458e8;
225 //
226   Int_t nt  = 0;
227   Int_t jev = 0;
228   Int_t j, kf, ks, ksp, imo;
229   kf = 0;
230     
231
232     
233   fTrials = 0;
234   
235   for (j = 0;j < 3; j++) origin0[j] = fOrigin[j];
236   if(fVertexSmear == kPerEvent) {
237       Vertex();
238       for (j=0; j < 3; j++) origin0[j] = fVertex[j];
239   } 
240
241
242   Float_t sign = (fRandomPz && (Rndm() < 0.5))? -1. : 1.;
243   while(1)
244   {
245 //    Generate one event
246 // --------------------------------------------------------------------------
247       fProjectileSpecn    = 0;  
248       fProjectileSpecp    = 0;
249       fTargetSpecn        = 0;  
250       fTargetSpecp        = 0;
251 // --------------------------------------------------------------------------
252       fHijing->GenerateEvent();
253       fTrials++;
254       fNprimaries = 0;
255       fHijing->ImportParticles(fParticles,"All");
256       if (fTrigger != kNoTrigger) {
257           if (!CheckTrigger()) continue;
258       }
259       if (fLHC) Boost();
260       
261       
262       Int_t np = fParticles->GetEntriesFast();
263       printf("\n **************************************************%d\n",np);
264       Int_t nc = 0;
265       if (np == 0 ) continue;
266       Int_t i;
267       Int_t* newPos     = new Int_t[np];
268       Int_t* pSelected  = new Int_t[np];
269
270       for (i = 0; i < np; i++) {
271           newPos[i]    = i;
272           pSelected[i] = 0;
273       }
274       
275 //      Get event vertex
276 //
277       TParticle *  iparticle = (TParticle *) fParticles->At(0);
278       fVertex[0] = origin0[0];
279       fVertex[1] = origin0[1];  
280       fVertex[2] = origin0[2];
281       
282 //
283 //      First select parent particles
284 //
285
286       for (i = 0; i < np; i++) {
287           iparticle = (TParticle *) fParticles->At(i);
288
289 // Is this a parent particle ?
290           if (Stable(iparticle)) continue;
291 //
292           Bool_t  selected             =  kTRUE;
293           Bool_t  hasSelectedDaughters =  kFALSE;
294           
295           
296           kf        = iparticle->GetPdgCode();
297           ks        = iparticle->GetStatusCode();
298           if (kf == 92) continue;
299             
300           if (!fSelectAll) selected = KinematicSelection(iparticle, 0) && 
301                                SelectFlavor(kf);
302           hasSelectedDaughters = DaughtersSelection(iparticle);
303 //
304 // Put particle on the stack if it is either selected or 
305 // it is the mother of at least one seleted particle
306 //
307           if (selected || hasSelectedDaughters) {
308               nc++;
309               pSelected[i] = 1;
310           } // selected
311       } // particle loop parents
312 //
313 // Now select the final state particles
314 //
315
316       for (i = 0; i<np; i++) {
317           TParticle *  iparticle = (TParticle *) fParticles->At(i);
318 // Is this a final state particle ?
319           if (!Stable(iparticle)) continue;
320       
321           Bool_t  selected             =  kTRUE;
322           kf        = iparticle->GetPdgCode();
323           ks        = iparticle->GetStatusCode();
324           ksp       = iparticle->GetUniqueID();
325           
326 // --------------------------------------------------------------------------
327 // Count spectator neutrons and protons
328           if(ksp == 0 || ksp == 1){
329               if(kf == kNeutron) fProjectileSpecn += 1;
330               if(kf == kProton)  fProjectileSpecp += 1;
331           }
332           else if(ksp == 10 || ksp == 11){
333               if(kf == kNeutron) fTargetSpecn += 1;
334               if(kf == kProton)  fTargetSpecp += 1;
335           }
336 // --------------------------------------------------------------------------
337 //          
338           if (!fSelectAll) {
339               selected = KinematicSelection(iparticle,0)&&SelectFlavor(kf);
340               if (!fSpectators && selected) selected = (ksp != 0 && ksp != 1 && ksp != 10
341                                                         && ksp != 11);
342           }
343 //
344 // Put particle on the stack if selected
345 //
346           if (selected) {
347               nc++;
348               pSelected[i] = 1;
349           } // selected
350       } // particle loop final state
351
352 //
353 //    Time of the interactions
354       Float_t tInt = 0.;
355       if (fPileUpTimeWindow > 0.) tInt = fPileUpTimeWindow * (2. * gRandom->Rndm() - 1.);
356
357 //
358 // Write particles to stack
359
360       for (i = 0; i<np; i++) {
361           TParticle *  iparticle = (TParticle *) fParticles->At(i);
362           Bool_t  hasMother   = (iparticle->GetFirstMother()     >=0);
363           Bool_t  hasDaughter = (iparticle->GetFirstDaughter()   >=0);
364           if (pSelected[i]) {
365               kf   = iparticle->GetPdgCode();
366               ks   = iparticle->GetStatusCode();
367               p[0] = iparticle->Px();
368               p[1] = iparticle->Py();
369               p[2] = iparticle->Pz() * sign;
370               origin[0] = origin0[0]+iparticle->Vx()/10;
371               origin[1] = origin0[1]+iparticle->Vy()/10;
372               origin[2] = origin0[2]+iparticle->Vz()/10;
373               tof = kconv * iparticle->T() + sign * origin0[2] / 3.e10;
374               if (fPileUpTimeWindow > 0.) tof += tInt;
375               
376               imo = -1;
377               TParticle* mother = 0;
378               if (hasMother) {
379                   imo = iparticle->GetFirstMother();
380                   mother = (TParticle *) fParticles->At(imo);
381                   imo = (mother->GetPdgCode() != 92) ? newPos[imo] : -1;
382               } // if has mother   
383               Bool_t tFlag = (fTrackIt && !hasDaughter);
384               PushTrack(tFlag,imo,kf,p,origin,polar,tof,kPNoProcess,nt, 1., ks);
385               fNprimaries++;
386               KeepTrack(nt);
387               newPos[i] = nt;
388           } // if selected
389       } // particle loop
390       delete[] newPos;
391       delete[] pSelected;
392       
393       printf("\n I've put %i particles on the stack \n",nc);
394       if (nc > 0) {
395           jev += nc;
396           if (jev >= fNpart || fNpart == -1) {
397               fKineBias = Float_t(fNpart)/Float_t(fTrials);
398               printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
399               break;
400           }
401       }
402   } // event loop
403   MakeHeader();
404   SetHighWaterMark(nt);
405 }
406
407 void AliGenHijing::KeepFullEvent()
408 {
409     fKeep=1;
410 }
411
412 void AliGenHijing::EvaluateCrossSections()
413 {
414 //     Glauber Calculation of geometrical x-section
415 //
416     Float_t xTot       = 0.;          // barn
417     Float_t xTotHard   = 0.;          // barn 
418     Float_t xPart      = 0.;          // barn
419     Float_t xPartHard  = 0.;          // barn 
420     Float_t sigmaHard  = 0.1;         // mbarn
421     Float_t bMin       = 0.;
422     Float_t bMax       = fHijing->GetHIPR1(34)+fHijing->GetHIPR1(35);
423     const Float_t kdib = 0.2;
424     Int_t   kMax       = Int_t((bMax-bMin)/kdib)+1;
425
426
427     printf("\n Projectile Radius (fm): %f \n",fHijing->GetHIPR1(34));
428     printf("\n Target     Radius (fm): %f \n",fHijing->GetHIPR1(35));    
429     Int_t i;
430     Float_t oldvalue= 0.;
431
432     Float_t* b   = new Float_t[kMax];
433     Float_t* si1 = new Float_t[kMax];    
434     Float_t* si2 = new Float_t[kMax];    
435     
436     for (i = 0; i < kMax; i++)
437     {
438         Float_t xb  = bMin+i*kdib;
439         Float_t ov;
440         ov=fHijing->Profile(xb);
441         Float_t gb  =  2.*0.01*fHijing->GetHIPR1(40)*kdib*xb*(1.-TMath::Exp(-fHijing->GetHINT1(12)*ov));
442         Float_t gbh =  2.*0.01*fHijing->GetHIPR1(40)*kdib*xb*sigmaHard*ov;
443         xTot+=gb;
444         xTotHard += gbh;
445         printf("profile %f %f %f\n", xb, ov, fHijing->GetHINT1(12));
446         
447         if (xb > fMinImpactParam && xb < fMaxImpactParam)
448         {
449             xPart += gb;
450             xPartHard += gbh;
451         }
452         
453         if(oldvalue) if ((xTot-oldvalue)/oldvalue<0.0001) break;
454         oldvalue = xTot;
455         printf("\n Total cross section (barn): %d %f %f \n",i, xb, xTot);
456         printf("\n Hard  cross section (barn): %d %f %f \n\n",i, xb, xTotHard);
457         if (i>0) {
458             si1[i] = gb/kdib;
459             si2[i] = gbh/gb;
460             b[i]  = xb;
461         }
462     }
463
464     printf("\n Total cross section (barn): %f \n",xTot);
465     printf("\n Hard  cross section (barn): %f \n \n",xTotHard);
466     printf("\n Partial       cross section (barn): %f %f \n",xPart, xPart/xTot*100.);
467     printf("\n Partial  hard cross section (barn): %f %f \n",xPartHard, xPartHard/xTotHard*100.);
468
469 //  Store result as a graph
470     b[0] = 0;
471     si1[0] = 0;
472     si2[0]=si2[1];
473     
474     fDsigmaDb  = new TGraph(i, b, si1);
475     fDnDb      = new TGraph(i, b, si2);
476 }
477
478 Bool_t AliGenHijing::DaughtersSelection(TParticle* iparticle)
479 {
480 //
481 // Looks recursively if one of the daughters has been selected
482 //
483 //    printf("\n Consider daughters %d:",iparticle->GetPdgCode());
484     Int_t imin = -1;
485     Int_t imax = -1;
486     Int_t i;
487     Bool_t hasDaughters = (iparticle->GetFirstDaughter() >=0);
488     Bool_t selected = kFALSE;
489     if (hasDaughters) {
490         imin = iparticle->GetFirstDaughter();
491         imax = iparticle->GetLastDaughter();       
492         for (i = imin; i <= imax; i++){
493             TParticle *  jparticle = (TParticle *) fParticles->At(i);   
494             Int_t ip = jparticle->GetPdgCode();
495             if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
496                 selected=kTRUE; break;
497             }
498             if (DaughtersSelection(jparticle)) {selected=kTRUE; break; }
499         }
500     } else {
501         return kFALSE;
502     }
503     return selected;
504 }
505
506
507 Bool_t AliGenHijing::SelectFlavor(Int_t pid)
508 {
509 // Select flavor of particle
510 // 0: all
511 // 4: charm and beauty
512 // 5: beauty
513     Bool_t res = 0;
514     
515     if (fFlavor == 0) {
516         res = kTRUE;
517     } else {
518         Int_t ifl = TMath::Abs(pid/100);
519         if (ifl > 10) ifl/=10;
520         res = (fFlavor == ifl);
521     }
522 //
523 //  This part if gamma writing is inhibited
524     if (fNoGammas) 
525         res = res && (pid != kGamma && pid != kPi0);
526 //
527     return res;
528 }
529
530 Bool_t AliGenHijing::Stable(TParticle*  particle) const
531 {
532 // Return true for a stable particle
533 //
534     
535     if (particle->GetFirstDaughter() < 0 )
536     {
537         return kTRUE;
538     } else {
539         return kFALSE;
540     }
541 }
542
543
544
545 void AliGenHijing::MakeHeader()
546 {
547 // Builds the event header, to be called after each event
548     AliGenEventHeader* header = new AliGenHijingEventHeader("Hijing");
549     ((AliGenHijingEventHeader*) header)->SetNProduced(fNprimaries);
550     ((AliGenHijingEventHeader*) header)->SetImpactParameter(fHijing->GetHINT1(19));
551     ((AliGenHijingEventHeader*) header)->SetTotalEnergy(fHijing->GetEATT());
552     ((AliGenHijingEventHeader*) header)->SetHardScatters(fHijing->GetJATT());
553     ((AliGenHijingEventHeader*) header)->SetParticipants(fHijing->GetNP(), fHijing->GetNT());
554     ((AliGenHijingEventHeader*) header)->SetCollisions(fHijing->GetN0(),
555                                                        fHijing->GetN01(),
556                                                        fHijing->GetN10(),
557                                                        fHijing->GetN11());
558     ((AliGenHijingEventHeader*) header)->SetSpectators(fProjectileSpecn, fProjectileSpecp,
559                                                        fTargetSpecn,fTargetSpecp);
560     ((AliGenHijingEventHeader*) header)->SetReactionPlaneAngle(fHijing->GetHINT1(20));
561     
562
563
564 // 4-momentum vectors of the triggered jets.
565 //
566 // Before final state gluon radiation.
567     TLorentzVector* jet1 = new TLorentzVector(fHijing->GetHINT1(21), 
568                                               fHijing->GetHINT1(22),
569                                               fHijing->GetHINT1(23),
570                                               fHijing->GetHINT1(24));
571
572     TLorentzVector* jet2 = new TLorentzVector(fHijing->GetHINT1(31), 
573                                               fHijing->GetHINT1(32),
574                                               fHijing->GetHINT1(33),
575                                               fHijing->GetHINT1(34));
576 // After final state gluon radiation.
577     TLorentzVector* jet3 = new TLorentzVector(fHijing->GetHINT1(26), 
578                                               fHijing->GetHINT1(27),
579                                               fHijing->GetHINT1(28),
580                                               fHijing->GetHINT1(29));
581
582     TLorentzVector* jet4 = new TLorentzVector(fHijing->GetHINT1(36), 
583                                               fHijing->GetHINT1(37),
584                                               fHijing->GetHINT1(38),
585                                               fHijing->GetHINT1(39));
586     ((AliGenHijingEventHeader*) header)->SetJets(jet1, jet2, jet3, jet4);
587 // Bookkeeping for kinematic bias
588     ((AliGenHijingEventHeader*) header)->SetTrials(fTrials);
589 // Event Vertex
590     header->SetPrimaryVertex(fVertex);
591     AddHeader(header);
592     fCollisionGeometry = (AliGenHijingEventHeader*)  header;
593 }
594
595
596 Bool_t AliGenHijing::CheckTrigger()
597 {
598 // Check the kinematic trigger condition
599 //
600     Bool_t   triggered = kFALSE;
601  
602     if (fTrigger == 1) {
603 //
604 //  jet-jet Trigger     
605         
606         TLorentzVector* jet1 = new TLorentzVector(fHijing->GetHINT1(26), 
607                                                   fHijing->GetHINT1(27),
608                                                   fHijing->GetHINT1(28),
609                                                   fHijing->GetHINT1(29));
610         
611         TLorentzVector* jet2 = new TLorentzVector(fHijing->GetHINT1(36), 
612                                                   fHijing->GetHINT1(37),
613                                                   fHijing->GetHINT1(38),
614                                                   fHijing->GetHINT1(39));
615         Double_t eta1      = jet1->Eta();
616         Double_t eta2      = jet2->Eta();
617         Double_t phi1      = jet1->Phi();
618         Double_t phi2      = jet2->Phi();
619 //    printf("\n Trigger: %f %f %f %f",
620 //         fEtaMinJet, fEtaMaxJet, fPhiMinJet, fPhiMaxJet);
621         if (
622             (eta1 < fEtaMaxJet && eta1 > fEtaMinJet &&  
623              phi1 < fPhiMaxJet && phi1 > fPhiMinJet) 
624             ||
625             (eta2 < fEtaMaxJet && eta2 > fEtaMinJet &&  
626              phi2 < fPhiMaxJet && phi2 > fPhiMinJet)
627             ) 
628             triggered = kTRUE;
629     } else if (fTrigger == 2) {
630 //  Gamma Jet
631 //
632         Int_t np = fParticles->GetEntriesFast();
633         for (Int_t i = 0; i < np; i++) {
634             TParticle* part = (TParticle*) fParticles->At(i);
635             Int_t kf = part->GetPdgCode();
636             Int_t ksp = part->GetUniqueID();
637             if (kf == 22 && ksp == 40) {
638                 Float_t phi = part->Phi();
639                 Float_t eta = part->Eta();
640                 if  (eta < fEtaMaxJet && 
641                      eta > fEtaMinJet &&
642                      phi < fPhiMaxJet && 
643                      phi > fPhiMinJet) {
644                     triggered = 1;
645                     break;
646                 } // check phi,eta within limits
647             } // direct gamma ? 
648         } // particle loop
649     } // fTrigger == 2
650     return triggered;
651 }