1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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
25 #include <TClonesArray.h>
26 #include <TDatabasePDG.h>
29 #include <TLorentzVector.h>
31 #include <TParticle.h>
32 #include <TParticlePDG.h>
34 #include <TVirtualMC.h>
36 #include "AliDecayer.h"
37 #include "AliGenMUONlib.h"
38 #include "AliGenParam.h"
41 #include "AliGenEventHeader.h"
45 //------------------------------------------------------------
49 <img src="picts/AliGenParam.gif">
53 //____________________________________________________________
54 AliGenParam::AliGenParam()
73 // Default constructor
75 //____________________________________________________________
76 AliGenParam::AliGenParam(Int_t npart, const AliGenLib * Library, Int_t param, const char* tname)
78 fPtParaFunc(Library->GetPt(param, tname)),
79 fYParaFunc (Library->GetY (param, tname)),
80 fIpParaFunc(Library->GetIp(param, tname)),
81 fV2ParaFunc(Library->GetV2(param, tname)),
96 // Constructor using number of particles parameterisation id and library
98 fTitle= "Particle Generator using pT and y parameterisation";
102 //____________________________________________________________
103 AliGenParam::AliGenParam(Int_t npart, Int_t param, const char* tname, const char* name):
123 // Constructor using parameterisation id and number of particles
126 fTitle= "Particle Generator using pT and y parameterisation";
128 AliGenLib* pLibrary = new AliGenMUONlib();
129 fPtParaFunc = pLibrary->GetPt(param, tname);
130 fYParaFunc = pLibrary->GetY (param, tname);
131 fIpParaFunc = pLibrary->GetIp(param, tname);
132 fV2ParaFunc = pLibrary->GetV2(param, tname);
136 for (Int_t i=0; i<5; i++) fChildSelect[i]=0;
139 SetChildMomentumRange();
142 SetChildThetaRange();
144 //____________________________________________________________
146 AliGenParam::AliGenParam(Int_t npart, Int_t param,
147 Double_t (*PtPara) (const Double_t*, const Double_t*),
148 Double_t (*YPara ) (const Double_t* ,const Double_t*),
149 Double_t (*V2Para) (const Double_t* ,const Double_t*),
150 Int_t (*IpPara) (TRandom *))
172 // Gines Martinez 1/10/99
174 fTitle= "Particle Generator using pT and y parameterisation";
178 for (Int_t i=0; i<5; i++) fChildSelect[i]=0;
181 SetChildMomentumRange();
184 SetChildThetaRange();
187 //____________________________________________________________
188 AliGenParam::~AliGenParam()
197 //____________________________________________________________
198 void AliGenParam::Init()
202 if (gMC) fDecayer = gMC->GetDecayer();
205 <img src="picts/AliGenParam.gif">
209 snprintf(name, 256, "pt-parameterisation for %s", GetName());
211 if (fPtPara) fPtPara->Delete();
212 fPtPara = new TF1(name, fPtParaFunc, fPtMin, fPtMax,0);
213 gROOT->GetListOfFunctions()->Remove(fPtPara);
214 // Set representation precision to 10 MeV
215 Int_t npx= Int_t((fPtMax - fPtMin) / fDeltaPt);
217 fPtPara->SetNpx(npx);
219 snprintf(name, 256, "y-parameterisation for %s", GetName());
220 if (fYPara) fYPara->Delete();
221 fYPara = new TF1(name, fYParaFunc, fYMin, fYMax, 0);
222 gROOT->GetListOfFunctions()->Remove(fYPara);
224 snprintf(name, 256, "v2-parameterisation for %s", GetName());
225 if (fV2Para) fV2Para->Delete();
226 fV2Para = new TF1(name, fV2ParaFunc, fPtMin, fPtMax, 0);
227 // fV2Para = new TF1(name, "2*[0]/(1+TMath::Exp([1]*([2]-x)))-[0]", fPtMin, fPtMax);
228 // fV2Para->SetParameter(0, 0.236910);
229 // fV2Para->SetParameter(1, 1.71122);
230 // fV2Para->SetParameter(2, 0.0827617);
231 //gROOT->GetListOfFunctions()->Remove(fV2Para); //TR: necessary?
233 snprintf(name, 256, "dNdPhi for %s", GetName());
234 if (fdNdPhi) fdNdPhi->Delete();
235 fdNdPhi = new TF1(name, "1+2*[0]*TMath::Cos(2*(x-[1]))", fPhiMin, fPhiMax);
236 //gROOT->GetListOfFunctions()->Remove(fdNdPhi); //TR: necessary?
238 snprintf(name, 256, "pt-for-%s", GetName());
239 TF1 ptPara(name ,fPtParaFunc, 0, 15, 0);
240 snprintf(name, 256, "y-for-%s", GetName());
241 TF1 yPara(name, fYParaFunc, -6, 6, 0);
248 fdNdy0=fYParaFunc(&y1,&y2);
250 // Integral over generation region
251 Float_t intYS = yPara.Integral(fYMin, fYMax,(Double_t*) 0x0,1.e-6);
252 Float_t intPt0 = ptPara.Integral(0,15,(Double_t *) 0x0,1.e-6);
253 Float_t intPtS = ptPara.Integral(fPtMin,fPtMax,(Double_t*) 0x0,1.e-6);
254 Float_t phiWgt=(fPhiMax-fPhiMin)/2./TMath::Pi(); //TR: should probably be done differently in case of anisotropic phi...
255 if (fAnalog == kAnalog) {
256 fYWgt = intYS/fdNdy0;
257 fPtWgt = intPtS/intPt0;
258 fParentWeight = fYWgt*fPtWgt*phiWgt/fNpart;
260 fYWgt = intYS/fdNdy0;
261 fPtWgt = (fPtMax-fPtMin)/intPt0;
262 fParentWeight = fYWgt*fPtWgt*phiWgt/fNpart;
265 // particle decay related initialization
266 fDecayer->SetForceDecay(fForceDecay);
273 //____________________________________________________________
274 void AliGenParam::Generate()
277 // Generate 1 event (see Generate(Int_t ntimes) for details
281 //____________________________________________________________
282 void AliGenParam::GenerateN(Int_t ntimes)
285 // Generate ntimes*'npart' light and heavy mesons (J/Psi, upsilon or phi, Pion,
286 // Kaons, Etas, Omegas) and Baryons (proton, antiprotons, neutrons and
287 // antineutrons in the the desired theta, phi and momentum windows;
288 // Gaussian smearing on the vertex is done if selected.
289 // The decay of heavy mesons is done using lujet,
290 // and the childern particle are tracked by GEANT
291 // However, light mesons are directly tracked by GEANT
292 // setting fForceDecay = nodecay (SetForceDecay(nodecay))
295 // Reinitialize decayer
296 fDecayer->SetForceDecay(fForceDecay);
300 Float_t polar[3]= {0,0,0}; // Polarisation of the parent particle (for GEANT tracking)
301 Float_t origin0[3]; // Origin of the generated parent particle (for GEANT tracking)
302 Float_t time0; // Time0 of the generated parent particle
303 Float_t pt, pl, ptot; // Transverse, logitudinal and total momenta of the parent particle
304 Float_t phi, theta; // Phi and theta spherical angles of the parent particle momentum
306 och[3]; // Momentum, polarisation and origin of the children particles from lujet
311 static TClonesArray *particles;
313 if(!particles) particles = new TClonesArray("TParticle",1000);
315 TDatabasePDG *pDataBase = TDatabasePDG::Instance();
319 // Calculating vertex position per event
320 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
322 if(fVertexSmear==kPerEvent) {
324 for (j=0;j<3;j++) origin0[j]=fVertex[j];
330 // Generating fNpart particles
333 Int_t nGen = fNpart*ntimes;
338 Int_t iPart = fIpParaFunc(fRandom);
339 fChildWeight=(fDecayer->GetPartialBranchingRatio(iPart))*fParentWeight;
340 TParticlePDG *particle = pDataBase->GetParticle(iPart);
341 Float_t am = particle->Mass();
346 ty = TMath::TanH(fYPara->GetRandom());
349 if (fAnalog == kAnalog) {
350 pt=fPtPara->GetRandom();
354 pt=fPtMin+random[1]*(fPtMax-fPtMin);
356 wgtp=fParentWeight*fPtParaFunc(& ptd, &dummy);
357 wgtch=fChildWeight*fPtParaFunc(& ptd, &dummy);
359 xmt=sqrt(pt*pt+am*am);
360 if (TMath::Abs(ty)==1.) {
363 "Division by 0: Please check you rapidity range !");
368 // phi=fEvPlane; //align first particle of each event with event plane
370 double v2 = fV2Para->Eval(pt);
371 fdNdPhi->SetParameter(0,v2);
372 fdNdPhi->SetParameter(1,fEvPlane);
373 phi=fdNdPhi->GetRandom();
376 pl=xmt*ty/sqrt((1.-ty)*(1.+ty));
377 theta=TMath::ATan2(pt,pl);
379 if(theta<fThetaMin || theta>fThetaMax) continue;
380 ptot=TMath::Sqrt(pt*pt+pl*pl);
382 if(ptot<fPMin || ptot>fPMax) continue;
384 p[0]=pt*TMath::Cos(phi);
385 p[1]=pt*TMath::Sin(phi);
387 if(fVertexSmear==kPerTrack) {
391 fOrigin[j]+fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
392 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
395 time0 = fTimeOrigin + fOsigma[2]/TMath::Ccgs()*
396 TMath::Cos(2*random[0]*TMath::Pi())*
397 TMath::Sqrt(-2*TMath::Log(random[1]));
400 // Looking at fForceDecay :
401 // if fForceDecay != none Primary particle decays using
402 // AliPythia and children are tracked by GEANT
404 // if fForceDecay == none Primary particle is tracked by GEANT
405 // (In the latest, make sure that GEANT actually does all the decays you want)
407 Bool_t decayed = kFALSE;
410 if (fForceDecay != kNoDecay) {
411 // Using lujet to decay particle
412 Float_t energy=TMath::Sqrt(ptot*ptot+am*am);
413 TLorentzVector pmom(p[0], p[1], p[2], energy);
414 fDecayer->Decay(iPart,&pmom);
416 // select decay particles
417 Int_t np=fDecayer->ImportParticles(particles);
419 // Selecting GeometryAcceptance for particles fPdgCodeParticleforAcceptanceCut;
420 if (fGeometryAcceptance)
421 if (!CheckAcceptanceGeometry(np,particles)) continue;
423 Int_t* pFlag = new Int_t[np];
424 Int_t* pParent = new Int_t[np];
425 Int_t* pSelected = new Int_t[np];
426 Int_t* trackIt = new Int_t[np];
428 for (i=0; i<np; i++) {
436 TParticle* iparticle = 0;
438 for (i = 1; i<np ; i++) {
440 iparticle = (TParticle *) particles->At(i);
441 Int_t kf = iparticle->GetPdgCode();
442 Int_t ks = iparticle->GetStatusCode();
446 ipF = iparticle->GetFirstDaughter();
447 ipL = iparticle->GetLastDaughter();
448 if (ipF > 0) for (j=ipF-1; j<ipL; j++) pFlag[j]=1;
452 // flag decay products of particles with long life-time (c tau > .3 mum)
455 // TParticlePDG *particle = pDataBase->GetParticle(kf);
457 Double_t lifeTime = fDecayer->GetLifetime(kf);
458 // Double_t mass = particle->Mass();
459 // Double_t width = particle->Width();
460 if (lifeTime > (Double_t) fMaxLifeTime) {
461 ipF = iparticle->GetFirstDaughter();
462 ipL = iparticle->GetLastDaughter();
463 if (ipF > 0) for (j=ipF-1; j<ipL; j++) pFlag[j]=1;
472 if ((ChildSelected(TMath::Abs(kf)) || fForceDecay == kAll || fSelectAll) && trackIt[i])
475 pc[0]=iparticle->Px();
476 pc[1]=iparticle->Py();
477 pc[2]=iparticle->Pz();
478 Bool_t childok = KinematicSelection(iparticle, 1);
489 } // if child selection
491 } // decay particle loop
492 } // if decay products
495 if ((fCutOnChild && ncsel >0) || !fCutOnChild){
501 PushTrack(0, -1, iPart, p, origin0, polar, time0, kPPrimary, nt, wgtp, ((decayed)? 11 : 1));
509 for (i = 1; i < np; i++) {
511 TParticle* iparticle = (TParticle *) particles->At(i);
512 Int_t kf = iparticle->GetPdgCode();
513 Int_t ksc = iparticle->GetStatusCode();
514 Int_t jpa = iparticle->GetFirstMother()-1;
516 och[0] = origin0[0]+iparticle->Vx();
517 och[1] = origin0[1]+iparticle->Vy();
518 och[2] = origin0[2]+iparticle->Vz();
519 pc[0] = iparticle->Px();
520 pc[1] = iparticle->Py();
521 pc[2] = iparticle->Pz();
524 iparent = pParent[jpa];
529 PushTrack(fTrackIt * trackIt[i], iparent, kf,
531 time0 + iparticle->T(), kPDecay, nt, wgtch, ksc);
539 if (pFlag) delete[] pFlag;
540 if (pParent) delete[] pParent;
541 if (pSelected) delete[] pSelected;
542 if (trackIt) delete[] trackIt;
543 } // kinematic selection
544 else // nodecay option, so parent will be tracked by GEANT (pions, kaons, eta, omegas, baryons)
547 PushTrack(fTrackIt,-1,iPart,p,origin0,polar,time0,kPPrimary,nt,wgtp, 1);
555 SetHighWaterMark(nt);
557 AliGenEventHeader* header = new AliGenEventHeader("PARAM");
558 header->SetPrimaryVertex(fVertex);
559 header->SetInteractionTime(fTime);
560 header->SetNProduced(fNprimaries);
563 //____________________________________________________________________________________
564 Float_t AliGenParam::GetRelativeArea(Float_t ptMin, Float_t ptMax, Float_t yMin, Float_t yMax, Float_t phiMin, Float_t phiMax)
567 // Normalisation for selected kinematic region
570 fPtPara->Integral(ptMin,ptMax,(Double_t *)0,1.e-6) / fPtPara->Integral( fPtPara->GetXmin(), fPtPara->GetXmax(),(Double_t *)0,1.e-6) *
571 fYPara->Integral(yMin,yMax,(Double_t *)0,1.e-6)/fYPara->Integral(fYPara->GetXmin(),fYPara->GetXmax(),(Double_t *)0,1.e-6) *
572 (phiMax-phiMin)/360.;
573 return TMath::Abs(ratio);
576 //____________________________________________________________________________________
578 void AliGenParam::Draw( const char * /*opt*/)
581 // Draw the pT and y Distributions
583 TCanvas *c0 = new TCanvas("c0","Canvas 0",400,10,600,700);
587 fPtPara->GetHistogram()->SetXTitle("p_{T} (GeV)");
590 fYPara->GetHistogram()->SetXTitle("y");