TGraph2DErrors* GetGraph(std::string fname)
{
    TGraph2DErrors* gr = 0;

    std::string fGrName = "mygraph";

    TFile *f = new TFile(fname.data());
    if (!f->IsOpen())
    {
        std::cerr << "Failed to open " << fname << std::endl;
        return gr;
    }

    f->ls();

    std::cout << "Enter name of graph : ";
    if (std::cin.peek()=='\n') std::cin.get();
    std::getline(std::cin, fGrName);

    f->GetObject(fGrName.data(), gr);
    if (gr!=NULL)
    {

        TGraph2DErrors* tgr = (TGraph2DErrors*) gr->Clone("mygraph_0");
        gr=tgr;
        gr->SetDirectory(0);
    }

    return gr;
}
TGraph2DErrors* GenerateRegionIntegratedSurface(TGraph2DErrors *gr,
                                          const ROOT::Math::IMultiGenFunction& func,
                                          std::vector<Regions>& regions)
{
    RegionIntegratorMultiDim Integrator;
    Integrator.SetFunction(func);

    TGraph2DErrors* mygr = new TGraph2DErrors(gr->GetN());
    mygr->SetDirectory(0);

    Double_t *fX = gr->GetX();
    Double_t *fY = gr->GetY();
    Double_t *fZ = gr->GetZ();

    Double_t v=0, err=0;

    Int_t n = std::count_if(fZ, fZ + gr->GetN(), std::bind2nd(std::greater<Double_t>(),0));
    std::cout << n << std::endl;

    UInt_t count = 0;
    std::cout << "\nGenerating the integrated surface";
    std::cout << "\n";
    boost::progress_display prg(n);

    for (Int_t i=0; i<gr->GetN() && i<regions.size(); i++)
    {
        if (fZ[i]==0) continue;

        regions[i] *= CLHEP::deg;

        v = Integrator.RegionIntegral(regions[i]);

        mygr->SetPoint(count,fX[i],fY[i],v);
        count++;
        ++prg;
    }

    std::cout << std::endl;
    return mygr;
}