File indexing completed on 2024-09-07 04:37:23
0001 #ifndef BTagPerformance_h
0002 #define BTagPerformance_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include "TArrayD.h"
0013 #include "TGraph.h"
0014 #include <cassert>
0015 #include <map>
0016
0017 class BTagPerformance {
0018 public:
0019 BTagPerformance() {}
0020 void Set(std::string name) {
0021 fname = name;
0022 fNcuts = 40;
0023 b_all = c_all = udsg_all = 0;
0024 for (int i = 0; i < fNcuts; ++i) {
0025 b_tagged[i] = 0;
0026 c_tagged[i] = 0;
0027 udsg_tagged[i] = 0;
0028 }
0029 };
0030 void SetMinDiscriminator(double value) { fMinDisc = value; };
0031 void SetMaxDiscriminator(double value) { fMaxDisc = value; };
0032 void SetNcuts(int value) {
0033 fNcuts = value;
0034 for (int i = 0; i < fNcuts; ++i) {
0035 b_tagged[i] = 0;
0036 c_tagged[i] = 0;
0037 udsg_tagged[i] = 0;
0038 }
0039 };
0040 void Add(double discriminator, int flavor) {
0041 fdisc = discriminator;
0042 fflavor = flavor;
0043 double binwidth = (fMaxDisc - fMinDisc) / ((double)fNcuts);
0044 if (fflavor == 5)
0045 b_all++;
0046 if (fflavor == 4)
0047 c_all++;
0048 if ((fflavor > 0 && fflavor < 4) || (fflavor == 21))
0049 udsg_all++;
0050
0051 for (int i = 0; i < fNcuts; ++i) {
0052 double cut = i * binwidth + fMinDisc;
0053 if (cut > fMaxDisc)
0054 cut = fMaxDisc;
0055
0056 disc_map[i] = cut;
0057 if (fdisc > cut) {
0058 if (fflavor == 5)
0059 b_tagged[i]++;
0060 if (fflavor == 4)
0061 c_tagged[i]++;
0062 if ((fflavor > 0 && fflavor < 4) || (fflavor == 21))
0063 udsg_tagged[i]++;
0064 }
0065 }
0066 };
0067
0068 void Eval() {
0069 double small = 1.e-5;
0070 int ip = 0;
0071 for (std::map<int, double>::const_iterator im = b_tagged.begin(); im != b_tagged.end(); ++im) {
0072 double eff = (im->second) / ((double)b_all);
0073 double err = sqrt(eff * (1 - eff) / b_all);
0074 if (eff == 0 || eff < small) {
0075 eff = small;
0076 err = 0;
0077 }
0078 b_eff[ip] = eff;
0079 b_effErr[ip] = err;
0080
0081
0082 ip++;
0083 }
0084 ip = 0;
0085 for (std::map<int, double>::const_iterator im = c_tagged.begin(); im != c_tagged.end(); ++im) {
0086 double eff = (im->second) / ((double)c_all);
0087 double err = sqrt(eff * (1 - eff) / c_all);
0088 if (eff == 0 || eff < small) {
0089 eff = small;
0090 err = 0;
0091 }
0092 c_eff[ip] = eff;
0093 c_effErr[ip] = err;
0094
0095
0096 ip++;
0097 }
0098 ip = 0;
0099 for (std::map<int, double>::const_iterator im = udsg_tagged.begin(); im != udsg_tagged.end(); ++im) {
0100 double eff = (im->second) / ((double)udsg_all);
0101 double err = sqrt(eff * (1 - eff) / udsg_all);
0102 if (eff == 0 || eff < small) {
0103 eff = small;
0104 err = 0;
0105 }
0106 udsg_eff[ip] = eff;
0107 udsg_effErr[ip] = err;
0108
0109
0110 ip++;
0111 }
0112 };
0113 std::map<int, double> GetMap(TString option = "b") {
0114 if (option == "b")
0115 return b_eff;
0116 if (option == "c")
0117 return c_eff;
0118 if (option == "udsg")
0119 return udsg_eff;
0120 if (option == "bErr")
0121 return b_effErr;
0122 if (option == "cErr")
0123 return c_effErr;
0124 if (option == "udsgErr")
0125 return udsg_effErr;
0126 if (option == "discriminator")
0127 return disc_map;
0128 else {
0129 assert(false);
0130 return disc_map;
0131 }
0132 };
0133
0134 TArrayD GetArray(TString option = "b") {
0135 std::map<int, double> amap = GetMap(option);
0136 TArrayD tarray(fNcuts);
0137 for (std::map<int, double>::const_iterator im = amap.begin(); im != amap.end(); ++im) {
0138
0139 tarray[im->first] = im->second;
0140 }
0141 return tarray;
0142 };
0143
0144 int GetN() { return fNcuts; };
0145
0146 double Getb_all() { return b_all; };
0147 double Getc_all() { return c_all; };
0148 double Getudsg_all() { return udsg_all; };
0149
0150 private:
0151 Double_t *farray;
0152 double fdisc;
0153 int fflavor;
0154 double fMinDisc;
0155 double fMaxDisc;
0156 int fNcuts;
0157 std::string fname;
0158
0159
0160 std::map<int, double> b_eff;
0161 std::map<int, double> c_eff;
0162 std::map<int, double> udsg_eff;
0163 std::map<int, double> b_effErr;
0164 std::map<int, double> c_effErr;
0165 std::map<int, double> udsg_effErr;
0166 std::map<int, double> disc_map;
0167
0168 std::map<int, double> b_tagged;
0169 std::map<int, double> c_tagged;
0170 std::map<int, double> udsg_tagged;
0171 double b_all;
0172 double c_all;
0173 double udsg_all;
0174 };
0175
0176 #endif