updating
[u/mrichter/AliRoot.git] / EVGEN / AliGenParam.cxx
CommitLineData
4c039060 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
88cb7938 16/* $Id$ */
6d4dd317 17
18// Class to generate particles from using paramtrized pT and y distributions.
19// Distributions are obtained from pointer to object of type AliGenLib.
20// (For example AliGenMUONlib)
21// Decays are performed using Pythia.
22// andreas.morsch@cern.ch
23
fe4da5cc 24#include "AliGenParam.h"
2904363f 25#include "AliDecayer.h"
fe4da5cc 26#include "AliGenMUONlib.h"
27#include "AliRun.h"
1578254f 28#include <TParticle.h>
fa480368 29#include <TParticlePDG.h>
30#include <TDatabasePDG.h>
31#include <TLorentzVector.h>
5d12ce38 32#include <TVirtualMC.h>
fa480368 33
f87cfe57 34#include <TF1.h>
5bd39445 35#include <TCanvas.h>
36#include <TH1.h>
2ad38d56 37#include <TMath.h>
5d12ce38 38#include "AliMC.h"
fe4da5cc 39
40ClassImp(AliGenParam)
41
42//------------------------------------------------------------
43
44 //Begin_Html
45 /*
1439f98e 46 <img src="picts/AliGenParam.gif">
fe4da5cc 47 */
48 //End_Html
49
50//____________________________________________________________
fe4da5cc 51AliGenParam::AliGenParam()
fe4da5cc 52{
b22ee262 53// Deafault constructor
54 fPtPara = 0;
55 fYPara = 0;
34f60c01 56 fParam = 0;
57 fAnalog = kAnalog;
b22ee262 58 SetDeltaPt();
2685bf00 59 fDecayer = 0;
8b31bfac 60
61
b22ee262 62}
2ad38d56 63//____________________________________________________________
fff02fee 64AliGenParam::AliGenParam(Int_t npart, AliGenLib * Library, Int_t param, char* tname):AliGenMC(npart)
b22ee262 65{
66// Constructor using number of particles parameterisation id and library
8b31bfac 67 fName = "Param";
68 fTitle= "Particle Generator using pT and y parameterisation";
b22ee262 69
70 fPtParaFunc = Library->GetPt(param, tname);
71 fYParaFunc = Library->GetY (param, tname);
72 fIpParaFunc = Library->GetIp(param, tname);
73
74 fPtPara = 0;
75 fYPara = 0;
76 fParam = param;
34f60c01 77 fAnalog = kAnalog;
b22ee262 78 SetForceDecay();
b22ee262 79 SetDeltaPt();
fe4da5cc 80}
fe4da5cc 81//____________________________________________________________
2ad38d56 82AliGenParam::AliGenParam(Int_t npart, Int_t param, const char* tname, const char* name):AliGenMC(npart)
fe4da5cc 83{
b22ee262 84// Constructor using parameterisation id and number of particles
8b31bfac 85//
2ad38d56 86 fName = name;
87 fTitle= "Particle Generator using pT and y parameterisation";
8b31bfac 88
675e9664 89 AliGenLib* pLibrary = new AliGenMUONlib();
b22ee262 90
675e9664 91 fPtParaFunc = pLibrary->GetPt(param, tname);
92 fYParaFunc = pLibrary->GetY (param, tname);
93 fIpParaFunc = pLibrary->GetIp(param, tname);
b22ee262 94
95 fPtPara = 0;
96 fYPara = 0;
97 fParam = param;
34f60c01 98 fAnalog = kAnalog;
b22ee262 99 fChildSelect.Set(5);
100 for (Int_t i=0; i<5; i++) fChildSelect[i]=0;
101 SetForceDecay();
102 SetCutOnChild();
103 SetChildMomentumRange();
104 SetChildPtRange();
105 SetChildPhiRange();
106 SetChildThetaRange();
107 SetDeltaPt();
fe4da5cc 108}
2ad38d56 109//____________________________________________________________
fe4da5cc 110
34f60c01 111AliGenParam::AliGenParam(Int_t npart, Int_t param,
886b6f73 112 Double_t (*PtPara) (Double_t*, Double_t*),
113 Double_t (*YPara ) (Double_t* ,Double_t*),
65fb704d 114 Int_t (*IpPara) (TRandom *))
fff02fee 115 :AliGenMC(npart)
886b6f73 116{
749070b6 117// Constructor
28337bc1 118// Gines Martinez 1/10/99
8b31bfac 119 fName = "Param";
120 fTitle= "Particle Generator using pT and y parameterisation";
121
886b6f73 122 fPtParaFunc = PtPara;
123 fYParaFunc = YPara;
124 fIpParaFunc = IpPara;
28337bc1 125//
886b6f73 126 fPtPara = 0;
127 fYPara = 0;
128 fParam = param;
34f60c01 129 fAnalog = kAnalog;
886b6f73 130 fChildSelect.Set(5);
131 for (Int_t i=0; i<5; i++) fChildSelect[i]=0;
132 SetForceDecay();
133 SetCutOnChild();
749070b6 134 SetChildMomentumRange();
135 SetChildPtRange();
136 SetChildPhiRange();
137 SetChildThetaRange();
138 SetDeltaPt();
886b6f73 139}
140
f87cfe57 141
6d4dd317 142AliGenParam::AliGenParam(const AliGenParam & Param)
198bb1c7 143 :AliGenMC(Param)
f87cfe57 144{
198bb1c7 145// Copy constructor
6d4dd317 146 Param.Copy(*this);
f87cfe57 147}
148
fe4da5cc 149//____________________________________________________________
150AliGenParam::~AliGenParam()
151{
749070b6 152// Destructor
fe4da5cc 153 delete fPtPara;
154 delete fYPara;
155}
156
157//____________________________________________________________
158void AliGenParam::Init()
159{
749070b6 160// Initialisation
fa480368 161
2904363f 162 if (gMC) fDecayer = gMC->GetDecayer();
fe4da5cc 163 //Begin_Html
164 /*
1439f98e 165 <img src="picts/AliGenParam.gif">
fe4da5cc 166 */
167 //End_Html
c5c3e4b0 168 char name[256];
169 sprintf(name, "pt-parameterisation for %s", GetName());
170
2ad38d56 171 if (fPtPara) fPtPara->Delete();
c5c3e4b0 172 fPtPara = new TF1(name, fPtParaFunc, fPtMin, fPtMax,0);
749070b6 173// Set representation precision to 10 MeV
c5c3e4b0 174 Int_t npx= Int_t((fPtMax - fPtMin) / fDeltaPt);
749070b6 175
176 fPtPara->SetNpx(npx);
c5c3e4b0 177
178 sprintf(name, "y-parameterisation for %s", GetName());
2ad38d56 179 if (fYPara) fYPara->Delete();
c5c3e4b0 180 fYPara = new TF1(name, fYParaFunc, fYMin, fYMax, 0);
749070b6 181
c5c3e4b0 182 sprintf(name, "pt-for-%s", GetName());
183 TF1 ptPara(name ,fPtParaFunc, 0, 15, 0);
184 sprintf(name, "y-for-%s", GetName());
185 TF1 yPara(name, fYParaFunc, -6, 6, 0);
b7601ac4 186
fe4da5cc 187//
188// dN/dy| y=0
749070b6 189 Double_t y1=0;
190 Double_t y2=0;
191
192 fdNdy0=fYParaFunc(&y1,&y2);
fe4da5cc 193//
194// Integral over generation region
2a336e15 195 Float_t intYS = yPara.Integral(fYMin, fYMax);
196 Float_t intPt0 = ptPara.Integral(0,15);
197 Float_t intPtS = ptPara.Integral(fPtMin,fPtMax);
749070b6 198 Float_t phiWgt=(fPhiMax-fPhiMin)/2./TMath::Pi();
34f60c01 199 if (fAnalog == kAnalog) {
749070b6 200 fYWgt = intYS/fdNdy0;
201 fPtWgt = intPtS/intPt0;
202 fParentWeight = fYWgt*fPtWgt*phiWgt/fNpart;
203 } else {
204 fYWgt = intYS/fdNdy0;
205 fPtWgt = (fPtMax-fPtMin)/intPt0;
206 fParentWeight = fYWgt*fPtWgt*phiWgt/fNpart;
207 }
fe4da5cc 208//
209// particle decay related initialization
00d6ce7d 210 fDecayer->SetForceDecay(fForceDecay);
fa480368 211 fDecayer->Init();
00d6ce7d 212
fe4da5cc 213//
fff02fee 214 AliGenMC::Init();
fe4da5cc 215}
216
217//____________________________________________________________
218void AliGenParam::Generate()
219{
28337bc1 220//
221// Generate 'npart' of light and heavy mesons (J/Psi, upsilon or phi, Pion,
222// Kaons, Etas, Omegas) and Baryons (proton, antiprotons, neutrons and
223// antineutrons in the the desired theta, phi and momentum windows;
224// Gaussian smearing on the vertex is done if selected.
cc5d764c 225// The decay of heavy mesons is done using lujet,
226// and the childern particle are tracked by GEANT
227// However, light mesons are directly tracked by GEANT
228// setting fForceDecay = nodecay (SetForceDecay(nodecay))
28337bc1 229//
771bbe45 230//
231// Reinitialize decayer
2ad38d56 232 fDecayer->SetForceDecay(fForceDecay);
233 fDecayer->Init();
234
771bbe45 235//
28337bc1 236 Float_t polar[3]= {0,0,0}; // Polarisation of the parent particle (for GEANT tracking)
237 Float_t origin0[3]; // Origin of the generated parent particle (for GEANT tracking)
238 Float_t pt, pl, ptot; // Transverse, logitudinal and total momenta of the parent particle
239 Float_t phi, theta; // Phi and theta spherical angles of the parent particle momentum
240 Float_t p[3], pc[3],
fff02fee 241 och[3]; // Momentum, polarisation and origin of the children particles from lujet
2d7a47be 242 Double_t ty, xmt;
fff02fee 243 Int_t nt, i, j;
fe4da5cc 244 Float_t wgtp, wgtch;
245 Double_t dummy;
09fd3ea2 246 static TClonesArray *particles;
fe4da5cc 247 //
fff02fee 248 if(!particles) particles = new TClonesArray("TParticle",1000);
8b31bfac 249
349be858 250 TDatabasePDG *pDataBase = TDatabasePDG::Instance();
fe4da5cc 251 //
252 Float_t random[6];
28337bc1 253
254// Calculating vertex position per event
fe4da5cc 255 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
aee8290b 256 if(fVertexSmear==kPerEvent) {
d9ea0e3b 257 Vertex();
258 for (j=0;j<3;j++) origin0[j]=fVertex[j];
fe4da5cc 259 }
d9ea0e3b 260
21aaa175 261 Int_t ipa=0;
fff02fee 262
28337bc1 263// Generating fNpart particles
21aaa175 264 while (ipa<fNpart) {
cc5d764c 265 while(1) {
fe4da5cc 266//
2ad38d56 267// particle type
65fb704d 268 Int_t iPart = fIpParaFunc(fRandom);
fa480368 269 fChildWeight=(fDecayer->GetPartialBranchingRatio(iPart))*fParentWeight;
675e9664 270 TParticlePDG *particle = pDataBase->GetParticle(iPart);
fa480368 271 Float_t am = particle->Mass();
8b31bfac 272
65fb704d 273 Rndm(random,2);
fe4da5cc 274//
275// phi
276 phi=fPhiMin+random[0]*(fPhiMax-fPhiMin);
277//
278// y
2d7a47be 279 ty = TMath::TanH(fYPara->GetRandom());
fe4da5cc 280//
281// pT
34f60c01 282 if (fAnalog == kAnalog) {
fe4da5cc 283 pt=fPtPara->GetRandom();
284 wgtp=fParentWeight;
285 wgtch=fChildWeight;
286 } else {
287 pt=fPtMin+random[1]*(fPtMax-fPtMin);
288 Double_t ptd=pt;
289 wgtp=fParentWeight*fPtParaFunc(& ptd, &dummy);
290 wgtch=fChildWeight*fPtParaFunc(& ptd, &dummy);
291 }
292 xmt=sqrt(pt*pt+am*am);
2d7a47be 293 if (TMath::Abs(ty)==1.) {
294 ty=0.;
295 Fatal("AliGenParam",
296 "Division by 0: Please check you rapidity range !");
297 }
298
fe4da5cc 299 pl=xmt*ty/sqrt(1.-ty*ty);
300 theta=TMath::ATan2(pt,pl);
cc5d764c 301// Cut on theta
fe4da5cc 302 if(theta<fThetaMin || theta>fThetaMax) continue;
303 ptot=TMath::Sqrt(pt*pt+pl*pl);
cc5d764c 304// Cut on momentum
fe4da5cc 305 if(ptot<fPMin || ptot>fPMax) continue;
fff02fee 306//
fe4da5cc 307 p[0]=pt*TMath::Cos(phi);
308 p[1]=pt*TMath::Sin(phi);
309 p[2]=pl;
aee8290b 310 if(fVertexSmear==kPerTrack) {
65fb704d 311 Rndm(random,6);
fe4da5cc 312 for (j=0;j<3;j++) {
313 origin0[j]=
314 fOrigin[j]+fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
315 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
316 }
317 }
28337bc1 318
319// Looking at fForceDecay :
cc5d764c 320// if fForceDecay != none Primary particle decays using
321// AliPythia and children are tracked by GEANT
28337bc1 322//
cc5d764c 323// if fForceDecay == none Primary particle is tracked by GEANT
324// (In the latest, make sure that GEANT actually does all the decays you want)
fe4da5cc 325//
fff02fee 326
34f60c01 327 if (fForceDecay != kNoDecay) {
28337bc1 328// Using lujet to decay particle
886b6f73 329 Float_t energy=TMath::Sqrt(ptot*ptot+am*am);
fa480368 330 TLorentzVector pmom(p[0], p[1], p[2], energy);
331 fDecayer->Decay(iPart,&pmom);
fe4da5cc 332//
cc5d764c 333// select decay particles
fa480368 334 Int_t np=fDecayer->ImportParticles(particles);
1242532d 335
336 // Selecting GeometryAcceptance for particles fPdgCodeParticleforAcceptanceCut;
337 if (fGeometryAcceptance)
338 if (!CheckAcceptanceGeometry(np,particles)) continue;
886b6f73 339 Int_t ncsel=0;
fff02fee 340 Int_t* pFlag = new Int_t[np];
341 Int_t* pParent = new Int_t[np];
342 Int_t* pSelected = new Int_t[np];
343 Int_t* trackIt = new Int_t[np];
344
345 for (i=0; i<np; i++) {
346 pFlag[i] = 0;
347 pSelected[i] = 0;
348 pParent[i] = -1;
349 }
350
6ba00c52 351 if (np >1) {
352 TParticle* iparticle = (TParticle *) particles->At(0);
fff02fee 353 Int_t ipF, ipL;
354 for (i = 1; i<np ; i++) {
355 trackIt[i] = 1;
6ba00c52 356 iparticle = (TParticle *) particles->At(i);
357 Int_t kf = iparticle->GetPdgCode();
fff02fee 358 Int_t ks = iparticle->GetStatusCode();
359// flagged particle
360
361 if (pFlag[i] == 1) {
fff02fee 362 ipF = iparticle->GetFirstDaughter();
363 ipL = iparticle->GetLastDaughter();
364 if (ipF > 0) for (j=ipF-1; j<ipL; j++) pFlag[j]=1;
365 continue;
366 }
367
368// flag decay products of particles with long life-time (c tau > .3 mum)
369
370 if (ks != 1) {
2d7a47be 371// TParticlePDG *particle = pDataBase->GetParticle(kf);
fff02fee 372
373 Double_t lifeTime = fDecayer->GetLifetime(kf);
2d7a47be 374// Double_t mass = particle->Mass();
375// Double_t width = particle->Width();
47fc6bd5 376 if (lifeTime > (Double_t) fMaxLifeTime) {
fff02fee 377 ipF = iparticle->GetFirstDaughter();
378 ipL = iparticle->GetLastDaughter();
379 if (ipF > 0) for (j=ipF-1; j<ipL; j++) pFlag[j]=1;
380 } else{
381 trackIt[i] = 0;
382 pSelected[i] = 1;
383 }
384 } // ks==1 ?
fe4da5cc 385//
386// children
47fc6bd5 387
fff02fee 388 if (ChildSelected(TMath::Abs(kf)) || fForceDecay == kAll && trackIt[i])
6ba00c52 389 {
6ba00c52 390 if (fCutOnChild) {
fff02fee 391 pc[0]=iparticle->Px();
392 pc[1]=iparticle->Py();
393 pc[2]=iparticle->Pz();
394 Bool_t childok = KinematicSelection(iparticle, 1);
395 if(childok) {
396 pSelected[i] = 1;
6ba00c52 397 ncsel++;
398 } else {
399 ncsel=-1;
400 break;
401 } // child kine cuts
402 } else {
fff02fee 403 pSelected[i] = 1;
886b6f73 404 ncsel++;
6ba00c52 405 } // if child selection
406 } // select muon
407 } // decay particle loop
408 } // if decay products
409
886b6f73 410 Int_t iparent;
411 if ((fCutOnChild && ncsel >0) || !fCutOnChild){
412 ipa++;
21aaa175 413//
fff02fee 414// Parent
642f15cf 415 PushTrack(0, -1, iPart, p, origin0, polar, 0, kPPrimary, nt, wgtp);
fff02fee 416 pParent[0] = nt;
a99cf51f 417 KeepTrack(nt);
fff02fee 418//
419// Decay Products
420//
421 for (i = 1; i < np; i++) {
422 if (pSelected[i]) {
423 TParticle* iparticle = (TParticle *) particles->At(i);
424 Int_t kf = iparticle->GetPdgCode();
425 Int_t ipa = iparticle->GetFirstMother()-1;
426
427 och[0] = origin0[0]+iparticle->Vx()/10;
428 och[1] = origin0[1]+iparticle->Vy()/10;
429 och[2] = origin0[2]+iparticle->Vz()/10;
430 pc[0] = iparticle->Px();
431 pc[1] = iparticle->Py();
432 pc[2] = iparticle->Pz();
433
434 if (ipa > -1) {
435 iparent = pParent[ipa];
436 } else {
437 iparent = -1;
438 }
1242532d 439
642f15cf 440 PushTrack(fTrackIt*trackIt[i], iparent, kf,
fff02fee 441 pc, och, polar,
442 0, kPDecay, nt, wgtch);
443 pParent[i] = nt;
a99cf51f 444 KeepTrack(nt);
8b31bfac 445 } // Selected
446 } // Particle loop
28337bc1 447 } // Decays by Lujet
8b31bfac 448 particles->Clear();
fff02fee 449 if (pFlag) delete[] pFlag;
450 if (pParent) delete[] pParent;
451 if (pSelected) delete[] pSelected;
8b31bfac 452 if (trackIt) delete[] trackIt;
21aaa175 453 } // kinematic selection
28337bc1 454 else // nodecay option, so parent will be tracked by GEANT (pions, kaons, eta, omegas, baryons)
455 {
5d12ce38 456 gAlice->GetMCApp()->
642f15cf 457 PushTrack(fTrackIt,-1,iPart,p,origin0,polar,0,kPPrimary,nt,wgtp);
28337bc1 458 ipa++;
459 }
fe4da5cc 460 break;
21aaa175 461 } // while
fe4da5cc 462 } // event loop
a99cf51f 463 SetHighWaterMark(nt);
fe4da5cc 464}
2ad38d56 465//____________________________________________________________________________________
466Float_t AliGenParam::GetRelativeArea(Float_t ptMin, Float_t ptMax, Float_t yMin, Float_t yMax, Float_t phiMin, Float_t phiMax)
467{
468//
469// Normalisation for selected kinematic region
470//
471 Float_t ratio =
472 fPtPara->Integral(ptMin,ptMax) / fPtPara->Integral( fPtPara->GetXmin(), fPtPara->GetXmax()) *
473 fYPara->Integral(yMin,yMax)/fYPara->Integral(fYPara->GetXmin(),fYPara->GetXmax()) *
474 (phiMax-phiMin)/360.;
475 return TMath::Abs(ratio);
476}
477
478//____________________________________________________________________________________
fe4da5cc 479
dc1d768c 480void AliGenParam::Draw( const char * /*opt*/)
5bd39445 481{
482 //
483 // Draw the pT and y Distributions
484 //
485 TCanvas *c0 = new TCanvas("c0","Canvas 0",400,10,600,700);
486 c0->Divide(2,1);
487 c0->cd(1);
488 fPtPara->Draw();
489 fPtPara->GetHistogram()->SetXTitle("p_{T} (GeV)");
490 c0->cd(2);
491 fYPara->Draw();
492 fYPara->GetHistogram()->SetXTitle("y");
493}
494
f87cfe57 495AliGenParam& AliGenParam::operator=(const AliGenParam& rhs)
496{
497// Assignment operator
198bb1c7 498 rhs.Copy(*this);
f87cfe57 499 return *this;
500}
501
fe4da5cc 502
503