PDF of histogram is not opening after using SaveAs()

Hello,

I’m saving a histogram as a pdf file using SaveAs(). But when I want to open the pdf file, it is doesn’t open. I’m using Form() to name the file with a specific number and I’m not sure if that is the cause of it. I’m using MacOS and Preview usually works to view these files. My code is shown below. Is there a reason why this is happening? Hope to hear an answer soon.

-Charlie Clark

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

#include "TFile.h"
#include "TH1.h"
#include "TH2.h"
#include "TF1.h"
#include "TMath.h"
#include "TPDF.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "TLatex.h"
#include "TTree.h"
#include "TLine.h"

void charge_ratio(const char* inputFile = "mip_18149069.root")
 {

  TFile *f = new TFile(inputFile);

  f->cd();

  std::string inputString = inputFile;

  size_t startPos = inputString.find_first_of("0123456789");

  std::string numericPart = inputString.substr(startPos);

  int runNumber;
  std::istringstream(numericPart) >> runNumber;

  TH1 * Nplus_pTG = (TH1*)f->Get("Nplus_pTG")->Clone();
  TH1 * Nminus_pTG = (TH1*)f->Get("Nminus_pTG")->Clone();

  TCanvas *c = new TCanvas("c","c",1000,1000);
  TH1F *charge_ratio = (TH1F*)Nplus_pTG->Clone("charge_ratio");
  charge_ratio->GetYaxis()->SetTitle("N+/N-");
  charge_ratio->GetXaxis()->SetTitle("pT");
  charge_ratio->SetTitle("Charge Ratio vs. pT");
  charge_ratio->SetMarkerStyle(8);
  charge_ratio->Divide(Nminus_pTG);
  charge_ratio->Draw("EP");
  TString SaveAsFile = Form("charge_ratio_%i.pdf",runNumber);
  charge_ratio->SaveAs(SaveAsFile);
}

ROOT Version: 6.26/06
Platform: MacOS
Compiler: C++


what is the erreur message ?
Can you copy/paste what you get ?

Hi,

isn’t
charge_ratio->SaveAs(SaveAsFile);
supposed to be
c->SaveAs(SaveAsFile);
?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.