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
24 #include "AliGenParam.h"
25 #include "AliDecayer.h"
26 #include "AliGenMUONlib.h"
28 #include <TParticle.h>
29 #include <TParticlePDG.h>
30 #include <TDatabasePDG.h>
31 #include <TLorentzVector.h>
39 //------------------------------------------------------------
43 <img src="picts/AliGenParam.gif">
47 //____________________________________________________________
48 //____________________________________________________________
49 AliGenParam::AliGenParam()
51 // Deafault constructor
62 AliGenParam::AliGenParam(Int_t npart, AliGenLib * Library, Int_t param, char* tname):AliGenMC(npart)
64 // Constructor using number of particles parameterisation id and library
66 fTitle= "Particle Generator using pT and y parameterisation";
68 fPtParaFunc = Library->GetPt(param, tname);
69 fYParaFunc = Library->GetY (param, tname);
70 fIpParaFunc = Library->GetIp(param, tname);
80 //____________________________________________________________
82 AliGenParam::AliGenParam(Int_t npart, Int_t param, char* tname):AliGenMC(npart)
84 // Constructor using parameterisation id and number of particles
87 fTitle= "Particle Generator using pT and y parameterisation";
89 AliGenLib* pLibrary = new AliGenMUONlib();
91 fPtParaFunc = pLibrary->GetPt(param, tname);
92 fYParaFunc = pLibrary->GetY (param, tname);
93 fIpParaFunc = pLibrary->GetIp(param, tname);
100 for (Int_t i=0; i<5; i++) fChildSelect[i]=0;
103 SetChildMomentumRange();
106 SetChildThetaRange();
110 AliGenParam::AliGenParam(Int_t npart, Int_t param,
111 Double_t (*PtPara) (Double_t*, Double_t*),
112 Double_t (*YPara ) (Double_t* ,Double_t*),
113 Int_t (*IpPara) (TRandom *))
117 // Gines Martinez 1/10/99
119 fTitle= "Particle Generator using pT and y parameterisation";
121 fPtParaFunc = PtPara;
123 fIpParaFunc = IpPara;
130 for (Int_t i=0; i<5; i++) fChildSelect[i]=0;
133 SetChildMomentumRange();
136 SetChildThetaRange();
141 AliGenParam::AliGenParam(const AliGenParam & Param)
148 //____________________________________________________________
149 AliGenParam::~AliGenParam()
156 //____________________________________________________________
157 void AliGenParam::Init()
161 if (gMC) fDecayer = gMC->GetDecayer();
164 <img src="picts/AliGenParam.gif">
168 fPtPara = new TF1("Pt-Parametrization",fPtParaFunc,fPtMin,fPtMax,0);
169 // Set representation precision to 10 MeV
170 Int_t npx= Int_t((fPtMax-fPtMin)/fDeltaPt);
172 fPtPara->SetNpx(npx);
174 fYPara = new TF1("Y -Parametrization",fYParaFunc,fYMin,fYMax,0);
175 TF1* ptPara = new TF1("Pt-Parametrization",fPtParaFunc,0,15,0);
176 TF1* yPara = new TF1("Y -Parametrization",fYParaFunc,-6,6,0);
183 fdNdy0=fYParaFunc(&y1,&y2);
185 // Integral over generation region
186 Float_t intYS = yPara ->Integral(fYMin, fYMax);
187 Float_t intPt0 = ptPara->Integral(0,15);
188 Float_t intPtS = ptPara->Integral(fPtMin,fPtMax);
189 Float_t phiWgt=(fPhiMax-fPhiMin)/2./TMath::Pi();
190 if (fAnalog == kAnalog) {
191 fYWgt = intYS/fdNdy0;
192 fPtWgt = intPtS/intPt0;
193 fParentWeight = fYWgt*fPtWgt*phiWgt/fNpart;
195 fYWgt = intYS/fdNdy0;
196 fPtWgt = (fPtMax-fPtMin)/intPt0;
197 fParentWeight = fYWgt*fPtWgt*phiWgt/fNpart;
200 // particle decay related initialization
201 fDecayer->SetForceDecay(fForceDecay);
208 //____________________________________________________________
209 void AliGenParam::Generate()
212 // Generate 'npart' of light and heavy mesons (J/Psi, upsilon or phi, Pion,
213 // Kaons, Etas, Omegas) and Baryons (proton, antiprotons, neutrons and
214 // antineutrons in the the desired theta, phi and momentum windows;
215 // Gaussian smearing on the vertex is done if selected.
216 // The decay of heavy mesons is done using lujet,
217 // and the childern particle are tracked by GEANT
218 // However, light mesons are directly tracked by GEANT
219 // setting fForceDecay = nodecay (SetForceDecay(nodecay))
222 // Reinitialize decayer
225 Float_t polar[3]= {0,0,0}; // Polarisation of the parent particle (for GEANT tracking)
226 Float_t origin0[3]; // Origin of the generated parent particle (for GEANT tracking)
227 Float_t pt, pl, ptot; // Transverse, logitudinal and total momenta of the parent particle
228 Float_t phi, theta; // Phi and theta spherical angles of the parent particle momentum
230 och[3]; // Momentum, polarisation and origin of the children particles from lujet
235 static TClonesArray *particles;
237 if(!particles) particles = new TClonesArray("TParticle",1000);
239 TDatabasePDG *pDataBase = TDatabasePDG::Instance();
243 // Calculating vertex position per event
244 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
245 if(fVertexSmear==kPerEvent) {
247 for (j=0;j<3;j++) origin0[j]=fVertex[j];
252 // Generating fNpart particles
257 Int_t iPart = fIpParaFunc(fRandom);
258 fChildWeight=(fDecayer->GetPartialBranchingRatio(iPart))*fParentWeight;
259 TParticlePDG *particle = pDataBase->GetParticle(iPart);
260 Float_t am = particle->Mass();
265 phi=fPhiMin+random[0]*(fPhiMax-fPhiMin);
268 ty = TMath::TanH(fYPara->GetRandom());
271 if (fAnalog == kAnalog) {
272 pt=fPtPara->GetRandom();
276 pt=fPtMin+random[1]*(fPtMax-fPtMin);
278 wgtp=fParentWeight*fPtParaFunc(& ptd, &dummy);
279 wgtch=fChildWeight*fPtParaFunc(& ptd, &dummy);
281 xmt=sqrt(pt*pt+am*am);
282 if (TMath::Abs(ty)==1.) {
285 "Division by 0: Please check you rapidity range !");
288 pl=xmt*ty/sqrt(1.-ty*ty);
289 theta=TMath::ATan2(pt,pl);
291 if(theta<fThetaMin || theta>fThetaMax) continue;
292 ptot=TMath::Sqrt(pt*pt+pl*pl);
294 if(ptot<fPMin || ptot>fPMax) continue;
296 p[0]=pt*TMath::Cos(phi);
297 p[1]=pt*TMath::Sin(phi);
299 if(fVertexSmear==kPerTrack) {
303 fOrigin[j]+fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
304 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
308 // Looking at fForceDecay :
309 // if fForceDecay != none Primary particle decays using
310 // AliPythia and children are tracked by GEANT
312 // if fForceDecay == none Primary particle is tracked by GEANT
313 // (In the latest, make sure that GEANT actually does all the decays you want)
316 if (fForceDecay != kNoDecay) {
317 // Using lujet to decay particle
318 Float_t energy=TMath::Sqrt(ptot*ptot+am*am);
319 TLorentzVector pmom(p[0], p[1], p[2], energy);
320 fDecayer->Decay(iPart,&pmom);
322 // select decay particles
323 Int_t np=fDecayer->ImportParticles(particles);
325 // Selecting GeometryAcceptance for particles fPdgCodeParticleforAcceptanceCut;
326 if (fGeometryAcceptance)
327 if (!CheckAcceptanceGeometry(np,particles)) continue;
329 Int_t* pFlag = new Int_t[np];
330 Int_t* pParent = new Int_t[np];
331 Int_t* pSelected = new Int_t[np];
332 Int_t* trackIt = new Int_t[np];
334 for (i=0; i<np; i++) {
341 TParticle* iparticle = (TParticle *) particles->At(0);
343 for (i = 1; i<np ; i++) {
345 iparticle = (TParticle *) particles->At(i);
346 Int_t kf = iparticle->GetPdgCode();
347 Int_t ks = iparticle->GetStatusCode();
351 ipF = iparticle->GetFirstDaughter();
352 ipL = iparticle->GetLastDaughter();
353 if (ipF > 0) for (j=ipF-1; j<ipL; j++) pFlag[j]=1;
357 // flag decay products of particles with long life-time (c tau > .3 mum)
360 // TParticlePDG *particle = pDataBase->GetParticle(kf);
362 Double_t lifeTime = fDecayer->GetLifetime(kf);
363 // Double_t mass = particle->Mass();
364 // Double_t width = particle->Width();
365 if (lifeTime > (Double_t) fMaxLifeTime) {
366 ipF = iparticle->GetFirstDaughter();
367 ipL = iparticle->GetLastDaughter();
368 if (ipF > 0) for (j=ipF-1; j<ipL; j++) pFlag[j]=1;
377 if (ChildSelected(TMath::Abs(kf)) || fForceDecay == kAll && trackIt[i])
380 pc[0]=iparticle->Px();
381 pc[1]=iparticle->Py();
382 pc[2]=iparticle->Pz();
383 Bool_t childok = KinematicSelection(iparticle, 1);
394 } // if child selection
396 } // decay particle loop
397 } // if decay products
400 if ((fCutOnChild && ncsel >0) || !fCutOnChild){
404 PushTrack(0, -1, iPart, p, origin0, polar, 0, kPPrimary, nt, wgtp);
410 for (i = 1; i < np; i++) {
412 TParticle* iparticle = (TParticle *) particles->At(i);
413 Int_t kf = iparticle->GetPdgCode();
414 Int_t ipa = iparticle->GetFirstMother()-1;
416 och[0] = origin0[0]+iparticle->Vx()/10;
417 och[1] = origin0[1]+iparticle->Vy()/10;
418 och[2] = origin0[2]+iparticle->Vz()/10;
419 pc[0] = iparticle->Px();
420 pc[1] = iparticle->Py();
421 pc[2] = iparticle->Pz();
424 iparent = pParent[ipa];
429 PushTrack(fTrackIt*trackIt[i], iparent, kf,
431 0, kPDecay, nt, wgtch);
438 if (pFlag) delete[] pFlag;
439 if (pParent) delete[] pParent;
440 if (pSelected) delete[] pSelected;
441 if (trackIt) delete[] trackIt;
442 } // kinematic selection
443 else // nodecay option, so parent will be tracked by GEANT (pions, kaons, eta, omegas, baryons)
446 PushTrack(fTrackIt,-1,iPart,p,origin0,polar,0,kPPrimary,nt,wgtp);
452 SetHighWaterMark(nt);
455 void AliGenParam::Draw()
458 // Draw the pT and y Distributions
460 TCanvas *c0 = new TCanvas("c0","Canvas 0",400,10,600,700);
464 fPtPara->GetHistogram()->SetXTitle("p_{T} (GeV)");
467 fYPara->GetHistogram()->SetXTitle("y");
470 AliGenParam& AliGenParam::operator=(const AliGenParam& rhs)
472 // Assignment operator