TH2 with arbitrary bin shape

If it is done using using OpenGL it will be a new option in TGLHistPainter. It should not be done using the geometry package.

[quote]
TCutG object ? What can be gained if TCutG is used instead of TPolyLine ?
Do you think I’d just start by using TCutG instead of TPolyLine for the honeycomb ? [/quote]
That’s not for honeycomb. It is a generalization. TCutG has the tools to know if a value is inside or outside the cut. That’s why a TCutG is better.

Hello all,

I would like to know which methods of TH2 I need to override in the derived class so that I can fill bin contents via TTree::Draw. I do not intend to make a class of arbitrary bin shapes but would like to write a class inherited from TH1/TH2/TH3.

TSelectorDraw http://root.cern.ch/root/html/src/TSelectorDraw.cxx.html#E2MUpB seems to be the correct one which I should look. So what I need to do is to override

  • FillN for TH1-based class
  • Fill for TH2-based class
  • Fill for TH3-based class

right?

Hi,

I have to dig a little more into how I did it, and more experienced people can give you a better answer,
but I far as I can remember, the only thing you have to do is write the proper SetBinContent() method.

Hope it can help. Tomorrow I can post the sources of my code if you wish.

Best
Julien

Hi,

A priori, all you need to do is ‘use’ you class:MyClass *histo = new MyClass("somename",....); mytree->Draw("py:px>>somename");(assuming you overload the right methods of TH2)

Cheers,
Philippe.

Hello Julien and Philippe,

Thanks for your replies. I should have explained my situation in detail.

I am planning to write a library to handle FITS files (astronomical data format) in ROOT. Most of 2D images used in astronomy has their own coordinate system (WCS; world coordinate system) because celestial coordinates cannot be projected on 2D images without distortion. For example, pixels in a FITS image are indexed from 1 to N1 for x and 1 to N2 for y, where the total number of pixels is N1 x N2. However, if I use WCS which converts pixel coordinates (x, y) to (galactic longitude, galactic latitude), I need an automated coordinate conversion when using TTree::Draw.

Here is an example.

TNtuple nt("nt", "Celestial Gamma-ray Event List", "longitude:latitude:energy:time"); nt.Fill(.....); .... TFitsImage2D img; img.SetName("image"); nt.Draw("latitude:longitude>>image");

where, I suppose TFitsImage2D should have a wrapper like

TFitsImage2D::Fill(double x, double y, double w) { double pix[2]; Sky2Pix(x, y, pix); // a method which converts celestial coordinates to 2D pixel numbers TH2D::Fill(pix[0], pix[1], w); }
to calculate the correct pixel position from latitude and longitude.

Is this all the thing I have to write?

Very recently we have introduced a new class interfacing FITS files to ROOT graphics, thanks to Claudi Martinez.
Could you have a look at this class (see: root.cern.ch/root/html/TFITSHDU.html) and possibly
cooperate for further developments?

For Julien, you will be pleased to know that we are about to release a new histogram class TH2Poly with arbitrary bin shapes (hexagons, country maps, etc) and with rendering in the normal 2d pad, but also with GL.

Rene

Some examples…










Dear rooters,

This is great ! This will save (me) a lot of time, and the results look great too (way better that what I have been able to do).

As I post it yesterday, for information I will attach here the class I wrote, as it is now.
There is no much comments in it, but I have been using it for now few months and
it seems quite stable. It also have been improved for memory management and robustness by my colleagues here.

There is also analysis methods specific to the detector I am working with (see previous posts),
especially to fit tracks. This has directly nothing to do with pure TH2 with arbitrary bin shape coding, but I will keep them here FYI

As soon as the TH2Poly is out I think I will test it and probably make my TMayaHisto class inherits from it.

Best
Julien
TMayaHisto.h (9.16 KB)
TMayaHisto.cxx (49.7 KB)

Yes it will be good to merge your work with TH2Poly.
Note that I will be on holidays from tomorrow. I’ll be back on August 23rd.

Olivier,

Don’t worry, this will not be before mi-september, as least !

Best
J.

Dear Rooters,

I finally have time to test your great TH2Poly class.
My plan is to implement my specific methods to this more general class.

I however have some (small) troubles/questions :

  • I would like to access the points defining a given bin. How can I do that ?
  • The area of the bin is automatically calculated, but I do not think the barycenter is. Is it (easily) possible to implement this ? It will ease calculations and fit procedures.

This being said the migration is rather easy.

Thank you again for the help and the development of this new class.

Best
Julien

Use GetPolygon in TH2PolyBin. root.cern.ch/root/html/TH2PolyBin.html

If you have some code to provide we can add it.

Olivier,

[quote]Use GetPolygon in TH2PolyBin. root.cern.ch/root/html/TH2PolyBin.html
[/quote]

Yes, but then what can I do with the TObject* I obtained ? What methods can I use to get the list (array ?) of the points ?

I will as soon as it is written and tested.

Best
Julien

Look how it is used here: root.cern.ch/root/html/src/TH2Po … tml#XaZ4IB
The object is either a TGraph or a TMultiGraph.

Olivier,

Here is what I wrote :

Bool_t TMayaHisto::GetBinCenter(TH2PolyBin *bin,Double_t &Xg,Double_t &Yg){

   Int_t     gn;
   TObject *poly = bin->GetPolygon();
   Double_t *gx,*gy ;

   Xg = 0.,Yg = 0. ;

   if (poly->IsA() == TGraph::Class()) {
      TGraph *g = (TGraph*)poly;
      gn = g->GetN() ;
      if(gn<=0) return kFALSE ;

      gx = g->GetX();
      gy = g->GetY();

      for(Int_t i=0;i<gn;i++){
	Xg += (Double_t)gx[i];
	Yg += (Double_t)gy[i];
      }
      Xg /= gn;
      Yg /= gn;
      return kTRUE ;
   }
  

   return kFALSE ;
}

This being said I think it will more efficient to have the barycenter calculated when AddBin() is called and stored in private variables e.g. fCenterX and fCenterY , as fArea is.

Best
Julien

Hi Julien,

I suggest you make a proposal (some prototype, modification of TH2Poly).
Is it ok for you ?

Cheers,
Olivier

Hi Julien,

You send me an email via this forum. I see it in my CERN mail box but it does not show your email address, and I do not see the email in the forum mailbox either. So please send me a direct email at olivier.couet@cern.ch so I can answer you.

Cheers,
Olivier

Hi everybody,

I know, the last reply is over 8 years ago and the TH2Poly class is totally normal. But what I can not reproduce is the LEGO-plot using Honeycomb binning (shown by couet)
https://root-forum.cern.ch/uploads/default/original/2X/e/ea7c65d5d43b700b4e51afdc68e6666193f11edc.png

What I do is basically the following

gStyle->SetCanvasPreferGL(true);
TCanvas *can = new TCanvas(); 
// ...
for ( int i = 0; i < binID->size(); i++ ) {
  //set histogram bins
  int bin = binID->at(i);
  myEvtHisto->SetBinContent( bin, myEvtHisto->GetBinContent(bin) + Amp->at(i) );
}
myEvtHisto->Draw("GLLEGO");
can->Print("output.png");

the output is a flat LEGO-plot: always all bins 0 and z-range from -1 to 1. The xy-range is correct. I would appreciate if someone had an advice to solve this problem. Thanks in advance!

{
   gStyle->SetCanvasPreferGL(true);
   TH2Poly *hc = new TH2Poly();
   hc->Honeycomb(0,0,.1,25,25);
   TRandom ran;
   for (int i = 0; i<300; i++) hc->Fill(ran.Gaus(2.,1), ran.Gaus(2.,1));
   hc->Draw("gllego ");
}