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()),
119 // Set random number generator
120 AliHerwigRndm::SetHerwigRandom(GetRandom());
123 AliGenHerwig::~AliGenHerwig()
128 void AliGenHerwig::SetEventListRange(Int_t eventFirst, Int_t eventLast)
132 if ( fEv2Pr == -1 ) fEv2Pr = fEv2Pr;
135 void AliGenHerwig::Init()
139 fProjectile.Resize(8);
140 SetMC(new THerwig6());
141 fHerwig=(THerwig6*) fMCEvGen;
142 // initialize common blocks
143 fHerwig->Initialize(fProjectile.Data(), fTarget.Data(), fMomentum1, fMomentum2, fProcess); //
144 // reset parameters according to user needs
146 fHerwig->SetPTMIN(fPtHardMin);
147 fHerwig->SetPTMAX(fPtHardMax);
148 fHerwig->SetPTRMS(fPtRMS);
149 fHerwig->SetMAXPR(fMaxPr);
150 fHerwig->SetMAXER(fMaxErrors);
151 fHerwig->SetENSOF(fEnSoft);
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 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
198 fHerwig->SetRMASS(4,1.2);
199 fHerwig->SetRMASS(5,4.75);
201 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(),50);
203 // fHerwig->Hwusta("PI0 ");
205 // compute parameter dependent constants
206 fHerwig->PrepareRunJimmy();
209 void AliGenHerwig::InitPDF()
213 // ONLY USES LHAPDF STRUCTURE FUNCTIONS
254 // case kMRST2004nlo:
256 // fAutPDF="HWLHAPDF";
259 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
263 fHerwig->SetMODPDF(1,fModPDF);
264 fHerwig->SetMODPDF(2,fModPDF);
265 fHerwig->SetAUTPDF(1,fAutPDF);
266 fHerwig->SetAUTPDF(2,fAutPDF);
269 void AliGenHerwig::Generate()
271 // Generate one event
273 Float_t polar[3] = {0,0,0};
274 Float_t origin[3] = {0,0,0};
277 static TClonesArray *particles;
278 // converts from mm/c to s
279 const Float_t kconv=0.001/2.999792458e8;
286 if(!particles) particles=new TClonesArray("TParticle",10000);
290 // Set collision vertex position
291 if (fVertexSmear == kPerEvent) Vertex();
295 fHerwig->GenerateEvent();
297 fHerwig->ImportParticles(particles,"All");
298 Int_t np = particles->GetEntriesFast()-1;
299 if (np == 0 ) continue;
301 //Check hard partons or direct gamma in kine range
303 if (fProcess == kHeJets || fProcess == kHeDirectGamma) {
304 TParticle* parton1 = (TParticle *) particles->At(6);
305 TParticle* parton2 = (TParticle *) particles->At(7);
306 if (!CheckParton(parton1, parton2)) continue ;
311 if (gAlice->GetEvNumber()>=fEv1Pr &&
312 gAlice->GetEvNumber()<=fEv2Pr) fHerwig->PrintEvt();
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();
337 origin[0] = fVertex[0] + iparticle->Vx()/10; // [cm]
338 origin[1] = fVertex[1] + iparticle->Vy()/10; // [cm]
339 origin[2] = fVertex[2] + iparticle->Vz()/10; // [cm]
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);
353 } // end of if: selection of particle
354 } // end of for: particle loop
355 if (newPos) delete[] newPos;
358 if (jev >= fNpart || fNpart == -1) {
359 fKineBias=Float_t(fNpart)/Float_t(fTrials);
367 SetHighWaterMark(nt);
368 // adjust weight due to kinematic selection
371 fXsection=fHerwig->GetAVWGT();
372 //printf(">> trials << %d\n",fTrials);
375 Bool_t AliGenHerwig::CheckParton(TParticle* parton1, TParticle* parton2)
377 // Check the kinematic trigger condition
379 //Select events with parton max energy
380 if(fPtHardMax < parton1->Pt()) return kFALSE;
382 // Select events within angular window
384 eta[0] = parton1->Eta();
385 eta[1] = parton2->Eta();
387 phi[0] = parton1->Phi();
388 phi[1] = parton2->Phi();
390 pdg[0] = parton1->GetPdgCode();
391 pdg[1] = parton2->GetPdgCode();
392 printf("min %f, max %f\n",fPtHardMin, fPtHardMax);
393 printf("Parton 1: %s, pT= %2.2f, eta = %1.2f, phi = %2.2f\n", parton1->GetName(),parton1->Pt(), eta[0],phi[0]*TMath::RadToDeg());
394 printf("Parton 2: %s, pT= %2.2f, eta = %1.2f, phi = %2.2f\n", parton2->GetName(),parton2->Pt(), eta[1],phi[1]*TMath::RadToDeg());
396 if (fProcess == kHeJets) {
397 //Check if one of the 2 outgoing partons are in the eta-phi window
398 for(Int_t i = 0; i < 2; i++)
399 if ((eta[i] < fEtaMaxParton && eta[i] > fEtaMinParton) &&
400 (phi[i] < fPhiMaxParton && phi[i] > fPhiMinParton)) return kTRUE ;
404 //Check if the gamma and the jet are in the eta-phi window
407 if(pdg[0] == 22) ijj=1;
409 if ((eta[ijj] < fEtaMaxParton && eta[ijj] > fEtaMinParton) &&
410 (phi[ijj] < fPhiMaxParton && phi[ijj] > fPhiMinParton)) {
412 if ((eta[igj] < fEtaMaxGamma && eta[igj] > fEtaMinGamma) &&
413 (phi[igj] < fPhiMaxGamma && phi[igj] > fPhiMinGamma)) return kTRUE;
421 void AliGenHerwig::AdjustWeights()
423 // Adjust the weights after generation of all events
425 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
426 for (Int_t i=0; i<ntrack; i++) {
427 part= gAlice->GetMCApp()->Particle(i);
428 part->SetWeight(part->GetWeight()*fKineBias);
433 void AliGenHerwig::KeepFullEvent()
438 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
441 // Looks recursively if one of the daughters has been selected
443 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
447 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
448 Bool_t selected=kFALSE;
450 imin=iparticle->GetFirstDaughter();
451 imax=iparticle->GetLastDaughter();
452 for (i=imin; i<= imax; i++){
453 TParticle * jparticle = (TParticle *) particles->At(i);
454 Int_t ip=jparticle->GetPdgCode();
455 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
456 selected=kTRUE; break;
458 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
468 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
470 // Select flavor of particle
472 // 4: charm and beauty
474 if (fFlavor == 0) return kTRUE;
476 Int_t ifl=TMath::Abs(pid/100);
477 if (ifl > 10) ifl/=10;
478 return (fFlavor == ifl);
481 Bool_t AliGenHerwig::Stable(TParticle* particle)
483 // Return true for a stable particle
485 Int_t kf = TMath::Abs(particle->GetPdgCode());
487 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
496 void AliGenHerwig::FinishRun()
501 void AliGenHerwig::FinishRunJimmy()
509 void AliGenHerwig::MakeHeader()
512 // Make header for the simulated event
514 if (fHeader) delete fHeader;
515 fHeader = new AliGenHerwigEventHeader("Herwig");
518 ((AliGenHerwigEventHeader*) fHeader)->SetProcessType(fHerwig->GetIHPRO());
521 ((AliGenHerwigEventHeader*) fHeader)->SetTrials(fTrials);
524 fHeader->SetPrimaryVertex(fVertex);
527 // Number of primaries
528 fHeader->SetNProduced(fNprimaries);