This commit was generated by cvs2svn to compensate for changes in r2,
[u/mrichter/AliRoot.git] / EVGEN / AliGenCocktail.cxx
1 #include "AliGenerator.h"
2 #include "AliGenCocktail.h"
3 #include "TGeant3.h"
4 #include "AliRun.h"
5 #include <TDirectory.h>
6 #include <TFile.h>
7 #include <TTree.h>
8 #include <stdlib.h>
9 ClassImp(AliGenCocktailEntry)
10 void AliGenCocktailEntry::PrintInfo()
11 {
12 printf("\n Generator: %s Generated Events: %d First: %d Last: %d",
13        (const char *) fName, fGenerator->NumberParticles(), fFirst, fLast);
14 }
15
16 ClassImp(AliGenCocktail)
17
18 AliGenCocktail::AliGenCocktail()
19                  :AliGenerator()
20 {
21     fEntries = new TList;
22     fNGenerators=0;
23 }
24
25
26 AliGenCocktail::~AliGenCocktail()
27 {
28     delete fEntries;
29 }
30
31 void AliGenCocktail::
32 AddGenerator(AliGenerator *Generator, TString Name, Float_t RateExp)
33 {
34 //
35 //  Forward parameters to the new generator
36     Generator->SetPtRange(fPtMin,fPtMax);
37     Generator->SetMomentumRange(fPMin,fPMax);
38     Generator->SetYRange(fYMin,fYMax);
39     Generator->
40         SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
41     Generator->
42         SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
43     Generator->
44         SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
45     Generator->
46         SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
47 //
48 //  Add generator to list   
49     AliGenCocktailEntry *Entry = 
50         new AliGenCocktailEntry(Generator, Name, RateExp);
51      fEntries->Add(Entry);
52      fNGenerators++;
53  }
54
55   void AliGenCocktail::Init()
56   {
57       TIter next(fEntries);
58       AliGenCocktailEntry *Entry;
59      //
60      // Loop over generators and initialize
61      while((Entry = (AliGenCocktailEntry*)next())) {
62         Entry->Generator()->Init();
63      }  
64  }
65
66  void AliGenCocktail::Generate()
67  {
68      TIter next(fEntries);
69      AliGenCocktailEntry *Entry;
70      AliGenCocktailEntry *e1;
71      AliGenCocktailEntry *e2;
72      TClonesArray *PartArray = gAlice->Particles();
73      //
74      // Loop over generators and generate events
75      Int_t igen=0;
76      while((Entry = (AliGenCocktailEntry*)next())) {
77          igen++;
78          if (igen ==1) {
79              Entry->SetFirst(0);
80          } else {
81              Entry->SetFirst((PartArray->GetEntriesFast())+1);
82          }
83          Entry->Generator()->Generate();
84          Entry->SetLast(PartArray->GetEntriesFast());
85      }  
86      next.Reset();
87      while((Entry = (AliGenCocktailEntry*)next())) {
88          Entry->PrintInfo();
89      }
90      for (Entry=FirstGenerator();
91           Entry;
92           Entry=NextGenerator()
93          ) {
94          Entry->PrintInfo();
95      }
96      for (FirstGeneratorPair(e1,e2);
97           (e1&&e2);
98           NextGeneratorPair(e1,e2)
99          ){
100          printf("\n -----------------------------");
101          e1->PrintInfo();
102          e2->PrintInfo();
103      }
104  }
105
106 AliGenCocktailEntry *  AliGenCocktail::FirstGenerator()
107 {
108     flnk1 = fEntries->FirstLink();
109     if (flnk1) {
110         return (AliGenCocktailEntry*) (flnk1->GetObject());
111     } else {
112         return 0;
113     }
114 }
115
116 AliGenCocktailEntry*  AliGenCocktail::NextGenerator()
117 {
118     flnk1 = flnk1->Next();
119     if (flnk1) {
120         return (AliGenCocktailEntry*) (flnk1->GetObject());
121     } else {
122         return 0;
123     }
124 }
125
126 void AliGenCocktail::
127 FirstGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
128 {
129     flnk2 = flnk1 = fEntries->FirstLink();
130     if (flnk1) {
131         e2 = e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
132     } else {
133         e2= e1 = 0;
134     }
135 }
136
137 void AliGenCocktail::
138 NextGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
139 {
140     flnk2 = flnk2->Next();
141     if (flnk2) {
142         e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
143         e2 = (AliGenCocktailEntry*) (flnk2->GetObject());       
144     } else {
145         flnk2 = flnk1 = flnk1->Next();
146         if (flnk1) {
147             e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
148             e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
149         } else {
150             e1=0;
151             e2=0;
152         }
153     }
154 }
155
156
157 void AliGenCocktail::Streamer(TBuffer &R__b)
158 {
159    // Stream an object of class AliGenCocktail.
160      TIter next(fEntries);
161      AliGenCocktailEntry *Entry;
162
163    if (R__b.IsReading()) {
164       Version_t R__v = R__b.ReadVersion(); if (R__v) { }
165       AliGenerator::Streamer(R__b);
166       R__b >> fNGenerators;
167       R__b >> fEntries;
168 // Stream generation related information
169       while((Entry = (AliGenCocktailEntry*)next())) {
170           Entry->Streamer(R__b);
171       }  
172    } else {
173        R__b.WriteVersion(AliGenCocktail::IsA());
174        AliGenerator::Streamer(R__b);
175        R__b << fNGenerators;
176        R__b << fEntries;
177 // Stream generation related information
178       while((Entry = (AliGenCocktailEntry*)next())) {
179           Entry->Streamer(R__b);
180       }  
181    }
182 }
183
184