ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Common/CEffUser2D.cc
Revision: 1.2
Committed: Tue Jul 26 07:18:45 2011 UTC (13 years, 9 months ago) by dkralph
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +3 -3 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 dkralph 1.1 #include "CEffUser2D.hh"
2     #include <iomanip>
3    
4     using namespace std;
5    
6     CEffUser2D::CEffUser2D():hEff(0),hErrl(0),hErrh(0){}
7     CEffUser2D::~CEffUser2D(){}
8    
9     //--------------------------------------------------------------------------------------------------
10 dkralph 1.2 void CEffUser2D::loadEff(TH2D* eff, TH2D* errl, TH2D* errh)
11 dkralph 1.1 {
12     hEff = eff;
13     hErrl = errl;
14     hErrh = errh;
15     }
16    
17     //--------------------------------------------------------------------------------------------------
18     Float_t CEffUser2D::getEff(const Double_t x, const Double_t y)
19     {
20     if(!hEff) {
21     cout << "Efficiency table not loaded! Aborting..." << endl;
22     assert(0);
23     }
24     return getValue(hEff,x,y);
25     }
26    
27     //--------------------------------------------------------------------------------------------------
28     Float_t CEffUser2D::getErrLow(const Double_t x, const Double_t y)
29     {
30     if(!hErrl) {
31     cout << "Low errors table not loaded! Aborting..." << endl;
32     assert(0);
33     }
34     return getValue(hErrl,x,y);
35     }
36    
37     //--------------------------------------------------------------------------------------------------
38     Float_t CEffUser2D::getErrHigh(const Double_t x, const Double_t y)
39     {
40     if(!hErrh) {
41     cout << "High errors table not loaded! Aborting..." << endl;
42     assert(0);
43     }
44     return getValue(hErrh,x,y);
45     }
46    
47     //--------------------------------------------------------------------------------------------------
48     void CEffUser2D::printEff(ostream& os)
49     {
50     if(!hEff) {
51     cout << "Efficiency table not loaded! Aborting..." << endl;
52     assert(0);
53     }
54     os << "Efficiency Table:" << endl;
55     os << "-----------------" << endl;
56     printHist2D(hEff,os);
57     }
58    
59     //--------------------------------------------------------------------------------------------------
60     void CEffUser2D::printErrLow(ostream& os)
61     {
62     if(!hErrl) {
63     cout << "Error (low) table not loaded! Aborting..." << endl;
64     assert(0);
65     }
66     os << "Low Errors Table:" << endl;
67     os << "-----------------" << endl;
68     printHist2D(hErrl,os);
69     }
70    
71     //--------------------------------------------------------------------------------------------------
72     void CEffUser2D::printErrHigh(ostream& os)
73     {
74     if(!hErrh) {
75     cout << "Error (high) table not loaded! Aborting..." << endl;
76     assert(0);
77     }
78     os << "High Errors Table:" << endl;
79     os << "------------------" << endl;
80     printHist2D(hErrh,os);
81     }
82    
83     //--------------------------------------------------------------------------------------------------
84 dkralph 1.2 void CEffUser2D::printHist2D(const TH2D* h, ostream& os) {
85 dkralph 1.1 const Int_t nx = h->GetNbinsX();
86     const Int_t ny = h->GetNbinsY();
87    
88     for(Int_t iy=0; iy<=ny; iy++) {
89     for(Int_t ix=0; ix<=nx; ix++) {
90     if(ix==0 && iy==0) {
91     os << setw(11) << "";
92     } else if(ix==0) {
93     os << "[" << setw(4) << h->GetYaxis()->GetBinLowEdge(iy) << "," << setw(4) << h->GetYaxis()->GetBinLowEdge(iy+1) << "]";
94     } else if(iy==0) {
95     os << "[" << setw(4) << h->GetXaxis()->GetBinLowEdge(ix) << "," << setw(4) << h->GetXaxis()->GetBinLowEdge(ix+1) << "]";
96     } else {
97     ios_base::fmtflags flags = os.flags();
98     os.precision(7);
99     os << " " << setw(9) << fixed << h->GetCellContent(ix,iy) << " ";
100     os.flags(flags);
101     }
102     }
103     os << endl;
104     }
105     }
106    
107     //--------------------------------------------------------------------------------------------------
108 dkralph 1.2 Float_t CEffUser2D::getValue(const TH2D* h, const Double_t x, const Double_t y)
109 dkralph 1.1 {
110     Int_t ix=0;
111     Int_t iy=0;
112     const Int_t nx = h->GetNbinsX();
113     const Int_t ny = h->GetNbinsY();
114    
115     for(Int_t i=1; i<=nx; i++) {
116     if((x >= h->GetXaxis()->GetBinLowEdge(i)) && (x < h->GetXaxis()->GetBinLowEdge(i+1))) {
117     ix=i;
118     break;
119     }
120     }
121    
122     for(Int_t i=1; i<=ny; i++) {
123     if((y >= h->GetYaxis()->GetBinLowEdge(i)) && (y < h->GetYaxis()->GetBinLowEdge(i+1))) {
124     iy=i;
125     break;
126     }
127     }
128    
129     if(ix>0 && iy>0)
130     return h->GetCellContent(ix,iy);
131     else
132     return -1;
133     }