ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Util/src/CEffUser2D.cc
Revision: 1.4
Committed: Tue Jun 19 17:11:29 2012 UTC (12 years, 11 months ago) by dkralph
Content type: text/plain
Branch: MAIN
CVS Tags: compiled, HEAD
Changes since 1.3: +4 -4 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 dkralph 1.1 #include "CEffUser2D.h"
2     #include <iomanip>
3    
4     using namespace std;
5    
6     CEffUser2D::CEffUser2D():hEff(0),hErrl(0),hErrh(0){}
7     CEffUser2D::~CEffUser2D(){}
8    
9     //--------------------------------------------------------------------------------------------------
10     void CEffUser2D::loadEff(TH2D* eff, TH2D* errl, TH2D* errh)
11     {
12     hEff = eff;
13     hErrl = errl;
14     hErrh = errh;
15     }
16    
17     //--------------------------------------------------------------------------------------------------
18 dkralph 1.3 Float_t CEffUser2D::getEff(const Double_t x, const Double_t y, const bool keepInBounds)
19 dkralph 1.1 {
20     if(!hEff) {
21     cout << "Efficiency table not loaded! Aborting..." << endl;
22     assert(0);
23     }
24 dkralph 1.3 return getValue(hEff,x,y,keepInBounds);
25 dkralph 1.1 }
26    
27     //--------------------------------------------------------------------------------------------------
28 dkralph 1.3 Float_t CEffUser2D::getErrLow(const Double_t x, const Double_t y, const bool keepInBounds)
29 dkralph 1.1 {
30     if(!hErrl) {
31     cout << "Low errors table not loaded! Aborting..." << endl;
32     assert(0);
33     }
34 dkralph 1.3 return getValue(hErrl,x,y,keepInBounds);
35 dkralph 1.1 }
36    
37     //--------------------------------------------------------------------------------------------------
38 dkralph 1.3 Float_t CEffUser2D::getErrHigh(const Double_t x, const Double_t y, const bool keepInBounds)
39 dkralph 1.1 {
40     if(!hErrh) {
41     cout << "High errors table not loaded! Aborting..." << endl;
42     assert(0);
43     }
44 dkralph 1.3 return getValue(hErrh,x,y,keepInBounds);
45 dkralph 1.1 }
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     void CEffUser2D::printHist2D(const TH2D* h, ostream& os) {
85     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.3 Float_t CEffUser2D::getValue(const TH2D* h, const Double_t x, const Double_t y, const bool keepInBounds)
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 dkralph 1.3 Double_t xval=x,yval=y;
115    
116     if(keepInBounds) {
117 dkralph 1.4 if(x <= h->GetXaxis()->GetBinLowEdge(1)) xval = h->GetXaxis()->GetBinCenter(1);
118     if(x >= h->GetXaxis()->GetBinUpEdge(nx)) xval = h->GetXaxis()->GetBinCenter(nx);
119     if(y <= h->GetYaxis()->GetBinLowEdge(1)) yval = h->GetYaxis()->GetBinCenter(1);
120     if(y >= h->GetYaxis()->GetBinUpEdge(ny)) yval = h->GetYaxis()->GetBinCenter(ny);
121 dkralph 1.3 }
122 dkralph 1.1
123     for(Int_t i=1; i<=nx; i++) {
124 dkralph 1.3 if((xval >= h->GetXaxis()->GetBinLowEdge(i)) && (xval < h->GetXaxis()->GetBinLowEdge(i+1))) {
125 dkralph 1.1 ix=i;
126     break;
127     }
128     }
129    
130     for(Int_t i=1; i<=ny; i++) {
131 dkralph 1.3 if((yval >= h->GetYaxis()->GetBinLowEdge(i)) && (yval < h->GetYaxis()->GetBinLowEdge(i+1))) {
132 dkralph 1.1 iy=i;
133     break;
134     }
135     }
136    
137 dkralph 1.2 if(ix>0 && iy>0) {
138     double rate = h->GetCellContent(ix,iy);
139     if(rate==1) { cerr << "error! rate = 1" << endl; assert(0); }
140     return rate;
141     }
142     else {
143     cerr << "CEffUser2D: out of range! " << setw(15) << x << setw(15) << y << endl;
144     assert(0);
145 dkralph 1.1 return -1;
146 dkralph 1.2 }
147 dkralph 1.1 }