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