Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <cassert>
0002 #include <iostream>
0003 #include <sstream>
0004 #include <string>
0005 
0006 #include "CondFormats/BTauObjects/interface/BTagEntry.h"
0007 #include "CondFormats/BTauObjects/interface/BTagCalibration.h"
0008 #include "CondTools/BTau/interface/BTagCalibrationReader.h"
0009 
0010 static bool eq(float a, float b, float prec = 1e-8) {
0011   float d = a - b;
0012   float d2 = d * d;
0013   return (d2 < prec);
0014 }
0015 
0016 int main() {
0017   using namespace std;
0018 
0019   string csv1(
0020       "0, comb, central, 0, 0, 1, 0, 1, 0, 999, \"2*x\" \n"
0021       "0, comb, central, 0, 0, 1, 1, 2, 0, 999, \"2*x\" \n"
0022       "0, comb, central, 0, 1, 2, 0, 1, 0, 999, \"-2*x\" \n"
0023       "0, comb, central, 0, 1, 2, 1, 2, 0, 999, \"-2*x\" \n"
0024       "3, comb, central, 0, 0, 1, 0, 1, 2, 3, \"2*x\" \n"
0025       "3, comb, central, 0, -1, 0, 0, 1, 2, 3, \"-2*x\" \n"
0026       "1, test, central, 1, -2, 2, 50, 500, 0, 999, \"2*x\" \n"
0027       "1, test, up,      1, -2, 2, 50, 500, 0, 999, \"2.1*x\" \n"
0028       "1, test, down,    1, -2, 2, 50, 500, 0, 999, \"1.9*x\" \n");
0029   stringstream csv1Stream(csv1);
0030   BTagCalibration bc1("csv");
0031   bc1.readCSV(csv1Stream, true);
0032 
0033   // test pt-dependent function
0034   BTagCalibrationReader bcr1(BTagEntry::OP_LOOSE);
0035   bcr1.load(bc1, BTagEntry::FLAV_B, "comb");
0036   assert(eq(bcr1.eval(BTagEntry::FLAV_B, 3.0, 1.5), 0.));  // out of range
0037   assert(eq(bcr1.eval(BTagEntry::FLAV_B, 1.5, 3.0), 0.));  // out of range
0038   assert(eq(bcr1.eval(BTagEntry::FLAV_B, 0.5, 0.5), 1.));
0039   assert(eq(bcr1.eval(BTagEntry::FLAV_B, 0.5, 1.5), 3.));
0040   assert(eq(bcr1.eval(BTagEntry::FLAV_B, 1.5, 0.5), -1.));
0041   assert(eq(bcr1.eval(BTagEntry::FLAV_B, 1.5, 1.5), -3.));
0042   assert(eq(bcr1.eval(BTagEntry::FLAV_B, -1.5, 1.5), -3.));  // abseta
0043 
0044   // test discr-dependent function
0045   BTagCalibrationReader bcr2(BTagEntry::OP_RESHAPING);
0046   bcr2.load(bc1, BTagEntry::FLAV_B, "comb");
0047   assert(eq(bcr2.eval(BTagEntry::FLAV_B, 0.5, 0.5, 1.0), 0.));
0048   assert(eq(bcr2.eval(BTagEntry::FLAV_B, 0.5, 0.5, 4.0), 0.));
0049   assert(eq(bcr2.eval(BTagEntry::FLAV_B, 0.5, 0.5, 2.5), 5.));
0050   assert(eq(bcr2.eval(BTagEntry::FLAV_B, -0.5, 0.5, 2.5), -5.));  // no abseta
0051 
0052   // test auto bounds
0053   BTagCalibrationReader bcr3(BTagEntry::OP_MEDIUM, "central", {"up", "down"});
0054   bcr3.load(bc1, BTagEntry::FLAV_C, "test");
0055   assert(eq(bcr3.eval_auto_bounds("central", BTagEntry::FLAV_C, 0.5, 100.), 200., 1e-3));
0056   assert(eq(bcr3.eval_auto_bounds("up", BTagEntry::FLAV_C, 0.5, 100.), 210., 1e-3));
0057   assert(eq(bcr3.eval_auto_bounds("down", BTagEntry::FLAV_C, 0.5, 100.), 190., 1e-3));
0058   assert(eq(bcr3.eval_auto_bounds("central", BTagEntry::FLAV_C, 0.5, 20.), 100., 1e-3));    // low pt
0059   assert(eq(bcr3.eval_auto_bounds("up", BTagEntry::FLAV_C, 0.5, 20.), 110., 1e-3));         // low pt
0060   assert(eq(bcr3.eval_auto_bounds("down", BTagEntry::FLAV_C, 0.5, 20.), 90., 1e-3));        // low pt
0061   assert(eq(bcr3.eval_auto_bounds("central", BTagEntry::FLAV_C, 0.5, 999.), 1000., 1e-3));  // high pt
0062   assert(eq(bcr3.eval_auto_bounds("up", BTagEntry::FLAV_C, 0.5, 999.), 1100., 1e-3));       // high pt
0063   assert(eq(bcr3.eval_auto_bounds("down", BTagEntry::FLAV_C, 0.5, 999.), 900., 1e-3));      // high pt
0064   assert(eq(bcr3.eval_auto_bounds("central", BTagEntry::FLAV_C, 2.5, 100.), 1., 1e-3));     // eta out of bounds
0065   assert(eq(bcr3.eval_auto_bounds("up", BTagEntry::FLAV_C, 2.5, 100.), 1., 1e-3));          // eta out of bounds
0066   assert(eq(bcr3.eval_auto_bounds("down", BTagEntry::FLAV_C, 2.5, 100.), 1., 1e-3));        // eta out of bounds
0067   assert(eq(bcr3.eval_auto_bounds("central", BTagEntry::FLAV_C, -2.5, 100.), 1., 1e-3));    // eta out of bounds
0068   assert(eq(bcr3.eval_auto_bounds("up", BTagEntry::FLAV_C, -2.5, 100.), 1., 1e-3));         // eta out of bounds
0069   assert(eq(bcr3.eval_auto_bounds("down", BTagEntry::FLAV_C, -2.5, 100.), 1., 1e-3));       // eta out of bounds
0070 
0071   return 0.;
0072 }