]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVGEN/AliGenCocktail.cxx
Removing extra symbols
[u/mrichter/AliRoot.git] / EVGEN / AliGenCocktail.cxx
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
16 /* $Id$ */
17
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
26 #include <TList.h>
27 #include <TObjArray.h>
28
29 #include "AliGenCocktail.h"
30 #include "AliGenCocktailEntry.h"
31 #include "AliCollisionGeometry.h"
32 #include "AliRun.h"
33 #include "AliMC.h"
34 #include "AliGenCocktailEventHeader.h"
35
36 ClassImp(AliGenCocktail)
37
38 AliGenCocktail::AliGenCocktail()
39                  :AliGenerator()
40 {
41 // Constructor
42     fName = "Cocktail";
43     fTitle= "Particle Generator using cocktail of generators";
44     flnk1            = 0;
45     flnk2            = 0;
46     fNGenerators     = 0;
47     fEntries         = 0;
48     fHeader          = 0;
49     fRandom          = kFALSE;
50     fUsePerEventRate = kFALSE;
51 }
52
53 AliGenCocktail::AliGenCocktail(const AliGenCocktail & cocktail):
54     AliGenerator(cocktail)
55 {
56 // Copy constructor
57     cocktail.Copy(*this);
58 }
59
60 AliGenCocktail::~AliGenCocktail()
61 {
62 // Destructor
63     delete fEntries;
64     fEntries = 0;
65     //    delete fHeader; // It is removed in AliRunLoader
66     fHeader = 0;
67 }
68
69 void AliGenCocktail::
70 AddGenerator(AliGenerator *Generator, const char* Name, Float_t RateExp)
71 {
72 //
73 // Add a generator to the list 
74 // First check that list exists
75     if (!fEntries) fEntries = new TList();
76
77 //
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);
83     
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]);
92
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);
98     
99         
100 //
101 //  Add generator to list   
102     char theName[256];
103     sprintf(theName, "%s_%d",Name, fNGenerators);
104     Generator->SetName(theName);
105
106     AliGenCocktailEntry *entry = 
107         new AliGenCocktailEntry(Generator, Name, RateExp);
108     
109      fEntries->Add(entry);
110      fNGenerators++;
111      flnk1 = 0;
112      flnk2 = 0;
113      fRandom  = kFALSE;
114      fHeader  = 0;
115 }
116
117   void AliGenCocktail::Init()
118 {
119 // Initialisation
120     TIter next(fEntries);
121     AliGenCocktailEntry *entry;
122     //
123     // Loop over generators and initialize
124     while((entry = (AliGenCocktailEntry*)next())) {
125         if (fStack)  entry->Generator()->SetStack(fStack);
126         entry->Generator()->Init();
127     }  
128
129     next.Reset();
130
131     if (fRandom) {
132         fProb.Set(fNGenerators);
133         next.Reset();
134         Float_t sum = 0.;
135         while((entry = (AliGenCocktailEntry*)next())) {
136             sum += entry->Rate();
137         } 
138
139         next.Reset();
140         Int_t i = 0;
141         Float_t psum = 0.;
142         while((entry = (AliGenCocktailEntry*)next())) {
143             psum +=  entry->Rate() / sum;
144             fProb[i++] = psum;
145         }
146     }
147         next.Reset();
148 }
149
150   void AliGenCocktail::FinishRun()
151 {
152 // Initialisation
153     TIter next(fEntries);
154     AliGenCocktailEntry *entry;
155     //
156     // Loop over generators and initialize
157     while((entry = (AliGenCocktailEntry*)next())) {
158         entry->Generator()->FinishRun();
159     }  
160 }
161
162  void AliGenCocktail::Generate()
163 {
164 //
165 // Generate event 
166     TIter next(fEntries);
167     AliGenCocktailEntry *entry = 0;
168     AliGenCocktailEntry *preventry = 0;
169     AliGenerator* gen = 0;
170     if (fHeader) delete fHeader;
171
172     
173     fHeader = new AliGenCocktailEventHeader("Cocktail Header");
174
175     TObjArray *partArray = gAlice->GetMCApp()->Particles();
176
177 //
178 //  Generate the vertex position used by all generators
179 //    
180     if(fVertexSmear == kPerEvent) Vertex();
181
182     TArrayF eventVertex;
183     eventVertex.Set(3);
184     for (Int_t j=0; j < 3; j++) eventVertex[j] = fVertex[j];
185
186     if (!fRandom) {
187         //
188         // Loop over generators and generate events
189         Int_t igen=0;
190         while((entry = (AliGenCocktailEntry*)next())) {
191
192             if (fUsePerEventRate && (gRandom->Rndm() > entry->Rate())) continue;
193             
194             igen++;
195             if (igen ==1) {
196                 entry->SetFirst(0);
197             } else {
198                 entry->SetFirst((partArray->GetEntriesFast())+1);
199             }
200 //
201 //      Handle case in which current generator needs collision geometry from previous generator
202 //
203             gen = entry->Generator();
204             if (gen->NeedsCollisionGeometry())
205             {
206                 if (preventry && preventry->Generator()->ProvidesCollisionGeometry())
207                 {
208                     gen->SetCollisionGeometry(preventry->Generator()->CollisionGeometry());
209                 } else {
210                     Fatal("Generate()", "No Collision Geometry Provided");
211                 }
212             }
213             entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2));
214             entry->Generator()->Generate();
215             entry->SetLast(partArray->GetEntriesFast());
216             preventry = entry;
217         }  
218     } else if (fRandom) {
219         //
220         // Select a generator randomly
221         //
222         Int_t i;
223         Float_t p0 =  gRandom->Rndm();
224
225         for (i = 0; i < fNGenerators; i++) {
226             if (p0 < fProb[i]) break;
227         }
228
229         entry = (AliGenCocktailEntry*) fEntries->At(i);
230         entry->SetFirst(0);
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());
235     } 
236     
237     next.Reset();
238
239 // Event Vertex
240     fHeader->SetPrimaryVertex(eventVertex);
241     gAlice->SetGenEventHeader(fHeader); 
242 }
243
244 void AliGenCocktail::SetVertexSmear(VertexSmear_t smear)
245 {
246 // Set vertex smearing and propagate it to the generators
247
248   AliGenerator::SetVertexSmear(smear);
249   TIter next(fEntries);
250   while (AliGenCocktailEntry* entry = (AliGenCocktailEntry*)next()) {
251     entry->Generator()->SetVertexSmear(smear);
252   }
253 }
254
255 AliGenCocktailEntry *  AliGenCocktail::FirstGenerator()
256 {
257 // Iterator over generators: Initialisation
258     flnk1 = fEntries->FirstLink();
259     if (flnk1) {
260         return (AliGenCocktailEntry*) (flnk1->GetObject());
261     } else {
262         return 0;
263     }
264 }
265
266 AliGenCocktailEntry*  AliGenCocktail::NextGenerator()
267 {
268 // Iterator over generators: Increment
269     flnk1 = flnk1->Next();
270     if (flnk1) {
271         return (AliGenCocktailEntry*) (flnk1->GetObject());
272     } else {
273         return 0;
274     }
275 }
276
277 void AliGenCocktail::
278 FirstGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
279 {
280 // Iterator over generator pairs: Initialisation
281     flnk2 = flnk1 = fEntries->FirstLink();
282     if (flnk1) {
283         e2 = e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
284     } else {
285         e2= e1 = 0;
286     }
287 }
288
289 void AliGenCocktail::
290 NextGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
291 {
292 // Iterator over generators: Increment
293     flnk2 = flnk2->Next();
294     if (flnk2) {
295         e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
296         e2 = (AliGenCocktailEntry*) (flnk2->GetObject());       
297     } else {
298         flnk2 = flnk1 = flnk1->Next();
299         if (flnk1) {
300             e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
301             e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
302         } else {
303             e1=0;
304             e2=0;
305         }
306     }
307 }
308
309 void AliGenCocktail::AddHeader(AliGenEventHeader* header)
310 {
311 // Add a header to the list 
312     if (fHeader) fHeader->AddHeader(header);
313 }
314                               
315 AliGenCocktail& AliGenCocktail::operator=(const  AliGenCocktail& rhs)
316 {
317 // Assignment operator
318     rhs.Copy(*this); 
319     return (*this);
320 }
321
322 void AliGenCocktail::Copy(TObject &) const
323 {
324     Fatal("Copy","Not implemented!\n");
325 }
326
327
328