CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Friends
BTagEntry Class Reference

#include <BTagEntry.h>

Classes

struct  Parameters
 

Public Types

enum  JetFlavor { FLAV_B =0, FLAV_C =1, FLAV_UDSG =2 }
 
enum  OperatingPoint { OP_LOOSE =0, OP_MEDIUM =1, OP_TIGHT =2, OP_RESHAPING =3 }
 

Public Member Functions

 BTagEntry ()
 
 BTagEntry (const std::string &csvLine)
 
 BTagEntry (const std::string &func, Parameters p)
 
 BTagEntry (const TF1 *func, Parameters p)
 
 BTagEntry (const TH1 *histo, Parameters p)
 
std::string makeCSVLine () const
 
 ~BTagEntry ()
 

Static Public Member Functions

static std::string makeCSVHeader ()
 
static std::string trimStr (std::string str)
 

Public Attributes

std::string formula
 
Parameters params
 

Private Member Functions

template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Friends

class boost::serialization::access
 
template<typename CondSerializationT , typename Enabled >
struct cond::serialization::access
 

Detailed Description

BTagEntry

Represents one pt- or discriminator-dependent calibration function.

measurement_type: e.g. comb, ttbar, di-mu, boosted, ... sys_type: e.g. central, plus, minus, plus_JEC, plus_JER, ...

Everything is converted into a function, as it is easiest to store it in a txt or json file.

Definition at line 24 of file BTagEntry.h.

Member Enumeration Documentation

Enumerator
FLAV_B 
FLAV_C 
FLAV_UDSG 

Definition at line 33 of file BTagEntry.h.

33  {
34  FLAV_B=0,
35  FLAV_C=1,
36  FLAV_UDSG=2,
37  };
Enumerator
OP_LOOSE 
OP_MEDIUM 
OP_TIGHT 
OP_RESHAPING 

Definition at line 27 of file BTagEntry.h.

Constructor & Destructor Documentation

BTagEntry::BTagEntry ( )
inline

Definition at line 67 of file BTagEntry.h.

67 {}
BTagEntry::BTagEntry ( const std::string &  csvLine)

Definition at line 36 of file BTagEntry.cc.

References begin, end, Exception, python.connectstrParser::f1, formula, i, params, AlCaHLTBitMon_QueryRunRegistry::string, and trimStr().

37 {
38  // make tokens
39  std::stringstream buff(csvLine);
40  std::vector<std::string> vec;
41  std::string token;
42  while (std::getline(buff, token, ","[0])) {
43  token = BTagEntry::trimStr(token);
44  if (token.empty()) {
45  continue;
46  }
47  vec.push_back(token);
48  }
49  if (vec.size() != 11) {
50  throw cms::Exception("BTagCalibration")
51  << "Invalid csv line; num tokens != 11: "
52  << csvLine;
53  }
54 
55  // clean string values
56  char chars[] = " \"\n";
57  for (unsigned int i = 0; i < strlen(chars); ++i) {
58  vec[1].erase(remove(vec[1].begin(),vec[1].end(),chars[i]),vec[1].end());
59  vec[2].erase(remove(vec[2].begin(),vec[2].end(),chars[i]),vec[2].end());
60  vec[10].erase(remove(vec[10].begin(),vec[10].end(),chars[i]),vec[10].end());
61  }
62 
63  // make formula
64  formula = vec[10];
65  TF1 f1("", formula.c_str()); // compile formula to check validity
66  if (f1.IsZombie()) {
67  throw cms::Exception("BTagCalibration")
68  << "Invalid csv line; formula does not compile: "
69  << csvLine;
70  }
71 
72  // make parameters
73  unsigned op = stoi(vec[0]);
74  if (op > 3) {
75  throw cms::Exception("BTagCalibration")
76  << "Invalid csv line; OperatingPoint > 3: "
77  << csvLine;
78  }
79  unsigned jf = stoi(vec[3]);
80  if (jf > 2) {
81  throw cms::Exception("BTagCalibration")
82  << "Invalid csv line; JetFlavor > 2: "
83  << csvLine;
84  }
87  vec[1],
88  vec[2],
90  stof(vec[4]),
91  stof(vec[5]),
92  stof(vec[6]),
93  stof(vec[7]),
94  stof(vec[8]),
95  stof(vec[9])
96  );
97 }
int i
Definition: DBlmapReader.cc:9
static std::string trimStr(std::string str)
Definition: BTagEntry.cc:251
vector< ParameterSet > Parameters
std::string formula
Definition: BTagEntry.h:78
#define end
Definition: vmac.h:37
OperatingPoint
Definition: BTagEntry.h:27
Parameters params
Definition: BTagEntry.h:79
#define begin
Definition: vmac.h:30
BTagEntry::BTagEntry ( const std::string &  func,
BTagEntry::Parameters  p 
)

Definition at line 99 of file BTagEntry.cc.

References Exception, python.connectstrParser::f1, and formula.

99  :
100  formula(func),
101  params(p)
102 {
103  TF1 f1("", formula.c_str()); // compile formula to check validity
104  if (f1.IsZombie()) {
105  throw cms::Exception("BTagCalibration")
106  << "Invalid func string; formula does not compile: "
107  << func;
108  }
109 }
std::string formula
Definition: BTagEntry.h:78
Parameters params
Definition: BTagEntry.h:79
BTagEntry::BTagEntry ( const TF1 *  func,
BTagEntry::Parameters  p 
)

Definition at line 111 of file BTagEntry.cc.

References Exception.

111  :
112  formula(std::string(func->GetExpFormula("p").Data())),
113  params(p)
114 {
115  if (func->IsZombie()) {
116  throw cms::Exception("BTagCalibration")
117  << "Invalid TF1 function; function is zombie: "
118  << func->GetName();
119  }
120 }
std::string formula
Definition: BTagEntry.h:78
Parameters params
Definition: BTagEntry.h:79
BTagEntry::BTagEntry ( const TH1 *  histo,
BTagEntry::Parameters  p 
)

Definition at line 186 of file BTagEntry.cc.

References BTagEntry::Parameters::discrMax, BTagEntry::Parameters::discrMin, Exception, python.connectstrParser::f1, formula, pileupCalc::nbins, OP_RESHAPING, BTagEntry::Parameters::operatingPoint, params, BTagEntry::Parameters::ptMax, BTagEntry::Parameters::ptMin, th1ToFormulaBinTree(), and th1ToFormulaLin().

186  :
187  params(p)
188 {
189  int nbins = hist->GetNbinsX();
190  TAxis const* axis = hist->GetXaxis();
191 
192  // overwrite bounds with histo values
194  params.discrMin = axis->GetBinLowEdge(1);
195  params.discrMax = axis->GetBinUpEdge(nbins);
196  } else {
197  params.ptMin = axis->GetBinLowEdge(1);
198  params.ptMax = axis->GetBinUpEdge(nbins);
199  }
200 
201  // balanced full binary tree height = ceil(log(2*n_leaves)/log(2))
202  // breakes even around 10, but lower values are more propable in pt-spectrum
203  if (nbins < 15) {
205  } else {
207  }
208 
209  // compile formula to check validity
210  TF1 f1("", formula.c_str());
211  if (f1.IsZombie()) {
212  throw cms::Exception("BTagCalibration")
213  << "Invalid histogram; formula does not compile (>150 bins?): "
214  << hist->GetName();
215  }
216 }
std::string th1ToFormulaBinTree(const TH1 *hist, int start=0, int end=-1)
Definition: BTagEntry.cc:145
std::string th1ToFormulaLin(const TH1 *hist)
Definition: BTagEntry.cc:125
OperatingPoint operatingPoint
Definition: BTagEntry.h:39
std::string formula
Definition: BTagEntry.h:78
Parameters params
Definition: BTagEntry.h:79
BTagEntry::~BTagEntry ( )
inline

Definition at line 72 of file BTagEntry.h.

72 {}

Member Function Documentation

std::string BTagEntry::makeCSVHeader ( )
static

Definition at line 218 of file BTagEntry.cc.

Referenced by BTagCalibration::makeCSV().

219 {
220  return "OperatingPoint, "
221  "measurementType, "
222  "sysType, "
223  "jetFlavor, "
224  "etaMin, "
225  "etaMax, "
226  "ptMin, "
227  "ptMax, "
228  "discrMin, "
229  "discrMax, "
230  "formula \n";
231 }
std::string BTagEntry::makeCSVLine ( ) const

Definition at line 233 of file BTagEntry.cc.

References BTagEntry::Parameters::discrMax, BTagEntry::Parameters::discrMin, BTagEntry::Parameters::etaMax, BTagEntry::Parameters::etaMin, formula, BTagEntry::Parameters::jetFlavor, BTagEntry::Parameters::measurementType, BTagEntry::Parameters::operatingPoint, params, BTagEntry::Parameters::ptMax, BTagEntry::Parameters::ptMin, and BTagEntry::Parameters::sysType.

234 {
235  std::stringstream buff;
236  buff << params.operatingPoint
237  << ", " << params.measurementType
238  << ", " << params.sysType
239  << ", " << params.jetFlavor
240  << ", " << params.etaMin
241  << ", " << params.etaMax
242  << ", " << params.ptMin
243  << ", " << params.ptMax
244  << ", " << params.discrMin
245  << ", " << params.discrMax
246  << ", \"" << formula
247  << "\" \n";
248  return buff.str();
249 }
std::string sysType
Definition: BTagEntry.h:41
JetFlavor jetFlavor
Definition: BTagEntry.h:42
OperatingPoint operatingPoint
Definition: BTagEntry.h:39
std::string formula
Definition: BTagEntry.h:78
Parameters params
Definition: BTagEntry.h:79
std::string measurementType
Definition: BTagEntry.h:40
template<class Archive >
void BTagEntry::serialize ( Archive &  ar,
const unsigned int  version 
)
private
std::string BTagEntry::trimStr ( std::string  str)
static

Definition at line 251 of file BTagEntry.cc.

References alignCSCRings::e, and alignCSCRings::s.

Referenced by BTagEntry(), and BTagCalibration::readCSV().

251  {
252  size_t s = str.find_first_not_of(" \n\r\t");
253  size_t e = str.find_last_not_of (" \n\r\t");
254 
255  if((std::string::npos == s) || (std::string::npos == e))
256  return "";
257  else
258  return str.substr(s, e-s+1);
259 }

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 81 of file BTagEntry.h.

template<typename CondSerializationT , typename Enabled >
friend struct cond::serialization::access
friend

Definition at line 81 of file BTagEntry.h.

Member Data Documentation

std::string BTagEntry::formula

Definition at line 78 of file BTagEntry.h.

Referenced by BTagEntry(), makeCSVLine(), and BTagCalibrationReader::setupTmpData().

Parameters BTagEntry::params