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