#include "TFile.h" #include "TTree.h" #include // you need to get this value from the one who created the "rd51tbgeo" TTree #define _MAX_POSSIBLE_G1XCL_ 99999 int Resolution_formula() { TFile *CRC = new TFile("CRC-Run065_Icomp100_Th15_MSPL1_lat32-32_I781uA_I771uA_asynchrous-121114_075331-0_ZeroOffSet.root", "READ"); if (!(CRC && CRC->IsOpen())) { delete CRC; return -1; } TTree *rd51tbgeo; CRC->GetObject("rd51tbgeo", rd51tbgeo); if (!rd51tbgeo) { delete CRC; return -2; } rd51tbgeo->SetMakeClass(1); // all branches in decomposed object mode rd51tbgeo->SetBranchStatus("*", 0); // disable all branches Int_t g1xcl_ = -1; rd51tbgeo->SetBranchStatus("g1xcl", 1); // activate "g1xcl" rd51tbgeo->SetBranchAddress("g1xcl", &g1xcl_); Float_t geoposX[(_MAX_POSSIBLE_G1XCL_)]; rd51tbgeo->SetBranchStatus("g1xcl.geoposX", 1); // activate "g1xcl.geoposX" rd51tbgeo->SetBranchAddress("g1xcl.geoposX", geoposX); Long64_t nevent = rd51tbgeo->GetEntries(); std::cout << "####### nevent = " << nevent << std::endl; for (Long64_t i = 0; i < nevent; i++) { rd51tbgeo->GetEntry(i); std::cout << "i = " << i << std::endl; std::cout << "g1xcl_ = " << g1xcl_ << std::endl; for (Int_t j = 0; j < g1xcl_; j++) { std::cout << "geoposX[" << j << "] = " << geoposX[j] << std::endl; } } rd51tbgeo->ResetBranchAddresses(); // "detach" from local variables delete CRC; // it will automatically delete "rd51tbgeo", too return 0; }