SetSeed implementation
[u/mrichter/AliRoot.git] / EVGEN / AliGenCocktailAfterBurner.cxx
index eff7d49..230ac78 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.
 //
 // 24.09.2001  Piotr Skowronski
 //             debug -> gDebug,
-//             fNEvents replaced with gAlice->GetEventsPerRun()
+//             fNEvents replaced with AliRunLoader::GetNumberOfEvents()
 //
-#include "AliGenCocktailAfterBurner.h"
-#include "AliGenCocktailEntry.h"
 
-#include "AliStack.h"
-#include <TObjArray.h>
+
+#include <Riostream.h>
+
 #include <TList.h>
+#include <TObjArray.h>
 #include <TParticle.h>
-#include <iostream.h>
 
+#include "AliGenCocktailAfterBurner.h"
+#include "AliGenCocktailEntry.h"
+#include "AliGenCocktailEventHeader.h"
+#include "AliCollisionGeometry.h"
+#include "AliStack.h"
+#include "AliMC.h"
+#include "AliRun.h"
 
+using std::cout;
+using std::endl;
 ClassImp(AliGenCocktailAfterBurner)
 /*********************************************************************/ 
 /*********************************************************************/ 
 
-AliGenCocktailAfterBurner::AliGenCocktailAfterBurner()
+    AliGenCocktailAfterBurner::AliGenCocktailAfterBurner():
+       fNAfterBurners(0),
+       fAfterBurnerEntries(0),
+       fGenerationDone(kFALSE),
+       fInternalStacks(0),
+       fCollisionGeometries(0),
+       fHeaders(0),
+       fCurrentEvent(0),
+       fActiveStack(0),
+       fActiveEvent(-1),
+       fCurrentGenerator(0),
+       fNBgEvents(0)
 {
 // Constructor
     if (gDebug > 0) 
-       cout<<"AliGenCocktailAfterBurner::AliGenCocktailAfterBurner()"<<endl;
+       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;  
-    fNBgEvents = 0;
-}
-/*********************************************************************/ 
-AliGenCocktailAfterBurner::AliGenCocktailAfterBurner(const AliGenCocktailAfterBurner& in)
-{
- //cpy ctor
 }
 
 /*********************************************************************/ 
@@ -77,35 +83,57 @@ AliGenCocktailAfterBurner::~AliGenCocktailAfterBurner()
        delete fInternalStacks;
     }
     if (fAfterBurnerEntries) delete fAfterBurnerEntries; //delete entries
+    Int_t numberOfEvents = AliRunLoader::Instance()->GetNumberOfEventsPerRun();
+    if (fCollisionGeometries) {
+      for (Int_t i = 0; i < (numberOfEvents + fNBgEvents); i++)
+       if (fCollisionGeometries[i]) delete fCollisionGeometries[i];
+      delete[] fCollisionGeometries;
+    }
+    if (fHeaders) {
+      for (Int_t i = 0; i < (numberOfEvents + fNBgEvents); i++)
+       if (fHeaders[i]) delete fHeaders[i];
+      delete[] fHeaders;
+    }
   }
 /*********************************************************************/ 
 /*********************************************************************/ 
 
 void AliGenCocktailAfterBurner::
-AddAfterBurner(AliGenerator *AfterBurner, char* Name, Float_t RateExp)
+AddAfterBurner(AliGenerator *AfterBurner, const char* Name, Float_t RateExp)
 {
 //
 //  Forward parameters to the new AfterBurner
     
     if (gDebug>0)cout<<"AliGenCocktailAfterBurner::AddAfterBurner  Named "<<Name<<endl;
 
-    if(TestBit(kPtRange)) 
+    if(TestBit(kPtRange) && !(AfterBurner->TestBit(kPtRange)) && !(AfterBurner->TestBit(kMomentumRange))) 
        AfterBurner->SetPtRange(fPtMin,fPtMax);
-    if(TestBit(kMomentumRange))
+    if(TestBit(kMomentumRange) && !(AfterBurner->TestBit(kPtRange)) && !(AfterBurner->TestBit(kMomentumRange)))
        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->SetVertexSmear(fVertexSmear);
-    AfterBurner->SetTrackingFlag(fTrackIt);    
+    if (TestBit(kYRange) && !(AfterBurner->TestBit(kYRange)))
+       AfterBurner->SetYRange(fYMin,fYMax);
+    if (TestBit(kPhiRange) && !(AfterBurner->TestBit(kPhiRange)))
+       AfterBurner->SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi());
+    if (TestBit(kThetaRange) && !(AfterBurner->TestBit(kThetaRange)) && !(AfterBurner->TestBit(kEtaRange)))
+       AfterBurner->SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi());
+    if (!(AfterBurner->TestBit(kVertexRange))) {
+       AfterBurner->SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]);
+       AfterBurner->SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]);
+       AfterBurner->SetVertexSmear(fVertexSmear);
+       AfterBurner->SetVertexSource(kContainer);
+       AfterBurner->SetTimeOrigin(fTimeOrigin);
+    }
+    AfterBurner->SetTrackingFlag(fTrackIt);
+    //AfterBurner->SetContainer(this);
+
 //
 //  Add AfterBurner to list   
     
     AliGenCocktailEntry *entry = 
        new AliGenCocktailEntry(AfterBurner, Name, RateExp);
+    if (!fAfterBurnerEntries) fAfterBurnerEntries = new TList();
+    
     fAfterBurnerEntries->Add(entry);
     fNAfterBurners++;
 //
@@ -117,6 +145,7 @@ AddAfterBurner(AliGenerator *AfterBurner, char* Name, Float_t RateExp)
 void AliGenCocktailAfterBurner::Init()
 {
 // Initialisation
+  Int_t numberOfEvents = AliRunLoader::Instance()->GetNumberOfEventsPerRun();
     fGenerationDone = kFALSE;
     if (fInternalStacks) //delete stacks
      { 
@@ -124,6 +153,17 @@ void AliGenCocktailAfterBurner::Init()
        fInternalStacks->Delete(); //clean after previous generation cycle
      }
 
+    if (fCollisionGeometries) {
+      for (Int_t i = 0; i < (numberOfEvents + fNBgEvents); i++)
+       if (fCollisionGeometries[i]) delete fCollisionGeometries[i];
+      delete[] fCollisionGeometries;
+    }
+    if (fHeaders) {
+      for (Int_t i = 0; i < (numberOfEvents + fNBgEvents); i++)
+       if (fHeaders[i]) delete fHeaders[i];
+      delete[] fHeaders;
+    }
+
     this->AliGenCocktail::Init(); 
     
     if (gDebug>0) cout<<"AliGenCocktailAfterBurner::Init"<<endl;
@@ -154,7 +194,8 @@ void AliGenCocktailAfterBurner::Generate()
       cout<<"#####################################"<<endl
           <<"#AliGenCocktailAfterBurner::Generate#"<<endl
           <<"#####################################"<<endl;
-    
+    // Initialize header
+    //
     Int_t i; //iterator
     AliStack * stack;
     
@@ -162,27 +203,42 @@ void AliGenCocktailAfterBurner::Generate()
     {//if generation is done (in first call) 
      //just copy particles from the stack to the gAlice
       SetTracks(++fCurrentEvent);
-      cout<<"Returning event "<<fCurrentEvent<<endl;
+      fHeader = fHeaders[fCurrentEvent];
+      gAlice->SetGenEventHeader(fHeader); 
+      cout<<"Returning event " << fCurrentEvent<<endl;
       return;  
     }
     else
     { //Here we are in the first call of the method
-      fCurrentEvent=0;
-      Int_t numberOfEvents = gAlice->GetEventsPerRun();
+       Int_t numberOfEvents = AliRunLoader::Instance()->GetNumberOfEventsPerRun();
+       cout << "Number of events per run" <<  numberOfEvents << endl;
+       TArrayF eventVertex;
+       eventVertex.Set(3 * (numberOfEvents + fNBgEvents));
+       TArrayF eventTime;
+       eventTime.Set(numberOfEvents + fNBgEvents);
+       fCurrentEvent=0;
       //Create stacks
-      fInternalStacks = new TObjArray(numberOfEvents + fNBgEvents); //Create array of internal stacks
-      for(i=0;i<numberOfEvents + fNBgEvents;i++) 
+       fInternalStacks      = new TObjArray(numberOfEvents + fNBgEvents); //Create array of internal stacks
+       fCollisionGeometries = new AliCollisionGeometry*[numberOfEvents + fNBgEvents]; //Create array of collision geometries
+       fHeaders             = new AliGenCocktailEventHeader*[numberOfEvents + fNBgEvents]; //Create array of headers   
+
+       for(i = 0; i < numberOfEvents + fNBgEvents; i++) 
        {       
-        stack = new AliStack(10000);
-        stack->Reset();
-        fInternalStacks->Add(stack);
+          stack = new AliStack(10000);
+          stack->Reset();
+          fInternalStacks->Add(stack);
+          Vertex();
+          for (Int_t j = 0; j < 3; j++) eventVertex[3 * i +  j] = fVertex[j];
+          eventTime[i] = fTime;
+          fHeaders[i] = new AliGenCocktailEventHeader();
+          fCollisionGeometries[i] = 0;
        }
 /*********************************************************************/ 
       TIter next(fEntries);
       AliGenCocktailEntry *entry;
       AliGenCocktailEntry *e1;
       AliGenCocktailEntry *e2;
-      TObjArray *partArray;
+      const TObjArray *partArray;
   //
   // Loop over generators and generate events
       Int_t igen=0;
@@ -192,26 +248,42 @@ void AliGenCocktailAfterBurner::Generate()
         cout<<"Generator "<<igen<<"  : "<<entry->GetName()<<endl;
 /***********************************************/
 //First generator for all evenets, than second for all events, etc...
-        for(i=0;i<numberOfEvents + fNBgEvents;i++) 
-          {  
-            cout<<"                  EVENT "<<i<<endl;
+        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());
-           }
+           }
+           // Set the vertex for the generator
+           Int_t ioff = 3 * i;
+           fCurrentGenerator->SetVertex(eventVertex.At(ioff), eventVertex.At(ioff + 1), eventVertex.At(ioff + 2));
+           fCurrentGenerator->SetTime(eventTime.At(i));
+           fHeader = fHeaders[i];
+           // Set the vertex and time for the cocktail
+           TArrayF v(3);
+           for (Int_t j=0; j<3; j++) v[j] = eventVertex.At(ioff + j);
+           fHeader->SetPrimaryVertex(v);
+           fHeader->SetInteractionTime(eventTime.At(i));
+           // Generate event
+           fCurrentGenerator->Generate();
+           //
+           entry->SetLast(partArray->GetEntriesFast());
+           
+           if (fCurrentGenerator->ProvidesCollisionGeometry())  
+             fCollisionGeometries[i] = 
+               new AliCollisionGeometry(*(fCurrentGenerator->CollisionGeometry()));
+       } // event loop
 /***********************************************/
-      }
+      } // generator loop
       next.Reset();
       while((entry = (AliGenCocktailEntry*)next())) 
         {
@@ -253,30 +325,39 @@ void AliGenCocktailAfterBurner::Generate()
       SetTracks(0); //copy event 0 to gAlice stack
        
 /*********************************************************************/
-       
-    }//else generated
+      // Pass the header to gAlice
+      fHeader = fHeaders[0];
+      gAlice->SetGenEventHeader(fHeader); 
+    } //else generated
 }
 /*********************************************************************/
 /*********************************************************************/ 
 
-AliGenCocktailAfterBurner& AliGenCocktailAfterBurner::operator=(const  AliGenCocktailAfterBurner& rhs)
+AliStack* AliGenCocktailAfterBurner::GetStack(Int_t n) const
 {
-// Assignment operator
-    return *this;
+//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; 
+    }
+    return ((AliStack*) fInternalStacks->At(n) );
 }
-/*********************************************************************/
+
+/*********************************************************************/ 
 /*********************************************************************/ 
 
-AliStack* AliGenCocktailAfterBurner::GetStack(Int_t n) const
+AliCollisionGeometry* AliGenCocktailAfterBurner::GetCollisionGeometry(Int_t n) const
 {
 //Returns the pointer to the N'th stack (event)
   if( ( n<0 ) || ( n>=GetNumberOfEvents() ) )
     {
-      Fatal("AliGenCocktailAfterBurner::GetStack","Asked for non existing stack (%d)",n);
+      Fatal("AliGenCocktailAfterBurner::GetCollisionGeometry","Asked for non existing stack (%d)",n);
       return 0; 
     }
-    return ((AliStack*) fInternalStacks->At(n) );
+    return fCollisionGeometries[n];
 }
+
 /*********************************************************************/ 
 /*********************************************************************/ 
 
@@ -301,10 +382,11 @@ void AliGenCocktailAfterBurner::SetTracks(Int_t stackno)
     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;
+    Int_t is;
     
     TParticle * p;
     Int_t n = instack->GetNtrack();
@@ -334,18 +416,21 @@ void AliGenCocktailAfterBurner::SetTracks(Int_t stackno)
       polz = pol.Z();
       mech = AliGenCocktailAfterBurner::IntToMCProcess(p->GetUniqueID());
       weight = p->GetWeight();
+      is = p->GetStatusCode();
+
+      gAlice->GetMCApp()->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,polx, poly, polz, mech, ntr, weight, is);
+
+      SetHighWaterMark(ntr) ; 
 
-      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)
+TMCProcess AliGenCocktailAfterBurner::IntToMCProcess(Int_t no)
 {
- //Mothod used to convert uniqueID (integer) to AliMCProcess type
-    const AliMCProcess kMCprocesses[kMaxMCProcess] = 
+ //Mothod used to convert uniqueID (integer) to TMCProcess type
+    const TMCProcess kMCprocesses[kMaxMCProcess] = 
     {
      kPNoProcess, kPMultipleScattering, kPEnergyLoss, kPMagneticFieldL, 
      kPDecay, kPPair, kPCompton, kPPhotoelectric, kPBrem, kPDeltaRay,
@@ -364,3 +449,4 @@ AliMCProcess AliGenCocktailAfterBurner::IntToMCProcess(Int_t no)
     } 
     return kPNoProcess;
 }
+