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.
23 #include "AliGenHerwig.h"
24 #include "AliHerwigRndm.h"
27 #include <TParticle.h>
30 #include "Riostream.h"
35 ClassImp(AliGenHerwig)
38 AliGenHerwig::AliGenHerwig() :
68 AliGenHerwig::AliGenHerwig(Int_t npart)
97 // Set random number generator
98 AliHerwigRndm::SetHerwigRandom(GetRandom());
101 AliGenHerwig::~AliGenHerwig()
106 void AliGenHerwig::SetEventListRange(Int_t eventFirst, Int_t eventLast)
108 fEv1Pr = ++eventFirst;
109 fEv2Pr = ++eventLast;
110 if ( fEv2Pr == -1 ) fEv2Pr = fEv2Pr;
113 void AliGenHerwig::Init()
117 fProjectile.Resize(8);
118 SetMC(new THerwig6());
119 fHerwig=(THerwig6*) fMCEvGen;
120 // initialize common blocks
121 fHerwig->Initialize(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
122 // reset parameters according to user needs
124 fHerwig->SetPTMIN(fPtHardMin);
125 fHerwig->SetPTRMS(fPtRMS);
126 fHerwig->SetMAXPR(fMaxPr);
127 fHerwig->SetMAXER(fMaxErrors);
128 fHerwig->SetENSOF(fEnSoft);
130 fHerwig->SetEV1PR(fEv1Pr);
131 fHerwig->SetEV2PR(fEv2Pr);
133 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
142 fHerwig->SetRMASS(4,1.2);
143 fHerwig->SetRMASS(5,4.75);
145 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(),50);
147 fHerwig->Hwusta("PI0 ");
149 // compute parameter dependent constants
150 fHerwig->PrepareRun();
153 void AliGenHerwig::InitJimmy()
157 fProjectile.Resize(8);
158 SetMC(new THerwig6());
159 fHerwig=(THerwig6*) fMCEvGen;
160 // initialize common blocks
161 fHerwig->InitializeJimmy(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
162 // reset parameters according to user needs
164 fHerwig->SetPTMIN(fPtHardMin);
165 fHerwig->SetPTRMS(fPtRMS);
166 fHerwig->SetMAXPR(fMaxPr);
167 fHerwig->SetMAXER(fMaxErrors);
168 fHerwig->SetENSOF(fEnSoft);
170 fHerwig->SetEV1PR(fEv1Pr);
171 fHerwig->SetEV2PR(fEv2Pr);
173 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
182 fHerwig->SetRMASS(4,1.2);
183 fHerwig->SetRMASS(5,4.75);
185 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(),50);
187 fHerwig->Hwusta("PI0 ");
189 // compute parameter dependent constants
190 fHerwig->PrepareRunJimmy();
193 void AliGenHerwig::InitPDF()
197 // ONLY USES LHAPDF STRUCTURE FUNCTIONS
238 // case kMRST2004nlo:
240 // fAutPDF="HWLHAPDF";
243 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
247 fHerwig->SetMODPDF(1,fModPDF);
248 fHerwig->SetMODPDF(2,fModPDF);
249 fHerwig->SetAUTPDF(1,fAutPDF);
250 fHerwig->SetAUTPDF(2,fAutPDF);
253 void AliGenHerwig::Generate()
255 // Generate one event
257 Float_t polar[3] = {0,0,0};
258 Float_t origin[3]= {0,0,0};
259 Float_t origin0[3]= {0,0,0};
260 Float_t p[4], random[6];
262 static TClonesArray *particles;
263 // converts from mm/c to s
264 const Float_t kconv=0.001/2.999792458e8;
268 Int_t j, kf, ks, imo;
271 if(!particles) particles=new TClonesArray("TParticle",10000);
274 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
275 if(fVertexSmear==kPerEvent) {
278 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
279 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
285 fHerwig->GenerateEvent();
287 fHerwig->ImportParticles(particles,"All");
288 Int_t np = particles->GetEntriesFast()-1;
289 if (np == 0 ) continue;
293 Int_t * newPos = new Int_t[np];
294 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
296 for (Int_t i = 0; i<np; i++) {
297 TParticle * iparticle = (TParticle *) particles->At(i);
298 imo = iparticle->GetFirstMother();
299 kf = iparticle->GetPdgCode();
300 ks = iparticle->GetStatusCode();
302 KinematicSelection(iparticle,0))
305 p[0]=iparticle->Px();
306 p[1]=iparticle->Py();
307 p[2]=iparticle->Pz();
308 p[3]=iparticle->Energy();
309 origin[0]=origin0[0]+iparticle->Vx()/10;
310 origin[1]=origin0[1]+iparticle->Vy()/10;
311 origin[2]=origin0[2]+iparticle->Vz()/10;
312 Float_t tof = kconv*iparticle->T();
313 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
314 Int_t trackIt = (ks == 1) && fTrackIt;
315 PushTrack(trackIt, iparent, kf,
316 p[0], p[1], p[2], p[3],
317 origin[0], origin[1], origin[2],
319 polar[0], polar[1], polar[2],
320 kPPrimary, nt, fHerwig->GetEVWGT(), ks);
323 } // end of if: selection of particle
324 } // end of for: particle loop
325 if (newPos) delete[] newPos;
329 if (jev >= fNpart || fNpart == -1) {
330 fKineBias=Float_t(fNpart)/Float_t(fTrials);
335 SetHighWaterMark(nt);
336 // adjust weight due to kinematic selection
339 fXsection=fHerwig->GetAVWGT();
342 void AliGenHerwig::AdjustWeights()
344 // Adjust the weights after generation of all events
346 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
347 for (Int_t i=0; i<ntrack; i++) {
348 part= gAlice->GetMCApp()->Particle(i);
349 part->SetWeight(part->GetWeight()*fKineBias);
354 void AliGenHerwig::KeepFullEvent()
359 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
362 // Looks recursively if one of the daughters has been selected
364 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
368 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
369 Bool_t selected=kFALSE;
371 imin=iparticle->GetFirstDaughter();
372 imax=iparticle->GetLastDaughter();
373 for (i=imin; i<= imax; i++){
374 TParticle * jparticle = (TParticle *) particles->At(i);
375 Int_t ip=jparticle->GetPdgCode();
376 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
377 selected=kTRUE; break;
379 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
389 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
391 // Select flavor of particle
393 // 4: charm and beauty
395 if (fFlavor == 0) return kTRUE;
397 Int_t ifl=TMath::Abs(pid/100);
398 if (ifl > 10) ifl/=10;
399 return (fFlavor == ifl);
402 Bool_t AliGenHerwig::Stable(TParticle* particle)
404 // Return true for a stable particle
406 Int_t kf = TMath::Abs(particle->GetPdgCode());
408 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
417 void AliGenHerwig::FinishRun()
422 void AliGenHerwig::FinishRunJimmy()