Reading branches inside a function from input TChain

Hi,

In my following code

[code]void FillHists(TChain* chain)
{
TH1F* mu_pt_hist = new TH1F(“histName”,“Muon pT Distribution”,100,0,1000000);

Long64_t nentries = chain->GetEntry();

for (Long64_t jentry=0; jentry<nentries;jentry++) {

	// Muons
	for (int k=0;k<mu_n;k++){
     		mu_pt_hist->Fill(mu_pt[k]);
		}	// End of for-loop for mu_hists
}

}[/code]

ROOT complains that mu_n and mu_pt are not defined in the current scope, but they are inside the TTree that was added to the input TChain. Any ideas how I can get those values?

Thanks
Jason

Try:
root […] chain->MakeClass()
See http://root.cern.ch/root/html/TTree.html#TTree:MakeClass for details.
Or try:
root […] chain->MakeSelector()
See http://root.cern.ch/root/html/TTree.html#TTree:MakeSelector for details.
Or try the simplest, considered “obsolete” nowadays:
root […] chain->MakeCode()
See http://root.cern.ch/root/html/TTree.html#TTree:MakeCode for details.

Hi,

You may also want to try MakeProxy:
See root.cern.ch/root/html/TTree.htm … :MakeProxy for details.

Cheers,
Philippe.

Thanks everyone,

I have used MakeClass in the previous step of my work for exactly this purpose, I now just feel stupid for mot thinking of it, thanks a lot and sorry again for the stupid question.

Jason