'What does this error mean ? warning: null passed to a callee that requires a non-null argument [-Wnonnull]
I am not sure why I get this error or what it means ? I am trying to run a HistPlotter.C file to create histograms. However I get an error that does not make it work? My Plotting directory has all the .root files needed to work, my other classmates are able to get theres to work.
Error in <TFile::TFile>: file hist-WenuNoJetsBVeto.root does not exist
[/Users/andrewbarajas/root/root_v6.22.08/lib/libCling.so]cling_runtime_internal_throwIfInvalidPointer (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[/Users/andrewbarajas/root/root_v6.22.08/lib/libCling.so] cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const (no debug info)
[/Users/andrewbarajas/root/root_v6.22.08/lib/libCling.so] cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (no debug info)
[/Users/andrewbarajas/root/root_v6.22.08/lib/libCling.so] cling::Interpreter::EvaluateInternal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) (no debug info)
[/Users/andrewbarajas/root/root_v6.22.08/lib/libCling.so] cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) (no debug info)
[/Users/andrewbarajas/root/root_v6.22.08/lib/libCling.so] cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)
[/Users/andrewbarajas/root/root_v6.22.08/lib/libCling.so] cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)
[/Users/andrewbarajas/root/root_v6.22.08/lib/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)
[/Users/andrewbarajas/root/root_v6.22.08/lib/libCling.so] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) (no debug info)
[/Users/andrewbarajas/root/root_v6.22.08/lib/libCling.so] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (no debug info)
[/Users/andrewbarajas/root/root_v6.22.08/lib/libCling.so] TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) (no debug info)
[/Users/andrewbarajas/root/root_v6.22.08/lib/libCore.6.22.so] TApplication::ExecuteFile(char const*, int*, bool) (no debug info)
[/Users/andrewbarajas/root/root_v6.22.08/lib/libRint.6.22.so] TRint::ProcessLineNr(char const*, char const*, int*) (no debug info)
[/Users/andrewbarajas/root/root_v6.22.08/lib/libRint.6.22.so] TRint::Run(bool) (no debug info)
[/Users/andrewbarajas/root/root_v6.22.08/bin/root.exe] main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
Error in <HandleInterpreterException>: Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
In file included from input_line_11:1:
/Users/andrewbarajas/root/Plotting/HistPlotter.C:252:23: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
TH1F *h = (TH1F*) f->Get(histname.c_str());
^
This my code, which is the hist plott.C. I am not sure where in the code I messed up ?
#include "include/AtlasStyle.C"
#include "include/AtlasLabels.C"
#include "include/AtlasUtils.C"
void groupSamples();
void makeGroupHist();
std::map<TString, float> db;
std::map<TString, float> dy;
std::map<TString, float> w;
std::map<TString, float> z;
std::map<TString, float> stop;
std::map<TString, float> tt;
std::map<TString, float> signalmap;
TH1F *h_db;
TH1F *h_drellyan;
TH1F *h_wjets;
TH1F *h_zjets;
TH1F *h_singletop;
TH1F *h_ttbar;
std::string histname = "h_event_selection";
float lumi = 1000.;
int rebin = 1; //20 - ZmInv //4 - wmt //1 - event selection
bool logy = true;
std::string signalmass = "400";
void HistPlotter(std::string mass = ""){
if(mass!= "") signalmass = mass;
SetAtlasStyle();
TH1::SetDefaultSumw2(true);
gROOT->Reset();
groupSamples();
makeGroupHist();
THStack *h_stack = new THStack("h_stack","");
h_db->SetFillColor(kRed);
h_drellyan->SetFillColor(kGreen);
h_wjets->SetFillColor(kMagenta);
h_zjets->SetFillColor(kBlue);
h_singletop->SetFillColor(kOrange);
h_ttbar->SetFillColor(kCyan);
h_stack->Add(h_db);
h_stack->Add(h_drellyan);
h_stack->Add(h_wjets);
h_stack->Add(h_zjets);
h_stack->Add(h_singletop);
h_stack->Add(h_ttbar);
TH1F *h_err = (TH1F*) h_db->Clone();
h_err->Add(h_drellyan);
h_err->Add(h_wjets);
h_err->Add(h_zjets);
h_err->Add(h_singletop);
h_err->Add(h_ttbar);
h_err->SetFillStyle(3004);
h_err->SetFillColor(kBlack);
h_err->SetLineColor(0);
h_err->SetMarkerStyle(1);
TFile *f_sig = TFile::Open(("hist-ZPrime" + signalmass + ".root").c_str());
TH1F* h_signal = (TH1F*) f_sig->Get(histname.c_str());
h_signal->Rebin(rebin);
TH1F* h_signal_clone = (TH1F*) h_signal->Clone();
//Rescale signal
h_signal->Scale(1e5*lumi*signalmap[("ZPrime" + signalmass).c_str()]);
h_signal->SetLineStyle(7);
h_signal->SetLineWidth(3);
h_signal->SetLineColor(kPink-8);
TFile *f_egamma = TFile::Open("hist-DataEgamma.root");
TFile *f_muon = TFile::Open("hist-DataMuons.root");
TH1F *h_data_egamma = (TH1F*) f_egamma->Get(histname.c_str());
TH1F *h_data_muon = (TH1F*) f_muon->Get(histname.c_str());
h_data_egamma->Rebin(rebin);
h_data_muon->Rebin(rebin);
TH1F *h_data = (TH1F*) h_data_egamma->Clone();
h_data->Add(h_data_muon);
h_data->SetMarkerSize(1);
h_data->SetMarkerStyle(20);
h_data->SetMarkerColor(kBlack);
/// Chi2
//double chi2_test = h_data->Chi2Test(h_err, "UW,P");
//cout<<"chi2_test "<<chi2_test<<endl;
// I will print some numbers here based on the h_signal, h_data and h_err (sum of all backgrounds) histograms
float cut = 0;
if(signalmass == "400") cut = 0.;
if(signalmass == "500") cut = 0.;
if(signalmass == "750") cut = 400.;
if(signalmass == "1000") cut = 500.;
if(signalmass == "1250") cut = 800.;
if(signalmass == "1500") cut = 1000.;
if(signalmass == "1750") cut = 1250.;
if(signalmass == "2000") cut = 1500.;
if(signalmass == "2250") cut = 1500.;
if(signalmass == "2500") cut = 1500.;
if(signalmass == "3000") cut = 1500.;
cout<<"#####\t Event yields"<<endl;
cout<<"#####\t Data \t:\t"<< h_data->Integral(h_data->GetXaxis()->FindBin(cut), h_data->GetNbinsX()+1)<<endl;
cout<<"#####\t MC \t:\t"<< h_err->Integral(h_err->GetXaxis()->FindBin(cut), h_err->GetNbinsX()+1)<<endl;
cout<<"#####\t Signal "<<signalmass<<" :\t"<< h_signal_clone->Integral(h_signal_clone->GetXaxis()->FindBin(cut), h_signal_clone->GetNbinsX()+1)<<endl;
//calculate event selection efficiency
if( histname== "h_event_selection"){
for(int bin = 2; bin < h_data->GetNbinsX(); bin++){
double eff_rel = h_err->GetBinContent(bin-1) != 0 ? h_err->GetBinContent(bin)/h_err->GetBinContent(bin-1) : 0;
double eff_abs = h_err->GetBinContent(1) != 0 ? h_err->GetBinContent(bin)/h_err->GetBinContent(1) : 0;
double eff_rel_err = h_err->GetBinContent(bin-1) != 0 ? sqrt( eff_rel*(1- eff_rel)/ h_err->GetBinContent(bin)/h_err->GetBinContent(bin-1)) : 0;
double eff_abs_err = h_err->GetBinContent(1) != 0 ? sqrt( eff_abs*(1- eff_abs)/ h_err->GetBinContent(bin)/h_err->GetBinContent(bin-1)) : 0;
cout<<h_err->GetXaxis()->GetBinLabel(bin)<<endl;
std::cout<< eff_rel<<" "<<eff_rel_err<<std::endl;
std::cout<< eff_abs<<" "<<eff_abs_err<<std::endl;
}
}
///// Plotting
TCanvas *can = new TCanvas("can","", 600, 600);
can->cd();
if(logy) can->SetLogy();
h_stack->Draw("hist");
h_err->Draw("e2same");
h_data->Draw("epsame");
h_signal->Draw("histsame");
h_stack->SetMaximum(1.15*h_stack->GetMaximum());
if (logy && histname.find("event_selection") != std::string::npos) h_stack->SetMaximum(1e8*h_stack->GetMaximum());
if (logy && histname.find("event_selection") != std::string::npos) h_stack->SetMinimum(10);
//else if(logy) h_stack->SetMinimum(0.5);
h_stack->GetXaxis()->SetTitle(h_data_egamma->GetXaxis()->GetTitle());
h_stack->GetYaxis()->SetTitle("Events");
h_stack->GetYaxis()->SetTitleOffset(1.60);
if(histname.find("wmt") != std::string::npos)h_stack->GetXaxis()->SetRangeUser(0, 775);
else if(histname.find("ZmInv") != std::string::npos)h_stack->GetXaxis()->SetRangeUser(0, 3775);
else if(histname.find("ZmT") != std::string::npos)h_stack->GetXaxis()->SetRangeUser(0, 3575);
else if(histname.find("lep_pt") != std::string::npos)h_stack->GetXaxis()->SetRangeUser(0, 1575);
else if(histname.find("h_ZpInvM") != std::string::npos) h_stack->GetXaxis()->SetRangeUser(0, 3350);
TLegend *leg = new TLegend(0.55, 0.55, 0.75, 0.9);
leg->SetBorderSize(0);
leg->SetTextFont(42);
leg->SetTextSize(0.035);
leg->SetLineColor(1);
leg->SetLineStyle(1);
leg->SetLineWidth(1);
leg->SetFillColor(0);
leg->SetFillStyle(1001);
leg->SetHeader(" #sqrt{s} = 8 TeV, 1 fb^{-1}");
leg->AddEntry(h_data,"Data","p");
leg->AddEntry(h_ttbar,"t#bar{t}","f");
leg->AddEntry(h_singletop,"Single top","f");
leg->AddEntry(h_zjets,"Z","f");
leg->AddEntry(h_wjets,"W","f");
leg->AddEntry(h_drellyan,"Drell-Yan","f");
leg->AddEntry(h_db,"Diboson","f");
leg->AddEntry(h_err,"MC stat. uncertainty","f");
leg->AddEntry(h_signal,("Z'(" + signalmass + " GeV)#rightarrow t#bar{t} x 10^{5}").c_str(),"l");
leg->Draw();
std::string outfile = histname.substr(2, std::string::npos);
if(logy) can->SaveAs((outfile+"_log.pdf").c_str());
else can->SaveAs((outfile+".pdf").c_str());
}
void groupSamples(){
std::ifstream samples;
samples.open("samples.txt");
while(!samples.eof()){
TString sample;
float xsec;
float red_eff;
float sumw;
float nevt;
samples >> sample >> xsec >> red_eff >> sumw >> nevt;
nevt=1;
//sumw=1;
if(sample.Contains("WW") || sample.Contains("WZ") || sample.Contains("ZZ") ) db[sample] = xsec*nevt/(red_eff*sumw);
if(sample.Contains("DY") ) dy[sample] = xsec*nevt/(red_eff*sumw);
if(sample.Contains("Wenu") || sample.Contains("Wmunu") || sample.Contains("Wtaunu") ) w[sample] = xsec*nevt/(red_eff*sumw);
if(sample.Contains("Zee") || sample.Contains("Zmumu") || sample.Contains("Ztautau") ) z[sample] = xsec*nevt/(red_eff*sumw);
if(sample.Contains("stop") ) stop[sample] = xsec*nevt/(red_eff*sumw);
if(sample.Contains("ttbar") ) tt[sample] = xsec*nevt/(red_eff*sumw);
if(sample.Contains("ZPrime") ) signalmap[sample] = xsec*nevt/(red_eff*sumw);
}
return;
}
void makeGroupHist(){
//for(unsigned int i = 0; i < db.size(); i++){
int i = 0;
for(std::map<TString, float>::iterator it = db.begin(); it != db.end(); ++it){
TFile *f = TFile::Open(Form("hist-%s.root",(it->first).Data()));
TH1F *h = (TH1F*) f->Get(histname.c_str());
h->Rebin(rebin);
h->Scale(it->second*lumi);
//h->Scale(it->second*lumi/h->Integral(0, h->GetNbinsX()+1));
if(i==0) h_db = (TH1F*) h->Clone();
else h_db->Add(h);
i++;
}
i = 0;
for(std::map<TString, float>::iterator it = dy.begin(); it != dy.end(); ++it){
TFile *f = TFile::Open(Form("hist-%s.root",(it->first).Data()));
TH1F *h = (TH1F*) f->Get(histname.c_str());
h->Rebin(rebin);
h->Scale(it->second*lumi);
//h->Scale(it->second*lumi/h->Integral(0, h->GetNbinsX()+1));
if(i==0) h_drellyan = (TH1F*) h->Clone();
else h_drellyan->Add(h);
i++;
}
i = 0;
for(std::map<TString, float>::iterator it = w.begin(); it != w.end(); ++it){
TFile *f = TFile::Open(Form("hist-%s.root",(it->first).Data()));
TH1F *h = (TH1F*) f->Get(histname.c_str());
h->Rebin(rebin);
h->Scale(it->second*lumi);
//h->Scale(it->second*lumi/h->Integral(0, h->GetNbinsX()+1));
if(i==0) h_wjets = (TH1F*) h->Clone();
else h_wjets->Add(h);
i++;
}
i = 0;
for(std::map<TString, float>::iterator it = z.begin(); it != z.end(); ++it){
TFile *f = TFile::Open(Form("hist-%s.root",(it->first).Data()));
TH1F *h = (TH1F*) f->Get(histname.c_str());
h->Rebin(rebin);
h->Scale(it->second*lumi);
//h->Scale(it->second*lumi/h->Integral(0, h->GetNbinsX()+1));
if(i==0) h_zjets = (TH1F*) h->Clone();
else h_zjets->Add(h);
i++;
}
i = 0;
for(std::map<TString, float>::iterator it = stop.begin(); it != stop.end(); ++it){
TFile *f = TFile::Open(Form("hist-%s.root",(it->first).Data()));
TH1F *h = (TH1F*) f->Get(histname.c_str());
h->Rebin(rebin);
h->Scale(it->second*lumi);
//h->Scale(it->second*lumi/h->Integral(0, h->GetNbinsX()+1));
if(i==0) h_singletop = (TH1F*) h->Clone();
else h_singletop->Add(h);
i++;
}
i = 0;
for(std::map<TString, float>::iterator it = tt.begin(); it != tt.end(); ++it){
TFile *f = TFile::Open(Form("hist-%s.root",(it->first).Data()));
TH1F *h = (TH1F*) f->Get(histname.c_str());
h->Rebin(rebin);
h->Scale(it->second*lumi);
//h->Scale(it->second*lumi/h->Integral(0, h->GetNbinsX()+1));
if(i==0) h_ttbar = (TH1F*) h->Clone();
else h_ttbar->Add(h);
i++;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|