]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EVGEN/AliGenExtFile.cxx
Removing warnings (Andrea)
[u/mrichter/AliRoot.git] / EVGEN / AliGenExtFile.cxx
index 02890c85bf269b3322c487973944c679837d5a0e..891ebf8eb582c064b72e44d04fc92860eb24bbae 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.12  2000/10/27 13:54:45  morsch
-Remove explicite reference to input file from constuctor.
+/* $Id$ */
 
-Revision 1.11  2000/10/02 21:28:06  fca
-Removal of useless dependecies via forward declarations
+// Event generator that using an instance of type AliGenReader
+// reads particles from a file and applies cuts.
+// Example: In your Config.C you can include the following lines
+//  AliGenExtFile *gener = new AliGenExtFile(-1);
+//  gener->SetMomentumRange(0,999);
+//  gener->SetPhiRange(-180.,180.);
+//  gener->SetThetaRange(0,180);
+//  gener->SetYRange(-999,999);
+//  AliGenReaderTreeK * reader = new AliGenReaderTreeK();
+//  reader->SetFileName("myFileWithTreeK.root");
+//  gener->SetReader(reader);
+//  gener->Init();
 
-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
-
-Revision 1.7  2000/02/16 14:56:27  morsch
-Convert geant particle code into pdg code before putting particle on the stack.
-
-Revision 1.6  1999/11/09 07:38:48  fca
-Changes for compatibility with version 2.23 of ROOT
-
-Revision 1.5  1999/09/29 09:24:12  fca
-Introduction of the Copyright and cvs Log
-
-*/
-
-#include <iostream.h>
+#include <Riostream.h>
 
 #include "AliGenExtFile.h"
-#include "AliMC.h"
-#include "AliRun.h"
+#include "AliRunLoader.h"
+#include "AliHeader.h"
+#include "AliGenEventHeader.h"
 
-#include <TDirectory.h>
-#include <TDatabasePDG.h>
+#include <TParticle.h>
 #include <TFile.h>
-#include <stdlib.h>
+#include <TTree.h>
+
+
+ClassImp(AliGenExtFile)
 
- ClassImp(AliGenExtFile)
-     AliGenExtFile::AliGenExtFile()
-        :AliGenerator(-1)
+AliGenExtFile::AliGenExtFile()
+    :AliGenMC(),
+     fFileName(0),
+     fReader(0)
 {
 //  Constructor
-    fName="ExtFile";
-    fTitle="Primaries from ext. File";
-    fFileName="";
-    fTreeNtuple=0;
-    fNcurrent=0;
 //
 //  Read all particles
-    fNpart=-1;
+    fNpart  =- 1;
 }
 
 AliGenExtFile::AliGenExtFile(Int_t npart)
-    :AliGenerator(npart)
+    :AliGenMC(npart),
+     fFileName(0),
+     fReader(0)
 {
 //  Constructor
-    fName="ExtFile";
-    fTitle="Primaries from ext. File";
-    fFileName="";
-    fTreeNtuple=0;
-    fNcurrent=0;
+    fName   = "ExtFile";
+    fTitle  = "Primaries from ext. File";
 }
 
-AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
-{
-// copy constructor
-}
 //____________________________________________________________
 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 = 0, 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==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 (fVertexSmear == kPerEvent) Vertex();
 
-  if (fNcurrent >= nentries) {
-      printf("\n No more entries !!! !\n");
+  while(1) {
+    Int_t nTracks = fReader->NextEvent();      
+    if (nTracks == 0) {
+      // printf("\n No more events !!! !\n");
+      Warning("AliGenExtFile::Generate","\nNo more events in external file!!!\nLast event may be empty or incomplete.\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 %f %f \n",
-               fIdpart,i,fE,amass, fPhi, fTheta);
-       prwn=0;
-      } else {
-       prwn=sqrt((fE+amass)*(fE-amass));
-      }
+    }
 
-      fTheta *= TMath::Pi()/180.;
-      fPhi    = (fPhi-180)*TMath::Pi()/180.;      
-      if(fTheta<fThetaMin || fTheta>fThetaMax ||
-        fPhi<fPhiMin || fPhi>fPhiMax         ||
-        prwn<fPMin || prwn>fPMax)          
-      {
-         ;
-      } 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==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]));
-             }
+    //
+    // Particle selection loop
+    //
+    // The selection criterium for the external file generator is as follows:
+    //
+    // 1) All tracks are subject to the cuts defined by AliGenerator, i.e.
+    //    fThetaMin, fThetaMax, fPhiMin, fPhiMax, fPMin, fPMax, fPtMin, fPtMax,
+    //    fYMin, fYMax.
+    //    If the particle does not satisfy these cuts, it is not put on the
+    //    stack.
+    // 2) If fCutOnChild and some specific child is selected (e.g. if
+    //    fForceDecay==kSemiElectronic) the event is rejected if NOT EVEN ONE
+    //    child falls into the child-cuts.
+    TParticle* iparticle = 0x0;
+    
+    if(fCutOnChild) {
+      // Count the selected children
+      Int_t nSelected = 0;
+      while ((iparticle=fReader->NextParticle()) ) {
+         Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
+         kf = TMath::Abs(kf);
+         if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
+             nSelected++;
          }
-         gAlice->SetTrack(fTrackIt,-1,fIdpart,p,origin,polar,0,kPPrimary,nt);
       }
-      fNcurrent++;
-      nb = (Int_t)h2->GetEvent(fNcurrent); 
-  }
-    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");
+      if (!nSelected) continue;    // No particle selected:  Go to next event
+      fReader->RewindEvent();
     }
-    TTree *fAli=gAlice->TreeK();
-    if (fAli) pFile =fAli->GetCurrentFile();
-    pFile->cd();
-}
 
+    //
+    // Stack filling loop
+    //
+    fNprimaries = 0;
+    for (i = 0; i < nTracks; i++) {
+       TParticle* iparticle = fReader->NextParticle();
+       Bool_t selected = KinematicSelection(iparticle,0); 
+       if (!selected) 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]));
+           }
+       } else {
+           origin[0] = fVertex[0] + iparticle->Vx();
+           origin[1] = fVertex[1] + iparticle->Vy();
+           origin[2] = fVertex[2] + iparticle->Vz();
+       }
+       
+       Int_t decayed    = iparticle->GetFirstDaughter();
+       Int_t doTracking = fTrackIt && (decayed < 0) && (TMath::Abs(idpart) > 10) && selected;
+       Int_t parent     = iparticle->GetFirstMother();
+       
+       PushTrack(doTracking,parent,idpart,p,origin,polar,0,kPPrimary,nt);
+       KeepTrack(nt);
+       fNprimaries++;
+    } // track loop
+
+    // Generated event header
+    
+    AliGenEventHeader * header = new AliGenEventHeader();
+    header->SetNProduced(fNprimaries);
+    header->SetPrimaryVertex(fVertex);
+    AddHeader(header);
+    break;
+    
+  } // event loop
+  
+  SetHighWaterMark(nt);
+  CdEventFile();
+}
 
-AliGenExtFile& AliGenExtFile::operator=(const  AliGenExtFile& rhs)
+void AliGenExtFile::CdEventFile()
 {
-// Assignment operator
-    return *this;
+// CD back to the event file
+    (AliRunLoader::GetRunLoader())->CdGAFile();
 }
 
 
 
 
 
-
-
-