#include "TFile.h" #include "TCanvas.h" #include "TStyle.h" #include "TH1.h" #include "TH2.h" #include "TH3.h" #include "TGaxis.h" #include "TRandom.h" #include "TLegend.h" #include "TPaveStats.h" #include "TGraph.h" #include "TPad.h" float offx=1.2; float offy=1.0; //double Emin=1600; //double Emax=7010; double Emin=1200; double Emax=5000; int BinSimMin0=0; int BinSimMax0=0; int BinExpMin0=0; int BinExpMax0=0; int BinSimMin1=0; int BinSimMax1=0; int BinExpMin1=0; int BinExpMax1=0; float margr=0.08; float w=3; float margl=0.12; void detratio() { gStyle->SetOptStat(00000); gStyle->SetOptFit(0); TFile *f = TFile::Open("SimLuna.root"); if (f == 0) { // if we cannot open the file, print an error message and return immediatly printf("Error: cannot open SimLuna.root!\n"); return; } f->ls(); TFile *g = TFile::Open("run0610-0611_GePD.root"); if (g == 0) { // if we cannot open the file, print an error message and return immediatly printf("Error: cannot open Experimental GePD File!\n"); return; } g->ls(); TFile *h = TFile::Open("run0610-0611_GeDD.root"); if (h == 0) { // if we cannot open the file, print an error message and return immediatly printf("Error: cannot open Experimental GeDD File!\n"); return; } h->ls(); TTree *t0=0; f->GetObject("Tree1",t0); if (t0 == nullptr ) { printf("Error: cannot get Tree1!\n"); return; } TCanvas *c01 = new TCanvas("c01","c01",1280,1024); //c01->SetLogy(); TPad *pad0a = new TPad("pad0a", "pad0a", 0.0, 0.3, 1.0, 1.0); pad0a->Draw(); // Draw the upper pad: pad0a pad0a->cd(); pad0a->SetLogy(); gPad->SetLeftMargin(margl); gPad->SetRightMargin(margr); gROOT->cd(); // newly created histograms should go here TH1F *hExp0 = (TH1F *)g->Get("GePD"); // TH1F *hSim0 = (TH1F*)hExp0->Clone("htemp0"); // hSim0->Reset("M"); TString hString0 = TString::Format("Edep[0]>> htemp0(7010, 0, 7010.)"); //TString hString0 = TString::Format("Edep[0] >> htemp0"); t0->Draw(hString0); TH1F *hSim0 = (TH1F*)gPad->GetPrimitive("htemp0"); BinSimMin0 = hSim0->GetXaxis()-> FindBin(Emin); BinSimMax0 = hSim0->GetXaxis()-> FindBin(Emax); hSim0->Scale(1./hSim0->Integral(BinSimMin0,BinSimMax0), "width"); hSim0->Sumw2(kFALSE); c01->Modified(); c01->Update(); hSim0->SetTitle("; Energy (keV); Counts"); hSim0->SetFillColor(kBlue); hSim0->SetLineColor(kBlue); hSim0->SetFillStyle(3005); c01->Update(); BinExpMin0 = hExp0->GetXaxis()-> FindBin(Emin); BinExpMax0 = hExp0->GetXaxis()-> FindBin(Emax); hExp0->Scale(1./hExp0->Integral(BinExpMin0,BinExpMax0), "width"); hExp0->Sumw2(kFALSE); c01->Modified(); c01->Update(); hExp0->SetLineColor(kRed); hExp0->SetFillColor(kRed); hExp0->SetFillStyle(3005); hExp0->SetTitle("; Energy (keV); Counts"); hExp0->GetXaxis()->SetTitleOffset(offx); hExp0->GetYaxis()->SetTitleOffset(offy); hExp0->SetStats(0); c01->Update(); hExp0->Draw("SAME"); c01->Update(); TLegend* leg0 = new TLegend(0.35, 0.7, .5, .8); leg0->SetHeader(""); leg0->SetNColumns(1); leg0->AddEntry(hSim0, "MC", "l"); leg0->AddEntry(hExp0, "Data: Run0610 + Run0611", "l"); leg0->SetBorderSize(0); leg0->Draw(); //if wanted // TPaveStats *statsGePD = (TPaveStats*)hExp0->GetListOfFunctions()->FindObject("stats"); //statsGePD->SetTextColor(kBlue); //statsGePD->SetX1NDC(0.80); statsg->SetX2NDC(0.98); //statsGePD->SetY1NDC(0.77); statsg->SetY2NDC(0.92); //c01->Update(); c01->cd(); c01->Update(); TPad *pad0b = new TPad("pad0b", "pad0b", 0.0, 0.0, 1.0, 0.3); pad0b->SetTopMargin(0.0); pad0b->SetGridx(); // vertical grid pad0b->Draw(); pad0b->cd(); // pad0b becomes the current pad TH1F *ratio0 = (TH1F *)hExp0->Clone("ratio"); if (!(ratio0->GetSumw2N() > 0))ratio0->Sumw2(kTRUE); ratio0->Divide(hExp0); ratio0-> SetLineColor(kGreen); ratio0->GetXaxis()->SetRangeUser(0,7010); ratio0->SetFillColor(kGreen); ratio0->SetTitle("; Energy (keV); ratio"); ratio0->Draw("E"); TLegend* leg0r = new TLegend(0.35, 0.7, .5, .8); leg0r->SetHeader(""); leg0r->SetNColumns(1); leg0r->AddEntry(ratio0, "Data/MC", "l"); leg0r->SetBorderSize(0); leg0r->Draw(); //if wanted gPad->SetLeftMargin(margl); gPad->SetRightMargin(margr); gPad->SetBottomMargin(0.15); c01->Print("Simulazione/DepEne_SimExpRatio_GePD.png"); delete c01; }