fParticles-> replaced by fParticles.
[u/mrichter/AliRoot.git] / TTherminator / AliGenTherminator.cxx
CommitLineData
2e967919 1// ALICE event generator based on the THERMINATOR model
2// It reads the test output of the model and puts it onto
3// the stack
ae89e57a 4// It has an option to use the Lhyquid3D input freeze-out
5// hypersurface
2e967919 6// Author: Adam.Kisiel@cern.ch
7
8#include <iostream>
9#include <fstream>
10#include <sstream>
11#include <TClonesArray.h>
12#include <TMCProcess.h>
13#include <TDatabasePDG.h>
14#include <TParticle.h>
15
16#include "AliConst.h"
17#include "AliDecayer.h"
18#include "AliGenEventHeader.h"
9abb118d 19#include "AliGenHijingEventHeader.h"
2e967919 20#include "AliGenTherminator.h"
21#include "AliLog.h"
22#include "AliRun.h"
23
24ClassImp(AliGenTherminator)
25
26using namespace std;
27
28AliGenTherminator::AliGenTherminator():
29 AliGenMC(),
30 fNt(0),
31 fEventNumber(0),
32 fFileName(""),
33 fFreezeOutModel(""),
34 fTemperature(0.1656),
35 fMiuI(-0.0009),
36 fMiuS(0.0),
37 fMiuB(0.0008),
38 fAlfaRange(6.0),
39 fRapRange(4.0),
40 fRhoMax(8.0),
41 fTau(8.0),
42 fBWA(0.0),
43 fBWVt(1.41),
44 fBWDelay(0.0)
45{
46 // Default constructor
2e967919 47}
48AliGenTherminator::AliGenTherminator(Int_t npart):
49 AliGenMC(npart),
50 fNt(0),
51 fEventNumber(0),
52 fFileName(""),
53 fFreezeOutModel(""),
54 fTemperature(0.1656),
55 fMiuI(-0.0009),
56 fMiuS(0.0),
57 fMiuB(0.0008),
58 fAlfaRange(6.0),
59 fRapRange(4.0),
60 fRhoMax(8.0),
61 fTau(8.0),
62 fBWA(0.0),
63 fBWVt(1.41),
64 fBWDelay(0.0)
65{
66 // Constructor specifying the size of the particle table
2e967919 67 fNprimaries = 0;
68}
69
70AliGenTherminator::~AliGenTherminator()
71{
72 // AliGenMC::~AliGenMC();
73 // if (fTherminator) delete fTherminator;
74}
75
76void AliGenTherminator::Generate()
77{
78 // Run single event generation with the Therminator model
79 AliWarning("Generating event from AliGenTherminator");
80
81 Float_t polar[3] = {0,0,0};
82 Float_t origin[3] = {0,0,0};
83 Float_t origin0[3] = {0,0,0};
84 Float_t p[3];
85 Float_t mass, energy;
86
87 Int_t nt = 0;
88 Int_t j, kf, ks, imo;
89 kf = 0;
90
91 Vertex();
92 for (j=0; j < 3; j++) origin0[j] = fVertex[j];
93
94 // Generate one event
95
96 ((TTherminator *) fMCEvGen)->GenerateEvent();
97 AliWarning("Generated");
8507138f 98 ((TTherminator *) fMCEvGen)->ImportParticles(&fParticles);
2e967919 99
8507138f 100 Int_t np = fParticles.GetEntriesFast();
2e967919 101 AliWarning(Form("Imported %d particles", np));
102
103 TParticle *iparticle;
9abb118d 104 Double_t evrot = gRandom->Rndm()*TMath::Pi();
2e967919 105
106 for (int i = 0; i < np; i++) {
8507138f 107 iparticle = (TParticle *) fParticles.At(i);
2e967919 108 Bool_t hasMother = (iparticle->GetFirstMother() >=0);
109 Bool_t hasDaughter = (iparticle->GetFirstDaughter() >=0);
110
111 kf = iparticle->GetPdgCode();
112 ks = iparticle->GetStatusCode();
9abb118d 113 Double_t aphi = TMath::ATan2(iparticle->Py(), iparticle->Px());
114 Double_t arho = TMath::Hypot(iparticle->Px(), iparticle->Py());
115 p[0] = arho*TMath::Cos(aphi + evrot);
116 p[1] = arho*TMath::Sin(aphi + evrot);
117// p[0] = iparticle->Px();
118// p[1] = iparticle->Py();
2e967919 119 p[2] = iparticle->Pz();
120 mass = TDatabasePDG::Instance()->GetParticle(kf)->Mass();
121 energy = sqrt(mass*mass + p[0]*p[0] + p[1]*p[1] + p[2]*p[2]);
e2867a14 122
123 Double_t vphi = TMath::ATan2(iparticle->Vy(), iparticle->Vx());
124 Double_t vrho = TMath::Hypot(iparticle->Vx(), iparticle->Vy());
125 origin[0] = origin0[0]+vrho*TMath::Cos(vphi + evrot);
126 origin[1] = origin0[1]+vrho*TMath::Sin(vphi + evrot);
2e967919 127 origin[2] = origin0[2]+iparticle->Vz();
128
129 imo = -1;
130 TParticle* mother = 0;
131 if (hasMother) {
132 imo = iparticle->GetFirstMother();
8507138f 133 mother = (TParticle *) fParticles.At(imo);
2e967919 134 } // if has mother
135 Bool_t tFlag = (!hasDaughter);
136
137 printf("Pushing Track %d with status %d mother %d\n", kf, tFlag, imo);
138 PushTrack(tFlag,imo,kf,
139 p[0],p[1],p[2],energy,
140 origin[0],origin[1],origin[2],iparticle->T()*0.197327*1e-13/300000000,
141 polar[0],polar[1],polar[2],
142 hasMother ? kPDecay:kPNoProcess,nt);
143
144 fNprimaries++;
145 KeepTrack(nt);
146 }
147
148 SetHighWaterMark(fNprimaries);
149
150 TArrayF eventVertex;
151 eventVertex.Set(3);
152 eventVertex[0] = origin0[0];
153 eventVertex[1] = origin0[1];
154 eventVertex[2] = origin0[2];
155
9abb118d 156// Builds the event header, to be called after each event
157 AliGenEventHeader* header = new AliGenHijingEventHeader("Therminator");
158
2e967919 159 // Header
9abb118d 160 // AliGenEventHeader* header = new AliGenEventHeader("Therminator");
2e967919 161 // Event Vertex
9abb118d 162// header->SetPrimaryVertex(eventVertex);
163// header->SetNProduced(fNprimaries);
164
165 ((AliGenHijingEventHeader*) header)->SetNProduced(fNprimaries);
166 ((AliGenHijingEventHeader*) header)->SetPrimaryVertex(eventVertex);
167 ((AliGenHijingEventHeader*) header)->SetImpactParameter(0.0);
168 ((AliGenHijingEventHeader*) header)->SetTotalEnergy(0.0);
169 ((AliGenHijingEventHeader*) header)->SetHardScatters(0);
170 ((AliGenHijingEventHeader*) header)->SetParticipants(0, 0);
171 ((AliGenHijingEventHeader*) header)->SetCollisions(0, 0, 0, 0);
172 ((AliGenHijingEventHeader*) header)->SetSpectators(0, 0, 0, 0);
173 ((AliGenHijingEventHeader*) header)->SetReactionPlaneAngle(evrot);
174
175
176// 4-momentum vectors of the triggered jets.
177//
178// Before final state gluon radiation.
179// TLorentzVector* jet1 = new TLorentzVector(fHijing->GetHINT1(21),
180// fHijing->GetHINT1(22),
181// fHijing->GetHINT1(23),
182// fHijing->GetHINT1(24));
183
184// TLorentzVector* jet2 = new TLorentzVector(fHijing->GetHINT1(31),
185// fHijing->GetHINT1(32),
186// fHijing->GetHINT1(33),
187// fHijing->GetHINT1(34));
188// // After final state gluon radiation.
189// TLorentzVector* jet3 = new TLorentzVector(fHijing->GetHINT1(26),
190// fHijing->GetHINT1(27),
191// fHijing->GetHINT1(28),
192// fHijing->GetHINT1(29));
193
194// TLorentzVector* jet4 = new TLorentzVector(fHijing->GetHINT1(36),
195// fHijing->GetHINT1(37),
196// fHijing->GetHINT1(38),
197// fHijing->GetHINT1(39));
198// ((AliGenHijingEventHeader*) header)->SetJets(jet1, jet2, jet3, jet4);
199// Bookkeeping for kinematic bias
200// ((AliGenHijingEventHeader*) header)->SetTrials(fTrials);
201// Event Vertex
202 header->SetPrimaryVertex(fVertex);
203 AddHeader(header);
204 fCollisionGeometry = (AliGenHijingEventHeader*) header;
205
2e967919 206 gAlice->SetGenEventHeader(header);
207}
208
209void AliGenTherminator::Init()
210{
211 // Initialize global variables and
212 // particle and decay tables
213 if (fFileName.Length() == 0)
214 fFileName = "event.out";
215 ReadShareParticleTable();
216
217 SetMC(new TTherminator());
218
219 AliGenMC::Init();
220 ((TTherminator *) fMCEvGen)->Initialize();
221}
222void AliGenTherminator::SetFileName(const char *infilename)
223{
224 // Set parameter filename
225 fFileName = infilename;
226}
227void AliGenTherminator::SetEventNumberInFile(int evnum)
228{
229 // Set number of events to generate - default: 1
230 fEventNumber = evnum;
231}
232
233void AliGenTherminator::ReadShareParticleTable()
234{
235 // Read in particle table from share
236 // and add missing particle type to TDatabasePDG
237
238 char str[50];
239 char str1[200];
240
241 TDatabasePDG *tInstance = TDatabasePDG::Instance();
242 TParticlePDG *tParticleType;
243
244 AliWarning(Form("Reading particle types from particles.data"));
ae89e57a 245
246 TString aroot = gSystem->Getenv("ALICE_ROOT");
247 ifstream in((aroot+"/TTherminator/data/SHARE/particles.data").Data());
248 // ifstream in("particles.data");
2e967919 249
250 int charge;
251
252 int number=0;
253 if ((in) && (in.is_open()))
254 {
255 //START OF HEAD-LINE
256 in.ignore(200,'\n');
257 in.ignore(200,'\n');
258 in.ignore(200,'\n');
259 //END OF HEAD-LINE
260
261 while (in>>str)
262 {
263 if (/*(*str == '#')||*/(*str<65)||(*str>122))
264 {
265 in.getline(str1,200);
266 continue;
267 }
268 double mass, gamma, spin, tI3, tI, q, s, aq, as, c, ac, mc;
269
270 in>>mass>>gamma>>spin>>tI>>tI3>>q>>s>>aq>>as>>c>>ac>>mc;
271 number++;
272 tParticleType = tInstance->GetParticle((int) mc);
273 if (!tParticleType) {
274 charge = 0;
275 if (strstr(str, "plu")) charge = 1;
276 if (strstr(str, "min")) charge = -1;
277 if (strstr(str, "plb")) charge = -1;
278 if (strstr(str, "mnb")) charge = 1;
279 if (strstr(str, "plp")) charge = 2;
280 if (strstr(str, "ppb")) charge = -2;
281 tInstance->AddParticle(str, str, mass, gamma == 0.0 ? 1:0, gamma, charge , "meson", (int) mc);
282 AliWarning(Form("Added particle %s with PDG PID %d charge %d", str, (int) mc, charge));
283 // AliWarning(Form("Quantum numbers q s c aq as ac tI3 %lf %lf %lf %lf %lf %lf %lf", q, s, c, aq, as, ac, tI3));
284
285 }
286 }
287 in.close();
288 }
289 CreateTherminatorInputFile();
290}
291
292void AliGenTherminator::CreateTherminatorInputFile()
293{
294 // Create Therminator input file
ae89e57a 295 const char *aroot = gSystem->Getenv("ALICE_ROOT");
2e967919 296 ofstream *ostr = new ofstream("therminator.in");
297 (*ostr) << "NumberOfEvents = 1" << endl;
298 (*ostr) << "Randomize = 1" << endl;
299 (*ostr) << "TableType = SHARE" << endl;
ae89e57a 300 (*ostr) << "InputDirSHARE = "<< aroot << "/TTherminator/data/SHARE" << endl;
2e967919 301 (*ostr) << "EventOutputFile = " << fFileName.Data() << endl;
ae89e57a 302 (*ostr) << "FOHSLocation = " << fFOHSlocation.Data() << endl;
2e967919 303 (*ostr) << "FreezeOutModel = " << fFreezeOutModel.Data() << endl;
304 (*ostr) << "BWVt = " << fBWVt << endl;
305 (*ostr) << "Tau = " << fTau << endl;
306 (*ostr) << "RhoMax = " << fRhoMax << endl;
307 (*ostr) << "Temperature = " << fTemperature << endl;
308 (*ostr) << "MiuI = " << fMiuI << endl;
309 (*ostr) << "MiuS = " << fMiuS << endl;
310 (*ostr) << "MiuB = " << fMiuB << endl;
311 (*ostr) << "AlphaRange = " << fAlfaRange << endl;
312 (*ostr) << "RapidityRange = " << fRapRange << endl;
313 (*ostr) << "NumberOfIntegrateSamples = 1000000" << endl;
314}
315
316void AliGenTherminator::SetModel(const char *model)
317{
318 // Set the freeze-out model to use
319 fFreezeOutModel = model;
320}
ae89e57a 321
322void AliGenTherminator::SetLhyquidSet(const char *set)
323{
324 // Select one of pregenerated Lhyquid hypersurfaces
325 const char *aroot = gSystem->Getenv("ALICE_ROOT");
326 if (strstr(set, "LHC500C0005")) {
327 AliWarning(Form("AliGenTherminator: Selected default Lhyquid hypersurface"));
328 AliWarning(Form(" Pb-Pb collisions, centrality 0-5%"));
329 AliWarning(Form(" initial temperature at tau=1 fm in the center Ti=500 MeV"));
330 AliWarning(Form(" freeze-out criteria Tf=145 MeV"));
331 AliWarning(Form(" for details see $(ALICE_ROOT)/TTherminator/data/LHC500C0005/FO.txt"));
332 fFOHSlocation = aroot;
333 fFOHSlocation += "/TTherminator/data/LHC500C0005";
334 }
335 else if (strstr(set, "LHC500C2030")) {
336 AliWarning(Form("AliGenTherminator: Selected default Lhyquid hypersurface"));
337 AliWarning(Form(" Pb-Pb collisions, centrality 20-30%"));
338 AliWarning(Form(" initial temperature at tau=1 fm in the center Ti=500 MeV"));
339 AliWarning(Form(" freeze-out criteria Tf=145 MeV"));
340 AliWarning(Form(" for details see $(ALICE_ROOT)/TTherminator/data/LHC500C2030/FO.txt"));
341 fFOHSlocation = aroot;
342 fFOHSlocation += "/TTherminator/data/LHC500C2030";
343 }
344 else {
345 AliWarning(Form("Did not find Lhyquid set %s", set));
346 AliWarning(Form("Reverting to default: current directory"));
347 fFOHSlocation = "";
348 }
349}
350
351void AliGenTherminator::SetLhyquidInputDir(const char *inputdir)
352{
353 // Select Your own Lhyquid hypersurface
354 fFOHSlocation = inputdir;
355}