ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FGolf/Tools/printFRtable.cc
Revision: 1.1
Committed: Sat Mar 17 19:42:24 2012 UTC (13 years, 1 month ago) by fgolf
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
replace C with cc

File Contents

# Content
1 #include "TROOT.h"
2
3 #include <iostream>
4 #include <string>
5
6 #include "printFRtable.h"
7
8 void printFRtable(TH2F* hist) {
9
10 // some commonly used charactors for printing table
11 std::string colsep = " & ";
12 std::string pmSign = " $\\pm$ ";
13 std::string endL = " \\\\ \\hline";
14
15 // print out header stuff for latex table
16 std::cout << "\\begin{table}[htb]" << std::endl;
17 std::cout << "\\begin{center}" << std::endl;
18 std::cout << "\\caption{}" << std::endl;
19 std::cout << "\\begin{tabular}{c|ccccc}" << std::endl;
20 std::cout << "\\hline" << std::endl;
21 std::cout << "\\backslashbox{$|\\eta|$}{$p_T$}";
22
23 int nbinsx = hist->GetNbinsX(); // number of bins along x axis
24 int nbinsy = hist->GetNbinsY(); // number of bins along y axis
25
26 // first, print pt ranges
27 for (int ny = 1; ny < nbinsy+1; ny++) {
28 float lowedge = hist->GetYaxis()->GetBinLowEdge(ny);
29 float width = hist->GetYaxis()->GetBinWidth(ny);
30
31 printf("%s%.3f%s%.3f", colsep.c_str(), lowedge, " -- ", lowedge+width);
32 }
33
34 std::cout << endL << "\\hline" << std::endl;
35
36 // loop over bins
37 for (int nx = 1; nx < nbinsx+1; nx++) {
38 for (int ny = 1; ny < nbinsy+1; ny++) {
39
40 int nbin = hist->GetBin(nx, ny);
41
42 // if first bin in column, print out eta range
43 if (ny == 1) {
44 float lowedge = hist->GetXaxis()->GetBinLowEdge(nx);
45 float width = hist->GetXaxis()->GetBinWidth(nx);
46
47 printf("%.3f%s%.3f", lowedge, " -- ", lowedge+width);
48 }
49
50 float fr = hist->GetBinContent(nbin);
51 float frerr = hist->GetBinError(nbin);
52
53 printf("%s%.4f%s%.4f", colsep.c_str(), fr, pmSign.c_str(), frerr);
54 }
55
56 std::cout << endL << std::endl;
57 }
58
59 // print out final header stuff for table
60 std::cout << "\\end{tabular}" << std::endl;
61 std::cout << "\\end{center}" << std::endl;
62 std::cout << "\\end{table}" << std::endl;
63 }