]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVGEN/AliGenCocktail.cxx
Bug corrected.
[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 /*
17 $Log$
18 Revision 1.17  2003/03/24 15:58:27  morsch
19 FinishRun() implemented.
20
21 Revision 1.16  2003/01/14 10:50:18  alibrary
22 Cleanup of STEER coding conventions
23
24 Revision 1.15  2003/01/07 14:13:22  morsch
25 Communication between generators provising and requesting collision
26 geometries.
27
28 Revision 1.14  2002/02/08 16:50:50  morsch
29 Add name and title in constructor.
30
31 Revision 1.13  2001/10/21 18:35:56  hristov
32 Several pointers were set to zero in the default constructors to avoid memory management problems
33
34 Revision 1.12  2001/06/18 13:07:30  morsch
35 Forward kinematic ranges to entries only if not set by user.
36
37 Revision 1.11  2001/01/30 09:23:12  hristov
38 Streamers removed (R.Brun)
39
40 Revision 1.10  2001/01/26 19:55:49  hristov
41 Major upgrade of AliRoot code
42
43 Revision 1.9  2000/12/21 16:24:06  morsch
44 Coding convention clean-up
45
46 Revision 1.8  2000/10/27 13:53:29  morsch
47 AddGenerator: check testbit before setting the pT and momentum range
48 (D.Y. Peressounko)
49
50 Revision 1.7  2000/10/02 15:15:41  morsch
51 Use default streamer for AliGenCocktail
52
53 Revision 1.6  2000/09/07 17:04:31  morsch
54 In Streamer: TIter() after R__b << fEntries (Dmitri Yurevitch Peressounko)
55
56 Revision 1.5  2000/06/09 20:28:51  morsch
57 All coding rule violations except RS3 corrected (AM)
58
59 Revision 1.4  1999/09/29 09:24:12  fca
60 Introduction of the Copyright and cvs Log
61
62 */
63
64 // Container class for AliGenerator through recursion.
65 // Container is itself an AliGenerator.
66 // What is stored are not the pointers to the generators directly but to objects of type
67 // AliGenCocktail entry.   
68 // The class provides also iterator functionality.  
69 // Author: andreas.morsch@cern.ch 
70 //
71
72 #include <TList.h>
73 #include <TObjArray.h>
74
75 #include "AliGenCocktail.h"
76 #include "AliGenCocktailEntry.h"
77 #include "AliCollisionGeometry.h"
78 #include "AliRun.h"
79
80 ClassImp(AliGenCocktail)
81
82 AliGenCocktail::AliGenCocktail()
83                  :AliGenerator()
84 {
85 // Constructor
86     fName = "Cocktail";
87     fTitle= "Particle Generator using cocktail of generators";
88     fEntries = new TList;
89     flnk1 = 0;
90     flnk2 = 0;
91     fNGenerators=0;
92 }
93
94 AliGenCocktail::AliGenCocktail(const AliGenCocktail & cocktail)
95 {
96 // copy constructor
97 }
98
99 AliGenCocktail::~AliGenCocktail()
100 {
101 // Destructor
102     delete fEntries;
103 }
104
105 void AliGenCocktail::
106 AddGenerator(AliGenerator *Generator, char* Name, Float_t RateExp)
107 {
108 //
109 //  Forward parameters to the new generator
110     if(TestBit(kPtRange) && !(Generator->TestBit(kPtRange)) && !(Generator->TestBit(kMomentumRange))) 
111         Generator->SetPtRange(fPtMin,fPtMax);
112     if(TestBit(kMomentumRange) && !(Generator->TestBit(kPtRange)) && !(Generator->TestBit(kMomentumRange)))
113         Generator->SetMomentumRange(fPMin,fPMax);
114     
115     if (!(Generator->TestBit(kYRange)))    
116         Generator->SetYRange(fYMin,fYMax);
117     if (!(Generator->TestBit(kPhiRange)))   
118         Generator->SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
119     if (!(Generator->TestBit(kThetaRange))) 
120         Generator->SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
121     if (!(Generator->TestBit(kVertexRange))) 
122         Generator->SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
123     Generator->
124         SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
125     Generator->SetVertexSmear(fVertexSmear);
126     Generator->SetTrackingFlag(fTrackIt);    
127 //
128 //  Add generator to list   
129     
130     AliGenCocktailEntry *entry = 
131         new AliGenCocktailEntry(Generator, Name, RateExp);
132      fEntries->Add(entry);
133      fNGenerators++;
134  }
135
136   void AliGenCocktail::Init()
137 {
138 // Initialisation
139     TIter next(fEntries);
140     AliGenCocktailEntry *entry;
141     //
142     // Loop over generators and initialize
143     while((entry = (AliGenCocktailEntry*)next())) {
144         entry->Generator()->Init();
145     }  
146 }
147
148   void AliGenCocktail::FinishRun()
149 {
150 // Initialisation
151     TIter next(fEntries);
152     AliGenCocktailEntry *entry;
153     //
154     // Loop over generators and initialize
155     while((entry = (AliGenCocktailEntry*)next())) {
156         entry->Generator()->FinishRun();
157     }  
158 }
159
160  void AliGenCocktail::Generate()
161 {
162 //
163 // Generate event 
164     TIter next(fEntries);
165     AliGenCocktailEntry *entry = 0;
166     AliGenCocktailEntry *preventry = 0;
167     AliGenerator* gen = 0;
168
169     TObjArray *partArray = gAlice->Particles();
170     //
171     // Loop over generators and generate events
172     Int_t igen=0;
173     
174     while((entry = (AliGenCocktailEntry*)next())) {
175         igen++;
176         if (igen ==1) {
177             entry->SetFirst(0);
178         } else {
179             entry->SetFirst((partArray->GetEntriesFast())+1);
180         }
181 //
182 //      Handle case in which current generator needs collision geometry from previous generator
183 //
184         gen = entry->Generator();
185         if (gen->NeedsCollisionGeometry())
186         {
187             if (preventry && preventry->Generator()->ProvidesCollisionGeometry())
188             {
189                 gen->SetCollisionGeometry(preventry->Generator()->CollisionGeometry());
190             } else {
191                 Fatal("Generate()", "No Collision Geometry Provided");
192             }
193         }
194         
195         entry->Generator()->Generate();
196         entry->SetLast(partArray->GetEntriesFast());
197         preventry = entry;
198     }  
199     next.Reset();
200 }
201
202 AliGenCocktailEntry *  AliGenCocktail::FirstGenerator()
203 {
204 // Iterator over generators: Initialisation
205     flnk1 = fEntries->FirstLink();
206     if (flnk1) {
207         return (AliGenCocktailEntry*) (flnk1->GetObject());
208     } else {
209         return 0;
210     }
211 }
212
213 AliGenCocktailEntry*  AliGenCocktail::NextGenerator()
214 {
215 // Iterator over generators: Increment
216     flnk1 = flnk1->Next();
217     if (flnk1) {
218         return (AliGenCocktailEntry*) (flnk1->GetObject());
219     } else {
220         return 0;
221     }
222 }
223
224 void AliGenCocktail::
225 FirstGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
226 {
227 // Iterator over generator pairs: Initialisation
228     flnk2 = flnk1 = fEntries->FirstLink();
229     if (flnk1) {
230         e2 = e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
231     } else {
232         e2= e1 = 0;
233     }
234 }
235
236 void AliGenCocktail::
237 NextGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
238 {
239 // Iterator over generators: Increment
240     flnk2 = flnk2->Next();
241     if (flnk2) {
242         e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
243         e2 = (AliGenCocktailEntry*) (flnk2->GetObject());       
244     } else {
245         flnk2 = flnk1 = flnk1->Next();
246         if (flnk1) {
247             e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
248             e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
249         } else {
250             e1=0;
251             e2=0;
252         }
253     }
254 }
255
256 AliGenCocktail& AliGenCocktail::operator=(const  AliGenCocktail& rhs)
257 {
258 // Assignment operator
259     return *this;
260 }
261
262