Coding Rule violations corrected.
[u/mrichter/AliRoot.git] / EVGEN / AliGenCocktailAfterBurner.cxx
index 2ad2411..8127ab0 100644 (file)
@@ -13,6 +13,8 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
+/* $Id$ */
+
 // 
 // Container class for AliGenerator and AfterBurners 
 // (which are AliGenerators as well) through recursion.
 // 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 <Riostream.h>
+
+#include <TList.h>
+#include <TObjArray.h>
+#include <TParticle.h>
 
 #include "AliGenCocktailAfterBurner.h"
 #include "AliGenCocktailEntry.h"
-#include "AliRun.h"
 #include "AliStack.h"
-#include <TObjArray.h>
-#include <TList.h>
-#include <TParticle.h>
-#include <iostream.h>
+#include "AliMC.h"
+
 
-static const Bool_t debug = kFALSE;
 ClassImp(AliGenCocktailAfterBurner)
+/*********************************************************************/ 
+/*********************************************************************/ 
 
 AliGenCocktailAfterBurner::AliGenCocktailAfterBurner()
 {
 // Constructor
-    if (debug) 
-       cout<<"AliGenCocktailAfterBurner::AliGenCocktailAfterBurner()"<<endl;
+    if (gDebug > 0) 
+       cout<<"AliGenCocktailAfterBurner::AliGenCocktailAfterBurner()"<<endl;
     SetName("AliGenCocktailAfterBurner");
     SetTitle("AliGenCocktailAfterBurner");
     fInternalStacks =0;
+    fActiveStack = 0;
+    fCurrentGenerator = 0;
     fCurrentEvent =0;
     fAfterBurnerEntries = new TList();
     fNAfterBurners = 0;
     fGenerationDone = kFALSE;
     
     fActiveEvent = -1;  
-    fNParticles = -1;
+    fNBgEvents = 0;
+}
+/*********************************************************************/ 
+AliGenCocktailAfterBurner::AliGenCocktailAfterBurner(const AliGenCocktailAfterBurner& cocktail):
+    AliGenCocktail(cocktail)
+
+{
+ //Copy constructor
+    cocktail.Copy(*this);
 }
 
+/*********************************************************************/ 
 
 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)
@@ -67,7 +96,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);
@@ -75,14 +104,10 @@ AddAfterBurner(AliGenerator *AfterBurner, char* Name, Float_t RateExp)
        AfterBurner->SetMomentumRange(fPMin,fPMax);
     
     AfterBurner->SetYRange(fYMin,fYMax);
-    AfterBurner->
-       SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
-    AfterBurner->
-       SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
-    AfterBurner->
-       SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
-    AfterBurner->
-       SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
+    AfterBurner->SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
+    AfterBurner->SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
+    AfterBurner->SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
+    AfterBurner->SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
     AfterBurner->SetVertexSmear(fVertexSmear);
     AfterBurner->SetTrackingFlag(fTrackIt);    
 //
@@ -92,14 +117,25 @@ AddAfterBurner(AliGenerator *AfterBurner, char* Name, Float_t RateExp)
        new AliGenCocktailEntry(AfterBurner, Name, RateExp);
     fAfterBurnerEntries->Add(entry);
     fNAfterBurners++;
+//
+    
 }
+/*********************************************************************/ 
+/*********************************************************************/ 
 
 void AliGenCocktailAfterBurner::Init()
 {
 // Initialisation
+    fGenerationDone = kFALSE;
+    if (fInternalStacks) //delete stacks
+     { 
+       fInternalStacks->SetOwner();
+       fInternalStacks->Delete(); //clean after previous generation cycle
+     }
+
     this->AliGenCocktail::Init(); 
     
-    if (debug) cout<<"AliGenCocktailAfterBurner::Init"<<endl;
+    if (gDebug>0) cout<<"AliGenCocktailAfterBurner::Init"<<endl;
     TIter next(fAfterBurnerEntries);
     AliGenCocktailEntry *entry;
     //
@@ -108,202 +144,238 @@ 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 + fNBgEvents); //Create array of internal stacks
+      for(i=0;i<numberOfEvents + fNBgEvents;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 + fNBgEvents;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;
+    rhs.Copy(*this);
+    return (*this);
 }
+/*********************************************************************/
+/*********************************************************************/ 
 
-
-AliStack* AliGenCocktailAfterBurner::GetStack(Int_t n)
+AliStack* AliGenCocktailAfterBurner::GetStack(Int_t n) const
 {
-    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; 
     }
-    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; 
     Int_t pdg;
     Double_t px, py, pz, e, vx, vy, vz, tof, polx, poly, polz;
-    AliMCProcess mech;
+    TMCProcess mech;
     Int_t ntr;
     Float_t weight;
     TVector3 pol;
     
     TParticle * p;
-    Int_t N = instack->GetNtrack();
-    if (debug) 
+    Int_t n = instack->GetNtrack();
+    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++)
+    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->GetMCApp()->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
+                       polx, poly, polz, mech, ntr, weight);
     }
 }
+/*********************************************************************/ 
+/*********************************************************************/ 
 
-AliMCProcess AliGenCocktailAfterBurner::IntToMCProcess(Int_t no)
+TMCProcess AliGenCocktailAfterBurner::IntToMCProcess(Int_t no)
 {
-    const AliMCProcess MCprocesses[kMaxMCProcess] = 
-    {kPNoProcess, kPMultipleScattering, kPEnergyLoss, kPMagneticFieldL, 
+ //Mothod used to convert uniqueID (integer) to TMCProcess type
+    const TMCProcess kMCprocesses[kMaxMCProcess] = 
+    {
+     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 (kMCprocesses[i] == no)
+        {
+          return kMCprocesses[i];
+        }
     } 
     return kPNoProcess;
 }
+
+void AliGenCocktailAfterBurner::Copy(AliGenCocktailAfterBurner &) const
+{
+    Fatal("Copy","Not implemented!\n");
+}