1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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
27 #include <TObjArray.h>
29 #include "AliGenCocktail.h"
30 #include "AliGenCocktailEntry.h"
31 #include "AliCollisionGeometry.h"
34 #include "AliGenCocktailEventHeader.h"
36 ClassImp(AliGenCocktail)
38 AliGenCocktail::AliGenCocktail()
43 fUsePerEventRate(kFALSE),
52 fTitle= "Particle Generator using cocktail of generators";
55 AliGenCocktail::~AliGenCocktail()
60 // delete fHeader; // It is removed in AliRunLoader
65 AddGenerator(AliGenerator *Generator, const char* Name, Float_t RateExp)
68 // Add a generator to the list
69 // First check that list exists
70 if (!fEntries) fEntries = new TList();
71 fTotalRate += RateExp;
73 // Forward parameters to the new generator
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);
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]);
87 Generator->SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
88 Generator->SetVertexSmear(fVertexSmear);
89 Generator->SetVertexSource(kContainer);
91 Generator->SetTrackingFlag(fTrackIt);
92 Generator->SetContainer(this);
96 // Add generator to list
98 sprintf(theName, "%s_%d",Name, fNGenerators);
99 Generator->SetName(theName);
101 AliGenCocktailEntry *entry =
102 new AliGenCocktailEntry(Generator, Name, RateExp);
104 fEntries->Add(entry);
112 void AliGenCocktail::Init()
115 TIter next(fEntries);
116 AliGenCocktailEntry *entry;
118 // Loop over generators and initialize
119 while((entry = (AliGenCocktailEntry*)next())) {
120 if (fStack) entry->Generator()->SetStack(fStack);
121 entry->Generator()->Init();
127 fProb.Set(fNGenerators);
130 while((entry = (AliGenCocktailEntry*)next())) {
131 sum += entry->Rate();
137 while((entry = (AliGenCocktailEntry*)next())) {
138 psum += entry->Rate() / sum;
145 void AliGenCocktail::FinishRun()
148 TIter next(fEntries);
149 AliGenCocktailEntry *entry;
151 // Loop over generators and initialize
152 while((entry = (AliGenCocktailEntry*)next())) {
153 entry->Generator()->FinishRun();
157 void AliGenCocktail::Generate()
161 TIter next(fEntries);
162 AliGenCocktailEntry *entry = 0;
163 AliGenCocktailEntry *preventry = 0;
164 AliGenerator* gen = 0;
165 if (fHeader) delete fHeader;
168 fHeader = new AliGenCocktailEventHeader("Cocktail Header");
170 const TObjArray *partArray = gAlice->GetMCApp()->Particles();
173 // Generate the vertex position used by all generators
175 if(fVertexSmear == kPerEvent) Vertex();
179 for (Int_t j=0; j < 3; j++) eventVertex[j] = fVertex[j];
183 // Loop over generators and generate events
185 while((entry = (AliGenCocktailEntry*)next())) {
186 if (fUsePerEventRate && (gRandom->Rndm() > entry->Rate())) continue;
192 entry->SetFirst((partArray->GetEntriesFast())+1);
195 // Handle case in which current generator needs collision geometry from previous generator
197 gen = entry->Generator();
198 if (gen->NeedsCollisionGeometry())
200 if (preventry && preventry->Generator()->ProvidesCollisionGeometry())
202 gen->SetCollisionGeometry(preventry->Generator()->CollisionGeometry());
204 Fatal("Generate()", "No Collision Geometry Provided");
207 entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2));
208 entry->Generator()->Generate();
209 entry->SetLast(partArray->GetEntriesFast());
212 } else if (fRandom) {
214 // Select a generator randomly
217 Float_t p0 = gRandom->Rndm();
219 for (i = 0; i < fNGenerators; i++) {
220 if (p0 < fProb[i]) break;
223 entry = (AliGenCocktailEntry*) fEntries->At(i);
225 gen = entry->Generator();
226 entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2));
227 entry->Generator()->Generate();
228 entry->SetLast(partArray->GetEntriesFast());
234 fHeader->SetPrimaryVertex(eventVertex);
235 fHeader->CalcNProduced();
236 gAlice->SetGenEventHeader(fHeader);
239 void AliGenCocktail::SetVertexSmear(VertexSmear_t smear)
241 // Set vertex smearing and propagate it to the generators
243 AliGenerator::SetVertexSmear(smear);
244 TIter next(fEntries);
245 while (AliGenCocktailEntry* entry = (AliGenCocktailEntry*)next()) {
246 entry->Generator()->SetVertexSmear(smear);
250 AliGenCocktailEntry * AliGenCocktail::FirstGenerator()
252 // Iterator over generators: Initialisation
253 flnk1 = fEntries->FirstLink();
255 return (AliGenCocktailEntry*) (flnk1->GetObject());
261 AliGenCocktailEntry* AliGenCocktail::NextGenerator()
263 // Iterator over generators: Increment
264 flnk1 = flnk1->Next();
266 return (AliGenCocktailEntry*) (flnk1->GetObject());
272 void AliGenCocktail::
273 FirstGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
275 // Iterator over generator pairs: Initialisation
276 flnk2 = flnk1 = fEntries->FirstLink();
278 e2 = e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
284 void AliGenCocktail::
285 NextGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
287 // Iterator over generators: Increment
288 flnk2 = flnk2->Next();
290 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
291 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
293 flnk2 = flnk1 = flnk1->Next();
295 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
296 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
304 void AliGenCocktail::AddHeader(AliGenEventHeader* header)
306 // Add a header to the list
307 if (fHeader) fHeader->AddHeader(header);