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