Implementation of eventdisplay in AliEve
[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
c9a371fc 111 if (hasDaughter) {
112 // This particle has decayed
113 // It will not be tracked
114 // Add it only once with coorduinates not
115 // smeared with primary vertex position
116
117 kf = iparticle->GetPdgCode();
118 ks = iparticle->GetStatusCode();
119 Double_t aphi = TMath::ATan2(iparticle->Py(), iparticle->Px());
120 Double_t arho = TMath::Hypot(iparticle->Px(), iparticle->Py());
121 p[0] = arho*TMath::Cos(aphi + evrot);
122 p[1] = arho*TMath::Sin(aphi + evrot);
123 // p[0] = iparticle->Px();
124 // p[1] = iparticle->Py();
125 p[2] = iparticle->Pz();
126 mass = TDatabasePDG::Instance()->GetParticle(kf)->Mass();
127 energy = sqrt(mass*mass + p[0]*p[0] + p[1]*p[1] + p[2]*p[2]);
128
129 Double_t vphi = TMath::ATan2(iparticle->Vy(), iparticle->Vx());
130 Double_t vrho = TMath::Hypot(iparticle->Vx(), iparticle->Vy());
c9c8970c 131 origin[0] = vrho*TMath::Cos(vphi + evrot);
132 origin[1] = vrho*TMath::Sin(vphi + evrot);
133 origin[2] = iparticle->Vz();
c9a371fc 134
135 imo = -1;
136 TParticle* mother = 0;
137 if (hasMother) {
138 imo = iparticle->GetFirstMother();
c9c8970c 139 mother = (TParticle *) fParticles.At(imo);
c9a371fc 140 } // if has mother
141 Bool_t tFlag = (!hasDaughter);
142
143 printf("Pushing Track %d with status %d mother %d\n", kf, tFlag, imo);
144 PushTrack(tFlag,imo,kf,
145 p[0],p[1],p[2],energy,
c9c8970c 146 origin[0],origin[1],origin[2],iparticle->T(),
c9a371fc 147 polar[0],polar[1],polar[2],
148 hasMother ? kPDecay:kPNoProcess,nt);
149 fNprimaries++;
150 KeepTrack(nt);
151 }
152 else {
153 // This is a final state particle
154 // It will be tracked
155 // Add it TWICE to the stack !!!
156 // First time with event-wide coordicates (for femtoscopy) -
157 // this one will not be tracked
158 // Second time with event-wide ccordiantes and vertex smearing
159 // this one will be tracked
160
161 kf = iparticle->GetPdgCode();
162 ks = iparticle->GetStatusCode();
163 Double_t aphi = TMath::ATan2(iparticle->Py(), iparticle->Px());
164 Double_t arho = TMath::Hypot(iparticle->Px(), iparticle->Py());
165 p[0] = arho*TMath::Cos(aphi + evrot);
166 p[1] = arho*TMath::Sin(aphi + evrot);
167 // p[0] = iparticle->Px();
168 // p[1] = iparticle->Py();
169 p[2] = iparticle->Pz();
170 mass = TDatabasePDG::Instance()->GetParticle(kf)->Mass();
171 energy = sqrt(mass*mass + p[0]*p[0] + p[1]*p[1] + p[2]*p[2]);
172
173 Double_t vphi = TMath::ATan2(iparticle->Vy(), iparticle->Vx());
174 Double_t vrho = TMath::Hypot(iparticle->Vx(), iparticle->Vy());
175 origin[0] = vrho*TMath::Cos(vphi + evrot);
176 origin[1] = vrho*TMath::Sin(vphi + evrot);
177 origin[2] = iparticle->Vz();
178
179 imo = -1;
180 TParticle* mother = 0;
181 if (hasMother) {
182 imo = iparticle->GetFirstMother();
c9c8970c 183 mother = (TParticle *) fParticles.At(imo);
c9a371fc 184 } // if has mother
185 Bool_t tFlag = (hasDaughter);
186
187 printf("Pushing Track %d with status %d mother %d\n", kf, tFlag, imo);
188 PushTrack(tFlag,imo,kf,
189 p[0],p[1],p[2],energy,
c9c8970c 190 origin[0],origin[1],origin[2],iparticle->T(),
c9a371fc 191 polar[0],polar[1],polar[2],
192 hasMother ? kPDecay:kPNoProcess,nt);
193 fNprimaries++;
194 KeepTrack(nt);
195
196 origin[0] = origin0[0]+vrho*TMath::Cos(vphi + evrot);
197 origin[1] = origin0[1]+vrho*TMath::Sin(vphi + evrot);
198 origin[2] = origin0[2]+iparticle->Vz();
199
200 imo = nt;
c9c8970c 201 mother = (TParticle *) fParticles.At(nt);
c9a371fc 202 tFlag = (!hasDaughter);
203
204 printf("Pushing Track %d with status %d mother %d\n", kf, tFlag, imo);
205 PushTrack(tFlag,imo,kf,
206 p[0],p[1],p[2],energy,
c9c8970c 207 origin[0],origin[1],origin[2],iparticle->T(),
c9a371fc 208 polar[0],polar[1],polar[2],
209 hasMother ? kPDecay:kPNoProcess,nt);
210 fNprimaries++;
211 KeepTrack(nt);
212 }
2e967919 213 }
214
215 SetHighWaterMark(fNprimaries);
216
217 TArrayF eventVertex;
218 eventVertex.Set(3);
219 eventVertex[0] = origin0[0];
220 eventVertex[1] = origin0[1];
221 eventVertex[2] = origin0[2];
222
9abb118d 223// Builds the event header, to be called after each event
224 AliGenEventHeader* header = new AliGenHijingEventHeader("Therminator");
225
2e967919 226 // Header
9abb118d 227 // AliGenEventHeader* header = new AliGenEventHeader("Therminator");
2e967919 228 // Event Vertex
9abb118d 229// header->SetPrimaryVertex(eventVertex);
230// header->SetNProduced(fNprimaries);
231
232 ((AliGenHijingEventHeader*) header)->SetNProduced(fNprimaries);
233 ((AliGenHijingEventHeader*) header)->SetPrimaryVertex(eventVertex);
234 ((AliGenHijingEventHeader*) header)->SetImpactParameter(0.0);
235 ((AliGenHijingEventHeader*) header)->SetTotalEnergy(0.0);
236 ((AliGenHijingEventHeader*) header)->SetHardScatters(0);
237 ((AliGenHijingEventHeader*) header)->SetParticipants(0, 0);
238 ((AliGenHijingEventHeader*) header)->SetCollisions(0, 0, 0, 0);
239 ((AliGenHijingEventHeader*) header)->SetSpectators(0, 0, 0, 0);
240 ((AliGenHijingEventHeader*) header)->SetReactionPlaneAngle(evrot);
241
242
243// 4-momentum vectors of the triggered jets.
244//
245// Before final state gluon radiation.
246// TLorentzVector* jet1 = new TLorentzVector(fHijing->GetHINT1(21),
247// fHijing->GetHINT1(22),
248// fHijing->GetHINT1(23),
249// fHijing->GetHINT1(24));
250
251// TLorentzVector* jet2 = new TLorentzVector(fHijing->GetHINT1(31),
252// fHijing->GetHINT1(32),
253// fHijing->GetHINT1(33),
254// fHijing->GetHINT1(34));
255// // After final state gluon radiation.
256// TLorentzVector* jet3 = new TLorentzVector(fHijing->GetHINT1(26),
257// fHijing->GetHINT1(27),
258// fHijing->GetHINT1(28),
259// fHijing->GetHINT1(29));
260
261// TLorentzVector* jet4 = new TLorentzVector(fHijing->GetHINT1(36),
262// fHijing->GetHINT1(37),
263// fHijing->GetHINT1(38),
264// fHijing->GetHINT1(39));
265// ((AliGenHijingEventHeader*) header)->SetJets(jet1, jet2, jet3, jet4);
266// Bookkeeping for kinematic bias
267// ((AliGenHijingEventHeader*) header)->SetTrials(fTrials);
268// Event Vertex
269 header->SetPrimaryVertex(fVertex);
270 AddHeader(header);
271 fCollisionGeometry = (AliGenHijingEventHeader*) header;
272
c9a371fc 273 // gAlice->SetGenEventHeader(header);
2e967919 274}
275
276void AliGenTherminator::Init()
277{
278 // Initialize global variables and
279 // particle and decay tables
280 if (fFileName.Length() == 0)
281 fFileName = "event.out";
282 ReadShareParticleTable();
283
284 SetMC(new TTherminator());
285
286 AliGenMC::Init();
287 ((TTherminator *) fMCEvGen)->Initialize();
288}
289void AliGenTherminator::SetFileName(const char *infilename)
290{
291 // Set parameter filename
292 fFileName = infilename;
293}
294void AliGenTherminator::SetEventNumberInFile(int evnum)
295{
296 // Set number of events to generate - default: 1
297 fEventNumber = evnum;
298}
299
300void AliGenTherminator::ReadShareParticleTable()
301{
302 // Read in particle table from share
303 // and add missing particle type to TDatabasePDG
304
305 char str[50];
306 char str1[200];
307
308 TDatabasePDG *tInstance = TDatabasePDG::Instance();
309 TParticlePDG *tParticleType;
310
311 AliWarning(Form("Reading particle types from particles.data"));
ae89e57a 312
313 TString aroot = gSystem->Getenv("ALICE_ROOT");
314 ifstream in((aroot+"/TTherminator/data/SHARE/particles.data").Data());
315 // ifstream in("particles.data");
2e967919 316
317 int charge;
318
319 int number=0;
320 if ((in) && (in.is_open()))
321 {
322 //START OF HEAD-LINE
323 in.ignore(200,'\n');
324 in.ignore(200,'\n');
325 in.ignore(200,'\n');
326 //END OF HEAD-LINE
327
328 while (in>>str)
329 {
330 if (/*(*str == '#')||*/(*str<65)||(*str>122))
331 {
332 in.getline(str1,200);
333 continue;
334 }
335 double mass, gamma, spin, tI3, tI, q, s, aq, as, c, ac, mc;
336
337 in>>mass>>gamma>>spin>>tI>>tI3>>q>>s>>aq>>as>>c>>ac>>mc;
338 number++;
339 tParticleType = tInstance->GetParticle((int) mc);
340 if (!tParticleType) {
341 charge = 0;
342 if (strstr(str, "plu")) charge = 1;
343 if (strstr(str, "min")) charge = -1;
344 if (strstr(str, "plb")) charge = -1;
345 if (strstr(str, "mnb")) charge = 1;
346 if (strstr(str, "plp")) charge = 2;
347 if (strstr(str, "ppb")) charge = -2;
348 tInstance->AddParticle(str, str, mass, gamma == 0.0 ? 1:0, gamma, charge , "meson", (int) mc);
349 AliWarning(Form("Added particle %s with PDG PID %d charge %d", str, (int) mc, charge));
350 // 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));
351
352 }
353 }
354 in.close();
355 }
356 CreateTherminatorInputFile();
357}
358
359void AliGenTherminator::CreateTherminatorInputFile()
360{
361 // Create Therminator input file
ae89e57a 362 const char *aroot = gSystem->Getenv("ALICE_ROOT");
2e967919 363 ofstream *ostr = new ofstream("therminator.in");
364 (*ostr) << "NumberOfEvents = 1" << endl;
365 (*ostr) << "Randomize = 1" << endl;
366 (*ostr) << "TableType = SHARE" << endl;
ae89e57a 367 (*ostr) << "InputDirSHARE = "<< aroot << "/TTherminator/data/SHARE" << endl;
2e967919 368 (*ostr) << "EventOutputFile = " << fFileName.Data() << endl;
ae89e57a 369 (*ostr) << "FOHSLocation = " << fFOHSlocation.Data() << endl;
2e967919 370 (*ostr) << "FreezeOutModel = " << fFreezeOutModel.Data() << endl;
371 (*ostr) << "BWVt = " << fBWVt << endl;
372 (*ostr) << "Tau = " << fTau << endl;
373 (*ostr) << "RhoMax = " << fRhoMax << endl;
374 (*ostr) << "Temperature = " << fTemperature << endl;
375 (*ostr) << "MiuI = " << fMiuI << endl;
376 (*ostr) << "MiuS = " << fMiuS << endl;
377 (*ostr) << "MiuB = " << fMiuB << endl;
378 (*ostr) << "AlphaRange = " << fAlfaRange << endl;
379 (*ostr) << "RapidityRange = " << fRapRange << endl;
380 (*ostr) << "NumberOfIntegrateSamples = 1000000" << endl;
381}
382
383void AliGenTherminator::SetModel(const char *model)
384{
385 // Set the freeze-out model to use
386 fFreezeOutModel = model;
387}
ae89e57a 388
389void AliGenTherminator::SetLhyquidSet(const char *set)
390{
391 // Select one of pregenerated Lhyquid hypersurfaces
392 const char *aroot = gSystem->Getenv("ALICE_ROOT");
393 if (strstr(set, "LHC500C0005")) {
394 AliWarning(Form("AliGenTherminator: Selected default Lhyquid hypersurface"));
395 AliWarning(Form(" Pb-Pb collisions, centrality 0-5%"));
396 AliWarning(Form(" initial temperature at tau=1 fm in the center Ti=500 MeV"));
397 AliWarning(Form(" freeze-out criteria Tf=145 MeV"));
398 AliWarning(Form(" for details see $(ALICE_ROOT)/TTherminator/data/LHC500C0005/FO.txt"));
399 fFOHSlocation = aroot;
400 fFOHSlocation += "/TTherminator/data/LHC500C0005";
401 }
402 else if (strstr(set, "LHC500C2030")) {
403 AliWarning(Form("AliGenTherminator: Selected default Lhyquid hypersurface"));
404 AliWarning(Form(" Pb-Pb collisions, centrality 20-30%"));
405 AliWarning(Form(" initial temperature at tau=1 fm in the center Ti=500 MeV"));
406 AliWarning(Form(" freeze-out criteria Tf=145 MeV"));
407 AliWarning(Form(" for details see $(ALICE_ROOT)/TTherminator/data/LHC500C2030/FO.txt"));
408 fFOHSlocation = aroot;
409 fFOHSlocation += "/TTherminator/data/LHC500C2030";
410 }
411 else {
412 AliWarning(Form("Did not find Lhyquid set %s", set));
413 AliWarning(Form("Reverting to default: current directory"));
414 fFOHSlocation = "";
415 }
416}
417
418void AliGenTherminator::SetLhyquidInputDir(const char *inputdir)
419{
420 // Select Your own Lhyquid hypersurface
421 fFOHSlocation = inputdir;
422}