DAS  3.0
Das Analysis System
BTagCalibration.cc File Reference
#include "Core/BTagging/interface/BTagCalibration.h"
#include <iostream>
#include <exception>
#include <algorithm>
#include <sstream>
#include <fstream>
+ Include dependency graph for BTagCalibration.cc:

Classes

class  BTagCalibrationReader::BTagCalibrationReaderImpl
 
struct  BTagCalibrationReader::BTagCalibrationReaderImpl::TmpEntry
 

Functions

std::string th1ToFormulaLin (const TH1 *hist)
 
std::string th1ToFormulaBinTree (const TH1 *hist, int start=0, int end=-1)
 

Function Documentation

◆ th1ToFormulaBinTree()

std::string th1ToFormulaBinTree ( const TH1 *  hist,
int  start = 0,
int  end = -1 
)
154  {
155  if (end == -1) { // initialize
156  start = 0.;
157  end = hist->GetNbinsX()+1;
158  TH1* h2 = (TH1*) hist->Clone();
159  h2->SetBinContent(start, 0); // kill underflow
160  h2->SetBinContent(end, 0); // kill overflow
161  std::string res = th1ToFormulaBinTree(h2, start, end);
162  delete h2;
163  return res;
164  }
165  if (start == end) { // leave is reached
166  char tmp_buff[20];
167  sprintf(tmp_buff, "%g", hist->GetBinContent(start));
168  return std::string(tmp_buff);
169  }
170  if (start == end - 1) { // no parenthesis for neighbors
171  char tmp_buff[70];
172  sprintf(tmp_buff,
173  "x<%g ? %g:%g",
174  hist->GetXaxis()->GetBinUpEdge(start),
175  hist->GetBinContent(start),
176  hist->GetBinContent(end));
177  return std::string(tmp_buff);
178  }
179 
180  // top-down recursion
181  std::stringstream buff;
182  int mid = (end-start)/2 + start;
183  char tmp_buff[25];
184  sprintf(tmp_buff,
185  "x<%g ? (",
186  hist->GetXaxis()->GetBinUpEdge(mid));
187  buff << tmp_buff
188  << th1ToFormulaBinTree(hist, start, mid)
189  << ") : ("
190  << th1ToFormulaBinTree(hist, mid+1, end)
191  << ")";
192  return buff.str();
193 }

◆ th1ToFormulaLin()

std::string th1ToFormulaLin ( const TH1 *  hist)
134  {
135  int nbins = hist->GetNbinsX();
136  TAxis const* axis = hist->GetXaxis();
137  std::stringstream buff;
138  buff << "x<" << axis->GetBinLowEdge(1) << " ? 0. : "; // default value
139  for (int i=1; i<nbins+1; ++i) {
140  char tmp_buff[50];
141  sprintf(tmp_buff,
142  "x<%g ? %g : ", // %g is the smaller one of %e or %f
143  axis->GetBinUpEdge(i),
144  hist->GetBinContent(i));
145  buff << tmp_buff;
146  }
147  buff << 0.; // default value
148  return buff.str();
149 }
th1ToFormulaBinTree
std::string th1ToFormulaBinTree(const TH1 *hist, int start=0, int end=-1)
Definition: BTagCalibration.cc:154