#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" #include "TCut.h" float offx=1.2; float offy=1.0; float margr=0.08; float w=3; float margl=0.12; void bibbkgdifftree() { gStyle->SetOptStat(00000); gStyle->SetOptFit(0); TH1::StatOverflows(true); TFile *fBIB = TFile::Open("/nfs/luna02/21Ne+p_HPGe_October2022/Analysis/ROOT_CAEN/run0735.root"); if (fBIB == 0) { // if we cannot open the file, print an error message and return immediatly printf("Error: cannot open BIB.root!\n"); return; } fBIB->ls(); TFile *fBkg = TFile::Open("/nfs/luna02/21Ne+p_HPGe_October2022/Analysis/ROOT_CAEN/run0694.root"); if (fBkg == 0) { // if we cannot open the file, print an error message and return immediatly printf("Error: cannot open Bkg.root!\n"); return; } fBkg->ls(); TTree *tBIB=0; TTree *tBkg=0; fBIB->GetObject("tree",tBIB); fBkg->GetObject("tree",tBkg); if (tBIB == nullptr ) { printf("Error: cannot get Tree BIB!\n"); return; } if (tBkg == nullptr ) { printf("Error: cannot get Tree Bkg!\n"); return; } tBIB->SetLineColor(kBlue); tBkg->SetLineColor(kMagenta); 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 TString hStringBIB0 = TString::Format("e0 >> htempBIB0(8000, 0., 8000.)"); TString hStringBkg0 = TString::Format("e0 >> htempBkg0(8000, 0., 8000.)"); TCut cut0a = TString::Format("e0>0").Data(); TCut cut0b = TString::Format("e2==0").Data(); tBIB->Draw(hStringBIB0,cut0a && cut0b); //tBIB->Draw(hStringBIB0); TH1F *hBIB0 = (TH1F*)gPad->GetPrimitive("htempBIB0"); //hBIB0->SetOption("HIST"); hBIB0->Scale(1./81420); c01->Modified(); c01->Update(); hBIB0->SetTitle("; Energy (keV); Counts/s"); c01->Modified(); c01->Update(); hBIB0->SetFillColor(kBlue); hBIB0->SetFillStyle(3005); hBIB0->SetMaximum(1.e-1); hBIB0->SetMinimum(1.e-5); c01->Update(); //tBkg->Draw(hStringBkg0,cut0a && cut0b , "same"); tBkg->Draw(hStringBkg0,"" , "same"); TH1F *hBkg0 = (TH1F*)gPad->GetPrimitive("htempBkg0"); // hBkg0->SetOption("HIST"); hBkg0->Scale(1./51180); c01->Modified(); c01->Update(); hBkg0->SetFillColor(kRed); hBkg0->SetFillStyle(3005); hBkg0->SetTitle("; Energy (keV); Counts/s"); hBkg0->GetXaxis()->SetTitleOffset(offx); hBkg0->GetYaxis()->SetTitleOffset(offy); hBkg0->SetStats(0); hBkg0->SetMaximum(1.e-1); hBkg0->SetMinimum(1.e-5); c01->Update(); TLegend* leg0 = new TLegend(0.35, 0.7, .5, .8); leg0->SetHeader(""); leg0->SetNColumns(1); leg0->AddEntry(hBIB0, "BIB/t_{BIB}: Run0735", "l"); leg0->AddEntry(hBkg0, "Bkg/t_{Bkg}: Run0694", "l"); leg0->SetBorderSize(0); leg0->Draw(); //if wanted 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->SetLogy(); pad0b->Draw(); pad0b->cd(); // pad0b becomes the current pad TH1F *diff0 = (TH1F *)hBIB0->Clone("diff0"); if (!(diff0->GetSumw2N() > 0))diff0->Sumw2(kTRUE); diff0->Add(hBkg0,-1); diff0-> SetLineColor(kGreen); diff0->GetXaxis()->SetRangeUser(0,8000); diff0->SetFillColor(kGreen); diff0->SetTitle("; Energy (keV); Difference"); diff0->SetOption("HIST"); // diff0->Draw("EP"); diff0->Draw(); TLegend* leg0r = new TLegend(0.45, 0.8, .6, .9); leg0r->SetHeader(""); leg0r->SetNColumns(1); leg0r->AddEntry(diff0, "BIB/t_{BIB} - Bkg/t_{Bkg}", "l"); leg0r->SetBorderSize(0); leg0r->Draw(); //if wanted gPad->SetLeftMargin(margl); gPad->SetRightMargin(margr); gPad->SetBottomMargin(0.15); c01->Print("BIB0735-Bkg0694_GePD.png"); delete c01; }