]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliReaderESD.cxx
Add AliAnalysisSelector in ANALYSIS package
[u/mrichter/AliRoot.git] / ANALYSIS / AliReaderESD.cxx
index f49f9483acccd63f7165df7e7f20e4d4f09c527a..b6aa2dfe1fb79eb9ae14da4afe15a509ec422d84 100644 (file)
@@ -1,4 +1,20 @@
-#include "AliReaderESD.h"
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/* $Id$ */
+
 //____________________________________________________________________
 //////////////////////////////////////////////////////////////////////
 //                                                                  //
 //                                                                  //
 //////////////////////////////////////////////////////////////////////
 
-#include <TPDGCode.h>
-#include <TString.h>
-#include <TObjString.h>
-#include <TTree.h>
 #include <TFile.h>
-#include <TKey.h>
-#include <TParticle.h>
+#include <TGliteXmlEventlist.h>
 #include <TH1.h>
+#include <TPDGCode.h>
+#include <TParticle.h>
+#include <TString.h>
 
-#include <AliRun.h>
-#include <AliRunLoader.h>
-#include <AliStack.h>
-#include <AliESDtrack.h>
-#include <AliKalmanTrack.h>
-#include <AliESD.h>
-
-#include "AliAnalysis.h"
-#include "AliAODRun.h"
 #include "AliAOD.h"
 #include "AliAODParticle.h"
-#include "AliAODParticleCut.h"
-#include "AliTrackPoints.h"
 #include "AliClusterMap.h"
+#include "AliESD.h"
+#include "AliESDtrack.h"
+#include "AliLog.h"
+#include "AliReaderESD.h"
+#include "AliRunLoader.h"
+#include "AliStack.h"
 
 ClassImp(AliReaderESD)
 
@@ -49,12 +58,13 @@ AliReaderESD::AliReaderESD(const Char_t* esdfilename, const Char_t* galfilename)
  fdR(0.0),
  fClusterMap(kFALSE),
  fITSTrackPoints(kFALSE),
+ fITSTrackPointsType(AliTrackPoints::kITS),
  fMustTPC(kFALSE),
- fReadCentralBarrel(kFALSE),
+ fReadCentralBarrel(kTRUE),
  fReadMuon(kFALSE),
  fReadPHOS(kFALSE),
  fNTPCClustMin(0),
- fNTPCClustMax(150),
+ fNTPCClustMax(1500),
  fTPCChi2PerClustMin(0.0),
  fTPCChi2PerClustMax(10e5),
  fChi2Min(0.0),
@@ -82,7 +92,7 @@ AliReaderESD::AliReaderESD(const Char_t* esdfilename, const Char_t* galfilename)
 
 {
   //cosntructor
-  if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
+  if ( ((Int_t)kNSpecies) != ((Int_t)AliPID::kSPECIES))
     Fatal("AliReaderESD","ESD defintions probobly changed. Ask Youra.");
 }
 /********************************************************************/
@@ -101,8 +111,9 @@ AliReaderESD::AliReaderESD(TObjArray* dirs,const Char_t* esdfilename, const Char
  fdR(0.0),
  fClusterMap(kFALSE),
  fITSTrackPoints(kFALSE),
+ fITSTrackPointsType(AliTrackPoints::kITS),
  fMustTPC(kFALSE),
- fReadCentralBarrel(kFALSE),
+ fReadCentralBarrel(kTRUE),
  fReadMuon(kFALSE),
  fReadPHOS(kFALSE),
  fNTPCClustMin(0),
@@ -133,7 +144,7 @@ AliReaderESD::AliReaderESD(TObjArray* dirs,const Char_t* esdfilename, const Char
  fTPCC44Max(10e5)
 {
   //cosntructor
-  if ( ((Int_t)kNSpecies) != ((Int_t)AliESDtrack::kSPECIES))
+  if ( ((Int_t)kNSpecies) != ((Int_t)AliPID::kSPECIES))
     Fatal("AliReaderESD","ESD defintions probobly changed. Ask Youra.");
 }
 /********************************************************************/
@@ -152,8 +163,7 @@ Int_t AliReaderESD::ReadNext()
 //reads next event from fFile
   //fRunLoader is for reading Kine
   
-  if (AliVAODParticle::GetDebug())
-    Info("ReadNext","Entered");
+  AliDebug(1,"Entered");
     
   if (fEventSim == 0x0)  fEventSim = new AliAOD();
   if (fEventRec == 0x0)  fEventRec = new AliAOD();
@@ -164,25 +174,22 @@ Int_t AliReaderESD::ReadNext()
   do  //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
     {
       if (fFile == 0x0)
-       {
-         fFile = OpenFile(fCurrentDir);//rl is opened here
-         if (fFile == 0x0)
-           {
-             Error("ReadNext","Cannot get fFile for dir no. %d",fCurrentDir);
-             fCurrentDir++;
-             continue;
-           }
-         fCurrentEvent = 0;
-       }
+       {
+         fFile = OpenFile(fCurrentDir);//rl is opened here
+         if (fFile == 0x0)
+           {
+             Error("ReadNext","Cannot get fFile for dir no. %d",fCurrentDir);
+             fCurrentDir++;
+             continue;
+           }
+         fCurrentEvent = 0;
+       }
      TString esdname = "ESD";
      esdname+=fCurrentEvent;
      AliESD* esd = dynamic_cast<AliESD*>(fFile->Get(esdname));
      if (esd == 0x0)
       {
-        if (AliVAODParticle::GetDebug() > 2 )
-          {
-            Info("ReadNext","Can not find AliESD object named %s",esdname.Data());
-          }
+        AliDebug(3,Form("Can not find AliESD object named %s",esdname.Data()));
         fCurrentDir++;
         delete fFile;//we have to assume there is no more ESD objects in the fFile
         fFile = 0x0;
@@ -225,7 +232,7 @@ Int_t AliReaderESD::ReadESD(AliESD* esd)
 Int_t AliReaderESD::ReadESDCentral(AliESD* esd)
 {
   //****** Tentative particle type "concentrations"
-  static const Double_t concentr[5]={0.05, 0., 0.85, 0.10, 0.05};
+  static const Double_t kConcentr[5]={0.05, 0., 0.85, 0.10, 0.05};
   
   Double_t pidtable[kNSpecies];//array used for reading pid probabilities from ESD track
   Double_t w[kNSpecies];
@@ -241,18 +248,18 @@ Int_t AliReaderESD::ReadESDCentral(AliESD* esd)
      return 1;
    }
    
-  Float_t mf = esd->GetMagneticField()
+  Float_t mf = esd->GetMagneticField()/10.; //AliESD::GetMagnField returns mf in kG
 
   if ( (mf == 0.0) && ((fNTrackPoints > 0) || fITSTrackPoints) )
    {
       Error("ReadESD","Magnetic Field is 0 and Track Points Demended. Skipping to next event.");
-      return 1;
+
    }
 
   if (fITSTrackPoints)
    {
-     Info("ReadESD","Magnetic Field is %f",mf/10.);
-     AliKalmanTrack::SetMagneticField(mf/10.);
+     Info("ReadESD","Magnetic Field is %f",mf);
+     //AliKalmanTrack::SetMagneticField(mf);
    }
  
   AliStack* stack = 0x0;
@@ -275,10 +282,7 @@ Int_t AliReaderESD::ReadESDCentral(AliESD* esd)
      vertex->GetXYZ(vertexpos);
    }
    
-  if (AliVAODParticle::GetDebug() > 0)
-   {
-     Info("ReadESD","Primary Vertex is (%f,%f,%f)",vertexpos[0],vertexpos[1],vertexpos[2]);
-   }
+  AliDebug(1,Form("Primary Vertex is (%f,%f,%f)",vertexpos[0],vertexpos[1],vertexpos[2]));
    
   Info("ReadESD","Reading Event %d",fCurrentEvent);
 
@@ -296,8 +300,7 @@ Int_t AliReaderESD::ReadESDCentral(AliESD* esd)
      //if (esdtrack->HasVertexParameters() == kFALSE) 
      if ((esdtrack->GetStatus() & AliESDtrack::kITSrefit) == kFALSE)
       {
-        if (AliVAODParticle::GetDebug() > 2) 
-          Info("ReadNext","Particle skipped: Data at vertex not available.");
+        AliDebug(3,Form("Particle skipped: Data at vertex not available."));
         continue;
       }
 
@@ -305,27 +308,24 @@ Int_t AliReaderESD::ReadESDCentral(AliESD* esd)
       {
        if ((esdtrack->GetStatus() & AliESDtrack::kTPCin) == kFALSE)
         {
-          if (AliVAODParticle::GetDebug() > 2) 
-            Info("ReadNext","Particle skipped: Was not reconstructed in TPC.");
+          AliDebug(3,"Particle skipped: Was not reconstructed in TPC.");
           continue;
         }
       }     
 
      if ((esdtrack->GetStatus() & AliESDtrack::kESDpid) == kFALSE) 
       {
-        if (AliVAODParticle::GetDebug() > 2) 
-          Info("ReadNext","Particle skipped: PID BIT is not set.");
+        AliDebug(3,"Particle skipped: PID BIT is not set.");
         continue;
       }
 
 
-     Double_t extx;
+     Double_t alpha,extx;
      Double_t extp[5];
-     esdtrack->GetConstrainedExternalParameters(extx,extp);
+     esdtrack->GetConstrainedExternalParameters(alpha,extx,extp);
      if (extp[4] == 0.0)
       {
-        if (AliVAODParticle::GetDebug() > 2) 
-          Info("ReadNext","Track has 0 contrianed curvature -> Probobly parameters never updated. Skipping.");
+        AliDebug(3,"Track has 0 contrianed curvature -> Probobly parameters never updated. Skipping.");
         continue;
       } 
      esdtrack->GetESDpid(pidtable);
@@ -354,8 +354,7 @@ Int_t AliReaderESD::ReadESDCentral(AliESD* esd)
          {
            if(Rejected(p->GetPdgCode())) 
             {
-              if ( AliVAODParticle::GetDebug() > 5 )
-                Info("ReadNext","Simulated Particle PID (%d) did not pass the cut.",p->GetPdgCode());
+              AliDebug(6,Form("Simulated Particle PID (%d) did not pass the cut.",p->GetPdgCode()));
               continue; //check if we are intersted with particles of this type 
             }
          }  
@@ -368,17 +367,16 @@ Int_t AliReaderESD::ReadESDCentral(AliESD* esd)
       
      //Here we apply Bayes' formula
      Double_t rc=0.;
-     for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) rc+=concentr[s]*pidtable[s];
+     for (Int_t s=0; s<AliPID::kSPECIES; s++) rc+=kConcentr[s]*pidtable[s];
      if (rc==0.0) 
       {
-        if (AliVAODParticle::GetDebug() > 2) 
-          Info("ReadNext","Particle rejected since total bayessian PID probab. is zero.");
+        AliDebug(3,"Particle rejected since total bayessian PID probab. is zero.");
         continue;
       }
 
-     for (Int_t s=0; s<AliESDtrack::kSPECIES; s++) w[s]=concentr[s]*pidtable[s]/rc;
+     for (Int_t s=0; s<AliPID::kSPECIES; s++) w[s]=kConcentr[s]*pidtable[s]/rc;
 
-     if (AliVAODParticle::GetDebug() > 4)
+     if (AliDebugLevel() > 4)
       { 
         Info("ReadNext","###########################################################################");
         Info("ReadNext","Momentum: %f %f %f",mom[0],mom[1],mom[2]);
@@ -397,19 +395,19 @@ Int_t AliReaderESD::ReadESDCentral(AliESD* esd)
            msg+=")";
          }
         Info("ReadNext","%s",msg.Data());
-      }//if (AliVAODParticle::GetDebug()>4)
+      }//if (AliDebugLevel()>4)
 
       AliTrackPoints* tpts = 0x0;
       if (fNTrackPoints > 0) 
        {
-         tpts = new AliTrackPoints(fNTrackPoints,esdtrack,mf,fdR);
+         tpts = new AliTrackPoints(fNTrackPoints,esdtrack,mf*10.0,fdR);
 //         tpts->Move(-vertexpos[0],-vertexpos[1],-vertexpos[2]);
        }
 
       AliTrackPoints* itstpts = 0x0;
       if (fITSTrackPoints) 
        {
-         itstpts = new AliTrackPoints(AliTrackPoints::kITS,esdtrack);
+         itstpts = new AliTrackPoints(fITSTrackPointsType,esdtrack,mf*10.0);
 //         itstpts->Move(-vertexpos[0],-vertexpos[1],-vertexpos[2]);
        }
 
@@ -432,7 +430,7 @@ Int_t AliReaderESD::ReadESDCentral(AliESD* esd)
         //find the most probable PID
         Int_t spec = 0;
         Float_t maxprob = w[0];
-        for (Int_t s=1; s<AliESDtrack::kSPECIES; s++) 
+        for (Int_t s=1; s<AliPID::kSPECIES; s++) 
          {
            if (w[s]>maxprob)
             {
@@ -450,15 +448,13 @@ Int_t AliReaderESD::ReadESDCentral(AliESD* esd)
         Float_t pp = w[s];
         if (pp == 0.0) 
          {
-           if ( AliVAODParticle::GetDebug() > 5 )
-             Info("ReadNext","Probability of being PID %d is zero. Continuing.",pdgcode);
+           AliDebug(6,Form("Probability of being PID %d is zero. Continuing.",pdgcode));
            continue;
          }
 
         if(Rejected(pdgcode)) 
          {
-           if ( AliVAODParticle::GetDebug() > 5 )
-             Info("ReadNext","PID (%d) did not pass the cut.",pdgcode);
+           AliDebug(6,Form("PID (%d) did not pass the cut.",pdgcode));
            continue; //check if we are intersted with particles of this type 
          }
 
@@ -479,8 +475,7 @@ Int_t AliReaderESD::ReadESDCentral(AliESD* esd)
         if(Rejected(track))//check if meets all criteria of any of our cuts
                        //if it does not delete it and take next good track
          { 
-           if ( AliVAODParticle::GetDebug() > 4 )
-             Info("ReadNext","Track did not pass the cut");
+           AliDebug(5,"Track did not pass the cut");
            delete track;
            continue;
          }
@@ -505,7 +500,7 @@ Int_t AliReaderESD::ReadESDCentral(AliESD* esd)
         if (particle) fEventSim->AddParticle(particle);
         keeppart = kTRUE;
 
-        if (AliVAODParticle::GetDebug() > 4 )
+        if (AliDebugLevel() > 4 )
          {
            Info("ReadNext","\n\nAdding Particle with incarnation %d",pdgcode);
            track->Print();
@@ -560,7 +555,7 @@ Int_t AliReaderESD::ReadESDCentral(AliESD* esd)
 /**********************************************************/
 Int_t AliReaderESD::ReadESDMuon(AliESD* esd)
 {
-
+  // Reads the muon tracks from the ESD
   Double_t vertexpos[3];//vertex position, assuming no secondary decay
 
   const AliESDVertex* vertex = esd->GetVertex();
@@ -576,18 +571,16 @@ Int_t AliReaderESD::ReadESDMuon(AliESD* esd)
 
  Int_t nTracks = (Int_t)esd->GetNumberOfMuonTracks() ;
 
- if (AliVAODParticle::GetDebug() > 0) {
-   Info("ReadESD","Reading Event %d",fCurrentEvent);
-   Info("ReadESD","Found %d tracks.",nTracks);
- }
+ AliDebug(1,Form("Reading Event %d \nFound %d tracks.",fCurrentEvent,nTracks));
+
  // settings
-  Float_t Chi2Cut = 100.;
-  Float_t PtCutMin = 1.;
-  Float_t PtCutMax = 10000.;
+  Float_t chi2Cut = 100.;
+  Float_t ptCutMin = 1.;
+  Float_t ptCutMax = 10000.;
   Float_t muonMass = 0.105658389;
   Int_t pdgcode = -13;
   Double_t thetaX, thetaY, pYZ;
-  Double_t pxRec1, pyRec1, pzRec1, E1;
+  Double_t pxRec1, pyRec1, pzRec1, e1;
   Int_t charge;
 
   Int_t ntrackhits;
@@ -607,8 +600,8 @@ Int_t AliReaderESD::ReadESDMuon(AliESD* esd)
       pxRec1  = pzRec1 * TMath::Tan(thetaX);
       pyRec1  = pzRec1 * TMath::Tan(thetaY);
       charge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
-      E1 = TMath::Sqrt(muonMass * muonMass + pxRec1 * pxRec1 + pyRec1 * pyRec1 + pzRec1 * pzRec1);
-      fV1.SetPxPyPzE(pxRec1, pyRec1, pzRec1, E1);
+      e1 = TMath::Sqrt(muonMass * muonMass + pxRec1 * pxRec1 + pyRec1 * pyRec1 + pzRec1 * pzRec1);
+      fV1.SetPxPyPzE(pxRec1, pyRec1, pzRec1, e1);
 
       ntrackhits = muonTrack->GetNHit();
       fitfmin    = muonTrack->GetChi2();
@@ -619,9 +612,9 @@ Int_t AliReaderESD::ReadESDMuon(AliESD* esd)
       // chi2 per d.o.f.
       Float_t ch1 =  fitfmin / (2.0 * ntrackhits - 5);
 
-      if ((ch1 < Chi2Cut) && (pt1 > PtCutMin) && (pt1 < PtCutMax)) {
+      if ((ch1 < chi2Cut) && (pt1 > ptCutMin) && (pt1 < ptCutMax)) {
        AliAODParticle* track = new AliAODParticle(pdgcode*charge,1,iTrack, 
-                                                   pxRec1, pyRec1,pzRec1, E1,
+                                                   pxRec1, pyRec1,pzRec1, e1,
                                                    vertexpos[0], vertexpos[1], vertexpos[2], 0.);
         fEventRec->AddParticle(track);
       }
@@ -644,6 +637,7 @@ void AliReaderESD::Rewind()
   fRunLoader = 0x0;
   fCurrentDir = 0;
   fNEventsRead = 0;
+  if (fEventList) fEventList->Reset(); 
   if (fTrackCounter) fTrackCounter->Reset();
 }
 /**********************************************************/
@@ -651,14 +645,39 @@ void AliReaderESD::Rewind()
 TFile* AliReaderESD::OpenFile(Int_t n)
 {
 //opens fFile with  tree
-
+ if (fEventList)
+  { 
+    if (fCurrentDir > n)
+     {
+       fEventList->Reset();
+       fCurrentDir = 0;
+     }
+    
+    while (fCurrentDir < n)
+     {
+       fEventList->Next();
+       fCurrentDir++;
+     }
+    fEventList->Next();
+  }
  const TString& dirname = GetDirName(n);
  if (dirname == "")
   {
    Error("OpenFiles","Can not get directory name");
    return 0x0;
   }
- TString filename = dirname +"/"+ fESDFileName;
+ TString filename;
+ if (fEventList)
+  {
+    filename = fEventList->GetURL(fESDFileName);
+  }
+ else
+  {
+    filename = dirname +"/"+ fESDFileName;
+  }
+ Info("OpenFile","%s ==> %s",fESDFileName.Data(),filename.Data()); 
  TFile *ret = TFile::Open(filename.Data()); 
 
  if ( ret == 0x0)
@@ -674,7 +693,19 @@ TFile* AliReaderESD::OpenFile(Int_t n)
  
  if (fReadSim )
   {
-   fRunLoader = AliRunLoader::Open(dirname +"/"+ fGAlFileName);
+    TString gafilename;
+    if (fEventList)
+     {
+       gafilename = fEventList->GetURL(fGAlFileName);
+     }
+    else
+     {
+       gafilename = dirname +"/"+ fGAlFileName;
+     }
+   Info("OpenFile","%s ==> %s",fGAlFileName.Data(),gafilename.Data()); 
+
+   fRunLoader = AliRunLoader::Open(gafilename);
+   
    if (fRunLoader == 0x0)
     {
       Error("OpenFiles","Can't get RunLoader for directory %s",dirname.Data());
@@ -683,6 +714,14 @@ TFile* AliReaderESD::OpenFile(Int_t n)
     }
     
    fRunLoader->LoadHeader();
+   
+   if (fEventList)
+    {
+      TString kinefilename = fEventList->GetURL("Kinematics.root");
+      fRunLoader->SetKineFileName(kinefilename);
+      Info("OpenFile","%s ==> %s","Kinematics.root",kinefilename.Data()); 
+    } 
+   
    if (fRunLoader->LoadKinematics())
     {
       Error("Next","Error occured while loading kinematics.");