495f9002856f3f76109be32aad603c7daec04eee
[u/mrichter/AliRoot.git] / EPOS / AliGenEpos.cxx
1 //
2 // AliGenEpos.cxx
3 //
4 //  ALICE event generator based on EPOS model from Klaus Werner
5 //
6 //  Created on: Feb 28, 2009
7 //      Author: Piotr Ostrowski, postrow@if.pw.edu.pl
8 //
9
10 #include "AliGenEpos.h"
11 #include "TEpos.h"
12 #include "TParticle.h"
13 #include "TMath.h"
14 #include "AliLog.h"
15 #include "AliGenEventHeader.h"
16 #include "AliGenEposEventHeader.h"
17
18 ClassImp(AliGenEpos)
19
20 AliGenEpos::AliGenEpos() : AliGenMC(),
21                 fBmin(0),
22                 fBmax(10000),
23                 fPhiMin(0),
24                 fPhiMax(TMath::TwoPi()),
25                 fFilterModelOutput(kFALSE) {
26         SetMC(new TEpos());
27 }
28
29 AliGenEpos::AliGenEpos(Int_t npart) : AliGenMC(npart),
30                 fBmin(0),
31                 fBmax(10000),
32                 fPhiMin(0),
33                 fPhiMax(TMath::TwoPi()),
34                 fFilterModelOutput(kFALSE) {
35         SetMC(new TEpos());
36 }
37
38 void AliGenEpos::Init() {
39   // Sets up TEpos
40         AliGenMC::Init();
41         TEpos *epos = GetTEpos();
42         epos->SetLaproj(this->fZProjectile);
43         epos->SetMaproj(this->fAProjectile);
44         epos->SetLatarg(this->fZTarget);
45         epos->SetMatarg(this->fATarget);
46         epos->SetPhimin(this->fPhiMin);
47         epos->SetPhimax(this->fPhiMax);
48         epos->SetBminim(this->fBmin);
49         epos->SetBmaxim(this->fBmax);
50         epos->SetEcms(this->fEnergyCMS);
51         epos->SetSplitting(kTRUE);
52         GetTEpos()->Initialize();
53 }
54
55 void AliGenEpos::Generate() {
56   // Does actual generation and output conversion
57           Float_t polar[3]    =   {0,0,0};
58           Float_t origin0[3]  =   {0,0,0};
59           Float_t origin[3]   =   {0,0,0};
60           fNprimaries = 0;
61           Int_t nt  = 0; //output parameter for PushTrack
62
63           Vertex();
64           for (int j=0; j < 3; j++) origin0[j] = fVertex[j];
65
66           // Generate one event
67
68           GetTEpos()->GenerateEvent();
69           AliWarning("Generated");
70           GetTEpos()->ImportParticles(&fParticles);
71
72           Int_t np = fParticles.GetEntriesFast();
73           AliWarning(Form("Imported %d particles", np));
74
75           Int_t *idsOnStack = NULL;
76           idsOnStack = new Int_t[np];
77           for (int i = 0; i < np; i++) idsOnStack[i] = 0;
78           TParticle *iparticle;
79
80           for (int i = 0; i < np; i++) {
81                   iparticle = (TParticle *) fParticles.At(i);
82                   //Bool_t isNullEntry = iparticle->GetStatusCode() == 0;
83                   //Bool_t isCommentOrUnknown = iparticle->GetStatusCode() > 2;
84                   Bool_t hasDecayed = iparticle->GetStatusCode() >= 2;
85                   Bool_t isFinalState = iparticle->GetStatusCode() == 1;
86                   Int_t imo = iparticle->GetFirstMother();
87                   Bool_t  hasMother = (imo >=0);
88
89
90                   if (isFinalState) {
91                           origin[0] = iparticle->Vx();
92                           origin[1] = iparticle->Vy();
93                           origin[2] = iparticle->Vz();
94                           //doubled track with freeze out coordinates for femtoscopy
95                           PushTrack(0,
96                                           imo>=0?idsOnStack[imo]:-1,
97                                           iparticle->GetPdgCode(),
98                                 iparticle->Px(),iparticle->Py(),iparticle->Pz(),iparticle->Energy(),
99                                 origin[0], origin[1], origin[2],
100                                 iparticle->T(),
101                                 polar[0],polar[1],polar[2],
102                                 hasMother ? kPDecay:kPNoProcess,nt);
103
104                       idsOnStack[i] = nt;
105                       fNprimaries++;
106                       KeepTrack(nt);
107
108                       //real track with smeared vertex
109                       origin[0] += origin0[0];
110                       origin[1] += origin0[1];
111                       origin[2] += origin0[2];
112                           PushTrack(1,
113                                           nt,   //doubled track as mother
114                                           iparticle->GetPdgCode(),
115                                 iparticle->Px(),iparticle->Py(),iparticle->Pz(),iparticle->Energy(),
116                                 origin[0], origin[1], origin[2],
117                                 iparticle->T(),
118                                 polar[0],polar[1],polar[2],
119                                 kPDecay,nt);
120                       fNprimaries++;
121                       KeepTrack(nt);
122                   } else if(hasDecayed || !fFilterModelOutput) {
123                           // don't track it and don't smear vertex
124                           origin[0] = iparticle->Vx();
125                           origin[1] = iparticle->Vy();
126                           origin[2] = iparticle->Vz();
127                           PushTrack(0,
128                                           imo>=0?idsOnStack[imo]:-1,
129                                           iparticle->GetPdgCode(),
130                                 iparticle->Px(),iparticle->Py(),iparticle->Pz(),iparticle->Energy(),
131                                 origin[0], origin[1], origin[2],
132                                 iparticle->T(),
133                                 polar[0],polar[1],polar[2],
134                                 hasMother ? kPDecay:kPNoProcess,nt);
135                       idsOnStack[i] = nt;
136                       fNprimaries++;
137                       KeepTrack(nt);
138                   } else if(fFilterModelOutput) {
139                           //filtered internal model objects
140                           idsOnStack[i] = -1; // to erase mother field in its dauthers
141                   }
142           }
143           SetHighWaterMark(fNprimaries);
144           TArrayF eventVertex;
145           eventVertex.Set(3);
146           eventVertex[0] = origin0[0];
147           eventVertex[1] = origin0[1];
148           eventVertex[2] = origin0[2];
149         // Builds the event header, to be called after each event
150           AliGenEposEventHeader* header = new AliGenEposEventHeader("EPOS");
151
152           header->SetNProduced(fNprimaries);
153           header->SetPrimaryVertex(eventVertex);
154
155           header->SetImpactParameter(GetTEpos()->GetBimevt());
156           header->SetReactionPlaneAngle(GetTEpos()->GetPhievt());
157
158           header->SetHardScatters(0);
159           header->SetParticipants(GetTEpos()->GetNpjevt(), GetTEpos()->GetNtgevt());
160           header->SetCollisions(GetTEpos()->GetKolevt(), 0, 0, GetTEpos()->GetNpjevt());
161           header->SetSpectators(GetTEpos()->GetJpnevt(), GetTEpos()->GetJppevt(), GetTEpos()->GetJtnevt(), GetTEpos()->GetJtpevt());
162
163         // Event Vertex
164           header->SetPrimaryVertex(fVertex);
165           
166           header->SetBimevt(GetTEpos()->GetBimevt());
167           header->SetPhievt(GetTEpos()->GetPhievt());
168           header->SetKolevt(GetTEpos()->GetKolevt());
169           header->SetKoievt(GetTEpos()->GetKoievt());
170           header->SetPmxevt(GetTEpos()->GetPmxevt());
171           header->SetEgyevt(GetTEpos()->GetEgyevt());
172           header->SetNpjevt(GetTEpos()->GetNpjevt());
173           header->SetNtgevt(GetTEpos()->GetNtgevt());
174           header->SetNpnevt(GetTEpos()->GetNpnevt());
175           header->SetNppevt(GetTEpos()->GetNppevt());
176           header->SetNtnevt(GetTEpos()->GetNtnevt());
177           header->SetNtpevt(GetTEpos()->GetNtpevt());
178           header->SetJpnevt(GetTEpos()->GetJpnevt());
179           header->SetJppevt(GetTEpos()->GetJppevt());
180           header->SetJtnevt(GetTEpos()->GetJtnevt());
181           header->SetJtpevt(GetTEpos()->GetJtpevt());
182           header->SetXbjevt(GetTEpos()->GetXbjevt());
183           header->SetQsqevt(GetTEpos()->GetQsqevt());
184           header->SetNglevt(GetTEpos()->GetNglevt());
185           header->SetZppevt(GetTEpos()->GetZppevt());
186           header->SetZptevt(GetTEpos()->GetZptevt());
187     AddHeader(header);
188     fCollisionGeometry = (AliGenEposEventHeader*)  header;
189     
190     delete[] idsOnStack;
191 }
192
193 AliGenEpos::~AliGenEpos() {
194 }
195