'How to draw new graph with new point? ROOT Cern

I wanted to ask for a information. I am studying ROOT. I have 100 files and each file has 9 columns. I need to take the x data of the first column and for every other y the relative values. using the push_back method i create the vectors X and Y[8].

Now to normalize it, I need to take the smallest value among the elements of X and translate all the points and make a graph with all the points translated.

I wanted to ask where I am going wrong.

M= 8 columns I = 100 file with 9 columns-- 1 for X and 8 for Y — for (int i=0; i<N; i++){ etc…

int npoints = (int)X.size();
        
        
            for (int k=0; k<M; k++) {
                
                g[i][k]= new TGraph();
                g[i][k]->SetNameTitle( Form("graphic_name_%d_%d",i,k), Form("graphic_name_ %d_%d",i,k) );
                
            }
        
        
              for (int p=0; p<M; p++) {
            
                    
                    for( int b=0; b<npoints; b++){
                    
                       float a=X[0];
                        double t;
                       
                        t=b-a;
                        
                        g[i][p]->SetPoint(b,X[t],Y[p][t]);
                    
                }
            }

please,can you help me? thanks



Solution 1:[1]

This code snippet might give you some ideas on how to approach your problem:

#define NFILES 100
#define NROWS 20
#define NCOLUMNS 9

void graphs()
{
    // Create some fake data
    float data[NFILES][NROWS][NCOLUMNS];

    for (int k=0; k<NFILES; k++) {
        for (int i=0; i<NROWS; i++) {
            for (int j=0; j<NCOLUMNS; j++) {
                data[k][i][j] = k*10+i*2.5+j*0.01;
            }
        }
    }

    // Allocate graphs
    TGraph* graphs[NFILES][NCOLUMNS-1];
    for (int k=0; k<NFILES; k++) {
        for (int j=0; j<NCOLUMNS-1; j++) {
            graphs[k][j]= new TGraph();
            graphs[k][j]->SetNameTitle( Form("graphic_name_%d_%d",k,j), Form("graphic_name_ %d_%d",k,j) );
        }
    }

    // Fill graphs
    for (int k=0; k<NFILES; k++) {
        const float a = data[k][0][0];
        for (int j=0; j<NCOLUMNS-1; j++) {
            for( int i=0; i<NROWS; i++) {
                graphs[k][j]->SetPoint(i,data[k][i][0]-a,data[k][i][j+1]);
            }
        }
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ferdymercury