Added PID task, some fixes for coding conventions
[u/mrichter/AliRoot.git] / THydjet / AliGenHydjet.cxx
CommitLineData
cb220f83 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
16/* $Id$ */
17
18// Generator using Hydjet as an external generator
19// The main Hydjet options are accessable for the user through this interface.
20// Uses the THydjet implementation of TGenerator.
21// Author:
22// Rafael Diaz Valdes (rafael.diaz.valdes@cern.ch)
23//
24#include <Riostream.h>
25#include <THydjet.h>
26#include <TParticle.h>
27#include <TClonesArray.h>
28
29#include "AliGenHydjet.h"
30#include "AliGenHydjetEventHeader.h"
31#include "AliRun.h"
32#include "AliPythiaRndm.h"
33
34ClassImp(AliGenHydjet)
35
36AliGenHydjet::AliGenHydjet(Int_t npart) :
37 AliGenMC(npart),
38 //initial parameters
cb220f83 39 fFrame("CMS"), // Reference frame
40 fAtomicWeigth(207), // Projectile-Target atomic weight
41 fIfbtype(0), // centrality type
42 fFixImpactParam(0), // fixed impact parameter
43 fMinImpactParam(0.), // minimum impact parameter
44 fMaxImpactParam(1.), // maximum impact parameter
45 fSoftMult(20000), // mean soft multiplicity
46 //hydro parameters
47 fJetProd(2), // flag Jet production (nhsel)
48 fYflow(5.), // max longitudinal flow
49 fTflow(1.), // max transverse flow
50 fSoftFract(1.), // Soft multiplicity fraction
51 // PYTHIA parameters
52 fDijetProd(1), // flag dijet production
53 fMinPtHard(10.), // min pt hard
54 fStructFunction(7), // Structure Function (default CTEQ5M)
55 fMultipleInt(0), // flag multiple interaction
56
57 fHydjet(0),
58
59 fSelectAll(0),
60 fFlavor(0)
61
62{
63// Default PbPb collisions at 5. 5 TeV
64//
e7c989e4 65 fEnergyCMS = 5500.; //Energy cms
cb220f83 66 fName = "Hydjet";
67 fTitle = "Particle Generator using Hydjet";
9731de01 68 // Set random number generator
69 if (!AliPythiaRndm::GetPythiaRandom())
70 AliPythiaRndm::SetPythiaRandom(GetRandom());
cb220f83 71}
72
73AliGenHydjet::~AliGenHydjet()
74{
75// Destructor
cb220f83 76}
77
78void AliGenHydjet::Init()
79{
80// Initialisation
81
82 SetMC(new THydjet(fEnergyCMS, fFrame,fAtomicWeigth,
83 fIfbtype,fMinImpactParam, fMaxImpactParam,
84 fFixImpactParam,fSoftMult));
85
86 fHydjet=(THydjet*) fMCEvGen;
87
88 // init hydro common blocks
89 fHydjet->SetNHSEL(fJetProd);
90 fHydjet->SetYLFL(fYflow);
91 fHydjet->SetYTFL(fTflow);
92 fHydjet->SetFPART(fSoftFract);
93 // init PYTHIA common block
94 fHydjet->SetMSEL(fDijetProd);
95 fHydjet->SetPTMIN(fMinPtHard);
96 fHydjet->SetCKIN(3,fMinPtHard);
97 fHydjet->SetMSTP(51,fStructFunction);
98 fHydjet->SetMSTP(81,0);
99 fHydjet->SetMSTU(21,1);
100 fHydjet->SetPARU(14,1.);
101
102// Initialize Hydjet
103 fHydjet->Initialize();
104
105}
106
107void AliGenHydjet::Generate()
108{
109
110///////////////////////////////////////////////////////////////////////////////////////////
111 Float_t polar[3] = {0,0,0};
112 Float_t origin[3] = {0,0,0};
113 Float_t origin0[3] = {0,0,0};
114 Float_t p[3];
115 Float_t tof;
116
117// converts from mm/c to s
118 const Float_t kconv = 0.001/2.999792458e8;
119//
120 Int_t nt = 0;
121 Int_t j, kf, ks, imo;
122 kf = 0;
123
124 for (j = 0;j < 3; j++) origin0[j] = fOrigin[j];
125 if(fVertexSmear == kPerEvent) {
126 Vertex();
127 for (j=0; j < 3; j++) origin0[j] = fVertex[j];
128 }
129
130 while(1)
131 {
132// Generate one event
133 fHydjet->GenerateEvent();
9731de01 134 fHydjet->ImportParticles(&fParticles,"All");
cb220f83 135
9731de01 136 Int_t np = fParticles.GetEntriesFast();
cb220f83 137 printf("\n **************************************************%d\n",np);
138 Int_t nc = 0;
139 if (np == 0 ) continue;
140 Int_t i;
141 Int_t* pSelected = new Int_t[np];
142
143 for (i = 0; i < np; i++) {
144 pSelected[i] = 0;
145 }
146
147// Get event vertex
148 fVertex[0] = origin0[0];
149 fVertex[1] = origin0[1];
150 fVertex[2] = origin0[2];
151
152//
153// Now select the final state particles
154//
155
156 for(i = 0; i<np; i++){
9731de01 157 TParticle * iparticle = (TParticle *) fParticles.At(i);
cb220f83 158 // Is this a final state particle ?
159 if (!Stable(iparticle)) continue;
160 Bool_t selected = kTRUE;
161 kf = iparticle->GetPdgCode();
162 ks = iparticle->GetStatusCode();
163 if(!fSelectAll) selected = KinematicSelection(iparticle,0)&&SelectFlavor(kf);
164 // Put particle on the stack if selected
165 if(selected) {
166 nc++;
167 pSelected[i] = 1;
168 } // selected
169 } // particle loop final state
170
171
172//
173// Write particles to stack
174//
175
176 for(i = 0; i<np; i++) {
9731de01 177 TParticle * iparticle = (TParticle *) fParticles.At(i);
cb220f83 178 Bool_t hasDaughter = (iparticle->GetFirstDaughter() > 0);
179 if(pSelected[i]){
180 kf = iparticle->GetPdgCode();
181 ks = iparticle->GetStatusCode();
182 p[0] = iparticle->Px();
183 p[1] = iparticle->Py();
184 p[2] = iparticle->Pz();
185 origin[0] = fVertex[0]+iparticle->Vx()/10;
186 origin[1] = fVertex[1]+iparticle->Vy()/10;
187 origin[2] = fVertex[2]+iparticle->Vz()/10;
188 tof = kconv*iparticle->T();
189
190 imo = -1;
191 //imo = iparticle->GetFirstMother();
192 //if(imo == 0) imo =-1;
193 Bool_t tFlag = (fTrackIt && !hasDaughter);
194 PushTrack(tFlag,imo,kf,p,origin,polar,tof,kPNoProcess,nt, 1., ks);
195 KeepTrack(nt);
196 } // if selected
197 } // particle loop
198 delete[] pSelected;
199
200 printf("\n I've put %i particles on the stack \n",nc);
201 if (nc > 0) break;
202 } // event loop
203 MakeHeader();
204}
205
206
207Bool_t AliGenHydjet::SelectFlavor(Int_t pid)
208{
209// Select flavor of particle
210// 0: all
211// 4: charm and beauty
212// 5: beauty
213 Bool_t res = 0;
214 if (fFlavor == 0) {
215 res = kTRUE;
216 } else {
217 Int_t ifl = TMath::Abs(pid/100);
218 if (ifl > 10) ifl/=10;
219 res = (fFlavor == ifl);
220 }
221 return res;
222}
223
224Bool_t AliGenHydjet::Stable(TParticle* particle) const
225{
226// Return true for a stable particle
227 if (particle->GetFirstDaughter() == 0 )
228 {
229 return kTRUE;
230 } else {
231 return kFALSE;
232 }
233}
234
235
236///////////////////////////////////
237void AliGenHydjet::MakeHeader()
238{
239// Builds the event header, to be called after each event
240 AliGenEventHeader* header = new AliGenHydjetEventHeader("Hydjet");
241 ((AliGenHydjetEventHeader*) header)->SetNProduced(fHydjet->GetN());
242 ((AliGenHydjetEventHeader*) header)->SetImpactParameter(fHydjet->GetBGEN());
243 ((AliGenHydjetEventHeader*) header)->SetNbcol(fHydjet->GetNBCOL());
244 ((AliGenHydjetEventHeader*) header)->SetNpart(fHydjet->GetNPART());
245 ((AliGenHydjetEventHeader*) header)->SetNpyt(fHydjet->GetNPYT());
246 ((AliGenHydjetEventHeader*) header)->SetNhyd(fHydjet->GetNHYD());
247 // draw generation values
248 cout << "*********Hyflow ********** " << endl;
249 cout << " YTFL " << fHydjet->GetYTFL() << endl;
250 cout << " YLFL " << fHydjet->GetYLFL() << endl;
251 cout << " FPART " << fHydjet->GetFPART() << endl;
252 cout << "*********Hyjpar ********* " << endl;
253 cout << " GetNHSEL() " << fHydjet->GetNHSEL() << endl;
254 cout << " GetPTMIN() " << fHydjet->GetPTMIN() << endl;
255 cout << " GetNJET() " << fHydjet->GetNJET() << endl;
256 cout << "*********Hyfpar ********* " << endl;
257 cout << " GetBGEN() " << fHydjet->GetBGEN() << endl;
258 cout << " GetNBCOL() " << fHydjet->GetNBCOL() << endl;
259 cout << " GetNPART() " << fHydjet->GetNPART() << endl;
260 cout << " GetNPYT() " << fHydjet->GetNPYT() << endl;
261 cout << " GetNHYD() " << fHydjet->GetNHYD() << endl;
262
263
264// Event Vertex
265 header->SetPrimaryVertex(fVertex);
266 AddHeader(header);
267 fCollisionGeometry = (AliGenHydjetEventHeader*) header;
268}
269
270void AliGenHydjet::AddHeader(AliGenEventHeader* header)
271{
272 // Passes header either to the container or to gAlice
273 if (fContainer) {
274 fContainer->AddHeader(header);
275 } else {
276 gAlice->SetGenEventHeader(header);
277 }
278}
279
280
281void AliGenHydjet::Copy(TObject &) const
282{
283 Fatal("Copy","Not implemented!\n");
284}
285
286AliGenHydjet& AliGenHydjet::operator=(const AliGenHydjet& rhs)
287{
288 rhs.Copy(*this);
289 return (*this);
290}
291