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