Hello,
I’m trying to make a script that renames a bunch of branches in a tree. Most of the branches are std::vector<some_type>, but one is just an unsigned int (“RunNumber” in the below). This code works for all the vector-type branches:
// Open file and rename some branches
TFile * output_file = new TFile(output_filename.c_str(),"UPDATE");
TTree *tree = (TTree*)output_file->Get(tree_name.c_str());
std::vector<std::string> final_names = {"main_track_nominal_nothadron","main_track_nominal_notmuon","stable_track_nominal_nothadron","main_track_validation_nothadron","main_track_validation_notmuon","stable_track_validation_nothadron"}; //,"RunNumber"};
for (auto out_name : final_names) {
std::string in_name = out_name + "_new";
auto branch = tree->GetBranch(in_name.c_str());
branch->SetName(out_name.c_str());
branch->SetTitle(out_name.c_str());
}
tree->Write();
But if I include RunNumber in the list, the final tree doesn’t seem to have the branch named correctly (there’s no title):
*............................................................................*
*Br 18 :RunNumber : UInt_t *
*Entries : 632573 : Total Size= 2532527 bytes File Size = 25207 *
*Baskets : 18 : Basket Size= 339968 bytes Compression= 100.44 *
*............................................................................*
I excluded RunNumber and instead added this code, which includes the type in SetTitle:
auto branch = tree->GetBranch("RunNumber_new");
branch->SetName("RunNumber");
branch->SetTitle("RunNumber/i");
In both cases, running my RDataFrame-based code on the output root file crashes with the error:
terminate called after throwing an instance of 'std::runtime_error'
what(): Unknown column: RunNumber
I can open the root files interactively and look at the contents of RunNumber: they can be displayed in a TTree and are correctly filled. Any idea what I’m doing wrong that my DataFrame can’t interpret the branch?
Cheers,
Kate
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided