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():
70 // Default constructor
72 //____________________________________________________________
73 AliGenParam::AliGenParam(Int_t npart, const AliGenLib * Library, Int_t param, const char* tname)
75 fPtParaFunc(Library->GetPt(param, tname)),
76 fYParaFunc (Library->GetY (param, tname)),
77 fIpParaFunc(Library->GetIp(param, tname)),
90 // Constructor using number of particles parameterisation id and library
92 fTitle= "Particle Generator using pT and y parameterisation";
96 //____________________________________________________________
97 AliGenParam::AliGenParam(Int_t npart, Int_t param, const char* tname, const char* name):
114 // Constructor using parameterisation id and number of particles
117 fTitle= "Particle Generator using pT and y parameterisation";
119 AliGenLib* pLibrary = new AliGenMUONlib();
120 fPtParaFunc = pLibrary->GetPt(param, tname);
121 fYParaFunc = pLibrary->GetY (param, tname);
122 fIpParaFunc = pLibrary->GetIp(param, tname);
126 for (Int_t i=0; i<5; i++) fChildSelect[i]=0;
129 SetChildMomentumRange();
132 SetChildThetaRange();
134 //____________________________________________________________
136 AliGenParam::AliGenParam(Int_t npart, Int_t param,
137 Double_t (*PtPara) (const Double_t*, const Double_t*),
138 Double_t (*YPara ) (const Double_t* ,const Double_t*),
139 Int_t (*IpPara) (TRandom *))
158 // Gines Martinez 1/10/99
160 fTitle= "Particle Generator using pT and y parameterisation";
164 for (Int_t i=0; i<5; i++) fChildSelect[i]=0;
167 SetChildMomentumRange();
170 SetChildThetaRange();
173 //____________________________________________________________
174 AliGenParam::~AliGenParam()
181 //____________________________________________________________
182 void AliGenParam::Init()
186 if (gMC) fDecayer = gMC->GetDecayer();
189 <img src="picts/AliGenParam.gif">
193 snprintf(name, 256, "pt-parameterisation for %s", GetName());
195 if (fPtPara) fPtPara->Delete();
196 fPtPara = new TF1(name, fPtParaFunc, fPtMin, fPtMax,0);
197 gROOT->GetListOfFunctions()->Remove(fPtPara);
198 // Set representation precision to 10 MeV
199 Int_t npx= Int_t((fPtMax - fPtMin) / fDeltaPt);
201 fPtPara->SetNpx(npx);
203 snprintf(name, 256, "y-parameterisation for %s", GetName());
204 if (fYPara) fYPara->Delete();
205 fYPara = new TF1(name, fYParaFunc, fYMin, fYMax, 0);
206 gROOT->GetListOfFunctions()->Remove(fYPara);
209 snprintf(name, 256, "pt-for-%s", GetName());
210 TF1 ptPara(name ,fPtParaFunc, 0, 15, 0);
211 snprintf(name, 256, "y-for-%s", GetName());
212 TF1 yPara(name, fYParaFunc, -6, 6, 0);
219 fdNdy0=fYParaFunc(&y1,&y2);
221 // Integral over generation region
222 Float_t intYS = yPara.Integral(fYMin, fYMax,(Double_t*) 0x0,1.e-6);
223 Float_t intPt0 = ptPara.Integral(0,15,(Double_t *) 0x0,1.e-6);
224 Float_t intPtS = ptPara.Integral(fPtMin,fPtMax,(Double_t*) 0x0,1.e-6);
225 Float_t phiWgt=(fPhiMax-fPhiMin)/2./TMath::Pi();
226 if (fAnalog == kAnalog) {
227 fYWgt = intYS/fdNdy0;
228 fPtWgt = intPtS/intPt0;
229 fParentWeight = fYWgt*fPtWgt*phiWgt/fNpart;
231 fYWgt = intYS/fdNdy0;
232 fPtWgt = (fPtMax-fPtMin)/intPt0;
233 fParentWeight = fYWgt*fPtWgt*phiWgt/fNpart;
236 // particle decay related initialization
237 fDecayer->SetForceDecay(fForceDecay);
244 //____________________________________________________________
245 void AliGenParam::Generate()
248 // Generate 'npart' of light and heavy mesons (J/Psi, upsilon or phi, Pion,
249 // Kaons, Etas, Omegas) and Baryons (proton, antiprotons, neutrons and
250 // antineutrons in the the desired theta, phi and momentum windows;
251 // Gaussian smearing on the vertex is done if selected.
252 // The decay of heavy mesons is done using lujet,
253 // and the childern particle are tracked by GEANT
254 // However, light mesons are directly tracked by GEANT
255 // setting fForceDecay = nodecay (SetForceDecay(nodecay))
258 // Reinitialize decayer
259 fDecayer->SetForceDecay(fForceDecay);
263 Float_t polar[3]= {0,0,0}; // Polarisation of the parent particle (for GEANT tracking)
264 Float_t origin0[3]; // Origin of the generated parent particle (for GEANT tracking)
265 Float_t pt, pl, ptot; // Transverse, logitudinal and total momenta of the parent particle
266 Float_t phi, theta; // Phi and theta spherical angles of the parent particle momentum
268 och[3]; // Momentum, polarisation and origin of the children particles from lujet
273 static TClonesArray *particles;
275 if(!particles) particles = new TClonesArray("TParticle",1000);
277 TDatabasePDG *pDataBase = TDatabasePDG::Instance();
281 // Calculating vertex position per event
282 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
283 if(fVertexSmear==kPerEvent) {
285 for (j=0;j<3;j++) origin0[j]=fVertex[j];
290 // Generating fNpart particles
297 Int_t iPart = fIpParaFunc(fRandom);
298 fChildWeight=(fDecayer->GetPartialBranchingRatio(iPart))*fParentWeight;
299 TParticlePDG *particle = pDataBase->GetParticle(iPart);
300 Float_t am = particle->Mass();
305 phi=fPhiMin+random[0]*(fPhiMax-fPhiMin);
308 ty = TMath::TanH(fYPara->GetRandom());
311 if (fAnalog == kAnalog) {
312 pt=fPtPara->GetRandom();
316 pt=fPtMin+random[1]*(fPtMax-fPtMin);
318 wgtp=fParentWeight*fPtParaFunc(& ptd, &dummy);
319 wgtch=fChildWeight*fPtParaFunc(& ptd, &dummy);
321 xmt=sqrt(pt*pt+am*am);
322 if (TMath::Abs(ty)==1.) {
325 "Division by 0: Please check you rapidity range !");
328 pl=xmt*ty/sqrt((1.-ty)*(1.+ty));
329 theta=TMath::ATan2(pt,pl);
331 if(theta<fThetaMin || theta>fThetaMax) continue;
332 ptot=TMath::Sqrt(pt*pt+pl*pl);
334 if(ptot<fPMin || ptot>fPMax) continue;
336 p[0]=pt*TMath::Cos(phi);
337 p[1]=pt*TMath::Sin(phi);
339 if(fVertexSmear==kPerTrack) {
343 fOrigin[j]+fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
344 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
348 // Looking at fForceDecay :
349 // if fForceDecay != none Primary particle decays using
350 // AliPythia and children are tracked by GEANT
352 // if fForceDecay == none Primary particle is tracked by GEANT
353 // (In the latest, make sure that GEANT actually does all the decays you want)
355 Bool_t decayed = kFALSE;
358 if (fForceDecay != kNoDecay) {
359 // Using lujet to decay particle
360 Float_t energy=TMath::Sqrt(ptot*ptot+am*am);
361 TLorentzVector pmom(p[0], p[1], p[2], energy);
362 fDecayer->Decay(iPart,&pmom);
364 // select decay particles
365 Int_t np=fDecayer->ImportParticles(particles);
367 // Selecting GeometryAcceptance for particles fPdgCodeParticleforAcceptanceCut;
368 if (fGeometryAcceptance)
369 if (!CheckAcceptanceGeometry(np,particles)) continue;
371 Int_t* pFlag = new Int_t[np];
372 Int_t* pParent = new Int_t[np];
373 Int_t* pSelected = new Int_t[np];
374 Int_t* trackIt = new Int_t[np];
376 for (i=0; i<np; i++) {
384 TParticle* iparticle = 0;
386 for (i = 1; i<np ; i++) {
388 iparticle = (TParticle *) particles->At(i);
389 Int_t kf = iparticle->GetPdgCode();
390 Int_t ks = iparticle->GetStatusCode();
394 ipF = iparticle->GetFirstDaughter();
395 ipL = iparticle->GetLastDaughter();
396 if (ipF > 0) for (j=ipF-1; j<ipL; j++) pFlag[j]=1;
400 // flag decay products of particles with long life-time (c tau > .3 mum)
403 // TParticlePDG *particle = pDataBase->GetParticle(kf);
405 Double_t lifeTime = fDecayer->GetLifetime(kf);
406 // Double_t mass = particle->Mass();
407 // Double_t width = particle->Width();
408 if (lifeTime > (Double_t) fMaxLifeTime) {
409 ipF = iparticle->GetFirstDaughter();
410 ipL = iparticle->GetLastDaughter();
411 if (ipF > 0) for (j=ipF-1; j<ipL; j++) pFlag[j]=1;
420 if ((ChildSelected(TMath::Abs(kf)) || fForceDecay == kAll || fSelectAll) && trackIt[i])
423 pc[0]=iparticle->Px();
424 pc[1]=iparticle->Py();
425 pc[2]=iparticle->Pz();
426 Bool_t childok = KinematicSelection(iparticle, 1);
437 } // if child selection
439 } // decay particle loop
440 } // if decay products
443 if ((fCutOnChild && ncsel >0) || !fCutOnChild){
449 PushTrack(0, -1, iPart, p, origin0, polar, 0, kPPrimary, nt, wgtp, ((decayed)? 11 : 1));
457 for (i = 1; i < np; i++) {
459 TParticle* iparticle = (TParticle *) particles->At(i);
460 Int_t kf = iparticle->GetPdgCode();
461 Int_t ksc = iparticle->GetStatusCode();
462 Int_t jpa = iparticle->GetFirstMother()-1;
464 och[0] = origin0[0]+iparticle->Vx()/10;
465 och[1] = origin0[1]+iparticle->Vy()/10;
466 och[2] = origin0[2]+iparticle->Vz()/10;
467 pc[0] = iparticle->Px();
468 pc[1] = iparticle->Py();
469 pc[2] = iparticle->Pz();
472 iparent = pParent[jpa];
477 PushTrack(fTrackIt * trackIt[i], iparent, kf,
479 0, kPDecay, nt, wgtch, ksc);
487 if (pFlag) delete[] pFlag;
488 if (pParent) delete[] pParent;
489 if (pSelected) delete[] pSelected;
490 if (trackIt) delete[] trackIt;
491 } // kinematic selection
492 else // nodecay option, so parent will be tracked by GEANT (pions, kaons, eta, omegas, baryons)
495 PushTrack(fTrackIt,-1,iPart,p,origin0,polar,0,kPPrimary,nt,wgtp, 1);
503 SetHighWaterMark(nt);
505 AliGenEventHeader* header = new AliGenEventHeader("PARAM");
506 header->SetPrimaryVertex(fVertex);
507 header->SetNProduced(fNprimaries);
510 //____________________________________________________________________________________
511 Float_t AliGenParam::GetRelativeArea(Float_t ptMin, Float_t ptMax, Float_t yMin, Float_t yMax, Float_t phiMin, Float_t phiMax)
514 // Normalisation for selected kinematic region
517 fPtPara->Integral(ptMin,ptMax,(Double_t *)0,1.e-6) / fPtPara->Integral( fPtPara->GetXmin(), fPtPara->GetXmax(),(Double_t *)0,1.e-6) *
518 fYPara->Integral(yMin,yMax,(Double_t *)0,1.e-6)/fYPara->Integral(fYPara->GetXmin(),fYPara->GetXmax(),(Double_t *)0,1.e-6) *
519 (phiMax-phiMin)/360.;
520 return TMath::Abs(ratio);
523 //____________________________________________________________________________________
525 void AliGenParam::Draw( const char * /*opt*/)
528 // Draw the pT and y Distributions
530 TCanvas *c0 = new TCanvas("c0","Canvas 0",400,10,600,700);
534 fPtPara->GetHistogram()->SetXTitle("p_{T} (GeV)");
537 fYPara->GetHistogram()->SetXTitle("y");