Harinder Singh Bawa | 27 Jul 2012 15:47
Picon
Picon

Adding Variable to existing Tree

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 ??

******************************
****************
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

Axel Naumann | 30 Jul 2012 10:09
Picon
Picon

Re: Adding Variable to existing Tree

Hi,

You cannot call size() on a double. Compile your code using .x MyCode.C+ 
(note the plus in the end) and fix all errors. If it then still fails 
please let us know.

Axel

On 07/27/2012 03:47 PM, Harinder Singh Bawa wrote:
> 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 <http://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
>
> Harinder Singh
>

Harinder Singh Bawa | 30 Jul 2012 16:26
Picon

Re: Adding Variable to existing Tree

Hi Axel,

Thanks for your comment. I actually switched to old way to generate class i.e using MakeClass. In that way, I dont need to define each classes individually. But Now, I got another set of problem. When I compile it runs fine but when I run , it runs upto 12k events and then crash.(seg fault)

If I see, Line 148 of the code is giving me problem. But dont know why?

I am just trying to add few variables to the copied tree.

Am attaching code, Could you tell if I am doing wrong somewhere.


Harinder



On Mon, Jul 30, 2012 at 10:09 AM, Axel Naumann <Axel.Naumann <at> cern.ch> wrote:
Hi,

You cannot call size() on a double. Compile your code using .x MyCode.C+ (note the plus in the end) and fix all errors. If it then still fails please let us know.

Axel


On 07/27/2012 03:47 PM, Harinder Singh Bawa wrote:
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 <http://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

Harinder Singh




Attachment (NewTree.C): text/x-csrc, 5829 bytes
Attachment (NewTree.h): text/x-chdr, 26 KiB
Axel Naumann | 1 Aug 2012 10:40
Picon
Picon

Re: Adding Variable to existing Tree

Hi,

You are not guaranteed to set indexSJet for all events. Set it to -1 
within the event loop before analyzing the event (you only do that 
before the event loop); check that it's != -1 before you use it as an index.

You call
fChain->SetMakeClass(1);
but pass a vector<xyz> pointers to SetBranchAddress(); that won't work.

Cheers, Axel.

On 07/30/2012 04:26 PM, Harinder Singh Bawa wrote:
> Hi Axel,
>
> Thanks for your comment. I actually switched to old way to generate
> class i.e using MakeClass. In that way, I dont need to define each
> classes individually. But Now, I got another set of problem. When I
> compile it runs fine but when I run , it runs upto 12k events and then
> crash.(seg fault)
>
> If I see, Line 148 of the code is giving me problem. But dont know why?
>
> I am just trying to add few variables to the copied tree.
>
> Am attaching code, Could you tell if I am doing wrong somewhere.
>
>
> Harinder
>
>
>
> On Mon, Jul 30, 2012 at 10:09 AM, Axel Naumann <Axel.Naumann <at> cern.ch
> <mailto:Axel.Naumann <at> cern.ch>> wrote:
>
>     Hi,
>
>     You cannot call size() on a double. Compile your code using .x
>     MyCode.C+ (note the plus in the end) and fix all errors. If it then
>     still fails please let us know.
>
>     Axel
>
>
>     On 07/27/2012 03:47 PM, Harinder Singh Bawa wrote:
>
>         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 <http://for.eg>
>         <http://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
>
>         Harinder Singh
>
>
>
>


Gmane