#include "TFile.h" #include "TCanvas.h" #include "TStyle.h" #include "TH1.h" #include "TGaxis.h" #include "TRandom.h" #include "TLegend.h" #include "TPaveStats.h" float offx=1.0; float offy=1.2; float n=3; float w=3; float marg=0.17; char dataout[200]; char datain[200]="Histo.root"; char histoname[200]="hGePD"; int x1=1660; int x2=1720; double tmin=1660; double tpeakmin=1684; double tpeakmax=1686; double tmax=1720; void histodrawbgk() { gStyle->SetOptStat(00000); gStyle->SetOptFit(); TFile *f = TFile::Open(datain); sprintf(dataout,"%s_bgkest_[%d,%d].png",histoname, x1,x2); if (f == 0) { // if we cannot open the file, print an error message and return immediatly printf("Error: cannot open root!\n"); return; } f->ls(); TH1F *histo = (TH1F *)f->Get(histoname); if (histo == 0){ printf("Error getting an histogram from the file!\n"); return; } else { TCanvas *c01 = new TCanvas("c01","histo",1280,1024); c01->SetLogy(); histo->GetXaxis()->SetRange(x1,x2); histo->GetXaxis()->SetTitle("Energy (keV)"); histo->GetYaxis()->SetTitle("Counts"); histo->SetTitle(" "); histo->SetFillStyle(3005); histo->SetFillColor(kBlue); histo->GetXaxis()->SetTitleOffset(offx); histo->GetYaxis()->SetTitleOffset(offy); auto b1 = new TBox(x1,0,x2,30); b1->SetFillColorAlpha(kGreen-4,0.5); b1->Draw(); auto b2 = new TBox(tpeakmin,0,tpeakmax,30); b2->SetFillColorAlpha(kOrange,0.5); b2->Draw(); auto lh = new TLine(tpeakmin,30,tpeakmax,30); lh->SetLineColor(kRed); lh->SetLineWidth(3.); lh->Draw(); auto lv1 = new TLine(tpeakmin,1,tpeakmin,200000); lv1->SetLineColor(kRed); lv1->SetLineWidth(3.); lv1->Draw(); auto lv2 = new TLine(tpeakmax,1,tpeakmax,200000); lv2->SetLineColor(kRed); lv2->SetLineWidth(3.); lv2->Draw(); auto t1 = new TText(0,5,""); t1->SetTextAlign(23); t1->SetTextColor(kRed); t1->SetTextFont(132); t1->Draw(); auto t2 = new TText(-10,100,""); t2->SetTextAlign(23); t2->SetTextColor(kBlue); t2->SetTextFont(132); t2->SetTextAngle(45); t2->Draw(); c01->Update(); gPad->Modified(); histo->Draw(); c01->Print(dataout); delete c01; } }