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)
67 AliGenHerwig::~AliGenHerwig()
72 void AliGenHerwig::Init()
76 fProjectile.Resize(8);
77 SetMC(new THerwig6());
78 fHerwig=(THerwig6*) fgMCEvGen;
79 // initialize common blocks
80 fHerwig->Initialize(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
81 // reset parameters according to user needs
83 fHerwig->SetPTMIN(fPtHardMin);
84 fHerwig->SetPTRMS(fPtRMS);
85 fHerwig->SetMAXPR(fMaxPr);
86 fHerwig->SetMAXER(fMaxErrors);
87 fHerwig->SetENSOF(fEnSoft);
88 // compute parameter dependent constants
89 fHerwig->PrepareRun();
92 void AliGenHerwig::InitPDF()
133 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
137 fHerwig->SetMODPDF(1,fModPDF);
138 fHerwig->SetMODPDF(2,fModPDF);
139 fHerwig->SetAUTPDF(1,fAutPDF);
140 fHerwig->SetAUTPDF(2,fAutPDF);
143 void AliGenHerwig::Generate()
145 // Generate one event
147 Float_t polar[3] = {0,0,0};
148 Float_t origin[3]= {0,0,0};
149 Float_t origin0[3]= {0,0,0};
150 Float_t p[4], random[6];
152 static TClonesArray *particles;
153 // converts from mm/c to s
154 const Float_t kconv=0.001/2.999792458e8;
158 Int_t j, kf, ks, imo;
161 if(!particles) particles=new TClonesArray("TParticle",10000);
164 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
165 if(fVertexSmear==kPerEvent) {
168 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
169 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
175 fHerwig->GenerateEvent();
177 fHerwig->ImportParticles(particles,"All");
178 Int_t np = particles->GetEntriesFast()-1;
179 if (np == 0 ) continue;
183 Int_t * newPos = new Int_t[np];
184 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
186 for (Int_t i = 0; i<np; i++) {
187 TParticle * iparticle = (TParticle *) particles->At(i);
188 imo = iparticle->GetFirstMother();
189 kf = iparticle->GetPdgCode();
190 ks = iparticle->GetStatusCode();
192 KinematicSelection(iparticle,0))
195 p[0]=iparticle->Px();
196 p[1]=iparticle->Py();
197 p[2]=iparticle->Pz();
198 p[3]=iparticle->Energy();
199 origin[0]=origin0[0]+iparticle->Vx()/10;
200 origin[1]=origin0[1]+iparticle->Vy()/10;
201 origin[2]=origin0[2]+iparticle->Vz()/10;
202 Float_t tof = kconv*iparticle->T();
203 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
204 Int_t trackIt = (ks == 1) && fTrackIt;
205 gAlice->PushTrack(trackIt, iparent, kf,
206 p[0], p[1], p[2], p[3],
207 origin[0], origin[1], origin[2],
209 polar[0], polar[1], polar[2],
210 kPPrimary, nt, 1., ks);
213 } // end of if: selection of particle
214 } // end of for: particle loop
215 if (newPos) delete[] newPos;
216 printf("\n I've put %i particles on the stack \n",nc);
218 printf("nc: %d %d\n", nc, fNpart);
222 if (jev >= fNpart || fNpart == -1) {
223 fKineBias=Float_t(fNpart)/Float_t(fTrials);
224 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
229 SetHighWaterMark(nt);
230 // adjust weight due to kinematic selection
233 fXsection=fHerwig->GetAVWGT();
236 void AliGenHerwig::AdjustWeights()
238 // Adjust the weights after generation of all events
240 Int_t ntrack=gAlice->GetNtrack();
241 for (Int_t i=0; i<ntrack; i++) {
242 part= gAlice->Particle(i);
243 part->SetWeight(part->GetWeight()*fKineBias);
248 void AliGenHerwig::KeepFullEvent()
253 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
256 // Looks recursively if one of the daughters has been selected
258 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
262 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
263 Bool_t selected=kFALSE;
265 imin=iparticle->GetFirstDaughter();
266 imax=iparticle->GetLastDaughter();
267 for (i=imin; i<= imax; i++){
268 TParticle * jparticle = (TParticle *) particles->At(i);
269 Int_t ip=jparticle->GetPdgCode();
270 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
271 selected=kTRUE; break;
273 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
283 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
285 // Select flavor of particle
287 // 4: charm and beauty
289 if (fFlavor == 0) return kTRUE;
291 Int_t ifl=TMath::Abs(pid/100);
292 if (ifl > 10) ifl/=10;
293 return (fFlavor == ifl);
296 Bool_t AliGenHerwig::Stable(TParticle* particle)
298 // Return true for a stable particle
300 Int_t kf = TMath::Abs(particle->GetPdgCode());
302 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
311 void AliGenHerwig::FinishRun()
317 AliGenHerwig& AliGenHerwig::operator=(const AliGenHerwig& rhs)
319 // Assignment operator
325 Double_t hwr_() {return sRandom->Rndm();}