Problem with SetBranchStatus

Hello all,

I am trying to write a tree with some branches.
e.g of how I am defining a branch:
myTree->Branch(“pt”,&pt,“pt/D”);

I want one of them to be filled only under certain conditions.

So I do myTree->SetBranchStatus(“pt”,0) whenever that condition is false and I set the status to 1 whenever the condition is true and then I do
myTree->Fill();

I have seen that even if the status of this branch is set to 0, if I print
the values of the local tree variable i.e. cout<<pt<<endl;
it gives some values.When I saw the plot, I found that those values(when the brstatus is 0) are filled inside it.

What is it that I am missing?
Could someone help me?

I have another query:
If I check the Entries of this branch from the plot, then do
I expect it to be equal to the number of times its status is set to 1
or the number of times myTree->Fill() is executed?

Thanks for any suggestions,
Best Regards,
Shilpi Jain

[quote]What is it that I am missing? [/quote]The BranchStatus concerns only reading back.

When filling, all branches must be equalling filled otherwise you are losing the synchronization of the branches. (I.e. if your attempt had succeeded, you would have lost all possibility of correlating correctly the pt with the other branches (event by event)).

The only way to have an optional branch is to use a container (array, vector, etc). For example you could use

vector<double> ptarr; myTree->Branch("pt",&ptarr) .... loop over events ptarr.clear(); if (!condition) { ptarr.push_back(ptvalue); } myTree->Fill(); }

Cheers,
Philippe.

Thanks much for your reply.
I tried this:

vector<double> ptarr; myTree->Branch("pt","std::vector<double>",&ptarr) for(int ievent = 0; ievent<nevent;ievent++) { ptarr.clear(); if (!condition) { ptarr.push_back(ptvalue); } //end of if myTree->Fill(); } //end of for

but its giving the problem of segmentation violation whenever myTree->Fill() is executed.

Also,
Somehow myTree->Branch(“pt”,&ptarr) is not working! I tried compiling this on lxplus
but it didn’t compile. It gave an error like :
===============ERROR==============================================
error: invalid conversion from std::vector<double, std::allocator<double> >*' toInt_t’
error: initializing argument 2 of `virtual Int_t TTree::Branch(const char*, Int_t, Int_t)’

Best Regards,
Shilpi

Thanks much for your reply.
I tried this:

vector<double> ptarr; myTree->Branch("pt","std::vector<double>",&ptarr) for(int ievent = 0; ievent<nevent;ievent++) { ptarr.clear(); if (!condition) { ptarr.push_back(ptvalue); } //end of if myTree->Fill(); } //end of for

but its giving the problem of segmentation violation whenever myTree->Fill() is executed.

Also,
Somehow myTree->Branch(“pt”,&ptarr) is not working! I tried compiling this on lxplus
but it didn’t compile. It gave an error like :
===============ERROR==============================================
error: invalid conversion from std::vector<double, std::allocator<double> >*' toInt_t’
error: initializing argument 2 of `virtual Int_t TTree::Branch(const char*, Int_t, Int_t)’

Best Regards,
Shilpi

You did not specify which version of ROOT you use. In thsi case we assume that you use the latest version 5.24. If this is not the case, please upgrade to v5.24.

Rene

On lxplus I found that the root version is 5.18

Thanks,
Shilpi

Hi,
How can I change my root version on lxplus machine?
The latest version which it shows is v5.22.

Thanks,
Shilpi

Hi,

to setup the 32bit version of ROOT v5.24 run from the shell prompt

. /afs/cern.ch/sw/lcg/app/releases/ROOT/5.24.00/slc4_ia32_gcc34/root/bin/thisroot.sh 

for (ba)sh and

source /afs/cern.ch/sw/lcg/app/releases/ROOT/5.24.00/slc4_ia32_gcc34/root/bin/thisroot.csh 

for (t)csh.

Cheers, Axel.

Hi,
Thanks everyone for helping me.
I could upgrade to v5.24 and now I am not getting any compilation error or segmentation
violation.

Best Regards,
Shilpi