updated parametrisation for pi0, eta, omega, phi for different energies, allow select...
[u/mrichter/AliRoot.git] / EVGEN / AliGenCocktail.cxx
... / ...
CommitLineData
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// Container class for AliGenerator through recursion.
19// Container is itself an AliGenerator.
20// What is stored are not the pointers to the generators directly but to objects of type
21// AliGenCocktail entry.
22// The class provides also iterator functionality.
23// Author: andreas.morsch@cern.ch
24//
25
26#include <TList.h>
27#include <TObjArray.h>
28#include <TFormula.h>
29
30#include "AliGenCocktail.h"
31#include "AliGenCocktailEntry.h"
32#include "AliCollisionGeometry.h"
33#include "AliRun.h"
34#include "AliLog.h"
35#include "AliMC.h"
36#include "AliGenCocktailEventHeader.h"
37
38ClassImp(AliGenCocktail)
39
40AliGenCocktail::AliGenCocktail()
41 :AliGenerator(),
42 fNGenerators(0),
43 fTotalRate(0.),
44 fSRandom(kFALSE),
45 fUsePerEventRate(kFALSE),
46 fProb(0),
47 fEntries(0),
48 flnk1(0),
49 flnk2(0),
50 fHeader(0)
51{
52// Constructor
53 fName = "Cocktail";
54 fTitle= "Particle Generator using cocktail of generators";
55}
56
57AliGenCocktail::~AliGenCocktail()
58{
59// Destructor
60 delete fEntries;
61 fEntries = 0;
62 // delete fHeader; // It is removed in AliRunLoader
63 fHeader = 0;
64}
65
66void AliGenCocktail::
67AddGenerator(AliGenerator *Generator, const char* Name, Float_t RateExp, TFormula* formula, Int_t ntimes)
68{
69//
70// Add a generator to the list
71// First check that list exists
72 if (!fEntries) fEntries = new TList();
73 fTotalRate += RateExp;
74//
75// Forward parameters to the new generator
76 if(TestBit(kPtRange) && !(Generator->TestBit(kPtRange)) && !(Generator->TestBit(kMomentumRange)))
77 Generator->SetPtRange(fPtMin,fPtMax);
78 if(TestBit(kMomentumRange) && !(Generator->TestBit(kPtRange)) && !(Generator->TestBit(kMomentumRange)))
79 Generator->SetMomentumRange(fPMin,fPMax);
80
81 if (TestBit(kYRange) && !(Generator->TestBit(kYRange)))
82 Generator->SetYRange(fYMin,fYMax);
83 if (TestBit(kPhiRange) && !(Generator->TestBit(kPhiRange)))
84 Generator->SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
85 if (TestBit(kThetaRange) && !(Generator->TestBit(kThetaRange)) && !(Generator->TestBit(kEtaRange)))
86 Generator->SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
87 if (!(Generator->TestBit(kVertexRange))) {
88 Generator->SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
89 Generator->SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
90 Generator->SetVertexSmear(fVertexSmear);
91 Generator->SetVertexSource(kContainer);
92 }
93 Generator->SetTrackingFlag(fTrackIt);
94 Generator->SetContainer(this);
95
96
97//
98// Add generator to list
99 char theName[256];
100 snprintf(theName, 256, "%s_%d",Name, fNGenerators);
101 Generator->SetName(theName);
102
103 AliGenCocktailEntry *entry =
104 new AliGenCocktailEntry(Generator, Name, RateExp);
105 if (formula) entry->SetFormula(formula);
106 entry->SetNTimes(ntimes);
107 fEntries->Add(entry);
108 fNGenerators++;
109 flnk1 = 0;
110 flnk2 = 0;
111 fSRandom = kFALSE;
112 fHeader = 0;
113}
114
115 void AliGenCocktail::Init()
116{
117// Initialisation
118 TIter next(fEntries);
119 AliGenCocktailEntry *entry;
120 //
121 // Loop over generators and initialize
122 while((entry = (AliGenCocktailEntry*)next())) {
123 if (fStack) entry->Generator()->SetStack(fStack);
124 entry->Generator()->Init();
125 }
126
127 next.Reset();
128
129 if (fSRandom) {
130 fProb.Set(fNGenerators);
131 next.Reset();
132 Float_t sum = 0.;
133 while((entry = (AliGenCocktailEntry*)next())) {
134 sum += entry->Rate();
135 }
136
137 next.Reset();
138 Int_t i = 0;
139 Float_t psum = 0.;
140 while((entry = (AliGenCocktailEntry*)next())) {
141 psum += entry->Rate() / sum;
142 fProb[i++] = psum;
143 }
144 }
145 next.Reset();
146}
147
148 void AliGenCocktail::FinishRun()
149{
150// Initialisation
151 TIter next(fEntries);
152 AliGenCocktailEntry *entry;
153 //
154 // Loop over generators and initialize
155 while((entry = (AliGenCocktailEntry*)next())) {
156 entry->Generator()->FinishRun();
157 }
158}
159
160 void AliGenCocktail::Generate()
161{
162//
163// Generate event
164 TIter next(fEntries);
165 AliGenCocktailEntry *entry = 0;
166 AliGenCocktailEntry *preventry = 0;
167 AliGenCocktailEntry *collentry = 0;
168 AliGenerator* gen = 0;
169 if (fHeader) delete fHeader;
170
171
172 fHeader = new AliGenCocktailEventHeader("Cocktail Header");
173
174 const TObjArray *partArray = gAlice->GetMCApp()->Particles();
175
176//
177// Generate the vertex position used by all generators
178//
179 if(fVertexSmear == kPerEvent) Vertex();
180
181 TArrayF eventVertex;
182 eventVertex.Set(3);
183 for (Int_t j=0; j < 3; j++) eventVertex[j] = fVertex[j];
184
185 if (!fSRandom) {
186 //
187 // Loop over generators and generate events
188 Int_t igen = 0;
189 while((entry = (AliGenCocktailEntry*)next())) {
190 Int_t ntimes = entry->NTimes();
191 if (fUsePerEventRate && (gRandom->Rndm() > entry->Rate())) continue;
192
193 igen++;
194 if (igen ==1) {
195 entry->SetFirst(0);
196 } else {
197 entry->SetFirst((partArray->GetEntriesFast())+1);
198 }
199 gen = entry->Generator();
200 if (gen->ProvidesCollisionGeometry()) collentry = entry;
201 //
202 // Handle case in which current generator needs collision geometry from previous generator
203 //
204 if (gen->NeedsCollisionGeometry() && (entry->Formula() == 0))
205 {
206 if (preventry && preventry->Generator()->ProvidesCollisionGeometry())
207 {
208 gen->SetCollisionGeometry(preventry->Generator()->CollisionGeometry());
209 } else {
210 Fatal("Generate()", "No Collision Geometry Provided");
211 }
212 }
213 //
214 // Number of signals is calculated from Collision Geometry
215 // and entry with given centrality bin is selected
216 //
217 if (entry->Formula() != 0)
218 {
219 if (!collentry) {
220 Fatal("Generate()", "No Collision Geometry Provided");
221 return;
222 }
223 AliCollisionGeometry* coll = (collentry->Generator())->CollisionGeometry();
224 Float_t b = coll->ImpactParameter();
225 Int_t nsig = Int_t(entry->Formula()->Eval(b));
226 Int_t bin = entry->Bin() - 100;
227 if (bin > 0) {
228 if (bin != nsig) continue;
229 } else {
230 if (nsig < 1) nsig = 1;
231 AliInfo(Form("Signal Events %13.3f %5d %5d\n", b, coll->HardScatters(), nsig));
232 ntimes = nsig;
233 }
234 }
235 gen->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2), fTime);
236
237 gen->GenerateN(ntimes);
238 entry->SetLast(partArray->GetEntriesFast());
239 preventry = entry;
240 }
241 } else if (fSRandom) {
242 //
243 // Select a generator randomly
244 //
245 Int_t i;
246 Float_t p0 = gRandom->Rndm();
247
248 for (i = 0; i < fNGenerators; i++) {
249 if (p0 < fProb[i]) break;
250 }
251
252 entry = (AliGenCocktailEntry*) fEntries->At(i);
253 entry->SetFirst(0);
254 gen = entry->Generator();
255 gen->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2), fTime);
256 gen->Generate();
257 entry->SetLast(partArray->GetEntriesFast());
258 }
259
260 next.Reset();
261
262 // Event Vertex
263 fHeader->SetPrimaryVertex(eventVertex);
264 fHeader->CalcNProduced();
265 if (fContainer) {
266 fHeader->SetName(fName);
267 fContainer->AddHeader(fHeader);
268 } else {
269 gAlice->SetGenEventHeader(fHeader);
270 }
271}
272
273void AliGenCocktail::SetVertexSmear(VertexSmear_t smear)
274{
275// Set vertex smearing and propagate it to the generators
276
277 AliGenerator::SetVertexSmear(smear);
278 TIter next(fEntries);
279 while (AliGenCocktailEntry* entry = (AliGenCocktailEntry*)next()) {
280 entry->Generator()->SetVertexSmear(smear);
281 }
282}
283
284AliGenCocktailEntry * AliGenCocktail::FirstGenerator()
285{
286// Iterator over generators: Initialisation
287 flnk1 = fEntries->FirstLink();
288 if (flnk1) {
289 return (AliGenCocktailEntry*) (flnk1->GetObject());
290 } else {
291 return 0;
292 }
293}
294
295AliGenCocktailEntry* AliGenCocktail::NextGenerator()
296{
297// Iterator over generators: Increment
298 flnk1 = flnk1->Next();
299 if (flnk1) {
300 return (AliGenCocktailEntry*) (flnk1->GetObject());
301 } else {
302 return 0;
303 }
304}
305
306void AliGenCocktail::
307FirstGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
308{
309// Iterator over generator pairs: Initialisation
310 flnk2 = flnk1 = fEntries->FirstLink();
311 if (flnk1) {
312 e2 = e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
313 } else {
314 e2= e1 = 0;
315 }
316}
317
318void AliGenCocktail::
319NextGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
320{
321// Iterator over generators: Increment
322 flnk2 = flnk2->Next();
323 if (flnk2) {
324 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
325 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
326 } else {
327 flnk2 = flnk1 = flnk1->Next();
328 if (flnk1) {
329 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
330 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
331 } else {
332 e1=0;
333 e2=0;
334 }
335 }
336}
337
338void AliGenCocktail::AddHeader(AliGenEventHeader* header)
339{
340// Add a header to the list
341 if (fHeader) fHeader->AddHeader(header);
342}
343
344
345
346