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"
24 #include "AliHerwigRndm.h"
27 #include <TParticle.h>
30 #include "Riostream.h"
33 ClassImp(AliGenHerwig)
36 AliGenHerwig::AliGenHerwig()
41 AliGenHerwig::AliGenHerwig(Int_t npart)
47 SetStrucFunc(kGRVLO98);
58 // Set random number generator
59 AliHerwigRndm::SetHerwigRandom(GetRandom());
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 printf("Particles from Herwig %d \n", np);
184 if (np == 0 ) continue;
188 Int_t * newPos = new Int_t[np];
189 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
191 for (Int_t i = 0; i<np; i++) {
192 TParticle * iparticle = (TParticle *) particles->At(i);
193 imo = iparticle->GetFirstMother();
194 kf = iparticle->GetPdgCode();
195 ks = iparticle->GetStatusCode();
197 KinematicSelection(iparticle,0))
200 p[0]=iparticle->Px();
201 p[1]=iparticle->Py();
202 p[2]=iparticle->Pz();
203 p[3]=iparticle->Energy();
204 origin[0]=origin0[0]+iparticle->Vx()/10;
205 origin[1]=origin0[1]+iparticle->Vy()/10;
206 origin[2]=origin0[2]+iparticle->Vz()/10;
207 Float_t tof = kconv*iparticle->T();
208 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
209 Int_t trackIt = (ks == 1) && fTrackIt;
210 PushTrack(trackIt, iparent, kf,
211 p[0], p[1], p[2], p[3],
212 origin[0], origin[1], origin[2],
214 polar[0], polar[1], polar[2],
215 kPPrimary, nt, 1., ks);
218 } // end of if: selection of particle
219 } // end of for: particle loop
220 if (newPos) delete[] newPos;
221 printf("\n I've put %i particles on the stack \n",nc);
223 printf("nc: %d %d\n", nc, fNpart);
227 if (jev >= fNpart || fNpart == -1) {
228 fKineBias=Float_t(fNpart)/Float_t(fTrials);
229 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
234 SetHighWaterMark(nt);
235 // adjust weight due to kinematic selection
238 fXsection=fHerwig->GetAVWGT();
241 void AliGenHerwig::AdjustWeights()
243 // Adjust the weights after generation of all events
245 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
246 for (Int_t i=0; i<ntrack; i++) {
247 part= gAlice->GetMCApp()->Particle(i);
248 part->SetWeight(part->GetWeight()*fKineBias);
253 void AliGenHerwig::KeepFullEvent()
258 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
261 // Looks recursively if one of the daughters has been selected
263 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
267 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
268 Bool_t selected=kFALSE;
270 imin=iparticle->GetFirstDaughter();
271 imax=iparticle->GetLastDaughter();
272 for (i=imin; i<= imax; i++){
273 TParticle * jparticle = (TParticle *) particles->At(i);
274 Int_t ip=jparticle->GetPdgCode();
275 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
276 selected=kTRUE; break;
278 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
288 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
290 // Select flavor of particle
292 // 4: charm and beauty
294 if (fFlavor == 0) return kTRUE;
296 Int_t ifl=TMath::Abs(pid/100);
297 if (ifl > 10) ifl/=10;
298 return (fFlavor == ifl);
301 Bool_t AliGenHerwig::Stable(TParticle* particle)
303 // Return true for a stable particle
305 Int_t kf = TMath::Abs(particle->GetPdgCode());
307 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
316 void AliGenHerwig::FinishRun()
322 AliGenHerwig& AliGenHerwig::operator=(const AliGenHerwig& rhs)
324 // Assignment operator