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