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