I am trying to create an array of TTree branches. For those branches, I am trying to draw a TGraph. The reason for doing this is to write a code for drawing a TGraph onces and that will create as many TGraphs as of branches in TTree.
My code is as follows:
std::vectorstd::string treeNameVector; //In this I am storing all TTree from .root file
treeNameVector.push_back(“ABC”); // ABC,DEF,GHI… are different TTree in one .root file
TFile *f1 = new TFile(“Tree.root”);
TTree T1 = (TTree)f1->Get(treeNameVector.at(i).c_str());
TCanvas *c = new TCanvas(treeNameVector.at(i).c_str(), treeNameVector.at(i).c_str(), 0, 0, 1000, 1000);
TObjArray branches = new TObjArray(0); //For getting branches of different TTree’s
branches = T1->GetListOfBranches();
int nbranches = branches->GetEntries();
cout << "Number of Branches = " << nbranches << endl;
for (int i = 0; i < nbranches; ++i)
string branchname = ((TBranch)(*branches)[i])->GetName();
cout << "Branch Name = " << branchname << endl;
[color=#FF0000]// This works fine for only 1st TTree. But not working for other TTree as TObjArray is already filled with Branch name’s of 1st TTree. At the end of this loop I am using Deleting the TObjArray , So that it will work as a Dynamic array. But it is not woking.
//This will be useful if TTree have many branches e.g: above 500. Then insted of writing code for drawing a TGraph for all 500 branches will increase code length.[/color]
T1->Draw(branchname.at(i+1).c_str():branchname.at(i).c_str(), cut, “same”);
TGraph *gr = new TGraph(T1->GetSelectedRows(),T1->GetV2(), T1->GetV1());
TMultiGraph *mg = new TMultiGraph();
mg -> Add(gr);
[color=#FF0000]// I am trying to flush-off the TObjArray for the use of next TTree branches but it is not working. [/color]
If anybody have an idea of [color=#FF0000]how to use TObjArray to be work as a dynamic array[/color] then please guide me.