Hello all,
I’m trying to read some information on a branch from one TTree (t) and write it to another TTree (t1). However, my code crashes when it finds an empty entry (I think), and the seg fault doesn’t say anything helpful. Below is my piece of code, and I have also added the result of scanning the branch I’m trying to read. You can see that there are some rows with no entries, and that I think is the problem. How can I direct my script to skip these empty entries? The input root file is on eos.
//Getting input file and tree:
TFile f1("/eos/experiment/fcc/ee/generation/DelphesEvents/fcc_v01/p8_ee_ZH_ecm240/events_000038119.root") ;
TTree *t = (TTree*)f1.Get("events");
int n = t->GetEntries();
//Create output file and tree
TFile f("FCCee_ZH.root","recreate");
TTree t1("events","output tree");
float px, phi;
float px0, phi0;
//Get my branches of interest
//t->SetBranchAddress("met.phi",&phi0);
//The code works fine when I look at met.phi because there are no empty entries there.
t->SetBranchAddress("muons.core.p4.px",&px0);
//Create the branches on the new tree
//t1.Branch("met_phi",&phi,"phi/F");
t1.Branch("muon_px",&px,"px/F");
//Fill the new tree
for (int i=0; i<n; i++) {
t->GetEntry(i);
if (t->GetEntry(i)<0 || t->GetEntry(i)==0) continue;
phi = phi0;
t1.Fill();
}
//Write new tree to file f
t1.Write();
//Output of events->Scan("muons.core.p4.px")
/*
***********************************
* Row * Instance * muons.cor *
***********************************
* 0 * 0 * 8.0309610 *
* 1 * 0 * *
* 2 * 0 * *
* 3 * 0 * *
* 4 * 0 * *
* 5 * 0 * *
* 6 * 0 * *
* 7 * 0 * 9.3634538 *
* 8 * 0 * 14.266631 *
* 8 * 1 * 10.907753 *
* 9 * 0 * *
* 10 * 0 * 54.991462 *
* 10 * 1 * 1.7402488 *
* 11 * 0 * -0.980190 *
* 12 * 0 * *
* 13 * 0 * *
* 14 * 0 * 4.2284102 *
* 15 * 0 * *
* 16 * 0 * -1.219771 *
* 16 * 1 * -2.019493 *
* 17 * 0 * *
* 18 * 0 * -8.203149 *
* 19 * 0 * 55.774704 *
* 19 * 1 * -40.93004 *
* 20 * 0 * *
..............................................
*/
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided