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