New files needed by the HBT processor (P.Skowronski)
[u/mrichter/AliRoot.git] / EVGEN / AliGenCocktailAfterBurner.cxx
index b7eb9bb..abf0d6c 100644 (file)
 // The class provides also iterator functionality.  
 // Author: andreas.morsch@cern.ch and piotr.skowronski@cern.ch
 //
-
+// 24.09.2001  Piotr Skowronski
+//             debug -> gDebug,
+//             fNEvents replaced with gAlice->GetEventsPerRun()
+//
 #include "AliGenCocktailAfterBurner.h"
 #include "AliGenCocktailEntry.h"
-#include "AliRun.h"
+
 #include "AliStack.h"
 #include <TObjArray.h>
 #include <TList.h>
 #include <TParticle.h>
 #include <iostream.h>
 
-static const Bool_t debug = kFALSE;
+
 ClassImp(AliGenCocktailAfterBurner)
+/*********************************************************************/ 
+/*********************************************************************/ 
 
 AliGenCocktailAfterBurner::AliGenCocktailAfterBurner()
 {
 // Constructor
-    if (debug
+    if (gDebug > 0
        cout<<"AliGenCocktailAfterBurner::AliGenCocktailAfterBurner()"<<endl;
     SetName("AliGenCocktailAfterBurner");
     SetTitle("AliGenCocktailAfterBurner");
@@ -51,14 +56,22 @@ AliGenCocktailAfterBurner::AliGenCocktailAfterBurner()
     
     fActiveEvent = -1;  
 }
-
+/*********************************************************************/ 
+/*********************************************************************/ 
 
 AliGenCocktailAfterBurner::~AliGenCocktailAfterBurner()
   {
-    fInternalStacks->SetOwner();
-    delete fInternalStacks;
-    delete fAfterBurnerEntries;
+//destructor
+
+    if (fInternalStacks) //delete stacks
+     { 
+       fInternalStacks->SetOwner();
+       delete fInternalStacks;
+    }
+    if (fAfterBurnerEntries) delete fAfterBurnerEntries; //delete entries
   }
+/*********************************************************************/ 
+/*********************************************************************/ 
 
 void AliGenCocktailAfterBurner::
 AddAfterBurner(AliGenerator *AfterBurner, char* Name, Float_t RateExp)
@@ -66,7 +79,7 @@ AddAfterBurner(AliGenerator *AfterBurner, char* Name, Float_t RateExp)
 //
 //  Forward parameters to the new AfterBurner
     
-    if (debug)cout<<"AliGenCocktailAfterBurner::AddAfterBurner  Named "<<Name<<endl;
+    if (gDebug>0)cout<<"AliGenCocktailAfterBurner::AddAfterBurner  Named "<<Name<<endl;
 
     if(TestBit(kPtRange)) 
        AfterBurner->SetPtRange(fPtMin,fPtMax);
@@ -92,16 +105,18 @@ AddAfterBurner(AliGenerator *AfterBurner, char* Name, Float_t RateExp)
     fAfterBurnerEntries->Add(entry);
     fNAfterBurners++;
 //
-    SetNumberOfEvents(gAlice->GetEventsPerRun());
     
 }
+/*********************************************************************/ 
+/*********************************************************************/ 
 
 void AliGenCocktailAfterBurner::Init()
 {
 // Initialisation
+    fGenerationDone = kFALSE;
     this->AliGenCocktail::Init(); 
     
-    if (debug) cout<<"AliGenCocktailAfterBurner::Init"<<endl;
+    if (gDebug>0) cout<<"AliGenCocktailAfterBurner::Init"<<endl;
     TIter next(fAfterBurnerEntries);
     AliGenCocktailEntry *entry;
     //
@@ -110,141 +125,167 @@ void AliGenCocktailAfterBurner::Init()
        entry->Generator()->Init();
     }  
 }
+/*********************************************************************/ 
+/*********************************************************************/ 
 
 void AliGenCocktailAfterBurner::Generate()
 {
 //
-// Generate event 
-    if (debug)cout<<"#####################################"<<endl
-                  <<"#AliGenCocktailAfterBurner::Generate#"
-                 <<endl<<"#####################################"<<endl;
+// Generate event
+//  Firsts runs each generator for all events
+//  than after burners ones for each event
+//
+//  It generates and processes all events during
+//  first call only.
+//  In next calls it just returns already generated 
+//  and processed events to the gAlice
+
+    if (gDebug>0)
+      cout<<"#####################################"<<endl
+          <<"#AliGenCocktailAfterBurner::Generate#"<<endl
+          <<"#####################################"<<endl;
     
     Int_t i; //iterator
     AliStack * stack;
+    
     if (fGenerationDone)
-    { 
-       SetTracks(++fCurrentEvent);
-       cout<<"Returning event "<<fCurrentEvent<<endl;
-       return;  
+    {//if generation is done (in first call) 
+     //just copy particles from the stack to the gAlice
+      SetTracks(++fCurrentEvent);
+      cout<<"Returning event "<<fCurrentEvent<<endl;
+      return;  
     }
     else
-    { 
-       fCurrentEvent=0;
-       fInternalStacks = new TObjArray(fNumberOfEvents); //Create array of internal stacks
-       for(i=0;i<fNumberOfEvents;i++) 
-       {       
-           stack = new AliStack(10000);
-           stack->Reset();
-           fInternalStacks->Add(stack);
-       }
+    { //Here we are in the first call of the method
+      fCurrentEvent=0;
+      Int_t numberOfEvents = gAlice->GetEventsPerRun();
+      //Create stacks
+      fInternalStacks = new TObjArray(numberOfEvents); //Create array of internal stacks
+      for(i=0;i<numberOfEvents;i++) 
+       {       
+        stack = new AliStack(10000);
+        stack->Reset();
+        fInternalStacks->Add(stack);
+       }
 /*********************************************************************/ 
-       TIter next(fEntries);
-       AliGenCocktailEntry *entry;
-       AliGenCocktailEntry *e1;
-       AliGenCocktailEntry *e2;
-       TObjArray *partArray;
-       //
-       // Loop over generators and generate events
-       Int_t igen=0;
-       while((entry = (AliGenCocktailEntry*)next())) 
-       {
-           igen++;
-           cout<<"Generator number "<<igen<<endl;
-           /***********************************************/
+      TIter next(fEntries);
+      AliGenCocktailEntry *entry;
+      AliGenCocktailEntry *e1;
+      AliGenCocktailEntry *e2;
+      TObjArray *partArray;
+  //
+  // Loop over generators and generate events
+      Int_t igen=0;
+      while((entry = (AliGenCocktailEntry*)next())) 
+      {
+        igen++;
+        cout<<"Generator "<<igen<<"  : "<<entry->GetName()<<endl;
+/***********************************************/
 //First generator for all evenets, than second for all events, etc...
-           for(i=0;i<fNumberOfEvents;i++) 
-           {  
-               
-               cout<<"                  EVENT "<<i<<endl;
-               stack = GetStack(i);
-               partArray = stack->Particles();
-               fCurrentGenerator = entry->Generator();
-               fCurrentGenerator->SetStack(stack);
-               
-               if (igen ==1) 
-               {
-                   entry->SetFirst(0);
-               } 
-               else 
-               {
-                   entry->SetFirst((partArray->GetEntriesFast())+1);
-               }
-               fCurrentGenerator->Generate();
-               entry->SetLast(partArray->GetEntriesFast());
-           }
-           /***********************************************/
-       }
-       next.Reset();
-       while((entry = (AliGenCocktailEntry*)next())) 
-       {
-           entry->PrintInfo();
-       }
-       for ( entry=FirstGenerator();entry;entry=NextGenerator() ) 
-       {
-           entry->PrintInfo();
-       }
-       
-       for (FirstGeneratorPair(e1,e2); (e1&&e2); NextGeneratorPair(e1,e2) )
-       {
-           printf("\n -----------------------------");
-           e1->PrintInfo();
-           e2->PrintInfo();
+        for(i=0;i<numberOfEvents;i++) 
+          {  
+            cout<<"                  EVENT "<<i<<endl;
+            stack = GetStack(i);
+            partArray = stack->Particles();
+            fCurrentGenerator = entry->Generator();
+            fCurrentGenerator->SetStack(stack);
+            if (igen ==1) 
+              {
+                entry->SetFirst(0);
+              } 
+            else 
+              {
+                entry->SetFirst((partArray->GetEntriesFast())+1);
+              }
+                fCurrentGenerator->Generate();
+                entry->SetLast(partArray->GetEntriesFast());
+           }
+/***********************************************/
+      }
+      next.Reset();
+      while((entry = (AliGenCocktailEntry*)next())) 
+        {
+          entry->PrintInfo();
+        }
+      for ( entry=FirstGenerator();entry;entry=NextGenerator() ) 
+        {
+          entry->PrintInfo();
+        }
+      for (FirstGeneratorPair(e1,e2); (e1&&e2); NextGeneratorPair(e1,e2) )
+        {
+          printf("\n -----------------------------");
+          e1->PrintInfo();
+          e2->PrintInfo();
         }
        
-       /***********************************************/
-       /*******After Burners Processing****************/
-       /***********************************************/
-       TIter nextAfterBurner(fAfterBurnerEntries);
-       AliGenCocktailEntry *afterBurnerEntry;
-       Int_t iab =0;
-       cout<<"\n\nRunning After Burners"<<endl;
-       while((afterBurnerEntry = (AliGenCocktailEntry*)nextAfterBurner()))
-       {
-           cout<<"After Burner number "<<iab++<<endl;
-           fCurrentGenerator = afterBurnerEntry->Generator();
-           fCurrentGenerator->Generate();
-       }
-       cout<<endl<<"Finished. Processed "<<iab<<" After Burners"<<endl;
        
-       /***********************************************/
-       /***********************************************/
-       /***********************************************/       
+      /***********************************************/
+      /*******After Burners Processing****************/
+      /***********************************************/
+      TIter nextAfterBurner(fAfterBurnerEntries);
+      AliGenCocktailEntry *afterBurnerEntry;
+      Int_t iab =0; //number of current after burner / counter
+      
+      cout<<"\n\nRunning After Burners"<<endl;
+      while((afterBurnerEntry = (AliGenCocktailEntry*)nextAfterBurner()))
+        {
+          cout<<"After Burner "<<iab++<<"  :"<<afterBurnerEntry->GetName()<<endl;
+          fCurrentGenerator = afterBurnerEntry->Generator();
+          fCurrentGenerator->Generate();
+        }
+      cout<<endl<<"Finished. Processed "<<iab<<" After Burners"<<endl;
+
+      /***********************************************/
+      /***********************************************/
+      /***********************************************/       
         
-       fGenerationDone=kTRUE; 
-       SetTracks(0); //copy event 0 to gAlice stack
+      fGenerationDone=kTRUE; 
+      SetTracks(0); //copy event 0 to gAlice stack
        
 /*********************************************************************/
        
     }//else generated
 }
-
+/*********************************************************************/
+/*********************************************************************/ 
 
 AliGenCocktailAfterBurner& AliGenCocktailAfterBurner::operator=(const  AliGenCocktailAfterBurner& rhs)
 {
 // Assignment operator
     return *this;
 }
-
+/*********************************************************************/
+/*********************************************************************/ 
 
 AliStack* AliGenCocktailAfterBurner::GetStack(Int_t n)
 {
-    if( (n<0) || (n>=fNumberOfEvents) )
+//Returns the pointer to the N'th stack (event)
+  if( ( n<0 ) || ( n>=GetNumberOfEvents() ) )
     {
-       Fatal("AliGenCocktailAfterBurner::GetStack","Asked for non existing stack (%d)",n);
-       return 0; 
+      Fatal("AliGenCocktailAfterBurner::GetStack","Asked for non existing stack (%d)",n);
+      return 0; 
     }
-    //PH    return ((AliStack*) ((*fInternalStacks)[n]) );
     return ((AliStack*) fInternalStacks->At(n) );
 }
+/*********************************************************************/ 
+/*********************************************************************/ 
 
 void AliGenCocktailAfterBurner::SetActiveEventNumber(Int_t actev)
 {
+//Set Active Events Number and Active Stack
+//There is only one active event number
+//Made fo convinience of work with AfterBurners (HBT processor)
+
     fActiveEvent = actev;
     fActiveStack = GetStack(actev);
 }
+/*********************************************************************/ 
+/*********************************************************************/ 
 
 void AliGenCocktailAfterBurner::SetTracks(Int_t stackno)
 {
+//Method which copies tracks from given stack to the
+//gAlice's stack
     AliStack* instack = GetStack(stackno);
     Int_t done;
     Int_t parent; 
@@ -257,56 +298,60 @@ void AliGenCocktailAfterBurner::SetTracks(Int_t stackno)
     
     TParticle * p;
     Int_t N = instack->GetNtrack();
-    if (debug) 
+    if (gDebug) 
     {
-       cout<<"AliGenCocktailAfterBurner::SetTracks("<<stackno<<"). Number of particles is: "<<N<<"\n";
+      cout<<"AliGenCocktailAfterBurner::SetTracks("<<stackno<<"). Number of particles is: "<<N<<"\n";
     }
     
     for(Int_t i = 0; i < N; i++)
     {
        
-       p = instack->Particle(i);
-       done = !p->TestBit(kDoneBit);
-       if (debug) {cout<<i<<"  "<<done<<"  "; fflush(0);}
-       parent = p->GetMother(0);
-       pdg = p->GetPdgCode();
-       px = p->Px();
-       py = p->Py();
-       pz = p->Pz();
-       e  = p->Energy();
-       vx = p->Vx();
-       vy = p->Vy();
-       vz = p->Vz();
-       tof = p->T();
-       p->GetPolarisation(pol);
-       polx = pol.X();
-       poly = pol.Y();
-       polz = pol.Z();
-       mech = AliGenCocktailAfterBurner::IntToMCProcess(p->GetUniqueID());
-       weight = p->GetWeight();
-       
-       gAlice->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
-                        polx, poly, polz, mech, ntr, weight);
+      p = instack->Particle(i);
+      done = !p->TestBit(kDoneBit);
+      parent = p->GetMother(0);
+      pdg = p->GetPdgCode();
+      px = p->Px();
+      py = p->Py();
+      pz = p->Pz();
+      e  = p->Energy();
+      vx = p->Vx();
+      vy = p->Vy();
+      vz = p->Vz();
+      tof = p->T();
+      p->GetPolarisation(pol);
+      polx = pol.X();
+      poly = pol.Y();
+      polz = pol.Z();
+      mech = AliGenCocktailAfterBurner::IntToMCProcess(p->GetUniqueID());
+      weight = p->GetWeight();
+
+      gAlice->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
+                       polx, poly, polz, mech, ntr, weight);
     }
 }
+/*********************************************************************/ 
+/*********************************************************************/ 
 
 AliMCProcess AliGenCocktailAfterBurner::IntToMCProcess(Int_t no)
 {
+ //Mothod used to convert uniqueID (integer) to AliMCProcess type
     const AliMCProcess MCprocesses[kMaxMCProcess] = 
-    {kPNoProcess, kPMultipleScattering, kPEnergyLoss, kPMagneticFieldL, 
+    {
+     kPNoProcess, kPMultipleScattering, kPEnergyLoss, kPMagneticFieldL, 
      kPDecay, kPPair, kPCompton, kPPhotoelectric, kPBrem, kPDeltaRay,
      kPAnnihilation, kPHadronic, kPNoProcess, kPEvaporation, kPNuclearFission,
      kPNuclearAbsorption, kPPbarAnnihilation, kPNCapture, kPHElastic, 
      kPHInhelastic, kPMuonNuclear, kPTOFlimit,kPPhotoFission, kPNoProcess, 
-     kPRayleigh, kPNoProcess, kPNoProcess, kPNoProcess, kPNull, kPStop};
+     kPRayleigh, kPNoProcess, kPNoProcess, kPNoProcess, kPNull, kPStop
+    };
     
     for (Int_t i = 0;i<kMaxMCProcess;i++)
     {
-       if (MCprocesses[i] == no)
-       {
-           //if (debug) cout<<"IntToMCProcess("<<no<<") returned AliMCProcess Named \""<<AliMCProcessName[MCprocesses[i]]<<"\""<<endl;
-           return MCprocesses[i];
-       }
+      if (MCprocesses[i] == no)
+        {
+          //if (debug) cout<<"IntToMCProcess("<<no<<") returned AliMCProcess Named \""<<AliMCProcessName[MCprocesses[i]]<<"\""<<endl;
+          return MCprocesses[i];
+        }
     } 
     return kPNoProcess;
 }