]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EVGEN/AliGenTHnSparse.cxx
Merge branch master into TRDdev
[u/mrichter/AliRoot.git] / EVGEN / AliGenTHnSparse.cxx
index c80cdf3ba48c2984ca4bf4a76d629145f85bac90..3ddbe88b25718c2e2348189a607ceea668ec637a 100644 (file)
 //-----------------------------------------------------------------------
 /*
   Example for generation :
        AliGenTHnSparse *gener = new AliGenTHnSparse();
        gener->SetNumberParticles(10);
-       gener->SetPart(13);
+       gener->SetPart(13,kTRUE); // for generating id 13 and -13
        gener->SetThnSparse("file_name","thn_name");
        gener->Init();
 */
 
 #include "AliGenTHnSparse.h"
 
+// NEW
+#include "AliRun.h"
+#include "AliLog.h"
+#include "AliGenEventHeader.h"
+//
+
 ClassImp(AliGenTHnSparse)
 
 //_______________________________________________________________________
@@ -44,7 +49,8 @@ AliGenTHnSparse::AliGenTHnSparse():
   AliGenerator(),
   fHn(0),
   fFile(0),
-  fIpart(0)
+  fIpart(0),
+  fBoth(kFALSE)
 {
     // Default constructor
     SetNumberParticles(1);
@@ -55,7 +61,8 @@ AliGenTHnSparse::AliGenTHnSparse(const AliGenTHnSparse& func):
   AliGenerator(),
   fHn(func.fHn),
   fFile(func.fFile),
-  fIpart(func.fIpart)
+  fIpart(func.fIpart),
+  fBoth(func.fBoth)
 {
     // Copy constructor
     SetNumberParticles(1);
@@ -69,6 +76,8 @@ AliGenTHnSparse & AliGenTHnSparse::operator=(const AliGenTHnSparse& func)
     fHn  = func.fHn;
     fFile  = func.fFile;
     fIpart  = func.fIpart;
+    fBoth   = func.fBoth;
+    
     return *this;
 }
 
@@ -82,15 +91,15 @@ AliGenTHnSparse::~AliGenTHnSparse()
 //_______________________________________________________________________
 void AliGenTHnSparse::Generate()
 {
-  
     // Generate Npart of id Ipart
+    Int_t naccepted =0;
     
     Double_t rand[4]; //  z, ptot, r, theta
     Float_t pos[3], phi, ptot, theta, pt, z, r;
     Float_t mom[3];
     Int_t pdg = fIpart;
   
-    for (Int_t ipart = 0; ipart < fNpart; ipart++) {
+    for (Int_t ipart = 0; ipart < fNpart && naccepted<fNpart; ipart++) {
 
        fHn->GetRandom(rand);
        z=rand[0];
@@ -117,12 +126,25 @@ void AliGenTHnSparse::Generate()
 
 // propagation
 
-       Float_t polarization[3]= {0,0,0};
+       Float_t polarization[3] = {0,0,0};
        Int_t nt;
+
+// Part and anti-part
+
+       if(fBoth){
+           Double_t sign = gRandom->Rndm();
+           if(sign < 0.5) pdg = -fIpart;
+           else pdg = fIpart;
+       }
+
        PushTrack(fTrackIt,-1,pdg,mom, pos, polarization,0,kPPrimary,nt);
+       naccepted++;
   }
 
+    AliGenEventHeader* header = new AliGenEventHeader("THn");
+    gAlice->SetGenEventHeader(header);
     return;
+
 }
 
 //_______________________________________________________________________
@@ -144,7 +166,7 @@ void AliGenTHnSparse::SetThnSparse(char *file_name, char *thn_name)
 {
 
     // Open the file and get object
-    TFile *fFile = new TFile(file_name);
-    fHn = (THnSparseF*)(fFile->Get(thn_name));
+  fFile = new TFile(file_name);
+  fHn = (THnSparseF*)(fFile->Get(thn_name));
 
 }