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() :
69 AliGenHerwig::AliGenHerwig(Int_t npart)
98 // Set random number generator
99 AliHerwigRndm::SetHerwigRandom(GetRandom());
102 AliGenHerwig::~AliGenHerwig()
107 void AliGenHerwig::SetEventListRange(Int_t eventFirst, Int_t eventLast)
109 fEv1Pr = ++eventFirst;
110 fEv2Pr = ++eventLast;
111 if ( fEv2Pr == -1 ) fEv2Pr = fEv2Pr;
114 void AliGenHerwig::Init()
118 fProjectile.Resize(8);
119 SetMC(new THerwig6());
120 fHerwig=(THerwig6*) fMCEvGen;
121 // initialize common blocks
122 fHerwig->Initialize(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
123 // reset parameters according to user needs
125 fHerwig->SetPTMIN(fPtHardMin);
126 fHerwig->SetPTRMS(fPtRMS);
127 fHerwig->SetMAXPR(fMaxPr);
128 fHerwig->SetMAXER(fMaxErrors);
129 fHerwig->SetENSOF(fEnSoft);
131 fHerwig->SetEV1PR(fEv1Pr);
132 fHerwig->SetEV2PR(fEv2Pr);
134 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
143 fHerwig->SetRMASS(4,1.2);
144 fHerwig->SetRMASS(5,4.75);
146 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(),50);
148 fHerwig->Hwusta("PI0 ");
150 // compute parameter dependent constants
151 fHerwig->PrepareRun();
154 void AliGenHerwig::InitJimmy()
158 fProjectile.Resize(8);
159 SetMC(new THerwig6());
160 fHerwig=(THerwig6*) fMCEvGen;
161 // initialize common blocks
162 fHerwig->InitializeJimmy(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
163 // reset parameters according to user needs
165 fHerwig->SetPTMIN(fPtHardMin);
166 fHerwig->SetPTRMS(fPtRMS);
167 fHerwig->SetMAXPR(fMaxPr);
168 fHerwig->SetMAXER(fMaxErrors);
169 fHerwig->SetENSOF(fEnSoft);
171 fHerwig->SetEV1PR(fEv1Pr);
172 fHerwig->SetEV2PR(fEv2Pr);
174 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
183 fHerwig->SetRMASS(4,1.2);
184 fHerwig->SetRMASS(5,4.75);
186 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(),50);
188 fHerwig->Hwusta("PI0 ");
190 // compute parameter dependent constants
191 fHerwig->PrepareRunJimmy();
194 void AliGenHerwig::InitPDF()
198 // ONLY USES LHAPDF STRUCTURE FUNCTIONS
239 // case kMRST2004nlo:
241 // fAutPDF="HWLHAPDF";
244 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
248 fHerwig->SetMODPDF(1,fModPDF);
249 fHerwig->SetMODPDF(2,fModPDF);
250 fHerwig->SetAUTPDF(1,fAutPDF);
251 fHerwig->SetAUTPDF(2,fAutPDF);
254 void AliGenHerwig::Generate()
256 // Generate one event
258 Float_t polar[3] = {0,0,0};
259 Float_t origin[3]= {0,0,0};
260 Float_t origin0[3]= {0,0,0};
261 Float_t p[4], random[6];
263 static TClonesArray *particles;
264 // converts from mm/c to s
265 const Float_t kconv=0.001/2.999792458e8;
269 Int_t j, kf, ks, imo;
272 if(!particles) particles=new TClonesArray("TParticle",10000);
275 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
276 if(fVertexSmear==kPerEvent) {
279 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
280 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
286 fHerwig->GenerateEvent();
288 fHerwig->ImportParticles(particles,"All");
289 Int_t np = particles->GetEntriesFast()-1;
290 if (np == 0 ) continue;
294 Int_t * newPos = new Int_t[np];
295 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
297 for (Int_t i = 0; i<np; i++) {
298 TParticle * iparticle = (TParticle *) particles->At(i);
299 imo = iparticle->GetFirstMother();
300 kf = iparticle->GetPdgCode();
301 ks = iparticle->GetStatusCode();
303 KinematicSelection(iparticle,0))
306 p[0]=iparticle->Px();
307 p[1]=iparticle->Py();
308 p[2]=iparticle->Pz();
309 p[3]=iparticle->Energy();
310 origin[0]=origin0[0]+iparticle->Vx()/10;
311 origin[1]=origin0[1]+iparticle->Vy()/10;
312 origin[2]=origin0[2]+iparticle->Vz()/10;
313 Float_t tof = kconv*iparticle->T();
314 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
315 Int_t trackIt = (ks == 1) && fTrackIt;
316 PushTrack(trackIt, iparent, kf,
317 p[0], p[1], p[2], p[3],
318 origin[0], origin[1], origin[2],
320 polar[0], polar[1], polar[2],
321 kPPrimary, nt, fHerwig->GetEVWGT(), ks);
324 } // end of if: selection of particle
325 } // end of for: particle loop
326 if (newPos) delete[] newPos;
330 if (jev >= fNpart || fNpart == -1) {
331 fKineBias=Float_t(fNpart)/Float_t(fTrials);
336 SetHighWaterMark(nt);
337 // adjust weight due to kinematic selection
340 fXsection=fHerwig->GetAVWGT();
343 void AliGenHerwig::AdjustWeights()
345 // Adjust the weights after generation of all events
347 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
348 for (Int_t i=0; i<ntrack; i++) {
349 part= gAlice->GetMCApp()->Particle(i);
350 part->SetWeight(part->GetWeight()*fKineBias);
355 void AliGenHerwig::KeepFullEvent()
360 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
363 // Looks recursively if one of the daughters has been selected
365 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
369 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
370 Bool_t selected=kFALSE;
372 imin=iparticle->GetFirstDaughter();
373 imax=iparticle->GetLastDaughter();
374 for (i=imin; i<= imax; i++){
375 TParticle * jparticle = (TParticle *) particles->At(i);
376 Int_t ip=jparticle->GetPdgCode();
377 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
378 selected=kTRUE; break;
380 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
390 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
392 // Select flavor of particle
394 // 4: charm and beauty
396 if (fFlavor == 0) return kTRUE;
398 Int_t ifl=TMath::Abs(pid/100);
399 if (ifl > 10) ifl/=10;
400 return (fFlavor == ifl);
403 Bool_t AliGenHerwig::Stable(TParticle* particle)
405 // Return true for a stable particle
407 Int_t kf = TMath::Abs(particle->GetPdgCode());
409 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
418 void AliGenHerwig::FinishRun()
423 void AliGenHerwig::FinishRunJimmy()