]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EVGEN/AliGenExtFile.cxx
Updates to RAW package. Used during the Computing DC.
[u/mrichter/AliRoot.git] / EVGEN / AliGenExtFile.cxx
index c48fdd9c9a5a95977b5d1de7634100625306e982..a2101984c562b32f62c06305dd4f2b26e038cb7a 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.20  2002/03/22 09:43:28  morsch
-Don't delete the TParticle.
-
-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
-
-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
-
-*/
-
+/* $Id$ */
 
 // Event generator that using an instance of type AliGenReader
-// reads particles from a file and applies cuts. 
+// 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();
 
-#include <iostream.h>
+
+#include <Riostream.h>
 
 #include "AliGenExtFile.h"
 #include "AliRun.h"
@@ -82,7 +39,7 @@ Introduction of the Copyright and cvs Log
 #include <TTree.h>
 
 
- ClassImp(AliGenExtFile)
+ClassImp(AliGenExtFile)
 
 AliGenExtFile::AliGenExtFile()
   :AliGenMC()
@@ -103,9 +60,11 @@ AliGenExtFile::AliGenExtFile(Int_t npart)
     fReader = 0;
 }
 
-AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
+AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile):
+    AliGenMC(ExtFile)
 {
-// copy constructor
+// Copy constructor
+    ExtFile.Copy(*this);
 }
 //____________________________________________________________
 AliGenExtFile::~AliGenExtFile()
@@ -131,7 +90,7 @@ 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) {
@@ -155,7 +114,7 @@ void AliGenExtFile::Generate()
     //
     // The selction 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 subjects 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
@@ -163,12 +122,13 @@ 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();
+      while ( (iparticle=fReader->NextParticle()) ) {
+        ;
        Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
        kf = TMath::Abs(kf);
        if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
@@ -185,7 +145,8 @@ void AliGenExtFile::Generate()
     for (i = 0; i < nTracks; i++) {
 
       TParticle* iparticle = fReader->NextParticle();
-      if (!KinematicSelection(iparticle,0)) {
+      Bool_t selected = KinematicSelection(iparticle,0); 
+      if (!selected) {
        Double_t  pz   = iparticle->Pz();
        Double_t  e    = iparticle->Energy();
        Double_t  y;
@@ -202,27 +163,30 @@ void AliGenExtFile::Generate()
               iparticle->P(),
               iparticle->Pt(),
               y);
-       delete iparticle;
-       continue;
+       //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]));
-         }
+      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);
+                        (TMath::Abs(idpart) > 10) && selected;
       // printf("*** pdg, first daughter, trk = %d, %d, %d\n",
       //   idpart,decayed, doTracking);
-      SetTrack(doTracking,-1,idpart,p,origin,polar,0,kPPrimary,nt);
+      //PH      PushTrack(doTracking,-1,idpart,p,origin,polar,0,kPPrimary,nt);
+      Int_t parent = iparticle->GetFirstMother();
+      PushTrack(doTracking,parent,idpart,p,origin,polar,0,kPPrimary,nt);
       KeepTrack(nt);
     } // track loop
 
@@ -231,9 +195,13 @@ void AliGenExtFile::Generate()
   } // event loop
 
   SetHighWaterMark(nt);
+  CdEventFile();
+}
 
+void AliGenExtFile::CdEventFile()
+{
+// CD back to the event file
   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");
@@ -241,16 +209,25 @@ void AliGenExtFile::Generate()
   }
   TTree *fAli=gAlice->TreeK();
   if (fAli) pFile =fAli->GetCurrentFile();
-  pFile->cd();
+  pFile->cd();    
 }
 
 
 AliGenExtFile& AliGenExtFile::operator=(const  AliGenExtFile& rhs)
 {
 // Assignment operator
+    rhs.Copy(*this);
     return *this;
 }
 
+void AliGenExtFile::Copy(TObject&) const
+{
+    //
+    // Copy 
+    //
+    Fatal("Copy","Not implemented!\n");
+}