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