comment about deleting det switch objects added
[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$
e6e2a20e 18Revision 1.5 2000/06/09 20:28:51 morsch
19All coding rule violations except RS3 corrected (AM)
20
374924b5 21Revision 1.4 1999/09/29 09:24:12 fca
22Introduction of the Copyright and cvs Log
23
4c039060 24*/
25
fe4da5cc 26#include "AliGenCocktail.h"
374924b5 27#include "AliGenCocktailEntry.h"
fe4da5cc 28#include "AliRun.h"
fe4da5cc 29#include <stdlib.h>
fe4da5cc 30
31ClassImp(AliGenCocktail)
32
33AliGenCocktail::AliGenCocktail()
34 :AliGenerator()
35{
374924b5 36// Constructor
fe4da5cc 37 fEntries = new TList;
38 fNGenerators=0;
39}
40
374924b5 41AliGenCocktail::AliGenCocktail(const AliGenCocktail & cocktail)
42{
43// copy constructor
44}
fe4da5cc 45
46AliGenCocktail::~AliGenCocktail()
47{
374924b5 48// Destructor
fe4da5cc 49 delete fEntries;
50}
51
52void AliGenCocktail::
53AddGenerator(AliGenerator *Generator, TString Name, Float_t RateExp)
54{
55//
56// Forward parameters to the new generator
57 Generator->SetPtRange(fPtMin,fPtMax);
58 Generator->SetMomentumRange(fPMin,fPMax);
59 Generator->SetYRange(fYMin,fYMax);
60 Generator->
61 SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
62 Generator->
63 SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
64 Generator->
65 SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
66 Generator->
67 SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
7a50a130 68 Generator->SetVertexSmear(fVertexSmear);
69 Generator->SetTrackingFlag(fTrackIt);
fe4da5cc 70//
71// Add generator to list
374924b5 72 AliGenCocktailEntry *entry =
fe4da5cc 73 new AliGenCocktailEntry(Generator, Name, RateExp);
374924b5 74 fEntries->Add(entry);
fe4da5cc 75 fNGenerators++;
76 }
77
78 void AliGenCocktail::Init()
374924b5 79{
80// Initialisation
81 TIter next(fEntries);
82 AliGenCocktailEntry *entry;
83 //
84 // Loop over generators and initialize
85 while((entry = (AliGenCocktailEntry*)next())) {
86 entry->Generator()->Init();
87 }
88}
fe4da5cc 89
90 void AliGenCocktail::Generate()
374924b5 91{
92//
93// Generate event
94 TIter next(fEntries);
95 AliGenCocktailEntry *entry;
96 AliGenCocktailEntry *e1;
97 AliGenCocktailEntry *e2;
98 TClonesArray *partArray = gAlice->Particles();
99 //
100 // Loop over generators and generate events
101 Int_t igen=0;
102 while((entry = (AliGenCocktailEntry*)next())) {
103 igen++;
104 if (igen ==1) {
105 entry->SetFirst(0);
106 } else {
107 entry->SetFirst((partArray->GetEntriesFast())+1);
108 }
109 entry->Generator()->Generate();
110 entry->SetLast(partArray->GetEntriesFast());
111 }
112 next.Reset();
113 while((entry = (AliGenCocktailEntry*)next())) {
114 entry->PrintInfo();
115 }
116 for (entry=FirstGenerator();
117 entry;
118 entry=NextGenerator()
119 ) {
120 entry->PrintInfo();
121 }
122 for (FirstGeneratorPair(e1,e2);
123 (e1&&e2);
124 NextGeneratorPair(e1,e2)
125 ){
126 printf("\n -----------------------------");
127 e1->PrintInfo();
128 e2->PrintInfo();
129 }
130}
fe4da5cc 131
132AliGenCocktailEntry * AliGenCocktail::FirstGenerator()
133{
374924b5 134// Iterator over generators: Initialisation
fe4da5cc 135 flnk1 = fEntries->FirstLink();
136 if (flnk1) {
137 return (AliGenCocktailEntry*) (flnk1->GetObject());
138 } else {
139 return 0;
140 }
141}
142
143AliGenCocktailEntry* AliGenCocktail::NextGenerator()
144{
374924b5 145// Iterator over generators: Increment
fe4da5cc 146 flnk1 = flnk1->Next();
147 if (flnk1) {
148 return (AliGenCocktailEntry*) (flnk1->GetObject());
149 } else {
150 return 0;
151 }
152}
153
154void AliGenCocktail::
155FirstGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
156{
374924b5 157// Iterator over generator pairs: Initialisation
fe4da5cc 158 flnk2 = flnk1 = fEntries->FirstLink();
159 if (flnk1) {
160 e2 = e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
161 } else {
162 e2= e1 = 0;
163 }
164}
165
166void AliGenCocktail::
167NextGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2)
168{
374924b5 169// Iterator over generators: Increment
fe4da5cc 170 flnk2 = flnk2->Next();
171 if (flnk2) {
172 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
173 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
174 } else {
175 flnk2 = flnk1 = flnk1->Next();
176 if (flnk1) {
177 e1 = (AliGenCocktailEntry*) (flnk1->GetObject());
178 e2 = (AliGenCocktailEntry*) (flnk2->GetObject());
179 } else {
180 e1=0;
181 e2=0;
182 }
183 }
184}
185
186
187void AliGenCocktail::Streamer(TBuffer &R__b)
188{
374924b5 189 // Stream an object of class AliGenCocktail.
e6e2a20e 190
374924b5 191 AliGenCocktailEntry *entry;
192
193 if (R__b.IsReading()) {
194 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
195 AliGenerator::Streamer(R__b);
196 R__b >> fNGenerators;
197 R__b >> fEntries;
e6e2a20e 198 TIter next(fEntries);
fe4da5cc 199// Stream generation related information
374924b5 200 while((entry = (AliGenCocktailEntry*)next())) {
201 entry->Streamer(R__b);
202 }
203 } else {
204 R__b.WriteVersion(AliGenCocktail::IsA());
205 AliGenerator::Streamer(R__b);
206 R__b << fNGenerators;
207 R__b << fEntries;
e6e2a20e 208 TIter next(fEntries);
fe4da5cc 209// Stream generation related information
374924b5 210 while((entry = (AliGenCocktailEntry*)next())) {
211 entry->Streamer(R__b);
212 }
213 }
214}
215
216AliGenCocktail& AliGenCocktail::operator=(const AliGenCocktail& rhs)
217{
218// Assignment operator
219 return *this;
fe4da5cc 220}
221
222