Ntuple as an array?

So i am trying to plot 64 graphs that are the same format at the same time, i wonder i can define my ntuple as an array to make that work? I don’t know if it is a dumb question, i appreciate any input. i am fairly new to this thing. thanks guy.

I think your question is too vague for us to answer properly. Can you show some code/pseudocode explaining what you want to do?

The only thing I can think of for “define ntuple as an array” is when you ntuple->Draw(“x:y”), you can then do ntuple->GetV1(), GetV2() to get arrays of the values that were used in the drawing.

Jean-François

Ok here is part of my code that doesn’t work, I hope this helps to clarify:
I don’t really know how else to do it, so i just do it with brute force. I encounter an error though, I think it won’t let me write gr[i] as an array<–thats what I meant. I have tried doing the same thing with TH1F and it works though.

Here is the error message: Error: Symbol TGraphsErrors is not defined in current scope gaintest.c:26:
Error: Symbol gr[64] is not defined in current scope gaintest.c:26:
(const int)0
*** Interpreter error recovered ***

#include <stdio.h>
#include “TFile.h”
#include “TTree.h”
#include “TGraphErrors.h”
#include “TCanvas.h”

void gaintest(void)
{
const char *data_file = “gain.txt”;
TFile *f =TFile::Open(gain_file, “RECREATE”);
const char *gain_file = “gain.root”;

TTree *ntuple1 = new TTree("ntuple1", "data from ascii file");
ntuple1->ReadFile(data_file, "date1/f:c1/f:c2/f:c3/f:c4/f:c5/f:c6/f:c7/f:c8/f:c9/f:c10/f:c11/f:c12/f:c13/f:c14/f:c15/f:c16/f:c17/f:c18/f:c19/f:c20/f:c21/f:c22/f:c23/f:c24/f:c25/f:c26/f:c27/f:c28/f:c29/f:c30/f:c31/f:c32/f:c33/f:c34/f:c35/f:c36/f:c37/f:c38/f:c39/f:c40/f:c41/f:c42/f:c43/f:c44/f:c45/f:c46/f:c47/f:c48/f:c49/f:c50/f:c51/f:c52/f:c53/f:c54/f:c55/f:c56/f:c57/f:c58/f:c59/f:c60/f:c61/f:c62/f:c63/f:c64/f"); //
ntuple1->Write();

//Declare the TGraphErrors objects
TGraphsErrors *gr[64];

    gr[1] = new TGraphErrors(data_file, "%lg %lg");
    gr[2] = new TGraphErrors(data_file, "%lg %*s %lg");
    gr[3] = new TGraphErrors(data_file, "%lg %*s %*s %lg");
gr[4] = new TGraphErrors(data_file, "%lg %*s %*s %*s %lg");
gr[5] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s%lg");
gr[6] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s%lg");
gr[7] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %lg");
gr[8] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %lg");
gr[9] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[10] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[11] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[12] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[13] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[14] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[15] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[16] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[17] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[18] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[19] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[20] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[21] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[22] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[23] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[24] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[25] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[26] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[27] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[28] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[29] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[30] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[31] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[32] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[33] = new TGraphErrors(data_file, "%lg %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[34] = new TGraphErrors(data_file, "%lg %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[35] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[36] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[37] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[38] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[39] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[40] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[41] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[42] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[43] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[44] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[45] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[46] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[47] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[48] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[49] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[50] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[51] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[52] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[53] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[54] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[55] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[56] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[57] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[58] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[59] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[60] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[61] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[62] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s  %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[63] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");
gr[64] = new TGraphErrors(data_file, "%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg");

// gr[i] = new TGraphErrors(data_file, “%lg %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lg”);

for (i=64; i<64, i++){
gr[i]->SetNameTitle("gr1", "Electronic Gain vs Time;date;Gain");
gr[i]->SetLineColor(kRed);
gr[i]->SetLineWidth(4);
gr->SetMarkerColor(kBlack);
gr->SetMarkerStyle(21);
//gr1->GetXaxis->SetLimits(1,365);
gr->Write();
}

// TGraphErrors *gr2 = new TGraphErrors(data_file, “%lg %*s %*s %lg”);
// gr2->SetNameTitle(“gr1”, “Electronic Gain vs Time;date;Gain”);
// gr2->SetLineColor(kRed);
// gr2->SetLineWidth(4);
// gr2->SetMarkerColor(kBlack);
// gr2->SetMarkerStyle(21);
// //gr1->GetXaxis->SetLimits(1,365);
// gr2->Write();

delete f;
TCanvas *c1 = new TCanvas("c1", "A Simple Graph Example", 200, 10, 700, 500);
c1->SetGrid();
c1->DrawFrame(0,0,40,0.0000000000001);
for (i=64; i<64, i++){
    gr[i]->Draw("ALP");}
c1->Modified(); c1->Update();

}

//

I can attach the TXT file if anyone needs it, but it is just
1 x1,x2,x3,x4…x64
2 y1,y2,y3…y64



64…

where x,y are just numbers in format of xx.xx

Once again you are not describing what you are trying to do. What kind of plot are you trying to obtain from this? It’s hard to help because your C++ code doesn’t seem to make a lot of sense, but you don’t describe what you think it’s supposed to be doing.

A few things I noticed looking at your code:

  • It’s TGraphErrors, not TGraphsErrors. That’s what your first error message is saying: “Symbol TGraphsErrors is not defined…”
  • From reading the documentation of the TGraphErrors constructor (here http://root.cern.ch/root/html/TGraphErrors.html#TGraphErrors:TGraphErrors@8) I can’t tell what you expect to happen from the long format strings. I guess you are trying to skip columns, but that’s only described in TGraph, not TGraphErrors. Probably that’s a mistake in the documentation, but it’s worth checking: does it work for TGraph? Does %*s work for a simpler example?
  • Why do you make a TTree with the ascii file and then write this giant pyramid to make your graphs? What is the TTree for?

A few other notes: please use the forum code blocks to paste code. You click on the button that says “Code” above the text box and put your code in between the blocks. This will make reading your code easier. You should also attach your code file and data file, even if it seems silly. Are you expecting me to generate a big ascii file myself with the right formats to figure out if your code works?

Jean-François