diff --git a/tree/inc/TTreeFilePrefetch.h b/tree/inc/TTreeFilePrefetch.h
index c73c65e1ac9f7952532da66760cd4630943daa31..8e1b5651a6ee46b92b20abd6852cde25e1eb6b21 100644
--- a/tree/inc/TTreeFilePrefetch.h
+++ b/tree/inc/TTreeFilePrefetch.h
@@ -1,4 +1,4 @@
-// @(#)root/tree:$Name:  $:$Id: TTreeFilePrefetch.h,v 1.1 2006/06/05 20:30:27 brun Exp $
+// @(#)root/tree:$Name:  $:$Id: TTreeFilePrefetch.h,v 1.2 2006/06/08 12:46:45 brun Exp $
 // Author: Rene Brun   04/06/2006
 
 /*************************************************************************
@@ -30,9 +30,11 @@ class TTree;
 class TTreeFilePrefetch : public TFilePrefetch {
 
 protected:
-   TTree        *fTree;       //!pointer to the TTree
-   Long64_t      fEntryMax;   //last entry in the cache
-   
+   TTree          *fTree;       //!pointer to the TTree
+   Long64_t        fEntryMin;   //first entry in the cache
+   Long64_t        fEntryMax;   //last entry in the cache
+   static Double_t fgThreshold; //do not register basket if entry-fEntrymin>fgEntryDiff   
+
 protected:
    TTreeFilePrefetch(const TTreeFilePrefetch &);            //this class cannot be copied
    TTreeFilePrefetch& operator=(const TTreeFilePrefetch &);
@@ -41,11 +43,13 @@ public:
    TTreeFilePrefetch();
    TTreeFilePrefetch(TTree *tree, Int_t buffersize=0);
    virtual ~TTreeFilePrefetch();
+   static Double_t     GetThreshold();
    TTree              *GetTree() const {return fTree;}
    virtual Bool_t      ReadBuffer(char *buf, Long64_t pos, Int_t len);
    Bool_t              Register(Long64_t offset);
-   void                SetEntryMax(Long64_t emax);
+   void                SetEntryRange(Long64_t emin, Long64_t emax);
    void                SetTree(TTree *tree);
+   static void         SetThreshold(Double_t t=0.01);
         
    ClassDef(TTreeFilePrefetch,1)  //Specialization of TFilePrefetch for a TTree 
 };
diff --git a/tree/src/TTreeFilePrefetch.cxx b/tree/src/TTreeFilePrefetch.cxx
index 9f8e3e095d2de90ef3e19424d531e16403f4708f..14dc51ca300e7a311c11272cc84f500101b6cb54 100644
--- a/tree/src/TTreeFilePrefetch.cxx
+++ b/tree/src/TTreeFilePrefetch.cxx
@@ -1,4 +1,4 @@
-// @(#)root/tree:$Name:  $:$Id: TTreeFilePrefetch.cxx,v 1.4 2006/06/08 13:26:01 brun Exp $
+// @(#)root/tree:$Name:  $:$Id: TTreeFilePrefetch.cxx,v 1.5 2006/06/09 11:54:33 brun Exp $
 // Author: Rene Brun   04/06/2006
 
 /*************************************************************************
@@ -36,11 +36,14 @@
 #include "TBranch.h"
 #include "TLeaf.h"
 
+Double_t TTreeFilePrefetch::fgThreshold = 0.01;
+
 ClassImp(TTreeFilePrefetch)
 
 //______________________________________________________________________________
 TTreeFilePrefetch::TTreeFilePrefetch() : TFilePrefetch(),
    fTree(0),
+   fEntryMin(0),
    fEntryMax(1)
 {
    // Default Constructor.
@@ -49,6 +52,7 @@ TTreeFilePrefetch::TTreeFilePrefetch() : TFilePrefetch(),
 //______________________________________________________________________________
 TTreeFilePrefetch::TTreeFilePrefetch(TTree *tree, Int_t buffersize) : TFilePrefetch(tree->GetCurrentFile(),buffersize),
    fTree(tree),
+   fEntryMin(0),
    fEntryMax(tree->GetEntries())
 {
    // Constructor.
@@ -75,6 +79,15 @@ TTreeFilePrefetch& TTreeFilePrefetch::operator=(const TTreeFilePrefetch& pf)
    return *this;
 }         
 
+//_____________________________________________________________________________
+Double_t TTreeFilePrefetch::GetThreshold()
+{
+   //static function returning fgThreshold
+   //see SetThreshold
+   
+   return fgThreshold;
+}
+
 //_____________________________________________________________________________
 Bool_t TTreeFilePrefetch::ReadBuffer(char *buf, Long64_t pos, Int_t len)
 {
@@ -106,11 +119,14 @@ Bool_t TTreeFilePrefetch::Register(Long64_t offset)
    // Register branch owning basket at starting position offset
    // return kTRUE if the registration succeeds
    
+   Bool_t status = kFALSE;
+   //do not cache branches with a small hit rate   
+   if ((fTree->GetReadEntry()-fEntryMin) > 100*fgThreshold) return status;
+   
    //reset cache when reaching the maximum cache size
    if (fNtot+30000 > fBufferSize) TFilePrefetch::Prefetch(0,0);
    Int_t nleaves = fTree->GetListOfLeaves()->GetEntriesFast();
    //loop on all the branches to find the branch with a buffer starting at offset
-   Bool_t status = kFALSE;
    TBranch *branch = 0;
    for (Int_t i=0;i<nleaves;i++) {
       TLeaf *leaf = (TLeaf*)fTree->GetListOfLeaves()->At(i);
@@ -121,6 +137,7 @@ Bool_t TTreeFilePrefetch::Register(Long64_t offset)
       Long64_t *entries = branch->GetBasketEntry();
       //we have found the branch. We now register all its baskets
       //from the requested offset to the basket below fEntrymax
+      Int_t ntb = 0;
       for (Int_t j=0;j<nb;j++) {
          if (branch->GetBasketSeek(j) == offset) {
             for (Int_t k=j;k<nb;k++) {
@@ -131,24 +148,26 @@ Bool_t TTreeFilePrefetch::Register(Long64_t offset)
                   return status;
                }
                TFilePrefetch::Prefetch(pos,len);
+               ntb++;
                status = kTRUE;
             }
-            if (gDebug > 0) printf("registering branch %s offset=%lld\n",branch->GetName(),offset);
+            if (gDebug > 0) printf("Entry: %lld, registering branch %s offset=%lld\n",fTree->GetReadEntry(),branch->GetName(),offset);
             return status;
          }
       }
    }
-   if (status && branch && gDebug > 0) printf("registering branch %s offset=%lld\n",branch->GetName(),offset);
+   if (status && branch && gDebug > 0) printf("Entry: %lld, registering branch %s offset=%lld\n",fTree->GetReadEntry(),branch->GetName(),offset);
    return status;
 }
 
 //_____________________________________________________________________________
-void TTreeFilePrefetch::SetEntryMax(Long64_t emax)
+void TTreeFilePrefetch::SetEntryRange(Long64_t emin, Long64_t emax)
 {
-   // Set the maximum entry number to be processed
+   // Set the minimum and maximum entry number to be processed
    // this information helps to optimize the number of baskets to read
    // when prefetching the branch buffers.
    
+   fEntryMin = emin;
    fEntryMax = emax;
 }
 
@@ -159,3 +178,15 @@ void TTreeFilePrefetch::SetTree(TTree *tree)
    
    fTree = tree;
 }
+
+//_____________________________________________________________________________
+void TTreeFilePrefetch::SetThreshold(Double_t t)
+{
+   // Static function to set fgThreshold
+   // A new basket will not be registered in the cache if
+   // the current (Tree entry < fEntryMin) > 100*fgThreshold
+   // so t is more or less the percentage of baskets read to be considered in the cache
+   // This algorithm eliminates branches where only a few baskets are processed
+   
+   fgThreshold = t;
+}
diff --git a/treeplayer/src/TTreePlayer.cxx b/treeplayer/src/TTreePlayer.cxx
index 02d9068bbdd19df2889c55470419367c68de1c52..4fdf2bd4eebd0f41f5a4ca3f2dbaadc1682ca6c5 100644
--- a/treeplayer/src/TTreePlayer.cxx
+++ b/treeplayer/src/TTreePlayer.cxx
@@ -1,4 +1,4 @@
-// @(#)root/treeplayer:$Name:  $:$Id: TTreePlayer.cxx,v 1.211 2006/06/05 20:30:28 brun Exp $
+// @(#)root/treeplayer:$Name:  $:$Id: TTreePlayer.cxx,v 1.212 2006/06/08 13:26:01 brun Exp $
 // Author: Rene Brun   12/01/96
 
 /*************************************************************************
@@ -2590,7 +2590,7 @@ Long64_t TTreePlayer::Process(TSelector *selector,Option_t *option, Long64_t nen
    TFile *curfile = fTree->GetCurrentFile();
    if (curfile && fTree->GetCacheSize() > 0) {
       TTreeFilePrefetch *tpf = (TTreeFilePrefetch*)curfile->GetFilePrefetch();
-      if (tpf) tpf->SetEntryMax(firstentry+nentries);
+      if (tpf) tpf->SetEntryRange(firstentry,firstentry+nentries);
       else fTree->SetCacheSize(fTree->GetCacheSize());
    }