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