gROOT->Reset(); #include "TChain.h" #include "TTree.h" #include "TObject.h" #include "TArray.h" #include "TFile.h" #include "TList.h" #include "TCanvas.h" #include "TAxis.h" #include "TH1.h" #include "TMath.h" void norm(TH1F* hist) { // normalizes a 1-d histogram to its bin width and number of events hist->Sumw2(); hist->Scale(1.0 / hist->Integral(),"width"); //new... Rene"s suggestion// /* for (Int_t i=1; i<=hist->GetNbinsX(); ++i) { hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i)); hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i)); }*/ } void style(TH1F* hist){ //removes stat box and title. just for reduce the line numbers// hist->SetStats(kFALSE); hist->SetBit(TH1::kNoTitle); } void Draw_eff_draw(){ TFile *strangefile = TFile::Open("StrangeSpectra_perugia_900GeV_596700_event.root", "read"); TList *liststrange = strangefile-> Get("coutput"); //get Y histograms from root file. B: abs(y)>0.9 C:abs(y)>0.5 D:abs(y)>2.5 B_LAMBDA = (TH1F*)(liststrange->FindObject("fMCYLambdapt0y09")) ; C_LAMBDA = (TH1F*)(liststrange->FindObject("fMCYLambdapt0y05")) ; D_LAMBDA = (TH1F*)(liststrange->FindObject("fMCYLambdapt0y25")) ; //make sumw2 for division B_LAMBDA->Sumw2(); C_LAMBDA->Sumw2(); D_LAMBDA->Sumw2(); //create a ratio histograms //binning and x-axis range same as original the distributions at root file TH1F *B_RATIO =new TH1F("B_RATIO", " Y distribution Lambda/Lambda Ratio for p_{T} >0 and Y>0.9",15,-3,3 ) ; B_RATIO->SetMarkerStyle(20); TH1F *C_RATIO =new TH1F("C_RATIO", " Y distribution Lambda/Lambda Ratio for p_{T} >0 and Y>0.5",15,-3,3 ) ; C_RATIO->SetMarkerStyle(22); TH1F *D_RATIO =new TH1F("D_RATIO", " Y distribution Lambda/Lambda Ratio for p_{T} >0 and Y>2.5",15,-3,3 ) ; D_RATIO->SetMarkerStyle(24); B_RATIO->Divide(B_LAMBDA,B_LAMBDA); //should give 1// C_RATIO->Divide(C_LAMBDA,C_LAMBDA); //should give 1// D_RATIO->Divide(D_LAMBDA,D_LAMBDA); //should give 1// //copy ratio histograms for normalization TH1F *B_RATIOnorm = new TH1F(*B_RATIO); TH1F *C_RATIOnorm = new TH1F(*C_RATIO); TH1F *D_RATIOnorm = new TH1F(*D_RATIO); //normalize histograms norm(B_RATIOnorm); norm(C_RATIOnorm); norm(D_RATIOnorm); //remove stat boxes and titles style(B_RATIO); style(C_RATIO); style(D_RATIO); style(B_RATIOnorm); style(C_RATIOnorm); style(D_RATIOnorm); //draw ratio histograms TCanvas *c1 = new TCanvas("c1","+1+ ORIGINAL"); B_RATIO->GetYaxis()->SetRangeUser(0,1.5); B_RATIO->Draw("e1p"); C_RATIO->Draw("e1psame"); D_RATIO->Draw("e1psame"); c1->BuildLegend(0.29,0.78,0.99,0.97); c1->SaveAs("before_normalization.png"); //draw normalized ratio histograms TCanvas *c2_normalized = new TCanvas("c2_normalized","+2+ NORMALIZED"); B_RATIOnorm->GetYaxis()->SetRangeUser(0,1.4); B_RATIOnorm->Draw("e1p"); C_RATIOnorm->Draw("e1psame"); D_RATIOnorm->Draw("e1psame"); c2_normalized->BuildLegend(0.29,0.78,0.99,0.97); c2_normalized->SaveAs("after_normalization.png"); }