Skip to content

Instantly share code, notes, and snippets.

@yuasatakayuki
Created November 7, 2014 17:02
Show Gist options
  • Save yuasatakayuki/ac4e988ba6477995b7be to your computer and use it in GitHub Desktop.
Save yuasatakayuki/ac4e988ba6477995b7be to your computer and use it in GitHub Desktop.
create ROOT histogram from a text file containing entries
void makeHistogram(std::string fileName){
using namespace std;
ifstream ifs(fileName.c_str());
int pi;
TCanvas* c=new TCanvas("c","c",600,600);
TH1D* hist=new TH1D("hist",fileName.c_str(),2048,0,2048);
while(ifs.is_open() && !ifs.eof()){
ifs >> pi;
hist->Fill(pi);
}
hist->Draw();
std::string pngFileName=fileName+".png";
std::string pdfFileName=fileName+".pdf";
c->SaveAs(pngFileName.c_str());
c->SaveAs(pdfFileName.c_str());
ifs.close();
}
@code2100
Copy link

Hello, I am happy to have come across your code as i belive it will be the solution to my issue. However, I have ran into an error
"Error: Function makeHistogram() is not define in current scope :0:
Interepreter error recovered"

Did you happen to run into this yourself when executing the code using ".x" in root?

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment