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