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