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