1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 // Generator using Herwig as an external generator
20 // The main Herwig options are accessable for the user through this interface.
21 // Uses the THerwig implementation of TGenerator.
24 #include <Riostream.h>
25 #include <TClonesArray.h>
26 #include <TParticle.h>
30 #include "AliGenHerwig.h"
31 #include "AliHerwigRndm.h"
36 ClassImp(AliGenHerwig)
39 AliGenHerwig::AliGenHerwig() :
68 fPhiMaxParton(2.* TMath::Pi()),
72 fPhiMaxGamma(2. * TMath::Pi())
78 AliGenHerwig::AliGenHerwig(Int_t npart)
107 fPhiMaxParton(2.* TMath::Pi()),
111 fPhiMaxGamma(2. * TMath::Pi())
116 // Set random number generator
117 AliHerwigRndm::SetHerwigRandom(GetRandom());
120 AliGenHerwig::~AliGenHerwig()
125 void AliGenHerwig::SetEventListRange(Int_t eventFirst, Int_t eventLast)
129 if ( fEv2Pr == -1 ) fEv2Pr = fEv2Pr;
132 void AliGenHerwig::Init()
136 fProjectile.Resize(8);
137 SetMC(new THerwig6());
138 fHerwig=(THerwig6*) fMCEvGen;
139 // initialize common blocks
140 fHerwig->Initialize(fProjectile.Data(), fTarget.Data(), fMomentum1, fMomentum2, fProcess); //
141 // reset parameters according to user needs
143 fHerwig->SetPTMIN(fPtHardMin);
144 fHerwig->SetPTMAX(fPtHardMax);
145 fHerwig->SetPTRMS(fPtRMS);
146 fHerwig->SetMAXPR(fMaxPr);
147 fHerwig->SetMAXER(fMaxErrors);
148 fHerwig->SetENSOF(fEnSoft);
149 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
158 fHerwig->SetRMASS(4,1.2);
159 fHerwig->SetRMASS(5,4.75);
161 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(),50);
163 //fHerwig->Hwusta("PI0 ");
165 // compute parameter dependent constants
166 fHerwig->PrepareRun();
169 void AliGenHerwig::InitJimmy()
173 fProjectile.Resize(8);
174 SetMC(new THerwig6());
175 fHerwig=(THerwig6*) fMCEvGen;
176 // initialize common blocks
177 fHerwig->InitializeJimmy(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
178 // reset parameters according to user needs
180 fHerwig->SetPTMIN(fPtHardMin);
181 fHerwig->SetPTRMS(fPtRMS);
182 fHerwig->SetMAXPR(fMaxPr);
183 fHerwig->SetMAXER(fMaxErrors);
184 fHerwig->SetENSOF(fEnSoft);
186 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
195 fHerwig->SetRMASS(4,1.2);
196 fHerwig->SetRMASS(5,4.75);
198 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(),50);
200 // fHerwig->Hwusta("PI0 ");
202 // compute parameter dependent constants
203 fHerwig->PrepareRunJimmy();
206 void AliGenHerwig::InitPDF()
210 // ONLY USES LHAPDF STRUCTURE FUNCTIONS
251 // case kMRST2004nlo:
253 // fAutPDF="HWLHAPDF";
256 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
260 fHerwig->SetMODPDF(1,fModPDF);
261 fHerwig->SetMODPDF(2,fModPDF);
262 fHerwig->SetAUTPDF(1,fAutPDF);
263 fHerwig->SetAUTPDF(2,fAutPDF);
266 void AliGenHerwig::Generate()
268 // Generate one event
270 Float_t polar[3] = {0,0,0};
271 Float_t origin[3]= {0,0,0};
272 Float_t origin0[3]= {0,0,0};
273 Float_t p[4], random[6];
275 static TClonesArray *particles;
276 // converts from mm/c to s
277 const Float_t kconv=0.001/2.999792458e8;
281 Int_t j, kf, ks, imo;
284 if(!particles) particles=new TClonesArray("TParticle",10000);
287 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
288 if(fVertexSmear==kPerEvent) {
291 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
292 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
298 fHerwig->GenerateEvent();
300 fHerwig->ImportParticles(particles,"All");
301 Int_t np = particles->GetEntriesFast()-1;
302 if (np == 0 ) continue;
304 //Check hard partons or direct gamma in kine range
306 if (fProcess == kHeJets || fProcess == kHeDirectGamma) {
307 TParticle* parton1 = (TParticle *) particles->At(6);
308 TParticle* parton2 = (TParticle *) particles->At(7);
309 if (!CheckParton(parton1, parton2)) continue ;
314 if (gAlice->GetEvNumber()>=fEv1Pr &&
315 gAlice->GetEvNumber()<=fEv2Pr) fHerwig->PrintEvt();
322 Int_t * newPos = new Int_t[np];
323 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
325 for (Int_t i = 0; i<np; i++) {
326 TParticle * iparticle = (TParticle *) particles->At(i);
327 imo = iparticle->GetFirstMother();
328 kf = iparticle->GetPdgCode();
329 ks = iparticle->GetStatusCode();
331 KinematicSelection(iparticle,0))
334 p[0]=iparticle->Px();
335 p[1]=iparticle->Py();
336 p[2]=iparticle->Pz();
337 p[3]=iparticle->Energy();
338 origin[0]=origin0[0]+iparticle->Vx()/10;
339 origin[1]=origin0[1]+iparticle->Vy()/10;
340 origin[2]=origin0[2]+iparticle->Vz()/10;
341 Float_t tof = kconv*iparticle->T();
342 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
343 Int_t trackIt = (ks == 1) && fTrackIt;
344 PushTrack(trackIt, iparent, kf,
345 p[0], p[1], p[2], p[3],
346 origin[0], origin[1], origin[2],
348 polar[0], polar[1], polar[2],
349 kPPrimary, nt, fHerwig->GetEVWGT(), ks);
352 } // end of if: selection of particle
353 } // end of for: particle loop
354 if (newPos) delete[] newPos;
358 if (jev >= fNpart || fNpart == -1) {
359 fKineBias=Float_t(fNpart)/Float_t(fTrials);
364 SetHighWaterMark(nt);
365 // adjust weight due to kinematic selection
368 fXsection=fHerwig->GetAVWGT();
369 //printf(">> trials << %d\n",fTrials);
372 Bool_t AliGenHerwig::CheckParton(TParticle* parton1, TParticle* parton2)
374 // Check the kinematic trigger condition
376 //Select events with parton max energy
377 if(fPtHardMax < parton1->Pt()) return kFALSE;
379 // Select events within angular window
381 eta[0] = parton1->Eta();
382 eta[1] = parton2->Eta();
384 phi[0] = parton1->Phi();
385 phi[1] = parton2->Phi();
387 pdg[0] = parton1->GetPdgCode();
388 pdg[1] = parton2->GetPdgCode();
389 printf("min %f, max %f\n",fPtHardMin, fPtHardMax);
390 printf("Parton 1: %s, pT= %2.2f, eta = %1.2f, phi = %2.2f\n", parton1->GetName(),parton1->Pt(), eta[0],phi[0]*TMath::RadToDeg());
391 printf("Parton 2: %s, pT= %2.2f, eta = %1.2f, phi = %2.2f\n", parton2->GetName(),parton2->Pt(), eta[1],phi[1]*TMath::RadToDeg());
393 if (fProcess == kHeJets) {
394 //Check if one of the 2 outgoing partons are in the eta-phi window
395 for(Int_t i = 0; i < 2; i++)
396 if ((eta[i] < fEtaMaxParton && eta[i] > fEtaMinParton) &&
397 (phi[i] < fPhiMaxParton && phi[i] > fPhiMinParton)) return kTRUE ;
401 //Check if the gamma and the jet are in the eta-phi window
404 if(pdg[0] == 22) ijj=1;
406 if ((eta[ijj] < fEtaMaxParton && eta[ijj] > fEtaMinParton) &&
407 (phi[ijj] < fPhiMaxParton && phi[ijj] > fPhiMinParton)) {
409 if ((eta[igj] < fEtaMaxGamma && eta[igj] > fEtaMinGamma) &&
410 (phi[igj] < fPhiMaxGamma && phi[igj] > fPhiMinGamma)) return kTRUE;
418 void AliGenHerwig::AdjustWeights()
420 // Adjust the weights after generation of all events
422 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
423 for (Int_t i=0; i<ntrack; i++) {
424 part= gAlice->GetMCApp()->Particle(i);
425 part->SetWeight(part->GetWeight()*fKineBias);
430 void AliGenHerwig::KeepFullEvent()
435 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
438 // Looks recursively if one of the daughters has been selected
440 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
444 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
445 Bool_t selected=kFALSE;
447 imin=iparticle->GetFirstDaughter();
448 imax=iparticle->GetLastDaughter();
449 for (i=imin; i<= imax; i++){
450 TParticle * jparticle = (TParticle *) particles->At(i);
451 Int_t ip=jparticle->GetPdgCode();
452 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
453 selected=kTRUE; break;
455 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
465 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
467 // Select flavor of particle
469 // 4: charm and beauty
471 if (fFlavor == 0) return kTRUE;
473 Int_t ifl=TMath::Abs(pid/100);
474 if (ifl > 10) ifl/=10;
475 return (fFlavor == ifl);
478 Bool_t AliGenHerwig::Stable(TParticle* particle)
480 // Return true for a stable particle
482 Int_t kf = TMath::Abs(particle->GetPdgCode());
484 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
493 void AliGenHerwig::FinishRun()
498 void AliGenHerwig::FinishRunJimmy()