]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EVGEN/AliGenExtFile.cxx
Shadowing of variabled corrected.
[u/mrichter/AliRoot.git] / EVGEN / AliGenExtFile.cxx
index 81f0a36d1d824c55ea06fa4c759436c10e7aaacc..dac8c078acdc7415489d78193ea710942acacd25 100644 (file)
@@ -18,7 +18,7 @@
 // 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);
+//  AliGenExtFile *gener = new AliGenExtFile(-1);
 //  gener->SetMomentumRange(0,999);
 //  gener->SetPhiRange(-180.,180.);
 //  gener->SetThetaRange(0,180);
 #include <Riostream.h>
 
 #include "AliGenExtFile.h"
-#include "AliRun.h"
+#include "AliRunLoader.h"
+#include "AliHeader.h"
+#include "AliGenEventHeader.h"
 
 #include <TParticle.h>
 #include <TFile.h>
 #include <TTree.h>
 
 
- ClassImp(AliGenExtFile)
+ClassImp(AliGenExtFile)
 
 AliGenExtFile::AliGenExtFile()
-  :AliGenMC()
+    :AliGenMC(),
+     fFileName(0),
+     fReader(0)
 {
 //  Constructor
 //
 //  Read all particles
     fNpart  =- 1;
-    fReader =  0;
 }
 
 AliGenExtFile::AliGenExtFile(Int_t npart)
-    :AliGenMC(npart)
+    :AliGenMC(npart),
+     fFileName(0),
+     fReader(0)
 {
 //  Constructor
     fName   = "ExtFile";
     fTitle  = "Primaries from ext. File";
-    fReader = 0;
 }
 
-AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
-{
-// copy constructor
-}
 //____________________________________________________________
 AliGenExtFile::~AliGenExtFile()
 {
@@ -88,16 +88,10 @@ void AliGenExtFile::Generate()
   Float_t origin[3] = {0,0,0};
   Float_t p[3];
   Float_t random[6];
-  Int_t i, j, nt;
+  Int_t i = 0, j, nt;
   //
-  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();
 
   while(1) {
     Int_t nTracks = fReader->NextEvent();      
@@ -110,9 +104,9 @@ void AliGenExtFile::Generate()
     //
     // Particle selection loop
     //
-    // The selction criterium for the external file generator is as follows:
+    // The selection criterium for the external file generator is as follows:
     //
-    // 1) All tracs are subjects to the cuts defined by AliGenerator, i.e.
+    // 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
@@ -120,17 +114,17 @@ void AliGenExtFile::Generate()
     // 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;
-
-      for (i = 0; i < nTracks; i++) {
-       TParticle* iparticle = fReader->NextParticle();
-       Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
-       kf = TMath::Abs(kf);
-       if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
-         nSelected++;
-       }
+      while ((iparticle=fReader->NextParticle()) ) {
+         Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
+         kf = TMath::Abs(kf);
+         if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
+             nSelected++;
+         }
       }
       if (!nSelected) continue;    // No particle selected:  Go to next event
       fReader->RewindEvent();
@@ -139,56 +133,48 @@ void AliGenExtFile::Generate()
     //
     // Stack filling loop
     //
+    fNprimaries = 0;
     for (i = 0; i < nTracks; i++) {
-
-      TParticle* iparticle = fReader->NextParticle();
-      if (!KinematicSelection(iparticle,0)) {
-       Double_t  pz   = iparticle->Pz();
-       Double_t  e    = iparticle->Energy();
-       Double_t  y;
-       if ((e-pz) == 0) {
-         y = 20.;
-       } else if ((e+pz) == 0.) {
-         y = -20.;
+       TParticle* jparticle = fReader->NextParticle();
+       Bool_t selected = KinematicSelection(jparticle,0); 
+       if (!selected) continue;
+       p[0] = jparticle->Px();
+       p[1] = jparticle->Py();
+       p[2] = jparticle->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 {
-         y = 0.5*TMath::Log((e+pz)/(e-pz));      
+           origin[0] = fVertex[0] + jparticle->Vx();
+           origin[1] = fVertex[1] + jparticle->Vy();
+           origin[2] = fVertex[2] + jparticle->Vz();
        }
-       printf("\n Not selected %d %f %f %f %f %f", i,
-              iparticle->Theta(),
-              iparticle->Phi(),
-              iparticle->P(),
-              iparticle->Pt(),
-              y);
-       //PH    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]));
-         }
-      }
-      Int_t decayed = iparticle->GetFirstDaughter();
-      Int_t doTracking = fTrackIt && (decayed < 0) &&
-                        (TMath::Abs(idpart) > 10);
-      // printf("*** pdg, first daughter, trk = %d, %d, %d\n",
-      //   idpart,decayed, doTracking);
-      //PH      SetTrack(doTracking,-1,idpart,p,origin,polar,0,kPPrimary,nt);
-      Int_t parent = iparticle->GetFirstMother();
-      SetTrack(doTracking,parent,idpart,p,origin,polar,0,kPPrimary,nt);
-      KeepTrack(nt);
+       
+       Int_t decayed    = jparticle->GetFirstDaughter();
+       Int_t doTracking = fTrackIt && (decayed < 0) && (TMath::Abs(idpart) > 10) && selected;
+       Int_t parent     = jparticle->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();
 }
@@ -196,28 +182,10 @@ void AliGenExtFile::Generate()
 void AliGenExtFile::CdEventFile()
 {
 // CD back to the event file
-  TFile *pFile=0;
-  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();    
+    (AliRunLoader::GetRunLoader())->CdGAFile();
 }
 
 
-AliGenExtFile& AliGenExtFile::operator=(const  AliGenExtFile& rhs)
-{
-// Assignment operator
-    return *this;
-}
-
-
-
-
-