#include #include #include #include #include using namespace std; void Read_Simulation(string rootFileName, string prefix_TSCname, int number_of_Realization, string newhisName,string rootFileNametoWrite){ // Open rootFileName TFile f(rootFileName.c_str()); //f.GetListOfKeys()->Print(); //Test // Read First TSC spectrum (real = 0) string stmp1 = prefix_TSCname + "0"; TH1F *h1 = (TH1F*)f.Get(stmp1.c_str()); h1->SetDirectory(0); // Loop for all TSC spectra for (int i=1; iAdd(h2); delete h2; }//End for loop // Scale histogram h1->Scale(1.0/number_of_Realization); double xbins[13]={0.1,0.5,1,1.5,2.0, 2.5,3.0,3.5,4.0,4.5,5.0,5.5,6.0}; // this will produce warnings TH1F *h1rebin = (TH1F*)h1->Rebin(12,"h1rebin",xbins); h1rebin->SetDirectory(0); // refill TH1F *h1new = new TH1F("h1new","h1new",12,xbins); h1new->SetDirectory(0); for (Int_t ib=1; ib <=h1->GetNbinsX(); ib++) { h1new->Fill(h1->GetBinCenter(ib), h1->GetBinContent(ib)); } h1new->Draw(); h1rebin->SetLineColor(2); h1rebin->Draw("same"); // show diff for (Int_t ib=1; ib <=h1new->GetNbinsX(); ib++) { cout << h1new->GetBinContent(ib) - h1rebin->GetBinContent(ib) << endl; } } void NA(){ Read_Simulation("Run0001.root","hExI0to36TSC_",20,"",""); }