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"
26 #include <TParticle.h>
29 #include "Riostream.h"
31 ClassImp(AliGenHerwig)
33 static TRandom * sRandom;
35 AliGenHerwig::AliGenHerwig()
40 AliGenHerwig::AliGenHerwig(Int_t npart)
46 SetStrucFunc(kGRVLO98);
58 if (!sRandom) sRandom=fRandom;
61 AliGenHerwig::AliGenHerwig(const AliGenHerwig & Herwig)
69 AliGenHerwig::~AliGenHerwig()
74 void AliGenHerwig::Init()
78 fProjectile.Resize(8);
79 SetMC(new THerwig6());
80 fHerwig=(THerwig6*) fMCEvGen;
81 // initialize common blocks
82 fHerwig->Initialize(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
83 // reset parameters according to user needs
85 fHerwig->SetPTMIN(fPtHardMin);
86 fHerwig->SetPTRMS(fPtRMS);
87 fHerwig->SetMAXPR(fMaxPr);
88 fHerwig->SetMAXER(fMaxErrors);
89 fHerwig->SetENSOF(fEnSoft);
90 // compute parameter dependent constants
91 fHerwig->PrepareRun();
94 void AliGenHerwig::InitPDF()
135 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
139 fHerwig->SetMODPDF(1,fModPDF);
140 fHerwig->SetMODPDF(2,fModPDF);
141 fHerwig->SetAUTPDF(1,fAutPDF);
142 fHerwig->SetAUTPDF(2,fAutPDF);
145 void AliGenHerwig::Generate()
147 // Generate one event
149 Float_t polar[3] = {0,0,0};
150 Float_t origin[3]= {0,0,0};
151 Float_t origin0[3]= {0,0,0};
152 Float_t p[4], random[6];
154 static TClonesArray *particles;
155 // converts from mm/c to s
156 const Float_t kconv=0.001/2.999792458e8;
160 Int_t j, kf, ks, imo;
163 if(!particles) particles=new TClonesArray("TParticle",10000);
166 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
167 if(fVertexSmear==kPerEvent) {
170 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
171 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
177 fHerwig->GenerateEvent();
179 fHerwig->ImportParticles(particles,"All");
180 Int_t np = particles->GetEntriesFast()-1;
181 if (np == 0 ) continue;
185 Int_t * newPos = new Int_t[np];
186 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
188 for (Int_t i = 0; i<np; i++) {
189 TParticle * iparticle = (TParticle *) particles->At(i);
190 imo = iparticle->GetFirstMother();
191 kf = iparticle->GetPdgCode();
192 ks = iparticle->GetStatusCode();
194 KinematicSelection(iparticle,0))
197 p[0]=iparticle->Px();
198 p[1]=iparticle->Py();
199 p[2]=iparticle->Pz();
200 p[3]=iparticle->Energy();
201 origin[0]=origin0[0]+iparticle->Vx()/10;
202 origin[1]=origin0[1]+iparticle->Vy()/10;
203 origin[2]=origin0[2]+iparticle->Vz()/10;
204 Float_t tof = kconv*iparticle->T();
205 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
206 Int_t trackIt = (ks == 1) && fTrackIt;
207 gAlice->PushTrack(trackIt, iparent, kf,
208 p[0], p[1], p[2], p[3],
209 origin[0], origin[1], origin[2],
211 polar[0], polar[1], polar[2],
212 kPPrimary, nt, 1., ks);
215 } // end of if: selection of particle
216 } // end of for: particle loop
217 if (newPos) delete[] newPos;
218 printf("\n I've put %i particles on the stack \n",nc);
220 printf("nc: %d %d\n", nc, fNpart);
224 if (jev >= fNpart || fNpart == -1) {
225 fKineBias=Float_t(fNpart)/Float_t(fTrials);
226 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
231 SetHighWaterMark(nt);
232 // adjust weight due to kinematic selection
235 fXsection=fHerwig->GetAVWGT();
238 void AliGenHerwig::AdjustWeights()
240 // Adjust the weights after generation of all events
242 Int_t ntrack=gAlice->GetNtrack();
243 for (Int_t i=0; i<ntrack; i++) {
244 part= gAlice->Particle(i);
245 part->SetWeight(part->GetWeight()*fKineBias);
250 void AliGenHerwig::KeepFullEvent()
255 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
258 // Looks recursively if one of the daughters has been selected
260 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
264 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
265 Bool_t selected=kFALSE;
267 imin=iparticle->GetFirstDaughter();
268 imax=iparticle->GetLastDaughter();
269 for (i=imin; i<= imax; i++){
270 TParticle * jparticle = (TParticle *) particles->At(i);
271 Int_t ip=jparticle->GetPdgCode();
272 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
273 selected=kTRUE; break;
275 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
285 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
287 // Select flavor of particle
289 // 4: charm and beauty
291 if (fFlavor == 0) return kTRUE;
293 Int_t ifl=TMath::Abs(pid/100);
294 if (ifl > 10) ifl/=10;
295 return (fFlavor == ifl);
298 Bool_t AliGenHerwig::Stable(TParticle* particle)
300 // Return true for a stable particle
302 Int_t kf = TMath::Abs(particle->GetPdgCode());
304 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
313 void AliGenHerwig::FinishRun()
319 AliGenHerwig& AliGenHerwig::operator=(const AliGenHerwig& rhs)
321 // Assignment operator
328 Double_t hwr_() {return sRandom->Rndm();}