Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-28 04:15:49

0001 #include <assert.h>
0002 #include <iostream>
0003 #include <string>
0004 #include <TF1.h>
0005 #include <TH1F.h>
0006 
0007 #include "CondFormats/BTauObjects/src/headers.h"
0008 
0009 int main() {
0010   using namespace std;
0011 
0012   auto par1 = BTagEntry::Parameters(BTagEntry::OP_TIGHT, "CoMb", "cEnTrAl_");
0013   assert(par1.measurementType == std::string("comb"));
0014   assert(par1.sysType == string("central_"));
0015 
0016   // default constructor
0017   auto b1 = BTagEntry();
0018 
0019   // function constructor
0020   auto f1 = TF1("", "[0]*x");
0021   f1.SetParameter(0, 2);
0022   auto b2 = BTagEntry(&f1, BTagEntry::Parameters(BTagEntry::OP_TIGHT, "comb", "up", BTagEntry::FLAV_C));
0023   assert(b2.formula == string("2*x"));
0024 
0025   // histo constructor
0026   auto h1 = TH1F("h1", "", 3, 0., 1.);    // lin.
0027   auto h2 = TH1F("h2", "", 100, 0., 1.);  // bin. tree
0028   auto sin = TF1("sin", "sin(x)");
0029   for (float f = 0.01f; f < 1.f; f += .01f) {
0030     h1.Fill(f, sin.Eval(f) / 30.);
0031     h2.Fill(f, sin.Eval(f));
0032   }
0033   auto f3_1 = TF1("", BTagEntry(&h1, par1).formula.c_str());
0034   auto f3_2 = TF1("", BTagEntry(&h2, par1).formula.c_str());
0035   for (float f = 0.01f; f < 1.f; f += .01f) {
0036     assert(fabs(h1.GetBinContent(h1.FindBin(f)) - f3_1.Eval(f)) < 1e-5);
0037     assert(fabs(h2.GetBinContent(h2.FindBin(f)) - f3_2.Eval(f)) < 1e-5);
0038   }
0039 
0040   // csv constructor
0041   string csv = "0, comb, up, 0, 1, 2, 3, 4, 5, 6, \"2*x\" \n";
0042   auto b4 = BTagEntry(csv, true);
0043   auto csv2 = b4.makeCSVLine();
0044   assert(b4.params.etaMin == 1);
0045   assert(b4.params.etaMax == 2);
0046   assert(b4.params.ptMin == 3);
0047   assert(b4.params.ptMax == 4);
0048   assert(b4.params.discrMin == 5);
0049   assert(b4.params.discrMax == 6);
0050   assert(csv == csv2);
0051 
0052   return 0;
0053 }