From 868c504a6622b3dbd7b13ebb80af1a3f16485ab9 Mon Sep 17 00:00:00 2001
From: Olivier Couet <Olivier.Couet@cern.ch>
Date: Thu, 2 Dec 2010 13:27:51 +0000
Subject: [PATCH] - New Fill method:  Fill(const char* name, Double_t w);

git-svn-id: http://root.cern.ch/svn/root/trunk@37177 27541ba8-7e3a-0410-8455-c3a389f83636
---
 hist/hist/inc/TH2Poly.h   |  6 ++---
 hist/hist/src/TH2Poly.cxx | 47 ++++++++++++++++++++++++++++++---------
 2 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/hist/hist/inc/TH2Poly.h b/hist/hist/inc/TH2Poly.h
index 97100ee3461..8b31c1f8d67 100644
--- a/hist/hist/inc/TH2Poly.h
+++ b/hist/hist/inc/TH2Poly.h
@@ -84,14 +84,14 @@ public:
    void        Draw(Option_t *option="");
    Int_t       Fill(Double_t x,Double_t y);
    Int_t       Fill(Double_t x,Double_t y, Double_t w);
+   Int_t       Fill(const char* name, Double_t w);
    void        FillN(Int_t ntimes, const Double_t* x, const Double_t* y, const Double_t* w, Int_t stride = 1);
-   Int_t       FindBin(Double_t x, Double_t y, Double_t z = 0);
    Int_t       Fill(Double_t){return -1;}                              //MayNotUse
-   Int_t       Fill(const char*, Double_t){return -1;}                 //MayNotUse
    Int_t       Fill(Double_t , const char *, Double_t){return -1;}     //MayNotUse
    Int_t       Fill(const char *, Double_t , Double_t ){return -1;}    //MayNotUse
    Int_t       Fill(const char *, const char *, Double_t ){return -1;} //MayNotUse
    void        FillN(Int_t, const Double_t*, const Double_t*, Int_t){return;}  //MayNotUse
+   Int_t       FindBin(Double_t x, Double_t y, Double_t z = 0);
    TList      *GetBins(){return fBins;}                                // Returns the TList of all bins in the histogram
    Double_t    GetBinContent(Int_t bin) const;
    Double_t    GetBinContent(Int_t, Int_t) const {return 0;}           //MayNotUse
@@ -127,7 +127,7 @@ protected:
    Double_t fOverflow[9];       //Overflow bins
    Int_t    fCellX;             //Number of partition cells in the x-direction of the histogram
    Int_t    fCellY;             //Number of partition cells in the y-direction of the histogram
-   Int_t    fNCells;            //Number of partition cells: fCellX*fCellY 
+   Int_t    fNCells;            //Number of partition cells: fCellX*fCellY
    TList   *fCells;             //[fNCells] The array of TLists that store the bins that intersect with each cell
    Double_t fStepX, fStepY;     //Dimensions of a partition cell
    Bool_t  *fIsEmpty;           //[fNCells] The array that returns true if the cell at the given coordinate is empty
diff --git a/hist/hist/src/TH2Poly.cxx b/hist/hist/src/TH2Poly.cxx
index 1a4c8f8348a..b656c5a5b7e 100644
--- a/hist/hist/src/TH2Poly.cxx
+++ b/hist/hist/src/TH2Poly.cxx
@@ -84,12 +84,12 @@ The following very simple macro shows how to build and fill a <tt>TH2Poly</tt>:
 {
    TH2Poly *h2p = new TH2Poly();
 
-   Double_t x1[] = {0, 5, 5};  
-   Double_t y1[] = {0, 0, 5};  
-   Double_t x2[] = {0, -1, -1, 0}; 
-   Double_t y2[] = {0, 0, -1, -1}; 
-   Double_t x3[] = {4, 3, 0, 1, 2.4}; 
-   Double_t y3[] = {4, 3.7, 1, 4.7, 3.5}; 
+   Double_t x1[] = {0, 5, 5};
+   Double_t y1[] = {0, 0, 5};
+   Double_t x2[] = {0, -1, -1, 0};
+   Double_t y2[] = {0, 0, -1, -1};
+   Double_t x3[] = {4, 3, 0, 1, 2.4};
+   Double_t y3[] = {4, 3.7, 1, 4.7, 3.5};
 
    h2p->AddBin(3, x1, y1);
    h2p->AddBin(3, x2, y2);
@@ -109,20 +109,20 @@ The partitioning algorithm forms an essential part of the <tt>TH2Poly</tt>
 class. It is implemented to speed up the filling of bins.
 <p>
 With the brute force approach, the filling is done in the following way:  An
-iterator loops over all bins in the <tt>TH2Poly</tt> and invokes the 
+iterator loops over all bins in the <tt>TH2Poly</tt> and invokes the
 method <tt>IsInside()</tt> for each of them.
 This method checks if the input location is in that bin. If the filling
 coordinate is inside, the bin is filled. Looping over all the bin is
-very slow. 
+very slow.
 <p>
 The alternative is to divide the histogram into virtual rectangular regions
-called "cells". Each cell stores the pointers of the bins intersecting it. 
+called "cells". Each cell stores the pointers of the bins intersecting it.
 When a coordinate is to be filled, the method finds which cell the coordinate
 falls into. Since the cells are rectangular, this can be done very quickly.
 It then only loops over the bins associated with that cell.
 <p>
 The addition of bins to the appropriate cells is done when the bin is added
-to the histogram. To do this, <tt>AddBin()</tt> calls the 
+to the histogram. To do this, <tt>AddBin()</tt> calls the
 <tt>AddBinToPartition()</tt> method.
 This method adds the input bin to the partitioning matrix.
 <p>
@@ -546,7 +546,7 @@ Int_t TH2Poly::Fill(Double_t x, Double_t y, Double_t w)
 
          SetBinContentChanged(kTRUE);
 
-         return 0;
+         return bin->GetBinNumber();
       }
    }
 
@@ -555,6 +555,31 @@ Int_t TH2Poly::Fill(Double_t x, Double_t y, Double_t w)
 }
 
 
+//______________________________________________________________________________
+Int_t TH2Poly::Fill(const char* name, Double_t w)
+{
+   // Increment the bin named "name" by w.
+
+   TString sname(name);
+
+   TIter    next(fBins);
+   TObject  *obj;
+   TH2PolyBin *bin;
+
+   while ((obj = next())) {
+      bin = (TH2PolyBin*) obj;
+      if (!sname.CompareTo(bin->GetPolygon()->GetName())) {
+         bin->Fill(w);
+         fEntries++;
+         SetBinContentChanged(kTRUE);
+         return bin->GetBinNumber();
+      }
+   }
+
+   return 0;
+}
+
+
 //______________________________________________________________________________
 void TH2Poly::FillN(Int_t ntimes, const Double_t* x, const Double_t* y,
                                const Double_t* w, Int_t stride)
-- 
GitLab