#include "TVectorD.h" #include #include "TString.h" #include "TCanvas.h" #include "TLine.h" #include "TMath.h" #include "TMarker.h" #include "TH1.h" TCanvas * MakePlot(TVectorD quantity, Double_t threshold, const std::vector& clusters) { static int npad = 0; TString pname = TString::Format("p%d",npad); TCanvas * c1 = new TCanvas();//TCanvas(pname,pname);//(pname,pname); c1->cd(); quantity.Draw(); TString title = TString::Format("N Clusters: %lu",clusters.size()); TH1D * h_vec = static_cast(c1->FindObject("TVectorD")); h_vec->SetTitle(title); TLine threshline; threshline.SetBit(kCanDelete); threshline.SetLineWidth(1); threshline.SetLineStyle(10); threshline.SetLineColor(kRed); if(TMath::Finite(threshold)) { threshline.DrawLine(0,threshold,quantity.GetNoElements(),threshold); } TMarker tm; tm.SetBit(kCanDelete); tm.SetMarkerColor(kGreen); tm.SetMarkerStyle(4); tm.SetMarkerSize(1); for(auto c : clusters) { tm.DrawMarker(c,quantity[c]); } return c1; } void test() { double vals[] = {4,5,6,7,8,9}; TVectorD quantity(6,vals); std::vector clusters{5,1}; TCanvas * c1 = new TCanvas(); c1->Divide(1,3); TCanvas * p1 = MakePlot(quantity,4.5,clusters); c1->cd(1); p1->Draw(); TCanvas * p2 = MakePlot(quantity,7,clusters); c1->cd(2); p2->Draw(); c1->SaveAs("test_MakePlot.pdf"); delete p2; delete p1; delete c1; } TCanvas * test2() { double vals[] = {4,5,6,7,8,9}; TVectorD quantity(6,vals); std::vector clusters{5,1}; return MakePlot(quantity,4.5,clusters); }