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