2 /**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
20 // Generator using Herwig as an external generator
21 // The main Herwig options are accessable for the user through this interface.
22 // Uses the THerwig implementation of TGenerator.
25 #include <Riostream.h>
26 #include <TClonesArray.h>
27 #include <TParticle.h>
31 #include "AliGenHerwig.h"
32 #include "AliGenHerwigEventHeader.h"
33 #include "AliHerwigRndm.h"
41 ClassImp(AliGenHerwig)
44 AliGenHerwig::AliGenHerwig() :
71 fPhiMaxParton(2.* TMath::Pi()),
75 fPhiMaxGamma(2. * TMath::Pi()),
82 AliGenHerwig::AliGenHerwig(Int_t npart)
109 fPhiMaxParton(2.* TMath::Pi()),
113 fPhiMaxGamma(2. * TMath::Pi()),
120 // Set random number generator
121 AliHerwigRndm::SetHerwigRandom(GetRandom());
124 AliGenHerwig::~AliGenHerwig()
129 void AliGenHerwig::Init()
133 fProjectile.Resize(8);
134 SetMC(new THerwig6());
135 fHerwig=(THerwig6*) fMCEvGen;
136 // initialize common blocks
137 fHerwig->Initialize(fProjectile.Data(), fTarget.Data(), fMomentum1, fMomentum2, fProcess); //
138 // reset parameters according to user needs
140 fHerwig->SetPTMIN(fPtHardMin);
141 fHerwig->SetPTMAX(fPtHardMax);
142 fHerwig->SetPTRMS(fPtRMS);
143 printf("SetMAXPR %15d \n", fMaxPr);
144 fHerwig->SetMAXPR(fMaxPr);
145 fHerwig->SetMAXER(fMaxErrors);
146 fHerwig->SetENSOF(fEnSoft);
147 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
156 fHerwig->SetRMASS(4,1.2);
157 fHerwig->SetRMASS(5,4.75);
159 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(), 49);
161 //fHerwig->Hwusta("PI0 ");
163 // compute parameter dependent constants
164 fHerwig->PrepareRun();
167 void AliGenHerwig::InitJimmy()
171 fProjectile.Resize(8);
172 SetMC(new THerwig6());
173 fHerwig=(THerwig6*) fMCEvGen;
174 // initialize common blocks
175 fHerwig->InitializeJimmy(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
176 // reset parameters according to user needs
178 fHerwig->SetPTMIN(fPtHardMin);
179 fHerwig->SetPTRMS(fPtRMS);
180 fHerwig->SetMAXPR(fMaxPr);
181 fHerwig->SetMAXER(fMaxErrors);
182 fHerwig->SetENSOF(fEnSoft);
184 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
193 fHerwig->SetRMASS(4,1.2);
194 fHerwig->SetRMASS(5,4.75);
196 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(), 49);
198 // fHerwig->Hwusta("PI0 ");
200 // compute parameter dependent constants
201 fHerwig->PrepareRunJimmy();
204 void AliGenHerwig::InitPDF()
209 // ONLY USES LHAPDF STRUCTURE FUNCTIONS
250 // case kMRST2004nlo:
252 // fAutPDF="HWLHAPDF";
255 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
259 fHerwig->SetMODPDF(1,fModPDF);
260 fHerwig->SetMODPDF(2,fModPDF);
261 fHerwig->SetAUTPDF(1,fAutPDF);
262 fHerwig->SetAUTPDF(2,fAutPDF);
265 void AliGenHerwig::Generate()
267 // Generate one event
269 Float_t polar[3] = {0,0,0};
270 Float_t origin[3] = {0,0,0};
273 static TClonesArray *particles;
274 // converts from mm/c to s
275 const Float_t kconv=0.001/2.999792458e8;
282 if(!particles) particles=new TClonesArray("TParticle",10000);
286 // Set collision vertex position
287 if (fVertexSmear == kPerEvent) Vertex();
291 fHerwig->GenerateEvent();
293 fHerwig->ImportParticles(particles,"All");
294 Int_t np = particles->GetEntriesFast()-1;
295 if (np == 0 ) continue;
297 //Check hard partons or direct gamma in kine range
299 if (fProcess == kHeJets || fProcess == kHeDirectGamma) {
300 TParticle* parton1 = (TParticle *) particles->At(6);
301 TParticle* parton2 = (TParticle *) particles->At(7);
302 if (!CheckParton(parton1, parton2)) continue ;
308 Int_t * newPos = new Int_t[np];
309 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
311 for (Int_t i = 0; i<np; i++) {
312 TParticle * iparticle = (TParticle *) particles->At(i);
313 imo = iparticle->GetFirstMother();
314 kf = iparticle->GetPdgCode();
315 ks = iparticle->GetStatusCode();
317 KinematicSelection(iparticle,0))
320 p[0]=iparticle->Px();
321 p[1]=iparticle->Py();
322 p[2]=iparticle->Pz();
323 p[3]=iparticle->Energy();
325 origin[0] = fVertex[0] + iparticle->Vx()/10; // [cm]
326 origin[1] = fVertex[1] + iparticle->Vy()/10; // [cm]
327 origin[2] = fVertex[2] + iparticle->Vz()/10; // [cm]
329 Float_t tof = fTime + kconv*iparticle->T();
330 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
331 Int_t trackIt = (ks == 1) && fTrackIt;
332 PushTrack(trackIt, iparent, kf,
333 p[0], p[1], p[2], p[3],
334 origin[0], origin[1], origin[2],
336 polar[0], polar[1], polar[2],
337 kPPrimary, nt, fHerwig->GetEVWGT(), ks);
341 } // end of if: selection of particle
342 } // end of for: particle loop
343 if (newPos) delete[] newPos;
346 if (jev >= fNpart || fNpart == -1) {
347 fKineBias=Float_t(fNpart)/Float_t(fTrials);
355 SetHighWaterMark(nt);
356 // adjust weight due to kinematic selection
359 fXsection=fHerwig->GetAVWGT();
360 //printf(">> trials << %d\n",fTrials);
363 Bool_t AliGenHerwig::CheckParton(const TParticle* parton1, const TParticle* parton2)
365 // Check the kinematic trigger condition
367 //Select events with parton max energy
368 if(fPtHardMax < parton1->Pt()) return kFALSE;
370 // Select events within angular window
372 eta[0] = parton1->Eta();
373 eta[1] = parton2->Eta();
375 phi[0] = parton1->Phi();
376 phi[1] = parton2->Phi();
378 pdg[0] = parton1->GetPdgCode();
379 pdg[1] = parton2->GetPdgCode();
380 printf("min %f, max %f\n",fPtHardMin, fPtHardMax);
381 printf("Parton 1: %s, pT= %2.2f, eta = %1.2f, phi = %2.2f\n", parton1->GetName(),parton1->Pt(), eta[0],phi[0]*TMath::RadToDeg());
382 printf("Parton 2: %s, pT= %2.2f, eta = %1.2f, phi = %2.2f\n", parton2->GetName(),parton2->Pt(), eta[1],phi[1]*TMath::RadToDeg());
384 if (fProcess == kHeJets) {
385 //Check if one of the 2 outgoing partons are in the eta-phi window
386 for(Int_t i = 0; i < 2; i++)
387 if ((eta[i] < fEtaMaxParton && eta[i] > fEtaMinParton) &&
388 (phi[i] < fPhiMaxParton && phi[i] > fPhiMinParton)) return kTRUE ;
392 //Check if the gamma and the jet are in the eta-phi window
395 if(pdg[0] == 22) ijj=1;
397 if ((eta[ijj] < fEtaMaxParton && eta[ijj] > fEtaMinParton) &&
398 (phi[ijj] < fPhiMaxParton && phi[ijj] > fPhiMinParton)) {
400 if ((eta[igj] < fEtaMaxGamma && eta[igj] > fEtaMinGamma) &&
401 (phi[igj] < fPhiMaxGamma && phi[igj] > fPhiMinGamma)) return kTRUE;
409 void AliGenHerwig::AdjustWeights()
411 // Adjust the weights after generation of all events
413 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
414 for (Int_t i=0; i<ntrack; i++) {
415 part= gAlice->GetMCApp()->Particle(i);
416 part->SetWeight(part->GetWeight()*fKineBias);
421 void AliGenHerwig::KeepFullEvent()
426 Bool_t AliGenHerwig::DaughtersSelection(const TParticle* iparticle, const TClonesArray* particles)
429 // Looks recursively if one of the daughters has been selected
431 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
435 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
436 Bool_t selected=kFALSE;
438 imin=iparticle->GetFirstDaughter();
439 imax=iparticle->GetLastDaughter();
440 for (i=imin; i<= imax; i++){
441 TParticle * jparticle = (TParticle *) particles->At(i);
442 Int_t ip=jparticle->GetPdgCode();
443 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
444 selected=kTRUE; break;
446 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
456 Bool_t AliGenHerwig::SelectFlavor(Int_t pid) const
458 // Select flavor of particle
460 // 4: charm and beauty
462 if (fFlavor == 0) return kTRUE;
464 Int_t ifl=TMath::Abs(pid/100);
465 if (ifl > 10) ifl/=10;
466 return (fFlavor == ifl);
469 Bool_t AliGenHerwig::Stable(const TParticle* particle) const
471 // Return true for a stable particle
473 Int_t kf = TMath::Abs(particle->GetPdgCode());
475 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
484 void AliGenHerwig::FinishRun()
489 void AliGenHerwig::FinishRunJimmy()
497 void AliGenHerwig::MakeHeader()
500 // Make header for the simulated event
502 if (fHeader) delete fHeader;
503 fHeader = new AliGenHerwigEventHeader("Herwig");
506 ((AliGenHerwigEventHeader*) fHeader)->SetProcessType(fHerwig->GetIHPRO());
509 ((AliGenHerwigEventHeader*) fHeader)->SetTrials(fTrials);
511 // Event weight (cross section)
512 ((AliGenHerwigEventHeader*) fHeader)->SetWeight(fHerwig->GetEVWGT());
515 fHeader->SetPrimaryVertex(fVertex);
516 fHeader->SetInteractionTime(fTime);
518 // Number of primaries
519 fHeader->SetNProduced(fNprimaries);