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