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