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"
46 ClassImp(AliGenCocktailAfterBurner)
47 /*********************************************************************/
48 /*********************************************************************/
50 AliGenCocktailAfterBurner::AliGenCocktailAfterBurner()
54 cout<<"AliGenCocktailAfterBurner::AliGenCocktailAfterBurner()"<<endl;
55 SetName("AliGenCocktailAfterBurner");
56 SetTitle("AliGenCocktailAfterBurner");
59 fCurrentGenerator = 0;
61 fAfterBurnerEntries = new TList();
63 fGenerationDone = kFALSE;
68 /*********************************************************************/
69 AliGenCocktailAfterBurner::AliGenCocktailAfterBurner(const AliGenCocktailAfterBurner& cocktail):
70 AliGenCocktail(cocktail)
77 /*********************************************************************/
79 AliGenCocktailAfterBurner::~AliGenCocktailAfterBurner()
83 if (fInternalStacks) //delete stacks
85 fInternalStacks->SetOwner();
86 delete fInternalStacks;
88 if (fAfterBurnerEntries) delete fAfterBurnerEntries; //delete entries
90 /*********************************************************************/
91 /*********************************************************************/
93 void AliGenCocktailAfterBurner::
94 AddAfterBurner(AliGenerator *AfterBurner, char* Name, Float_t RateExp)
97 // Forward parameters to the new AfterBurner
99 if (gDebug>0)cout<<"AliGenCocktailAfterBurner::AddAfterBurner Named "<<Name<<endl;
101 if(TestBit(kPtRange))
102 AfterBurner->SetPtRange(fPtMin,fPtMax);
103 if(TestBit(kMomentumRange))
104 AfterBurner->SetMomentumRange(fPMin,fPMax);
106 AfterBurner->SetYRange(fYMin,fYMax);
107 AfterBurner->SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
108 AfterBurner->SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
109 AfterBurner->SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
110 AfterBurner->SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
111 AfterBurner->SetVertexSmear(fVertexSmear);
112 AfterBurner->SetTrackingFlag(fTrackIt);
114 // Add AfterBurner to list
116 AliGenCocktailEntry *entry =
117 new AliGenCocktailEntry(AfterBurner, Name, RateExp);
118 fAfterBurnerEntries->Add(entry);
123 /*********************************************************************/
124 /*********************************************************************/
126 void AliGenCocktailAfterBurner::Init()
129 fGenerationDone = kFALSE;
130 if (fInternalStacks) //delete stacks
132 fInternalStacks->SetOwner();
133 fInternalStacks->Delete(); //clean after previous generation cycle
136 this->AliGenCocktail::Init();
138 if (gDebug>0) cout<<"AliGenCocktailAfterBurner::Init"<<endl;
139 TIter next(fAfterBurnerEntries);
140 AliGenCocktailEntry *entry;
142 // Loop over generators and initialize
143 while((entry = (AliGenCocktailEntry*)next())) {
144 entry->Generator()->Init();
147 /*********************************************************************/
148 /*********************************************************************/
150 void AliGenCocktailAfterBurner::Generate()
154 // Firsts runs each generator for all events
155 // than after burners ones for each event
157 // It generates and processes all events during
159 // In next calls it just returns already generated
160 // and processed events to the gAlice
163 cout<<"#####################################"<<endl
164 <<"#AliGenCocktailAfterBurner::Generate#"<<endl
165 <<"#####################################"<<endl;
171 {//if generation is done (in first call)
172 //just copy particles from the stack to the gAlice
173 SetTracks(++fCurrentEvent);
174 cout<<"Returning event "<<fCurrentEvent<<endl;
178 { //Here we are in the first call of the method
180 Int_t numberOfEvents = gAlice->GetEventsPerRun();
182 fInternalStacks = new TObjArray(numberOfEvents + fNBgEvents); //Create array of internal stacks
183 for(i=0;i<numberOfEvents + fNBgEvents;i++)
185 stack = new AliStack(10000);
187 fInternalStacks->Add(stack);
189 /*********************************************************************/
190 TIter next(fEntries);
191 AliGenCocktailEntry *entry;
192 AliGenCocktailEntry *e1;
193 AliGenCocktailEntry *e2;
194 TObjArray *partArray;
196 // Loop over generators and generate events
198 while((entry = (AliGenCocktailEntry*)next()))
201 cout<<"Generator "<<igen<<" : "<<entry->GetName()<<endl;
202 /***********************************************/
203 //First generator for all evenets, than second for all events, etc...
204 for(i=0;i<numberOfEvents + fNBgEvents;i++)
206 cout<<" EVENT "<<i<<endl;
208 partArray = stack->Particles();
209 fCurrentGenerator = entry->Generator();
210 fCurrentGenerator->SetStack(stack);
217 entry->SetFirst((partArray->GetEntriesFast())+1);
219 fCurrentGenerator->Generate();
220 entry->SetLast(partArray->GetEntriesFast());
222 /***********************************************/
225 while((entry = (AliGenCocktailEntry*)next()))
229 for ( entry=FirstGenerator();entry;entry=NextGenerator() )
233 for (FirstGeneratorPair(e1,e2); (e1&&e2); NextGeneratorPair(e1,e2) )
235 printf("\n -----------------------------");
241 /***********************************************/
242 /*******After Burners Processing****************/
243 /***********************************************/
244 TIter nextAfterBurner(fAfterBurnerEntries);
245 AliGenCocktailEntry *afterBurnerEntry;
246 Int_t iab =0; //number of current after burner / counter
248 cout<<"\n\nRunning After Burners"<<endl;
249 while((afterBurnerEntry = (AliGenCocktailEntry*)nextAfterBurner()))
251 cout<<"After Burner "<<iab++<<" :"<<afterBurnerEntry->GetName()<<endl;
252 fCurrentGenerator = afterBurnerEntry->Generator();
253 fCurrentGenerator->Generate();
255 cout<<endl<<"Finished. Processed "<<iab<<" After Burners"<<endl;
257 /***********************************************/
258 /***********************************************/
259 /***********************************************/
261 fGenerationDone=kTRUE;
262 SetTracks(0); //copy event 0 to gAlice stack
264 /*********************************************************************/
268 /*********************************************************************/
269 /*********************************************************************/
271 AliGenCocktailAfterBurner& AliGenCocktailAfterBurner::operator=(const AliGenCocktailAfterBurner& rhs)
273 // Assignment operator
277 /*********************************************************************/
278 /*********************************************************************/
280 AliStack* AliGenCocktailAfterBurner::GetStack(Int_t n) const
282 //Returns the pointer to the N'th stack (event)
283 if( ( n<0 ) || ( n>=GetNumberOfEvents() ) )
285 Fatal("AliGenCocktailAfterBurner::GetStack","Asked for non existing stack (%d)",n);
288 return ((AliStack*) fInternalStacks->At(n) );
290 /*********************************************************************/
291 /*********************************************************************/
293 void AliGenCocktailAfterBurner::SetActiveEventNumber(Int_t actev)
295 //Set Active Events Number and Active Stack
296 //There is only one active event number
297 //Made fo convinience of work with AfterBurners (HBT processor)
299 fActiveEvent = actev;
300 fActiveStack = GetStack(actev);
302 /*********************************************************************/
303 /*********************************************************************/
305 void AliGenCocktailAfterBurner::SetTracks(Int_t stackno)
307 //Method which copies tracks from given stack to the
309 AliStack* instack = GetStack(stackno);
313 Double_t px, py, pz, e, vx, vy, vz, tof, polx, poly, polz;
320 Int_t n = instack->GetNtrack();
323 cout<<"AliGenCocktailAfterBurner::SetTracks("<<stackno<<"). Number of particles is: "<<n<<"\n";
326 for(Int_t i = 0; i < n; i++)
329 p = instack->Particle(i);
330 done = !p->TestBit(kDoneBit);
331 parent = p->GetMother(0);
332 pdg = p->GetPdgCode();
341 p->GetPolarisation(pol);
345 mech = AliGenCocktailAfterBurner::IntToMCProcess(p->GetUniqueID());
346 weight = p->GetWeight();
348 gAlice->GetMCApp()->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
349 polx, poly, polz, mech, ntr, weight);
352 /*********************************************************************/
353 /*********************************************************************/
355 TMCProcess AliGenCocktailAfterBurner::IntToMCProcess(Int_t no)
357 //Mothod used to convert uniqueID (integer) to TMCProcess type
358 const TMCProcess kMCprocesses[kMaxMCProcess] =
360 kPNoProcess, kPMultipleScattering, kPEnergyLoss, kPMagneticFieldL,
361 kPDecay, kPPair, kPCompton, kPPhotoelectric, kPBrem, kPDeltaRay,
362 kPAnnihilation, kPHadronic, kPNoProcess, kPEvaporation, kPNuclearFission,
363 kPNuclearAbsorption, kPPbarAnnihilation, kPNCapture, kPHElastic,
364 kPHInhelastic, kPMuonNuclear, kPTOFlimit,kPPhotoFission, kPNoProcess,
365 kPRayleigh, kPNoProcess, kPNoProcess, kPNoProcess, kPNull, kPStop
368 for (Int_t i = 0;i<kMaxMCProcess;i++)
370 if (kMCprocesses[i] == no)
372 return kMCprocesses[i];
378 void AliGenCocktailAfterBurner::Copy(TObject &) const
380 Fatal("Copy","Not implemented!\n");