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"
35 ClassImp(AliGenHerwig)
38 AliGenHerwig::AliGenHerwig() :
68 AliGenHerwig::AliGenHerwig(Int_t npart)
97 // Set random number generator
98 AliHerwigRndm::SetHerwigRandom(GetRandom());
101 AliGenHerwig::AliGenHerwig(const AliGenHerwig & Herwig)
133 AliGenHerwig::~AliGenHerwig()
138 void AliGenHerwig::SetEventListRange(Int_t eventFirst, Int_t eventLast)
140 fEv1Pr = ++eventFirst;
141 fEv2Pr = ++eventLast;
142 if ( fEv2Pr == -1 ) fEv2Pr = fEv2Pr;
145 void AliGenHerwig::Init()
149 fProjectile.Resize(8);
150 SetMC(new THerwig6());
151 fHerwig=(THerwig6*) fMCEvGen;
152 // initialize common blocks
153 fHerwig->Initialize(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
154 // reset parameters according to user needs
156 fHerwig->SetPTMIN(fPtHardMin);
157 fHerwig->SetPTRMS(fPtRMS);
158 fHerwig->SetMAXPR(fMaxPr);
159 fHerwig->SetMAXER(fMaxErrors);
160 fHerwig->SetENSOF(fEnSoft);
162 fHerwig->SetEV1PR(fEv1Pr);
163 fHerwig->SetEV2PR(fEv2Pr);
165 // C---D,U,S,C,B,T QUARK AND GLUON MASSES (IN THAT ORDER)
174 fHerwig->SetRMASS(4,1.2);
175 fHerwig->SetRMASS(5,4.75);
177 if ( fProcess < 0 ) strncpy(VVJIN.QQIN,fFileName.Data(),50);
179 fHerwig->Hwusta("PI0 ");
181 // compute parameter dependent constants
182 fHerwig->PrepareRun();
185 void AliGenHerwig::InitPDF()
230 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
234 fHerwig->SetMODPDF(1,fModPDF);
235 fHerwig->SetMODPDF(2,fModPDF);
236 fHerwig->SetAUTPDF(1,fAutPDF);
237 fHerwig->SetAUTPDF(2,fAutPDF);
240 void AliGenHerwig::Generate()
242 // Generate one event
244 Float_t polar[3] = {0,0,0};
245 Float_t origin[3]= {0,0,0};
246 Float_t origin0[3]= {0,0,0};
247 Float_t p[4], random[6];
249 static TClonesArray *particles;
250 // converts from mm/c to s
251 const Float_t kconv=0.001/2.999792458e8;
255 Int_t j, kf, ks, imo;
258 if(!particles) particles=new TClonesArray("TParticle",10000);
261 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
262 if(fVertexSmear==kPerEvent) {
265 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
266 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
272 fHerwig->GenerateEvent();
274 fHerwig->ImportParticles(particles,"All");
275 Int_t np = particles->GetEntriesFast()-1;
276 if (np == 0 ) continue;
280 Int_t * newPos = new Int_t[np];
281 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
283 for (Int_t i = 0; i<np; i++) {
284 TParticle * iparticle = (TParticle *) particles->At(i);
285 imo = iparticle->GetFirstMother();
286 kf = iparticle->GetPdgCode();
287 ks = iparticle->GetStatusCode();
289 KinematicSelection(iparticle,0))
292 p[0]=iparticle->Px();
293 p[1]=iparticle->Py();
294 p[2]=iparticle->Pz();
295 p[3]=iparticle->Energy();
296 origin[0]=origin0[0]+iparticle->Vx()/10;
297 origin[1]=origin0[1]+iparticle->Vy()/10;
298 origin[2]=origin0[2]+iparticle->Vz()/10;
299 Float_t tof = kconv*iparticle->T();
300 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
301 Int_t trackIt = (ks == 1) && fTrackIt;
302 PushTrack(trackIt, iparent, kf,
303 p[0], p[1], p[2], p[3],
304 origin[0], origin[1], origin[2],
306 polar[0], polar[1], polar[2],
307 kPPrimary, nt, fHerwig->GetEVWGT(), ks);
310 } // end of if: selection of particle
311 } // end of for: particle loop
312 if (newPos) delete[] newPos;
316 if (jev >= fNpart || fNpart == -1) {
317 fKineBias=Float_t(fNpart)/Float_t(fTrials);
322 SetHighWaterMark(nt);
323 // adjust weight due to kinematic selection
326 fXsection=fHerwig->GetAVWGT();
329 void AliGenHerwig::AdjustWeights()
331 // Adjust the weights after generation of all events
333 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
334 for (Int_t i=0; i<ntrack; i++) {
335 part= gAlice->GetMCApp()->Particle(i);
336 part->SetWeight(part->GetWeight()*fKineBias);
341 void AliGenHerwig::KeepFullEvent()
346 Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
349 // Looks recursively if one of the daughters has been selected
351 // printf("\n Consider daughters %d:",iparticle->GetPdgCode());
355 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
356 Bool_t selected=kFALSE;
358 imin=iparticle->GetFirstDaughter();
359 imax=iparticle->GetLastDaughter();
360 for (i=imin; i<= imax; i++){
361 TParticle * jparticle = (TParticle *) particles->At(i);
362 Int_t ip=jparticle->GetPdgCode();
363 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
364 selected=kTRUE; break;
366 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
376 Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
378 // Select flavor of particle
380 // 4: charm and beauty
382 if (fFlavor == 0) return kTRUE;
384 Int_t ifl=TMath::Abs(pid/100);
385 if (ifl > 10) ifl/=10;
386 return (fFlavor == ifl);
389 Bool_t AliGenHerwig::Stable(TParticle* particle)
391 // Return true for a stable particle
393 Int_t kf = TMath::Abs(particle->GetPdgCode());
395 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
404 void AliGenHerwig::FinishRun()
410 AliGenHerwig& AliGenHerwig::operator=(const AliGenHerwig& rhs)
412 // Assignment operator