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->SetPTMAX(fPtHardMax);
145 fHerwig->SetPTRMS(fPtRMS);
146 fHerwig->SetMAXPR(fMaxPr);
147 fHerwig->SetMAXER(fMaxErrors);
148 fHerwig->SetENSOF(fEnSoft);
150 fHerwig->SetEV1PR(fEv1Pr);
151 fHerwig->SetEV2PR(fEv2Pr);
153 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
162 fHerwig->SetRMASS(4,1.2);
163 fHerwig->SetRMASS(5,4.75);
165 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(),50);
167 //fHerwig->Hwusta("PI0 ");
169 // compute parameter dependent constants
170 fHerwig->PrepareRun();
173 void AliGenHerwig::InitJimmy()
177 fProjectile.Resize(8);
178 SetMC(new THerwig6());
179 fHerwig=(THerwig6*) fMCEvGen;
180 // initialize common blocks
181 fHerwig->InitializeJimmy(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
182 // reset parameters according to user needs
184 fHerwig->SetPTMIN(fPtHardMin);
185 fHerwig->SetPTRMS(fPtRMS);
186 fHerwig->SetMAXPR(fMaxPr);
187 fHerwig->SetMAXER(fMaxErrors);
188 fHerwig->SetENSOF(fEnSoft);
190 fHerwig->SetEV1PR(fEv1Pr);
191 fHerwig->SetEV2PR(fEv2Pr);
193 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
202 fHerwig->SetRMASS(4,1.2);
203 fHerwig->SetRMASS(5,4.75);
205 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(),50);
207 // fHerwig->Hwusta("PI0 ");
209 // compute parameter dependent constants
210 fHerwig->PrepareRunJimmy();
213 void AliGenHerwig::InitPDF()
217 // ONLY USES LHAPDF STRUCTURE FUNCTIONS
258 // case kMRST2004nlo:
260 // fAutPDF="HWLHAPDF";
263 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
267 fHerwig->SetMODPDF(1,fModPDF);
268 fHerwig->SetMODPDF(2,fModPDF);
269 fHerwig->SetAUTPDF(1,fAutPDF);
270 fHerwig->SetAUTPDF(2,fAutPDF);
273 void AliGenHerwig::Generate()
275 // Generate one event
277 Float_t polar[3] = {0,0,0};
278 Float_t origin[3]= {0,0,0};
279 Float_t origin0[3]= {0,0,0};
280 Float_t p[4], random[6];
282 static TClonesArray *particles;
283 // converts from mm/c to s
284 const Float_t kconv=0.001/2.999792458e8;
288 Int_t j, kf, ks, imo;
291 if(!particles) particles=new TClonesArray("TParticle",10000);
294 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
295 if(fVertexSmear==kPerEvent) {
298 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
299 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
305 fHerwig->GenerateEvent();
307 fHerwig->ImportParticles(particles,"All");
308 Int_t np = particles->GetEntriesFast()-1;
309 if (np == 0 ) continue;
311 //Check hard partons or direct gamma in kine range
313 if (fProcess == kHeJets || fProcess == kHeDirectGamma) {
314 TParticle* parton1 = (TParticle *) particles->At(6);
315 TParticle* parton2 = (TParticle *) particles->At(7);
316 if (!CheckParton(parton1, parton2)) continue ;
321 Int_t * newPos = new Int_t[np];
322 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
324 for (Int_t i = 0; i<np; i++) {
325 TParticle * iparticle = (TParticle *) particles->At(i);
326 imo = iparticle->GetFirstMother();
327 kf = iparticle->GetPdgCode();
328 ks = iparticle->GetStatusCode();
330 KinematicSelection(iparticle,0))
333 p[0]=iparticle->Px();
334 p[1]=iparticle->Py();
335 p[2]=iparticle->Pz();
336 p[3]=iparticle->Energy();
337 origin[0]=origin0[0]+iparticle->Vx()/10;
338 origin[1]=origin0[1]+iparticle->Vy()/10;
339 origin[2]=origin0[2]+iparticle->Vz()/10;
340 Float_t tof = kconv*iparticle->T();
341 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
342 Int_t trackIt = (ks == 1) && fTrackIt;
343 PushTrack(trackIt, iparent, kf,
344 p[0], p[1], p[2], p[3],
345 origin[0], origin[1], origin[2],
347 polar[0], polar[1], polar[2],
348 kPPrimary, nt, fHerwig->GetEVWGT(), ks);
351 } // end of if: selection of particle
352 } // end of for: particle loop
353 if (newPos) delete[] newPos;
357 if (jev >= fNpart || fNpart == -1) {
358 fKineBias=Float_t(fNpart)/Float_t(fTrials);
363 SetHighWaterMark(nt);
364 // adjust weight due to kinematic selection
367 fXsection=fHerwig->GetAVWGT();
368 //printf(">> trials << %d\n",fTrials);
371 Bool_t AliGenHerwig::CheckParton(TParticle* parton1, TParticle* parton2)
373 // Check the kinematic trigger condition
375 //Select events with parton max energy
376 if(fPtHardMax < parton1->Pt()) return kFALSE;
378 // Select events within angular window
380 eta[0] = parton1->Eta();
381 eta[1] = parton2->Eta();
383 phi[0] = parton1->Phi();
384 phi[1] = parton2->Phi();
386 pdg[0] = parton1->GetPdgCode();
387 pdg[1] = parton2->GetPdgCode();
388 printf("min %f, max %f\n",fPtHardMin, fPtHardMax);
389 printf("Parton 1: %s, pT= %2.2f, eta = %1.2f, phi = %2.2f\n", parton1->GetName(),parton1->Pt(), eta[0],phi[0]*TMath::RadToDeg());
390 printf("Parton 2: %s, pT= %2.2f, eta = %1.2f, phi = %2.2f\n", parton2->GetName(),parton2->Pt(), eta[1],phi[1]*TMath::RadToDeg());
392 if (fProcess == kHeJets) {
393 //Check if one of the 2 outgoing partons are in the eta-phi window
394 for(Int_t i = 0; i < 2; i++)
395 if ((eta[i] < fEtaMaxParton && eta[i] > fEtaMinParton) &&
396 (phi[i] < fPhiMaxParton && phi[i] > fPhiMinParton)) return kTRUE ;
400 //Check if the gamma and the jet are in the eta-phi window
403 if(pdg[0] == 22) ijj=1;
405 if ((eta[ijj] < fEtaMaxParton && eta[ijj] > fEtaMinParton) &&
406 (phi[ijj] < fPhiMaxParton && phi[ijj] > fPhiMinParton)) {
408 if ((eta[igj] < fEtaMaxGamma && eta[igj] > fEtaMinGamma) &&
409 (phi[igj] < fPhiMaxGamma && phi[igj] > fPhiMinGamma)) return kTRUE;
417 void AliGenHerwig::AdjustWeights()
419 // Adjust the weights after generation of all events
421 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
422 for (Int_t i=0; i<ntrack; i++) {
423 part= gAlice->GetMCApp()->Particle(i);
424 part->SetWeight(part->GetWeight()*fKineBias);
429 void AliGenHerwig::KeepFullEvent()
434 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
437 // Looks recursively if one of the daughters has been selected
439 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
443 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
444 Bool_t selected=kFALSE;
446 imin=iparticle->GetFirstDaughter();
447 imax=iparticle->GetLastDaughter();
448 for (i=imin; i<= imax; i++){
449 TParticle * jparticle = (TParticle *) particles->At(i);
450 Int_t ip=jparticle->GetPdgCode();
451 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
452 selected=kTRUE; break;
454 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
464 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
466 // Select flavor of particle
468 // 4: charm and beauty
470 if (fFlavor == 0) return kTRUE;
472 Int_t ifl=TMath::Abs(pid/100);
473 if (ifl > 10) ifl/=10;
474 return (fFlavor == ifl);
477 Bool_t AliGenHerwig::Stable(TParticle* particle)
479 // Return true for a stable particle
481 Int_t kf = TMath::Abs(particle->GetPdgCode());
483 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
492 void AliGenHerwig::FinishRun()
497 void AliGenHerwig::FinishRunJimmy()