-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhist_plot.cpp
50 lines (39 loc) · 1.12 KB
/
hist_plot.cpp
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
50
// This is a simple code to plot three distributions from .root files.
void hist_plot() {
TFile *file2 = new TFile("file_name_1.root");
TFile *file4 = new TFile("file_name_2.root");
TFile *file6 = new TFile("file_name_3.root");
TH1F *hist2;
TH1F *hist4;
TH1F *hist6;
TF1 *fitFunc;
gStyle->SetOptStat(0);
/* printf("File open... ");
if (!file) {
printf("[FAIL]\n");
return 0;
} else printf("[OK]\n");
*/
printf("Loading histogram... ");
hist2 = file2->GetObject("fCounterSipm", hist2);
hist4 = file4->GetObject("fCounterSipm", hist4);
hist6 = file6->GetObject("fCounterSipm", hist6);
/* if (!hist1) {
printf("[FAIL]\n");
return 0;
} else printf("[OK]\n");
if (!hist2) {
printf("[FAIL]\n");
return 0;
} else printf("[OK]\n");
*/
fitFunc = new TF1("fitFunc", "landau");
hist2->Fit(fitFunc);
hist4->Fit(fitFunc);
hist6->Fit(fitFunc);
hist4->SetLineColor(kRed);
hist6->SetLineColor(kBlue);
hist2->Draw("SAME");
hist4->Draw("SAME");
hist6->Draw("SAME");
}