Missing initialisation of headers added,
[u/mrichter/AliRoot.git] / EVGEN / AliGenCocktailAfterBurner.cxx
CommitLineData
0b359ada 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
88cb7938 16/* $Id$ */
17
0b359ada 18//
19// Container class for AliGenerator and AfterBurners
20// (which are AliGenerators as well) through recursion.
21// The container is itself an AliGenerator a
22// what is stored are not the pointers to the generators directly
23// but to objects of type
24// AliGenCocktailAfterBurner entry.
25// The class provides also iterator functionality.
26// Author: andreas.morsch@cern.ch and piotr.skowronski@cern.ch
27//
2b9786f4 28// 24.09.2001 Piotr Skowronski
29// debug -> gDebug,
124253ee 30// fNEvents replaced with AliRunLoader::GetNumberOfEvents()
2b9786f4 31//
2b9786f4 32
88cb7938 33
34#include <Riostream.h>
35
0b359ada 36#include <TList.h>
88cb7938 37#include <TObjArray.h>
0b359ada 38#include <TParticle.h>
88cb7938 39
40#include "AliGenCocktailAfterBurner.h"
41#include "AliGenCocktailEntry.h"
baf77725 42#include "AliGenCocktailEventHeader.h"
cc41459d 43#include "AliCollisionGeometry.h"
88cb7938 44#include "AliStack.h"
5d12ce38 45#include "AliMC.h"
0b359ada 46
2b9786f4 47
0b359ada 48ClassImp(AliGenCocktailAfterBurner)
2b9786f4 49/*********************************************************************/
50/*********************************************************************/
0b359ada 51
1c56e311 52 AliGenCocktailAfterBurner::AliGenCocktailAfterBurner():
53 fNAfterBurners(0),
54 fAfterBurnerEntries(new TList()),
55 fGenerationDone(kFALSE),
56 fInternalStacks(0),
57 fCollisionGeometries(0),
9c64a93a 58 fHeaders(0),
1c56e311 59 fCurrentEvent(0),
60 fActiveStack(0),
61 fActiveEvent(-1),
62 fCurrentGenerator(0),
63 fNBgEvents(0)
0b359ada 64{
65// Constructor
2b9786f4 66 if (gDebug > 0)
1c56e311 67 cout<<"AliGenCocktailAfterBurner::AliGenCocktailAfterBurner()"<<endl;
0b359ada 68 SetName("AliGenCocktailAfterBurner");
69 SetTitle("AliGenCocktailAfterBurner");
0b359ada 70}
20dddfab 71
2b9786f4 72/*********************************************************************/
0b359ada 73
74AliGenCocktailAfterBurner::~AliGenCocktailAfterBurner()
75 {
2b9786f4 76//destructor
77
78 if (fInternalStacks) //delete stacks
79 {
80 fInternalStacks->SetOwner();
81 delete fInternalStacks;
82 }
83 if (fAfterBurnerEntries) delete fAfterBurnerEntries; //delete entries
cc41459d 84 delete[] fCollisionGeometries;
9c64a93a 85 delete[] fHeaders;
0b359ada 86 }
2b9786f4 87/*********************************************************************/
88/*********************************************************************/
0b359ada 89
90void AliGenCocktailAfterBurner::
91AddAfterBurner(AliGenerator *AfterBurner, char* Name, Float_t RateExp)
92{
93//
94// Forward parameters to the new AfterBurner
95
2b9786f4 96 if (gDebug>0)cout<<"AliGenCocktailAfterBurner::AddAfterBurner Named "<<Name<<endl;
0b359ada 97
98 if(TestBit(kPtRange))
99 AfterBurner->SetPtRange(fPtMin,fPtMax);
100 if(TestBit(kMomentumRange))
101 AfterBurner->SetMomentumRange(fPMin,fPMax);
102
103 AfterBurner->SetYRange(fYMin,fYMax);
466bfded 104 AfterBurner->SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
105 AfterBurner->SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
106 AfterBurner->SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
107 AfterBurner->SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
0b359ada 108 AfterBurner->SetVertexSmear(fVertexSmear);
109 AfterBurner->SetTrackingFlag(fTrackIt);
59fe7b77 110 AfterBurner->SetVertexSource(kContainer);
0b359ada 111//
112// Add AfterBurner to list
113
114 AliGenCocktailEntry *entry =
115 new AliGenCocktailEntry(AfterBurner, Name, RateExp);
116 fAfterBurnerEntries->Add(entry);
117 fNAfterBurners++;
984c69bd 118//
984c69bd 119
0b359ada 120}
2b9786f4 121/*********************************************************************/
122/*********************************************************************/
0b359ada 123
124void AliGenCocktailAfterBurner::Init()
125{
126// Initialisation
2b9786f4 127 fGenerationDone = kFALSE;
466bfded 128 if (fInternalStacks) //delete stacks
129 {
130 fInternalStacks->SetOwner();
131 fInternalStacks->Delete(); //clean after previous generation cycle
132 }
133
cc41459d 134 if (fCollisionGeometries) delete[] fCollisionGeometries;
cc41459d 135
0b359ada 136 this->AliGenCocktail::Init();
137
2b9786f4 138 if (gDebug>0) cout<<"AliGenCocktailAfterBurner::Init"<<endl;
0b359ada 139 TIter next(fAfterBurnerEntries);
140 AliGenCocktailEntry *entry;
141 //
142 // Loop over generators and initialize
143 while((entry = (AliGenCocktailEntry*)next())) {
144 entry->Generator()->Init();
145 }
146}
2b9786f4 147/*********************************************************************/
148/*********************************************************************/
0b359ada 149
150void AliGenCocktailAfterBurner::Generate()
151{
152//
2b9786f4 153// Generate event
154// Firsts runs each generator for all events
155// than after burners ones for each event
156//
157// It generates and processes all events during
158// first call only.
159// In next calls it just returns already generated
160// and processed events to the gAlice
161
162 if (gDebug>0)
163 cout<<"#####################################"<<endl
164 <<"#AliGenCocktailAfterBurner::Generate#"<<endl
165 <<"#####################################"<<endl;
baf77725 166 // Initialize header
baf77725 167 //
0b359ada 168 Int_t i; //iterator
169 AliStack * stack;
2b9786f4 170
0b359ada 171 if (fGenerationDone)
2b9786f4 172 {//if generation is done (in first call)
173 //just copy particles from the stack to the gAlice
174 SetTracks(++fCurrentEvent);
9c64a93a 175 fHeader = fHeaders[fCurrentEvent];
176 gAlice->SetGenEventHeader(fHeader);
177 cout<<"Returning event " << fCurrentEvent<<endl;
2b9786f4 178 return;
0b359ada 179 }
180 else
2b9786f4 181 { //Here we are in the first call of the method
9c64a93a 182 Int_t numberOfEvents = AliRunLoader::Instance()->GetNumberOfEventsPerRun();
183 cout << "Number of events per run" << numberOfEvents << endl;
184 TArrayF eventVertex;
185 eventVertex.Set(3 * (numberOfEvents + fNBgEvents));
186 fCurrentEvent=0;
2b9786f4 187 //Create stacks
9c64a93a 188 fInternalStacks = new TObjArray(numberOfEvents + fNBgEvents); //Create array of internal stacks
189 fCollisionGeometries = new AliCollisionGeometry*[numberOfEvents + fNBgEvents]; //Create array of collision geometries
190 fHeaders = new AliGenCocktailEventHeader*[numberOfEvents + fNBgEvents]; //Create array of headers
191
192 for(i = 0; i < numberOfEvents + fNBgEvents; i++)
2b9786f4 193 {
9c64a93a 194 stack = new AliStack(10000);
195 stack->Reset();
196 fInternalStacks->Add(stack);
197 Vertex();
198 for (Int_t j = 0; j < 3; j++) eventVertex[3 * i + j] = fVertex[j];
0709d8b9 199 fHeaders[i] = new AliGenCocktailEventHeader();
2b9786f4 200 }
0b359ada 201/*********************************************************************/
2b9786f4 202 TIter next(fEntries);
203 AliGenCocktailEntry *entry;
204 AliGenCocktailEntry *e1;
205 AliGenCocktailEntry *e2;
d94af0c1 206 const TObjArray *partArray;
2b9786f4 207 //
208 // Loop over generators and generate events
209 Int_t igen=0;
210 while((entry = (AliGenCocktailEntry*)next()))
211 {
212 igen++;
213 cout<<"Generator "<<igen<<" : "<<entry->GetName()<<endl;
214/***********************************************/
0b359ada 215//First generator for all evenets, than second for all events, etc...
9c64a93a 216 for(i = 0; i < numberOfEvents + fNBgEvents; i++)
59fe7b77 217 {
218 cout<<" EVENT "<<i << endl;
2b9786f4 219 stack = GetStack(i);
220 partArray = stack->Particles();
221 fCurrentGenerator = entry->Generator();
222 fCurrentGenerator->SetStack(stack);
223 if (igen ==1)
59fe7b77 224 {
2b9786f4 225 entry->SetFirst(0);
59fe7b77 226 }
2b9786f4 227 else
59fe7b77 228 {
2b9786f4 229 entry->SetFirst((partArray->GetEntriesFast())+1);
59fe7b77 230 }
9c64a93a 231 // Set the vertex for the generator
232 Int_t ioff = 3 * i;
233 fCurrentGenerator->SetVertex(eventVertex.At(ioff), eventVertex.At(ioff + 1), eventVertex.At(ioff + 2));
234 fHeader = fHeaders[i];
235 // Set the vertex for the cocktail
236 TArrayF v(3);
237 for (Int_t j=0; j<3; j++) v[j] = eventVertex.At(ioff + j);
238 fHeader->SetPrimaryVertex(v);
239 // Generate event
59fe7b77 240 fCurrentGenerator->Generate();
9c64a93a 241 //
59fe7b77 242 entry->SetLast(partArray->GetEntriesFast());
243
244 if (fCurrentGenerator->ProvidesCollisionGeometry()) fCollisionGeometries[i] = fCurrentGenerator->CollisionGeometry();
245
9c64a93a 246 } // event loop
2b9786f4 247/***********************************************/
9c64a93a 248 } // generator loop
2b9786f4 249 next.Reset();
250 while((entry = (AliGenCocktailEntry*)next()))
251 {
252 entry->PrintInfo();
253 }
254 for ( entry=FirstGenerator();entry;entry=NextGenerator() )
255 {
256 entry->PrintInfo();
257 }
258 for (FirstGeneratorPair(e1,e2); (e1&&e2); NextGeneratorPair(e1,e2) )
259 {
260 printf("\n -----------------------------");
261 e1->PrintInfo();
262 e2->PrintInfo();
0b359ada 263 }
264
0b359ada 265
2b9786f4 266 /***********************************************/
267 /*******After Burners Processing****************/
268 /***********************************************/
269 TIter nextAfterBurner(fAfterBurnerEntries);
270 AliGenCocktailEntry *afterBurnerEntry;
271 Int_t iab =0; //number of current after burner / counter
272
273 cout<<"\n\nRunning After Burners"<<endl;
274 while((afterBurnerEntry = (AliGenCocktailEntry*)nextAfterBurner()))
275 {
276 cout<<"After Burner "<<iab++<<" :"<<afterBurnerEntry->GetName()<<endl;
277 fCurrentGenerator = afterBurnerEntry->Generator();
278 fCurrentGenerator->Generate();
279 }
280 cout<<endl<<"Finished. Processed "<<iab<<" After Burners"<<endl;
281
282 /***********************************************/
283 /***********************************************/
284 /***********************************************/
0b359ada 285
2b9786f4 286 fGenerationDone=kTRUE;
287 SetTracks(0); //copy event 0 to gAlice stack
0b359ada 288
289/*********************************************************************/
baf77725 290 // Pass the header to gAlice
9c64a93a 291 fHeader = fHeaders[0];
baf77725 292 gAlice->SetGenEventHeader(fHeader);
9c64a93a 293 } //else generated
0b359ada 294}
2b9786f4 295/*********************************************************************/
296/*********************************************************************/
0b359ada 297
20dddfab 298AliStack* AliGenCocktailAfterBurner::GetStack(Int_t n) const
0b359ada 299{
2b9786f4 300//Returns the pointer to the N'th stack (event)
c516e34c 301 if( ( n<0 ) || ( n >= (GetNumberOfEvents()) ) )
0b359ada 302 {
2b9786f4 303 Fatal("AliGenCocktailAfterBurner::GetStack","Asked for non existing stack (%d)",n);
304 return 0;
0b359ada 305 }
2682e810 306 return ((AliStack*) fInternalStacks->At(n) );
0b359ada 307}
cc41459d 308
309/*********************************************************************/
310/*********************************************************************/
311
cc41459d 312AliCollisionGeometry* AliGenCocktailAfterBurner::GetCollisionGeometry(Int_t n) const
313{
314//Returns the pointer to the N'th stack (event)
315 if( ( n<0 ) || ( n>=GetNumberOfEvents() ) )
316 {
317 Fatal("AliGenCocktailAfterBurner::GetCollisionGeometry","Asked for non existing stack (%d)",n);
318 return 0;
319 }
320 return fCollisionGeometries[n];
321}
322
2b9786f4 323/*********************************************************************/
324/*********************************************************************/
0b359ada 325
326void AliGenCocktailAfterBurner::SetActiveEventNumber(Int_t actev)
327{
2b9786f4 328//Set Active Events Number and Active Stack
329//There is only one active event number
330//Made fo convinience of work with AfterBurners (HBT processor)
331
0b359ada 332 fActiveEvent = actev;
333 fActiveStack = GetStack(actev);
334}
2b9786f4 335/*********************************************************************/
336/*********************************************************************/
0b359ada 337
338void AliGenCocktailAfterBurner::SetTracks(Int_t stackno)
339{
2b9786f4 340//Method which copies tracks from given stack to the
341//gAlice's stack
0b359ada 342 AliStack* instack = GetStack(stackno);
343 Int_t done;
344 Int_t parent;
345 Int_t pdg;
346 Double_t px, py, pz, e, vx, vy, vz, tof, polx, poly, polz;
acc86a24 347 TMCProcess mech;
0b359ada 348 Int_t ntr;
349 Float_t weight;
350 TVector3 pol;
351
352 TParticle * p;
20dddfab 353 Int_t n = instack->GetNtrack();
2b9786f4 354 if (gDebug)
0b359ada 355 {
20dddfab 356 cout<<"AliGenCocktailAfterBurner::SetTracks("<<stackno<<"). Number of particles is: "<<n<<"\n";
0b359ada 357 }
358
20dddfab 359 for(Int_t i = 0; i < n; i++)
0b359ada 360 {
361
2b9786f4 362 p = instack->Particle(i);
363 done = !p->TestBit(kDoneBit);
364 parent = p->GetMother(0);
365 pdg = p->GetPdgCode();
366 px = p->Px();
367 py = p->Py();
368 pz = p->Pz();
369 e = p->Energy();
370 vx = p->Vx();
371 vy = p->Vy();
372 vz = p->Vz();
373 tof = p->T();
374 p->GetPolarisation(pol);
375 polx = pol.X();
376 poly = pol.Y();
377 polz = pol.Z();
378 mech = AliGenCocktailAfterBurner::IntToMCProcess(p->GetUniqueID());
379 weight = p->GetWeight();
380
cc41459d 381 gAlice->GetMCApp()->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,polx, poly, polz, mech, ntr, weight);
382
cc41459d 383 SetHighWaterMark(ntr) ;
cc41459d 384
0b359ada 385 }
386}
2b9786f4 387/*********************************************************************/
388/*********************************************************************/
0b359ada 389
acc86a24 390TMCProcess AliGenCocktailAfterBurner::IntToMCProcess(Int_t no)
0b359ada 391{
acc86a24 392 //Mothod used to convert uniqueID (integer) to TMCProcess type
393 const TMCProcess kMCprocesses[kMaxMCProcess] =
2b9786f4 394 {
395 kPNoProcess, kPMultipleScattering, kPEnergyLoss, kPMagneticFieldL,
0b359ada 396 kPDecay, kPPair, kPCompton, kPPhotoelectric, kPBrem, kPDeltaRay,
397 kPAnnihilation, kPHadronic, kPNoProcess, kPEvaporation, kPNuclearFission,
398 kPNuclearAbsorption, kPPbarAnnihilation, kPNCapture, kPHElastic,
399 kPHInhelastic, kPMuonNuclear, kPTOFlimit,kPPhotoFission, kPNoProcess,
2b9786f4 400 kPRayleigh, kPNoProcess, kPNoProcess, kPNoProcess, kPNull, kPStop
401 };
0b359ada 402
403 for (Int_t i = 0;i<kMaxMCProcess;i++)
404 {
20dddfab 405 if (kMCprocesses[i] == no)
2b9786f4 406 {
20dddfab 407 return kMCprocesses[i];
2b9786f4 408 }
0b359ada 409 }
410 return kPNoProcess;
411}
198bb1c7 412