Code causing warning messages corrected.
[u/mrichter/AliRoot.git] / THerwig / AliGenHerwig.cxx
CommitLineData
618e1dc0 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
7cdba479 16/* $Id$ */
618e1dc0 17
18
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.
22
23#include "AliGenHerwig.h"
24#include "AliRun.h"
25
26#include <TParticle.h>
27#include "THerwig6.h"
28
29#include "Riostream.h"
30
014a9521 31ClassImp(AliGenHerwig)
618e1dc0 32
7cdba479 33static TRandom * sRandom;
34
618e1dc0 35AliGenHerwig::AliGenHerwig()
36{
37// Constructor
38}
39
40AliGenHerwig::AliGenHerwig(Int_t npart)
41 :AliGenMC(npart)
42{
43 SetBeamMomenta();
44 SetTarget();
45 SetProjectile();
46 SetStrucFunc(kGRVLO98);
47 fKeep=0;
48 fTrigger=0;
49 fDecaysOff=1;
50 fSelectAll=0;
51 fFlavor=0;
52 fPtHardMin=10.;
53 fPtRMS=0.0;
54 fEnSoft=1.0;
55 fMaxPr=1;
56 fMaxErrors=1000;
57// Set random number
58 if (!sRandom) sRandom=fRandom;
59}
60
61AliGenHerwig::AliGenHerwig(const AliGenHerwig & Herwig)
014a9521 62 :AliGenMC(Herwig)
618e1dc0 63{
014a9521 64// Copy constructor
65 Herwig.Copy(*this);
618e1dc0 66}
67
68
69AliGenHerwig::~AliGenHerwig()
70{
71// Destructor
72}
73
74void AliGenHerwig::Init()
75{
76// Initialisation
77 fTarget.Resize(8);
78 fProjectile.Resize(8);
79 SetMC(new THerwig6());
d274cd60 80 fHerwig=(THerwig6*) fMCEvGen;
618e1dc0 81 // initialize common blocks
82 fHerwig->Initialize(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess);
83 // reset parameters according to user needs
84 InitPDF();
85 fHerwig->SetPTMIN(fPtHardMin);
86 fHerwig->SetPTRMS(fPtRMS);
87 fHerwig->SetMAXPR(fMaxPr);
88 fHerwig->SetMAXER(fMaxErrors);
89 fHerwig->SetENSOF(fEnSoft);
90 // compute parameter dependent constants
91 fHerwig->PrepareRun();
92}
93
94void AliGenHerwig::InitPDF()
95{
96 switch(fStrucFunc)
97 {
98 case kGRVLO:
99 fModPDF=5;
100 fAutPDF="GRV";
101 break;
102 case kGRVHO:
103 fModPDF=6;
104 fAutPDF="GRV";
105 break;
106 case kGRVLO98:
107 fModPDF=12;
108 fAutPDF="GRV";
109 break;
110 case kMRSDminus:
111 fModPDF=31;
112 fAutPDF="MRS";
113 break;
114 case kMRSD0:
115 fModPDF=30;
116 fAutPDF="MRS";
117 break;
118 case kMRSG:
119 fModPDF=41;
120 fAutPDF="MRS";
121 break;
122 case kMRSTcgLO:
123 fModPDF=72;
124 fAutPDF="MRS";
125 break;
126 case kCTEQ4M:
127 fModPDF=34;
128 fAutPDF="CTEQ";
129 break;
130 case kCTEQ5L:
131 fModPDF=46;
132 fAutPDF="CTEQ";
133 break;
134 default:
135 cerr << "This structure function is not inplemented " << fStrucFunc << endl;
136 break;
137 }
138 fAutPDF.Resize(20);
139 fHerwig->SetMODPDF(1,fModPDF);
140 fHerwig->SetMODPDF(2,fModPDF);
141 fHerwig->SetAUTPDF(1,fAutPDF);
142 fHerwig->SetAUTPDF(2,fAutPDF);
143}
144
145void AliGenHerwig::Generate()
146{
147 // Generate one event
148
149 Float_t polar[3] = {0,0,0};
150 Float_t origin[3]= {0,0,0};
151 Float_t origin0[3]= {0,0,0};
152 Float_t p[4], random[6];
153
154 static TClonesArray *particles;
155 // converts from mm/c to s
156 const Float_t kconv=0.001/2.999792458e8;
157 //
158 Int_t nt=0;
159 Int_t jev=0;
160 Int_t j, kf, ks, imo;
161 kf=0;
162
163 if(!particles) particles=new TClonesArray("TParticle",10000);
164
165 fTrials=0;
166 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
167 if(fVertexSmear==kPerEvent) {
168 Rndm(random,6);
169 for (j=0;j<3;j++) {
170 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
171 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
172 }
173 }
174
175 while(1)
176 {
177 fHerwig->GenerateEvent();
178 fTrials++;
179 fHerwig->ImportParticles(particles,"All");
180 Int_t np = particles->GetEntriesFast()-1;
181 if (np == 0 ) continue;
182
183 Int_t nc=0;
184
185 Int_t * newPos = new Int_t[np];
186 for (Int_t i = 0; i<np; i++) *(newPos+i)=-1;
187
188 for (Int_t i = 0; i<np; i++) {
189 TParticle * iparticle = (TParticle *) particles->At(i);
190 imo = iparticle->GetFirstMother();
191 kf = iparticle->GetPdgCode();
192 ks = iparticle->GetStatusCode();
193 if (ks != 3 &&
194 KinematicSelection(iparticle,0))
195 {
196 nc++;
197 p[0]=iparticle->Px();
198 p[1]=iparticle->Py();
199 p[2]=iparticle->Pz();
200 p[3]=iparticle->Energy();
201 origin[0]=origin0[0]+iparticle->Vx()/10;
202 origin[1]=origin0[1]+iparticle->Vy()/10;
203 origin[2]=origin0[2]+iparticle->Vz()/10;
204 Float_t tof = kconv*iparticle->T();
205 Int_t iparent = (imo > -1) ? newPos[imo] : -1;
206 Int_t trackIt = (ks == 1) && fTrackIt;
642f15cf 207 gAlice->PushTrack(trackIt, iparent, kf,
618e1dc0 208 p[0], p[1], p[2], p[3],
209 origin[0], origin[1], origin[2],
210 tof,
211 polar[0], polar[1], polar[2],
212 kPPrimary, nt, 1., ks);
213 KeepTrack(nt);
214 newPos[i]=nt;
215 } // end of if: selection of particle
216 } // end of for: particle loop
217 if (newPos) delete[] newPos;
218 printf("\n I've put %i particles on the stack \n",nc);
219 // MakeHeader();
220 printf("nc: %d %d\n", nc, fNpart);
221
222 if (nc > 0) {
223 jev+=nc;
224 if (jev >= fNpart || fNpart == -1) {
225 fKineBias=Float_t(fNpart)/Float_t(fTrials);
226 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
227 break;
228 }
229 }
230 }
231 SetHighWaterMark(nt);
232// adjust weight due to kinematic selection
233 AdjustWeights();
234// get cross-section
235 fXsection=fHerwig->GetAVWGT();
236}
237
238void AliGenHerwig::AdjustWeights()
239{
240// Adjust the weights after generation of all events
241 TParticle *part;
242 Int_t ntrack=gAlice->GetNtrack();
243 for (Int_t i=0; i<ntrack; i++) {
244 part= gAlice->Particle(i);
245 part->SetWeight(part->GetWeight()*fKineBias);
246 }
247}
248
249
250void AliGenHerwig::KeepFullEvent()
251{
252 fKeep=1;
253}
254
255Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles)
256{
257//
258// Looks recursively if one of the daughters has been selected
259//
260// printf("\n Consider daughters %d:",iparticle->GetPdgCode());
261 Int_t imin=-1;
262 Int_t imax=-1;
263 Int_t i;
264 Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0);
265 Bool_t selected=kFALSE;
266 if (hasDaughters) {
267 imin=iparticle->GetFirstDaughter();
268 imax=iparticle->GetLastDaughter();
269 for (i=imin; i<= imax; i++){
270 TParticle * jparticle = (TParticle *) particles->At(i);
271 Int_t ip=jparticle->GetPdgCode();
272 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
273 selected=kTRUE; break;
274 }
275 if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; }
276 }
277 } else {
278 return kFALSE;
279 }
280
281 return selected;
282}
283
284
285Bool_t AliGenHerwig::SelectFlavor(Int_t pid)
286{
287// Select flavor of particle
288// 0: all
289// 4: charm and beauty
290// 5: beauty
291 if (fFlavor == 0) return kTRUE;
292
293 Int_t ifl=TMath::Abs(pid/100);
294 if (ifl > 10) ifl/=10;
295 return (fFlavor == ifl);
296}
297
298Bool_t AliGenHerwig::Stable(TParticle* particle)
299{
300// Return true for a stable particle
301//
302 Int_t kf = TMath::Abs(particle->GetPdgCode());
303
304 if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122))
305
306 {
307 return kTRUE;
308 } else {
309 return kFALSE;
310 }
311}
312
313void AliGenHerwig::FinishRun()
314{
315 fHerwig->Hwefin();
316}
317
318
319AliGenHerwig& AliGenHerwig::operator=(const AliGenHerwig& rhs)
320{
321// Assignment operator
014a9521 322 rhs.Copy(*this);
323 return (*this);
618e1dc0 324}
325
326
327extern "C" {
328 Double_t hwr_() {return sRandom->Rndm();}
329}