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