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