[ROOT] Re: drawing (& removing) regions of TH2's [ER] (PR#1030)

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Jul 20 2001 - 16:08:06 MEST


Hi Justin,

I had already several requests similar to yours.
I have implemented this functionality in the current development version in CVS.
The idea is to use the already existing graphical cut class TCutG.
You can create this cut in a macro (see example below) or interactively
with the ROOT graphics editor.
Below is the log I added to the CVS history describing the changes:

The THistPainter and TLego classes have been extended with 
new functions to draw selected regions of a 2-d histogram.
One can create one or more graphical cuts (TCutG objects)
and specify this (these) cuts in option string of the Draw
function. Example, assuming two graphical cuts with name
"cut1" and "cut2", one can do:
  h1.Draw("lego");
  h2.Draw("[cut1,-cut2],surf,same");
The second Draw will superimpose on top of the first lego plot
a subset of h2 using the "surf" option with:
 -all the bins inside cut1
 -all the bins outside cut2
Up to 16 cuts may be specified in the cut string delimited by "[..]"

Currently only the following drawing options are sensitive to 
the cuts option: col, box, scat, hist, lego, surf and cartesian 
coordinates only.

A set of new functions has been added in THistPainter:
    virtual Bool_t  IsInside(Int_t x, Int_t y);
    virtual Bool_t  IsInside(Double_t x, Double_t y);
    virtual Int_t   MakeCuts(char *cutsopt);

The MakeCuts function is called by THistPainter::MakeChopt to fill
the new THistpainter data members: fNcuts, fCutsOpt and fCuts.
The functions IsInside are called by the THistpainter functions
or the TLego functions.

Example using the file hsimple.root produced by $ROOTSYS/tutorials/hsimple.C

{
   gROOT->Reset();
   TCutG *mycut = new TCutG("mycut",8);
   mycut->SetVarX("");
   mycut->SetVarY("");
   mycut->SetTitle("Graph");
   mycut->SetFillColor(1);
   mycut->SetPoint(0,-0.646552,0.932203);
   mycut->SetPoint(1,-1.26437,0.105932);
   mycut->SetPoint(2,-0.574713,-1.10169);
   mycut->SetPoint(3,0.948276,-0.338983);
   mycut->SetPoint(4,1.07759,0.720339);
   mycut->SetPoint(5,-0.316092,-0.0847458);
   mycut->SetPoint(6,-0.45977,0.402542);
   mycut->SetPoint(7,-0.646552,0.932203);
   
   TFile f("hsimple.root")
   TH2F *hpxpy = (TH2F*)f.Get("hpxpy");
   hpxpy->SetMinimum(0);
   hpxpy->SetMaximum(180);
   hpxpy->SetFillColor(kBlue);
   hpxpy->DrawCopy("lego1");
   hpxpy->SetFillColor(kRed);
   hpxpy->Draw("same,surf1,[mycut]");
}

Rene Brun

jalbert@slac.stanford.edu wrote:
> 
> Full_Name: Justin Albert
> Urgency: minor
> 
> Dear ROOTers,
> 
>     It would be extremely nice to have a feature in which
> one could Draw() a histo but with only certain bins of
> the histo plotted (or certain bins removed).  The specific
> case is that we'd like to be able to draw a TH2F as a surface plot,
> but without a certain set of bins (the TH2F in our case
> is a fit, but there is an box-shaped area within the
> rectangle which is not part of the fit, but ROOT currently
> still must plot it anyway. See
> http://www.slac.stanford.edu/~jalbert/DstarD/07152001/dstarddatafitplot.gif
> -- the lower right-hand corner is not part of the fit
> [in this plot it is a region in which higher resonances
> can feed into the sideband and thus must be excluded],
> but ROOT must still plot it and thus it reduces
> the information content of the plot).  One can not
> merely set those bins to zero or to a negative number
> since the grid lines still slope down to the zero/negative
> area as if that were the actual content of the bins.
> 
>     It would be very nice if Draw() could take an argument
> representing a set of cuts, perhaps similar to
> the TTreeFormula syntax, and not plot any area which is
> cut out.
> 
> thanks,
> justin (for several members of the BaBar experiment)



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:52 MET