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