]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HBTAN/AliHBTReader.cxx
Bug correction
[u/mrichter/AliRoot.git] / HBTAN / AliHBTReader.cxx
index b6edaa3623744e480690238e0a69ec5575129463..4489f6561db1b79028df8a8f89397e7d84e9c67f 100644 (file)
@@ -1,10 +1,37 @@
 #include "AliHBTReader.h"
+//_________________________________________________________________________
+///////////////////////////////////////////////////////////////////////////
+//
+// class AliHBTReader
+//
+// Reader Base class (reads particles and tracks and
+// puts it to the AliHBTRun objects
+//
+// Provides functionality for both buffering and non-buffering reading
+// This can be switched on/off via method SetEventBuffering(bool)
+// The main method that inheriting classes need to implement is ReadNext()
+// that read next event in queue.
+// The others are:
+// Bool_t  ReadsTracks() const; specifies if reader is able to read simulated particles
+// Bool_t  ReadsParticles() const; specifies if reader is able to read reconstructed tracks
+// void    Rewind(); rewind reading to the beginning
+//
+// reading of next event is triggered via method Next()
+//
+// This class provides full functionality for reading from many sources
+// User can provide TObjArray of TObjString (SetDirs method or via parameter 
+// in constructor) which desribes paths of directories to search data in.
+// If none specified current directory is searched.
+//
+// Piotr.Skowronski@cern.ch
+///////////////////////////////////////////////////////////////////////////
 
 #include <TString.h>
 #include <TObjString.h>
 #include <TObjArray.h>
 #include <TClass.h>
 #include <TRandom.h>
+#include <TH1.h>
 
 #include "AliHBTParticleCut.h"
 #include "AliHBTEvent.h"
@@ -29,7 +56,8 @@ AliHBTReader::AliHBTReader():
  fBufferEvents(kFALSE),
  fBlend(kFALSE),
  fFirst(0),
- fLast(0)
+ fLast(0),
+ fTrackCounter(0x0)
 {
 //constructor
 }
@@ -49,11 +77,32 @@ AliHBTReader::AliHBTReader(TObjArray* dirs):
  fBufferEvents(kFALSE),
  fBlend(kFALSE),
  fFirst(0),
- fLast(0)
+ fLast(0),
+ fTrackCounter(0x0)
 {
 //ctor with array of directories to read as parameter
 }
 /*************************************************************************************/
+AliHBTReader::AliHBTReader(const AliHBTReader& in):
+ TNamed(in),
+ fCuts((in.fCuts)?(TObjArray*)in.fCuts->Clone():0x0),
+ fDirs((in.fDirs)?(TObjArray*)in.fDirs->Clone():0x0),
+ fCurrentEvent(0),
+ fCurrentDir(0),
+ fNEventsRead(0),
+ fTracksEvent(0x0),
+ fParticlesEvent(0x0),
+ fParticles(0x0),
+ fTracks(0x0),
+ fIsRead(kFALSE),
+ fBufferEvents(in.fBufferEvents),
+ fBlend(in.fBlend),
+ fFirst(in.fFirst),
+ fLast(in.fLast),
+ fTrackCounter(0x0)
+{
+ //cpy constructor
+}
 
 AliHBTReader::~AliHBTReader()
 {
@@ -65,23 +114,59 @@ AliHBTReader::~AliHBTReader()
   }
  delete fParticlesEvent;
  delete fTracksEvent;
+ delete fTrackCounter;
+}
+/*************************************************************************************/
+
+AliHBTReader& AliHBTReader::operator=(const AliHBTReader& in)
+{
+  //Assigment operator
+ if (this == &in) return *this;  
+ TNamed::operator=( (const TNamed&)in );
+  
+ fCuts = (in.fCuts)?(TObjArray*)in.fCuts->Clone():0x0;
+ fDirs = (in.fDirs)?(TObjArray*)in.fDirs->Clone():0x0;
+ fCurrentEvent = 0;
+ fCurrentDir = 0;
+ fNEventsRead = 0;
+ fTracksEvent = 0x0;
+ fParticlesEvent = 0x0;
+ fParticles = 0x0;
+ fTracks = 0x0;
+ fIsRead = kFALSE;
+ fBufferEvents = in.fBufferEvents;
+ fBlend = in.fBlend;
+ fFirst = in.fFirst;
+ fLast = in.fLast;
+ fTrackCounter = 0x0;
+ return *this;  
 }
 /*************************************************************************************/
 
 Int_t AliHBTReader::Next()
 {
 //moves to next event
-  if ((fNEventsRead > fLast) && (fLast > 0) )
-   
-  do
+
+  //if asked to read up to event nb. fLast, and it is overcome, report no more events
+  if ((fNEventsRead > fLast) && (fLast > 0) ) return kTRUE;
+  
+  if (fTrackCounter == 0x0)//create Track Counter
+   {
+     fTrackCounter = new TH1I("trackcounter","Track Counter",20000,0,20000);
+     fTrackCounter->SetDirectory(0x0);
+   }
+  
+  do //if asked to read from event fFirst, rewind to it
    {
-    if ( ReadNext() == kTRUE)
+    if ( ReadNext() == kTRUE) //if no more evets, return it
       return kTRUE;
    }while (fNEventsRead < fFirst);
+   
+  //here we have event
   
-  if (fBlend) Blend();
+  if (fBlend) Blend();//Mix particles order 
   
-  if (fBufferEvents)
+  if (fBufferEvents)//store events if buffering is on
    {
      if ( ReadsTracks() && fTracksEvent) 
        fTracks->SetEvent(fNEventsRead-1-fFirst,fTracksEvent);
@@ -238,13 +323,13 @@ Int_t AliHBTReader::Read(AliHBTRun* particles, AliHBTRun *tracks)
 }      
 /*************************************************************************************/
 
-Bool_t AliHBTReader::Pass(AliHBTParticle* p)
+Bool_t AliHBTReader::Rejected(AliHBTParticle* p)
 {
  //Method examines whether particle meets all cut and particle type criteria
   
    if(p==0x0)//of corse we not pass NULL pointers
     {
-     Warning("Pass()","No Pasaran! We never accept NULL pointers");
+     Warning("Rejected()","No Pasaran! We never accept NULL pointers");
      return kTRUE;
     }
    //if no particle is specified, we pass all particles
@@ -253,14 +338,14 @@ Bool_t AliHBTReader::Pass(AliHBTParticle* p)
   for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)   
    {
      AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i));
-     if(!cut.Pass(p)) return kFALSE;  //accepted
+     if(!cut.Rejected(p)) return kFALSE;  //accepted
    }
    
   return kTRUE;//not accepted
 }
 /*************************************************************************************/
 
-Bool_t  AliHBTReader::Pass(Int_t pid)
+Bool_t  AliHBTReader::Rejected(Int_t pid)
 {
 //this method checks if any of existing cuts accepts this pid particles
 //or any cuts accepts all particles
@@ -324,6 +409,9 @@ void AliHBTReader::Blend()
   //randomly change positions of the particles after reading
   //is used to check if some distr depends on order of particles
   //(tracking gives particles Pt sorted)
+  
+  if (fParticlesEvent == 0x0) return;
+  
   for (Int_t i = 2; i < fParticlesEvent->GetNumberOfParticles(); i++)
    {
      Int_t with = gRandom->Integer(i);
@@ -331,3 +419,15 @@ void AliHBTReader::Blend()
      if (fTracksEvent) fTracksEvent->SwapParticles(i,with);
    }
 }
+/*************************************************************************************/
+
+void AliHBTReader::WriteTrackCounter() const
+{
+ //writes the counter histogram
+ if (fTrackCounter) fTrackCounter->Write(0,TObject::kOverwrite);
+ else 
+  {
+    Warning("WriteTrackCounter","Counter is NULL");
+  }
+}