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.2.2.3 2002/10/11 10:40:46 hristov
21 Revision 1.2.2.2 2002/07/26 18:34:02 alibrary
24 Revision 1.3 2002/07/26 15:32:24 hristov
25 stream.h doesn't exest on Sun, removed from includes
27 Revision 1.2 2002/07/19 11:43:10 morsch
29 - Use SetTrack passing energy.
31 Revision 1.1 2002/07/16 11:33:26 morsch
38 // Generator using Herwig as an external generator
39 // The main Herwig options are accessable for the user through this interface.
40 // Uses the THerwig implementation of TGenerator.
42 #include "AliGenHerwig.h"
45 #include <TParticle.h>
48 #include "Riostream.h"
50 ClassImp(AliGenHerwig)
52 AliGenHerwig::AliGenHerwig()
57 AliGenHerwig::AliGenHerwig(Int_t npart)
63 SetStrucFunc(kGRVLO98);
75 if (!sRandom) sRandom=fRandom;
78 AliGenHerwig::AliGenHerwig(const AliGenHerwig & Herwig)
84 AliGenHerwig::~AliGenHerwig()
89 void AliGenHerwig::Init()
93 fProjectile.Resize(8);
94 SetMC(new THerwig6());
95 fHerwig=(THerwig6*) fgMCEvGen;
96 // initialize common blocks
97 fHerwig->Initialize(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
98 // reset parameters according to user needs
100 fHerwig->SetPTMIN(fPtHardMin);
101 fHerwig->SetPTRMS(fPtRMS);
102 fHerwig->SetMAXPR(fMaxPr);
103 fHerwig->SetMAXER(fMaxErrors);
104 fHerwig->SetENSOF(fEnSoft);
105 // compute parameter dependent constants
106 fHerwig->PrepareRun();
109 void AliGenHerwig::InitPDF()
150 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
154 fHerwig->SetMODPDF(1,fModPDF);
155 fHerwig->SetMODPDF(2,fModPDF);
156 fHerwig->SetAUTPDF(1,fAutPDF);
157 fHerwig->SetAUTPDF(2,fAutPDF);
160 void AliGenHerwig::Generate()
162 // Generate one event
164 Float_t polar[3] = {0,0,0};
165 Float_t origin[3]= {0,0,0};
166 Float_t origin0[3]= {0,0,0};
167 Float_t p[4], random[6];
169 static TClonesArray *particles;
170 // converts from mm/c to s
171 const Float_t kconv=0.001/2.999792458e8;
175 Int_t j, kf, ks, imo;
178 if(!particles) particles=new TClonesArray("TParticle",10000);
181 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
182 if(fVertexSmear==kPerEvent) {
185 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
186 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
192 fHerwig->GenerateEvent();
194 fHerwig->ImportParticles(particles,"All");
195 Int_t np = particles->GetEntriesFast()-1;
196 if (np == 0 ) continue;
200 Int_t * newPos = new Int_t[np];
201 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
203 for (Int_t i = 0; i<np; i++) {
204 TParticle * iparticle = (TParticle *) particles->At(i);
205 imo = iparticle->GetFirstMother();
206 kf = iparticle->GetPdgCode();
207 ks = iparticle->GetStatusCode();
209 KinematicSelection(iparticle,0))
212 p[0]=iparticle->Px();
213 p[1]=iparticle->Py();
214 p[2]=iparticle->Pz();
215 p[3]=iparticle->Energy();
216 origin[0]=origin0[0]+iparticle->Vx()/10;
217 origin[1]=origin0[1]+iparticle->Vy()/10;
218 origin[2]=origin0[2]+iparticle->Vz()/10;
219 Float_t tof = kconv*iparticle->T();
220 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
221 Int_t trackIt = (ks == 1) && fTrackIt;
222 gAlice->SetTrack(trackIt, iparent, kf,
223 p[0], p[1], p[2], p[3],
224 origin[0], origin[1], origin[2],
226 polar[0], polar[1], polar[2],
227 kPPrimary, nt, 1., ks);
230 } // end of if: selection of particle
231 } // end of for: particle loop
232 if (newPos) delete[] newPos;
233 printf("\n I've put %i particles on the stack \n",nc);
235 printf("nc: %d %d\n", nc, fNpart);
239 if (jev >= fNpart || fNpart == -1) {
240 fKineBias=Float_t(fNpart)/Float_t(fTrials);
241 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
246 SetHighWaterMark(nt);
247 // adjust weight due to kinematic selection
250 fXsection=fHerwig->GetAVWGT();
253 void AliGenHerwig::AdjustWeights()
255 // Adjust the weights after generation of all events
257 Int_t ntrack=gAlice->GetNtrack();
258 for (Int_t i=0; i<ntrack; i++) {
259 part= gAlice->Particle(i);
260 part->SetWeight(part->GetWeight()*fKineBias);
265 void AliGenHerwig::KeepFullEvent()
270 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
273 // Looks recursively if one of the daughters has been selected
275 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
279 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
280 Bool_t selected=kFALSE;
282 imin=iparticle->GetFirstDaughter();
283 imax=iparticle->GetLastDaughter();
284 for (i=imin; i<= imax; i++){
285 TParticle * jparticle = (TParticle *) particles->At(i);
286 Int_t ip=jparticle->GetPdgCode();
287 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
288 selected=kTRUE; break;
290 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
300 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
302 // Select flavor of particle
304 // 4: charm and beauty
306 if (fFlavor == 0) return kTRUE;
308 Int_t ifl=TMath::Abs(pid/100);
309 if (ifl > 10) ifl/=10;
310 return (fFlavor == ifl);
313 Bool_t AliGenHerwig::Stable(TParticle* particle)
315 // Return true for a stable particle
317 Int_t kf = TMath::Abs(particle->GetPdgCode());
319 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
328 void AliGenHerwig::FinishRun()
334 AliGenHerwig& AliGenHerwig::operator=(const AliGenHerwig& rhs)
336 // Assignment operator
342 Double_t hwr_() {return sRandom->Rndm();}