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"
32 ClassImp(AliGenHerwig)
34 static TRandom * sRandom;
36 AliGenHerwig::AliGenHerwig()
41 AliGenHerwig::AliGenHerwig(Int_t npart)
47 SetStrucFunc(kGRVLO98);
59 if (!sRandom) sRandom=fRandom;
62 AliGenHerwig::AliGenHerwig(const AliGenHerwig & Herwig)
70 AliGenHerwig::~AliGenHerwig()
75 void AliGenHerwig::Init()
79 fProjectile.Resize(8);
80 SetMC(new THerwig6());
81 fHerwig=(THerwig6*) fMCEvGen;
82 // initialize common blocks
83 fHerwig->Initialize(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
84 // reset parameters according to user needs
86 fHerwig->SetPTMIN(fPtHardMin);
87 fHerwig->SetPTRMS(fPtRMS);
88 fHerwig->SetMAXPR(fMaxPr);
89 fHerwig->SetMAXER(fMaxErrors);
90 fHerwig->SetENSOF(fEnSoft);
91 // compute parameter dependent constants
92 fHerwig->PrepareRun();
95 void AliGenHerwig::InitPDF()
136 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
140 fHerwig->SetMODPDF(1,fModPDF);
141 fHerwig->SetMODPDF(2,fModPDF);
142 fHerwig->SetAUTPDF(1,fAutPDF);
143 fHerwig->SetAUTPDF(2,fAutPDF);
146 void AliGenHerwig::Generate()
148 // Generate one event
150 Float_t polar[3] = {0,0,0};
151 Float_t origin[3]= {0,0,0};
152 Float_t origin0[3]= {0,0,0};
153 Float_t p[4], random[6];
155 static TClonesArray *particles;
156 // converts from mm/c to s
157 const Float_t kconv=0.001/2.999792458e8;
161 Int_t j, kf, ks, imo;
164 if(!particles) particles=new TClonesArray("TParticle",10000);
167 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
168 if(fVertexSmear==kPerEvent) {
171 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
172 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
178 fHerwig->GenerateEvent();
180 fHerwig->ImportParticles(particles,"All");
181 Int_t np = particles->GetEntriesFast()-1;
182 if (np == 0 ) continue;
186 Int_t * newPos = new Int_t[np];
187 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
189 for (Int_t i = 0; i<np; i++) {
190 TParticle * iparticle = (TParticle *) particles->At(i);
191 imo = iparticle->GetFirstMother();
192 kf = iparticle->GetPdgCode();
193 ks = iparticle->GetStatusCode();
195 KinematicSelection(iparticle,0))
198 p[0]=iparticle->Px();
199 p[1]=iparticle->Py();
200 p[2]=iparticle->Pz();
201 p[3]=iparticle->Energy();
202 origin[0]=origin0[0]+iparticle->Vx()/10;
203 origin[1]=origin0[1]+iparticle->Vy()/10;
204 origin[2]=origin0[2]+iparticle->Vz()/10;
205 Float_t tof = kconv*iparticle->T();
206 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
207 Int_t trackIt = (ks == 1) && fTrackIt;
208 gAlice->GetMCApp()->PushTrack(trackIt, iparent, kf,
209 p[0], p[1], p[2], p[3],
210 origin[0], origin[1], origin[2],
212 polar[0], polar[1], polar[2],
213 kPPrimary, nt, 1., ks);
216 } // end of if: selection of particle
217 } // end of for: particle loop
218 if (newPos) delete[] newPos;
219 printf("\n I've put %i particles on the stack \n",nc);
221 printf("nc: %d %d\n", nc, fNpart);
225 if (jev >= fNpart || fNpart == -1) {
226 fKineBias=Float_t(fNpart)/Float_t(fTrials);
227 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
232 SetHighWaterMark(nt);
233 // adjust weight due to kinematic selection
236 fXsection=fHerwig->GetAVWGT();
239 void AliGenHerwig::AdjustWeights()
241 // Adjust the weights after generation of all events
243 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
244 for (Int_t i=0; i<ntrack; i++) {
245 part= gAlice->GetMCApp()->Particle(i);
246 part->SetWeight(part->GetWeight()*fKineBias);
251 void AliGenHerwig::KeepFullEvent()
256 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
259 // Looks recursively if one of the daughters has been selected
261 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
265 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
266 Bool_t selected=kFALSE;
268 imin=iparticle->GetFirstDaughter();
269 imax=iparticle->GetLastDaughter();
270 for (i=imin; i<= imax; i++){
271 TParticle * jparticle = (TParticle *) particles->At(i);
272 Int_t ip=jparticle->GetPdgCode();
273 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
274 selected=kTRUE; break;
276 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
286 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
288 // Select flavor of particle
290 // 4: charm and beauty
292 if (fFlavor == 0) return kTRUE;
294 Int_t ifl=TMath::Abs(pid/100);
295 if (ifl > 10) ifl/=10;
296 return (fFlavor == ifl);
299 Bool_t AliGenHerwig::Stable(TParticle* particle)
301 // Return true for a stable particle
303 Int_t kf = TMath::Abs(particle->GetPdgCode());
305 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
314 void AliGenHerwig::FinishRun()
320 AliGenHerwig& AliGenHerwig::operator=(const AliGenHerwig& rhs)
322 // Assignment operator
329 Double_t hwr_() {return sRandom->Rndm();}