SetSeed implementation
[u/mrichter/AliRoot.git] / EVGEN / AliGenCocktailAfterBurner.cxx
index e078170..230ac78 100644 (file)
 #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),
@@ -81,38 +83,57 @@ AliGenCocktailAfterBurner::~AliGenCocktailAfterBurner()
        delete fInternalStacks;
     }
     if (fAfterBurnerEntries) delete fAfterBurnerEntries; //delete entries
-    delete[] fCollisionGeometries;
-    delete[] fHeaders;
+    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);    
-    AfterBurner->SetVertexSource(kContainer);
+    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++;
 //
@@ -124,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
      { 
@@ -131,8 +153,17 @@ void AliGenCocktailAfterBurner::Init()
        fInternalStacks->Delete(); //clean after previous generation cycle
      }
 
-    if (fCollisionGeometries) delete[] fCollisionGeometries;
-    
+    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;
@@ -183,6 +214,8 @@ void AliGenCocktailAfterBurner::Generate()
        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
@@ -196,7 +229,9 @@ void AliGenCocktailAfterBurner::Generate()
           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);
@@ -231,18 +266,21 @@ void AliGenCocktailAfterBurner::Generate()
            // 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 for the cocktail
+           // 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] = fCurrentGenerator->CollisionGeometry();
-           
+           if (fCurrentGenerator->ProvidesCollisionGeometry())  
+             fCollisionGeometries[i] = 
+               new AliCollisionGeometry(*(fCurrentGenerator->CollisionGeometry()));
        } // event loop
 /***********************************************/
       } // generator loop
@@ -348,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();
@@ -377,8 +416,9 @@ 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);
 
       SetHighWaterMark(ntr) ;