Very weird things happening with TChain

Hi,

I have two root files which have same tree name and same branch name (only one branch). Most of the leaves inside the branches in both root files have same name except few of them.

I am processing both root files in one script file. If I access leaves with the same name in both files then there is no problem. But if I try to access the leaves with different name then one of the leaves can’t be accessed. Here is a simplified code:

int main(int argc, char** argv)
{
    readChain1();
    cout << "--------------------------------------" << endl;
    readChain2();
}

void readChain1()
{
    TChain *chain = new TChain("cmeEvent");
    chain->Add("test1.root");
    double area;
    TBranch *b_cme_area;

    chain->SetMakeClass(1);
    chain->SetBranchStatus("*", 0);
    chain->SetBranchStatus("area", 1);
    chain->SetBranchAddress("area", &area, &b_cme_area);

    for(int i=0; i<chain->GetEntries(); i++) {
        chain->GetEntry(i, 0);
        if(TMath::IsNaN(area)) continue;
        cout << area << endl;
    }
    delete chain;
    chain = 0; b_cme_area = 0;
}

void readChain2()
{
    TChain *chain = new TChain("cmeEvent");
    chain->Add("test2.root");
    double eccentPart;
    TBranch *b_cme_eccentPart;

    chain->SetMakeClass(1);
    chain->SetBranchStatus("*", 0);
    chain->SetBranchStatus("eccentPart", 1);
    chain->SetBranchAddress("eccentPart", &eccentPart, &b_cme_eccentPart);

    for(int i=0; i<chain->GetEntries(); i++) {
        chain->GetEntry(i, 0);
        if(TMath::IsNaN(eccentPart)) continue;
        cout << eccentPart << endl;
    }
    delete chain;
    chain = 0; b_cme_eccentPart = 0;
}
~

Here readChain2() can’t access the leaf, it prints 6.9144e-310 which is not because I have checked it by opening the file with browser. Could anybody point me out where I am doing wrong?

Thanks.

I have attached sample root files here.

Thanks.
test1.root (6.0 KB)
test2.root (6.0 KB)

Does anybody like to make a comment on this?

try

        if(b_cme_area == nullptr || TMath::IsNaN(area)) continue;
.......
        if(b_cme_eccentPart == nullptr || TMath::IsNaN(eccentPart)) continue;
.......

Thanks. Still same problem.

Can you provide small version of your files so that we can reproduce the problem?

Sorry for the late reply. The attached code (in the 1st submit) with the attached files (test1.root and test2.root in 2nd reply) will reproduce the problem.

Thanks.

Hi manoj,
I look at your code but I wasn’t able to solve your problem.

By the way, I noticed a very weird thing.If you call first readChain2() and then readChain1() everything seems fine.

I don’t know if this can help you in some way,

Cheers,
Stefano

Hi Dilicus,

Thanks for the reply. Yes calling first readChain2() and then readChain1() is good for tree with two variables. If there are more variables then calling readChain2() and then readChain1() does not work.

Also, the program prints 6.93187e-310 for readChain2(), that is the problem.

Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.