SetSeed implementation
[u/mrichter/AliRoot.git] / EVGEN / AliGenCocktailAfterBurner.cxx
index 265c6af..230ac78 100644 (file)
 
 #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():
        fNAfterBurners(0),
-       fAfterBurnerEntries(new TList()),
+       fAfterBurnerEntries(0),
        fGenerationDone(kFALSE),
        fInternalStacks(0),
        fCollisionGeometries(0),
+       fHeaders(0),
        fCurrentEvent(0),
        fActiveStack(0),
        fActiveEvent(-1),
@@ -79,36 +83,57 @@ AliGenCocktailAfterBurner::~AliGenCocktailAfterBurner()
        delete fInternalStacks;
     }
     if (fAfterBurnerEntries) delete fAfterBurnerEntries; //delete entries
-    delete[] fCollisionGeometries;
+    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++;
 //
@@ -120,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
      { 
@@ -127,10 +153,17 @@ void AliGenCocktailAfterBurner::Init()
        fInternalStacks->Delete(); //clean after previous generation cycle
      }
 
-// ANDREAS MORSCH ---------------------------------------------------(
-    if (fCollisionGeometries) delete[] fCollisionGeometries;
-// ANDREAS MORSCH ---------------------------------------------------)
-    
+    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;
@@ -161,7 +194,8 @@ void AliGenCocktailAfterBurner::Generate()
       cout<<"#####################################"<<endl
           <<"#AliGenCocktailAfterBurner::Generate#"<<endl
           <<"#####################################"<<endl;
-    
+    // Initialize header
+    //
     Int_t i; //iterator
     AliStack * stack;
     
@@ -169,21 +203,35 @@ 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 = AliRunLoader::Instance()->GetNumberOfEvents() + 1;
+       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
-      fCollisionGeometries = new AliCollisionGeometry*[numberOfEvents + fNBgEvents]; //Create array of collision geometries
-      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);
@@ -200,31 +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());
-               
-// ANDREAS MORSCH ---------------------------------------------------(
-               if (fCurrentGenerator->ProvidesCollisionGeometry())  fCollisionGeometries[i] = fCurrentGenerator->CollisionGeometry();
-// ANDREAS MORSCH ---------------------------------------------------)
-               
-           }
+           }
+           // 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())) 
         {
@@ -266,8 +325,10 @@ 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
 }
 /*********************************************************************/
 /*********************************************************************/ 
@@ -275,7 +336,7 @@ void AliGenCocktailAfterBurner::Generate()
 AliStack* AliGenCocktailAfterBurner::GetStack(Int_t n) const
 {
 //Returns the pointer to the N'th stack (event)
-  if( ( n<0 ) || ( n >= (GetNumberOfEvents()+1) ) )
+  if( ( n<0 ) || ( n >= (GetNumberOfEvents()) ) )
     {
       Fatal("AliGenCocktailAfterBurner::GetStack","Asked for non existing stack (%d)",n);
       return 0; 
@@ -286,8 +347,6 @@ AliStack* AliGenCocktailAfterBurner::GetStack(Int_t n) const
 /*********************************************************************/ 
 /*********************************************************************/ 
 
-// ANDREAS MORSCH ---------------------------------------------------(
-
 AliCollisionGeometry* AliGenCocktailAfterBurner::GetCollisionGeometry(Int_t n) const
 {
 //Returns the pointer to the N'th stack (event)
@@ -299,8 +358,6 @@ AliCollisionGeometry* AliGenCocktailAfterBurner::GetCollisionGeometry(Int_t n) c
     return fCollisionGeometries[n];
 }
 
-// ANDREAS MORSCH ---------------------------------------------------)
-
 /*********************************************************************/ 
 /*********************************************************************/ 
 
@@ -329,6 +386,7 @@ void AliGenCocktailAfterBurner::SetTracks(Int_t stackno)
     Int_t ntr;
     Float_t weight;
     TVector3 pol;
+    Int_t is;
     
     TParticle * p;
     Int_t n = instack->GetNtrack();
@@ -358,12 +416,11 @@ 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);
+      gAlice->GetMCApp()->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,polx, poly, polz, mech, ntr, weight, is);
 
-// ANDREAS MORSCH ---------------------------------------------------(
       SetHighWaterMark(ntr) ; 
-// ANDREAS MORSCH ---------------------------------------------------)
 
     }
 }