Checking cuts implemented
authorskowron <skowron@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 24 Aug 2004 09:03:37 +0000 (09:03 +0000)
committerskowron <skowron@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 24 Aug 2004 09:03:37 +0000 (09:03 +0000)
ANALYSIS/AliReaderAOD.cxx
ANALYSIS/AliReaderAOD.h

index 2a4b92e..f0748af 100644 (file)
@@ -1,20 +1,44 @@
 #include "AliReaderAOD.h"
+//______________________________________________________________________________
+////////////////////////////////////////////////////////////////////////////////
+//                                                                            //
+// class AliReaderAOD                                                         //
+//                                                                            //
+// Reader and Writer for AOD format.                                          //
+// AODs are stored in a tree named by the variable fgkTreeName.               //
+// There is stored 1 or 2 branches. Each of them stores AOD objects           //
+// First branch is named by the variable fgkReconstructedDataBranchName       //
+// ("reconstructed.") and keeps reconstructed data.                           //
+// Second branch is called by the variable fgkSimulatedDataBranchName         //
+// ("simulated.") and stores Monte carlo truth. If both branches are present  //
+// AODs are parallel, i.e. nth particle in one branch corresponds to the nth  //
+// particle in the other one.                                                 //
+//                                                                            //
+// Since we accept different formats of particles that are stored in AODs     //
+// reader must take care of that fact: clean buffer if the next file contains //
+// different particle type.                                                   //
+//                                                                            //
+// Piotr.Skowronski@cern.ch                                                   //
+//                                                                            //
+////////////////////////////////////////////////////////////////////////////////
 
 ClassImp(AliReaderAOD)
 
 #include <TError.h>
 #include <TFile.h>
 #include <TTree.h>
+#include <TH1.h>
 #include "AliAOD.h"
 
 
 const TString AliReaderAOD::fgkTreeName("TAOD");
-const TString AliReaderAOD::fgkRecosntructedDataBranchName("reconstructed.");
+const TString AliReaderAOD::fgkReconstructedDataBranchName("reconstructed.");
 const TString AliReaderAOD::fgkSimulatedDataBranchName("simulated.");
 
 AliReaderAOD::AliReaderAOD(const Char_t* aodfilename):
  fFileName(aodfilename),
  fReadSim(kFALSE),
+ fReadRec(kTRUE),
  fTree(0x0),
  fFile(0x0),
  fSimBuffer(0x0),
@@ -60,8 +84,8 @@ Int_t AliReaderAOD::ReadNext()
     {
       if (fFile == 0x0)
        {
-         Int_t opened = OpenFile(fCurrentDir);//rl is opened here
-         if (opened)
+         Int_t openfailed = OpenFile(fCurrentDir);//rl is opened here
+         if (openfailed)
            {
              //Error("ReadNext","Error Occured while opening directory number %d",fCurrentDir);
              fCurrentDir++;
@@ -69,33 +93,38 @@ Int_t AliReaderAOD::ReadNext()
            }
          fCurrentEvent = 0;
        }
+      //Tree must exist because OpenFile would reuturn error in the other case
+      if ( fCurrentEvent >= fTree->GetEntries() )
+       {
+         delete fTree;
+         fTree = 0x0;
+         delete fFile;
+         fFile = 0x0;
+         fSimBuffer = 0x0;
+         fRecBuffer = 0x0;
+         fCurrentDir++;
+         continue;
+       }
+       
       Info("ReadNext","Getting event %d",fCurrentEvent);
       fTree->GetEvent(fCurrentEvent);
       Info("ReadNext","Getting event %d Done",fCurrentEvent);
       
-      //Temporary testing sollution
-      fEventSim = fSimBuffer;
-      fEventRec = fRecBuffer;
-      
-      fCurrentEvent++;
-      fNEventsRead++;
-
-      if (fTree)
+      Int_t retval = 0;
+      if (fReadRec && fReadSim)
        {
-         if ( fCurrentEvent >= fTree->GetEntries() )
-          {
-            delete fTree;
-            fTree = 0x0;
-            delete fFile;
-            fFile = 0x0;
-            fSimBuffer = 0x0;
-            fRecBuffer = 0x0;
-            fCurrentDir++;
-          } 
+         retval = ReadRecAndSim();
        }
+      else
+       {
+         if (fReadRec) retval = ReadRec();
+         if (fReadSim) retval = ReadSim();
+       } 
 
+      fCurrentEvent++;
+      if (retval == 0) fNEventsRead++;
 
-      return 0;//success -> read one event
+      return retval;//success -> read one event
       
     }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array  
    
@@ -105,6 +134,147 @@ Int_t AliReaderAOD::ReadNext()
 }
 /********************************************************************/
 
+Int_t AliReaderAOD::ReadRecAndSim()
+{
+//Reads raconstructed and simulated data 
+
+ Info("ReadRecAndSim","Found %d reconstructed tracks and %d simulated particles",
+       fRecBuffer->GetNumberOfParticles(),fSimBuffer->GetNumberOfParticles());
+
+ if (fCuts->GetEntriesFast() == 0x0)
+  {//if there is no cuts we return pointer to the buffer
+    if (fEventRec != fRecBuffer)
+     {
+       delete fEventRec;
+       delete fEventSim;
+     }
+    fEventRec = fRecBuffer;//fEventRec is the pointer that the user gets when he asks about an event
+    fEventSim = fSimBuffer;
+  }
+ else
+  {//if there are cuts specified
+    if ( (fEventRec == 0x0) || (fEventRec == fRecBuffer) )
+     {//we need to create a new event, if it is not existing  or it is the same as branch buffer
+       fEventRec = new AliAOD();
+       fEventSim = new AliAOD();
+
+       fEventRec->SetParticleClass( fRecBuffer->GetParticleClass() );
+       fEventSim->SetParticleClass( fSimBuffer->GetParticleClass() );
+     } 
+    else
+     {//or simply reset it in case it already exists
+       fEventRec->Reset();
+       fEventSim->Reset();
+     }
+
+    Int_t npart = fRecBuffer->GetNumberOfParticles();
+    for (Int_t i = 0; i < npart; i++)
+     {
+       AliVAODParticle* prec = fRecBuffer->GetParticle(i);
+       if (Rejected(prec)) continue;//we make cuts only on simulated data
+
+       fEventRec->AddParticle(prec);
+       fEventSim->AddParticle( fSimBuffer->GetParticle(i));
+     }
+  }
+
+ Info("ReadRecAndSim","Read %d reconstructed tracks and %d simulated particles",
+       fEventRec->GetNumberOfParticles(),fEventSim->GetNumberOfParticles());
+ fTrackCounter->Fill(fEventRec->GetNumberOfParticles());
+ return 0;
+}
+/********************************************************************/
+
+Int_t AliReaderAOD::ReadRec()
+{
+//Reads reconstructed data only
+
+ Info("ReadRec","Found %d reconstructed tracks",fRecBuffer->GetNumberOfParticles());
+
+ if (fCuts->GetEntriesFast() == 0x0)
+  {//if there is no cuts we return pointer to the buffer
+    if (fEventRec != fRecBuffer)
+     {
+       delete fEventRec;
+     }
+    fEventRec = fRecBuffer;//fEventRec is the pointer that the user gets when he asks about an event
+  }
+ else
+  {//if there are cuts specified
+    if ( (fEventRec == 0x0) || (fEventRec == fRecBuffer) )
+     {//we need to create a new event, if it is not existing  or it is the same as branch buffer
+       fEventRec = new AliAOD();
+
+       fEventRec->SetParticleClass( fRecBuffer->GetParticleClass() );
+     } 
+    else
+     {//or simply reset it in case it already exists
+       fEventRec->Reset();
+     }
+
+    Int_t npart = fRecBuffer->GetNumberOfParticles();
+    for (Int_t i = 0; i < npart; i++)
+     {
+       AliVAODParticle* prec = fRecBuffer->GetParticle(i);
+       if (Rejected(prec)) continue;//we make cuts only on simulated data
+
+       fEventRec->AddParticle(prec);
+     }
+  }
+
+ Info("ReadRec","Read %d reconstructed tracks",fEventRec->GetNumberOfParticles());
+ fTrackCounter->Fill(fEventRec->GetNumberOfParticles());
+
+ return 0;
+}
+/********************************************************************/
+
+Int_t AliReaderAOD::ReadSim()
+{
+//Reads simulated data only
+
+ Info("ReadSim","Found %d simulated particles",fSimBuffer->GetNumberOfParticles());
+
+ if (fCuts->GetEntriesFast() == 0x0)
+  {//if there is no cuts we return pointer to the buffer
+    if (fEventSim != fSimBuffer)
+     {
+       delete fEventSim;
+     }
+    fEventSim = fSimBuffer;
+  }
+ else
+  {//if there are cuts specified
+    if ( (fEventSim == 0x0) || (fEventSim == fSimBuffer) )
+     {//we need to create a new event, if it is not existing  or it is the same as branch buffer
+       fEventSim = new AliAOD();
+
+       fEventSim->SetParticleClass( fSimBuffer->GetParticleClass() );
+     } 
+    else
+     {//or simply reset it in case it already exists
+       fEventSim->Reset();
+     }
+
+    Int_t npart = fSimBuffer->GetNumberOfParticles();
+    for (Int_t i = 0; i < npart; i++)
+     {
+       AliVAODParticle* prec = fSimBuffer->GetParticle(i);
+       if (Rejected(prec)) continue;//we make cuts only on simulated data
+       fEventSim->AddParticle(prec);
+     }
+  }
+
+ Info("ReadSim","Read %d simulated particles",fEventSim->GetNumberOfParticles());
+ fTrackCounter->Fill(fEventSim->GetNumberOfParticles());
+
+
+ return 0;
+}
+/********************************************************************/
+
 Int_t AliReaderAOD::OpenFile(Int_t n)
 {
 //opens fFile with  tree
@@ -144,24 +314,53 @@ Int_t AliReaderAOD::OpenFile(Int_t n)
       {
         Info("ReadNext","Can not find TTree object named %s",fgkTreeName.Data());
       }
-    fCurrentDir++;
-    delete fFile;//we have to assume there is no more ESD objects in the fFile
+    delete fFile;
     fFile = 0x0;
     return 4;
   }
 
 //  Info("ReadNext","Got TREE, Setting branch addresses");
 
-  fTree->SetBranchAddress(fgkSimulatedDataBranchName,&fSimBuffer);
-  fTree->SetBranchAddress(fgkRecosntructedDataBranchName,&fRecBuffer);
+  if (fReadRec)
+   {
+     TBranch* branch = fTree->GetBranch(fgkReconstructedDataBranchName);
+     if (branch == 0x0)
+      {
+        Error("OpenFile","Can not find branch %s in file %s",
+              fgkReconstructedDataBranchName.Data(),filename.Data());
+        
+        delete fTree;
+        fTree = 0x0;
+        delete fFile;
+        fFile = 0x0;
+        return 5;
+      }
+     fTree->SetBranchAddress(fgkReconstructedDataBranchName,&fRecBuffer);
+   }
   
+
+  if (fReadSim)
+   {
+     TBranch* branch = fTree->GetBranch(fgkSimulatedDataBranchName);
+     if (branch == 0x0)
+      {
+        Error("OpenFile","Can not find branch %s in file %s",
+              fgkSimulatedDataBranchName.Data(),filename.Data());
+        
+        delete fTree;
+        fTree = 0x0;
+        delete fFile;
+        fFile = 0x0;
+        return 6;
+      }
+     fTree->SetBranchAddress(fgkSimulatedDataBranchName,&fSimBuffer);
+   }
 //  Info("ReadNext","Got TREE, Addresses are set.");
 //  Info("ReadNext","Quitting the method.");
   
   return 0;
  
 }
-
 /********************************************************************/
 
 Int_t AliReaderAOD::WriteAOD(AliReader* reader, const char* outfilename, const char* pclassname,  Bool_t /*multcheck*/)
@@ -196,7 +395,7 @@ Int_t AliReaderAOD::WriteAOD(AliReader* reader, const char* outfilename, const c
   AliAOD* recbuffer = eventrec;
   AliAOD* simbuffer = eventsim;
   
-  if (reader->ReadsRec()) recbranch = tree->Branch(fgkRecosntructedDataBranchName,"AliAOD",&recbuffer,32000,99);
+  if (reader->ReadsRec()) recbranch = tree->Branch(fgkReconstructedDataBranchName,"AliAOD",&recbuffer,32000,99);
   if (reader->ReadsSim()) simbranch = tree->Branch(fgkSimulatedDataBranchName,"AliAOD",&simbuffer,32000,99);
 
   reader->Rewind();
index b7e4592..49a4454 100644 (file)
@@ -1,5 +1,33 @@
 #ifndef ALIREADERAOD_H
 #define ALIREADERAOD_H
+//______________________________________________________________________________
+////////////////////////////////////////////////////////////////////////////////
+//                                                                            //
+// class AliReaderAOD                                                         //
+//                                                                            //
+// Reader and Writer for AOD format.                                          //
+// AODs are stored in a tree named by the variable fgkTreeName.               //
+// There is stored 1 or 2 branches. Each of them stores AOD objects           //
+// First branch is named by the variable fgkReconstructedDataBranchName       //
+// ("reconstructed.") and keeps reconstructed data.                           //
+// Second branch is called by the variable fgkSimulatedDataBranchName         //
+// ("simulated.") and stores Monte carlo truth. If both branches are present  //
+// AODs are parallel, i.e. nth particle in one branch corresponds to the nth  //
+// particle in the other one.                                                 //
+//                                                                            //
+// Since we accept different formats of particles that are stored in AODs     //
+// reader must take care of that fact: clean buffer if the next file contains //
+// different particle type.                                                   //
+//                                                                            //
+// If no cuts are specified in a reader, it reuturns pointer to the           //
+// buffers. In the other case data are copied to the onother AOD (filtering   //
+// out particles that do not pass a cut), thus reading is slower.             //
+//                                                                            //
+// Piotr.Skowronski@cern.ch                                                   //
+//                                                                            //
+////////////////////////////////////////////////////////////////////////////////
+
+
 
 #include "AliReader.h"
 
@@ -13,7 +41,8 @@ class AliReaderAOD: public AliReader
     virtual ~AliReaderAOD();
 
     void          ReadSimulatedData(Bool_t flag){fReadSim = flag;}//switches reading MC data
-    Bool_t        ReadsRec() const {return kTRUE;}
+    void          ReadReconsructedData(Bool_t flag){fReadRec = flag;}//switches reading MC data
+    Bool_t        ReadsRec() const {return fReadRec;}
     Bool_t        ReadsSim() const {return fReadSim;}
 
     void          Rewind();
@@ -24,10 +53,14 @@ class AliReaderAOD: public AliReader
     
   protected:
     virtual Int_t         ReadNext();
-    virtual Int_t        OpenFile(Int_t evno);//opens files to be read for given event
-
+    virtual Int_t         OpenFile(Int_t evno);//opens files to be read for given event
+    
+    virtual Int_t         ReadRecAndSim();
+    virtual Int_t         ReadRec();
+    virtual Int_t         ReadSim();
+    
     static const TString  fgkTreeName;//name of branch holding simulated data
-    static const TString  fgkRecosntructedDataBranchName;//name of branch holding reconstructed data
+    static const TString  fgkReconstructedDataBranchName;//name of branch holding reconstructed data
     static const TString  fgkSimulatedDataBranchName;//name of branch holding simulated data
     
   
@@ -35,6 +68,7 @@ class AliReaderAOD: public AliReader
     TString fFileName;//File name
     
     Bool_t  fReadSim;//indicates if to read simulated data
+    Bool_t  fReadRec;//indicates if to read simulated data
 
     TTree*        fTree;//!tree
     TFile*        fFile;//!file