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" |
93831bcf |
24 | #include "AliHerwigRndm.h" |
618e1dc0 |
25 | #include "AliRun.h" |
26 | |
27 | #include <TParticle.h> |
28 | #include "THerwig6.h" |
29 | |
30 | #include "Riostream.h" |
5d12ce38 |
31 | #include "AliMC.h" |
618e1dc0 |
32 | |
014a9521 |
33 | ClassImp(AliGenHerwig) |
618e1dc0 |
34 | |
7cdba479 |
35 | |
a1d47d99 |
36 | AliGenHerwig::AliGenHerwig() : |
37 | AliGenMC(), |
38 | fAutPDF("GRV"), |
39 | fModPDF(5), |
40 | fStrucFunc(kGRVHO), |
41 | fKeep(0), |
42 | fDecaysOff(1), |
43 | fTrigger(0), |
44 | fSelectAll(0), |
45 | fFlavor(0), |
46 | fEnergyCMS(14000), |
47 | fMomentum1(7000), |
48 | fMomentum2(7000), |
49 | fKineBias(1), |
50 | fTrials(0), |
51 | fXsection(0), |
52 | fHerwig(0x0), |
53 | fProcess(0), |
54 | fPtHardMin(0), |
55 | fPtRMS(0), |
56 | fMaxPr(10), |
57 | fMaxErrors(1000), |
58 | fEnSoft(1) |
618e1dc0 |
59 | { |
60 | // Constructor |
61 | } |
62 | |
63 | AliGenHerwig::AliGenHerwig(Int_t npart) |
64 | :AliGenMC(npart) |
65 | { |
66 | SetBeamMomenta(); |
67 | SetTarget(); |
68 | SetProjectile(); |
69 | SetStrucFunc(kGRVLO98); |
70 | fKeep=0; |
71 | fTrigger=0; |
72 | fDecaysOff=1; |
73 | fSelectAll=0; |
74 | fFlavor=0; |
93831bcf |
75 | fPtHardMin=0.; |
618e1dc0 |
76 | fPtRMS=0.0; |
77 | fEnSoft=1.0; |
93831bcf |
78 | fMaxPr=10; |
618e1dc0 |
79 | fMaxErrors=1000; |
93831bcf |
80 | // Set random number generator |
81 | AliHerwigRndm::SetHerwigRandom(GetRandom()); |
618e1dc0 |
82 | } |
83 | |
84 | AliGenHerwig::AliGenHerwig(const AliGenHerwig & Herwig) |
014a9521 |
85 | :AliGenMC(Herwig) |
618e1dc0 |
86 | { |
014a9521 |
87 | // Copy constructor |
88 | Herwig.Copy(*this); |
618e1dc0 |
89 | } |
90 | |
91 | |
92 | AliGenHerwig::~AliGenHerwig() |
93 | { |
94 | // Destructor |
95 | } |
96 | |
97 | void AliGenHerwig::Init() |
98 | { |
99 | // Initialisation |
100 | fTarget.Resize(8); |
101 | fProjectile.Resize(8); |
102 | SetMC(new THerwig6()); |
d274cd60 |
103 | fHerwig=(THerwig6*) fMCEvGen; |
618e1dc0 |
104 | // initialize common blocks |
105 | fHerwig->Initialize(fProjectile, fTarget, fMomentum1, fMomentum2, fProcess); |
106 | // reset parameters according to user needs |
107 | InitPDF(); |
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(); |
115 | } |
116 | |
117 | void AliGenHerwig::InitPDF() |
118 | { |
119 | switch(fStrucFunc) |
120 | { |
121 | case kGRVLO: |
122 | fModPDF=5; |
123 | fAutPDF="GRV"; |
124 | break; |
125 | case kGRVHO: |
126 | fModPDF=6; |
127 | fAutPDF="GRV"; |
128 | break; |
129 | case kGRVLO98: |
130 | fModPDF=12; |
131 | fAutPDF="GRV"; |
132 | break; |
133 | case kMRSDminus: |
134 | fModPDF=31; |
135 | fAutPDF="MRS"; |
136 | break; |
137 | case kMRSD0: |
138 | fModPDF=30; |
139 | fAutPDF="MRS"; |
140 | break; |
141 | case kMRSG: |
142 | fModPDF=41; |
143 | fAutPDF="MRS"; |
144 | break; |
145 | case kMRSTcgLO: |
146 | fModPDF=72; |
147 | fAutPDF="MRS"; |
148 | break; |
149 | case kCTEQ4M: |
150 | fModPDF=34; |
151 | fAutPDF="CTEQ"; |
152 | break; |
153 | case kCTEQ5L: |
154 | fModPDF=46; |
155 | fAutPDF="CTEQ"; |
156 | break; |
157 | default: |
158 | cerr << "This structure function is not inplemented " << fStrucFunc << endl; |
159 | break; |
160 | } |
161 | fAutPDF.Resize(20); |
162 | fHerwig->SetMODPDF(1,fModPDF); |
163 | fHerwig->SetMODPDF(2,fModPDF); |
164 | fHerwig->SetAUTPDF(1,fAutPDF); |
165 | fHerwig->SetAUTPDF(2,fAutPDF); |
166 | } |
167 | |
168 | void AliGenHerwig::Generate() |
169 | { |
170 | // Generate one event |
171 | |
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]; |
176 | |
177 | static TClonesArray *particles; |
178 | // converts from mm/c to s |
179 | const Float_t kconv=0.001/2.999792458e8; |
180 | // |
181 | Int_t nt=0; |
182 | Int_t jev=0; |
183 | Int_t j, kf, ks, imo; |
184 | kf=0; |
185 | |
186 | if(!particles) particles=new TClonesArray("TParticle",10000); |
187 | |
188 | fTrials=0; |
189 | for (j=0;j<3;j++) origin0[j]=fOrigin[j]; |
190 | if(fVertexSmear==kPerEvent) { |
191 | Rndm(random,6); |
192 | for (j=0;j<3;j++) { |
193 | origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())* |
194 | TMath::Sqrt(-2*TMath::Log(random[2*j+1])); |
195 | } |
196 | } |
197 | |
198 | while(1) |
199 | { |
200 | fHerwig->GenerateEvent(); |
201 | fTrials++; |
202 | fHerwig->ImportParticles(particles,"All"); |
203 | Int_t np = particles->GetEntriesFast()-1; |
204 | if (np == 0 ) continue; |
205 | |
206 | Int_t nc=0; |
207 | |
208 | Int_t * newPos = new Int_t[np]; |
209 | for (Int_t i = 0; i<np; i++) *(newPos+i)=-1; |
210 | |
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(); |
216 | if (ks != 3 && |
217 | KinematicSelection(iparticle,0)) |
218 | { |
219 | nc++; |
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; |
93831bcf |
230 | PushTrack(trackIt, iparent, kf, |
231 | p[0], p[1], p[2], p[3], |
232 | origin[0], origin[1], origin[2], |
233 | tof, |
234 | polar[0], polar[1], polar[2], |
235 | kPPrimary, nt, 1., ks); |
618e1dc0 |
236 | KeepTrack(nt); |
237 | newPos[i]=nt; |
238 | } // end of if: selection of particle |
239 | } // end of for: particle loop |
240 | if (newPos) delete[] newPos; |
618e1dc0 |
241 | // MakeHeader(); |
618e1dc0 |
242 | if (nc > 0) { |
243 | jev+=nc; |
244 | if (jev >= fNpart || fNpart == -1) { |
245 | fKineBias=Float_t(fNpart)/Float_t(fTrials); |
618e1dc0 |
246 | break; |
247 | } |
248 | } |
249 | } |
250 | SetHighWaterMark(nt); |
251 | // adjust weight due to kinematic selection |
252 | AdjustWeights(); |
253 | // get cross-section |
254 | fXsection=fHerwig->GetAVWGT(); |
255 | } |
256 | |
257 | void AliGenHerwig::AdjustWeights() |
258 | { |
259 | // Adjust the weights after generation of all events |
260 | TParticle *part; |
5d12ce38 |
261 | Int_t ntrack=gAlice->GetMCApp()->GetNtrack(); |
618e1dc0 |
262 | for (Int_t i=0; i<ntrack; i++) { |
5d12ce38 |
263 | part= gAlice->GetMCApp()->Particle(i); |
618e1dc0 |
264 | part->SetWeight(part->GetWeight()*fKineBias); |
265 | } |
266 | } |
267 | |
268 | |
269 | void AliGenHerwig::KeepFullEvent() |
270 | { |
271 | fKeep=1; |
272 | } |
273 | |
274 | Bool_t AliGenHerwig::DaughtersSelection(TParticle* iparticle, TClonesArray* particles) |
275 | { |
276 | // |
277 | // Looks recursively if one of the daughters has been selected |
278 | // |
279 | // printf("\n Consider daughters %d:",iparticle->GetPdgCode()); |
280 | Int_t imin=-1; |
281 | Int_t imax=-1; |
282 | Int_t i; |
283 | Bool_t hasDaughters= (iparticle->GetFirstDaughter() >=0); |
284 | Bool_t selected=kFALSE; |
285 | if (hasDaughters) { |
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; |
293 | } |
294 | if (DaughtersSelection(jparticle, particles)) {selected=kTRUE; break; } |
295 | } |
296 | } else { |
297 | return kFALSE; |
298 | } |
299 | |
300 | return selected; |
301 | } |
302 | |
303 | |
304 | Bool_t AliGenHerwig::SelectFlavor(Int_t pid) |
305 | { |
306 | // Select flavor of particle |
307 | // 0: all |
308 | // 4: charm and beauty |
309 | // 5: beauty |
310 | if (fFlavor == 0) return kTRUE; |
311 | |
312 | Int_t ifl=TMath::Abs(pid/100); |
313 | if (ifl > 10) ifl/=10; |
314 | return (fFlavor == ifl); |
315 | } |
316 | |
317 | Bool_t AliGenHerwig::Stable(TParticle* particle) |
318 | { |
319 | // Return true for a stable particle |
320 | // |
321 | Int_t kf = TMath::Abs(particle->GetPdgCode()); |
322 | |
323 | if ( (particle->GetFirstDaughter() < 0 ) || (kf == 1000*fFlavor+122)) |
324 | |
325 | { |
326 | return kTRUE; |
327 | } else { |
328 | return kFALSE; |
329 | } |
330 | } |
331 | |
332 | void AliGenHerwig::FinishRun() |
333 | { |
334 | fHerwig->Hwefin(); |
335 | } |
336 | |
337 | |
338 | AliGenHerwig& AliGenHerwig::operator=(const AliGenHerwig& rhs) |
339 | { |
340 | // Assignment operator |
014a9521 |
341 | rhs.Copy(*this); |
342 | return (*this); |
618e1dc0 |
343 | } |
344 | |
345 | |