Additiona protection
[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"
fe4da5cc 34
35ClassImp(AliGenCocktail)
36
37AliGenCocktail::AliGenCocktail()
38 :AliGenerator()
39{
374924b5 40// Constructor
8b31bfac 41 fName = "Cocktail";
42 fTitle= "Particle Generator using cocktail of generators";
2685bf00 43 flnk1 = 0;
44 flnk2 = 0;
fe4da5cc 45 fNGenerators=0;
b1403e15 46 fEntries = 0;
47
fe4da5cc 48}
49
198bb1c7 50AliGenCocktail::AliGenCocktail(const AliGenCocktail & cocktail):
51 AliGenerator(cocktail)
374924b5 52{
198bb1c7 53// Copy constructor
54 cocktail.Copy(*this);
374924b5 55}
fe4da5cc 56
57AliGenCocktail::~AliGenCocktail()
58{
374924b5 59// Destructor
fe4da5cc 60 delete fEntries;
61}
62
63void AliGenCocktail::
a764b7de 64AddGenerator(AliGenerator *Generator, const char* Name, Float_t RateExp)
fe4da5cc 65{
66//
b1403e15 67// Add a generator to the list
68// First check that list exists
69 if (!fEntries) fEntries = new TList();
70
71//
fe4da5cc 72// Forward parameters to the new generator
212bcf04 73 if(TestBit(kPtRange) && !(Generator->TestBit(kPtRange)) && !(Generator->TestBit(kMomentumRange)))
74 Generator->SetPtRange(fPtMin,fPtMax);
75 if(TestBit(kMomentumRange) && !(Generator->TestBit(kPtRange)) && !(Generator->TestBit(kMomentumRange)))
76 Generator->SetMomentumRange(fPMin,fPMax);
77
78 if (!(Generator->TestBit(kYRange)))
79 Generator->SetYRange(fYMin,fYMax);
80 if (!(Generator->TestBit(kPhiRange)))
81 Generator->SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
82 if (!(Generator->TestBit(kThetaRange)))
83 Generator->SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
84 if (!(Generator->TestBit(kVertexRange)))
85 Generator->SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
c8f7f6f9 86
87 Generator->SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
7a50a130 88 Generator->SetVertexSmear(fVertexSmear);
c8f7f6f9 89 Generator->SetVertexSource(kContainer);
90 Generator->SetTrackingFlag(fTrackIt);
c97002cc 91
fe4da5cc 92//
93// Add generator to list
c5c3e4b0 94 char theName[256];
95 sprintf(theName, "%s_%d",Name, fNGenerators);
96 Generator->SetName(theName);
97
374924b5 98 AliGenCocktailEntry *entry =
fe4da5cc 99 new AliGenCocktailEntry(Generator, Name, RateExp);
c5c3e4b0 100
374924b5 101 fEntries->Add(entry);
fe4da5cc 102 fNGenerators++;
103 }
104
105 void AliGenCocktail::Init()
374924b5 106{
107// Initialisation
108 TIter next(fEntries);
109 AliGenCocktailEntry *entry;
110 //
111 // Loop over generators and initialize
112 while((entry = (AliGenCocktailEntry*)next())) {
c97002cc 113 if (fStack) entry->Generator()->SetStack(fStack);
374924b5 114 entry->Generator()->Init();
115 }
116}
fe4da5cc 117
09e2e187 118 void AliGenCocktail::FinishRun()
119{
120// Initialisation
121 TIter next(fEntries);
122 AliGenCocktailEntry *entry;
123 //
124 // Loop over generators and initialize
125 while((entry = (AliGenCocktailEntry*)next())) {
126 entry->Generator()->FinishRun();
127 }
128}
129
fe4da5cc 130 void AliGenCocktail::Generate()
374924b5 131{
132//
133// Generate event
134 TIter next(fEntries);
a8408367 135 AliGenCocktailEntry *entry = 0;
136 AliGenCocktailEntry *preventry = 0;
137 AliGenerator* gen = 0;
09e2e187 138
5d12ce38 139 TObjArray *partArray = gAlice->GetMCApp()->Particles();
c8f7f6f9 140
141//
142// Generate the vertex position used by all generators
143//
144 if(fVertexSmear == kPerEvent) Vertex();
145
146
147 //
374924b5 148 // Loop over generators and generate events
149 Int_t igen=0;
a8408367 150
374924b5 151 while((entry = (AliGenCocktailEntry*)next())) {
152 igen++;
153 if (igen ==1) {
154 entry->SetFirst(0);
155 } else {
156 entry->SetFirst((partArray->GetEntriesFast())+1);
157 }
a8408367 158//
159// Handle case in which current generator needs collision geometry from previous generator
160//
161 gen = entry->Generator();
162 if (gen->NeedsCollisionGeometry())
163 {
164 if (preventry && preventry->Generator()->ProvidesCollisionGeometry())
165 {
166 gen->SetCollisionGeometry(preventry->Generator()->CollisionGeometry());
167 } else {
168 Fatal("Generate()", "No Collision Geometry Provided");
169 }
170 }
c8f7f6f9 171 entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2));
374924b5 172 entry->Generator()->Generate();
173 entry->SetLast(partArray->GetEntriesFast());
a8408367 174 preventry = entry;
374924b5 175 }
176 next.Reset();
374924b5 177}
fe4da5cc 178
179AliGenCocktailEntry * AliGenCocktail::FirstGenerator()
180{
374924b5 181// Iterator over generators: Initialisation
fe4da5cc 182 flnk1 = fEntries->FirstLink();
183 if (flnk1) {
184 return (AliGenCocktailEntry*) (flnk1->GetObject());
185 } else {
186 return 0;
187 }
188}
189
190AliGenCocktailEntry* AliGenCocktail::NextGenerator()
191{
374924b5 192// Iterator over generators: Increment
fe4da5cc 193 flnk1 = flnk1->Next();
194 if (flnk1) {
195 return (AliGenCocktailEntry*) (flnk1->GetObject());
196 } else {
197 return 0;
198 }
199}
200
201void AliGenCocktail::
202FirstGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
203{
374924b5 204// Iterator over generator pairs: Initialisation
fe4da5cc 205 flnk2 = flnk1 = fEntries->FirstLink();
206 if (flnk1) {
207 e2 = e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
208 } else {
209 e2= e1 = 0;
210 }
211}
212
213void AliGenCocktail::
214NextGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
215{
374924b5 216// Iterator over generators: Increment
fe4da5cc 217 flnk2 = flnk2->Next();
218 if (flnk2) {
219 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
220 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
221 } else {
222 flnk2 = flnk1 = flnk1->Next();
223 if (flnk1) {
224 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
225 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
226 } else {
227 e1=0;
228 e2=0;
229 }
230 }
231}
232
374924b5 233AliGenCocktail& AliGenCocktail::operator=(const AliGenCocktail& rhs)
234{
235// Assignment operator
198bb1c7 236 rhs.Copy(*this);
237 return (*this);
fe4da5cc 238}
239
dc1d768c 240void AliGenCocktail::Copy(TObject &) const
198bb1c7 241{
242 Fatal("Copy","Not implemented!\n");
243}
244
245
fe4da5cc 246