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() :
63 AliGenHerwig::AliGenHerwig(Int_t npart)
69 SetStrucFunc(kGRVLO98);
80 // Set random number generator
81 AliHerwigRndm::SetHerwigRandom(GetRandom());
84 AliGenHerwig::AliGenHerwig(const AliGenHerwig & Herwig)
92 AliGenHerwig::~AliGenHerwig()
97 void AliGenHerwig::Init()
101 fProjectile.Resize(8);
102 SetMC(new THerwig6());
103 fHerwig=(THerwig6*) fMCEvGen;
104 // initialize common blocks
105 fHerwig->Initialize(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
106 // reset parameters according to user needs
108 fHerwig->SetPTMIN(fPtHardMin);
109 fHerwig->SetPTRMS(fPtRMS);
110 fHerwig->SetMAXPR(fMaxPr);
111 fHerwig->SetMAXER(fMaxErrors);
112 fHerwig->SetENSOF(fEnSoft);
113 // compute parameter dependent constants
114 fHerwig->PrepareRun();
117 void AliGenHerwig::InitPDF()
158 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
162 fHerwig->SetMODPDF(1,fModPDF);
163 fHerwig->SetMODPDF(2,fModPDF);
164 fHerwig->SetAUTPDF(1,fAutPDF);
165 fHerwig->SetAUTPDF(2,fAutPDF);
168 void AliGenHerwig::Generate()
170 // Generate one event
172 Float_t polar[3] = {0,0,0};
173 Float_t origin[3]= {0,0,0};
174 Float_t origin0[3]= {0,0,0};
175 Float_t p[4], random[6];
177 static TClonesArray *particles;
178 // converts from mm/c to s
179 const Float_t kconv=0.001/2.999792458e8;
183 Int_t j, kf, ks, imo;
186 if(!particles) particles=new TClonesArray("TParticle",10000);
189 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
190 if(fVertexSmear==kPerEvent) {
193 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
194 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
200 fHerwig->GenerateEvent();
202 fHerwig->ImportParticles(particles,"All");
203 Int_t np = particles->GetEntriesFast()-1;
204 if (np == 0 ) continue;
208 Int_t * newPos = new Int_t[np];
209 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
211 for (Int_t i = 0; i<np; i++) {
212 TParticle * iparticle = (TParticle *) particles->At(i);
213 imo = iparticle->GetFirstMother();
214 kf = iparticle->GetPdgCode();
215 ks = iparticle->GetStatusCode();
217 KinematicSelection(iparticle,0))
220 p[0]=iparticle->Px();
221 p[1]=iparticle->Py();
222 p[2]=iparticle->Pz();
223 p[3]=iparticle->Energy();
224 origin[0]=origin0[0]+iparticle->Vx()/10;
225 origin[1]=origin0[1]+iparticle->Vy()/10;
226 origin[2]=origin0[2]+iparticle->Vz()/10;
227 Float_t tof = kconv*iparticle->T();
228 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
229 Int_t trackIt = (ks == 1) && fTrackIt;
230 PushTrack(trackIt, iparent, kf,
231 p[0], p[1], p[2], p[3],
232 origin[0], origin[1], origin[2],
234 polar[0], polar[1], polar[2],
235 kPPrimary, nt, 1., ks);
238 } // end of if: selection of particle
239 } // end of for: particle loop
240 if (newPos) delete[] newPos;
244 if (jev >= fNpart || fNpart == -1) {
245 fKineBias=Float_t(fNpart)/Float_t(fTrials);
250 SetHighWaterMark(nt);
251 // adjust weight due to kinematic selection
254 fXsection=fHerwig->GetAVWGT();
257 void AliGenHerwig::AdjustWeights()
259 // Adjust the weights after generation of all events
261 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
262 for (Int_t i=0; i<ntrack; i++) {
263 part= gAlice->GetMCApp()->Particle(i);
264 part->SetWeight(part->GetWeight()*fKineBias);
269 void AliGenHerwig::KeepFullEvent()
274 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
277 // Looks recursively if one of the daughters has been selected
279 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
283 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
284 Bool_t selected=kFALSE;
286 imin=iparticle->GetFirstDaughter();
287 imax=iparticle->GetLastDaughter();
288 for (i=imin; i<= imax; i++){
289 TParticle * jparticle = (TParticle *) particles->At(i);
290 Int_t ip=jparticle->GetPdgCode();
291 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
292 selected=kTRUE; break;
294 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
304 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
306 // Select flavor of particle
308 // 4: charm and beauty
310 if (fFlavor == 0) return kTRUE;
312 Int_t ifl=TMath::Abs(pid/100);
313 if (ifl > 10) ifl/=10;
314 return (fFlavor == ifl);
317 Bool_t AliGenHerwig::Stable(TParticle* particle)
319 // Return true for a stable particle
321 Int_t kf = TMath::Abs(particle->GetPdgCode());
323 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
332 void AliGenHerwig::FinishRun()
338 AliGenHerwig& AliGenHerwig::operator=(const AliGenHerwig& rhs)
340 // Assignment operator