Created
November 7, 2014 17:02
-
-
Save yuasatakayuki/ac4e988ba6477995b7be to your computer and use it in GitHub Desktop.
create ROOT histogram from a text file containing entries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!!