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