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)
127 fEv1Pr = ++eventFirst;
128 fEv2Pr = ++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, fTarget, fMomentum1, fMomentum2, fProcess);
141 // reset parameters according to user needs
143 fHerwig->SetPTMIN(fPtHardMin);
144 fHerwig->SetPTRMS(fPtRMS);
145 fHerwig->SetMAXPR(fMaxPr);
146 fHerwig->SetMAXER(fMaxErrors);
147 fHerwig->SetENSOF(fEnSoft);
149 fHerwig->SetEV1PR(fEv1Pr);
150 fHerwig->SetEV2PR(fEv2Pr);
152 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
161 fHerwig->SetRMASS(4,1.2);
162 fHerwig->SetRMASS(5,4.75);
164 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(),50);
166 //fHerwig->Hwusta("PI0 ");
168 // compute parameter dependent constants
169 fHerwig->PrepareRun();
172 void AliGenHerwig::InitJimmy()
176 fProjectile.Resize(8);
177 SetMC(new THerwig6());
178 fHerwig=(THerwig6*) fMCEvGen;
179 // initialize common blocks
180 fHerwig->InitializeJimmy(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
181 // reset parameters according to user needs
183 fHerwig->SetPTMIN(fPtHardMin);
184 fHerwig->SetPTRMS(fPtRMS);
185 fHerwig->SetMAXPR(fMaxPr);
186 fHerwig->SetMAXER(fMaxErrors);
187 fHerwig->SetENSOF(fEnSoft);
189 fHerwig->SetEV1PR(fEv1Pr);
190 fHerwig->SetEV2PR(fEv2Pr);
192 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
201 fHerwig->SetRMASS(4,1.2);
202 fHerwig->SetRMASS(5,4.75);
204 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(),50);
206 // fHerwig->Hwusta("PI0 ");
208 // compute parameter dependent constants
209 fHerwig->PrepareRunJimmy();
212 void AliGenHerwig::InitPDF()
216 // ONLY USES LHAPDF STRUCTURE FUNCTIONS
257 // case kMRST2004nlo:
259 // fAutPDF="HWLHAPDF";
262 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
266 fHerwig->SetMODPDF(1,fModPDF);
267 fHerwig->SetMODPDF(2,fModPDF);
268 fHerwig->SetAUTPDF(1,fAutPDF);
269 fHerwig->SetAUTPDF(2,fAutPDF);
272 void AliGenHerwig::Generate()
274 // Generate one event
276 Float_t polar[3] = {0,0,0};
277 Float_t origin[3]= {0,0,0};
278 Float_t origin0[3]= {0,0,0};
279 Float_t p[4], random[6];
281 static TClonesArray *particles;
282 // converts from mm/c to s
283 const Float_t kconv=0.001/2.999792458e8;
287 Int_t j, kf, ks, imo;
290 if(!particles) particles=new TClonesArray("TParticle",10000);
293 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
294 if(fVertexSmear==kPerEvent) {
297 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
298 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
304 fHerwig->GenerateEvent();
306 fHerwig->ImportParticles(particles,"All");
307 Int_t np = particles->GetEntriesFast()-1;
308 if (np == 0 ) continue;
310 //Check hard partons or direct gamma in kine range
312 if (fProcess == kHeJets || fProcess == kHeDirectGamma) {
313 TParticle* parton1 = (TParticle *) particles->At(6);
314 TParticle* parton2 = (TParticle *) particles->At(7);
315 if (!CheckParton(parton1, parton2)) continue ;
320 Int_t * newPos = new Int_t[np];
321 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
323 for (Int_t i = 0; i<np; i++) {
324 TParticle * iparticle = (TParticle *) particles->At(i);
325 imo = iparticle->GetFirstMother();
326 kf = iparticle->GetPdgCode();
327 ks = iparticle->GetStatusCode();
329 KinematicSelection(iparticle,0))
332 p[0]=iparticle->Px();
333 p[1]=iparticle->Py();
334 p[2]=iparticle->Pz();
335 p[3]=iparticle->Energy();
336 origin[0]=origin0[0]+iparticle->Vx()/10;
337 origin[1]=origin0[1]+iparticle->Vy()/10;
338 origin[2]=origin0[2]+iparticle->Vz()/10;
339 Float_t tof = kconv*iparticle->T();
340 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
341 Int_t trackIt = (ks == 1) && fTrackIt;
342 PushTrack(trackIt, iparent, kf,
343 p[0], p[1], p[2], p[3],
344 origin[0], origin[1], origin[2],
346 polar[0], polar[1], polar[2],
347 kPPrimary, nt, fHerwig->GetEVWGT(), ks);
350 } // end of if: selection of particle
351 } // end of for: particle loop
352 if (newPos) delete[] newPos;
356 if (jev >= fNpart || fNpart == -1) {
357 fKineBias=Float_t(fNpart)/Float_t(fTrials);
362 SetHighWaterMark(nt);
363 // adjust weight due to kinematic selection
366 fXsection=fHerwig->GetAVWGT();
367 //printf(">> trials << %d\n",fTrials);
370 Bool_t AliGenHerwig::CheckParton(TParticle* parton1, TParticle* parton2)
372 // Check the kinematic trigger condition
374 //Select events with parton max energy
375 if(fPtHardMax < parton1->Pt()) return kFALSE;
377 // Select events within angular window
379 eta[0] = parton1->Eta();
380 eta[1] = parton2->Eta();
382 phi[0] = parton1->Phi();
383 phi[1] = parton2->Phi();
385 pdg[0] = parton1->GetPdgCode();
386 pdg[1] = parton2->GetPdgCode();
387 printf("min %f, max %f\n",fPtHardMin, fPtHardMax);
388 printf("Parton 1: %s, pT= %2.2f, eta = %1.2f, phi = %2.2f\n", parton1->GetName(),parton1->Pt(), eta[0],phi[0]*TMath::RadToDeg());
389 printf("Parton 2: %s, pT= %2.2f, eta = %1.2f, phi = %2.2f\n", parton2->GetName(),parton2->Pt(), eta[1],phi[1]*TMath::RadToDeg());
391 if (fProcess == kHeJets) {
392 //Check if one of the 2 outgoing partons are in the eta-phi window
393 for(Int_t i = 0; i < 2; i++)
394 if ((eta[i] < fEtaMaxParton && eta[i] > fEtaMinParton) &&
395 (phi[i] < fPhiMaxParton && phi[i] > fPhiMinParton)) return kTRUE ;
399 //Check if the gamma and the jet are in the eta-phi window
402 if(pdg[0] == 22) ijj=1;
404 if ((eta[ijj] < fEtaMaxParton && eta[ijj] > fEtaMinParton) &&
405 (phi[ijj] < fPhiMaxParton && phi[ijj] > fPhiMinParton)) {
407 if ((eta[igj] < fEtaMaxGamma && eta[igj] > fEtaMinGamma) &&
408 (phi[igj] < fPhiMaxGamma && phi[igj] > fPhiMinGamma)) return kTRUE;
416 void AliGenHerwig::AdjustWeights()
418 // Adjust the weights after generation of all events
420 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
421 for (Int_t i=0; i<ntrack; i++) {
422 part= gAlice->GetMCApp()->Particle(i);
423 part->SetWeight(part->GetWeight()*fKineBias);
428 void AliGenHerwig::KeepFullEvent()
433 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
436 // Looks recursively if one of the daughters has been selected
438 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
442 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
443 Bool_t selected=kFALSE;
445 imin=iparticle->GetFirstDaughter();
446 imax=iparticle->GetLastDaughter();
447 for (i=imin; i<= imax; i++){
448 TParticle * jparticle = (TParticle *) particles->At(i);
449 Int_t ip=jparticle->GetPdgCode();
450 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
451 selected=kTRUE; break;
453 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
463 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
465 // Select flavor of particle
467 // 4: charm and beauty
469 if (fFlavor == 0) return kTRUE;
471 Int_t ifl=TMath::Abs(pid/100);
472 if (ifl > 10) ifl/=10;
473 return (fFlavor == ifl);
476 Bool_t AliGenHerwig::Stable(TParticle* particle)
478 // Return true for a stable particle
480 Int_t kf = TMath::Abs(particle->GetPdgCode());
482 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
491 void AliGenHerwig::FinishRun()
496 void AliGenHerwig::FinishRunJimmy()