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