TChain losing values from data file

ROOT Version: 6.20/06
Platform: Linux
Compiler: ROOT macro


I’ve been having an issue with reading a .root ntuple into a TChain. I had been using a TFile to get a TTree, like this:

TFile* file = new TFile();
file = TFile::Open(filename);
TTree* originalTree = (TTree*)file->Get(TString::Format("%s", tree.c_str()));

where “tree” is a variable passed into the code. This worked fine, but I wanted to change this to using a TChain to be able to handle adding multiple files. However, using the new line:

TChain* originalTree = new TChain(tree.c_str());
originalTree->Add("filename");

I add the branch with:

originalTree->SetBranchAddress("failJvt_jet_isTrueHS",&failJvt_jet_isTrueHS);

and I build an index to match events with truth; this eventNumber is how I know I’m looking at the same events for me to see the error. I now find that the length of one of my variables, a vector, is now 0 for a specific event where I can see there is an instance (ie, size() = 1).

*    Row   * Instance * eventNumb * jet_isTru * failJvt_j * failJvt_j *
***********************************************************************
*      111 *        0 *    124382 *           *         0 * 23580.431 *
***********************************************************************

There should be the ‘0’ returned when I call (int) failJvt_jet_isTrueHS->at(i) for i=0, but instead I get a range error:

terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)

Is there a reason TChain would be dropping this event? Am I adding the files incorrectly? I’ve used TChain before with this method and never had an issue, so I’m somewhat confused. Any advice would be greatly appreciated.

What does

originalTree->GetBranch("failJvt_jet_isTrueHS")->Print();

show?

Adding that line adds:

*Br    0 :failJvt_jet_isTrueHS : vector<char>                                *
*Entries :   308302 : Total  Size=    4381401 bytes  File Size  =     751029 *
*Baskets :      339 : Basket Size=      25600 bytes  Compression=   5.82     *
*............................................................................*

to the output

and what is the type of the variable failJvt_jet_isTrueHS ?

it’s supposed to be a vector of char, defined in /athena/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/TopAnalysis/EventSaverFlatNtuple.h

0759     std::vector<char>  m_failJvt_jet_isTrueHS;

Ok, I see what you were saying, and I found the error. In my macro there was an initialization of failJvt_jet_isTrueHS as a std::vector<float>, that hadn’t caused an issue when I was reading with the TFile and TTree but wasn’t read into the TChain properly. This seems to have fixed the issue. Thanks!