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.1 2002/07/16 11:33:26 morsch
25 // Generator using Herwig as an external generator
26 // The main Herwig options are accessable for the user through this interface.
27 // Uses the THerwig implementation of TGenerator.
30 #include "AliGenHerwig.h"
33 #include <TParticle.h>
37 ClassImp(AliGenHerwig)
39 AliGenHerwig::AliGenHerwig()
44 AliGenHerwig::AliGenHerwig(Int_t npart)
50 SetStrucFunc(kGRVLO98);
62 if (!sRandom) sRandom=fRandom;
65 AliGenHerwig::AliGenHerwig(const AliGenHerwig & Herwig)
71 AliGenHerwig::~AliGenHerwig()
76 void AliGenHerwig::Init()
80 fProjectile.Resize(8);
81 SetMC(new THerwig6());
82 fHerwig=(THerwig6*) fgMCEvGen;
83 // initialize common blocks
84 fHerwig->Initialize(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
85 // reset parameters according to user needs
87 fHerwig->SetPTMIN(fPtHardMin);
88 fHerwig->SetPTRMS(fPtRMS);
89 fHerwig->SetMAXPR(fMaxPr);
90 fHerwig->SetMAXER(fMaxErrors);
91 fHerwig->SetENSOF(fEnSoft);
92 // compute parameter dependent constants
93 fHerwig->PrepareRun();
96 void AliGenHerwig::InitPDF()
138 fHerwig->SetMODPDF(1,fModPDF);
139 fHerwig->SetMODPDF(2,fModPDF);
140 fHerwig->SetAUTPDF(1,fAutPDF);
141 fHerwig->SetAUTPDF(2,fAutPDF);
144 void AliGenHerwig::Generate()
146 // Generate one event
148 Float_t polar[3] = {0,0,0};
149 Float_t origin[3]= {0,0,0};
150 Float_t origin0[3]= {0,0,0};
151 Float_t p[4], random[6];
153 static TClonesArray *particles;
154 // converts from mm/c to s
155 const Float_t kconv=0.001/2.999792458e8;
159 Int_t j, kf, ks, imo;
162 if(!particles) particles=new TClonesArray("TParticle",10000);
165 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
166 if(fVertexSmear==kPerEvent) {
169 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
170 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
176 fHerwig->GenerateEvent();
178 fHerwig->ImportParticles(particles,"All");
179 Int_t np = particles->GetEntriesFast()-1;
180 if (np == 0 ) continue;
184 Int_t * newPos = new Int_t[np];
185 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
187 for (Int_t i = 0; i<np; i++) {
188 TParticle * iparticle = (TParticle *) particles->At(i);
189 imo = iparticle->GetFirstMother();
190 kf = iparticle->GetPdgCode();
191 ks = iparticle->GetStatusCode();
193 KinematicSelection(iparticle,0))
196 p[0]=iparticle->Px();
197 p[1]=iparticle->Py();
198 p[2]=iparticle->Pz();
199 p[3]=iparticle->Energy();
200 origin[0]=origin0[0]+iparticle->Vx()/10;
201 origin[1]=origin0[1]+iparticle->Vy()/10;
202 origin[2]=origin0[2]+iparticle->Vz()/10;
203 Float_t tof = kconv*iparticle->T();
204 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
205 Int_t trackIt = (ks == 1) && fTrackIt;
206 gAlice->SetTrack(trackIt, iparent, kf,
207 p[0], p[1], p[2], p[3],
208 origin[0], origin[1], origin[2],
210 polar[0], polar[1], polar[2],
211 kPPrimary, nt, 1., ks);
214 } // end of if: selection of particle
215 } // end of for: particle loop
216 if (newPos) delete[] newPos;
217 printf("\n I've put %i particles on the stack \n",nc);
219 printf("nc: %d %d\n", nc, fNpart);
223 if (jev >= fNpart || fNpart == -1) {
224 fKineBias=Float_t(fNpart)/Float_t(fTrials);
225 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
230 SetHighWaterMark(nt);
231 // adjust weight due to kinematic selection
234 fXsection=fHerwig->GetAVWGT();
237 void AliGenHerwig::AdjustWeights()
239 // Adjust the weights after generation of all events
241 Int_t ntrack=gAlice->GetNtrack();
242 for (Int_t i=0; i<ntrack; i++) {
243 part= gAlice->Particle(i);
244 part->SetWeight(part->GetWeight()*fKineBias);
249 void AliGenHerwig::KeepFullEvent()
254 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
257 // Looks recursively if one of the daughters has been selected
259 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
263 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
264 Bool_t selected=kFALSE;
266 imin=iparticle->GetFirstDaughter();
267 imax=iparticle->GetLastDaughter();
268 for (i=imin; i<= imax; i++){
269 TParticle * jparticle = (TParticle *) particles->At(i);
270 Int_t ip=jparticle->GetPdgCode();
271 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
272 selected=kTRUE; break;
274 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
284 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
286 // Select flavor of particle
288 // 4: charm and beauty
290 if (fFlavor == 0) return kTRUE;
292 Int_t ifl=TMath::Abs(pid/100);
293 if (ifl > 10) ifl/=10;
294 return (fFlavor == ifl);
297 Bool_t AliGenHerwig::Stable(TParticle* particle)
299 // Return true for a stable particle
301 Int_t kf = TMath::Abs(particle->GetPdgCode());
303 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
312 void AliGenHerwig::FinishRun()
318 AliGenHerwig& AliGenHerwig::operator=(const AliGenHerwig& rhs)
320 // Assignment operator
326 Double_t hwr_() {return sRandom->Rndm();}