#include "TFile.h" #include "TTree.h" #include #define _MAX_POSSIBLE_G1XCL_ 9999999 int Analyze_LHE() { TFile *lhe = new TFile("lhe.root", "READ"); if (!(lhe && lhe->IsOpen())) { delete lhe; return -1; } TTree *tree; lhe->GetObject("tree", tree); if (!tree) { delete lhe; return -2; } tree->SetMakeClass(1); // all branches in decomposed object mode tree->SetBranchStatus("*", 0); // disable all branches Int_t Llep0_ = -1; tree->SetBranchStatus("Llep0", 1); // activate "Llep0" tree->SetBranchAddress("Llep0", &Llep0_); Float_t Pt[(_MAX_POSSIBLE_G1XCL_)]; tree->SetBranchStatus("Llep0.Pt()", 1); // activate "Llep0.Pt" tree->SetBranchAddress("Llep0.Pt()", Pt); Long64_t nevent = tree->GetEntries(); std::cout << "####### nevent = " << nevent << std::endl; for (Long64_t i = 0; i < nevent; i++) { tree->GetEntry(i); std::cout << "i = " << i << std::endl; std::cout << "Llep0_ = " << Llep0_ << std::endl; for (Int_t j = 0; j < Llep0_; j++) { std::cout << "Pt[" << j << "] = " << Pt[j] << std::endl; } } tree->ResetBranchAddresses(); // "detach" from local variables delete lhe; // it will automatically delete "tree", too return 0; }