Several graphs from tree

Hello,

I just started to learning root and i already stuck.

there is a problem: I need to make a data file with tree data and around 128 different graphs in it.

So, i can do data file with tree data and only 1 graphs ( i can’t find way to make cycle )

[code]#include <TGraph.h>
#include <TMath.h>
#include <TTree.h>
#include <string.h>

void basic2() {

TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
dir.ReplaceAll(“basic2.C”,"");
dir.ReplaceAll("/./","/");

TFile *f = new TFile(“data.root”,“RECREATE”); //create file data.root
TTree *T = new TTree(“tree”,“data from ascii file”);
Double_t nlines = T->ReadFile(Form("%soutampl.txt",dir.Data()),“cal:channel:amplitude:rms”);//create tree with cal:channel:amplitude:rms
printf(" found %lld points\n",nlines); //not needed so

//make graphs
tree->Draw(“amplitude:cal”,“channel==1”);
TGraph gr = new TGraph(tree->GetSelectedRows(),tree->GetV2(), tree->GetV1());
gr->SetName(“myGraph”);
gr->SetMarkerStyle(2);
gr->Draw("AC
");
gr->Write();

T->Write();

}[/code]

In this line “tree->Draw(“amplitude:cal”,“channel==1”);” in cycle, i need to switch number of channel from 0 to 127

how can i to do it or i should make different way?
Thanks
Mikhail.

Try: for (Int_t i = 0; i < 128; i++) { TString selection = TString::Format("channel==%d", i); // http://root.cern.ch/root/html/TTree.html#TTree:Draw@2 tree->Draw("amplitude:cal", selection); // an unbinned 2-d scatter-plot gPad->Modified(); gPad->Update(); // make sure it's really (re-)drawn #if 1 /* 0 or 1 */ TGraph *gr = (TGraph *)gPad->GetPrimitive("Graph")->Clone(); // 2D #else /* 0 or 1 */ TGraph *gr = new TGraph(tree->GetSelectedRows(), tree->GetV2(), tree->GetV1()); #endif /* 0 or 1 */ gr->SetNameTitle(TString::Format("myGraph_%d", i), selection); gr->SetMarkerStyle(2); // gr->Draw("AC*"); gr->Write(); }

[quote=“Wile E. Coyote”]Try: for (Int_t i = 0; i < 128; i++) { TString selection = TString::Format("channel==%d", i); // http://root.cern.ch/root/html/TTree.html#TTree:Draw@2 tree->Draw("amplitude:cal", selection); // 2-d scatter-plot gPad->Modified(); gPad->Update(); // make sure it's really (re-)drawn #if 1 /* 0 or 1 */ TGraph *gr = (TGraph *)gPad->GetPrimitive("Graph")->Clone(); // 2D #else /* 0 or 1 */ TGraph *gr = new TGraph(tree->GetSelectedRows(), tree->GetV2(), tree->GetV1()); #endif /* 0 or 1 */ gr->SetNameTitle(TString::Format("myGraph_%d", i), selection); gr->SetMarkerStyle(2); // gr->Draw("AC*"); gr->Write(); }[/quote]

Thanks, was really helpful for me. (:
but like this:

for (Int_t i = 0; i < 127; i++) { TString condition = TString::Format("channel==%d", i); tree->Draw("amplitude:cal", condition); TGraph *gr = new TGraph(tree->GetSelectedRows(),tree->GetV2(), tree->GetV1()); gPad->Modified(); gPad->Update(); // make sure it's really (re-)drawn gr->Draw("AC*"); gr->SetMarkerStyle(2); gr->Write(); }