TH2Poly::Interpolate or meshing surface

Dear all,
I would like to know if there is some existing code able to perform what i have in mind.
Basically i have some code with is generally building an optimal binning scheme in a 2D plane with TH2Poly. This gets filled with data/mc ratios and after that when i want to extract a weight i would like to interpolate among the bins.

If i understand correctly this is not possible with TH2Poly. Therefore i was trying to figure out if “given” an already existing TH2Poly there might be some way to get an interpolated TH2D with more fine grained bins, or in general anythin which can help to interpolate the TH2Poly bins.

Thanks in advance

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

To be fair, i can call TH2Poly::Interpolate, but the result makes always no sense, no matter what i call, i get back always 0 value, even if when i Draw("colz") i get a valid 2D histogram.

Yes it is clear from the doc:

sure, but somehow i was not getting that message when calling it, so i supposed that the TH2::Interpolate was called.
I am just trying to figure out if there is an approximate approach one could follow, for example , fill all bins and content in a TGraph2 and generate a histogram using the Deluanay triangulation…

TH2Poly and TGraph2D are very different objects. There is no direct bridge from one to the other. One easy thing you can try is to book a TH2F with a fine binning with the same limits as the TH2Poly, and you fill both: the TH2F and the TH2Poly. The TH2F might end up close to what you are looking for.

Dear @couet, I circumvent the issue doing the following :

TH2D * getHist( TH2Poly * histoPoly){
    TList* list = (TList*)histoPoly->GetBins();
    // list->Print();
    // for( auto el =  list->begin(); el != list->end(); ++el){
    TIter next(list);
    TObject* bin = 0;
    TGraph2D *dt = new TGraph2D();
    dt->SetTitle("Graph title; X axis title; Y axis title; Z axis title");
    int i = 0;
    while ((bin = next())){
        auto * myBin = static_cast<TH2PolyBin*>( bin) ; //->Print();
        // cout<<"-----------------------------"<<endl;
        // cout<< "x [ "<< myBin->GetXMin()<< " , "<< myBin->GetXMax()  << " ] "<< endl;
        // cout<< "y [ "<< myBin->GetYMin()<< " , "<< myBin->GetYMax()  << " ] "<< endl;

        auto x = (myBin->GetXMax() +  myBin->GetXMin() ) /2.;
        auto y = (myBin->GetYMax() +  myBin->GetYMin() ) /2.;
        cout<< " content = "<< myBin->GetContent() << endl;
        dt->SetPoint(i, x,y, myBin->GetContent());
    return (TH2D*)dt->GetHistogram();

This function basically loop over the TH2Poly bins and set points on a TGraph2D, then the GetHistogram function performs a sort of interpolation with Deluanay Triangles.
I do have an issue now, that TGrap2D::GetHistogram sets the boundaries of the resulting TH2D trimmed wrt the original TH2Poly. Do you know how one can force on a TGraph2D::GetHistogram to return something where the x-axis range and y-axis range can be set properly?

Thanks in advance

Here just an example for a TH2Poly ( which by luck happens to look like a TH2D )

Here what the function i posted spit out

My question is if there is a way to force the bin boundaries to be the same as the original TH2Poly.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.