Re: Error in <TTree::SetBranchStatus>: unknown branch

From: Axel Naumann <Axel.Naumann_at_cern.ch>
Date: Mon, 2 Aug 2010 14:35:46 +0200


Hi,

you can use TTree::GetListOfBranches()->FindObject("branchname") to determine whether the tree has a branch called branchname:

if (tree->GetListOfBranches()->FindObject("jet.px"))   b_jet_px = tree->GetBranch("jet.px")
else
  b_jet_px = 0;
...
if (b_jet_px) tree->SetBranchStatus("jet.px"...

Cheers, Axel.

Harinder Singh Bawa wrote on 08/02/2010 01:13 PM:
> Dear Axel, Philips,
>
> Thanks for the reply but I figured out that the branches are not in my
> input rootfiles because these input files are older and my code is
> according to newer one.
> So now my question is
> I need to analyse the rootfiles(all some with more variables and some
> with less variables). What needs to be done so that I dont get erorr
> like variables not found.
>
> I did MakeClass with newer one and so I am having more variables defined
> in my .h file. Now If I run to older file, it is complaiing that these
> variables are unknown branches. I want to run on both older and newer files.
>
> Kindly suggest
>
>
>
>
> Harinder
> *From: *"Philippe Canal" <pcanal_at_fnal.gov>
> *To: *"Harinder Singh Bawa" <hbawa_at_csufresno.edu>
> *Cc: *"roottalk" <roottalk_at_cern.ch>
> *Sent: *Friday, July 30, 2010 5:22:18 PM
> *Subject: *Re: [ROOT] Error in <TTree::SetBranchStatus>: unknown branch
>
> Hi,
>
> It is plausible that you do not have any branch with exactly those
> names. You may want to try:
>
> fChain->SetBranchStatus("L2_xe12*",1);
>
> or double check the names (via mytree->Print()).
>
> Cheers,
> Philippe.
>
>
> On 7/30/10 7:55 AM, Harinder Singh Bawa wrote:
>
> Dear Root Experts,
>
> 1. I need to understand 2 things. First I opened a rootfile and made
> .C and .h using MakeClass. I am expecting that MakeClass
> incorporated all the branch addresses and variables. But when I run
> , I am getting the following error.
>
> Error in <TTree::SetBranchStatus>: unknown branch -> trig_EF_ph
> Error in <TTree::SetBranchStatus>: unknown branch -> L2_xe12
> Error in <TTree::SetBranchStatus>: unknown branch -> xxxxxxxxx(blah
> blah)
> Error in <TTree::SetBranchStatus>: unknown branch -> xxxxxxxxx
> Error in <TTree::SetBranchStatus>: unknown branch -> xxxxxxxxx
> Error in <TTree::SetBranchStatus>: unknown branch -> xxxxxxxxx
> Error in <TTree::SetBranchStatus>: unknown branch -> xxxxxxxxx
>
> What needs to be done ? The code is running but I want to get rid of it
>
> 2. I did something in my .C file as
> fChain->SetBranchStatus("*",0);
>
> if ( stream_analyzed==TYPE_DATA) {
> fChain->SetBranchStatus("RunNumber",1);
> fChain->SetBranchStatus("lbn",1);
> }
> fChain->SetBranchStatus("L1_EM10",1);
> fChain->SetBranchStatus("vxp_nTracks",1);
> fChain->SetBranchStatus("MET_Goodness_N90Cells_Jet",1);
> fChain->SetBranchStatus("MET_Goodness_PtEM_Jet",1);
> fChain->SetBranchStatus("MET_Goodness_N90Cells_Jet",1);
> fChain->SetBranchStatus("MET_Goodness_HECf_Jet",1);
> fChain->SetBranchStatus("MET_Goodness_QualityFrac_Jet",1);
> fChain->SetBranchStatus("MET_Goodness_EMFraction_Jet",1);
> fChain->SetBranchStatus("MET_Goodness_Timing_Jet",1);
> fChain->SetBranchStatus("el_n",1);
> fChain->SetBranchStatus("el_cl_eta",1);
> fChain->SetBranchStatus("el_cl_phi",1);
> fChain->SetBranchStatus("el_cl_pt",1);
> fChain->SetBranchStatus("el_author",1);
> fChain->SetBranchStatus("el_loose",1);
> fChain->SetBranchStatus("el_medium",1);
> fChain->SetBranchStatus("el_tightIso",1);
> fChain->SetBranchStatus("el_isEM",1);
> fChain->SetBranchStatus("el_expectHitInBLayer",1);
> fChain->SetBranchStatus("MET_LocHadTopo_et",1);
> fChain->SetBranchStatus("MET_LocHadTopo_phi",1);
>
> In order to read only those variables which are of my interest. I
> thought , it will read only the above variables and branches and I
> should not get the errors as pointed out in 1, because it is not
> reading now all the branches. But I think It is reading but taking
> only those which are defined above. Am I right?
>
>
>
> If yes,
> Then My question is same for both points. How to get rid of the errors.
>
> thanks
>
>
>
>
>
>
>
> Harinder Singh Bawa
> California State University Fresno
> Alternative email:- bawa_at_cern.ch
>
> Office:-
> CERN B591-R-024 CSU Fresno:- Science II Room326
> Phone:- +41-22-767-78187 Telephone:- +1-559-278-5802
> CERN Mobile:- 0764878721
> Res:- 0033-457055309
>
Received on Mon Aug 02 2010 - 14:35:56 CEST

This archive was generated by hypermail 2.2.0 : Mon Aug 02 2010 - 23:50:01 CEST