]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EVGEN/AliGenExtFile.cxx
New options kPi0Flat y kEtaFlat (Gustavo Conesa)
[u/mrichter/AliRoot.git] / EVGEN / AliGenExtFile.cxx
index 7950715cb40ef317b2bd0bb4b6dc320f7fe0b274..cc1631846aa197e0493eba38a559aeef74261a6c 100644 (file)
 
 /*
 $Log$
+Revision 1.19  2002/02/08 16:50:50  morsch
+Add name and title in constructor.
+
+Revision 1.18  2001/11/12 14:31:00  morsch
+Memory leaks fixed. (M. Bondila)
+
+Revision 1.17  2001/11/09 09:12:58  morsch
+Generalization by using AliGenReader object to read particles from file.
+
+Revision 1.16  2001/07/27 17:09:35  morsch
+Use local SetTrack, KeepTrack and SetHighWaterMark methods
+to delegate either to local stack or to stack owned by AliRun.
+(Piotr Skowronski, A.M.)
+
+Revision 1.15  2001/01/23 13:29:37  morsch
+Add method SetParticleCode and enum type Code_t to handle both PDG (new ntuples)
+and GEANT3 codes (old ntuples) in input file.
+
+Revision 1.14  2000/12/21 16:24:06  morsch
+Coding convention clean-up
+
+Revision 1.13  2000/11/30 07:12:50  alibrary
+Introducing new Rndm and QA classes
+
+Revision 1.12  2000/10/27 13:54:45  morsch
+Remove explicite reference to input file from constuctor.
+
+Revision 1.11  2000/10/02 21:28:06  fca
+Removal of useless dependecies via forward declarations
+
+Revision 1.10  2000/07/11 18:24:55  fca
+Coding convention corrections + few minor bug fixes
+
+Revision 1.9  2000/06/14 15:20:09  morsch
+Include clean-up (IH)
+
 Revision 1.8  2000/06/09 20:36:44  morsch
 All coding rule violations except RS3 corrected
 
@@ -29,40 +65,38 @@ Introduction of the Copyright and cvs Log
 
 */
 
+
+// Event generator that using an instance of type AliGenReader
+// reads particles from a file and applies cuts. 
+
 #include <iostream.h>
 
 #include "AliGenExtFile.h"
-#include "AliMC.h"
 #include "AliRun.h"
 
-#include <TDirectory.h>
+#include <TParticle.h>
 #include <TFile.h>
-#include <stdlib.h>
+#include <TTree.h>
+
 
  ClassImp(AliGenExtFile)
      AliGenExtFile::AliGenExtFile()
         :AliGenerator(-1)
 {
 //  Constructor
-    fName="ExtFile";
-    fTitle="Primaries from ext. File";
-    fFileName="dtujet93.root";
-    fTreeNtuple=0;
-    fNcurrent=0;
 //
 //  Read all particles
-    fNpart=-1;
+    fNpart  =- 1;
+    fReader =  0;
 }
 
 AliGenExtFile::AliGenExtFile(Int_t npart)
     :AliGenerator(npart)
 {
 //  Constructor
-    fName="ExtFile";
-    fTitle="Primaries from ext. File";
-    fFileName="dtujet93.root";
-    fTreeNtuple=0;
-    fNcurrent=0;
+    fName   = "ExtFile";
+    fTitle  = "Primaries from ext. File";
+    fReader = 0;
 }
 
 AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
@@ -73,134 +107,97 @@ AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
 AliGenExtFile::~AliGenExtFile()
 {
 // Destructor
-    delete fTreeNtuple;
+    delete fReader;
 }
 
-//____________________________________________________________
-void AliGenExtFile::NtupleInit() 
+//___________________________________________________________
+void AliGenExtFile::Init()
 {
-//
-// reset the existing file environment and open a new root file if
-// the pointer to the Fluka tree is null
-    
-    TFile *pFile=0;
-    if (fTreeNtuple==0) {
-        if (!pFile) {
-           pFile = new TFile(fFileName);
-           pFile->cd();
-           cout<<"I have opened "<<fFileName<<" file "<<endl;
-        }
-// get the tree address in the Fluka boundary source file
-       fTreeNtuple = (TTree*)gDirectory->Get("h888");
-    } else {
-        pFile = fTreeNtuple->GetCurrentFile();
-        pFile->cd();
-    }
-
-    TTree *h2=fTreeNtuple;
-//Set branch addresses
-//Set branch addresses
-    h2->SetBranchAddress("Nihead",&fNihead);
-    h2->SetBranchAddress("Ihead",fIhead);
-    h2->SetBranchAddress("Nrhead",&fNrhead);
-    h2->SetBranchAddress("Rhead",fRhead);
-    h2->SetBranchAddress("Idpart",&fIdpart);
-    h2->SetBranchAddress("Theta",&fTheta);
-    h2->SetBranchAddress("Phi",&fPhi);
-    h2->SetBranchAddress("P",&fP);
-    h2->SetBranchAddress("E",&fE);
+// Initialize
+    if (fReader) fReader->Init();
 }
 
-
-//____________________________________________________________
+    
 void AliGenExtFile::Generate()
 {
 // Generate particles
 
-  Float_t polar[3]= {0,0,0};
+  Float_t polar[3]  = {0,0,0};
   //
-  Float_t origin[3]={0,0,0};
+  Float_t origin[3] = {0,0,0};
   Float_t p[3];
   Float_t random[6];
-  Float_t prwn;
-  Int_t i, j, nt, nTracks=0;
+  Int_t i, j, nt;
   //
-  NtupleInit();
-  TTree *h2=fTreeNtuple;
-  Int_t nentries = (Int_t) h2->GetEntries();
-  // loop over number of particles
-  Int_t nb = (Int_t)h2->GetEvent(fNcurrent);
-  Int_t i5=fIhead[4];
-  Int_t i6=fIhead[5];
-
   for (j=0;j<3;j++) origin[j]=fOrigin[j];
-  if(fVertexSmear==perEvent) {
-    gMC->Rndm(random,6);
-    for (j=0;j<3;j++) {
-       origin[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
+  if(fVertexSmear == kPerTrack) {
+    Rndm(random,6);
+    for (j = 0; j < 3; j++) {
+       origin[j] += fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
            TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
     }
   }
 
-  if (fNcurrent >= nentries) {
-      printf("\n No more entries !!! !\n");
+  Int_t nTracks = fReader->NextEvent();        
+  if (nTracks == 0) {
+      printf("\n No more events !!! !\n");
       return;
   }
-  
-         
-  if (i5==0) {
-      printf("\n This should never happen !\n");
-  } else {
-      printf("\n Next event contains %d tracks! \n", i6);
-      nTracks=i6;
-  }
-  for (i=0; i<nTracks; i++) {
-      fIdpart=gMC->PDGFromId(fIdpart);
-      Double_t amass = TDatabasePDG::Instance()->GetParticle(fIdpart)->Mass();
-      if(fE<=amass) {
-       Warning("Generate","Particle %d no %d E = %f mass = %f\n",
-               fIdpart,i,fE,amass);
-       prwn=0;
+
+  for (i = 0; i < nTracks; i++) {
+
+      
+      TParticle* iparticle = fReader->NextParticle();
+      Double_t  theta = iparticle->Theta();
+      Double_t  phi = iparticle->Phi();
+      if (phi > TMath::Pi()) phi -= 2.*TMath::Pi();
+      Double_t  pmom = iparticle->P();
+      Double_t  pz   = iparticle->Pz();
+      Double_t  e    = iparticle->Energy();
+      Double_t  pt   = iparticle->Pt();
+      Double_t  y;
+      if ((e-pz) == 0) {
+         y = 20.;
+      } else if ((e+pz) == 0.) {
+         y = -20.;
       } else {
-       prwn=sqrt((fE+amass)*(fE-amass));
+         y = 0.5*TMath::Log((e+pz)/(e-pz));      
       }
-
-      fTheta *= TMath::Pi()/180.;
-      fPhi    = (fPhi-180)*TMath::Pi()/180.;      
-      if(fTheta<fThetaMin || fTheta>fThetaMax ||
-        fPhi<fPhiMin || fPhi>fPhiMax         ||
-        prwn<fPMin || prwn>fPMax)          
+       
+      if(theta < fThetaMin || theta > fThetaMax ||
+        phi   < fPhiMin   || phi   > fPhiMax   ||
+        pmom  < fPMin     || pmom  > fPMax     ||
+        pt    < fPtMin    || pt    > fPtMax    ||
+        y     < fYMin     || y     > fYMax        )
       {
-         ;
-      } else {
-         p[0]=prwn*TMath::Sin(fTheta)*TMath::Cos(fPhi);
-         p[1]=prwn*TMath::Sin(fTheta)*TMath::Sin(fPhi);      
-         p[2]=prwn*TMath::Cos(fTheta);
-         
-         if(fVertexSmear==perTrack) {
-             gMC->Rndm(random,6);
-             for (j=0;j<3;j++) {
-                 origin[j]=fOrigin[j]
-                     +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
-                     TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
-             }
+         printf("\n Not selected %d %f %f %f %f %f", i, theta, phi, pmom, pt, y);
+         delete iparticle;
+         continue;
+      }
+      p[0] = iparticle->Px();
+      p[1] = iparticle->Py();
+      p[2] = iparticle->Pz();
+      Int_t idpart = iparticle->GetPdgCode();
+      if(fVertexSmear==kPerTrack) {
+         Rndm(random,6);
+         for (j = 0; j < 3; j++) {
+             origin[j]=fOrigin[j]
+                 +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
+                 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
          }
-         gAlice->SetTrack(fTrackIt,-1,fIdpart,p,origin,polar,0,"Primary",nt);
       }
-      fNcurrent++;
-      nb = (Int_t)h2->GetEvent(fNcurrent); 
-  }
-    TFile *pFile=0;
+      SetTrack(fTrackIt,-1,idpart,p,origin,polar,0,kPPrimary,nt);
+   }
+  TFile *pFile=0;
 // Get AliRun object or create it 
-    if (!gAlice) {
-       gAlice = (AliRun*)pFile->Get("gAlice");
-       if (gAlice) printf("AliRun object found on file\n");
-       if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
-    }
-    TTree *fAli=gAlice->TreeK();
-    if (fAli) pFile =fAli->GetCurrentFile();
-    pFile->cd();
+  if (!gAlice) {
+      gAlice = (AliRun*)pFile->Get("gAlice");
+      if (gAlice) printf("AliRun object found on file\n");
+      if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
+  }
+  TTree *fAli=gAlice->TreeK();
+  if (fAli) pFile =fAli->GetCurrentFile();
+  pFile->cd();
 }