|
DAS
3.0
Das Analysis System
|
|
void | applyBTagSF (const vector< fs::path > &inputs, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0}) |
|
vector< double > | GetDeepJetEdges (int year, bool HIPM=false) |
|
void | getBTagBinnedDiscriminant (const vector< fs::path > &inputs, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0}) |
|
void | getBTagFraction (const vector< fs::path > &inputs, const fs::path &output, const int steering) |
|
void | getBTagPerformance (const vector< fs::path > &inputs, const fs::path &output, const int steering) |
|
◆ applyBTagSF()
void DAS::BTagging::applyBTagSF |
( |
const vector< fs::path > & |
inputs, |
|
|
const fs::path & |
output, |
|
|
const pt::ptree & |
config, |
|
|
const int |
steering, |
|
|
const DT::Slice |
slice = {1,0} |
|
) |
| |
Apply the multi-WP calibration with fix-WPs tables.
- Parameters
-
inputs | input ROOT files (n-tuples) |
output | output ROOT file (n-tuple) |
config | config handled with `Darwin::Tools::options` |
steering | parameters obtained from explicit options |
slice | number and index of slice |
123 cout << __func__ <<
' ' << slice <<
" start" << endl;
126 auto tIn = flow.GetInputTree(
inputs, slice);
127 auto tOut = flow.GetOutputTree(output);
131 auto isMC = metainfo.Get<
bool>(
"flags",
"isMC");
132 if (!
isMC) BOOST_THROW_EXCEPTION(
DE::BadInput(
"Only MC may be used as input.",
133 make_unique<TFile>(
inputs.front().c_str() )) );
134 auto R = metainfo.Get<
int>(
"flags",
"R");
135 if (R != 4) BOOST_THROW_EXCEPTION(
DE::BadInput(
"Only AK4 jets may be used.",
136 make_unique<TFile>(
inputs.front().c_str() )) );
138 auto recJets = flow.GetBranchReadWrite<vector<RecJet>>(
"recJets");
141 BOOST_THROW_EXCEPTION( logic_error(
"B-tagging variations not yet implemented\n") );
143 auto discriminant =
config.get<fs::path>(
"corrections.btagging.discriminant"),
144 SFtables =
config.get<fs::path>(
"corrections.btagging.SFtables");
145 JetWeight
w(SFtables, discriminant);
147 metainfo.Set<fs::path>(
"corrections",
"btagging",
"discriminant", discriminant);
148 metainfo.Set<fs::path>(
"corrections",
"btagging",
"SFtables" , SFtables );
150 for (
DT::Looper looper(tIn); looper(); ++looper) {
154 for (
auto& jet: *recJets)
155 jet.weights *=
w(jet);
157 if (steering &
DT::fill) tOut->Fill();
160 metainfo.Set<
bool>(
"git",
"complete",
true);
162 cout << __func__ <<
' ' << slice <<
" stop" << endl;
◆ getBTagBinnedDiscriminant()
void DAS::BTagging::getBTagBinnedDiscriminant |
( |
const vector< fs::path > & |
inputs, |
|
|
const fs::path & |
output, |
|
|
const pt::ptree & |
config, |
|
|
const int |
steering, |
|
|
const DT::Slice |
slice = {1,0} |
|
) |
| |
Get B-tagged binned discriminant in bins of pt, true flavour, and discriminant value. Works for both data and MC (although in the case of data, the true flavour is always trivial).
- Todo:
- GSP?
- Todo:
- loop over variations
- Todo:
- gen event weight
- Parameters
-
inputs | input ROOT files (n-tuples) |
output | output ROOT file (n-tuple) |
config | config handled with `Darwin::Tools::options` |
steering | parameters obtained from explicit options |
slice | number and index of slice |
62 cout << __func__ <<
' ' << slice <<
" start" << endl;
65 auto tIn = flow.GetInputTree(
inputs, slice);
66 auto [fOut, tOut] = flow.GetOutput(output);
71 auto year = metainfo.Get<
int>(
"flags",
"year");
72 bool HIPM = metainfo.Find(
"flags",
"labels");
73 if (HIPM &&
year != 2016)
74 cerr <<
orange <<
"The HIPM label may only be used for 2016 samples. It will be just ignored for other years.\n" <<
def;
76 const vector<double> flavour_edges = {0.5, 1.5, 2.5, 3.5, 4.5, 5.5},
78 const int nFlBins = flavour_edges.size()-1,
79 nDiscBins = disc_edges.size()-1;
80 auto discriminant = make_unique<TH3D>(
"discriminant",
"B-tag discriminant",
82 nFlBins, flavour_edges.data(),
83 nDiscBins, disc_edges.data());
86 BOOST_THROW_EXCEPTION( logic_error(
"B-tagging variations not yet implemented\n") );
89 auto recEvent = flow.GetBranchReadOnly<RecEvent>(
"recEvent");
90 auto recJets = flow.GetBranchReadOnly<vector<RecJet>>(
"recJets");
92 for (
DT::Looper looper(tIn); looper(); ++looper) {
98 auto evWgt = recEvent->weights.front();
102 for (
const RecJet& jet: *recJets) {
103 auto jWgt = jet.weights.front();
104 discriminant->Fill(jet.CorrPt(), jet.hadronFlavour(), jet.DeepJet.B(), jWgt*evWgt);
109 discriminant->SetDirectory(fOut);
110 discriminant->Write();
111 metainfo.Set<
bool>(
"git",
"complete",
true);
113 cout << __func__ <<
' ' << slice <<
" stop" << endl;
◆ getBTagFraction()
void DAS::BTagging::getBTagFraction |
( |
const vector< fs::path > & |
inputs, |
|
|
const fs::path & |
output, |
|
|
const int |
steering |
|
) |
| |
Extract the B-tagged fraction from the output of getBTagDiscriminant
. Works for both data and MC.
- Parameters
-
inputs | input ROOT files (histograms) |
output | output ROOT file (histograms) |
steering | parameters obtained from explicit options |
40 cout << __func__ <<
" start" << endl;
42 unique_ptr<TH3> hIn = DT::GetHist<TH3>(
inputs,
"discriminant");
43 if (hIn->GetNbinsZ() != 4) {
44 const char * what = Form(
"Found %d working points (expecting 4)", hIn->GetNbinsZ());
51 return unique_ptr<TH1>( hIn->ProjectionX(
name, 0, -1, bin, 4) );
54 auto hIncl =
project(
"inclusive", 1);
55 int im = hIncl->FindBin(22),
56 iM = hIncl->GetNbinsX();
57 auto integrate = [im,iM](
const unique_ptr<TH1>& h) {
58 return h->Integral(im, iM);
60 double sum = integrate(hIncl);
62 map<TString, int> WPs { {
"loose", 2}, {
"medium", 3}, {
"tight", 4} };
63 for (
const auto& WP: WPs) {
64 auto h =
project(WP.first, WP.second);
65 h->SetTitle(
"B-tagged jet fraction for " + WP.first +
" working point");
66 cout << h->GetTitle() <<
": " << integrate(h)/sum << endl;
67 h->Divide(h.get(), hIncl.get(), 1, 1,
"b");
71 cout << __func__ <<
" stop" << endl;
◆ getBTagPerformance()
void DAS::BTagging::getBTagPerformance |
( |
const vector< fs::path > & |
inputs, |
|
|
const fs::path & |
output, |
|
|
const int |
steering |
|
) |
| |
Extract the B-tagged performance from the output of getBTagBinnedDiscriminant
. The B-tagging efficiency and mistag rates are calculated.
- Todo:
- crash if under- or overflow non-empty
- Parameters
-
inputs | input ROOT files (histograms) |
output | output ROOT file (histograms) |
steering | parameters obtained from explicit options |
40 cout << __func__ <<
" start" << endl;
42 unique_ptr<TH3> hIn = DT::GetHist<TH3>(
inputs,
"discriminant");
43 if (hIn->GetNbinsZ() != 4) {
44 const char * what = Form(
"Found %d working points (expecting 4)", hIn->GetNbinsZ());
50 map<TString, int> flavours { {
"light" , 0}, {
"charm" , 4}, {
"bottom", 5} };
51 map<TString, int> WPs { {
"loose", 2}, {
"medium", 3}, {
"tight", 4} };
52 for (
const auto& WP: WPs) {
54 int tagBin = WP.second;
56 auto hIncl = unique_ptr<TH1>( hIn->ProjectionX(
"inclusive", 0, -1, tagBin, 4) );
58 for (
const auto&
flavour: flavours) {
64 auto h = unique_ptr<TH1>( hIn->ProjectionX(
name, flBin, flBin, tagBin, 4) );
65 TString title =
flavour.first +
" for " + WP.first +
" working point";
66 cout << title << endl;
68 h->Divide(h.get(), hIncl.get(), 1, 1,
"b");
75 cout << __func__ <<
" stop" << endl;
◆ GetDeepJetEdges()
vector<double> DAS::BTagging::GetDeepJetEdges |
( |
int |
year, |
|
|
bool |
HIPM = false |
|
) |
| |
Working points provided by BTV for Full-Run-2 Ultra-Legacy samples.
Reference: Wiki
38 if (HIPM)
return { 0., 0.0508, 0.2598, 0.6502, 1. };
39 else return { 0., 0.0480, 0.2489, 0.6377, 1. };
41 return {0., 0.0532, 0.3040, 0.7476, 1.};
43 return {0., 0.0490, 0.2783, 0.7100, 1.};
45 const char * what = Form(
"The year %d is currently not supported",
year);
46 BOOST_THROW_EXCEPTION( invalid_argument(what) );
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
cerr
Definition: Ntupliser_cfg.py:93
static bool verbose
Definition: Step.h:40
static const char * def
Definition: Step.h:36
int year
Definition: Ntupliser_cfg.py:63
string flavour
Definition: Ntupliser_cfg.py:42
static const std::vector< double > pt_edges
Definition: binnings.h:33
static const float w
Definition: common.h:51
vector< double > GetDeepJetEdges(int year, bool HIPM=false)
Definition: getBTagBinnedDiscriminant.cc:34
config
Definition: Ntupliser_cfg.py:260
static const char * orange
Definition: colours.h:6
static const int nPtBins
Definition: binnings.h:39
string isMC
Definition: Ntupliser_cfg.py:59
def inputs
Definition: jercExample.py:118