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 **************************************************************************/
18 Revision 1.4 2002/10/14 14:55:35 hristov
19 Merging the VirtualMC branch to the main development branch (HEAD)
21 Revision 1.2.2.3 2002/10/11 10:40:46 hristov
24 Revision 1.2.2.2 2002/07/26 18:34:02 alibrary
27 Revision 1.3 2002/07/26 15:32:24 hristov
28 stream.h doesn't exest on Sun, removed from includes
30 Revision 1.2 2002/07/19 11:43:10 morsch
32 - Use SetTrack passing energy.
34 Revision 1.1 2002/07/16 11:33:26 morsch
41 // Generator using Herwig as an external generator
42 // The main Herwig options are accessable for the user through this interface.
43 // Uses the THerwig implementation of TGenerator.
45 #include "AliGenHerwig.h"
48 #include <TParticle.h>
51 #include "Riostream.h"
53 ClassImp(AliGenHerwig)
55 AliGenHerwig::AliGenHerwig()
60 AliGenHerwig::AliGenHerwig(Int_t npart)
66 SetStrucFunc(kGRVLO98);
78 if (!sRandom) sRandom=fRandom;
81 AliGenHerwig::AliGenHerwig(const AliGenHerwig & Herwig)
87 AliGenHerwig::~AliGenHerwig()
92 void AliGenHerwig::Init()
96 fProjectile.Resize(8);
97 SetMC(new THerwig6());
98 fHerwig=(THerwig6*) fgMCEvGen;
99 // initialize common blocks
100 fHerwig->Initialize(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
101 // reset parameters according to user needs
103 fHerwig->SetPTMIN(fPtHardMin);
104 fHerwig->SetPTRMS(fPtRMS);
105 fHerwig->SetMAXPR(fMaxPr);
106 fHerwig->SetMAXER(fMaxErrors);
107 fHerwig->SetENSOF(fEnSoft);
108 // compute parameter dependent constants
109 fHerwig->PrepareRun();
112 void AliGenHerwig::InitPDF()
153 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
157 fHerwig->SetMODPDF(1,fModPDF);
158 fHerwig->SetMODPDF(2,fModPDF);
159 fHerwig->SetAUTPDF(1,fAutPDF);
160 fHerwig->SetAUTPDF(2,fAutPDF);
163 void AliGenHerwig::Generate()
165 // Generate one event
167 Float_t polar[3] = {0,0,0};
168 Float_t origin[3]= {0,0,0};
169 Float_t origin0[3]= {0,0,0};
170 Float_t p[4], random[6];
172 static TClonesArray *particles;
173 // converts from mm/c to s
174 const Float_t kconv=0.001/2.999792458e8;
178 Int_t j, kf, ks, imo;
181 if(!particles) particles=new TClonesArray("TParticle",10000);
184 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
185 if(fVertexSmear==kPerEvent) {
188 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
189 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
195 fHerwig->GenerateEvent();
197 fHerwig->ImportParticles(particles,"All");
198 Int_t np = particles->GetEntriesFast()-1;
199 if (np == 0 ) continue;
203 Int_t * newPos = new Int_t[np];
204 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
206 for (Int_t i = 0; i<np; i++) {
207 TParticle * iparticle = (TParticle *) particles->At(i);
208 imo = iparticle->GetFirstMother();
209 kf = iparticle->GetPdgCode();
210 ks = iparticle->GetStatusCode();
212 KinematicSelection(iparticle,0))
215 p[0]=iparticle->Px();
216 p[1]=iparticle->Py();
217 p[2]=iparticle->Pz();
218 p[3]=iparticle->Energy();
219 origin[0]=origin0[0]+iparticle->Vx()/10;
220 origin[1]=origin0[1]+iparticle->Vy()/10;
221 origin[2]=origin0[2]+iparticle->Vz()/10;
222 Float_t tof = kconv*iparticle->T();
223 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
224 Int_t trackIt = (ks == 1) && fTrackIt;
225 gAlice->SetTrack(trackIt, iparent, kf,
226 p[0], p[1], p[2], p[3],
227 origin[0], origin[1], origin[2],
229 polar[0], polar[1], polar[2],
230 kPPrimary, nt, 1., ks);
233 } // end of if: selection of particle
234 } // end of for: particle loop
235 if (newPos) delete[] newPos;
236 printf("\n I've put %i particles on the stack \n",nc);
238 printf("nc: %d %d\n", nc, fNpart);
242 if (jev >= fNpart || fNpart == -1) {
243 fKineBias=Float_t(fNpart)/Float_t(fTrials);
244 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
249 SetHighWaterMark(nt);
250 // adjust weight due to kinematic selection
253 fXsection=fHerwig->GetAVWGT();
256 void AliGenHerwig::AdjustWeights()
258 // Adjust the weights after generation of all events
260 Int_t ntrack=gAlice->GetNtrack();
261 for (Int_t i=0; i<ntrack; i++) {
262 part= gAlice->Particle(i);
263 part->SetWeight(part->GetWeight()*fKineBias);
268 void AliGenHerwig::KeepFullEvent()
273 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
276 // Looks recursively if one of the daughters has been selected
278 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
282 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
283 Bool_t selected=kFALSE;
285 imin=iparticle->GetFirstDaughter();
286 imax=iparticle->GetLastDaughter();
287 for (i=imin; i<= imax; i++){
288 TParticle * jparticle = (TParticle *) particles->At(i);
289 Int_t ip=jparticle->GetPdgCode();
290 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
291 selected=kTRUE; break;
293 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
303 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
305 // Select flavor of particle
307 // 4: charm and beauty
309 if (fFlavor == 0) return kTRUE;
311 Int_t ifl=TMath::Abs(pid/100);
312 if (ifl > 10) ifl/=10;
313 return (fFlavor == ifl);
316 Bool_t AliGenHerwig::Stable(TParticle* particle)
318 // Return true for a stable particle
320 Int_t kf = TMath::Abs(particle->GetPdgCode());
322 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
331 void AliGenHerwig::FinishRun()
337 AliGenHerwig& AliGenHerwig::operator=(const AliGenHerwig& rhs)
339 // Assignment operator
345 Double_t hwr_() {return sRandom->Rndm();}