// Simple ROOT macro to plot a histogram. // Edited from Glen's code // Ian Connelly 10/11/11 // Unnamed macro : histogrammaker.cc // To run : .x histogrammaker.cc // Takes input for filename (include the .root) // Takes input for a histogram type and name { using std::cin; using std::cout; using std::endl; cout << "Enter filename : " ; TString file; cin >> file; TFile* f = new TFile(file); f->ls(); cout << "Enter histogram type (TH1D/TH1F/TH2D/TH2F) : "; TString type; cin >> type; cout << "Enter histogram name (or type end) : " ; TString name ; cin >> name; if (type =="TH1D") { TH1D* h1 = (TH1D*)f->Get(name); } if (type =="TH1F") { TH1F h1 = (TH1F)*f->Get(name); } if (type =="TH2D") { TH1F h1 = (TH2D)*f->Get(name); } if (type =="TH2F") { TH1F h1 = (TH2F)*f->Get(name); } h1->SetXTitle("x"); h1->SetYTitle("f(x;#xi)"); h1->Draw(); }