#include "TCanvas.h" #include "TH2F.h" #include "TH1F.h" #include "TFile.h" #include "TLegend.h" #include "TNtuple.h" /* This is an example of how to analyze an ntuple. Carsten Rott (CCAPP) Jun 21, 2010 run it in the following way. root -l gSystem->CompileMacro("ntuple_analysis.C"); ntuple_analysis(4444); // run number as input */ void ntuple_analysis(int run_num = 123456) { TFile *f_data = new TFile("ntuple_file.root"); TNtuple *chain_data = (TNtuple*) f_data->Get("ntuple"); chain_data->SetBranchStatus("*",1); double date,run_number,subrun,rate,rate_error; //Data chain_data->SetBranchAddress("date",&date); // variable name in the ntuple, variable name in this macro ... can be identical chain_data->SetBranchAddress("run_number",&run_number); TH1F *h1_rate = new TH1F("h1_rate","h1_rate",501,-0.5,500.5); // see how big the ntuple is ... const int size_data = chain_data->GetEntries(); // now loop over the ntuple for(int i = 0;iGetEntry(i); if(run_number == run_num) { h1_rate->SetBinContent(subrun,rate); h1_rate->SetBinError(subrun,rate_error); } TCanvas *c4 = new TCanvas("c4","c4",450,550,500,600); h1_rate->Draw(); }