#include "Plotter.h" #include using namespace AWPlotter; using namespace boost; using namespace std; Plotter::Plotter() : m_min(9999.) , m_max(-9999.) { } Plotter::~Plotter() { //delete m_c1; //delete m_c2; } void Plotter::init(int numBins) { m_c1 = new TCanvas("c1","Series", 200,10,700,900); m_c1->SetFillColor(kWhite); m_c1->SetGrid(); m_c2 = new TCanvas("c2","Histogram", 210,10,710,900); m_c2->SetFillColor(kWhite); m_hist.reset(new TH1D("Histogram","Histogram Data",numBins,11.,10.)); //note lower limit is greater than upper limit thus we get automatic rebinning after 1000 entries or BufferEmpty is called m_hist->SetMarkerSize(1.5); m_hist->GetXaxis()->SetLabelSize(0.05f); m_hist->GetYaxis()->SetLabelSize(0.05f); m_hist->SetBit(TH1::kCanRebin); m_graph.reset(new TGraph()); m_start = true; } void Plotter::plotHistogram(double data) { m_c2->cd(); if (data > m_max) { m_max = data; m_hist->BufferEmpty(); } else if (data < m_min) { m_min = data; m_hist->BufferEmpty(); } m_hist->Fill(data); m_hist->Draw(); m_c2->Modified(); m_c2->Update(); } void Plotter::plotScatter(const std::vector& X, const std::vector& Y) { m_c1->cd(); m_c1->Clear(); //since we create a new graph int N = static_cast(X.size()); Double_t* x = const_cast(&X[0]); Double_t* y = const_cast(&Y[0]); //Need to lock any new calls TThread::Lock(); m_graph.reset(new TGraph(N, x, y)); TMarker* m = new TMarker(x[N-1], y[N-1], 22); //use to mark last drawn point TThread::UnLock(); m_graph->SetMarkerStyle(kOpenCircle); m_graph->SetMarkerColor(kBlue); m_graph->Draw("ALP"); m->SetMarkerSize(2); m->SetMarkerColor(kGreen); m->Draw(); m_graph->Fit("pol1"); //Access the fit resuts TF1 *f1 = m_graph->GetFunction("pol1"); f1->SetLineWidth(1); f1->SetLineColor(kGreen); double a = f1->GetParameter(0); double b = f1->GetParameter(1); std::ostringstream msg2; msg2 << "a=" << a << ", b=" << b; std::string sMsg2 = msg2.str(); m_graph->SetTitle(sMsg2.c_str()); m_c1->Modified(); m_c1->Update(); } TVirtualPad* Plotter::pad(int i) { if (i == 1) return m_c1->cd(); else return m_c2->cd(); }