Adaption to new fluka common blocks (E. Futo)
[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
16/*
17$Log$
c8f7f6f9 18Revision 1.18 2003/03/24 16:38:40 morsch
19Bug corrected.
20
417b3b54 21Revision 1.17 2003/03/24 15:58:27 morsch
22FinishRun() implemented.
23
09e2e187 24Revision 1.16 2003/01/14 10:50:18 alibrary
25Cleanup of STEER coding conventions
26
116cbefd 27Revision 1.15 2003/01/07 14:13:22 morsch
28Communication between generators provising and requesting collision
29geometries.
30
a8408367 31Revision 1.14 2002/02/08 16:50:50 morsch
32Add name and title in constructor.
33
8b31bfac 34Revision 1.13 2001/10/21 18:35:56 hristov
35Several pointers were set to zero in the default constructors to avoid memory management problems
36
2685bf00 37Revision 1.12 2001/06/18 13:07:30 morsch
38Forward kinematic ranges to entries only if not set by user.
39
212bcf04 40Revision 1.11 2001/01/30 09:23:12 hristov
41Streamers removed (R.Brun)
42
a8a6107b 43Revision 1.10 2001/01/26 19:55:49 hristov
44Major upgrade of AliRoot code
45
2ab0c725 46Revision 1.9 2000/12/21 16:24:06 morsch
47Coding convention clean-up
48
675e9664 49Revision 1.8 2000/10/27 13:53:29 morsch
50AddGenerator: check testbit before setting the pT and momentum range
51(D.Y. Peressounko)
52
699cb625 53Revision 1.7 2000/10/02 15:15:41 morsch
54Use default streamer for AliGenCocktail
55
a436e7fc 56Revision 1.6 2000/09/07 17:04:31 morsch
57In Streamer: TIter() after R__b << fEntries (Dmitri Yurevitch Peressounko)
58
e6e2a20e 59Revision 1.5 2000/06/09 20:28:51 morsch
60All coding rule violations except RS3 corrected (AM)
61
374924b5 62Revision 1.4 1999/09/29 09:24:12 fca
63Introduction of the Copyright and cvs Log
64
4c039060 65*/
66
675e9664 67// Container class for AliGenerator through recursion.
68// Container is itself an AliGenerator.
69// What is stored are not the pointers to the generators directly but to objects of type
70// AliGenCocktail entry.
71// The class provides also iterator functionality.
72// Author: andreas.morsch@cern.ch
73//
74
116cbefd 75#include <TList.h>
76#include <TObjArray.h>
77
fe4da5cc 78#include "AliGenCocktail.h"
374924b5 79#include "AliGenCocktailEntry.h"
09e2e187 80#include "AliCollisionGeometry.h"
fe4da5cc 81#include "AliRun.h"
fe4da5cc 82
83ClassImp(AliGenCocktail)
84
85AliGenCocktail::AliGenCocktail()
86 :AliGenerator()
87{
374924b5 88// Constructor
8b31bfac 89 fName = "Cocktail";
90 fTitle= "Particle Generator using cocktail of generators";
fe4da5cc 91 fEntries = new TList;
2685bf00 92 flnk1 = 0;
93 flnk2 = 0;
fe4da5cc 94 fNGenerators=0;
95}
96
374924b5 97AliGenCocktail::AliGenCocktail(const AliGenCocktail & cocktail)
98{
99// copy constructor
100}
fe4da5cc 101
102AliGenCocktail::~AliGenCocktail()
103{
374924b5 104// Destructor
fe4da5cc 105 delete fEntries;
106}
107
108void AliGenCocktail::
a436e7fc 109AddGenerator(AliGenerator *Generator, char* Name, Float_t RateExp)
fe4da5cc 110{
111//
112// Forward parameters to the new generator
212bcf04 113 if(TestBit(kPtRange) && !(Generator->TestBit(kPtRange)) && !(Generator->TestBit(kMomentumRange)))
114 Generator->SetPtRange(fPtMin,fPtMax);
115 if(TestBit(kMomentumRange) && !(Generator->TestBit(kPtRange)) && !(Generator->TestBit(kMomentumRange)))
116 Generator->SetMomentumRange(fPMin,fPMax);
117
118 if (!(Generator->TestBit(kYRange)))
119 Generator->SetYRange(fYMin,fYMax);
120 if (!(Generator->TestBit(kPhiRange)))
121 Generator->SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
122 if (!(Generator->TestBit(kThetaRange)))
123 Generator->SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
124 if (!(Generator->TestBit(kVertexRange)))
125 Generator->SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
c8f7f6f9 126
127 Generator->SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
7a50a130 128 Generator->SetVertexSmear(fVertexSmear);
c8f7f6f9 129 Generator->SetVertexSource(kContainer);
130 Generator->SetTrackingFlag(fTrackIt);
fe4da5cc 131//
132// Add generator to list
a436e7fc 133
374924b5 134 AliGenCocktailEntry *entry =
fe4da5cc 135 new AliGenCocktailEntry(Generator, Name, RateExp);
374924b5 136 fEntries->Add(entry);
fe4da5cc 137 fNGenerators++;
138 }
139
140 void AliGenCocktail::Init()
374924b5 141{
142// Initialisation
143 TIter next(fEntries);
144 AliGenCocktailEntry *entry;
145 //
146 // Loop over generators and initialize
147 while((entry = (AliGenCocktailEntry*)next())) {
148 entry->Generator()->Init();
149 }
150}
fe4da5cc 151
09e2e187 152 void AliGenCocktail::FinishRun()
153{
154// Initialisation
155 TIter next(fEntries);
156 AliGenCocktailEntry *entry;
157 //
158 // Loop over generators and initialize
159 while((entry = (AliGenCocktailEntry*)next())) {
160 entry->Generator()->FinishRun();
161 }
162}
163
fe4da5cc 164 void AliGenCocktail::Generate()
374924b5 165{
166//
167// Generate event
168 TIter next(fEntries);
a8408367 169 AliGenCocktailEntry *entry = 0;
170 AliGenCocktailEntry *preventry = 0;
171 AliGenerator* gen = 0;
09e2e187 172
2ab0c725 173 TObjArray *partArray = gAlice->Particles();
c8f7f6f9 174
175//
176// Generate the vertex position used by all generators
177//
178 if(fVertexSmear == kPerEvent) Vertex();
179
180
181 //
374924b5 182 // Loop over generators and generate events
183 Int_t igen=0;
a8408367 184
374924b5 185 while((entry = (AliGenCocktailEntry*)next())) {
186 igen++;
187 if (igen ==1) {
188 entry->SetFirst(0);
189 } else {
190 entry->SetFirst((partArray->GetEntriesFast())+1);
191 }
a8408367 192//
193// Handle case in which current generator needs collision geometry from previous generator
194//
195 gen = entry->Generator();
196 if (gen->NeedsCollisionGeometry())
197 {
198 if (preventry && preventry->Generator()->ProvidesCollisionGeometry())
199 {
200 gen->SetCollisionGeometry(preventry->Generator()->CollisionGeometry());
201 } else {
202 Fatal("Generate()", "No Collision Geometry Provided");
203 }
204 }
c8f7f6f9 205 entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2));
374924b5 206 entry->Generator()->Generate();
207 entry->SetLast(partArray->GetEntriesFast());
a8408367 208 preventry = entry;
374924b5 209 }
210 next.Reset();
374924b5 211}
fe4da5cc 212
213AliGenCocktailEntry * AliGenCocktail::FirstGenerator()
214{
374924b5 215// Iterator over generators: Initialisation
fe4da5cc 216 flnk1 = fEntries->FirstLink();
217 if (flnk1) {
218 return (AliGenCocktailEntry*) (flnk1->GetObject());
219 } else {
220 return 0;
221 }
222}
223
224AliGenCocktailEntry* AliGenCocktail::NextGenerator()
225{
374924b5 226// Iterator over generators: Increment
fe4da5cc 227 flnk1 = flnk1->Next();
228 if (flnk1) {
229 return (AliGenCocktailEntry*) (flnk1->GetObject());
230 } else {
231 return 0;
232 }
233}
234
235void AliGenCocktail::
236FirstGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
237{
374924b5 238// Iterator over generator pairs: Initialisation
fe4da5cc 239 flnk2 = flnk1 = fEntries->FirstLink();
240 if (flnk1) {
241 e2 = e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
242 } else {
243 e2= e1 = 0;
244 }
245}
246
247void AliGenCocktail::
248NextGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
249{
374924b5 250// Iterator over generators: Increment
fe4da5cc 251 flnk2 = flnk2->Next();
252 if (flnk2) {
253 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
254 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
255 } else {
256 flnk2 = flnk1 = flnk1->Next();
257 if (flnk1) {
258 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
259 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
260 } else {
261 e1=0;
262 e2=0;
263 }
264 }
265}
266
374924b5 267AliGenCocktail& AliGenCocktail::operator=(const AliGenCocktail& rhs)
268{
269// Assignment operator
270 return *this;
fe4da5cc 271}
272
273