]>
Commit | Line | Data |
---|---|---|
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" |
4f85aa78 | 34 | #include "AliGenCocktailEventHeader.h" |
fe4da5cc | 35 | |
36 | ClassImp(AliGenCocktail) | |
37 | ||
38 | AliGenCocktail::AliGenCocktail() | |
1c56e311 | 39 | :AliGenerator(), |
40 | fNGenerators(0), | |
8058ead1 | 41 | fTotalRate(0.), |
1c56e311 | 42 | fRandom(kFALSE), |
43 | fUsePerEventRate(kFALSE), | |
44 | fProb(0), | |
45 | fEntries(0), | |
46 | flnk1(0), | |
47 | flnk2(0), | |
48 | fHeader(0) | |
fe4da5cc | 49 | { |
374924b5 | 50 | // Constructor |
8b31bfac | 51 | fName = "Cocktail"; |
52 | fTitle= "Particle Generator using cocktail of generators"; | |
fe4da5cc | 53 | } |
54 | ||
fe4da5cc | 55 | AliGenCocktail::~AliGenCocktail() |
56 | { | |
374924b5 | 57 | // Destructor |
fe4da5cc | 58 | delete fEntries; |
373c1a55 | 59 | fEntries = 0; |
60 | // delete fHeader; // It is removed in AliRunLoader | |
61 | fHeader = 0; | |
fe4da5cc | 62 | } |
63 | ||
64 | void AliGenCocktail:: | |
a764b7de | 65 | AddGenerator(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(); | |
8058ead1 | 71 | fTotalRate += RateExp; |
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()); | |
4a6ca8fc | 85 | if (!(Generator->TestBit(kVertexRange))) { |
212bcf04 | 86 | Generator->SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]); |
4a6ca8fc | 87 | Generator->SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]); |
88 | Generator->SetVertexSmear(fVertexSmear); | |
89 | Generator->SetVertexSource(kContainer); | |
90 | } | |
c8f7f6f9 | 91 | Generator->SetTrackingFlag(fTrackIt); |
4f85aa78 | 92 | Generator->SetContainer(this); |
93 | ||
c97002cc | 94 | |
fe4da5cc | 95 | // |
96 | // Add generator to list | |
c5c3e4b0 | 97 | char theName[256]; |
98 | sprintf(theName, "%s_%d",Name, fNGenerators); | |
99 | Generator->SetName(theName); | |
100 | ||
374924b5 | 101 | AliGenCocktailEntry *entry = |
fe4da5cc | 102 | new AliGenCocktailEntry(Generator, Name, RateExp); |
c5c3e4b0 | 103 | |
374924b5 | 104 | fEntries->Add(entry); |
fe4da5cc | 105 | fNGenerators++; |
373c1a55 | 106 | flnk1 = 0; |
107 | flnk2 = 0; | |
108 | fRandom = kFALSE; | |
109 | fHeader = 0; | |
110 | } | |
fe4da5cc | 111 | |
112 | void AliGenCocktail::Init() | |
374924b5 | 113 | { |
114 | // Initialisation | |
115 | TIter next(fEntries); | |
116 | AliGenCocktailEntry *entry; | |
117 | // | |
118 | // Loop over generators and initialize | |
119 | while((entry = (AliGenCocktailEntry*)next())) { | |
c97002cc | 120 | if (fStack) entry->Generator()->SetStack(fStack); |
374924b5 | 121 | entry->Generator()->Init(); |
122 | } | |
1ebe6dc8 | 123 | |
124 | next.Reset(); | |
125 | ||
126 | if (fRandom) { | |
127 | fProb.Set(fNGenerators); | |
128 | next.Reset(); | |
129 | Float_t sum = 0.; | |
130 | while((entry = (AliGenCocktailEntry*)next())) { | |
131 | sum += entry->Rate(); | |
132 | } | |
133 | ||
134 | next.Reset(); | |
135 | Int_t i = 0; | |
136 | Float_t psum = 0.; | |
137 | while((entry = (AliGenCocktailEntry*)next())) { | |
138 | psum += entry->Rate() / sum; | |
139 | fProb[i++] = psum; | |
140 | } | |
141 | } | |
142 | next.Reset(); | |
374924b5 | 143 | } |
fe4da5cc | 144 | |
09e2e187 | 145 | void AliGenCocktail::FinishRun() |
146 | { | |
147 | // Initialisation | |
148 | TIter next(fEntries); | |
149 | AliGenCocktailEntry *entry; | |
150 | // | |
151 | // Loop over generators and initialize | |
152 | while((entry = (AliGenCocktailEntry*)next())) { | |
153 | entry->Generator()->FinishRun(); | |
154 | } | |
155 | } | |
156 | ||
fe4da5cc | 157 | void AliGenCocktail::Generate() |
374924b5 | 158 | { |
159 | // | |
160 | // Generate event | |
161 | TIter next(fEntries); | |
a8408367 | 162 | AliGenCocktailEntry *entry = 0; |
163 | AliGenCocktailEntry *preventry = 0; | |
164 | AliGenerator* gen = 0; | |
4f85aa78 | 165 | if (fHeader) delete fHeader; |
c89fc3f1 | 166 | |
167 | ||
4f85aa78 | 168 | fHeader = new AliGenCocktailEventHeader("Cocktail Header"); |
09e2e187 | 169 | |
5d12ce38 | 170 | TObjArray *partArray = gAlice->GetMCApp()->Particles(); |
c8f7f6f9 | 171 | |
172 | // | |
173 | // Generate the vertex position used by all generators | |
174 | // | |
175 | if(fVertexSmear == kPerEvent) Vertex(); | |
176 | ||
67db3ff2 | 177 | TArrayF eventVertex; |
178 | eventVertex.Set(3); | |
179 | for (Int_t j=0; j < 3; j++) eventVertex[j] = fVertex[j]; | |
180 | ||
1ebe6dc8 | 181 | if (!fRandom) { |
182 | // | |
183 | // Loop over generators and generate events | |
184 | Int_t igen=0; | |
1ebe6dc8 | 185 | while((entry = (AliGenCocktailEntry*)next())) { |
c89fc3f1 | 186 | if (fUsePerEventRate && (gRandom->Rndm() > entry->Rate())) continue; |
187 | ||
1ebe6dc8 | 188 | igen++; |
189 | if (igen ==1) { | |
190 | entry->SetFirst(0); | |
191 | } else { | |
192 | entry->SetFirst((partArray->GetEntriesFast())+1); | |
193 | } | |
a8408367 | 194 | // |
195 | // Handle case in which current generator needs collision geometry from previous generator | |
196 | // | |
1ebe6dc8 | 197 | gen = entry->Generator(); |
198 | if (gen->NeedsCollisionGeometry()) | |
a8408367 | 199 | { |
1ebe6dc8 | 200 | if (preventry && preventry->Generator()->ProvidesCollisionGeometry()) |
201 | { | |
202 | gen->SetCollisionGeometry(preventry->Generator()->CollisionGeometry()); | |
203 | } else { | |
204 | Fatal("Generate()", "No Collision Geometry Provided"); | |
205 | } | |
a8408367 | 206 | } |
1ebe6dc8 | 207 | entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2)); |
208 | entry->Generator()->Generate(); | |
209 | entry->SetLast(partArray->GetEntriesFast()); | |
210 | preventry = entry; | |
211 | } | |
c89fc3f1 | 212 | } else if (fRandom) { |
1ebe6dc8 | 213 | // |
214 | // Select a generator randomly | |
215 | // | |
216 | Int_t i; | |
217 | Float_t p0 = gRandom->Rndm(); | |
218 | ||
219 | for (i = 0; i < fNGenerators; i++) { | |
220 | if (p0 < fProb[i]) break; | |
a8408367 | 221 | } |
1ebe6dc8 | 222 | |
223 | entry = (AliGenCocktailEntry*) fEntries->At(i); | |
224 | entry->SetFirst(0); | |
225 | gen = entry->Generator(); | |
c8f7f6f9 | 226 | entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2)); |
374924b5 | 227 | entry->Generator()->Generate(); |
228 | entry->SetLast(partArray->GetEntriesFast()); | |
c89fc3f1 | 229 | } |
1ebe6dc8 | 230 | |
374924b5 | 231 | next.Reset(); |
4f85aa78 | 232 | |
67db3ff2 | 233 | // Event Vertex |
4f85aa78 | 234 | fHeader->SetPrimaryVertex(eventVertex); |
bcee5fdf | 235 | fHeader->CalcNProduced(); |
4f85aa78 | 236 | gAlice->SetGenEventHeader(fHeader); |
374924b5 | 237 | } |
fe4da5cc | 238 | |
c44d1c08 | 239 | void AliGenCocktail::SetVertexSmear(VertexSmear_t smear) |
240 | { | |
241 | // Set vertex smearing and propagate it to the generators | |
242 | ||
243 | AliGenerator::SetVertexSmear(smear); | |
244 | TIter next(fEntries); | |
245 | while (AliGenCocktailEntry* entry = (AliGenCocktailEntry*)next()) { | |
246 | entry->Generator()->SetVertexSmear(smear); | |
247 | } | |
248 | } | |
249 | ||
fe4da5cc | 250 | AliGenCocktailEntry * AliGenCocktail::FirstGenerator() |
251 | { | |
374924b5 | 252 | // Iterator over generators: Initialisation |
fe4da5cc | 253 | flnk1 = fEntries->FirstLink(); |
254 | if (flnk1) { | |
255 | return (AliGenCocktailEntry*) (flnk1->GetObject()); | |
256 | } else { | |
257 | return 0; | |
258 | } | |
259 | } | |
260 | ||
261 | AliGenCocktailEntry* AliGenCocktail::NextGenerator() | |
262 | { | |
374924b5 | 263 | // Iterator over generators: Increment |
fe4da5cc | 264 | flnk1 = flnk1->Next(); |
265 | if (flnk1) { | |
266 | return (AliGenCocktailEntry*) (flnk1->GetObject()); | |
267 | } else { | |
268 | return 0; | |
269 | } | |
270 | } | |
271 | ||
272 | void AliGenCocktail:: | |
273 | FirstGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2) | |
274 | { | |
374924b5 | 275 | // Iterator over generator pairs: Initialisation |
fe4da5cc | 276 | flnk2 = flnk1 = fEntries->FirstLink(); |
277 | if (flnk1) { | |
278 | e2 = e1 = (AliGenCocktailEntry*) (flnk1->GetObject()); | |
279 | } else { | |
280 | e2= e1 = 0; | |
281 | } | |
282 | } | |
283 | ||
284 | void AliGenCocktail:: | |
285 | NextGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2) | |
286 | { | |
374924b5 | 287 | // Iterator over generators: Increment |
fe4da5cc | 288 | flnk2 = flnk2->Next(); |
289 | if (flnk2) { | |
290 | e1 = (AliGenCocktailEntry*) (flnk1->GetObject()); | |
291 | e2 = (AliGenCocktailEntry*) (flnk2->GetObject()); | |
292 | } else { | |
293 | flnk2 = flnk1 = flnk1->Next(); | |
294 | if (flnk1) { | |
295 | e1 = (AliGenCocktailEntry*) (flnk1->GetObject()); | |
296 | e2 = (AliGenCocktailEntry*) (flnk2->GetObject()); | |
297 | } else { | |
298 | e1=0; | |
299 | e2=0; | |
300 | } | |
301 | } | |
302 | } | |
303 | ||
4f85aa78 | 304 | void AliGenCocktail::AddHeader(AliGenEventHeader* header) |
305 | { | |
306 | // Add a header to the list | |
307 | if (fHeader) fHeader->AddHeader(header); | |
308 | } | |
fe4da5cc | 309 | |
198bb1c7 | 310 | |
311 | ||
fe4da5cc | 312 |