27 Jul 2012 15:47
Adding Variable to existing Tree
Harinder Singh Bawa <Harinder.Singh.Bawa <at> cern.ch>
2012-07-27 13:47:48 GMT
2012-07-27 13:47:48 GMT
Hello experts,
I need help in understanding the problem. I am actually trying to copy input tree into New file with some addition of variables. I could successfully copy the tree to new file but When inside code, I wanted to use some variables for calculation like for.eg here I wanted
Number of Jets by calc size of jet_AntiKt6TopoEM_E, I am not able to call "jet_AntiKt6TopoEM_E" from input tree properly. And am getting 0. I tried to SetBranchAddress of "jet_AntiKt6TopoEM_E" but doesnt help!. Can anybody suggest where exactly I missing ??
******************************
I need help in understanding the problem. I am actually trying to copy input tree into New file with some addition of variables. I could successfully copy the tree to new file but When inside code, I wanted to use some variables for calculation like for.eg here I wanted
Number of Jets by calc size of jet_AntiKt6TopoEM_E, I am not able to call "jet_AntiKt6TopoEM_E" from input tree properly. And am getting 0. I tried to SetBranchAddress of "jet_AntiKt6TopoEM_E" but doesnt help!. Can anybody suggest where exactly I missing ??
******************************
****************
void copy()
{
TChain *oldtree = new TChain("qcd") ;
oldtree->Add("file1.root");
oldtree->Add("file2.root");
double nEvents = (int) oldtree->GetEntries();
oldtree->SetBranchStatus("*",1);
TFile *newfile = new TFile("CopyTree.root", "recreate");
TTree *newTree = oldtree->CopyTree("");
double RunNumber,jet_AntiKt6TopoEM_E;
for (Long64_t i=0;i<nentries;i++) {
oldtree->GetEntry(i);
oldtree->SetBranchAddress("RunNumber",&RunNumber);
oldtree->SetBranchAddress("jet_AntiKt6TopoEM_E",&jet_AntiKt6TopoEM_E);
unsigned int NJets=jet_AntiKt6TopoEM_E->size();
COUT<<NJets<<endl;//***************************
for(unsigned int i=0; i<NJets; i++)
{
COUNTER++;
}
}
newfile->cd();
newTree->AutoSave();
newfile->Close();
}
Thanks
void copy()
{
TChain *oldtree = new TChain("qcd") ;
oldtree->Add("file1.root");
oldtree->Add("file2.root");
double nEvents = (int) oldtree->GetEntries();
oldtree->SetBranchStatus("*",1);
TFile *newfile = new TFile("CopyTree.root", "recreate");
TTree *newTree = oldtree->CopyTree("");
double RunNumber,jet_AntiKt6TopoEM_E;
for (Long64_t i=0;i<nentries;i++) {
oldtree->GetEntry(i);
oldtree->SetBranchAddress("RunNumber",&RunNumber);
oldtree->SetBranchAddress("jet_AntiKt6TopoEM_E",&jet_AntiKt6TopoEM_E);
unsigned int NJets=jet_AntiKt6TopoEM_E->size();
COUT<<NJets<<endl;//***************************
for(unsigned int i=0; i<NJets; i++)
{
COUNTER++;
}
}
newfile->cd();
newTree->AutoSave();
newfile->Close();
}
Thanks
Harinder Singh
RSS Feed