1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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
28 // 24.09.2001 Piotr Skowronski
30 // fNEvents replaced with gAlice->GetEventsPerRun()
34 #include <Riostream.h>
37 #include <TObjArray.h>
38 #include <TParticle.h>
40 #include "AliGenCocktailAfterBurner.h"
41 #include "AliGenCocktailEntry.h"
45 ClassImp(AliGenCocktailAfterBurner)
46 /*********************************************************************/
47 /*********************************************************************/
49 AliGenCocktailAfterBurner::AliGenCocktailAfterBurner()
53 cout<<"AliGenCocktailAfterBurner::AliGenCocktailAfterBurner()"<<endl;
54 SetName("AliGenCocktailAfterBurner");
55 SetTitle("AliGenCocktailAfterBurner");
58 fCurrentGenerator = 0;
60 fAfterBurnerEntries = new TList();
62 fGenerationDone = kFALSE;
67 /*********************************************************************/
68 AliGenCocktailAfterBurner::AliGenCocktailAfterBurner(const AliGenCocktailAfterBurner& cocktail):
69 AliGenCocktail(cocktail)
76 /*********************************************************************/
78 AliGenCocktailAfterBurner::~AliGenCocktailAfterBurner()
82 if (fInternalStacks) //delete stacks
84 fInternalStacks->SetOwner();
85 delete fInternalStacks;
87 if (fAfterBurnerEntries) delete fAfterBurnerEntries; //delete entries
89 /*********************************************************************/
90 /*********************************************************************/
92 void AliGenCocktailAfterBurner::
93 AddAfterBurner(AliGenerator *AfterBurner, char* Name, Float_t RateExp)
96 // Forward parameters to the new AfterBurner
98 if (gDebug>0)cout<<"AliGenCocktailAfterBurner::AddAfterBurner Named "<<Name<<endl;
100 if(TestBit(kPtRange))
101 AfterBurner->SetPtRange(fPtMin,fPtMax);
102 if(TestBit(kMomentumRange))
103 AfterBurner->SetMomentumRange(fPMin,fPMax);
105 AfterBurner->SetYRange(fYMin,fYMax);
106 AfterBurner->SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
107 AfterBurner->SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
108 AfterBurner->SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
109 AfterBurner->SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
110 AfterBurner->SetVertexSmear(fVertexSmear);
111 AfterBurner->SetTrackingFlag(fTrackIt);
113 // Add AfterBurner to list
115 AliGenCocktailEntry *entry =
116 new AliGenCocktailEntry(AfterBurner, Name, RateExp);
117 fAfterBurnerEntries->Add(entry);
122 /*********************************************************************/
123 /*********************************************************************/
125 void AliGenCocktailAfterBurner::Init()
128 fGenerationDone = kFALSE;
129 if (fInternalStacks) //delete stacks
131 fInternalStacks->SetOwner();
132 fInternalStacks->Delete(); //clean after previous generation cycle
135 this->AliGenCocktail::Init();
137 if (gDebug>0) cout<<"AliGenCocktailAfterBurner::Init"<<endl;
138 TIter next(fAfterBurnerEntries);
139 AliGenCocktailEntry *entry;
141 // Loop over generators and initialize
142 while((entry = (AliGenCocktailEntry*)next())) {
143 entry->Generator()->Init();
146 /*********************************************************************/
147 /*********************************************************************/
149 void AliGenCocktailAfterBurner::Generate()
153 // Firsts runs each generator for all events
154 // than after burners ones for each event
156 // It generates and processes all events during
158 // In next calls it just returns already generated
159 // and processed events to the gAlice
162 cout<<"#####################################"<<endl
163 <<"#AliGenCocktailAfterBurner::Generate#"<<endl
164 <<"#####################################"<<endl;
170 {//if generation is done (in first call)
171 //just copy particles from the stack to the gAlice
172 SetTracks(++fCurrentEvent);
173 cout<<"Returning event "<<fCurrentEvent<<endl;
177 { //Here we are in the first call of the method
179 Int_t numberOfEvents = gAlice->GetEventsPerRun();
181 fInternalStacks = new TObjArray(numberOfEvents + fNBgEvents); //Create array of internal stacks
182 for(i=0;i<numberOfEvents + fNBgEvents;i++)
184 stack = new AliStack(10000);
186 fInternalStacks->Add(stack);
188 /*********************************************************************/
189 TIter next(fEntries);
190 AliGenCocktailEntry *entry;
191 AliGenCocktailEntry *e1;
192 AliGenCocktailEntry *e2;
193 TObjArray *partArray;
195 // Loop over generators and generate events
197 while((entry = (AliGenCocktailEntry*)next()))
200 cout<<"Generator "<<igen<<" : "<<entry->GetName()<<endl;
201 /***********************************************/
202 //First generator for all evenets, than second for all events, etc...
203 for(i=0;i<numberOfEvents + fNBgEvents;i++)
205 cout<<" EVENT "<<i<<endl;
207 partArray = stack->Particles();
208 fCurrentGenerator = entry->Generator();
209 fCurrentGenerator->SetStack(stack);
216 entry->SetFirst((partArray->GetEntriesFast())+1);
218 fCurrentGenerator->Generate();
219 entry->SetLast(partArray->GetEntriesFast());
221 /***********************************************/
224 while((entry = (AliGenCocktailEntry*)next()))
228 for ( entry=FirstGenerator();entry;entry=NextGenerator() )
232 for (FirstGeneratorPair(e1,e2); (e1&&e2); NextGeneratorPair(e1,e2) )
234 printf("\n -----------------------------");
240 /***********************************************/
241 /*******After Burners Processing****************/
242 /***********************************************/
243 TIter nextAfterBurner(fAfterBurnerEntries);
244 AliGenCocktailEntry *afterBurnerEntry;
245 Int_t iab =0; //number of current after burner / counter
247 cout<<"\n\nRunning After Burners"<<endl;
248 while((afterBurnerEntry = (AliGenCocktailEntry*)nextAfterBurner()))
250 cout<<"After Burner "<<iab++<<" :"<<afterBurnerEntry->GetName()<<endl;
251 fCurrentGenerator = afterBurnerEntry->Generator();
252 fCurrentGenerator->Generate();
254 cout<<endl<<"Finished. Processed "<<iab<<" After Burners"<<endl;
256 /***********************************************/
257 /***********************************************/
258 /***********************************************/
260 fGenerationDone=kTRUE;
261 SetTracks(0); //copy event 0 to gAlice stack
263 /*********************************************************************/
267 /*********************************************************************/
268 /*********************************************************************/
270 AliGenCocktailAfterBurner& AliGenCocktailAfterBurner::operator=(const AliGenCocktailAfterBurner& rhs)
272 // Assignment operator
276 /*********************************************************************/
277 /*********************************************************************/
279 AliStack* AliGenCocktailAfterBurner::GetStack(Int_t n) const
281 //Returns the pointer to the N'th stack (event)
282 if( ( n<0 ) || ( n>=GetNumberOfEvents() ) )
284 Fatal("AliGenCocktailAfterBurner::GetStack","Asked for non existing stack (%d)",n);
287 return ((AliStack*) fInternalStacks->At(n) );
289 /*********************************************************************/
290 /*********************************************************************/
292 void AliGenCocktailAfterBurner::SetActiveEventNumber(Int_t actev)
294 //Set Active Events Number and Active Stack
295 //There is only one active event number
296 //Made fo convinience of work with AfterBurners (HBT processor)
298 fActiveEvent = actev;
299 fActiveStack = GetStack(actev);
301 /*********************************************************************/
302 /*********************************************************************/
304 void AliGenCocktailAfterBurner::SetTracks(Int_t stackno)
306 //Method which copies tracks from given stack to the
308 AliStack* instack = GetStack(stackno);
312 Double_t px, py, pz, e, vx, vy, vz, tof, polx, poly, polz;
319 Int_t n = instack->GetNtrack();
322 cout<<"AliGenCocktailAfterBurner::SetTracks("<<stackno<<"). Number of particles is: "<<n<<"\n";
325 for(Int_t i = 0; i < n; i++)
328 p = instack->Particle(i);
329 done = !p->TestBit(kDoneBit);
330 parent = p->GetMother(0);
331 pdg = p->GetPdgCode();
340 p->GetPolarisation(pol);
344 mech = AliGenCocktailAfterBurner::IntToMCProcess(p->GetUniqueID());
345 weight = p->GetWeight();
347 gAlice->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
348 polx, poly, polz, mech, ntr, weight);
351 /*********************************************************************/
352 /*********************************************************************/
354 TMCProcess AliGenCocktailAfterBurner::IntToMCProcess(Int_t no)
356 //Mothod used to convert uniqueID (integer) to TMCProcess type
357 const TMCProcess kMCprocesses[kMaxMCProcess] =
359 kPNoProcess, kPMultipleScattering, kPEnergyLoss, kPMagneticFieldL,
360 kPDecay, kPPair, kPCompton, kPPhotoelectric, kPBrem, kPDeltaRay,
361 kPAnnihilation, kPHadronic, kPNoProcess, kPEvaporation, kPNuclearFission,
362 kPNuclearAbsorption, kPPbarAnnihilation, kPNCapture, kPHElastic,
363 kPHInhelastic, kPMuonNuclear, kPTOFlimit,kPPhotoFission, kPNoProcess,
364 kPRayleigh, kPNoProcess, kPNoProcess, kPNoProcess, kPNull, kPStop
367 for (Int_t i = 0;i<kMaxMCProcess;i++)
369 if (kMCprocesses[i] == no)
371 return kMCprocesses[i];
377 void AliGenCocktailAfterBurner::Copy(AliGenCocktailAfterBurner &) const
379 Fatal("Copy","Not implemented!\n");