-
Notifications
You must be signed in to change notification settings - Fork 2
/
readtextfile.C
49 lines (37 loc) · 1.08 KB
/
readtextfile.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{
//! Raghav Kunnawalkam Elayavalli
//! Rutgers University
//! June 8th 2017
//! readtextfile - to read a text file and make a histogram
TCanvas * ctest = new TCanvas("ctest", "Tutorial", 600, 600);
ctest->Divide(2,1);
TGraphErrors graph_input("./macro2_input.txt","%lg %lg %lg");
graph_input.SetTitle("Measurement;length [cm];Arb.Units");
graph_input.SetFillColor(3);
ctest->cd(1);
graph_input.Draw("ACP");
ifstream fin;
fin.open("macro2_input.txt");
int x;
double y;
int ey;
TH1F * htest = new TH1F("htest", "Measurement;length (cm);arb.units", 10, 0, 10);
while(1){
fin >> x >> y >> ey;
// cout << "x = " << x << endl;
htest->SetBinContent(x, y);
htest->SetBinError(x, ey);
if(!fin.good()) break;
}
ctest->cd(2);
htest->Draw("BAR");
ctest->SaveAs("testplot.pdf", "RECREATE");
TFile * fout = new TFile("testfile.root", "RECREATE");
fout->cd();
graph_input.SetName("mytestGraph");
graph_input.Write();
htest->SetName("mytestHisto");
htest->Write();
fout->Close();
}