Accessing folder inside a tree

Hi all,

I need to access variables (e.g Pt(), M(), …) that are inside a folder Reco_QQ_4mom in tree “myTree” in my root file (see attachment). I can access variables directly inside myTree, but cannot access e.g myTree/Reco_QQ_4mom/Pt(). My code looks like:


void HF_deposit() {
  cout << "Starting macro" << endl;
  
  // Open the appropriate input file
  TFile *inFile;
  inFile = new TFile("data/UPC_HLT_HIUPCSingleMuNotHF2Pixel_SingleTrack_v1_NoCuts.root","READ");

  TDirectoryFile *hionia = (TDirectoryFile*)inFile->Get("hionia");
  TTree* myTree = (TTree*)hionia->Get("myTree");
  
  UInt_t y;
  cout << "bla bla1"<< endl;
  myTree->SetBranchAddress("eventNb", &y);
  cout << "bla bla2"<< endl;
  
  Double_t x;
  cout << "bla bla3"<< endl;
  myTree->SetBranchAddress("Reco_QQ_4mom.M()", &x);
  cout << "bla bla3"<< endl;

  Int_t Entries = myTree->GetEntries();
  cout << "myTree has " << Entries << " entries." << endl;

// Events loop

  //for (Int_t i=0; i<Entries; i++)
  for (Int_t i=0; i<30000; i++) // loops
    {
    myTree->GetEntry(i);

    if(i==10000) cout << "bla bla 5: " << x << ", " << y << endl;
    if(i==20000) cout << "bla bla 6: " << x << ", " << y << endl;

    }
}

and gives:


root [7] .x HF_deposit.c
Starting macro
bla bla1
bla bla2
bla bla3
Error in <TTree::SetBranchAddress>: unknown branch -> Reco_QQ_4mom.M()
bla bla3
myTree has 28549076 entries.
bla bla 5: 6.95322e-310, 41340929
bla bla 6: 6.95322e-310, 43117422
root [8] 

so it reads myTree/eventNb but does not read myTree/Reco_QQ_4mom/M(). Of course M() is inside this folder, though cannot be seen in the attachment. Furthermore what does it mean that the leafs inside Reco_QQ_4mom have red “!” on them?

Additionally, doing myTree->Draw("Reco_QQ_4mom.M()","") in root works fine and draws nice histo.

Thanks for help!
Marek


Attachment:

Hi,

You are trying to assign address to result of function M(). This does not work.

You need to assign address for “Reco_QQ_4mom” branch (appropriate version of TLorentzVector) and call your_vector->M() method.

Or after calling myTree->Draw(“Reco_QQ_4mom.M()”,"") access result with TTree::GetV1() method.

Regards,
Sergey