Leave the loop when primaries are filled (I.Hrivnacova)
[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$
2ab0c725 18Revision 1.9 2000/12/21 16:24:06 morsch
19Coding convention clean-up
20
675e9664 21Revision 1.8 2000/10/27 13:53:29 morsch
22AddGenerator: check testbit before setting the pT and momentum range
23(D.Y. Peressounko)
24
699cb625 25Revision 1.7 2000/10/02 15:15:41 morsch
26Use default streamer for AliGenCocktail
27
a436e7fc 28Revision 1.6 2000/09/07 17:04:31 morsch
29In Streamer: TIter() after R__b << fEntries (Dmitri Yurevitch Peressounko)
30
e6e2a20e 31Revision 1.5 2000/06/09 20:28:51 morsch
32All coding rule violations except RS3 corrected (AM)
33
374924b5 34Revision 1.4 1999/09/29 09:24:12 fca
35Introduction of the Copyright and cvs Log
36
4c039060 37*/
38
675e9664 39// Container class for AliGenerator through recursion.
40// Container is itself an AliGenerator.
41// What is stored are not the pointers to the generators directly but to objects of type
42// AliGenCocktail entry.
43// The class provides also iterator functionality.
44// Author: andreas.morsch@cern.ch
45//
46
fe4da5cc 47#include "AliGenCocktail.h"
374924b5 48#include "AliGenCocktailEntry.h"
fe4da5cc 49#include "AliRun.h"
675e9664 50#include <TList.h>
fe4da5cc 51
52ClassImp(AliGenCocktail)
53
54AliGenCocktail::AliGenCocktail()
55 :AliGenerator()
56{
374924b5 57// Constructor
fe4da5cc 58 fEntries = new TList;
59 fNGenerators=0;
60}
61
374924b5 62AliGenCocktail::AliGenCocktail(const AliGenCocktail & cocktail)
63{
64// copy constructor
65}
fe4da5cc 66
67AliGenCocktail::~AliGenCocktail()
68{
374924b5 69// Destructor
fe4da5cc 70 delete fEntries;
71}
72
73void AliGenCocktail::
a436e7fc 74AddGenerator(AliGenerator *Generator, char* Name, Float_t RateExp)
fe4da5cc 75{
76//
77// Forward parameters to the new generator
699cb625 78 if(TestBit(kPtRange))
fe4da5cc 79 Generator->SetPtRange(fPtMin,fPtMax);
699cb625 80 if(TestBit(kMomentumRange))
fe4da5cc 81 Generator->SetMomentumRange(fPMin,fPMax);
699cb625 82
fe4da5cc 83 Generator->SetYRange(fYMin,fYMax);
84 Generator->
85 SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
86 Generator->
87 SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
88 Generator->
89 SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
90 Generator->
91 SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
7a50a130 92 Generator->SetVertexSmear(fVertexSmear);
93 Generator->SetTrackingFlag(fTrackIt);
fe4da5cc 94//
95// Add generator to list
a436e7fc 96
374924b5 97 AliGenCocktailEntry *entry =
fe4da5cc 98 new AliGenCocktailEntry(Generator, Name, RateExp);
374924b5 99 fEntries->Add(entry);
fe4da5cc 100 fNGenerators++;
101 }
102
103 void AliGenCocktail::Init()
374924b5 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()->Init();
112 }
113}
fe4da5cc 114
115 void AliGenCocktail::Generate()
374924b5 116{
117//
118// Generate event
119 TIter next(fEntries);
120 AliGenCocktailEntry *entry;
121 AliGenCocktailEntry *e1;
122 AliGenCocktailEntry *e2;
2ab0c725 123 TObjArray *partArray = gAlice->Particles();
374924b5 124 //
125 // Loop over generators and generate events
126 Int_t igen=0;
127 while((entry = (AliGenCocktailEntry*)next())) {
128 igen++;
129 if (igen ==1) {
130 entry->SetFirst(0);
131 } else {
132 entry->SetFirst((partArray->GetEntriesFast())+1);
133 }
134 entry->Generator()->Generate();
135 entry->SetLast(partArray->GetEntriesFast());
136 }
137 next.Reset();
138 while((entry = (AliGenCocktailEntry*)next())) {
139 entry->PrintInfo();
140 }
141 for (entry=FirstGenerator();
142 entry;
143 entry=NextGenerator()
144 ) {
145 entry->PrintInfo();
146 }
147 for (FirstGeneratorPair(e1,e2);
148 (e1&&e2);
149 NextGeneratorPair(e1,e2)
150 ){
151 printf("\n -----------------------------");
152 e1->PrintInfo();
153 e2->PrintInfo();
154 }
155}
fe4da5cc 156
157AliGenCocktailEntry * AliGenCocktail::FirstGenerator()
158{
374924b5 159// Iterator over generators: Initialisation
fe4da5cc 160 flnk1 = fEntries->FirstLink();
161 if (flnk1) {
162 return (AliGenCocktailEntry*) (flnk1->GetObject());
163 } else {
164 return 0;
165 }
166}
167
168AliGenCocktailEntry* AliGenCocktail::NextGenerator()
169{
374924b5 170// Iterator over generators: Increment
fe4da5cc 171 flnk1 = flnk1->Next();
172 if (flnk1) {
173 return (AliGenCocktailEntry*) (flnk1->GetObject());
174 } else {
175 return 0;
176 }
177}
178
179void AliGenCocktail::
180FirstGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
181{
374924b5 182// Iterator over generator pairs: Initialisation
fe4da5cc 183 flnk2 = flnk1 = fEntries->FirstLink();
184 if (flnk1) {
185 e2 = e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
186 } else {
187 e2= e1 = 0;
188 }
189}
190
191void AliGenCocktail::
192NextGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
193{
374924b5 194// Iterator over generators: Increment
fe4da5cc 195 flnk2 = flnk2->Next();
196 if (flnk2) {
197 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
198 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
199 } else {
200 flnk2 = flnk1 = flnk1->Next();
201 if (flnk1) {
202 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
203 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
204 } else {
205 e1=0;
206 e2=0;
207 }
208 }
209}
210
a436e7fc 211/*
fe4da5cc 212void AliGenCocktail::Streamer(TBuffer &R__b)
213{
374924b5 214 // Stream an object of class AliGenCocktail.
e6e2a20e 215
374924b5 216 AliGenCocktailEntry *entry;
217
218 if (R__b.IsReading()) {
219 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
220 AliGenerator::Streamer(R__b);
221 R__b >> fNGenerators;
222 R__b >> fEntries;
e6e2a20e 223 TIter next(fEntries);
fe4da5cc 224// Stream generation related information
374924b5 225 while((entry = (AliGenCocktailEntry*)next())) {
226 entry->Streamer(R__b);
227 }
228 } else {
229 R__b.WriteVersion(AliGenCocktail::IsA());
230 AliGenerator::Streamer(R__b);
231 R__b << fNGenerators;
232 R__b << fEntries;
e6e2a20e 233 TIter next(fEntries);
fe4da5cc 234// Stream generation related information
374924b5 235 while((entry = (AliGenCocktailEntry*)next())) {
236 entry->Streamer(R__b);
237 }
238 }
239}
a436e7fc 240*/
374924b5 241
242AliGenCocktail& AliGenCocktail::operator=(const AliGenCocktail& rhs)
243{
244// Assignment operator
245 return *this;
fe4da5cc 246}
247
248