ATLAS Offline Software
BTaggingTruthTaggingTool.cxx
Go to the documentation of this file.
9 #include "PATCore/AcceptData.h"
10 
11 #include "TFile.h"
12 
13 #include <algorithm>
14 #include <numeric>
15 
16 using std::string;
17 
18 using CP::CorrectionCode;
19 using CP::SystematicSet;
22 
28 using Analysis::Total;
29 using Analysis::SFEigen;
30 using Analysis::SFNamed;
31 using Analysis::None;
32 
33 using xAOD::IParticle;
34 
36  : asg::AsgTool( name ),
37  m_effTool ("BTaggingEfficiencyTool/effTool", this),
38  m_selTool ("BTaggingSelectionTool/selTool", this)
39  {
40 
41  m_initialised = false;
42 
43  // properties of BTaggingTruthTaggingTool
44  declareProperty( "IgnoreScaleFactors", m_ignoreSF=true, "ignore scale factors in computation of TRF weight");
45  declareProperty( "UsePermutations", m_usePerm=true, "if the chosen permutation is used, a reweighting is applied to the TRF weight for systematics");
46  declareProperty( "UseQuantile", m_useQuntile=true, "if the chosen quantile is used, a reweighting is applied to the TRF weight for systematics");
47  declareProperty( "UseSystematics", m_useSys=false, "will the results contain all systematic variations, or just the nominal");
48  declareProperty( "MaxNtagged", m_nbtag=2, "what is the maximal possible number of tagged jets");
49 
50  // properties of BtaggingSelectionTool
51  declareProperty( "MaxEta", m_maxEta = 2.5 );
52  declareProperty( "MinPt", m_minPt = 20000 /*MeV*/);
53  declareProperty( "MaxRangePt", m_maxRangePt = 1000000 /*MeV*/);
54 
55  // properties of BTaggingEfficiencyTool
56  declareProperty("TaggerName", m_taggerName="MV2c10", "tagging algorithm name as specified in CDI file");
57  declareProperty("OperatingPoint", m_OP="FixedCutBEff_77", "operating point as specified in CDI file");
58  declareProperty("JetAuthor", m_jetAuthor="AntiKt4EMTopoJets", "jet collection & JVF/JVT specification in CDI file");
59  declareProperty("ScaleFactorFileName", m_SFFile = "xAODBTaggingEfficiency/13TeV/2016-20_7-13TeV-MC15-CDI-July12_v1.root", "name of the official scale factor calibration CDI file (uses PathResolver)");
60  declareProperty("UseDevelopmentFile", m_useDevFile = false, "specify whether or not to use the (PathResolver) area for temporary scale factor calibration CDI files");
61  declareProperty("EfficiencyFileName", m_EffFile = "", "name of optional user-provided MC efficiency CDI file");
62  declareProperty("ScaleFactorBCalibration", m_SFBName = "default", "name of b-jet scale factor calibration object");
63  declareProperty("ScaleFactorCCalibration", m_SFCName = "default", "name of c-jet scale factor calibration object");
64  declareProperty("ScaleFactorTCalibration", m_SFTName = "default", "name of tau-jet scale factor calibration object");
65  declareProperty("ScaleFactorLightCalibration", m_SFLightName = "default", "name of light-flavour jet scale factor calibration object");
66  declareProperty("EigenvectorReductionB", m_EVReductionB = "Loose", "b-jet scale factor Eigenvector reduction strategy; choose between 'Loose', 'Medium', 'Tight'");
67  declareProperty("EigenvectorReductionC", m_EVReductionC = "Loose", "c-jet scale factor Eigenvector reduction strategy; choose between 'Loose', 'Medium', 'Tight'");
68  declareProperty("EigenvectorReductionLight", m_EVReductionLight = "Loose","light-flavour jet scale factor Eigenvector reduction strategy; choose between 'Loose', 'Medium', 'Tight'");
69  declareProperty("EfficiencyBCalibrations", m_EffBName = "default", "(semicolon-separated) name(s) of b-jet efficiency object(s)");
70  declareProperty("EfficiencyCCalibrations", m_EffCName = "default", "(semicolon-separated) name(s) of c-jet efficiency object(s)");
71  declareProperty("EfficiencyTCalibrations", m_EffTName = "default", "(semicolon-separated) name(s) of tau-jet efficiency object(s)");
72  declareProperty("EfficiencyLightCalibrations", m_EffLightName = "default", "(semicolon-separated) name(s) of light-flavour-jet efficiency object(s)");
73  declareProperty("ExcludeFromEigenVectorTreatment", m_excludeFromEV = "", "(semicolon-separated) names of uncertainties to be excluded from eigenvector decomposition (if used)");
74  declareProperty("SystematicsStrategy", m_systStrategy = "SFEigen", "name of systematics model; presently choose between 'SFEigen' and 'Envelope'");
75  declareProperty("ConeFlavourLabel", m_coneFlavourLabel = true, "specify whether or not to use the cone-based flavour labelling instead of the default ghost association based labelling");
76  declareProperty("OldConeFlavourLabel", m_oldConeFlavourLabel = false, "when using cone-based flavour labelling, specify whether or not to use the (deprecated) Run-1 legacy labelling");
77  declareProperty("CutBenchmark", m_cutBenchmark = "1,2", "if you want to run in continuous you need to fix a benchmark - it does something only if running in Continuous OP");
78  declareProperty("ExcludeSpecificEigens", m_excludeEV = "" , "(semicolon-separated) names of Eigens you want to exclude. in case of continuous some eigenvectors can be ignored to make the computation faster");
79  declareProperty("StoreOnlyUpVariations", m_doOnlyUpVariations = false , "If set to true it processes only the __1up b-tagging variations. It speeds up the computation in case of symmetric variations.");
80  declareProperty("doDirectTagging", m_doDirectTag = false , "If set to true it also computes and stores the direct tagging choice and the related SFs for each jet");
81  // if it is empty, the onnx tool won't be initialised
82  declareProperty( "pathToONNX", m_pathToONNX = "", "path to the onnx file that will be used for inference");
83  declareProperty( "TaggingStrategy", m_taggingStrategy = "AllJets", "tagging strategy in the Analysis (eg. 'leading2SignalJets' in boosted VHbb). Required to do TT with GNN");
84 }
85 
86 StatusCode BTaggingTruthTaggingTool::setEffMapIndex(const std::string& flavour, unsigned int index){
88  return StatusCode::SUCCESS;
89 }
90 
92  ATH_MSG_DEBUG("setting the use of systematics to: " <<useSystematics);
93  m_useSys = useSystematics;
94  ATH_MSG_DEBUG(" m_useSys = " << m_useSys);
95 }
96 
99 }
100 
102 {
103  for (auto syst : systConfig) {
104  CP::SystematicSet myset;
105  ATH_MSG_WARNING("applySystematicVariation was called for " << syst.name() << " but BTaggingTruthTaggingTool does not apply Systematic Variations");
106  //the truth tagging tool provides results for all possible systematic variations in its results objects, the user does not need to call each one seperatly.
107  }
108  return StatusCode::SUCCESS;
109 }
110 
112 {
114  return sys.find( systematic) != sys.end();
115 }
116 
118  return affectingSystematics();
119 }
120 
122 
124  m_initialised = true;
125 
130  ANA_CHECK(m_selTool.setProperty("OperatingPoint", m_OP));
132  ANA_CHECK(m_selTool.setProperty("FlvTagCutDefinitionsFileName", m_SFFile));
134 
137  ANA_CHECK(m_effTool.setProperty("OperatingPoint", m_OP));
139  ANA_CHECK(m_effTool.setProperty("ScaleFactorFileName", m_SFFile ));
140  ANA_CHECK(m_effTool.setProperty("UseDevelopmentFile", m_useDevFile ));
141  ANA_CHECK(m_effTool.setProperty("EfficiencyFileName", m_EffFile ));
142  ANA_CHECK(m_effTool.setProperty("ScaleFactorBCalibration", m_SFBName ));
143  ANA_CHECK(m_effTool.setProperty("ScaleFactorCCalibration", m_SFCName ));
144  ANA_CHECK(m_effTool.setProperty("ScaleFactorTCalibration", m_SFTName ));
145  ANA_CHECK(m_effTool.setProperty("ScaleFactorLightCalibration", m_SFLightName ));
146  ANA_CHECK(m_effTool.setProperty("EigenvectorReductionB", m_EVReductionB ));
147  ANA_CHECK(m_effTool.setProperty("EigenvectorReductionC", m_EVReductionC ));
148  ANA_CHECK(m_effTool.setProperty("EigenvectorReductionLight", m_EVReductionLight ));
149  ANA_CHECK(m_effTool.setProperty("EfficiencyBCalibrations", m_EffBName ));
150  ANA_CHECK(m_effTool.setProperty("EfficiencyCCalibrations", m_EffCName ));
151  ANA_CHECK(m_effTool.setProperty("EfficiencyTCalibrations", m_EffTName ));
152  ANA_CHECK(m_effTool.setProperty("EfficiencyLightCalibrations", m_EffLightName ));
153  ANA_CHECK(m_effTool.setProperty("ExcludeFromEigenVectorTreatment", m_excludeFromEV ));
154  ANA_CHECK(m_effTool.setProperty("SystematicsStrategy", m_systStrategy ));
155  ANA_CHECK(m_effTool.setProperty("ConeFlavourLabel", m_coneFlavourLabel ));
156  ANA_CHECK(m_effTool.setProperty("OldConeFlavourLabel", m_oldConeFlavourLabel ));
157  ANA_CHECK(m_effTool.setProperty("pathToONNX", m_pathToONNX ));
158 
160 
161  m_continuous = false;
162  m_continuous2D = false;
163  if(m_OP.find("Continuous") != std::string::npos){
164  ATH_MSG_INFO("You are running in Continuous and you chose " << m_cutBenchmark <<" as benchmarks" );
165  m_continuous = true;
166  if(m_OP.find("Continuous2D") != std::string::npos)
167  m_continuous2D = true;
168 
169  //tokenize the quantiles that will be used as tagged bin indices.
170  std::vector<std::string> tag_benchmarks = split(m_cutBenchmark, ',');
171  for (const auto & tag_bin : tag_benchmarks ){
172  if(m_continuous2D)
173  m_OperatingBins.push_back(std::atoi(tag_bin.c_str()));
174  else //continuous
175  m_OperatingBins.push_back(std::atoi(tag_bin.c_str())-1); //different convention
176  }
177  }
178  else{ //FixedCut working points
179  m_OperatingBins.clear();
180  m_OperatingBins.push_back(1); //first bin: untagged, second bin: tagged.
181 }
182 
183  if(m_useQuntile && !m_continuous){
184  ATH_MSG_ERROR("UseQuantile is available only in Continuous WP. Please consider switching the Operating Point.");
185  return StatusCode::FAILURE;
186  }
187 
188  if (m_pathToONNX != ""){
189  // 60% = 4, 70% = 3, 77% = 2, 85% = 1, 100% = 0
190  m_OP_index_for_GNN = find(m_availableOP_fixCut.begin(), m_availableOP_fixCut.end(), m_OP) - m_availableOP_fixCut.begin() + 1; // GNN predicts 5 bins
191  }
192 
193  m_eff_syst.clear();
194  m_sys_name.clear();
195  CP::SystematicSet def_set;
196  m_eff_syst.push_back(def_set);
197  m_sys_name.push_back("Nominal");
198 
199  if(m_useSys){
200  std::vector<std::string> excludeEV_vector;
201  if(m_excludeEV != "")
202  excludeEV_vector = split(m_excludeEV, ';');
204  for (const auto & syst : systs) {
205  CP::SystematicSet myset;
206  string s = syst.name();
207  if(m_doOnlyUpVariations && s.find("__1down") !=string::npos) continue;
208  if(std::any_of(excludeEV_vector.begin(), excludeEV_vector.end(), [&s](const std::string& str) { return str.find(s) != std::string::npos; })) continue;
209  myset.insert(syst);
210  if(m_excludeEV != "")
211  ATH_MSG_INFO("Adding systematic " << syst.name() << "to the list ");
212  else
213  ATH_MSG_DEBUG("Adding systematic " << syst.name() << "to the list ");
214  m_eff_syst.push_back(myset);
215  m_sys_name.push_back(syst.name());
216  }
217  }
218 
219  ATH_MSG_INFO("end of systematics ");
220 
221  //set the cuts
222  TString pathtofile = PathResolverFindCalibFile(m_SFFile);
223  m_inf = TFile::Open(pathtofile, "read");
224 
225  float min_cut_low = (m_taggerName == "MV2c10") ? -1 : -20;
226  float max_cut_hig = (m_taggerName == "MV2c10") ? +1 : +20;
227 
228  if(m_OP == "Continuous"){
229  std::vector<float> bin_edges;
230  bin_edges.push_back(min_cut_low);
231  for (auto bin_name : m_availableOP_fixCut){
232  TString cutname = m_taggerName+"/"+m_jetAuthor+"/"+bin_name+"/cutvalue";
233  float cutval = ((TVector*) m_inf->Get(cutname))[0](0);
234  bin_edges.push_back(cutval);
235  }
236  bin_edges.push_back(max_cut_hig);
237  for (unsigned int be = 0 ; be < bin_edges.size()-1 ; be++){
238  //check if the bin is one of the bins used for btagging
239  //NB. i+1 is to follow the convention 1-5!
240  bool is_tagbin = std::count(m_OperatingBins.begin(), m_OperatingBins.end(), be);
241  TagBin one_cut = TagBin(is_tagbin, bin_edges.at(be), bin_edges.at(be+1));
242  m_cuts.push_back(one_cut);
243  }
244  } //== continuous
245  else if (m_OP.find("Continuous2D") != std::string::npos){
246  ATH_MSG_INFO("TruthTagging initialization: Working with Continuous2D WP.");
247  TString cutname = m_taggerName+"/"+m_jetAuthor+"/Continuous2D/cutvalue";
248  TMatrixD* cuts2D = (TMatrixD*) m_inf->Get(cutname);
249  ATH_MSG_DEBUG("Counting " <<cuts2D->GetNrows() <<" bins ");
250 
251  for (int bin = 0; bin < cuts2D->GetNrows(); bin++){
252  ATH_MSG_DEBUG("INITIALIZATION c-cuts : " <<(*cuts2D)(bin,0) <<" "
253  <<(*cuts2D)(bin,1) <<" b-cuts : "
254  <<(*cuts2D)(bin,2) <<" "
255  <<(*cuts2D)(bin,3));
256 
257  //check if the bin is one of the bins used for btagging
258  //NB. i follows the convention 0-4 of the continuous2D tagging
259  bool is_tagbin = std::count(m_OperatingBins.begin(), m_OperatingBins.end(), bin);
260 
261  //set protection limits, so the final generated tagweight values have a meaning
262  float c_tagcut_low = ((*cuts2D)(bin,0) < min_cut_low) ? min_cut_low : (*cuts2D)(bin,0);
263  float c_tagcut_hig = ((*cuts2D)(bin,1) > max_cut_hig) ? max_cut_hig : (*cuts2D)(bin,1);
264  float b_tagcut_low = ((*cuts2D)(bin,2) < min_cut_low) ? min_cut_low : (*cuts2D)(bin,2);
265  float b_tagcut_hig = ((*cuts2D)(bin,3) > max_cut_hig) ? max_cut_hig : (*cuts2D)(bin,3);
266 
267  TagBin one_cut = TagBin(is_tagbin, b_tagcut_low, b_tagcut_hig, c_tagcut_low, c_tagcut_hig);
268  m_cuts.push_back(one_cut);
269  }
270  }//continuous2D
271  else{ //fixed-cut
272  TString cutname = m_taggerName+"/"+m_jetAuthor+"/"+m_OP+"/cutvalue";
273  float cutval = ((TVector*) m_inf->Get(cutname))[0](0);
274 
275  TagBin untag_bin = TagBin(false, min_cut_low, cutval); //bin 0
276  TagBin tag_bin = TagBin(true, cutval, max_cut_hig); //bin 1
277 
278  m_cuts.push_back(untag_bin);
279  m_cuts.push_back(tag_bin);
280  } //FixedCut
281 
282  if(m_continuous)
283  for (auto c : m_cuts){
284  ATH_MSG_INFO("b-tag low: " <<c.bcut_low <<" b-tag hig: " <<c.bcut_hig <<" c-tag low: " <<c.ccut_low <<" c-tag hig: " <<c.ccut_hig <<" Added to tag bins: " <<c.is_tagbin);
285  }
286 
287  //total number of bins. helpful in loops
288  m_nbins = m_cuts.size(); //FixedCut
289  ATH_MSG_INFO("Total number of bins: " <<m_nbins);
290 
291 
292  // "AllJets" is the default strategy
293  if (m_taggingStrategy == "AllJets"){
295  } else if (m_taggingStrategy == "Leading2SignalJets"){
297  } else if (m_taggingStrategy == "Leading3SignalJets"){
299  } else {
300  ATH_MSG_ERROR("BTaggingTruthTaggingTool::tagging strategy " << m_taggingStrategy << " is not implemented in the TruthTagging Tool");
301  return StatusCode::FAILURE;
302  }
303 
304  return StatusCode::SUCCESS;
305  }
306 
307 
308 StatusCode BTaggingTruthTaggingTool::setJets(TRFinfo &trfinf,std::vector<float>& pt, std::vector<float>& eta, std::vector<int>& flav, std::vector<float>& tagw){
310  if(pt.size()!=eta.size() || pt.size()!=flav.size() || pt.size()!=tagw.size()){
311  ATH_MSG_ERROR( "Vectors of pt, eta, flav and tagw should have same size" );
312  return StatusCode::FAILURE;
313  }
314 
315  std::vector<Analysis::CalibrationDataVariables>* vars = new std::vector<Analysis::CalibrationDataVariables>(0);
316  for(unsigned int i =0; i<pt.size(); i++){
318  ANA_CHECK(fillVariables(pt.at(i), eta.at(i), tagw.at(i), vars_appo));
319  vars->push_back(vars_appo);
320  }
321 
322  ANA_CHECK(setJets(trfinf,flav, vars));
323  delete vars;
324  return StatusCode::SUCCESS;
325 }
326 
329  std::vector<int> flav;
330  std::vector<Analysis::CalibrationDataVariables>* vars = new std::vector<Analysis::CalibrationDataVariables>(0);
331  for(const auto jet : jets) {
333  ANA_CHECK(fillVariables(*jet, vars_appo));
334  vars->push_back(vars_appo);
335  flav.push_back(jetFlavourLabel(*jet));
336  }
337 
338  ANA_CHECK(setJets(trfinf,flav, vars));
339  delete vars;
340  flav.clear();
341  return StatusCode::SUCCESS;
342 }
343 
344 StatusCode BTaggingTruthTaggingTool::setJets(TRFinfo &trfinf,std::vector<int>& flav, std::vector<Analysis::CalibrationDataVariables>* vars){
345  if(flav.size()!=vars->size()){
346  ATH_MSG_ERROR( "Vector of CalibrationDataVariables and flavour should have same size" );
347  return StatusCode::FAILURE;
348  }
349  trfinf.jets.clear();
350  for(unsigned int i =0; i<vars->size(); i++){
351  jetVariable jetVar_appo;
352  jetVar_appo.flav=flav.at(i);
353  jetVar_appo.vars=vars->at(i);
354  trfinf.jets.push_back(jetVar_appo);
355 
356  }
357  trfinf.njets=trfinf.jets.size();
358  return StatusCode::SUCCESS;
359 }
360 
361 // sets node_feat which will be used by the onnx tool
362 StatusCode BTaggingTruthTaggingTool::setJets(TRFinfo &trfinf, const std::vector<std::vector<float>>& node_feat, std::vector<float>& tagw){
364  if(node_feat.size()!=tagw.size()){
365  ATH_MSG_ERROR( "Vectors of node_feat (outer axis) and tagw should have same size" );
366  return StatusCode::FAILURE;
367  }
368 
369  std::vector<int> flav;
370  std::vector<Analysis::CalibrationDataVariables>* vars = new std::vector<Analysis::CalibrationDataVariables>(0);
371  for(unsigned int i =0; i<tagw.size(); i++){
373 
374  // node_feat[i] is always {flav, pt, eta, ...}
375  float pt = node_feat.at(i)[1];
376  float eta = node_feat.at(i)[2];
377 
378  ANA_CHECK(fillVariables(pt, eta, tagw.at(i), vars_appo));
379  vars->push_back(vars_appo);
380  flav.push_back(node_feat.at(i)[0]);
381  }
382 
383  ANA_CHECK(setJets(trfinf, flav, vars, node_feat));
384  return StatusCode::SUCCESS;
385 }
386 
387 // sets node_feat which will be used by the onnx tool
388 StatusCode BTaggingTruthTaggingTool::setJets(TRFinfo &trfinf, const xAOD::JetContainer& jets, const std::vector<std::vector<float>>& node_feat){
390  std::vector<int> flav;
391  std::vector<Analysis::CalibrationDataVariables>* vars = new std::vector<Analysis::CalibrationDataVariables>(0);
392  for(const auto jet : jets) {
394  ANA_CHECK(fillVariables(*jet, vars_appo));
395  vars->push_back(vars_appo);
396  flav.push_back(jetFlavourLabel(*jet));
397  }
398 
399  ANA_CHECK(setJets(trfinf, flav, vars, node_feat));
400  flav.clear();
401  return StatusCode::SUCCESS;
402 }
403 
404 // sets node_feat which will be used by the onnx tool
405 // node_feat contains feats for all the jets as it will be used by the GNN.
406 // trfinf.jets contains only the jets we care about for TT. eg. the leading2 jets if taggingStrategy == Leading2SignalJets
407 StatusCode BTaggingTruthTaggingTool::setJets(TRFinfo &trfinf,std::vector<int>& flav, const std::vector<Analysis::CalibrationDataVariables>* vars, const std::vector<std::vector<float>>& node_feat){
408  if(flav.size()!=vars->size()){
409  ATH_MSG_ERROR( "Vector of CalibrationDataVariables and flavour should have same size" );
410  return StatusCode::FAILURE;
411  }
412  trfinf.jets.clear();
413 
414  if (m_njetsTagStrategy == -1){
415  trfinf.njets = vars->size();
416  } else {
417  trfinf.njets = std::min(static_cast<unsigned int>(m_njetsTagStrategy), static_cast<unsigned int>(vars->size()));
418  }
419 
420  for(unsigned int i =0; i<trfinf.njets; i++){
421  jetVariable jetVar_appo;
422  jetVar_appo.flav=flav.at(i);
423  jetVar_appo.vars=vars->at(i);
424  trfinf.jets.push_back(jetVar_appo);
425  }
426  trfinf.node_feat = node_feat;
427  return StatusCode::SUCCESS;
428 }
429 
430 
432  x.jetPt = jet.pt();
433  x.jetEta = jet.eta();
434  x.jetAuthor = m_jetAuthor;
435 
437  if (!tagInfo) return StatusCode::FAILURE;
438 
439  CorrectionCode code = m_selTool->getTaggerWeight(jet, x.jetTagWeight);
440  if(!(code==CorrectionCode::Ok || code==CorrectionCode::OutOfValidityRange)){
441  ATH_MSG_ERROR("BTaggingSelectionTool::getTaggerWeight returned CorrectionCode::Error");
442  return StatusCode::FAILURE;
443  }
444 
445  return StatusCode::SUCCESS;
446 }
447 
448 StatusCode BTaggingTruthTaggingTool::fillVariables( const float jetPt, const float jetEta, const float jetTagWeight, CalibrationDataVariables& x){
449  x.jetPt = jetPt;
450  x.jetEta = jetEta;
451  x.jetTagWeight = jetTagWeight;
452  x.jetAuthor = m_jetAuthor;
453  return StatusCode::SUCCESS;
454 }
455 
456 StatusCode BTaggingTruthTaggingTool::GetTruthTagWeights(TRFinfo &trfinf, std::vector<float> &trf_weight_ex, std::vector<float> &trf_weight_in){
457 
459  //get MC efficiencies
460  ANA_CHECK(getAllEffMC(trfinf));
461  //compute truth tag weights
462  ANA_CHECK(getTRFweight(trfinf,m_nbtag, true));
463  // choice of the selected permutation
465 
466  // choice of the tagged bins
467  ANA_CHECK(chooseAllTagBins(trfinf));
468 
469  trf_weight_ex = trfinf.trfw_ex;
470  trf_weight_in = trfinf.trfw_in;
471  return StatusCode::SUCCESS;
472 }
473 
474 
477  results.clear();
478 
479  if(rand_seed!=-1){
480  trfinf.rand.SetSeed(rand_seed);
481  }
482 
483  std::vector<float> trf_weight_ex, trf_weight_in;
484 
485  trf_weight_ex.clear();
486  trf_weight_in.clear();
487 
488  ANA_CHECK(GetTruthTagWeights(trfinf, trf_weight_ex, trf_weight_in));
489 
490  ANA_CHECK(getTagPermutation(trfinf,results.trf_chosen_perm_ex,results.trf_chosen_perm_in));
491 
492  //modify quantiles according to the different conventions
493  ANA_CHECK(getQuantiles(trfinf,results.trf_bin_ex, results.trf_bin_in));
494 
495  //new tagger scores
496  ANA_CHECK(generateRandomTaggerScores(results.trf_bin_ex, results.trf_bin_score_ex, results.trf_ctag_bin_score_ex));
497  ANA_CHECK(generateRandomTaggerScores(results.trf_bin_in, results.trf_bin_score_in, results.trf_ctag_bin_score_in));
498 
499  //direct tag
500  if(m_doDirectTag)
501  ANA_CHECK( getDirectTaggedJets(trfinf, results.is_tagged) );
502 
503  //handle systematics
504  unsigned int n_systs = (m_useSys) ? m_eff_syst.size() : 1;
505  results.syst_names.clear();
506 
507  for(unsigned int sys = 0; sys < n_systs; ++sys){
508  if(sys!=0 && m_useSys) {
510  }
511 
512  results.syst_names.push_back(m_sys_name.at(sys));
513 
514  results.map_trf_weight_ex[m_sys_name.at(sys)].resize(trfinf.trfw_ex.size());
515  results.map_trf_weight_in[m_sys_name.at(sys)].resize(trfinf.trfw_in.size());
516 
517  results.map_SF_ex[m_sys_name.at(sys)].resize(trfinf.trfw_ex.size());
518  results.map_SF_in[m_sys_name.at(sys)].resize(trfinf.trfw_in.size());
519 
520  //direct tagging
521  if(m_doDirectTag){
522  std::vector<int> is_tagged;
523  for(auto t : results.is_tagged){
524  is_tagged.push_back(static_cast<int>(t));
525  }
526  results.map_SF[m_sys_name.at(sys)]=getEvtSF(trfinf,is_tagged);
527  }
528 
529  //go over the ntag combinations.
530  //ntj = number of tagged jets
531  for(unsigned int ntj=0; ntj< trfinf.trfw_ex.size(); ntj++){
532  if(ntj > trfinf.njets) {
533  results.map_SF_ex[m_sys_name.at(sys)].at(ntj) = 1.;
534  results.map_SF_in[m_sys_name.at(sys)].at(ntj) = 1.;
535  ATH_MSG_DEBUG("number of jets: " <<trfinf.njets <<" less than max btag: " <<m_nbtag <<". Return BTag SF = 1. Consider applying an event pre-selection if this happens too often.");
536  }
537  else{
538  results.map_SF_ex[m_sys_name.at(sys)].at(ntj) = getEvtSF(trfinf,results.trf_bin_ex.at(ntj));
539  results.map_SF_in[m_sys_name.at(sys)].at(ntj) = getEvtSF(trfinf,results.trf_bin_in.at(ntj));
540  }
541 
542  results.map_trf_weight_ex[m_sys_name.at(sys)].at(ntj) = trfinf.trfw_ex.at(ntj) * results.map_SF_ex[m_sys_name.at(sys)].at(ntj);
543  results.map_trf_weight_in[m_sys_name.at(sys)].at(ntj) = trfinf.trfw_in.at(ntj) * results.map_SF_in[m_sys_name.at(sys)].at(ntj);
544  }
545  }
546 
547  if(m_useSys) { // reset syst to nominal
548  CP::SystematicSet defaultSet;
550  }
551 
552  return StatusCode::SUCCESS;
553 
554 }
555 
556 StatusCode BTaggingTruthTaggingTool::CalculateResults(std::vector<float>& pt, std::vector<float>& eta, std::vector<int>& flav, std::vector<float>& tagw, Analysis::TruthTagResults& results,int rand_seed){
557 
559 
560  TRFinfo trfinf;
561 
562  ANA_CHECK(setJets(trfinf,pt, eta, flav, tagw));
563 
564  return CalculateResults(trfinf,results,rand_seed);
565 }
566 
568 
570 
571  TRFinfo trfinf;
572 
573  ANA_CHECK(setJets(trfinf,jets));
574 
575  return CalculateResults(trfinf,results,rand_seed);
576 }
577 
578 // setting inputs that the onnx tool will use
579 StatusCode BTaggingTruthTaggingTool::CalculateResultsONNX(const std::vector<std::vector<float>>& node_feat, std::vector<float>& tagw, Analysis::TruthTagResults& results, int rand_seed){
580 
582 
583  TRFinfo trfinf;
584 
585  ANA_CHECK(setJets(trfinf, node_feat, tagw));
586 
587  return CalculateResults(trfinf, results, rand_seed);
588 }
589 
590 // setting inputs that the onnx tool will use
591 StatusCode BTaggingTruthTaggingTool::CalculateResultsONNX(const xAOD::JetContainer& jets, const std::vector<std::vector<float>>& node_feat, Analysis::TruthTagResults& results, int rand_seed){
592 
594 
595  TRFinfo trfinf;
596 
597  ANA_CHECK(setJets(trfinf, jets, node_feat));
598 
599  return CalculateResults(trfinf, results, rand_seed);
600 }
601 
603  if (trfinf.node_feat.size() == 0){
604  return getAllEffMCCDI(trfinf);
605  } else {
606  return getAllEffMCGNN(trfinf);
607  }
608 }
609 
610 // uses onnx tool
612 
613  for(int bin = 0; bin < m_nbins; bin++)
614  trfinf.effMC_allBins[bin].clear();
615 
616  //extract efficiency
617  std::vector<std::vector<float>> tmp_effMC_allBins; // shape:{num_jets, num_wp}
618  CorrectionCode code = m_effTool->getMCEfficiencyONNX(trfinf.node_feat, tmp_effMC_allBins);
619 
620  if(!(code==CorrectionCode::Ok || code==CorrectionCode::OutOfValidityRange)){
621  ATH_MSG_ERROR("BTaggingEfficiencyTool::getMCEfficiencyONNX returned CorrectionCode::Error");
622  return StatusCode::FAILURE;
623  }
624 
625  if(m_continuous) {
626  for(int bin = 0; bin < m_nbins; bin++){
627  // need to transpose
628  std::vector<float> tmp_effMC_oneBin; // shape: {num_jet} = trfinf.njets
629  for (unsigned int jet_index=0; jet_index<trfinf.njets; jet_index++){
630  tmp_effMC_oneBin.push_back(tmp_effMC_allBins[jet_index][bin]);
631  }
632  trfinf.effMC_allBins[bin] = tmp_effMC_oneBin;
633  }
634  } // m_continuous
635  else{
636  for (unsigned int jet_index=0; jet_index<trfinf.njets; jet_index++){
637  float tmp_effMC = std::accumulate(tmp_effMC_allBins[jet_index].begin()+m_OP_index_for_GNN, tmp_effMC_allBins[jet_index].end(), 0.0);
638  trfinf.effMC_allBins[0].push_back(1-tmp_effMC);
639  trfinf.effMC_allBins[1].push_back(tmp_effMC);
640  }
641  } // !m_continuous
642 
643  return StatusCode::SUCCESS;
644 }
645 
647 
648  float eff_all =1.;
649  for(int bin = 0; bin < m_nbins; bin++)
650  trfinf.effMC_allBins[bin].clear();
651 
652  for(size_t jet=0; jet < trfinf.jets.size(); jet++){
653  for(int bin = 0; bin < m_nbins; bin++){ // loop on bins
654  eff_all=1.;
655 
656  //set a dumb value of the truth tag weight to get the different efficiency maps for each bin. to be improved..
657  if (m_continuous2D)
658  trfinf.jets.at(jet).vars.jetTagWeight = bin+0.5;
659  else
660  trfinf.jets.at(jet).vars.jetTagWeight = (m_cuts[bin].bcut_low + m_cuts[bin].bcut_hig)/2.;
661 
662  ATH_MSG_DEBUG("effMC_allBins: tag bin: " <<bin <<" tagw: " << trfinf.jets.at(jet).vars.jetTagWeight <<" " <<m_cuts[bin].bcut_low <<" " << m_cuts[bin].bcut_hig <<" " <<trfinf.jets.at(jet).vars.jetPt <<" " <<trfinf.jets.at(jet).vars.jetEta <<" " <<trfinf.jets.at(jet).flav);
663  //get the efficiency
664  CorrectionCode code = m_effTool->getMCEfficiency(trfinf.jets.at(jet).flav, trfinf.jets.at(jet).vars, eff_all);
665  if(!(code==CorrectionCode::Ok || code==CorrectionCode::OutOfValidityRange)){
666  ATH_MSG_ERROR("BTaggingEfficiencyTool::getMCEfficiency returned CorrectionCode::Error");
667  return StatusCode::FAILURE;
668  }
669 
670  trfinf.effMC_allBins[bin].push_back(eff_all);
671  ATH_MSG_DEBUG("effMC_allBins: tag bin: " <<bin <<" tagw: " << trfinf.jets.at(jet).vars.jetTagWeight <<" eff: " <<eff_all);
672  } // end loop on bins
673  } // end loop on jets
674 
675  return StatusCode::SUCCESS;
676 }
677 
678 std::vector<std::vector<bool> > BTaggingTruthTaggingTool::generatePermutations(int njets, int tags, int start){
679  std::vector<std::vector<bool> > perm;
680  std::vector<std::vector<bool> > temp_perm;
681  if(tags==0){
682  std::vector<bool> tags(njets,false);
683  perm.push_back(tags);
684  }
685  else if(tags == njets) {
686  std::vector<bool> tags(njets,true);
687  perm.push_back(tags);
688  }
689  else {
690  for(int i=start; i<njets;i++){
691  temp_perm = generatePermutations(njets,tags-1,i+1);
692  for(unsigned int j=0; j<temp_perm.size(); j++){
693  temp_perm.at(j).at(i)=true;
694  perm.push_back(temp_perm.at(j));
695  }
696  }
697  }
698  return perm;
699 }
700 
701 
702 float BTaggingTruthTaggingTool::trfWeight(TRFinfo &trfinf,const std::vector<bool> &tags){
703 
704  float weight = 1;
705  for (unsigned int t=0; t<tags.size();t++) {
706  float trf = 0.;
707 
708  //sum of the efficiencies in the tagged bins
709  for (int bin : m_OperatingBins){
710 
711  trf += trfinf.effMC_allBins[bin][t];
712 
713  }
714  if(trf>1.) {
715  ATH_MSG_WARNING("Truth Tagging weight > 1. --> setting it to 1. check maps!");
716  trf = 1.;
717  }
718  if(tags.at(t)) weight *= trf;
719  else weight *= (1.-trf);
720  ATH_MSG_DEBUG("weight " <<weight);
721  } // end loop over jets
722  return weight;
723 }
724 
725 
726 StatusCode BTaggingTruthTaggingTool::getTRFweight(TRFinfo &trfinf,unsigned int nbtag, bool isInclusive){
727 
728  unsigned int njets = trfinf.njets;
729  // Consider permutations of njet jets with up to limit b-tags
730  unsigned int limit = (njets > 7) ? 8 : njets+1;
731 
732  // Permutations: njets, ntags, permutations
733  auto& perm = trfinf.perms[njets];
734  if (perm.empty()) { // if I don't have already saved the possible permutations for njet
735  perm.resize (limit);
736  for(unsigned int i=0;i<limit;i++)
737  trfinf.perms[njets].at(i) = generatePermutations(njets,i);
738  }
739  trfinf.permsWeight.clear(), trfinf.permsWeight.resize(limit); // trfinf.permsWeight.at(i).at(j): TRF weight of the j-th perm with i b-tags
740  trfinf.permsSumWeight.clear(), trfinf.permsSumWeight.resize(limit); // trfinf.permsSumWeight.at(i).at(j): partial sum of TRF weight of the permutations with i b-tags up to j (0,1,..,j-th) perm. Used in the choice of the selected permutation
741 
742  // compute TRF weight
743  unsigned int max = nbtag+1; // from 0 to nbtag b-tags --> nbtag+1 positions
744  trfinf.trfw_ex.clear(), trfinf.trfw_in.clear();
745  trfinf.trfw_ex.resize(max), trfinf.trfw_in.resize(max);
746 
747  //clear and resize elements of trfinf
748  trfinf.perm_ex.clear(), trfinf.perm_in.clear(); // vector<vector<bool>> --> for each number of tags the chosen permutation
749  trfinf.perm_ex.resize(max), trfinf.perm_in.resize(max);
750  trfinf.permprob_ex.clear(), trfinf.permprob_in.clear(); // probability of the perm in trfinf.perm_ex/in
751  trfinf.permprob_ex.resize(max), trfinf.permprob_in.resize(max);
752 
753  if(isInclusive) {
754  for(unsigned int i=0; i<limit; i++) { // note: I consider maximum limit tags. It's an approximation
755  std::vector<float> weights;
756  float sum = 0.;
757  float w = 0.; //weight
758  trfinf.permsWeight.at(i).clear();
759  trfinf.permsSumWeight.at(i).clear();
760  trfinf.permsWeight.at(i).resize(trfinf.perms[njets].at(i).size());
761  trfinf.permsSumWeight.at(i).resize(trfinf.perms[njets].at(i).size());
762 
763  // loop on all the permutations with i tags
764  for(unsigned int p=0; p<trfinf.perms[njets].at(i).size(); p++) {
765 
766  w = trfWeight(trfinf,trfinf.perms[njets].at(i).at(p));
767  sum+=w;
768  trfinf.permsWeight.at(i).at(p) = w;
769  trfinf.permsSumWeight.at(i).at(p) = sum;
770 
771  ATH_MSG_DEBUG("nbtag = " << i << " wei = " << w << " sum = " << sum);
772  }
773  if(i<limit && i<max) {
774  // note: I need to already have the exclusive weights filled to compite the inclusive
775  trfinf.trfw_ex.at(i) = sum; // sum of TRF weights for all perm with i b-tags
776  if(i == 0) trfinf.trfw_in.at(0) = 1.;
777  else trfinf.trfw_in.at(i) = trfinf.trfw_in.at(i-1) - trfinf.trfw_ex.at(i-1); // P(>=4) = P(>=3) - P(==3)
778  ATH_MSG_DEBUG("i = " << i << " sum = " << sum << " TRF in " << trfinf.trfw_in.at(i) << " ex = " << trfinf.trfw_ex.at(i));
779  }
780  }
781  ATH_MSG_DEBUG("before return, nbtag = " << nbtag << " size de trfinf.trfw_in = " << trfinf.trfw_in.size());
782  return StatusCode::SUCCESS;
783  }
784  else { // exclusive case, only one calculation needed
785  std::vector<float> weights;
786  float sum = 0., w = 0.;
787  size_t size = trfinf.perms[njets].at(nbtag).size();
788  trfinf.permsWeight.at(nbtag).clear();
789  trfinf.permsSumWeight.at(nbtag).clear();
790  trfinf.permsWeight.at(nbtag).resize(size);
791  trfinf.permsSumWeight.at(nbtag).resize(size);
792  // loop on all the permutations with i tags
793  for(unsigned int p=0; p<trfinf.perms[njets].at(nbtag).size(); p++) {
794  w = trfWeight(trfinf,trfinf.perms[njets].at(nbtag).at(p));
795  sum+=w;
796  trfinf.permsWeight.at(nbtag).at(p) = w;
797  trfinf.permsSumWeight.at(nbtag).at(p) = sum;
798  }
799  trfinf.trfw_ex.at(nbtag) = sum;
800  return StatusCode::SUCCESS;
801  }
802  return StatusCode::SUCCESS;
803 }
804 
805 
806 StatusCode BTaggingTruthTaggingTool::getTagPermutation(TRFinfo &trfinf, std::vector<std::vector<bool> > &trf_chosen_perm_ex, std::vector<std::vector<bool> > &trf_chosen_perm_in){
807  trf_chosen_perm_ex.resize(m_nbtag+1);
808  trf_chosen_perm_in.resize(m_nbtag+1);
809  trf_chosen_perm_ex = trfinf.perm_ex;
810  trf_chosen_perm_in = trfinf.perm_in;
811  std::string print_perm = "Permutation: ";
812  for(auto perm: trfinf.perm_ex){
813  for(auto is: perm) {
814  if(is) print_perm+=std::to_string(1);
815  else print_perm+=std::to_string(0);
816  print_perm+=" ";
817  }
818  }
819  ATH_MSG_DEBUG(print_perm);
820  return StatusCode::SUCCESS;
821 }
822 
824 
826 
827  if(!m_usePerm){
828  return StatusCode::FAILURE;
829  }
830 
831  unsigned int njets = trfinf.njets;
832  unsigned int limit = (njets > 7) ? 8 : njets+1;
833  unsigned int max = (njets < nbtag+1) ? limit : nbtag+1;
834 
835  trfinf.perm_ex.clear(), trfinf.perm_ex.resize(nbtag+1);
836  trfinf.perm_in.clear(), trfinf.perm_in.resize(nbtag+1);
837 
838  trfinf.permprob_ex.clear(), trfinf.permprob_ex.resize(nbtag+1);
839  trfinf.permprob_in.clear(), trfinf.permprob_in.resize(nbtag+1);
840 
841  for(unsigned int i=0; i<max; i++) { // need +1 as 0 is included
842  ANA_CHECK(chooseTagPermutation(trfinf,i,false));
843  ANA_CHECK(chooseTagPermutation(trfinf,i,true));
844  }
845 
846  return StatusCode::SUCCESS;
847 }
848 
849 StatusCode BTaggingTruthTaggingTool::chooseTagPermutation(TRFinfo &trfinf,unsigned int nbtag, bool isIncl){
850  std::vector<float> incl;
851  std::vector<std::pair<unsigned int, unsigned int> > trackPerm;
852  float sum = 0;
853  if(isIncl) {
854  for(unsigned int itag=nbtag; itag < trfinf.permsWeight.size(); itag++) {
855  for(unsigned int ip = 0; ip < trfinf.permsWeight.at(itag).size(); ip++) {
856  sum += trfinf.permsWeight.at(itag).at(ip);
857  incl.push_back(sum);
858  trackPerm.push_back(std::make_pair(itag,ip));
859  }
860  }
861  }
862  else { // in exclusive case
863  sum = trfinf.permsSumWeight.at(nbtag).back();
864  incl = trfinf.permsSumWeight.at(nbtag);
865  for(unsigned int ip = 0; ip < trfinf.permsSumWeight.at(nbtag).size(); ip++) trackPerm.push_back(std::make_pair(nbtag,ip));
866  }
867  float theX = trfinf.rand.Uniform(sum);
868  for(unsigned int ip=0; ip < incl.size(); ip++) {
869  ATH_MSG_DEBUG("incl.at(ip): " << incl.at(ip) << " theX: " << theX);
870  if(incl.at(ip) >= theX) {
871  if(isIncl) {
872  trfinf.perm_in.at(nbtag) = trfinf.perms[trfinf.njets].at(trackPerm.at(ip).first).at(trackPerm.at(ip).second);
873  trfinf.permprob_in.at(nbtag) = trfinf.permsWeight.at(trackPerm.at(ip).first).at(trackPerm.at(ip).second) / trfinf.trfw_in.at(nbtag);
874  }
875  else {
876  trfinf.perm_ex.at(nbtag) = trfinf.perms[trfinf.njets].at(trackPerm.at(ip).first).at(trackPerm.at(ip).second);
877  trfinf.permprob_ex.at(nbtag) = trfinf.permsWeight.at(trackPerm.at(ip).first).at(trackPerm.at(ip).second) / trfinf.trfw_ex.at(nbtag);
878  }
879  return StatusCode::SUCCESS;
880  }
881  }
882  return StatusCode::SUCCESS;
883 }
884 
885 
886 
888 // Cheatsheet:
889 // returns 5 if between 60% and 0%
890 // returns 4 if between 70% and 60%
891 // returns 3 if between 77% and 70%
892 // returns 2 if between 85% and 77%
893 // returns 1 if between 100% and 85%
894 // return -1 if not in b-tagging acceptance
896 
897 
898 StatusCode BTaggingTruthTaggingTool::getQuantiles(TRFinfo &trfinf,std::vector<std::vector<int> > &trf_bin_ex, std::vector<std::vector<int> > &trf_bin_in){
899  trf_bin_ex.resize(trfinf.tbins_ex.size());
900  for(unsigned int i =0; i<trfinf.tbins_ex.size(); i++)
901  trf_bin_ex.at(i).resize(trfinf.tbins_ex.at(i).size());
902 
903  trf_bin_in.resize(trfinf.tbins_in.size());
904  for(unsigned int i =0; i<trfinf.tbins_in.size(); i++)
905  trf_bin_in.at(i).resize(trfinf.tbins_in.at(i).size());
906  // increasing the value by 1 to match conventions in selectionTool (not continuous2D)
907  for(unsigned int i =0; i<trfinf.tbins_ex.size(); i++)
908  for(unsigned int j=0; j<trfinf.tbins_ex.at(i).size(); j++)
909  trf_bin_ex.at(i).at(j)= (m_continuous2D || !m_continuous) ? trfinf.tbins_ex.at(i).at(j) : trfinf.tbins_ex.at(i).at(j) +1;
910 
911  for(unsigned int i =0; i<trfinf.tbins_in.size(); i++)
912  for(unsigned int j=0; j<trfinf.tbins_in.at(i).size(); j++)
913  trf_bin_in.at(i).at(j) = (m_continuous2D || !m_continuous) ? trfinf.tbins_in.at(i).at(j) : trfinf.tbins_in.at(i).at(j) +1;
914 
915  return StatusCode::SUCCESS;
916 }
917 
920  trfinf.tbins_ex.clear();
921  trfinf.tbins_in.clear();
922  trfinf.tbins_ex.resize( trfinf.trfw_ex.size());
923  trfinf.tbins_in.resize( trfinf.trfw_in.size());
924 
925  trfinf.binsprob_ex.clear();
926  trfinf.binsprob_in.clear();
927  trfinf.binsprob_ex.resize( trfinf.trfw_ex.size());
928  trfinf.binsprob_in.resize( trfinf.trfw_in.size());
929 
930  if(trfinf.perm_ex.size() != trfinf.perm_in.size()) ATH_MSG_WARNING("Different sizes in exclusive and inclusive permutation choices");
931 
932  for(unsigned int nb=0; nb<trfinf.perm_ex.size(); nb++) {
933  ANA_CHECK(chooseTagBins_cum(trfinf,trfinf.perm_ex.at(nb), false, nb));
934  ANA_CHECK(chooseTagBins_cum(trfinf,trfinf.perm_in.at(nb), true, nb));
935  }
936  return StatusCode::SUCCESS;
937 }
938 
939 
940 StatusCode BTaggingTruthTaggingTool::chooseTagBins_cum(TRFinfo &trfinf,std::vector<bool> &tagconf, bool isIncl, unsigned int nbtag){
941  std::vector<int> btagops;
942 
943  ATH_MSG_DEBUG("chooseTagBins_cum ntag: " <<nbtag);
944 
945  std::vector<float> incl;
946  std::vector<float> untagged_bins;
947  float prob = 1.;
948 
949  //define the untagged bins
950  for (int bin=0; bin<m_nbins; bin++) {
951  if (std::count(m_OperatingBins.begin(), m_OperatingBins.end(), bin)) continue;
952  untagged_bins.push_back(bin);
953  }
954 
955  //How to calculate Probabilities:
956  //sum: [---- P(bin 0) -----][-- P(bin 1) ---][- P(bin 2) -]
957  //random X up to sum of the bins. pick one prob based on the efficiency
958  for(unsigned int j=0; j<tagconf.size(); j++) {
959 
960  ATH_MSG_DEBUG("tagconf.at(tc) " <<tagconf.at(j));
961 
962  if(tagconf.at(j)) { // tagged jet
963  float sum=0.;
964  incl.clear();
965  for (int tagged_bin : m_OperatingBins){
966  sum += trfinf.effMC_allBins[tagged_bin][j];
967  incl.push_back(sum);
968  }
969 
970  float theX = trfinf.rand.Uniform(sum);
971  auto tag_index = std::lower_bound(incl.begin(), incl.end(), theX) - incl.begin();
972  float tbin_choice = m_OperatingBins[tag_index];
973  btagops.push_back(tbin_choice);
974  prob *= (trfinf.effMC_allBins[tbin_choice][j]);
975  ATH_MSG_DEBUG("it " <<tag_index <<" theX " <<theX <<" effMC " <<trfinf.effMC_allBins[tbin_choice][j] <<" prob* " <<prob);
976  } //tagged
977  else { // untagged jet
978  float untag_sum = 0. ;
979  incl.clear();
980  //sum over untagged bins
981  for(auto bin : untagged_bins){
982  untag_sum += trfinf.effMC_allBins[bin][j];
983  incl.push_back(untag_sum);
984  }
985 
986  float theX = trfinf.rand.Uniform(untag_sum);
987  auto untag_index = std::lower_bound(incl.begin(), incl.end(), theX) - incl.begin();
988  float utbin_choice = untagged_bins[untag_index];
989  btagops.push_back(utbin_choice);
990  prob *= 1 - trfinf.effMC_allBins[utbin_choice][j];
991  ATH_MSG_DEBUG(" unt_bin " <<untag_index <<" theX " <<theX<<" 1-effMC " <<1-trfinf.effMC_allBins[utbin_choice][j] <<" prob* " <<prob);
992  }
993  }
994 
995  if(btagops.size() != tagconf.size()) {
996  ATH_MSG_ERROR("You should not be here -> wrong size of tag bins vector. btagops: " <<btagops.size() <<" tagconf: " <<tagconf.size());
997  return StatusCode::FAILURE;
998  }
999  if(isIncl) {
1000  trfinf.tbins_in.at(nbtag) = btagops;
1001  trfinf.binsprob_in.at(nbtag) = prob;
1002  ATH_MSG_DEBUG("incl, nbtag " << nbtag << " prob " << prob);
1003  }
1004  else {
1005  trfinf.tbins_ex.at(nbtag) = btagops;
1006  trfinf.binsprob_ex.at(nbtag) = prob;
1007  ATH_MSG_DEBUG("excl, nbtag " << nbtag << " prob " << prob);
1008  }
1009  return StatusCode::SUCCESS;
1010 }
1011 
1012 float BTaggingTruthTaggingTool::getTagBinsConfProb(TRFinfo &trfinf,std::vector<int> &tagws){
1013  float prob = 1.;
1014  for(unsigned int j=0; j<tagws.size(); j++) {
1015 
1016  float sum_tag = 0.;
1017  //calculate sum of all tagged bins
1018  for (auto bin : m_OperatingBins)
1019  sum_tag += trfinf.effMC_allBins[bin][j];
1020 
1021  if(std::count(m_OperatingBins.begin(), m_OperatingBins.end(), tagws.at(j) ) ) { // tagged
1022  prob *= (trfinf.effMC_allBins[tagws.at(j)][j]) / sum_tag;
1023  ATH_MSG_DEBUG("prob " << prob);
1024  }
1025  else { // untagged
1026  prob *= (1 - trfinf.effMC_allBins[tagws.at(j)][j]) / (1 - sum_tag);
1027  ATH_MSG_DEBUG("prob " << prob);
1028  }
1029  }
1030  return prob;
1031 }
1032 
1034  is_tagged.clear();
1035  std::vector<int> appo;
1036  auto is_jettag = false;
1037  for(const auto &jet : trfinf.jets) {
1038  ATH_MSG_DEBUG("pt " << jet.vars.jetPt << " eta " << jet.vars.jetEta << " wei " << jet.vars.jetTagWeight);
1039  is_jettag = static_cast<bool>(m_selTool->accept(jet.vars.jetPt, jet.vars.jetEta, jet.vars.jetTagWeight));
1040 
1041  ATH_MSG_DEBUG("is tagged? " << is_jettag);
1042  if(is_jettag) is_tagged.push_back(1);
1043  else is_tagged.push_back(0);
1044  }
1045 
1046  return StatusCode::SUCCESS;
1047 }
1048 
1049 
1050 float BTaggingTruthTaggingTool::getEvtSF(TRFinfo &trfinf, std::vector<int>& quantiles){
1051 
1052  float SF = 1.;
1053 
1054  if (m_ignoreSF)
1055  return SF;
1056 
1057  for(unsigned int i =0; i< trfinf.njets; i++) {
1058  float jetSF = 1;
1059 
1060  if(!m_continuous){ //FixedCut
1061 
1062  bool is_btagged = quantiles.at(i);
1063  auto code = (is_btagged) ? m_effTool->getScaleFactor(trfinf.jets.at(i).flav, trfinf.jets.at(i).vars, jetSF) : m_effTool->getInefficiencyScaleFactor(trfinf.jets.at(i).flav, trfinf.jets.at(i).vars, jetSF);
1064 
1065  if(!(code==CorrectionCode::Ok || code==CorrectionCode::OutOfValidityRange)){
1066  ATH_MSG_ERROR("BTaggingEfficiencyTool::getScaleFactor returned CorrectionCode::Error");
1067  return -99.;
1068  }
1069  }
1070  else{ //continuous & continuous2D
1071  int bin = quantiles.at(i);
1072  //set new tagweight bin according to the final decision
1073  //the quantile convention for continuous is: bin+1!
1074  trfinf.jets.at(i).vars.jetTagWeight = (m_continuous2D) ? bin+0.5 : (m_cuts[bin-1].bcut_low + m_cuts[bin-1].bcut_hig)/2.;
1075 
1076  auto code = m_effTool->getScaleFactor(trfinf.jets.at(i).flav, trfinf.jets.at(i).vars, jetSF);
1077  if(!(code==CorrectionCode::Ok || code==CorrectionCode::OutOfValidityRange)){
1078  ATH_MSG_ERROR("BTaggingEfficiencyTool::getScaleFactor returned CorrectionCode::Error");
1079  return -99;
1080  }
1081  ATH_MSG_DEBUG("BIN " <<bin <<"SF: pt " <<trfinf.jets.at(i).vars.jetPt <<" " <<trfinf.jets.at(i).vars.jetEta <<" " <<trfinf.jets.at(i).vars.jetTagWeight <<" jetSF " <<jetSF);
1082  }
1083  SF*=jetSF;
1084  } //loop over jets
1085 
1086  ATH_MSG_DEBUG(" FINAL SF : " <<SF);
1087  return SF;
1088 }
1089 
1090 
1092  if(sys < m_eff_syst.size()) return StatusCode::SUCCESS;
1093  ATH_MSG_ERROR(sys << " Out of range of available systematics");
1094  return StatusCode::FAILURE;
1095 }
1096 
1097 
1098 
1100 
1101  // delete trfinf.jets;
1102 
1103 }
1104 
1105 
1107  if (m_coneFlavourLabel)
1109  else
1111 }
1112 
1114 
1115  const std::string labelB = "GhostBHadronsFinal";
1116  const std::string labelC = "GhostCHadronsFinal";
1117  const std::string labelTau = "GhostTausFinal";
1118 
1119  std::vector<const IParticle*> ghostB;
1120  if (jet.getAssociatedObjects<IParticle>(labelB, ghostB) && ghostB.size() > 0) return 5;
1121  std::vector<const IParticle*> ghostC;
1122  if (jet.getAssociatedObjects<IParticle>(labelC, ghostC) && ghostC.size() > 0) return 4;
1123  std::vector<const IParticle*> ghostTau;
1124  if (jet.getAssociatedObjects<IParticle>(labelTau, ghostTau) && ghostTau.size() > 0) return 15;
1125 
1126 
1127  return 0;
1128 }
1129 
1131  // default label means "invalid"
1132  int label = -1;
1133  // First try the new naming scheme
1134  if (jet.getAttribute("ConeTruthLabelID",label)) return label;
1135  // If that fails, revert to the old scheme. In this case, further testing is not very useful
1136  jet.getAttribute("TruthLabelID", label);
1137  return label;
1138 }
1139 
1141  // default label means "invalid"
1142  int label = -1;
1143  // We don't check the return value, as we would not be able to handle it gracefully anyway
1144  jet.getAttribute("HadronConeExclTruthLabelID",label);
1145  return label;
1146 }
1147 
1148 // local utility function: trim leading and trailing whitespace in the property strings
1149 std::string trim(const std::string& str,
1150  const std::string& whitespace = " \t") {
1151  const auto strBegin = str.find_first_not_of(whitespace);
1152  if (strBegin == std::string::npos)
1153  return ""; // no content
1154 
1155  const auto strEnd = str.find_last_not_of(whitespace);
1156  const auto strRange = strEnd - strBegin + 1;
1157 
1158  return str.substr(strBegin, strRange);
1159 }
1160 
1161 
1162 std::vector<std::string> BTaggingTruthTaggingTool::split(const std::string& str, char token) {
1163  std::vector<std::string> result;
1164  if (str.size() > 0) {
1165  std::string::size_type end;
1166  std::string tmp(str);
1167  do {
1168  end = tmp.find(token);
1169  std::string entry = trim(tmp.substr(0,end));
1170  if (entry.size() > 0) result.push_back(entry);
1171  if (end != std::string::npos) tmp = tmp.substr(end+1);
1172  } while (end != std::string::npos);
1173  }
1174  return result;
1175 }
1176 
1177 StatusCode BTaggingTruthTaggingTool::generateRandomTaggerScores(std::vector< std::vector<int> > &quantiles, std::vector< std::vector<float> > &btag_scores, std::vector< std::vector<float> > &ctag_scores){
1178 
1179  TRandom3 random;
1180 
1181  btag_scores.clear();
1182  btag_scores.resize(quantiles.size());
1183 
1184  if(m_continuous2D){
1185  ctag_scores.clear();
1186  ctag_scores.resize(quantiles.size());
1187  }
1188 
1189  for(unsigned int i=0; i <quantiles.size(); i++ ){
1190 
1191  btag_scores.at(i).resize(quantiles.at(i).size());
1192  if(m_continuous2D)
1193  ctag_scores.at(i).resize(quantiles.at(i).size());
1194 
1195  unsigned int njets = quantiles.at(i).size();
1196  for(unsigned int j=0; j < njets; j++ ){
1197 
1198  int temp_quantile = (m_continuous2D) ? quantiles.at(i).at(j) : quantiles.at(i).at(j) -1;
1199 
1200  float btag_low = m_cuts[temp_quantile].bcut_low;
1201  float btag_hig = m_cuts[temp_quantile].bcut_hig;
1202 
1203  float ctag_low = m_cuts[temp_quantile].ccut_low;
1204  float ctag_hig = m_cuts[temp_quantile].ccut_hig;
1205 
1206  btag_scores.at(i).at(j) = btag_low + random.Uniform()*(btag_hig - btag_low );
1207  if(m_continuous2D)
1208  ctag_scores.at(i).at(j) = ctag_low + random.Uniform()*(ctag_hig - ctag_low );
1209  }
1210  }
1211  return StatusCode::SUCCESS;
1212 
1213 }
1214 
Analysis::CalibResult
std::pair< double, double > CalibResult
Definition: CalibrationDataInterfaceBase.h:34
asg::AnaToolHandle::initialize
StatusCode initialize()
initialize the tool
BTaggingTruthTaggingTool::GAFinalHadronFlavourLabel
int GAFinalHadronFlavourLabel(const xAOD::Jet &jet)
Definition: BTaggingTruthTaggingTool.cxx:1113
BTaggingTruthTaggingTool::getAllEffMCGNN
StatusCode getAllEffMCGNN(TRFinfo &trfinf)
Definition: BTaggingTruthTaggingTool.cxx:611
BTaggingTruthTaggingTool::m_EffCName
std::string m_EffCName
semicolon-separated list of MC efficiency parametrisation names for charm jets
Definition: BTaggingTruthTaggingTool.h:229
BTaggingUtilities.h
BTaggingTruthTaggingTool::m_OP_index_for_GNN
unsigned int m_OP_index_for_GNN
Definition: BTaggingTruthTaggingTool.h:284
BTaggingTruthTaggingTool::jetVariable
Definition: BTaggingTruthTaggingTool.h:79
BTaggingTruthTaggingTool::m_inf
TFile * m_inf
Definition: BTaggingTruthTaggingTool.h:180
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
BTaggingTruthTaggingTool::TRFinfo::permprob_ex
std::vector< float > permprob_ex
Definition: BTaggingTruthTaggingTool.h:105
BTaggingTruthTaggingTool::m_minPt
float m_minPt
Definition: BTaggingTruthTaggingTool.h:269
get_generator_info.result
result
Definition: get_generator_info.py:21
BTaggingTruthTaggingTool::m_EVReductionC
std::string m_EVReductionC
specification of the eigenvector reduction strategy for c jets (if eigenvectors are used)
Definition: BTaggingTruthTaggingTool.h:223
Analysis::CalibrationDataContainer
Definition: CalibrationDataContainer.h:51
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
max
#define max(a, b)
Definition: cfImp.cxx:41
BTaggingTruthTaggingTool::m_pathToONNX
std::string m_pathToONNX
if this string is empty, the onnx tool won't be used
Definition: BTaggingTruthTaggingTool.h:257
IBTaggingEfficiencyTool::getMCEfficiencyONNX
virtual CP::CorrectionCode getMCEfficiencyONNX(const std::vector< std::vector< float >> &node_feat, std::vector< float > &effAllJet)=0
BTaggingTruthTaggingTool::m_cutBenchmark
std::string m_cutBenchmark
operating point when running in Continuous
Definition: BTaggingTruthTaggingTool.h:241
BTaggingTruthTaggingTool::setJets
StatusCode setJets(TRFinfo &trfinf, std::vector< float > &pt, std::vector< float > &eta, std::vector< int > &flav, std::vector< float > &tagw)
Definition: BTaggingTruthTaggingTool.cxx:308
BTaggingTruthTaggingTool::m_systStrategy
std::string m_systStrategy
systematics model to be used (current choices are "SFEigen" and "Envelope")
Definition: BTaggingTruthTaggingTool.h:245
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
BTagging.h
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
BTaggingTruthTaggingTool::TRFinfo::tbins_in
std::vector< std::vector< int > > tbins_in
Definition: BTaggingTruthTaggingTool.h:99
BTaggingTruthTaggingTool::TRFinfo::trfw_in
std::vector< float > trfw_in
Definition: BTaggingTruthTaggingTool.h:102
BTaggingTruthTaggingTool::Leading2SignalJets
@ Leading2SignalJets
Definition: BTaggingTruthTaggingTool.h:261
trim
std::string trim(const std::string &str, const std::string &whitespace=" \t")
Definition: BTaggingTruthTaggingTool.cxx:1149
CalibrationDataContainer.h
BTaggingTruthTaggingTool::fillVariables
StatusCode fillVariables(const xAOD::Jet &jet, Analysis::CalibrationDataVariables &x)
Definition: BTaggingTruthTaggingTool.cxx:431
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
index
Definition: index.py:1
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Analysis::SFNamed
@ SFNamed
Definition: CalibrationDataInterfaceROOT.h:70
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
BTaggingTruthTaggingTool::m_coneFlavourLabel
bool m_coneFlavourLabel
if true, use cone-based labelling (as opposed to ghost association)
Definition: BTaggingTruthTaggingTool.h:249
BTaggingTruthTaggingTool::m_cuts
std::vector< TagBin > m_cuts
Definition: BTaggingTruthTaggingTool.h:183
BTaggingEfficiencyTool.h
BTaggingTruthTaggingTool::CalculateResultsONNX
StatusCode CalculateResultsONNX(const std::vector< std::vector< float >> &node_feat, std::vector< float > &tagw, Analysis::TruthTagResults &results, int rand_seed=-1)
Definition: BTaggingTruthTaggingTool.cxx:579
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
BTaggingTruthTaggingTool::chooseTagPermutation
StatusCode chooseTagPermutation(TRFinfo &trfinf, unsigned int nbtag, bool isIncl)
Definition: BTaggingTruthTaggingTool.cxx:849
BTaggingTruthTaggingTool::m_initialised
bool m_initialised
Definition: BTaggingTruthTaggingTool.h:185
BTaggingTruthTaggingTool::m_OperatingBins
std::vector< int > m_OperatingBins
Definition: BTaggingTruthTaggingTool.h:283
BTaggingTruthTaggingTool::getTagBinsConfProb
float getTagBinsConfProb(TRFinfo &trfinf, std::vector< int > &tagws)
Definition: BTaggingTruthTaggingTool.cxx:1012
BTaggingTruthTaggingTool::m_useDevFile
bool m_useDevFile
if true, attempt to retrieve the data/MC efficiency scale factor calibration files from the @PathReso...
Definition: BTaggingTruthTaggingTool.h:247
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
asg
Definition: DataHandleTestTool.h:28
test_pyathena.pt
pt
Definition: test_pyathena.py:11
TRT_PAI_gasdata::SF
const float SF[NF]
Cross sections for Fluor.
Definition: TRT_PAI_gasdata.h:285
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
BTaggingTruthTaggingTool::m_EffTName
std::string m_EffTName
semicolon-separated list of MC efficiency parametrisation names for tau jets
Definition: BTaggingTruthTaggingTool.h:231
BTaggingTruthTaggingTool::TRFinfo::permsWeight
std::vector< std::vector< float > > permsWeight
Definition: BTaggingTruthTaggingTool.h:111
bin
Definition: BinsDiffFromStripMedian.h:43
BTaggingTruthTaggingTool::TagBin
Create a proper constructor for Athena.
Definition: BTaggingTruthTaggingTool.h:54
BTaggingTruthTaggingTool::TRFinfo::jets
std::vector< jetVariable > jets
Definition: BTaggingTruthTaggingTool.h:87
BTaggingTruthTaggingTool::TRFinfo::binsprob_ex
std::vector< float > binsprob_ex
Definition: BTaggingTruthTaggingTool.h:107
BTaggingTruthTaggingTool::ConeFinalPartonFlavourLabel
int ConeFinalPartonFlavourLabel(const xAOD::Jet &jet)
Definition: BTaggingTruthTaggingTool.cxx:1130
IBTaggingSelectionTool::getTaggerWeight
virtual CP::CorrectionCode getTaggerWeight(const xAOD::Jet &jet, double &tagweight) const =0
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
BTaggingTruthTaggingTool::m_maxEta
float m_maxEta
Definition: BTaggingTruthTaggingTool.h:268
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
BTaggingTruthTaggingTool::getDirectTaggedJets
StatusCode getDirectTaggedJets(TRFinfo &trfinf, std::vector< bool > &is_tagged)
Definition: BTaggingTruthTaggingTool.cxx:1033
BTaggingTruthTaggingTool::check_syst_range
StatusCode check_syst_range(unsigned int sys)
Definition: BTaggingTruthTaggingTool.cxx:1091
CP::SystematicVariation
Definition: SystematicVariation.h:47
BTaggingTruthTaggingTool::m_SFLightName
std::string m_SFLightName
name of the data/MC scale factor calibration for light-flavour jets
Definition: BTaggingTruthTaggingTool.h:219
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
asg::AnaToolHandle::setProperty
StatusCode setProperty(const std::string &property, const T2 &value)
set the given property of the tool.
covarianceTool.prob
prob
Definition: covarianceTool.py:678
BTaggingTruthTaggingTool::jetFlavourLabel
int jetFlavourLabel(const xAOD::Jet &jet)
Definition: BTaggingTruthTaggingTool.cxx:1106
x
#define x
BTaggingTruthTaggingTool::TRFinfo::tbins_ex
std::vector< std::vector< int > > tbins_ex
Definition: BTaggingTruthTaggingTool.h:98
BTaggingTruthTaggingTool::m_sys_name
std::vector< std::string > m_sys_name
Definition: BTaggingTruthTaggingTool.h:195
BTaggingTruthTaggingTool::recommendedSystematics
CP::SystematicSet recommendedSystematics() const
the list of all systematics this tool recommends to use
Definition: BTaggingTruthTaggingTool.cxx:117
BTaggingTruthTaggingTool::affectingSystematics
CP::SystematicSet affectingSystematics() const
the list of all systematics this tool can be affected by
Definition: BTaggingTruthTaggingTool.cxx:97
BTaggingTruthTaggingTool::m_eff_syst
std::vector< CP::SystematicSet > m_eff_syst
Definition: BTaggingTruthTaggingTool.h:194
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
BTaggingTruthTaggingTool::setUseSystematics
void setUseSystematics(bool useSystematics)
Definition: BTaggingTruthTaggingTool.cxx:91
Analysis::Total
@ Total
Definition: CalibrationDataInterfaceROOT.h:70
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
IBTaggingEfficiencyTool::setMapIndex
virtual bool setMapIndex(const std::string &flavour, unsigned int index)=0
ANA_CHECK_THROW
#define ANA_CHECK_THROW(EXP)
check whether the given expression was successful, throwing an exception on failure
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:339
BTaggingTruthTaggingTool::TRFinfo::permprob_in
std::vector< float > permprob_in
Definition: BTaggingTruthTaggingTool.h:106
BTaggingTruthTaggingTool::TRFinfo::trfw_ex
std::vector< float > trfw_ex
Definition: BTaggingTruthTaggingTool.h:101
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
BTaggingTruthTaggingTool::getAllEffMC
StatusCode getAllEffMC(TRFinfo &trfinf)
Definition: BTaggingTruthTaggingTool.cxx:602
BTaggingTruthTaggingTool::m_jetAuthor
std::string m_jetAuthor
jet collection name
Definition: BTaggingTruthTaggingTool.h:243
BTaggingTruthTaggingTool::getTRFweight
StatusCode getTRFweight(TRFinfo &trfinf, unsigned int nbtag, bool isInclusive)
Definition: BTaggingTruthTaggingTool.cxx:726
CalibrationDataInterfaceROOT.h
tags
std::vector< std::string > tags
Definition: hcg.cxx:102
BTaggingTruthTaggingTool::m_continuous
bool m_continuous
Definition: BTaggingTruthTaggingTool.h:278
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
BTaggingTruthTaggingTool::m_selTool
asg::AnaToolHandle< IBTaggingSelectionTool > m_selTool
Definition: BTaggingTruthTaggingTool.h:290
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
BTaggingTruthTaggingTool::m_taggerName
std::string m_taggerName
tagger name
Definition: BTaggingTruthTaggingTool.h:237
BTaggingTruthTaggingTool::GetTruthTagWeights
StatusCode GetTruthTagWeights(TRFinfo &trfinf, std::vector< float > &trf_weight_ex, std::vector< float > &trf_weight_in)
Definition: BTaggingTruthTaggingTool.cxx:456
BTaggingTruthTaggingTool::Leading3SignalJets
@ Leading3SignalJets
Definition: BTaggingTruthTaggingTool.h:261
BTaggingTruthTaggingTool::~BTaggingTruthTaggingTool
virtual ~BTaggingTruthTaggingTool()
Definition: BTaggingTruthTaggingTool.cxx:1099
lumiFormat.i
int i
Definition: lumiFormat.py:92
SystematicRegistry.h
BTaggingTruthTaggingTool::m_excludeEV
std::string m_excludeEV
in case of continuous WP you can choose to ignore some of the eigenvectors
Definition: BTaggingTruthTaggingTool.h:253
Analysis::Uncertainty
Uncertainty
specification of type information requested by the user
Definition: CalibrationDataInterfaceROOT.h:70
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
BTaggingTruthTaggingTool::getQuantiles
StatusCode getQuantiles(TRFinfo &trfinf, std::vector< std::vector< int > > &trf_bin_ex, std::vector< std::vector< int > > &trf_bin_in)
Definition: BTaggingTruthTaggingTool.cxx:898
BTaggingTruthTaggingTool::m_continuous2D
bool m_continuous2D
Definition: BTaggingTruthTaggingTool.h:279
BTaggingTruthTaggingTool::m_useQuntile
bool m_useQuntile
Definition: BTaggingTruthTaggingTool.h:277
BTaggingTruthTaggingTool::m_SFTName
std::string m_SFTName
name of the data/MC scale factor calibration for tau jets
Definition: BTaggingTruthTaggingTool.h:217
Analysis::SFEigen
@ SFEigen
Definition: CalibrationDataInterfaceROOT.h:70
BTaggingTruthTaggingTool::ExclusiveConeHadronFlavourLabel
int ExclusiveConeHadronFlavourLabel(const xAOD::Jet &jet)
Definition: BTaggingTruthTaggingTool.cxx:1140
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
IBTaggingEfficiencyTool::getMCEfficiency
virtual CP::CorrectionCode getMCEfficiency(const xAOD::Jet &jet, float &eff)=0
BTaggingTruthTaggingTool::m_doDirectTag
bool m_doDirectTag
possibility to compute the direct tagging SFs map directly from the TruthTaggingTool
Definition: BTaggingTruthTaggingTool.h:255
BTaggingTruthTaggingTool::m_SFBName
std::string m_SFBName
name of the data/MC scale factor calibration for b jets
Definition: BTaggingTruthTaggingTool.h:213
Analysis::TruthTagResults
Definition: TruthTagResults.h:14
BTaggingTruthTaggingTool::m_nbtag
int m_nbtag
Definition: BTaggingTruthTaggingTool.h:281
BTaggingTruthTaggingTool.h
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
IBTaggingEfficiencyTool::getScaleFactor
virtual CP::CorrectionCode getScaleFactor(const xAOD::Jet &jet, float &sf)=0
Declare the interface that the class provides.
xAOD::BTagging_v1
Definition: BTagging_v1.h:39
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
AcceptData.h
BTaggingTruthTaggingTool::m_excludeFromEV
std::string m_excludeFromEV
semicolon-separated list of uncertainties to be excluded from the eigenvector variation procedure
Definition: BTaggingTruthTaggingTool.h:235
CP::IReentrantSystematicsTool::affectingSystematics
virtual SystematicSet affectingSystematics() const =0
the list of all systematics this tool can be affected by
BTaggingTruthTaggingTool::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: BTaggingTruthTaggingTool.cxx:121
BTaggingTruthTaggingTool::getAllEffMCCDI
StatusCode getAllEffMCCDI(TRFinfo &trfinf)
Definition: BTaggingTruthTaggingTool.cxx:646
min
#define min(a, b)
Definition: cfImp.cxx:40
BTaggingTruthTaggingTool::m_useSys
bool m_useSys
Definition: BTaggingTruthTaggingTool.h:280
BTaggingTruthTaggingTool::m_njetsTagStrategy
NjetsTagStrategy m_njetsTagStrategy
Definition: BTaggingTruthTaggingTool.h:262
BTaggingTruthTaggingTool::generateRandomTaggerScores
StatusCode generateRandomTaggerScores(std::vector< std::vector< int > > &quantiles, std::vector< std::vector< float > > &btag_scores, std::vector< std::vector< float > > &ctag_scores)
Definition: BTaggingTruthTaggingTool.cxx:1177
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
BTaggingTruthTaggingTool::m_availableOP_fixCut
std::vector< std::string > m_availableOP_fixCut
Definition: BTaggingTruthTaggingTool.h:178
PathResolver.h
Analysis::CalibrationStatus
CalibrationStatus
Definition: CalibrationDataVariables.h:56
pmontree.code
code
Definition: pmontree.py:443
CP::SystematicSet::insert
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
Definition: SystematicSet.cxx:88
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
BTaggingTruthTaggingTool::jetVariable::vars
Analysis::CalibrationDataVariables vars
Definition: BTaggingTruthTaggingTool.h:80
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
BTaggingTruthTaggingTool::m_oldConeFlavourLabel
bool m_oldConeFlavourLabel
when using cone-based labelling (see above), if true, use the "traditional" (parton-based) labelling ...
Definition: BTaggingTruthTaggingTool.h:251
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
BTaggingTruthTaggingTool::TRFinfo::perms
std::map< int, std::vector< std::vector< std::vector< bool > > > > perms
Definition: BTaggingTruthTaggingTool.h:110
BTaggingTruthTaggingTool::TRFinfo::njets
unsigned int njets
Definition: BTaggingTruthTaggingTool.h:92
BTaggingTruthTaggingTool::getTagPermutation
StatusCode getTagPermutation(TRFinfo &trfinf, std::vector< std::vector< bool > > &trf_chosen_perm_ex, std::vector< std::vector< bool > > &trf_chosen_perm_in)
Definition: BTaggingTruthTaggingTool.cxx:806
BTaggingTruthTaggingTool::TRFinfo::binsprob_in
std::vector< float > binsprob_in
Definition: BTaggingTruthTaggingTool.h:108
BTaggingTruthTaggingTool::chooseAllTagBins
StatusCode chooseAllTagBins(TRFinfo &trfinf)
Definition: BTaggingTruthTaggingTool.cxx:918
python.ami.results
def results
Definition: ami.py:386
BTaggingTruthTaggingTool::m_EffBName
std::string m_EffBName
semicolon-separated list of MC efficiency parametrisation names for b jets
Definition: BTaggingTruthTaggingTool.h:227
BTaggingTruthTaggingTool::chooseTagBins_cum
StatusCode chooseTagBins_cum(TRFinfo &trfinf, std::vector< bool > &tagconf, bool isIncl, unsigned int nbtag)
Definition: BTaggingTruthTaggingTool.cxx:940
BTaggingTruthTaggingTool::AllJets
@ AllJets
Definition: BTaggingTruthTaggingTool.h:261
BTaggingTruthTaggingTool::TRFinfo::rand
TRandom3 rand
Definition: BTaggingTruthTaggingTool.h:94
BTaggingTruthTaggingTool::m_effTool
asg::AnaToolHandle< IBTaggingEfficiencyTool > m_effTool
Definition: BTaggingTruthTaggingTool.h:289
BTaggingTruthTaggingTool::split
std::vector< std::string > split(const std::string &str, char token)
Definition: BTaggingTruthTaggingTool.cxx:1162
BTaggingTruthTaggingTool::isAffectedBySystematic
bool isAffectedBySystematic(const CP::SystematicVariation &systematic) const
Declare the interface that this class provides.
Definition: BTaggingTruthTaggingTool.cxx:111
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
xAOD::BTaggingUtilities::getBTagging
const BTagging * getBTagging(const SG::AuxElement &part)
Access the default xAOD::BTagging object associated to an object.
Definition: BTaggingUtilities.cxx:37
BTaggingTruthTaggingTool::m_EVReductionB
std::string m_EVReductionB
specification of the eigenvector reduction strategy for b jets (if eigenvectors are used)
Definition: BTaggingTruthTaggingTool.h:221
BTaggingTruthTaggingTool::TRFinfo::node_feat
std::vector< std::vector< float > > node_feat
Definition: BTaggingTruthTaggingTool.h:90
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
BTaggingTruthTaggingTool::TRFinfo::perm_in
std::vector< std::vector< bool > > perm_in
Definition: BTaggingTruthTaggingTool.h:97
BTaggingTruthTaggingTool::m_EVReductionLight
std::string m_EVReductionLight
specification of the eigenvector reduction strategy for light-flavour jets (if eigenvectors are used)
Definition: BTaggingTruthTaggingTool.h:225
BTaggingTruthTaggingTool::TRFinfo::permsSumWeight
std::vector< std::vector< float > > permsSumWeight
Definition: BTaggingTruthTaggingTool.h:112
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
BTaggingTruthTaggingTool::generatePermutations
std::vector< std::vector< bool > > generatePermutations(int njets, int tags, int start=0)
Definition: BTaggingTruthTaggingTool.cxx:678
ANA_CHECK_SET_TYPE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:314
BTaggingTruthTaggingTool::CalculateResults
StatusCode CalculateResults(TRFinfo &trfinf, Analysis::TruthTagResults &results, int rand_seed=-1)
Definition: BTaggingTruthTaggingTool.cxx:475
CP::SystematicRegistry
This module implements the central registry for handling systematic uncertainties with CP tools.
Definition: SystematicRegistry.h:25
BTaggingTruthTaggingTool::m_SFCName
std::string m_SFCName
name of the data/MC scale factor calibration for charm jets
Definition: BTaggingTruthTaggingTool.h:215
Analysis::CalibrationDataVariables
Definition: CalibrationDataVariables.h:42
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
BTaggingTruthTaggingTool::applySystematicVariation
StatusCode applySystematicVariation(const CP::SystematicSet &systConfig)
effects: configure this tool for the given list of systematic variations.
Definition: BTaggingTruthTaggingTool.cxx:101
BTaggingTruthTaggingTool::TRFinfo::perm_ex
std::vector< std::vector< bool > > perm_ex
Definition: BTaggingTruthTaggingTool.h:96
BTaggingTruthTaggingTool::setEffMapIndex
StatusCode setEffMapIndex(const std::string &flavour, unsigned int index)
Declare the interface that the class provides.
Definition: BTaggingTruthTaggingTool.cxx:86
BTaggingTruthTaggingTool::chooseAllTagPermutation
StatusCode chooseAllTagPermutation(TRFinfo &trfinf, unsigned int nbtag)
Definition: BTaggingTruthTaggingTool.cxx:823
BTaggingTruthTaggingTool::m_EffFile
std::string m_EffFile
name of the optional MC efficiency file (may be changed by the PathResolver)
Definition: BTaggingTruthTaggingTool.h:211
Analysis::None
@ None
Definition: CalibrationDataInterfaceROOT.h:70
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
IBTaggingSelectionTool::accept
virtual asg::AcceptData accept(const xAOD::IParticle *p) const =0
Declare the interface that the class provides.
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
str
Definition: BTagTrackIpAccessor.cxx:11
BTaggingTruthTaggingTool::getEvtSF
float getEvtSF(TRFinfo &trfinf, std::vector< int > &quantiles)
Definition: BTaggingTruthTaggingTool.cxx:1050
IBTaggingEfficiencyTool::getInefficiencyScaleFactor
virtual CP::CorrectionCode getInefficiencyScaleFactor(const xAOD::Jet &jet, float &sf)=0
BTaggingTruthTaggingTool::m_ignoreSF
bool m_ignoreSF
Definition: BTaggingTruthTaggingTool.h:275
CaloLCW_tf.trf
trf
Definition: CaloLCW_tf.py:20
BTaggingTruthTaggingTool::m_usePerm
bool m_usePerm
Definition: BTaggingTruthTaggingTool.h:276
BTaggingTruthTaggingTool::m_EffLightName
std::string m_EffLightName
semicolon-separated list of MC efficiency parametrisation names for light-flavour jets
Definition: BTaggingTruthTaggingTool.h:233
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
BTaggingTruthTaggingTool::m_nbins
int m_nbins
Definition: BTaggingTruthTaggingTool.h:282
hotSpotInTAG.nb
nb
Definition: hotSpotInTAG.py:164
BTaggingTruthTaggingTool::TRFinfo::effMC_allBins
std::map< int, std::vector< float > > effMC_allBins
Definition: BTaggingTruthTaggingTool.h:104
IParticle
Definition: Event/EventKernel/EventKernel/IParticle.h:43
CP::ISystematicsTool::applySystematicVariation
virtual StatusCode applySystematicVariation(const SystematicSet &systConfig)=0
effects: configure this tool for the given list of systematic variations.
python.compressB64.c
def c
Definition: compressB64.py:93
updateCoolNtuple.limit
int limit
Definition: updateCoolNtuple.py:45
BTaggingTruthTaggingTool::jetVariable::flav
int flav
Definition: BTaggingTruthTaggingTool.h:81
PlotCalibFromCool.be
be
Definition: PlotCalibFromCool.py:398
BTaggingTruthTaggingTool::m_maxRangePt
float m_maxRangePt
Definition: BTaggingTruthTaggingTool.h:270
BTaggingTruthTaggingTool::m_SFFile
std::string m_SFFile
name of the data/MC efficiency scale factor calibration file (may be changed by the PathResolver)
Definition: BTaggingTruthTaggingTool.h:209
BTaggingTruthTaggingTool::m_taggingStrategy
std::string m_taggingStrategy
tagging strategy is required to do TT with GNN, when we don't want to truth tag all the jets (eg....
Definition: BTaggingTruthTaggingTool.h:259
BTaggingTruthTaggingTool::BTaggingTruthTaggingTool
BTaggingTruthTaggingTool(const std::string &name)
Create a constructor for standalone usage.
Definition: BTaggingTruthTaggingTool.cxx:35
BTaggingTruthTaggingTool::m_doOnlyUpVariations
bool m_doOnlyUpVariations
Definition: BTaggingTruthTaggingTool.h:274
BTaggingTruthTaggingTool::TRFinfo
Definition: BTaggingTruthTaggingTool.h:85
BTaggingTruthTaggingTool::trfWeight
float trfWeight(TRFinfo &trfinf, const std::vector< bool > &tags)
Definition: BTaggingTruthTaggingTool.cxx:702
BTaggingTruthTaggingTool::m_OP
std::string m_OP
operating point
Definition: BTaggingTruthTaggingTool.h:239