16 #include "TObjArray.h"
17 #include "TObjString.h"
43 :
asg::AsgTool(
name ), m_acceptinfo(
"JetSelection" )
49 declareProperty(
"FlvTagCutDefinitionsFileName",
m_CutFileName =
"",
"name of the files containing official cut definitions (uses PathResolver)");
53 declareProperty(
"WorkingPointDefinitions",
m_wps_raw=
"FixedCutBEff_85,FixedCutBEff_77,FixedCutBEff_70,FixedCutBEff_60",
"Comma-separated list of tagger working points (in decreasing order of efficiency!) - required for 1D tagging purposes");
54 declareProperty(
"ErrorOnTagWeightFailure",
m_ErrorOnTagWeightFailure=
true,
"optionally ignore cases where the tagweight cannot be retrived. default behaviour is to give an error, switching to false will turn it into a warning");
56 declareProperty(
"useCTagging",
m_useCTag=
false,
"Enabled only for FixedCut or Continuous WPs: define wether the cuts refer to b-tagging or c-tagging");
63 ATH_MSG_ERROR(
"BTaggingSelectionTool wasn't given a working point name" );
64 return StatusCode::FAILURE;
68 m_inf = TFile::Open(pathtofile,
"read");
70 ATH_MSG_ERROR(
"BTaggingSelectionTool couldn't access tagging cut definitions" );
71 return StatusCode::FAILURE;
76 if(!
m_inf->Get(check_CDI)){
78 return StatusCode::FAILURE;
81 if(!
m_inf->Get(check_CDI)){
83 return StatusCode::FAILURE;
90 if((
m_jetAuthor.find(
"AntiKt2PV0TrackJets") != std::string::npos) ||
91 (
m_jetAuthor.find(
"AntiKt4PV0TrackJets") != std::string::npos) ||
92 (
m_jetAuthor.find(
"AntiKtVR30Rmax4Rmin02TrackJets") != std::string::npos)) {
99 return StatusCode::FAILURE;
103 TString cutname =
m_OP;
107 if(cutname.Contains(
"Continuous2D")){
114 TMatrixD*
matrix = (TMatrixD*)
m_inf->Get(cutname);
128 TVector *fraction_data = (TVector*)
m_inf->Get(fraction_data_name);
129 if(fraction_data!=
nullptr)
132 ATH_MSG_ERROR(
"Tagger fraction_b in Continuous2D WP not available");
136 fraction_data = (TVector*)
m_inf->Get(fraction_data_name);
137 if(fraction_data!=
nullptr){
140 ATH_MSG_ERROR(
"Tagger fraction_c in Continuous2D WP not available");
143 else if (
"Continuous"==cutname(0,10)){
149 m_wps_raw=
"FixedCutBEff_90,FixedCutBEff_85,FixedCutBEff_77,FixedCutBEff_70,FixedCutBEff_65";
151 std::sort(workingpoints.begin(), workingpoints.end());
152 std::reverse(workingpoints.begin(), workingpoints.end());
153 for(
const std::string&
wp : workingpoints){
159 ATH_MSG_ERROR(
"Continuous tagging is trying to use an invalid operating point: " +
wp );
176 std::vector<int> tag_benchmarks;
177 for (
const std::string& tagbin : tag_benchmarks_names){
178 tag_benchmarks.push_back(
std::atoi(tagbin.c_str()));
179 ATH_MSG_INFO(
"adding " <<tag_benchmarks.back() <<
" as tagged bin ");
187 m_acceptinfo.
addCut(
"Pt",
"Selection of jets according to their transverse momentum" );
188 m_acceptinfo.
addCut(
"WorkingPoint",
"Working point for flavour-tagging of jets according to their b-tagging weight" );
190 return StatusCode::SUCCESS;
195 TString cutname = OP;
198 tagger.
name = taggerName;
200 if (
"FlatBEff"==cutname(0,8) ||
"HybBEff"==cutname(0,7) ){
201 cutname = taggerName+
"/"+
m_jetAuthor+
"/"+OP+
"/cutprofile";
207 cutname = taggerName+
"/"+
m_jetAuthor+
"/"+OP+
"/cutvalue";
217 TString fraction_data_name = taggerName+
"/"+
m_jetAuthor+
"/"+OP+
"/fraction";
218 TVector *fraction_data = (TVector*)
m_inf->Get(fraction_data_name);
220 double fraction = -1;
221 if(fraction_data!=
nullptr){
222 fraction = fraction_data[0](0);
224 if(
"DL1" ==taggerName){ fraction = 0.08; }
225 if(
"DL1mu" ==taggerName){ fraction = 0.08; }
226 if(
"DL1rnn" ==taggerName){ fraction = 0.03; }
231 double fraction_tau = 0.;
232 TString fraction_tau_name = taggerName+
"/"+
m_jetAuthor+
"/"+OP+
"/fraction_tau";
233 TVector *fraction_tau_data = (TVector*)
m_inf->Get(fraction_tau_name);
234 if( fraction_tau_data !=
nullptr ) {
235 fraction_tau = fraction_tau_data[0](0);
239 delete fraction_data;
240 delete fraction_tau_data;
252 if (taggerName ==
"GN2v00LegacyWP" || taggerName ==
"GN2v00NewAliasWP"){
253 taggerName =
"GN2v00";
258 ATH_MSG_ERROR(
"Difference between initialisation and getTaggerWeight request! useCTagging property set to " <<
m_useCTag <<
" while getTaggerWeight use c-tag is set to " <<getCTagW <<
".");
272 return CorrectionCode::Ok;
276 return CorrectionCode::Ok;
288 ATH_MSG_ERROR(
"Failed to retrieve the BTagging information");
292 if ( (!btag->
pb(taggerName, dl1_pb ))
293 || (!btag->
pc(taggerName, dl1_pc ))
294 || (!btag->
pu(taggerName, dl1_pu ))
295 || (taggerName==
"GN2v01" && !btag->
ptau(taggerName, dl1_ptau))){
302 return CorrectionCode::Ok;
306 return getTaggerWeight(dl1_pb, dl1_pc, dl1_pu, tagweight, getCTagW, dl1_ptau);
318 ATH_MSG_ERROR(
"For GN2v01 tagger, there is a new tau claass in the NN output. Please update your getTaggerWeight() to getTaggerWeight( double pb, double pc, double pu, double & tagweight, double ptau)");
334 ATH_MSG_ERROR(
"Difference between initialisation and getTaggerWeight request! useCTagging property set to " <<
m_useCTag <<
" while getTaggerWeight use c-tag is set to " <<getCTagW <<
".");
341 bool valid_input = (!std::isnan(
pu) &&
pb>=0 &&
pc>=0 &&
pu>=0 && ptau>=0);
345 ATH_MSG_ERROR(
"Invalid inputs for "+taggerName+
" pb " <<
pb <<
" pc " <<
pc <<
" pu " <<
pu <<
" ptau " << ptau <<
" ");
348 ATH_MSG_WARNING(
"Invalid inputs for "+taggerName+
" pb " <<
pb <<
" pc " <<
pc <<
" pu " <<
pu <<
" ptau " << ptau <<
" ");
349 return CorrectionCode::Ok;
366 return CorrectionCode::Ok;
370 ATH_MSG_ERROR(
"this call to getTaggerWeight only works for DL1/GNx taggers");
388 ATH_MSG_FATAL(
"accept(...) Failed to cast particle to jet" );
400 ATH_MSG_ERROR(
"BTaggingSelectionTool has not been initialised");
406 acceptData.
setCutResult(
"NConstituents",
jet.numConstituents() >= 2 );
409 double pT =
jet.pt();
413 double taggerweight_b(-100);
414 double taggerweight_c(-100);
419 return accept(
pT,
eta, taggerweight_b,taggerweight_c);
422 double taggerweight(-100);
436 ATH_MSG_ERROR(
"BTaggingSelectionTool has not been initialised");
449 throw std::logic_error(
"bin == 0 in the list of tagged bins. you should not be here. Wrong convention");
450 }
else if (
bin == 1 ) {
466 double cutvalue(DBL_MAX);
471 if ( tag_weight < cutvalue ){
487 ATH_MSG_ERROR(
"BTaggingSelectionTool has not been initialised");
499 <<taggerWeight_c <<
" taggerWeight_b "
525 ATH_MSG_ERROR(
"For GN2v01 tagger, there is a new tau claass in the NN output. Please update the accept() to accept(double pT, double eta, double pb, double pc, double pu, double ptau)");
537 ATH_MSG_ERROR(
"BTaggingSelectionTool has not been initialised");
547 double cutvalue(DBL_MAX);
554 double tagger_weight_b(-100);
555 double tagger_weight_c(-100);
559 return accept(
pT,
eta, tagger_weight_b, tagger_weight_c);
562 double tagger_weight(-100);
565 if ( tagger_weight < cutvalue )
585 ATH_MSG_FATAL(
"accept(...) Failed to cast particle to jet" );
594 double pT =
jet.pt();
595 double eta = std::abs(
jet.eta() );
599 double tag_weight_b(-100.);
600 double tag_weight_c(-100.);
603 ATH_MSG_WARNING(
"getQuantile: Failed to retrieve tag weight for Continuous2D!");
610 double tag_weight(-100.);
625 ATH_MSG_ERROR(
"BTaggingSelectionTool has not been initialised");
677 ATH_MSG_DEBUG(
"inside getQuantile 2D " <<
pT <<
" " <<
eta <<
" " <<tag_weight_b <<
" " <<tag_weight_c);
687 for(
int i = 0;
i < ncuts ;
i++){
693 ATH_MSG_DEBUG(
"bin " <<
i <<
" c_cut low " <<c_cut_low <<
" c_cut hig " <<c_cut_hig <<
" c_cut low " <<b_cut_low <<
" b_ct hig" <<b_cut_hig);
694 if (tag_weight_c > c_cut_low &&
695 tag_weight_c <= c_cut_hig &&
696 tag_weight_b > b_cut_low &&
697 tag_weight_b <= b_cut_hig){
735 if (tagger.spline !=
nullptr && tagger.constcut ==
nullptr) {
737 double maxsplinept = tagger.spline->GetXmax();
738 if (
pT>maxsplinept){
pT = maxsplinept; }
739 cutval = tagger.spline->Eval(
pT);
742 else if (tagger.constcut !=
nullptr && tagger.spline ==
nullptr) {
743 cutval = tagger.constcut[0](0);
753 return CorrectionCode::Ok;
757 std::vector<std::string>
v;
758 std::istringstream buf(
input);
759 for(std::string token; std::getline(buf, token,
delimiter); )