Superimposing many graphs using TMultiGraph (error in TGraphPainter)

I want to create and draw then many graphs (nChannels in this case). This is my code:

void CSectionOnEnergy( Float_t eMin, Float_t eMax, Int_t eBins = 100 )
{
    TMultiGraph* mg = new TMultiGraph();
    Int_t nChannels = (Int_t)CHANNEL::Object::GetSize();

    TGraph* gArray[nChannels]; 
    for( Int_t i = 0; i < nChannels; i++ )
    {
        gArray[i] = new TGraph();
    }

    Float_t cs;
    Float_t eCur = eMin;

    Float_t eStep = ( eMax - eMin ) / eBins;

    for ( Int_t id = 0; id < nChannels; id++ )
    {
        gArray[id]->SetMarkerStyle(id);
        gArray[id]->SetMarkerColor(id);
        
        for( Int_t n = 0; eCur < eMax; n++ )
        {
            cs = csection( eCur, id+1 ); 
            gArray[id]->SetPoint( n, eCur, cs );
            eCur += eStep;
        }
        mg->Add( gArray[id] );
    }
    if ( !gROOT->IsBatch() )
    {
        mg->Draw("AP");
    }
}

After running this script I get many identical errors:

Error in TGraphPainter::PaintGraph: illegal number of points (0)

What am I doing wrong?

Sorry. The problem was that I did not fill other graphs except the first one. How to delete this post?

Yes that’s messages from the TGraphs … they were empty. Good you found it yourself :slight_smile:

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