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 "AliGenHerwigEventHeader.h"
32 #include "AliHerwigRndm.h"
37 ClassImp(AliGenHerwig)
40 AliGenHerwig::AliGenHerwig() :
69 fPhiMaxParton(2.* TMath::Pi()),
73 fPhiMaxGamma(2. * TMath::Pi()),
80 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::SetEventListRange(Int_t eventFirst, Int_t eventLast)
133 if ( fEv2Pr == -1 ) fEv2Pr = fEv1Pr;
136 void AliGenHerwig::Init()
140 fProjectile.Resize(8);
141 SetMC(new THerwig6());
142 fHerwig=(THerwig6*) fMCEvGen;
143 // initialize common blocks
144 fHerwig->Initialize(fProjectile.Data(), fTarget.Data(), fMomentum1, fMomentum2, fProcess); //
145 // reset parameters according to user needs
147 fHerwig->SetPTMIN(fPtHardMin);
148 fHerwig->SetPTMAX(fPtHardMax);
149 fHerwig->SetPTRMS(fPtRMS);
150 fHerwig->SetMAXPR(fMaxPr);
151 fHerwig->SetMAXER(fMaxErrors);
152 fHerwig->SetENSOF(fEnSoft);
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(), 49);
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 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
199 fHerwig->SetRMASS(4,1.2);
200 fHerwig->SetRMASS(5,4.75);
202 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(), 49);
204 // fHerwig->Hwusta("PI0 ");
206 // compute parameter dependent constants
207 fHerwig->PrepareRunJimmy();
210 void AliGenHerwig::InitPDF()
215 // ONLY USES LHAPDF STRUCTURE FUNCTIONS
256 // case kMRST2004nlo:
258 // fAutPDF="HWLHAPDF";
261 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
265 fHerwig->SetMODPDF(1,fModPDF);
266 fHerwig->SetMODPDF(2,fModPDF);
267 fHerwig->SetAUTPDF(1,fAutPDF);
268 fHerwig->SetAUTPDF(2,fAutPDF);
271 void AliGenHerwig::Generate()
273 // Generate one event
275 Float_t polar[3] = {0,0,0};
276 Float_t origin[3] = {0,0,0};
279 static TClonesArray *particles;
280 // converts from mm/c to s
281 const Float_t kconv=0.001/2.999792458e8;
288 if(!particles) particles=new TClonesArray("TParticle",10000);
292 // Set collision vertex position
293 if (fVertexSmear == kPerEvent) Vertex();
297 fHerwig->GenerateEvent();
299 fHerwig->ImportParticles(particles,"All");
300 Int_t np = particles->GetEntriesFast()-1;
301 if (np == 0 ) continue;
303 //Check hard partons or direct gamma in kine range
305 if (fProcess == kHeJets || fProcess == kHeDirectGamma) {
306 TParticle* parton1 = (TParticle *) particles->At(6);
307 TParticle* parton2 = (TParticle *) particles->At(7);
308 if (!CheckParton(parton1, parton2)) continue ;
313 if (gAlice->GetEvNumber()>=fEv1Pr &&
314 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();
339 origin[0] = fVertex[0] + iparticle->Vx()/10; // [cm]
340 origin[1] = fVertex[1] + iparticle->Vy()/10; // [cm]
341 origin[2] = fVertex[2] + iparticle->Vz()/10; // [cm]
343 Float_t tof = kconv*iparticle->T();
344 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
345 Int_t trackIt = (ks == 1) && fTrackIt;
346 PushTrack(trackIt, iparent, kf,
347 p[0], p[1], p[2], p[3],
348 origin[0], origin[1], origin[2],
350 polar[0], polar[1], polar[2],
351 kPPrimary, nt, fHerwig->GetEVWGT(), ks);
355 } // end of if: selection of particle
356 } // end of for: particle loop
357 if (newPos) delete[] newPos;
360 if (jev >= fNpart || fNpart == -1) {
361 fKineBias=Float_t(fNpart)/Float_t(fTrials);
369 SetHighWaterMark(nt);
370 // adjust weight due to kinematic selection
373 fXsection=fHerwig->GetAVWGT();
374 //printf(">> trials << %d\n",fTrials);
377 Bool_t AliGenHerwig::CheckParton(const TParticle* parton1, const TParticle* parton2)
379 // Check the kinematic trigger condition
381 //Select events with parton max energy
382 if(fPtHardMax < parton1->Pt()) return kFALSE;
384 // Select events within angular window
386 eta[0] = parton1->Eta();
387 eta[1] = parton2->Eta();
389 phi[0] = parton1->Phi();
390 phi[1] = parton2->Phi();
392 pdg[0] = parton1->GetPdgCode();
393 pdg[1] = parton2->GetPdgCode();
394 printf("min %f, max %f\n",fPtHardMin, fPtHardMax);
395 printf("Parton 1: %s, pT= %2.2f, eta = %1.2f, phi = %2.2f\n", parton1->GetName(),parton1->Pt(), eta[0],phi[0]*TMath::RadToDeg());
396 printf("Parton 2: %s, pT= %2.2f, eta = %1.2f, phi = %2.2f\n", parton2->GetName(),parton2->Pt(), eta[1],phi[1]*TMath::RadToDeg());
398 if (fProcess == kHeJets) {
399 //Check if one of the 2 outgoing partons are in the eta-phi window
400 for(Int_t i = 0; i < 2; i++)
401 if ((eta[i] < fEtaMaxParton && eta[i] > fEtaMinParton) &&
402 (phi[i] < fPhiMaxParton && phi[i] > fPhiMinParton)) return kTRUE ;
406 //Check if the gamma and the jet are in the eta-phi window
409 if(pdg[0] == 22) ijj=1;
411 if ((eta[ijj] < fEtaMaxParton && eta[ijj] > fEtaMinParton) &&
412 (phi[ijj] < fPhiMaxParton && phi[ijj] > fPhiMinParton)) {
414 if ((eta[igj] < fEtaMaxGamma && eta[igj] > fEtaMinGamma) &&
415 (phi[igj] < fPhiMaxGamma && phi[igj] > fPhiMinGamma)) return kTRUE;
423 void AliGenHerwig::AdjustWeights()
425 // Adjust the weights after generation of all events
427 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
428 for (Int_t i=0; i<ntrack; i++) {
429 part= gAlice->GetMCApp()->Particle(i);
430 part->SetWeight(part->GetWeight()*fKineBias);
435 void AliGenHerwig::KeepFullEvent()
440 Bool_t AliGenHerwig::DaughtersSelection(const TParticle* iparticle, const TClonesArray* particles)
443 // Looks recursively if one of the daughters has been selected
445 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
449 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
450 Bool_t selected=kFALSE;
452 imin=iparticle->GetFirstDaughter();
453 imax=iparticle->GetLastDaughter();
454 for (i=imin; i<= imax; i++){
455 TParticle * jparticle = (TParticle *) particles->At(i);
456 Int_t ip=jparticle->GetPdgCode();
457 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
458 selected=kTRUE; break;
460 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
470 Bool_t AliGenHerwig::SelectFlavor(Int_t pid) const
472 // Select flavor of particle
474 // 4: charm and beauty
476 if (fFlavor == 0) return kTRUE;
478 Int_t ifl=TMath::Abs(pid/100);
479 if (ifl > 10) ifl/=10;
480 return (fFlavor == ifl);
483 Bool_t AliGenHerwig::Stable(const TParticle* particle) const
485 // Return true for a stable particle
487 Int_t kf = TMath::Abs(particle->GetPdgCode());
489 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
498 void AliGenHerwig::FinishRun()
503 void AliGenHerwig::FinishRunJimmy()
511 void AliGenHerwig::MakeHeader()
514 // Make header for the simulated event
516 if (fHeader) delete fHeader;
517 fHeader = new AliGenHerwigEventHeader("Herwig");
520 ((AliGenHerwigEventHeader*) fHeader)->SetProcessType(fHerwig->GetIHPRO());
523 ((AliGenHerwigEventHeader*) fHeader)->SetTrials(fTrials);
525 // Event weight (cross section)
526 ((AliGenHerwigEventHeader*) fHeader)->SetWeight(fHerwig->GetEVWGT());
529 fHeader->SetPrimaryVertex(fVertex);
532 // Number of primaries
533 fHeader->SetNProduced(fNprimaries);