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 fTitle= "Particle Generator using cocktail of generators";
50 fUsePerEventRate = kFALSE;
53 AliGenCocktail::AliGenCocktail(const AliGenCocktail & cocktail):
54 AliGenerator(cocktail)
60 AliGenCocktail::~AliGenCocktail()
65 // delete fHeader; // It is removed in AliRunLoader
70 AddGenerator(AliGenerator *Generator, const char* Name, Float_t RateExp)
73 // Add a generator to the list
74 // First check that list exists
75 if (!fEntries) fEntries = new TList();
78 // Forward parameters to the new generator
79 if(TestBit(kPtRange) && !(Generator->TestBit(kPtRange)) && !(Generator->TestBit(kMomentumRange)))
80 Generator->SetPtRange(fPtMin,fPtMax);
81 if(TestBit(kMomentumRange) && !(Generator->TestBit(kPtRange)) && !(Generator->TestBit(kMomentumRange)))
82 Generator->SetMomentumRange(fPMin,fPMax);
84 if (!(Generator->TestBit(kYRange)))
85 Generator->SetYRange(fYMin,fYMax);
86 if (!(Generator->TestBit(kPhiRange)))
87 Generator->SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
88 if (!(Generator->TestBit(kThetaRange)))
89 Generator->SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
90 if (!(Generator->TestBit(kVertexRange)))
91 Generator->SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
93 Generator->SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
94 Generator->SetVertexSmear(fVertexSmear);
95 Generator->SetVertexSource(kContainer);
96 Generator->SetTrackingFlag(fTrackIt);
97 Generator->SetContainer(this);
101 // Add generator to list
103 sprintf(theName, "%s_%d",Name, fNGenerators);
104 Generator->SetName(theName);
106 AliGenCocktailEntry *entry =
107 new AliGenCocktailEntry(Generator, Name, RateExp);
109 fEntries->Add(entry);
117 void AliGenCocktail::Init()
120 TIter next(fEntries);
121 AliGenCocktailEntry *entry;
123 // Loop over generators and initialize
124 while((entry = (AliGenCocktailEntry*)next())) {
125 if (fStack) entry->Generator()->SetStack(fStack);
126 entry->Generator()->Init();
132 fProb.Set(fNGenerators);
135 while((entry = (AliGenCocktailEntry*)next())) {
136 sum += entry->Rate();
142 while((entry = (AliGenCocktailEntry*)next())) {
143 psum += entry->Rate() / sum;
150 void AliGenCocktail::FinishRun()
153 TIter next(fEntries);
154 AliGenCocktailEntry *entry;
156 // Loop over generators and initialize
157 while((entry = (AliGenCocktailEntry*)next())) {
158 entry->Generator()->FinishRun();
162 void AliGenCocktail::Generate()
166 TIter next(fEntries);
167 AliGenCocktailEntry *entry = 0;
168 AliGenCocktailEntry *preventry = 0;
169 AliGenerator* gen = 0;
170 if (fHeader) delete fHeader;
173 fHeader = new AliGenCocktailEventHeader("Cocktail Header");
175 TObjArray *partArray = gAlice->GetMCApp()->Particles();
178 // Generate the vertex position used by all generators
180 if(fVertexSmear == kPerEvent) Vertex();
184 for (Int_t j=0; j < 3; j++) eventVertex[j] = fVertex[j];
188 // Loop over generators and generate events
190 while((entry = (AliGenCocktailEntry*)next())) {
192 if (fUsePerEventRate && (gRandom->Rndm() > entry->Rate())) continue;
198 entry->SetFirst((partArray->GetEntriesFast())+1);
201 // Handle case in which current generator needs collision geometry from previous generator
203 gen = entry->Generator();
204 if (gen->NeedsCollisionGeometry())
206 if (preventry && preventry->Generator()->ProvidesCollisionGeometry())
208 gen->SetCollisionGeometry(preventry->Generator()->CollisionGeometry());
210 Fatal("Generate()", "No Collision Geometry Provided");
213 entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2));
214 entry->Generator()->Generate();
215 entry->SetLast(partArray->GetEntriesFast());
218 } else if (fRandom) {
220 // Select a generator randomly
223 Float_t p0 = gRandom->Rndm();
225 for (i = 0; i < fNGenerators; i++) {
226 if (p0 < fProb[i]) break;
229 entry = (AliGenCocktailEntry*) fEntries->At(i);
231 gen = entry->Generator();
232 entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2));
233 entry->Generator()->Generate();
234 entry->SetLast(partArray->GetEntriesFast());
240 fHeader->SetPrimaryVertex(eventVertex);
241 gAlice->SetGenEventHeader(fHeader);
244 void AliGenCocktail::SetVertexSmear(VertexSmear_t smear)
246 // Set vertex smearing and propagate it to the generators
248 AliGenerator::SetVertexSmear(smear);
249 TIter next(fEntries);
250 while (AliGenCocktailEntry* entry = (AliGenCocktailEntry*)next()) {
251 entry->Generator()->SetVertexSmear(smear);
255 AliGenCocktailEntry * AliGenCocktail::FirstGenerator()
257 // Iterator over generators: Initialisation
258 flnk1 = fEntries->FirstLink();
260 return (AliGenCocktailEntry*) (flnk1->GetObject());
266 AliGenCocktailEntry* AliGenCocktail::NextGenerator()
268 // Iterator over generators: Increment
269 flnk1 = flnk1->Next();
271 return (AliGenCocktailEntry*) (flnk1->GetObject());
277 void AliGenCocktail::
278 FirstGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
280 // Iterator over generator pairs: Initialisation
281 flnk2 = flnk1 = fEntries->FirstLink();
283 e2 = e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
289 void AliGenCocktail::
290 NextGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
292 // Iterator over generators: Increment
293 flnk2 = flnk2->Next();
295 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
296 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
298 flnk2 = flnk1 = flnk1->Next();
300 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
301 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
309 void AliGenCocktail::AddHeader(AliGenEventHeader* header)
311 // Add a header to the list
312 if (fHeader) fHeader->AddHeader(header);
315 AliGenCocktail& AliGenCocktail::operator=(const AliGenCocktail& rhs)
317 // Assignment operator
322 void AliGenCocktail::Copy(TObject &) const
324 Fatal("Copy","Not implemented!\n");