#include "TCanvas.h" #include "TROOT.h" #include "TStyle.h" #include "TH1F.h" #include "TH1D.h" #include "TGraphErrors.h" #include "TLegend.h" #include "TFile.h" #include "TString.h" #include #include #include class Plot { TCanvas * c1; TLegend* legen; TLegend* leg[6]; // legends TH1F* hh[6]; // frames std::vector files; std::map typefilename; TString path; public: Plot(); void Initialize(TString pre=".."); void CreateCanvas(); bool Draw(TString name, TString select, TString option); void DrawLegends(); TCanvas * GetCanvas() { return c1; } void Print(TString n); }; Plot::Plot() : c1(0) { for (Int_t i=0; i<6;++i) leg[i]=0; for (Int_t i=0; i<6;++i) hh[i]=0; typefilename["default"]="cms10gev"; typefilename["EMV"]="cms10gev71"; typefilename["EMX"]="cms10gevSC"; // disp } void Plot::Initialize(TString pre) { path=pre; gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetOptStat(0); gStyle->SetNdivisions(210, "y"); gStyle->SetLabelSize(0.06, "x"); gStyle->SetLabelSize(0.06, "y"); gStyle->SetTitleOffset(0.9, "x"); gStyle->SetTitleOffset(0.7, "y"); gStyle->SetTitleSize(0.07, "x"); gStyle->SetTitleSize(0.07, "y"); gStyle->SetMarkerSize(1.5); gStyle->SetPadBottomMargin(0.13); gStyle->SetPadTopMargin(0.09); gStyle->SetPadLeftMargin(0.1); gStyle->SetPadRightMargin(0.05); gStyle->SetPadBorderMode(0); gStyle->SetTitleOffset(1.0, "y"); gStyle->SetMarkerSize(1.0); gStyle->SetPadLeftMargin(0.16); gStyle->SetPadRightMargin(0.08); // std::cerr<<" Style initialised "<Divide(2,3); TString hed[6] = {"Central crystal", "Central crystal","3x3 matrix","3x3 matrix","5x5 matrix","5x5 matrix"}; TString axtit[5] = {"Visible energy (E/E_{0})","Resolution #sigma_{E}/E_{0} (%)","cut (mm)","CPU (rel. units)","E (GeV)"}; Double_t y1[6] = {0.73, 2, 0.92 , 1, 0.96, 0}; Double_t y2[6] = {0.79, 7, 0.95, 2.5, 0.98, 2}; legen = new TLegend(0.2, 0.90, 0.8, 0.97); legen->SetTextSize(0.05); legen->SetHeader("e^{-} 10 GeV in PbWO_{4} Crystal Calorimeter"); for(Int_t i=0; i<6; i++) { c1->cd(i+1); gPad->SetLogx(); gPad->SetGrid(); leg[i] = new TLegend(0.2, 0.2, 0.6, 0.5); hh[i] = gPad->DrawFrame(0.00001,y1[i],1000,y2[i],""); leg[i]->SetTextSize(0.05); leg[i]->SetHeader(hed[i]); hh[i]->GetXaxis()->SetTitle(axtit[2]); if(i==0 || i==2 || i==4) { hh[i]->GetYaxis()->SetTitle(axtit[0]); } else { hh[i]->GetYaxis()->SetTitle(axtit[1]); } // hh[i]->Draw("AXIS SAME"); } } bool Plot::Draw(TString nam, TString type, TString sname) { if (type=="") type="default"; if (type=="all") { Draw(nam,"default",sname); Draw(nam,"EMV",sname); Draw(nam,"EMX",sname); return true; } // std::cerr<<" name = "<Get("h0"); // TH1D* h1 = (TH1D*)ff->Get("h1"); TH1D* h2 = (TH1D*)ff->Get("h2"); TH1D* h3 = (TH1D*)ff->Get("h3"); TH1D* h4 = (TH1D*)ff->Get("h4"); TH1D* h5 = (TH1D*)ff->Get("h5"); TH1D* h6 = (TH1D*)ff->Get("h6"); TH1D* h7 = (TH1D*)ff->Get("h7"); c1->cd(1); Int_t bins = h0->GetNbinsX(); // cout << "bins= " << bins << endl; Double_t x[20]; Double_t e1[20], e2[20], e3[20], r1[20], r2[20], r3[20]; Double_t errx[20]; Double_t erre1[20], erre2[20], erre3[20], errr1[20], errr2[20], errr3[20]; for(Int_t ii=0; iiGetBinContent(ii+1); errx[ii] = 0; e1[ii] = h2->GetBinContent(ii+1); erre1[ii] = h2->GetBinError(ii+1); r1[ii] = h3->GetBinContent(ii+1); errr1[ii] = h3->GetBinError(ii+1); e2[ii] = h4->GetBinContent(ii+1); erre2[ii] = h4->GetBinError(ii+1); r2[ii] = h5->GetBinContent(ii+1); errr2[ii] = h5->GetBinError(ii+1); e3[ii] = h6->GetBinContent(ii+1); erre3[ii] = h6->GetBinError(ii+1); r3[ii] = h7->GetBinContent(ii+1); errr3[ii] = h7->GetBinError(ii+1); } c1->cd(1); Int_t idx = files.size(); TGraphErrors * gr = new TGraphErrors(bins,x,e1,errx,erre1); gr->SetMarkerColor(col[idx]); gr->SetMarkerStyle(mar[idx]); gr->Draw("P SAME"); leg[0]->AddEntry(gr, txtx, "p"); if(nam != "geant4-07-01-patch-01") { c1->cd(2); gr = new TGraphErrors(bins,x,r1,errx,errr1); gr->SetMarkerColor(col[idx]); gr->SetMarkerStyle(mar[idx]); gr->Draw("P SAME"); leg[1]->AddEntry(gr, txtx, "p"); } c1->cd(3); gr = new TGraphErrors(bins,x,e2,errx,erre2); gr->SetMarkerColor(col[idx]); gr->SetMarkerStyle(mar[idx]); gr->Draw("P SAME"); leg[2]->AddEntry(gr, txtx, "p"); if(nam != "geant4-07-01-patch-01") { c1->cd(4); gr = new TGraphErrors(bins,x,r2,errx,errr2); gr->SetMarkerColor(col[idx]); gr->SetMarkerStyle(mar[idx]); gr->Draw("P SAME"); leg[3]->AddEntry(gr, txtx, "p"); } c1->cd(5); gr = new TGraphErrors(bins,x,e3,errx,erre3); gr->SetMarkerColor(col[idx]); gr->SetMarkerStyle(mar[idx]); gr->Draw("P SAME"); leg[4]->AddEntry(gr, txtx, "p"); if(nam != "geant4-07-01-patch-01") { c1->cd(6); gr = new TGraphErrors(bins,x,r3,errx,errr3); gr->SetMarkerColor(col[idx]); gr->SetMarkerStyle(mar[idx]); gr->Draw("P SAME"); leg[5]->AddEntry(gr, txtx, "p"); } files.push_back(ff); c1->Update(); return true; } void Plot::DrawLegends() { c1->cd(1); legen->Draw(); for(Int_t i=0; i<6; i++) { c1->cd(i+1); leg[i]->Draw(); } // std::cerr<<"done1"<Update(); // std::cerr<<"done2"<Print(n); // std::cerr<<"done"<