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>
32 #include <TVirtualMC.h>
41 //------------------------------------------------------------
45 <img src="picts/AliGenParam.gif">
49 //____________________________________________________________
50 //____________________________________________________________
51 AliGenParam::AliGenParam()
53 // Deafault constructor
64 AliGenParam::AliGenParam(Int_t npart, AliGenLib * Library, Int_t param, char* tname):AliGenMC(npart)
66 // Constructor using number of particles parameterisation id and library
68 fTitle= "Particle Generator using pT and y parameterisation";
70 fPtParaFunc = Library->GetPt(param, tname);
71 fYParaFunc = Library->GetY (param, tname);
72 fIpParaFunc = Library->GetIp(param, tname);
82 //____________________________________________________________
84 AliGenParam::AliGenParam(Int_t npart, Int_t param, char* tname):AliGenMC(npart)
86 // Constructor using parameterisation id and number of particles
89 fTitle= "Particle Generator using pT and y parameterisation";
91 AliGenLib* pLibrary = new AliGenMUONlib();
93 fPtParaFunc = pLibrary->GetPt(param, tname);
94 fYParaFunc = pLibrary->GetY (param, tname);
95 fIpParaFunc = pLibrary->GetIp(param, tname);
102 for (Int_t i=0; i<5; i++) fChildSelect[i]=0;
105 SetChildMomentumRange();
108 SetChildThetaRange();
112 AliGenParam::AliGenParam(Int_t npart, Int_t param,
113 Double_t (*PtPara) (Double_t*, Double_t*),
114 Double_t (*YPara ) (Double_t* ,Double_t*),
115 Int_t (*IpPara) (TRandom *))
119 // Gines Martinez 1/10/99
121 fTitle= "Particle Generator using pT and y parameterisation";
123 fPtParaFunc = PtPara;
125 fIpParaFunc = IpPara;
132 for (Int_t i=0; i<5; i++) fChildSelect[i]=0;
135 SetChildMomentumRange();
138 SetChildThetaRange();
143 AliGenParam::AliGenParam(const AliGenParam & Param)
150 //____________________________________________________________
151 AliGenParam::~AliGenParam()
158 //____________________________________________________________
159 void AliGenParam::Init()
163 if (gMC) fDecayer = gMC->GetDecayer();
166 <img src="picts/AliGenParam.gif">
170 sprintf(name, "pt-parameterisation for %s", GetName());
172 fPtPara = new TF1(name, fPtParaFunc, fPtMin, fPtMax,0);
173 // Set representation precision to 10 MeV
174 Int_t npx= Int_t((fPtMax - fPtMin) / fDeltaPt);
176 fPtPara->SetNpx(npx);
178 sprintf(name, "y-parameterisation for %s", GetName());
179 fYPara = new TF1(name, fYParaFunc, fYMin, fYMax, 0);
181 sprintf(name, "pt-for-%s", GetName());
182 TF1 ptPara(name ,fPtParaFunc, 0, 15, 0);
183 sprintf(name, "y-for-%s", GetName());
184 TF1 yPara(name, fYParaFunc, -6, 6, 0);
191 fdNdy0=fYParaFunc(&y1,&y2);
193 // Integral over generation region
194 Float_t intYS = yPara.Integral(fYMin, fYMax);
195 Float_t intPt0 = ptPara.Integral(0,15);
196 Float_t intPtS = ptPara.Integral(fPtMin,fPtMax);
197 Float_t phiWgt=(fPhiMax-fPhiMin)/2./TMath::Pi();
198 if (fAnalog == kAnalog) {
199 fYWgt = intYS/fdNdy0;
200 fPtWgt = intPtS/intPt0;
201 fParentWeight = fYWgt*fPtWgt*phiWgt/fNpart;
203 fYWgt = intYS/fdNdy0;
204 fPtWgt = (fPtMax-fPtMin)/intPt0;
205 fParentWeight = fYWgt*fPtWgt*phiWgt/fNpart;
208 // particle decay related initialization
209 fDecayer->SetForceDecay(fForceDecay);
216 //____________________________________________________________
217 void AliGenParam::Generate()
220 // Generate 'npart' of light and heavy mesons (J/Psi, upsilon or phi, Pion,
221 // Kaons, Etas, Omegas) and Baryons (proton, antiprotons, neutrons and
222 // antineutrons in the the desired theta, phi and momentum windows;
223 // Gaussian smearing on the vertex is done if selected.
224 // The decay of heavy mesons is done using lujet,
225 // and the childern particle are tracked by GEANT
226 // However, light mesons are directly tracked by GEANT
227 // setting fForceDecay = nodecay (SetForceDecay(nodecay))
230 // Reinitialize decayer
233 Float_t polar[3]= {0,0,0}; // Polarisation of the parent particle (for GEANT tracking)
234 Float_t origin0[3]; // Origin of the generated parent particle (for GEANT tracking)
235 Float_t pt, pl, ptot; // Transverse, logitudinal and total momenta of the parent particle
236 Float_t phi, theta; // Phi and theta spherical angles of the parent particle momentum
238 och[3]; // Momentum, polarisation and origin of the children particles from lujet
243 static TClonesArray *particles;
245 if(!particles) particles = new TClonesArray("TParticle",1000);
247 TDatabasePDG *pDataBase = TDatabasePDG::Instance();
251 // Calculating vertex position per event
252 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
253 if(fVertexSmear==kPerEvent) {
255 for (j=0;j<3;j++) origin0[j]=fVertex[j];
260 // Generating fNpart particles
265 Int_t iPart = fIpParaFunc(fRandom);
266 fChildWeight=(fDecayer->GetPartialBranchingRatio(iPart))*fParentWeight;
267 TParticlePDG *particle = pDataBase->GetParticle(iPart);
268 Float_t am = particle->Mass();
273 phi=fPhiMin+random[0]*(fPhiMax-fPhiMin);
276 ty = TMath::TanH(fYPara->GetRandom());
279 if (fAnalog == kAnalog) {
280 pt=fPtPara->GetRandom();
284 pt=fPtMin+random[1]*(fPtMax-fPtMin);
286 wgtp=fParentWeight*fPtParaFunc(& ptd, &dummy);
287 wgtch=fChildWeight*fPtParaFunc(& ptd, &dummy);
289 xmt=sqrt(pt*pt+am*am);
290 if (TMath::Abs(ty)==1.) {
293 "Division by 0: Please check you rapidity range !");
296 pl=xmt*ty/sqrt(1.-ty*ty);
297 theta=TMath::ATan2(pt,pl);
299 if(theta<fThetaMin || theta>fThetaMax) continue;
300 ptot=TMath::Sqrt(pt*pt+pl*pl);
302 if(ptot<fPMin || ptot>fPMax) continue;
304 p[0]=pt*TMath::Cos(phi);
305 p[1]=pt*TMath::Sin(phi);
307 if(fVertexSmear==kPerTrack) {
311 fOrigin[j]+fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
312 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
316 // Looking at fForceDecay :
317 // if fForceDecay != none Primary particle decays using
318 // AliPythia and children are tracked by GEANT
320 // if fForceDecay == none Primary particle is tracked by GEANT
321 // (In the latest, make sure that GEANT actually does all the decays you want)
324 if (fForceDecay != kNoDecay) {
325 // Using lujet to decay particle
326 Float_t energy=TMath::Sqrt(ptot*ptot+am*am);
327 TLorentzVector pmom(p[0], p[1], p[2], energy);
328 fDecayer->Decay(iPart,&pmom);
330 // select decay particles
331 Int_t np=fDecayer->ImportParticles(particles);
333 // Selecting GeometryAcceptance for particles fPdgCodeParticleforAcceptanceCut;
334 if (fGeometryAcceptance)
335 if (!CheckAcceptanceGeometry(np,particles)) continue;
337 Int_t* pFlag = new Int_t[np];
338 Int_t* pParent = new Int_t[np];
339 Int_t* pSelected = new Int_t[np];
340 Int_t* trackIt = new Int_t[np];
342 for (i=0; i<np; i++) {
349 TParticle* iparticle = (TParticle *) particles->At(0);
351 for (i = 1; i<np ; i++) {
353 iparticle = (TParticle *) particles->At(i);
354 Int_t kf = iparticle->GetPdgCode();
355 Int_t ks = iparticle->GetStatusCode();
359 ipF = iparticle->GetFirstDaughter();
360 ipL = iparticle->GetLastDaughter();
361 if (ipF > 0) for (j=ipF-1; j<ipL; j++) pFlag[j]=1;
365 // flag decay products of particles with long life-time (c tau > .3 mum)
368 // TParticlePDG *particle = pDataBase->GetParticle(kf);
370 Double_t lifeTime = fDecayer->GetLifetime(kf);
371 // Double_t mass = particle->Mass();
372 // Double_t width = particle->Width();
373 if (lifeTime > (Double_t) fMaxLifeTime) {
374 ipF = iparticle->GetFirstDaughter();
375 ipL = iparticle->GetLastDaughter();
376 if (ipF > 0) for (j=ipF-1; j<ipL; j++) pFlag[j]=1;
385 if (ChildSelected(TMath::Abs(kf)) || fForceDecay == kAll && trackIt[i])
388 pc[0]=iparticle->Px();
389 pc[1]=iparticle->Py();
390 pc[2]=iparticle->Pz();
391 Bool_t childok = KinematicSelection(iparticle, 1);
402 } // if child selection
404 } // decay particle loop
405 } // if decay products
408 if ((fCutOnChild && ncsel >0) || !fCutOnChild){
412 PushTrack(0, -1, iPart, p, origin0, polar, 0, kPPrimary, nt, wgtp);
418 for (i = 1; i < np; i++) {
420 TParticle* iparticle = (TParticle *) particles->At(i);
421 Int_t kf = iparticle->GetPdgCode();
422 Int_t ipa = iparticle->GetFirstMother()-1;
424 och[0] = origin0[0]+iparticle->Vx()/10;
425 och[1] = origin0[1]+iparticle->Vy()/10;
426 och[2] = origin0[2]+iparticle->Vz()/10;
427 pc[0] = iparticle->Px();
428 pc[1] = iparticle->Py();
429 pc[2] = iparticle->Pz();
432 iparent = pParent[ipa];
437 PushTrack(fTrackIt*trackIt[i], iparent, kf,
439 0, kPDecay, nt, wgtch);
446 if (pFlag) delete[] pFlag;
447 if (pParent) delete[] pParent;
448 if (pSelected) delete[] pSelected;
449 if (trackIt) delete[] trackIt;
450 } // kinematic selection
451 else // nodecay option, so parent will be tracked by GEANT (pions, kaons, eta, omegas, baryons)
454 PushTrack(fTrackIt,-1,iPart,p,origin0,polar,0,kPPrimary,nt,wgtp);
460 SetHighWaterMark(nt);
463 void AliGenParam::Draw( const char * /*opt*/)
466 // Draw the pT and y Distributions
468 TCanvas *c0 = new TCanvas("c0","Canvas 0",400,10,600,700);
472 fPtPara->GetHistogram()->SetXTitle("p_{T} (GeV)");
475 fYPara->GetHistogram()->SetXTitle("y");
478 AliGenParam& AliGenParam::operator=(const AliGenParam& rhs)
480 // Assignment operator