Plots added
[u/mrichter/AliRoot.git] / EVGEN / AliGenCocktail.cxx
CommitLineData
4c039060 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
88cb7938 16/* $Id$ */
4c039060 17
675e9664 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
116cbefd 26#include <TList.h>
27#include <TObjArray.h>
28
fe4da5cc 29#include "AliGenCocktail.h"
374924b5 30#include "AliGenCocktailEntry.h"
09e2e187 31#include "AliCollisionGeometry.h"
fe4da5cc 32#include "AliRun.h"
5d12ce38 33#include "AliMC.h"
67db3ff2 34#include "AliGenEventHeader.h"
fe4da5cc 35
36ClassImp(AliGenCocktail)
37
38AliGenCocktail::AliGenCocktail()
39 :AliGenerator()
40{
374924b5 41// Constructor
8b31bfac 42 fName = "Cocktail";
43 fTitle= "Particle Generator using cocktail of generators";
2685bf00 44 flnk1 = 0;
45 flnk2 = 0;
fe4da5cc 46 fNGenerators=0;
b1403e15 47 fEntries = 0;
1ebe6dc8 48 fRandom = kFALSE;
fe4da5cc 49}
50
198bb1c7 51AliGenCocktail::AliGenCocktail(const AliGenCocktail & cocktail):
52 AliGenerator(cocktail)
374924b5 53{
198bb1c7 54// Copy constructor
55 cocktail.Copy(*this);
374924b5 56}
fe4da5cc 57
58AliGenCocktail::~AliGenCocktail()
59{
374924b5 60// Destructor
fe4da5cc 61 delete fEntries;
62}
63
64void AliGenCocktail::
a764b7de 65AddGenerator(AliGenerator *Generator, const char* Name, Float_t RateExp)
fe4da5cc 66{
67//
b1403e15 68// Add a generator to the list
69// First check that list exists
70 if (!fEntries) fEntries = new TList();
71
72//
fe4da5cc 73// Forward parameters to the new generator
212bcf04 74 if(TestBit(kPtRange) && !(Generator->TestBit(kPtRange)) && !(Generator->TestBit(kMomentumRange)))
75 Generator->SetPtRange(fPtMin,fPtMax);
76 if(TestBit(kMomentumRange) && !(Generator->TestBit(kPtRange)) && !(Generator->TestBit(kMomentumRange)))
77 Generator->SetMomentumRange(fPMin,fPMax);
78
79 if (!(Generator->TestBit(kYRange)))
80 Generator->SetYRange(fYMin,fYMax);
81 if (!(Generator->TestBit(kPhiRange)))
82 Generator->SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
83 if (!(Generator->TestBit(kThetaRange)))
84 Generator->SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
85 if (!(Generator->TestBit(kVertexRange)))
86 Generator->SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
c8f7f6f9 87
88 Generator->SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
7a50a130 89 Generator->SetVertexSmear(fVertexSmear);
c8f7f6f9 90 Generator->SetVertexSource(kContainer);
91 Generator->SetTrackingFlag(fTrackIt);
c97002cc 92
fe4da5cc 93//
94// Add generator to list
c5c3e4b0 95 char theName[256];
96 sprintf(theName, "%s_%d",Name, fNGenerators);
97 Generator->SetName(theName);
98
374924b5 99 AliGenCocktailEntry *entry =
fe4da5cc 100 new AliGenCocktailEntry(Generator, Name, RateExp);
c5c3e4b0 101
374924b5 102 fEntries->Add(entry);
fe4da5cc 103 fNGenerators++;
104 }
105
106 void AliGenCocktail::Init()
374924b5 107{
108// Initialisation
109 TIter next(fEntries);
110 AliGenCocktailEntry *entry;
111 //
112 // Loop over generators and initialize
113 while((entry = (AliGenCocktailEntry*)next())) {
c97002cc 114 if (fStack) entry->Generator()->SetStack(fStack);
374924b5 115 entry->Generator()->Init();
116 }
1ebe6dc8 117
118 next.Reset();
119
120 if (fRandom) {
121 fProb.Set(fNGenerators);
122 next.Reset();
123 Float_t sum = 0.;
124 while((entry = (AliGenCocktailEntry*)next())) {
125 sum += entry->Rate();
126 }
127
128 next.Reset();
129 Int_t i = 0;
130 Float_t psum = 0.;
131 while((entry = (AliGenCocktailEntry*)next())) {
132 psum += entry->Rate() / sum;
133 fProb[i++] = psum;
134 }
135 }
136 next.Reset();
374924b5 137}
fe4da5cc 138
09e2e187 139 void AliGenCocktail::FinishRun()
140{
141// Initialisation
142 TIter next(fEntries);
143 AliGenCocktailEntry *entry;
144 //
145 // Loop over generators and initialize
146 while((entry = (AliGenCocktailEntry*)next())) {
147 entry->Generator()->FinishRun();
148 }
149}
150
fe4da5cc 151 void AliGenCocktail::Generate()
374924b5 152{
153//
154// Generate event
155 TIter next(fEntries);
a8408367 156 AliGenCocktailEntry *entry = 0;
157 AliGenCocktailEntry *preventry = 0;
158 AliGenerator* gen = 0;
09e2e187 159
5d12ce38 160 TObjArray *partArray = gAlice->GetMCApp()->Particles();
c8f7f6f9 161
162//
163// Generate the vertex position used by all generators
164//
165 if(fVertexSmear == kPerEvent) Vertex();
166
67db3ff2 167 TArrayF eventVertex;
168 eventVertex.Set(3);
169 for (Int_t j=0; j < 3; j++) eventVertex[j] = fVertex[j];
170
1ebe6dc8 171 if (!fRandom) {
172 //
173 // Loop over generators and generate events
174 Int_t igen=0;
175
176 while((entry = (AliGenCocktailEntry*)next())) {
177 igen++;
178 if (igen ==1) {
179 entry->SetFirst(0);
180 } else {
181 entry->SetFirst((partArray->GetEntriesFast())+1);
182 }
a8408367 183//
184// Handle case in which current generator needs collision geometry from previous generator
185//
1ebe6dc8 186 gen = entry->Generator();
187 if (gen->NeedsCollisionGeometry())
a8408367 188 {
1ebe6dc8 189 if (preventry && preventry->Generator()->ProvidesCollisionGeometry())
190 {
191 gen->SetCollisionGeometry(preventry->Generator()->CollisionGeometry());
192 } else {
193 Fatal("Generate()", "No Collision Geometry Provided");
194 }
a8408367 195 }
1ebe6dc8 196 entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2));
197 entry->Generator()->Generate();
198 entry->SetLast(partArray->GetEntriesFast());
199 preventry = entry;
200 }
201 } else {
202 //
203 // Select a generator randomly
204 //
205 Int_t i;
206 Float_t p0 = gRandom->Rndm();
207
208 for (i = 0; i < fNGenerators; i++) {
209 if (p0 < fProb[i]) break;
a8408367 210 }
1ebe6dc8 211
212 entry = (AliGenCocktailEntry*) fEntries->At(i);
213 entry->SetFirst(0);
214 gen = entry->Generator();
c8f7f6f9 215 entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2));
374924b5 216 entry->Generator()->Generate();
217 entry->SetLast(partArray->GetEntriesFast());
1ebe6dc8 218 }
219
220
374924b5 221 next.Reset();
67db3ff2 222// Header
223 AliGenEventHeader* header = new AliGenEventHeader("AliGenCocktail");
224// Event Vertex
225 header->SetPrimaryVertex(eventVertex);
226 gAlice->SetGenEventHeader(header);
374924b5 227}
fe4da5cc 228
c44d1c08 229void AliGenCocktail::SetVertexSmear(VertexSmear_t smear)
230{
231// Set vertex smearing and propagate it to the generators
232
233 AliGenerator::SetVertexSmear(smear);
234 TIter next(fEntries);
235 while (AliGenCocktailEntry* entry = (AliGenCocktailEntry*)next()) {
236 entry->Generator()->SetVertexSmear(smear);
237 }
238}
239
fe4da5cc 240AliGenCocktailEntry * AliGenCocktail::FirstGenerator()
241{
374924b5 242// Iterator over generators: Initialisation
fe4da5cc 243 flnk1 = fEntries->FirstLink();
244 if (flnk1) {
245 return (AliGenCocktailEntry*) (flnk1->GetObject());
246 } else {
247 return 0;
248 }
249}
250
251AliGenCocktailEntry* AliGenCocktail::NextGenerator()
252{
374924b5 253// Iterator over generators: Increment
fe4da5cc 254 flnk1 = flnk1->Next();
255 if (flnk1) {
256 return (AliGenCocktailEntry*) (flnk1->GetObject());
257 } else {
258 return 0;
259 }
260}
261
262void AliGenCocktail::
263FirstGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
264{
374924b5 265// Iterator over generator pairs: Initialisation
fe4da5cc 266 flnk2 = flnk1 = fEntries->FirstLink();
267 if (flnk1) {
268 e2 = e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
269 } else {
270 e2= e1 = 0;
271 }
272}
273
274void AliGenCocktail::
275NextGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
276{
374924b5 277// Iterator over generators: Increment
fe4da5cc 278 flnk2 = flnk2->Next();
279 if (flnk2) {
280 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
281 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
282 } else {
283 flnk2 = flnk1 = flnk1->Next();
284 if (flnk1) {
285 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
286 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
287 } else {
288 e1=0;
289 e2=0;
290 }
291 }
292}
293
374924b5 294AliGenCocktail& AliGenCocktail::operator=(const AliGenCocktail& rhs)
295{
296// Assignment operator
198bb1c7 297 rhs.Copy(*this);
298 return (*this);
fe4da5cc 299}
300
dc1d768c 301void AliGenCocktail::Copy(TObject &) const
198bb1c7 302{
303 Fatal("Copy","Not implemented!\n");
304}
305
306
fe4da5cc 307