diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/Root/EventSaverFlatNtuple.cxx b/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/Root/EventSaverFlatNtuple.cxx index 980df371278e90743c13c8365c9f518f3082b601..18d3eb5af3dc5838438c3bdb466f55b58f5d26dd 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/Root/EventSaverFlatNtuple.cxx +++ b/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/Root/EventSaverFlatNtuple.cxx @@ -10,6 +10,7 @@ #include "TopEventSelectionTools/TreeManager.h" #include "TopParticleLevel/TruthTools.h" #include "xAODMissingET/MissingETContainer.h" +#include "xAODBTagging/BTaggingUtilities.h" #include "AthContainers/AuxTypeRegistry.h" @@ -2781,9 +2782,7 @@ namespace top { m_jet_eta[i] = jetPtr->eta(); m_jet_phi[i] = jetPtr->phi(); m_jet_e[i] = jetPtr->e(); - // In R21, list of b-tagging variables is changing and this is outdated - //const xAOD::BTagging* btag(nullptr); - //btag = jetPtr->btagging(); + const xAOD::BTagging* btag = xAOD::BTaggingUtilities::getBTagging(*jetPtr); if (m_config->isMC()) { m_jet_truthflav[i] = -99; if (jetPtr->isAvailable<int>("HadronConeExclTruthLabelID")) { @@ -2808,11 +2807,11 @@ namespace top { static const SG::AuxElement::Accessor< float > accZ0("z0"); static const SG::AuxElement::Accessor< float > accQOverP("qOverP"); - std::vector<const xAOD::TrackParticle*> ghostTracks; + std::vector<const xAOD::TrackParticle*> ghostTracks; if(jetPtr->getAssociatedObjects<xAOD::TrackParticle>(m_config->decoKeyJetGhostTrack(event.m_hashValue),ghostTracks)) { - const unsigned int nghostTracks = ghostTracks.size(); + const unsigned int nghostTracks = ghostTracks.size(); m_jet_ghostTrack_pt[i].clear(); m_jet_ghostTrack_eta[i].clear(); @@ -2888,7 +2887,7 @@ namespace top { if (m_config->bTagAlgo_MV2c10_used()) { double mvx = -999; - //if (btag) btag->MVx_discriminant("MV2c10", mvx); + if (btag) btag->MVx_discriminant("MV2c10", mvx); m_jet_mv2c10[i] = mvx; } @@ -2913,27 +2912,26 @@ namespace top { // calculated by BtaggingSelectionTool for (const std::string& algo : m_config->bTagAlgo_available()) { std::vector<float>& m_jet_DLx_pick = m_jet_DLx.at(algo); - //std::vector<float>& m_jet_DLx_pb_pick = m_jet_DLx_pb.at(algo); - //std::vector<float>& m_jet_DLx_pc_pick = m_jet_DLx_pc.at(algo); - //std::vector<float>& m_jet_DLx_pu_pick = m_jet_DLx_pu.at(algo); + std::vector<float>& m_jet_DLx_pb_pick = m_jet_DLx_pb.at(algo); + std::vector<float>& m_jet_DLx_pc_pick = m_jet_DLx_pc.at(algo); + std::vector<float>& m_jet_DLx_pu_pick = m_jet_DLx_pu.at(algo); const SG::AuxElement::ConstAccessor<float>& DLx_acc = DLx.at(algo); i = 0; for (const auto* const jetPtr : event.m_jets) { m_jet_DLx_pick[i] = DLx_acc(*jetPtr); - //const xAOD::BTagging* btag(nullptr); - //btag = jetPtr->btagging(); - //if (btag) { - // double pu = -999; - // double pc = -999; - // double pb = -999; - // btag->pu(algo, pu); - // btag->pc(algo, pc); - // btag->pb(algo, pb); - // m_jet_DLx_pb_pick[i] = pb; - // m_jet_DLx_pc_pick[i] = pc; - // m_jet_DLx_pu_pick[i] = pu; - //} + const xAOD::BTagging* btag = xAOD::BTaggingUtilities::getBTagging(*jetPtr); + if (btag) { + double pu = -999; + double pc = -999; + double pb = -999; + btag->pu(algo, pu); + btag->pc(algo, pc); + btag->pb(algo, pb); + m_jet_DLx_pb_pick[i] = pb; + m_jet_DLx_pc_pick[i] = pc; + m_jet_DLx_pu_pick[i] = pu; + } ++i; } } @@ -3270,10 +3268,9 @@ namespace top { m_tjet_e[i] = jetPtr->e(); if (m_config->bTagAlgo_MV2c10_used_trkJet()) { - //const xAOD::BTagging* btag(nullptr); - //btag = jetPtr->btagging(); + const xAOD::BTagging* btag = xAOD::BTaggingUtilities::getBTagging(*jetPtr); double mvx = -999; - //if (btag) btag->MVx_discriminant("MV2c10", mvx); + if (btag) btag->MVx_discriminant("MV2c10", mvx); m_tjet_mv2c10[i] = mvx; } @@ -3315,27 +3312,26 @@ namespace top { // calculated by BtaggingSelectionTool for (const std::string& algo : m_config->bTagAlgo_available_trkJet()) { std::vector<float>& m_tjet_DLx_pick = m_tjet_DLx.at(algo); - //std::vector<float>& m_tjet_DLx_pb_pick = m_tjet_DLx_pb.at(algo); - //std::vector<float>& m_tjet_DLx_pc_pick = m_tjet_DLx_pc.at(algo); - //std::vector<float>& m_tjet_DLx_pu_pick = m_tjet_DLx_pu.at(algo); + std::vector<float>& m_tjet_DLx_pb_pick = m_tjet_DLx_pb.at(algo); + std::vector<float>& m_tjet_DLx_pc_pick = m_tjet_DLx_pc.at(algo); + std::vector<float>& m_tjet_DLx_pu_pick = m_tjet_DLx_pu.at(algo); const SG::AuxElement::ConstAccessor<float>& DLx_acc = DLx.at(algo); i = 0; for (const auto* const jetPtr : event.m_trackJets) { m_tjet_DLx_pick[i] = DLx_acc(*jetPtr); - //const xAOD::BTagging* btag(nullptr); - //btag = jetPtr->btagging(); - //if (btag) { - // double pu = -999; - // double pc = -999; - // double pb = -999; - // btag->pu(algo, pu); - // btag->pc(algo, pc); - // btag->pb(algo, pb); - // m_tjet_DLx_pb_pick[i] = pb; - // m_tjet_DLx_pc_pick[i] = pc; - // m_tjet_DLx_pu_pick[i] = pu; - //} + const xAOD::BTagging* btag = xAOD::BTaggingUtilities::getBTagging(*jetPtr); + if (btag) { + double pu = -999; + double pc = -999; + double pb = -999; + btag->pu(algo, pu); + btag->pc(algo, pc); + btag->pb(algo, pb); + m_tjet_DLx_pb_pick[i] = pb; + m_tjet_DLx_pc_pick[i] = pc; + m_tjet_DLx_pu_pick[i] = pu; + } ++i; } } @@ -3556,21 +3552,21 @@ namespace top { } const xAOD::Jet* subjet(nullptr); - //const xAOD::BTagging* btag(nullptr); + const xAOD::BTagging* btag(nullptr); for (auto rc_jet_subjet : rc_jet->getConstituents()) { subjet = static_cast<const xAOD::Jet*>(rc_jet_subjet->rawConstituent()); if (m_config->bTagAlgo_MV2c10_used()) { - //btag = subjet->btagging(); + btag = xAOD::BTaggingUtilities::getBTagging(*subjet); - //double mvx10(-999.); // b-tagging mv2c10 + double mvx10(-999.); // b-tagging mv2c10 - //if (btag) { - // btag->MVx_discriminant("MV2c10", mvx10); - //} else { - // mvx10 = -999.; - //} - //m_rcjetsub_mv2c10[i].push_back(mvx10); + if (btag) { + btag->MVx_discriminant("MV2c10", mvx10); + } else { + mvx10 = -999.; + } + m_rcjetsub_mv2c10[i].push_back(mvx10); } m_rcjetsub_pt[i].push_back(subjet->pt()); @@ -3745,7 +3741,7 @@ namespace top { // loop over subjets const xAOD::Jet* subjet(nullptr); - //const xAOD::BTagging* btag(nullptr); + const xAOD::BTagging* btag(nullptr); m_VarRCjetsubBranches[VarRC + "_" + name + "_sub_pt"][i].clear(); // clear the vector size (otherwise it // grows out of control!) m_VarRCjetsubBranches[VarRC + "_" + name + "_sub_eta"][i].clear(); @@ -3758,16 +3754,16 @@ namespace top { subjet = static_cast<const xAOD::Jet*>(rc_jet_subjet->rawConstituent()); if (m_config->bTagAlgo_MV2c10_used()) { - //btag = subjet->btagging(); + btag = xAOD::BTaggingUtilities::getBTagging(*subjet); - //double mvx10(-999.); // b-tagging mv2c10 + double mvx10(-999.); // b-tagging mv2c10 - //if (btag) { - // btag->MVx_discriminant("MV2c10", mvx10); - //} else { - // mvx10 = -999.; - //} - //m_VarRCjetsubBranches[VarRC + "_" + name + "_sub_mv2c10"][i].push_back(mvx10); + if (btag) { + btag->MVx_discriminant("MV2c10", mvx10); + } else { + mvx10 = -999.; + } + m_VarRCjetsubBranches[VarRC + "_" + name + "_sub_mv2c10"][i].push_back(mvx10); } m_VarRCjetsubBranches[VarRC + "_" + name + "_sub_pt"][i].push_back(subjet->pt()); diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/Root/EventSaverxAODNext.cxx b/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/Root/EventSaverxAODNext.cxx index dd6cd0e2a145dd8d52a910a1c4d84a640da87390..60fb7a5bd36ffe03a4439962ede26d2c768dd7c0 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/Root/EventSaverxAODNext.cxx +++ b/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/Root/EventSaverxAODNext.cxx @@ -20,9 +20,8 @@ #include "xAODMuon/MuonContainer.h" #include "xAODTau/TauJetContainer.h" #include "xAODJet/JetContainer.h" -// #include "xAODBtagging/BTaggingContainer.h" #include "xAODMissingET/MissingETContainer.h" - +#include "xAODBTagging/BTaggingUtilities.h" #include "TFile.h" @@ -496,7 +495,7 @@ namespace top { std::map<unsigned int, unsigned int> currentSystematicThinningMap; std::string sgKey = currentSystematic.second; const xAOD::JetContainer* xaod(nullptr); - top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve electrons"); + top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve jets"); xAOD::JetContainer* output = new xAOD::JetContainer {}; SG::IAuxStore* output_aux = evtStore()->event()->recordAux(sgKey + "Aux."); @@ -528,10 +527,12 @@ namespace top { } // Loop over container // Reset b-tagging links - //for (std::map<unsigned int, unsigned int>::const_iterator i = currentSystematicThinningMap.begin(); - // i != currentSystematicThinningMap.end(); ++i) { - // output->at((*i).second)->setBTaggingLink(xaod->at((*i).first)->btaggingLink()); - //} + for (auto i : currentSystematicThinningMap) { + const xAOD::Jet *jet = output->at(i.second); + const ElementLink< xAOD::BTaggingContainer > el = xAOD::BTaggingUtilities::getBTaggingLink(*xaod->at(i.first)); + xAOD::BTaggingUtilities::setBTaggingLink(*jet, el); + } + } // saveEventObjects top::check(evtStore()->event()->record(output, sgKey), "Failed to record xAOD::JetContainer"); thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap)); @@ -549,7 +550,7 @@ namespace top { std::map<unsigned int, unsigned int> currentSystematicThinningMap; std::string sgKey = currentSystematic.second; const xAOD::JetContainer* xaod(nullptr); - top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve electrons"); + top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve LargeRjets"); xAOD::JetContainer* output = new xAOD::JetContainer {}; SG::IAuxStore* output_aux = evtStore()->event()->recordAux(sgKey + "Aux."); @@ -581,10 +582,11 @@ namespace top { } // Loop over container // Reset b-tagging links - //for (std::map<unsigned int, unsigned int>::const_iterator i = currentSystematicThinningMap.begin(); - // i != currentSystematicThinningMap.end(); ++i) { - // output->at((*i).second)->setBTaggingLink(xaod->at((*i).first)->btaggingLink()); - //} + for (auto i : currentSystematicThinningMap) { + const xAOD::Jet *jet = output->at(i.second); + const ElementLink< xAOD::BTaggingContainer > el = xAOD::BTaggingUtilities::getBTaggingLink(*xaod->at(i.first)); + xAOD::BTaggingUtilities::setBTaggingLink(*jet, el); + } } // saveEventObjects top::check(evtStore()->event()->record(output, sgKey), "Failed to record xAOD::JetContainer"); thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap)); @@ -602,7 +604,7 @@ namespace top { std::map<unsigned int, unsigned int> currentSystematicThinningMap; std::string sgKey = currentSystematic.second; const xAOD::JetContainer* xaod(nullptr); - top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve electrons"); + top::check(evtStore()->retrieve(xaod, sgKey), "Failed to retrieve trackjets"); xAOD::JetContainer* output = new xAOD::JetContainer {}; SG::IAuxStore* output_aux = evtStore()->event()->recordAux(sgKey + "Aux."); @@ -634,10 +636,11 @@ namespace top { } // Loop over container // Reset b-tagging links - //for (std::map<unsigned int, unsigned int>::const_iterator i = currentSystematicThinningMap.begin(); - // i != currentSystematicThinningMap.end(); ++i) { - // output->at((*i).second)->setBTaggingLink(xaod->at((*i).first)->btaggingLink()); - //} + for (auto i : currentSystematicThinningMap) { + const xAOD::Jet *jet = output->at(i.second); + const ElementLink< xAOD::BTaggingContainer > el = xAOD::BTaggingUtilities::getBTaggingLink(*xaod->at(i.first)); + xAOD::BTaggingUtilities::setBTaggingLink(*jet, el); + } } // saveEventObjects top::check(evtStore()->event()->record(output, sgKey), "Failed to record xAOD::JetContainer"); thinningMap->insert(std::make_pair(currentSystematic.first, currentSystematicThinningMap)); diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopEventSelectionTools/Root/MV2c10Selector.cxx b/PhysicsAnalysis/TopPhys/xAOD/TopEventSelectionTools/Root/MV2c10Selector.cxx index 47223c9143f6d5580534a425637692f53c788b4f..6f20425ef5eed6fa0fa2b55ed4331933649b5f31 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopEventSelectionTools/Root/MV2c10Selector.cxx +++ b/PhysicsAnalysis/TopPhys/xAOD/TopEventSelectionTools/Root/MV2c10Selector.cxx @@ -1,9 +1,10 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "TopEventSelectionTools/MV2c10Selector.h" #include "TopEvent/EventTools.h" +#include "xAODBTagging/BTaggingUtilities.h" #include <algorithm> @@ -14,11 +15,11 @@ namespace top { } bool MV2c10Selector::apply(const top::Event& event) const { - auto func = [&](const xAOD::Jet* const /*jetPtr*/) { - //double mv2c10_discriminant = 0.; - //const bool hasMv2c10 = jetPtr->btagging()->MVx_discriminant("MV2c10", mv2c10_discriminant); + auto func = [&](const xAOD::Jet* const jetPtr) { + double mv2c10_discriminant = 0.; + const bool hasMv2c10 = xAOD::BTaggingUtilities::getBTagging(*jetPtr)->MVx_discriminant("MV2c10", mv2c10_discriminant); - //if (hasMv2c10) return mv2c10_discriminant > value(); + if (hasMv2c10) return mv2c10_discriminant > value(); return false; }; diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopExamples/Root/DefaultPlots.cxx b/PhysicsAnalysis/TopPhys/xAOD/TopExamples/Root/DefaultPlots.cxx index 6d70bd0385cf2a55625e59b831f1cd2337b80390..d41c386afcff55acf9194037d0df0908ed42def2 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopExamples/Root/DefaultPlots.cxx +++ b/PhysicsAnalysis/TopPhys/xAOD/TopExamples/Root/DefaultPlots.cxx @@ -10,6 +10,8 @@ #include "TopCorrections/ScaleFactorRetriever.h" +#include "xAODBTagging/BTaggingUtilities.h" + #include <cmath> #include <array> @@ -132,7 +134,7 @@ namespace top { manager.hist("jet_e")->Fill(jetPtr->e() * toGeV, eventWeight); double mv2c10_discriminant = 0.; - //jetPtr->btagging()->MVx_discriminant("MV2c10", mv2c10_discriminant); + xAOD::BTaggingUtilities::getBTagging(*jetPtr)->MVx_discriminant("MV2c10", mv2c10_discriminant); manager.hist("jet_mv2c10")->Fill(mv2c10_discriminant, eventWeight); diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopExamples/Root/LJetsTtresAnalysis.cxx b/PhysicsAnalysis/TopPhys/xAOD/TopExamples/Root/LJetsTtresAnalysis.cxx index a599fd3419c3b1d19c9b1db03f5dcb260667d3e9..00c2d3798b6f99c65bd02e364a387f76de778e70 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopExamples/Root/LJetsTtresAnalysis.cxx +++ b/PhysicsAnalysis/TopPhys/xAOD/TopExamples/Root/LJetsTtresAnalysis.cxx @@ -9,6 +9,8 @@ #include "TopEvent/Event.h" #include "TopEvent/EventTools.h" +#include "xAODBTagging/BTaggingUtilities.h" + #include "TFile.h" #include "TH1.h" @@ -227,10 +229,10 @@ namespace top { vjets.push_back(new TLorentzVector(0, 0, 0, 0)); vjets[z]->SetPtEtaPhiE(topEvent.m_jets[z]->pt(), topEvent.m_jets[z]->eta(), topEvent.m_jets[z]->phi(), topEvent.m_jets[z]->e()); - //const xAOD::BTagging* myBTag = topEvent.m_jets[z]->btagging(); + const xAOD::BTagging* myBTag = xAOD::BTaggingUtilities::getBTagging(*topEvent.m_jets[z]); // https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/BTagingxAODEDM // https://twiki.cern.ch/twiki/bin/view/AtlasProtected/BTaggingBenchmarks - //vjets_btagged.push_back(myBTag->SV1plusIP3D_discriminant() > 1.85); // best discriminant available for 8 TeV + vjets_btagged.push_back(myBTag->SV1plusIP3D_discriminant() > 1.85); // best discriminant available for 8 TeV // (cut at 70%) } TLorentzVector met(0, 0, 0, 0); diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopSystematicObjectMaker/Root/JetObjectCollectionMaker.cxx b/PhysicsAnalysis/TopPhys/xAOD/TopSystematicObjectMaker/Root/JetObjectCollectionMaker.cxx index 6ee10ed8087e27a147d60ae10813e64cce34832f..03b216796bfb45dbf89590b47d1fcc43b06d5697 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopSystematicObjectMaker/Root/JetObjectCollectionMaker.cxx +++ b/PhysicsAnalysis/TopPhys/xAOD/TopSystematicObjectMaker/Root/JetObjectCollectionMaker.cxx @@ -14,6 +14,8 @@ #include "xAODCore/ShallowCopy.h" #include "xAODBase/IParticleHelpers.h" #include "xAODMissingET/MissingETContainer.h" +#include "xAODBTagging/BTaggingUtilities.h" + #include "PATInterfaces/SystematicsUtil.h" #include "TopJetSubstructure/TopJetSubstructure.h" @@ -880,18 +882,18 @@ namespace top { = (trackJets ? m_btagSelToolsDL1Decor_trkJet : m_btagSelToolsDL1Decor); for (std::pair<std::string, ToolHandle<IBTaggingSelectionTool>> algo : m_btagDecorTools) { double DL1_weight = -999.; - //double dl1_pb = -10.; - //double dl1_pc = -10.; - //double dl1_pu = -10.; - //if (jet->btagging()->pb(algo.first, dl1_pb) - // && jet->btagging()->pc(algo.first, dl1_pc) - // && jet->btagging()->pu(algo.first, dl1_pu)) { - // if (!algo.second->getTaggerWeight(dl1_pb, dl1_pc, dl1_pu, DL1_weight)) { - // DL1_weight = -999.; // value for errors from retrieving DL1x weight - // } - //} else { - // DL1_weight = -100.; // value for errors from nonexistence of probabilities - //} + double dl1_pb = -10.; + double dl1_pc = -10.; + double dl1_pu = -10.; + if (xAOD::BTaggingUtilities::getBTagging(*jet)->pb(algo.first, dl1_pb) + && xAOD::BTaggingUtilities::getBTagging(*jet)->pc(algo.first, dl1_pc) + && xAOD::BTaggingUtilities::getBTagging(*jet)->pu(algo.first, dl1_pu)) { + if (!algo.second->getTaggerWeight(dl1_pb, dl1_pc, dl1_pu, DL1_weight)) { + DL1_weight = -999.; // value for errors from retrieving DL1x weight + } + } else { + DL1_weight = -100.; // value for errors from nonexistence of probabilities + } DLx.at(algo.first)(*jet) = DL1_weight; } }