I’m getting the following error
Error: illegal pointer to class object stat_tautau[0] 0x0 667 FILE:bg_pt_comp.C
which is for the line
stat_tautau [0]->SetOptStat(1110);
near the end of my macro file. I’m trying to put statistic boxes onto my histogram. From what I’ve read it seems that updating my graph in right place may be the problem.
Jody.
gROOT->Reset();
#include “TFile.h”
#include “TH1.h”
#include “TCanvas.h”
#include “TStyle.h”
#include “TPostScript.h”
#include “TLegend.h”
#include “TROOT.h”
#include “TGraphErrors.h”
#include “TDatime.h”
using std::cout;
using std::endl;
using std::vector;
void bg_pt_comp(){
TFile *tautau_MC = new TFile (“tautauMCcut_160707.root”);
TFile *ttbar_MC = new TFile (“ttbar_MC_bgcut_160707a.root”);
TFile *w_MC = new TFile (“wtop_MCc_160707.root”);
//making histograms for all mass regions
TH1F pt_tautau_c1 = (TH1F) tautau_MC->Get(“pt_dimu_c1”);
TH1F pt_ttbar_c1 = (TH1F) ttbar_MC->Get(“pt_dimu_c1”);
TH1F pt_w_c1 = (TH1F) w_MC->Get(“pt_dimu_c1”);
TH1F pt_tautau_c2 = (TH1F) tautau_MC->Get(“pt_dimu_c2”);
TH1F pt_ttbar_c2 = (TH1F) ttbar_MC->Get(“pt_dimu_c2”);
TH1F pt_w_c2 = (TH1F) w_MC->Get(“pt_dimu_c2”);
TH1F pt_tautau_c3 = (TH1F) tautau_MC->Get(“pt_dimu_c3”);
TH1F pt_ttbar_c3 = (TH1F) ttbar_MC->Get(“pt_dimu_c3”);
TH1F pt_w_c3 = (TH1F) w_MC->Get(“pt_dimu_c3”);
TPaveStats* stat_ttbar[3];//pointers to statistics
TPaveStats* stat_tautau[3];
TPaveStats* stat_w[3];
//cout << Ntautau_c1+Ntautau_c2+ Ntautau_c3<< endl;
pt_tautau_c1->SetLineColor(2);
pt_tautau_c1->SetLineWidth(2.0);
pt_tautau_c1->SetMarkerStyle(8);
pt_tautau_c1->SetMarkerColor(2);
pt_tautau_c1->SetMarkerSize(0.7);
pt_tautau_c1->SetStats(kTRUE);
pt_ttbar_c1->SetLineColor(1);
pt_ttbar_c1->SetLineWidth(2.0);
pt_ttbar_c1->SetMarkerStyle(8);
pt_ttbar_c1->SetMarkerColor(1);
pt_ttbar_c1->SetMarkerSize(0.7);
pt_ttbar_c1->SetStats(kTRUE);
pt_w_c1->SetLineColor(4);
pt_w_c1->SetLineWidth(2.0);
pt_w_c1->SetMarkerStyle(8);
pt_w_c1->SetMarkerColor(4);
pt_w_c1->SetMarkerSize(0.7);
pt_w_c1->SetStats(kTRUE);
gROOT->SetStyle(“Plain”);
TCanvas *myCanvas = new TCanvas(“myCanvas”,“Comparison”);
myCanvas->Divide(1,3);
myCanvas->cd(1);
myCanvas_1->Update();
stat_tautau [0]=(TPaveStats*) pt_tautau_c1->GetListOfFunctions()->FindObject(“stats”);
stat_ttbar [0]=(TPaveStats*) pt_ttbar_c1->GetListOfFunctions()->FindObject(“stats”);
stats_w [0]=(TPaveStats*) pt_w_c1->GetListOfFunctions()->FindObject(“stats”);
// stat_tautau [1]=(TPaveStats*) pt_tautau_c2->GetListOfFunctions()->FindObject(“stats”);
// stat_ttbar [1]=(TPaveStats*) pt_ttbar_c2->GetListOfFunctions()->FindObject(“stats”);
// stat_w [1]=(TPaveStats*) pt_w_c2->GetListOfFunctions()->FindObject(“stats”);
// stat_tautau [2]=(TPaveStats*) pt_tautau_c3->GetListOfFunctions()->FindObject(“stats”);
// stat_ttbar [2]=(TPaveStats*) pt_ttbar_c3->GetListOfFunctions()->FindObject(“stats”);
// stat_w [2]=(TPaveStats*) pt_w_c3->GetListOfFunctions()->FindObject(“stats”);
pt_tautau_c1 ->Draw(“ep”);
pt_ttbar_c1->Draw(“ep same”);
pt_w_c1->Draw(“ep same”);
myCanvas_1->Update();
pt_tautau_c1->SetName(“pt_tautau_c1”); //need to set names so TLegend doesnt make
pt_ttbar_c1->SetName(“pt_ttbar_c1”); //them both same colour
pt_w_c1->SetName(“pt_w_c1”);
TLegend *leg_c1 = new TLegend(0.8,0.7,0.9,0.4,"");//position of corners of legend
leg_c1->AddEntry(“pt_ttbar_c1”,"ttbar ",“l”);
leg_c1->AddEntry(“pt_tautau_c1”,“tautau”, “l” );
leg_c1->AddEntry(“pt_w_c1”,“w”,“l”);
leg_c1->Draw();
myCanvas_1->RedrawAxis();
myCanvas_1->Update();
stat_tautau [0]->SetOptStat(1110);
myCanvas_1->RedrawAxis();
}//end of bg_pt_comp