ATLAS Offline Software
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Efficiency2D Class Reference

#include <Efficiency2D.h>

Inheritance diagram for Efficiency2D:
Collaboration diagram for Efficiency2D:

Public Member Functions

 Efficiency2D (TH2F *h, const std::string &n="")
 
 Efficiency2D (TH2F *hnum, TH2F *hden, const std::string &n, double scale=100)
 
 ~Efficiency2D ()
 
void Fill (double x, double y, double w=1)
 fill methods ... More...
 
void FillDenom (double x, double y, float w=1)
 
TGraphAsymmErrors * BayesX (int slice, double scale=100)
 evaluate the uncertainties correctly ... More...
 
TGraphAsymmErrors * BayesY (int slice, double scale=100)
 
TH1D * sliceX (int i)
 
TH1D * sliceY (int i)
 
int slicesX () const
 
int slicesY () const
 
const std::string & name () const
 
TH2F * Hist ()
 
void finalise (double scale=100)
 actually calculate the efficiencies More...
 
double findTotalEfficiency ()
 these 1D and 2D Fill versionms should never be called directly in fact, are they even needed at all ?
More...
 
void Write ()
 

Protected Member Functions

virtual void getibinvec (bool force=false)
 
std::string slicename (const std::string &s, int i) const
 
TGraphAsymmErrors * BayesInternal (TH1 *hn, TH1 *hd, double scale=100) const
 

Protected Attributes

std::string m_name
 
TH2F * m_hnumer
 
TH2F * m_hdenom
 
TH2F * m_hmissed
 
TH2F * m_heff
 
std::vector< int > m_ibin
 

Detailed Description

Definition at line 19 of file Efficiency2D.h.

Constructor & Destructor Documentation

◆ Efficiency2D() [1/2]

Efficiency2D::Efficiency2D ( TH2F *  h,
const std::string &  n = "" 
)
inline

Definition at line 23 of file Efficiency2D.h.

23  :
24  T_Efficiency<TH2F>( h, n ) { }

◆ Efficiency2D() [2/2]

Efficiency2D::Efficiency2D ( TH2F *  hnum,
TH2F *  hden,
const std::string &  n,
double  scale = 100 
)
inline

Definition at line 26 of file Efficiency2D.h.

26  :
27  T_Efficiency<TH2F>( hnum, hden, n, scale ) {
28  getibinvec(true);
29  finalise( scale );
30  }

◆ ~Efficiency2D()

Efficiency2D::~Efficiency2D ( )
inline

Definition at line 32 of file Efficiency2D.h.

32 { }

Member Function Documentation

◆ BayesInternal()

TGraphAsymmErrors* T_Efficiency< TH2F >::BayesInternal ( TH1 *  hn,
TH1 *  hd,
double  scale = 100 
) const
inlineprotectedinherited

stupid root, told to divide, it skips bins where the nukber of entries is 0 (ok) but then complains that "number of points is not the same as the number of bins" now that would be ok, if these were user input values, but is stupid if this is some root policy. : root decides to do X and then prints a warning so instead, set the bin contents, for these bins to something really, really, really tiny ...

root is just such a pain - can't just get/set specific y values I mean - why some functions to get an x or y value and others only get all the x values, but the functions to return the errors only get ONE AT A TIME ? why isn't there a simple ScaleX() function? All this functionality no one cares about, and basic functionality missing

Definition at line 166 of file T_Efficiency.h.

166  {
167 
176 
177  for ( int i=1 ; i<=hd->GetNbinsX() ; i++ ) { // cppcheck-suppress [ctunullpointer, nullPointer]; false positive
178  double y = hd->GetBinContent(i);
179  if ( y==0 ) hd->SetBinContent(i, 1e-20);
180  }
181 
182  TGraphAsymmErrors* tg = new TGraphAsymmErrors( hn, hd, "cl=0.683 b(1,1) mode" );
183 
184 
185  double* x = tg->GetX();
186  double* y = tg->GetY();
187 
188  int n = tg->GetN();
189 
190  for ( int i=0 ; i<n ; i++ ) {
191 
192  y[i] *= scale;
193 
194  double yeup = tg->GetErrorYhigh(i);
195  double yedown = tg->GetErrorYlow(i);
196 
197  yeup *= scale;
198  yedown *= scale;
199 
206 
207  tg->SetPoint( i, x[i], y[i] );
208 
209  tg->SetPointEYhigh( i, yeup );
210  tg->SetPointEYlow( i, yedown );
211 
212  tg->SetPointEXhigh( i, 0 );
213  tg->SetPointEXlow( i, 0 );
214 
215  }
216 
217  return tg;
218 
219  }

◆ BayesX()

TGraphAsymmErrors* Efficiency2D::BayesX ( int  slice,
double  scale = 100 
)
inline

evaluate the uncertainties correctly ...

Definition at line 49 of file Efficiency2D.h.

49  {
50 
51  if ( slice<0 || slice>=slicesX() ) return 0;
52 
53  TH1D* hn = 0;
54  TH1D* hd = 0;
55 
56  if ( m_hnumer ) {
57  // get some slice from the numerator histo
58  hn = m_hnumer->ProjectionY( slicename( name()+"_yslice", slice).c_str(), slice+1, slice+1, "e");
59  }
60 
61  if ( m_hdenom ) {
62  // get some slice from the denominator histo
63  hd = m_hdenom->ProjectionY( slicename( name()+"_yslice", slice).c_str(), slice+1, slice+1, "e");
64  }
65 
66  return BayesInternal( hn, hd, scale );
67 
68  }

◆ BayesY()

TGraphAsymmErrors* Efficiency2D::BayesY ( int  slice,
double  scale = 100 
)
inline

Definition at line 72 of file Efficiency2D.h.

72  {
73 
74  if ( slice<0 || slice>=slicesY() ) return 0;
75 
76  TH1D* hn = 0;
77  TH1D* hd = 0;
78 
79  if ( m_hnumer ) {
80  // get some slice from the numerator histo
81  hn = m_hnumer->ProjectionX( slicename( name()+"_yslice", slice).c_str(), slice+1, slice+1, "e");
82  }
83 
84  if ( m_hdenom ) {
85  // get some slice from the denominator histo
86  hd = m_hdenom->ProjectionX( slicename( name()+"_yslice", slice).c_str(), slice+1, slice+1, "e");
87  }
88 
89  return BayesInternal( hn, hd, scale );
90 
91  }

◆ Fill()

void Efficiency2D::Fill ( double  x,
double  y,
double  w = 1 
)
inline

fill methods ...

Definition at line 36 of file Efficiency2D.h.

36  {
37  m_hnumer->Fill( float(x), float(y), float(w) );
38  m_hdenom->Fill( float(x), float(y), float(w) );
39  }

◆ FillDenom()

void Efficiency2D::FillDenom ( double  x,
double  y,
float  w = 1 
)
inline

Definition at line 41 of file Efficiency2D.h.

41  {
42  m_hmissed->Fill(float(x), float(y), float(w));
43  m_hdenom->Fill(float(x), float(y), float(w));
44  }

◆ finalise()

void T_Efficiency< TH2F >::finalise ( double  scale = 100)
inlineinherited

actually calculate the efficiencies

Definition at line 71 of file T_Efficiency.h.

71  {
72  getibinvec();
73  m_heff->Reset();
74  for ( size_t i=0 ; i<m_ibin.size() ; i++ ) {
75  double n = m_hnumer->GetBinContent(m_ibin[i]);
76  double d = m_hdenom->GetBinContent(m_ibin[i]);
77 
78  double e = 0;
79  double ee = 0;
80  if ( d!=0 ) {
81  e = n/d;
82  ee = e*(1-e)/d;
83  }
84 
85  // need proper error calculation...
86  m_heff->SetBinContent( m_ibin[i], scale*e );
87  m_heff->SetBinError( m_ibin[i], scale*std::sqrt(ee) );
88 
89  }
90  }

◆ findTotalEfficiency()

double T_Efficiency< TH2F >::findTotalEfficiency
inlineinherited

these 1D and 2D Fill versionms should never be called directly in fact, are they even needed at all ?

calculate the efficiencies ...

Definition at line 131 of file T_Efficiency.h.

131  {
132 
133  getibinvec();
134 
135  double n_tot = 0;
136  double d_tot = 0;
137 
138  for ( size_t i=0 ; i<m_ibin.size() ; i++ ) {
139  double n = m_hnumer->GetBinContent(m_ibin[i]);
140  double d = m_hdenom->GetBinContent(m_ibin[i]);
141 
142  n_tot += n;
143  d_tot += d;
144  }
145 
146  if ( d_tot!=0 ) {
147  return n_tot / d_tot;
148  }
149 
150  return 0.;
151  }

◆ getibinvec()

virtual void Efficiency2D::getibinvec ( bool  force = false)
inlineprotectedvirtual

Implements T_Efficiency< TH2F >.

Definition at line 118 of file Efficiency2D.h.

118  {
119  if ( !force && !m_ibin.empty() ) return;
120  for ( int i=1 ; i<=m_hdenom->GetNbinsX() ; i++ ) {
121  for ( int j=1 ; j<=m_hdenom->GetNbinsY() ; j++ ) {
122  m_ibin.push_back( m_hdenom->GetBin(i,j) );
123  }
124  }
125  }

◆ Hist()

TH2F * T_Efficiency< TH2F >::Hist
inlineinherited

Definition at line 66 of file T_Efficiency.h.

66 { return m_heff; }

◆ name()

const std::string& T_Efficiency< TH2F >::name
inlineinherited

Definition at line 64 of file T_Efficiency.h.

64 { return m_name; }

◆ slicename()

std::string Efficiency2D::slicename ( const std::string &  s,
int  i 
) const
inlineprotected

Definition at line 128 of file Efficiency2D.h.

128  {
129  if ( i<10 ) return s + "0" + std::to_string(i);
130  else return s + std::to_string(i);
131  }

◆ slicesX()

int Efficiency2D::slicesX ( ) const
inline

Definition at line 105 of file Efficiency2D.h.

105  {
106  if ( m_hdenom ) return m_hdenom->GetXaxis()->GetNbins();
107  return 0;
108  }

◆ slicesY()

int Efficiency2D::slicesY ( ) const
inline

Definition at line 111 of file Efficiency2D.h.

111  {
112  if ( m_hdenom ) return m_hdenom->GetYaxis()->GetNbins();
113  return 0;
114  }

◆ sliceX()

TH1D* Efficiency2D::sliceX ( int  i)
inline

Definition at line 94 of file Efficiency2D.h.

94  {
95  if ( i<0 || i>=slicesX() ) return 0;
96  return m_heff->ProjectionY( slicename( name()+"_xslice", i).c_str(), i+1, i+1, "e");
97  }

◆ sliceY()

TH1D* Efficiency2D::sliceY ( int  i)
inline

Definition at line 99 of file Efficiency2D.h.

99  {
100  if ( i<0 || i>=slicesY() ) return 0;
101  return m_heff->ProjectionX( slicename( name()+"_yslice", i).c_str(), i+1, i+1, "e");
102  }

◆ Write()

void T_Efficiency< TH2F >::Write
inlineinherited

Definition at line 153 of file T_Efficiency.h.

153  {
154  m_hnumer->Write();
155  m_hdenom->Write();
156  m_hmissed->Write();
157  m_heff->Write();
158  }

Member Data Documentation

◆ m_hdenom

TH2F * T_Efficiency< TH2F >::m_hdenom
protectedinherited

Definition at line 227 of file T_Efficiency.h.

◆ m_heff

TH2F * T_Efficiency< TH2F >::m_heff
protectedinherited

Definition at line 231 of file T_Efficiency.h.

◆ m_hmissed

TH2F * T_Efficiency< TH2F >::m_hmissed
protectedinherited

Definition at line 229 of file T_Efficiency.h.

◆ m_hnumer

TH2F * T_Efficiency< TH2F >::m_hnumer
protectedinherited

Definition at line 226 of file T_Efficiency.h.

◆ m_ibin

std::vector<int> T_Efficiency< TH2F >::m_ibin
protectedinherited

Definition at line 233 of file T_Efficiency.h.

◆ m_name

std::string T_Efficiency< TH2F >::m_name
protectedinherited

Definition at line 224 of file T_Efficiency.h.


The documentation for this class was generated from the following file:
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
calibdata.force
bool force
Definition: calibdata.py:19
T_Efficiency< TH2F >::getibinvec
virtual void getibinvec(bool force=false)=0
hist_file_dump.d
d
Definition: hist_file_dump.py:137
T_Efficiency< TH2F >::m_name
std::string m_name
Definition: T_Efficiency.h:224
T_Efficiency< TH2F >::finalise
void finalise(double scale=100)
actually calculate the efficiencies
Definition: T_Efficiency.h:71
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
Efficiency2D::slicesY
int slicesY() const
Definition: Efficiency2D.h:111
x
#define x
T_Efficiency< TH2F >
T_Efficiency< TH2F >::name
const std::string & name() const
Definition: T_Efficiency.h:64
T_Efficiency< TH2F >::m_hmissed
TH2F * m_hmissed
Definition: T_Efficiency.h:229
perfmonmt-refit.slice
slice
Definition: perfmonmt-refit.py:52
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
perfmonmt-refit.n_tot
n_tot
Definition: perfmonmt-refit.py:104
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
T_Efficiency< TH2F >::m_heff
TH2F * m_heff
Definition: T_Efficiency.h:231
y
#define y
h
Efficiency2D::slicesX
int slicesX() const
Definition: Efficiency2D.h:105
T_Efficiency< TH2F >::m_ibin
std::vector< int > m_ibin
Definition: T_Efficiency.h:233
Efficiency2D::getibinvec
virtual void getibinvec(bool force=false)
Definition: Efficiency2D.h:118
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
Efficiency2D::slicename
std::string slicename(const std::string &s, int i) const
Definition: Efficiency2D.h:128
T_Efficiency< TH2F >::m_hdenom
TH2F * m_hdenom
Definition: T_Efficiency.h:227
T_Efficiency< TH2F >::BayesInternal
TGraphAsymmErrors * BayesInternal(TH1 *hn, TH1 *hd, double scale=100) const
Definition: T_Efficiency.h:166
T_Efficiency< TH2F >::m_hnumer
TH2F * m_hnumer
Definition: T_Efficiency.h:226