#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 "TSystem.h" #include "TTree.h" #include "TTreePlayer.h" #include "TF1.h" #include #include #include float fillcolor=0.35; void idpartb21() { gStyle->SetOptStat(111110); gSystem->mkdir(TString::Format("graph"), kTRUE); TFile *fin = TFile::Open("setup/build/LemmaMC.root"); fin->ls (); if (fin == 0) { printf("Error: cannot open the file!\n"); } else { TTree *t=0; fin->GetObject("LEMMA",t); t->SetScanField(0); TCanvas *c01 = new TCanvas("c01","",1280,1024); c01->SetLogy(); t->SetLineColor(kBlue); TString outputname = TString::Format("graph/Idp.pdf"); TString hidpstring = TString::Format("Idp >> htemp(100., 0., 0.)"); t->Draw(hidpstring); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(""); TH1F *hidp = (TH1F*)gPad->GetPrimitive("htemp"); hidp->SetFillStyle(1001); hidp->GetXaxis()->SetTitle("Energy (GeV)"); hidp->GetYaxis()->SetTitle("Counts"); hidp->GetXaxis()->SetLabelFont(43); hidp->GetXaxis()->SetLabelSize(30); hidp->GetYaxis()->SetLabelFont(43); hidp->GetYaxis()->SetLabelSize(30); hidp->GetXaxis()->SetTitleFont(43); hidp->GetXaxis()->SetTitleSize(30); hidp->GetYaxis()->SetTitleFont(43); hidp->GetYaxis()->SetTitleSize(30); hidp->SetFillColorAlpha(kBlue, fillcolor); hidp->Draw(); hidp->SetName("Title"); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* leg = new TLegend(0.65, 0.7, .75, .75); leg->SetHeader("Legend"); leg->SetNColumns(1); leg->AddEntry(hidp, "Data", "l"); leg->Draw(); gPad->Update(); TPaveStats *stats = (TPaveStats*)hidp->GetListOfFunctions()->FindObject("stats"); stats->SetTextColor(kBlue); stats->SetX1NDC(0.80); stats->SetX2NDC(0.98); stats->SetY1NDC(0.77); stats->SetY2NDC(0.92); gPad->Update(); c01->Print(outputname); delete c01; } }