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