34 m_electronSelection(nullptr),
35 m_fwdElectronSelection(nullptr),
36 m_muonSelection(nullptr),
37 m_softmuonSelection(nullptr),
38 m_tauSelection(nullptr),
39 m_jetSelection(nullptr),
40 m_photonSelection(nullptr),
41 m_largeJetSelection(nullptr),
42 m_trackJetSelection(nullptr),
43 m_jetGhostTrackSelection(nullptr),
44 m_trackSelection(nullptr),
45 m_overlapRemovalToolPostSelection(nullptr),
46 m_electronInJetSubtractor(nullptr),
47 m_passPreORSelection(
"passPreORSelection"),
48 m_passPreORSelectionLoose(
"passPreORSelectionLoose"),
50 m_ORToolDecoration(
"ORToolDecoration"),
51 m_ORToolDecorationLoose(
"ORToolDecorationLoose"),
53 m_overlapRemovalTool_softMuons_Alljets(
"OverlapRemovalTool_softMuons_Alljets")
88 if (
m_config->applyElectronInJetSubtraction()) {
91 "top::ElectronInJetSubtractionCollectionMaker"));
94 "Failed to setProperty of top::ElectronInJetSubtractionCollectionMaker");
101 for (
const std::string&
WP :
m_config->bTagWP()) {
107 for (
const std::string&
WP :
m_config->bTagWP_trkJet()) {
113 return StatusCode::SUCCESS;
171 return StatusCode::SUCCESS;
190 if (
m_config->applyElectronInJetSubtraction()) {
192 m_executeNominal),
"Failed to execute top::ElectronInJetSubtractionCollectionMaker");
227 for (
auto currentSystematic : *
m_config->systSgKeyMapPhotons()) {
234 currentSystematic.second),
235 "TopObjectSelection::applySelectionPreOverlapRemovalPhotons() failed to retrieve photons");
236 ATH_MSG_DEBUG(
" Cut on Photons with key = " << currentSystematic.second);
238 for (
auto photonPtr : *photons) {
255 for (
auto currentSystematic : *
m_config->systSgKeyMapElectrons()) {
262 currentSystematic.second),
263 "TopObjectSelection::applySelectionPreOverlapRemovalElectrons() failed to retrieve electrons");
264 ATH_MSG_DEBUG(
" Cut on Electrons with key = " << currentSystematic.second);
284 for (
const auto& currentSystematic : *
m_config->systSgKeyMapFwdElectrons()) {
291 currentSystematic.second),
292 "TopObjectSelection::applySelectionPreOverlapRemovalFwdElectrons() failed to retrieve fwd electrons");
293 ATH_MSG_DEBUG(
" Cut on Electrons with key = " << currentSystematic.second);
301 "Failed to retrieve EventInfo in TopObjectSelection::applySelectionPreOverlapRemovalFwdElectrons()");
306 for (
auto electronPtr : *fwdelectrons) {
321 for (
auto currentSystematic : *
m_config->systSgKeyMapMuons()) {
327 currentSystematic.second),
328 "TopObjectSelection::applySelectionPreOverlapRemovalMuons() failed to retrieve muons");
330 for (
auto muonPtr : *muons) {
342 for (
const auto& currentSystematic : *
m_config->systSgKeyMapSoftMuons()) {
348 currentSystematic.second),
349 "TopObjectSelection::applySelectionPreOverlapRemovalSoftMuons() failed to retrieve soft muons");
351 for (
const xAOD::Muon* softmuonPtr : *softmuons) {
359 for (
auto currentSystematic : *
m_config->systSgKeyMapTaus()) {
365 currentSystematic.second),
366 "TopObjectSelection::applySelectionPreOverlapRemovalTaus() failed to retrieve taus");
368 for (
auto tauPtr : *taus) {
383 bool isLooseJets(
false);
385 for (
auto currentSystematic : *
m_config->systSgKeyMapJets(isLooseJets)) {
392 currentSystematic.second),
393 "TopObjectSelection::applySelectionPreOverlapRemovalJets() failed to retrieve jets");
394 ATH_MSG_DEBUG(
" Cut on Jets with key = " << currentSystematic.second);
396 for (
auto jetPtr : *
jets) {
401 bool passedJVT_and_fJVT =
true;
402 if (jetPtr->isAvailable<
char>(
"passJVT")) {
403 if (jetPtr->isAvailable<
char>(
"AnalysisTop_fJVTdecision")) {
404 passedJVT_and_fJVT = jetPtr->auxdataConst<
char>(
"passJVT") && jetPtr->auxdataConst<
char>(
"AnalysisTop_fJVTdecision");
407 passedJVT_and_fJVT = jetPtr->auxdataConst<
char>(
"passJVT");
410 else if (jetPtr->isAvailable<
char>(
"AnalysisTop_fJVTdecision")) {
411 passedJVT_and_fJVT = jetPtr->auxdataConst<
char>(
"AnalysisTop_fJVTdecision");
414 if (
m_config->applyElectronInJetSubtraction()) {
415 if (jetPtr->isAvailable<
char>(
"passesFancyOR")) {
416 if (!jetPtr->auxdecor<
char>(
"passesFancyOR"))
passed =
false;
429 if (btagSel.first.find(
"Continuous") == std::string::npos) {
430 bool isTagged =
false;
431 if (std::fabs(jetPtr->eta()) <= 2.5) {
432 isTagged =
static_cast<bool>(btagSel.second->accept(*jetPtr));
434 jetPtr->auxdecor<
char>(
"isbtagged_" + btagSel.first) = isTagged;
436 int tagWeightBin = -2;
437 if (std::fabs(jetPtr->eta()) <= 2.5) {
438 tagWeightBin = btagSel.second->getQuantile(*jetPtr);
440 jetPtr->auxdecor<
int>(
"tagWeightBin_" + btagSel.first) = tagWeightBin;
455 currentSystematic.second),
456 "TopObjectSelection::applySelectionPreOverlapRemovalJets() failed to retrieve jets");
457 ATH_MSG_DEBUG(
" Cut on Jets with key = " << currentSystematic.second);
459 for (
auto jetPtr : *
jets) {
463 bool passedJVT_and_fJVT =
true;
464 if (jetPtr->isAvailable<
char>(
"passJVT")) {
465 if (jetPtr->isAvailable<
char>(
"AnalysisTop_fJVTdecision")) {
466 passedJVT_and_fJVT = jetPtr->auxdataConst<
char>(
"passJVT") && jetPtr->auxdataConst<
char>(
"AnalysisTop_fJVTdecision");
469 passedJVT_and_fJVT = jetPtr->auxdataConst<
char>(
"passJVT");
472 else if (jetPtr->isAvailable<
char>(
"AnalysisTop_fJVTdecision")) {
473 passedJVT_and_fJVT = jetPtr->auxdataConst<
char>(
"AnalysisTop_fJVTdecision");
481 jetPtr->auxdecor<
char>(
m_ORToolDecoration) = (decoration ? (passedJVT_and_fJVT ? 2 : 1) : 0);
486 if (btagSel.first.find(
"Continuous") == std::string::npos) {
487 bool isTagged =
false;
488 if (std::fabs(jetPtr->eta()) < 2.5) {
489 isTagged =
static_cast<bool>(btagSel.second->accept(*jetPtr));
491 jetPtr->auxdecor<
char>(
"isbtagged_" + btagSel.first) = isTagged;
493 int tagWeightBin = -2;
494 if (std::fabs(jetPtr->eta()) < 2.5) {
495 tagWeightBin = btagSel.second->getQuantile(*jetPtr);
497 jetPtr->auxdecor<
int>(
"tagWeightBin_" + btagSel.first) = tagWeightBin;
506 for (
auto currentSystematic : *
m_config->systSgKeyMapLargeRJets()) {
513 currentSystematic.second),
514 "TopObjectSelection::applySelectionPreOverlapRemovalLargeRJets() failed to retrieve large R jets");
516 for (
auto jetPtr : *
jets) {
535 "TopObjectSelection::applySelectionPreOverlapRemovalTrackJets() failed to retrieve track jets");
546 if (
m_config->sgKeyTrackJets() ==
"AntiKtVR30Rmax4Rmin02PV0TrackJets") {
547 float pt_baseline = 5
e3;
551 bool passDRcut =
true;
553 if (jet2->pt() < pt_baseline)
continue;
554 if (jetPtr == jet2)
continue;
559 if (dr_jets <
std::min(radius1, radius2)) passDRcut =
false;
561 jetPtr->auxdecor<
char>(
"passDRcut") = passDRcut;
565 if (btagSel.first.find(
"Continuous") == std::string::npos) {
566 bool isTagged =
false;
567 if (std::fabs(jetPtr->eta()) < 2.5) {
568 isTagged =
static_cast<bool>(btagSel.second->accept(*jetPtr));
570 jetPtr->auxdecor<
char>(
"isbtagged_" + btagSel.first) = isTagged;
572 int tagWeightBin = -2;
573 if (std::fabs(jetPtr->eta()) < 2.5) {
574 tagWeightBin = btagSel.second->getQuantile(*jetPtr);
576 jetPtr->auxdecor<
int>(
"tagWeightBin_" + btagSel.first) = tagWeightBin;
584 auto jetsystematic = *
m_config->systSgKeyMapJets(
false);
586 std::size_t m_nominalHashValue =
nominal.hash();
588 for (
auto currentSystematic : *
m_config->systMapJetGhostTrack()) {
591 std::unordered_map<std::size_t, std::string>::const_iterator jetsyst_name = jetsystematic.find(currentSystematic.first);
592 if (jetsyst_name == jetsystematic.end()) {
593 jetsyst_name = jetsystematic.find(m_nominalHashValue);
604 (*jetsyst_name).second),
605 "TopObjectSelection::applySelectionPreOverlapRemovalJetGhostTracks() failed to retrieve jets");
606 ATH_MSG_DEBUG(
" Cut on JetsGhostTracks with key = " << (*jetsyst_name).second);
610 for (
auto jetPtr : *
jets)
615 std::vector<const xAOD::TrackParticle*> jetTracks;
619 if (jetTracks.size() == 0){
620 ATH_MSG_WARNING(
"TopObjectSelection::applySelectionPreOverlapRemovalJetGhostTracks() failed to retrieve tracks, jet pT and eta:" << jetPtr->pt() <<
" " << std::fabs(jetPtr->eta()) );
626 const auto it_pv = std::find_if(vertices->
cbegin(), vertices->
cend(),
628 {return vtx->vertexType() == xAOD::VxType::PriVtx;});
629 const xAOD::Vertex* primaryVertex = (it_pv == vertices->
cend()) ?
nullptr : *it_pv;
630 if (primaryVertex ==
nullptr)
ATH_MSG_WARNING(
"TopObjectSelection No primary vertex found." );
634 for (
auto jetTrIt : jetTracks){
650 for (
auto currentSystematic : *
m_config->systSgKeyMapTracks()) {
659 currentSystematic.second),
660 "TopObjectSelection::applySelectionPreOverlapRemovalTracks() failed to retrieve tracks");
662 ATH_MSG_DEBUG(
" Cut on Tracks with key = " << currentSystematic.second);
667 const auto it_pv = std::find_if(vertices->
cbegin(), vertices->
cend(),
669 {return vtx->vertexType() == xAOD::VxType::PriVtx;});
670 const xAOD::Vertex* primaryVertex = (it_pv == vertices->
cend()) ?
nullptr : *it_pv;
671 if (primaryVertex ==
nullptr)
ATH_MSG_WARNING(
"TopObjectSelection. No primary vertex found." );
673 for (
auto trackPtr : *tracks) {
686 bool aLooseEvent(
true), aTightEvent(
false);
690 m_config->sgKeyTopSystematicEvents()),
"Failed to apply overlap removal");
694 m_config->sgKeyTopSystematicEventsLoose()),
"Failed to apply overlap removal");
696 return StatusCode::SUCCESS;
703 systEventCont->setStore(systEventAuxCont);
711 std::vector<size_t> sortedSystHashAll(
m_config->systHashAll()->begin(),
m_config->systHashAll()->end());
712 std::sort(sortedSystHashAll.begin(), sortedSystHashAll.end(),
713 [
this](
const size_t& lhs,
const size_t& rhs) {
715 if (this->m_config->isSystNominal(this->m_config->systematicName(lhs))) return true;
717 else if (this->m_config->isSystNominal(this->m_config->systematicName(rhs))) return false;
719 else return(this->m_config->systematicName(lhs) < this->m_config->systematicName(rhs));
722 for (
auto systematicNumber : sortedSystHashAll) {
728 if ((!
m_config->doTightSysts() && !isLoose) &&
729 !
m_config->isSystNominal(
m_config->systematicName(systematicNumber)))
continue;
730 if ((!
m_config->doLooseSysts() && isLoose) &&
731 !
m_config->isSystNominal(
m_config->systematicName(systematicNumber)))
continue;
749 std::string sgKeyNominal = sgKey +
"Nominal";
752 std::string outputSGKeyNominalAux = sgKeyNominal +
"Aux.";
755 StatusCode saveAux =
evtStore()->tds()->record(systEventAuxCont, outputSGKeyNominalAux);
756 if (!
save || !saveAux) {
757 return StatusCode::FAILURE;
759 return StatusCode::SUCCESS;
764 for (
auto x: *systEventContNominal) {
766 systEventCont->
push_back(systEventNominal);
767 *systEventNominal = *
x;
771 std::string outputSGKeyAux = sgKey +
"Aux.";
775 if (!
save || !saveAux) {
776 return StatusCode::FAILURE;
778 return StatusCode::SUCCESS;
793 bool looseLeptonOR(
false);
796 looseLeptonOR =
true;
798 if (
m_config->doOverlapRemovalOnLooseLeptonDef()) {
799 looseLeptonOR =
true;
809 "TopObjectSelection::applyOverlapRemovalPostSelection() failed to retrieve photons");
815 "TopObjectSelection::applyOverlapRemovalPostSelection() failed to retrieve electrons");
821 "TopObjectSelection::applyOverlapRemovalPostSelection() failed to retrieve fwd electrons");
827 "TopObjectSelection::applyOverlapRemovalPostSelection() failed to retrieve muons");
833 "TopObjectSelection::applyOverlapRemovalPostSelection() failed to retrieve soft muons");
839 "TopObjectSelection::applyOverlapRemovalPostSelection() failed to retrieve taus");
845 "TopObjectSelection::applyOverlapRemovalPostSelection() failed to retrieve jets");
851 "TopObjectSelection::applyOverlapRemovalPostSelection() failed to retrieve large-R jets");
857 "TopObjectSelection::applyOverlapRemovalPostSelection() failed to retrieve track jets");
862 "TopObjectSelection::applyOverlapRemovalPostSelection() failed to retrieve tracks");
866 std::vector<unsigned int> goodPhotons, goodElectrons, goodFwdElectrons, goodMuons, goodSoftMuons, goodTaus,
867 goodJets, goodLargeRJets, goodTrackJets, goodTracks;
872 goodPhotons, goodElectrons, goodMuons, goodTaus,
873 goodJets, goodLargeRJets, looseLeptonOR);
876 std::vector<unsigned int> overlapsEl, overlapsMu;
878 currentSystematic->
auxdecor< std::vector<unsigned int> >(
"overlapsEl") = overlapsEl;
881 currentSystematic->
auxdecor< std::vector<unsigned int> >(
"overlapsMu") = overlapsMu;
896 for (
unsigned int i = 0;
i < xaod_tjet->
size(); ++
i) goodTrackJets.push_back(
i);
904 std::string passTopCuts(
"");
905 if (!looseLeptonOR) {
906 passTopCuts =
"passPreORSelection";
909 passTopCuts =
"passPreORSelectionLoose";
912 if (
x->auxdataConst<
char >(passTopCuts) == 1) goodFwdElectrons.push_back(
i);
921 std::string passTopCuts =
"passPreORSelection";
941 std::string passTopCuts =
"passPreORSelection";
945 bool promptMuOR =
false;
947 for (
unsigned int iMu : goodMuons) {
950 if (muPtr->
p4().DeltaR(
x->p4()) < 0.01) {
960 if (
x->auxdataConst<
char >(passTopCuts) == 1 && !promptMuOR && (!
m_config->useJets() || dRmin < m_config->softmuonDRJetcut()))
962 goodSoftMuons.push_back(
i);
976 std::vector<const xAOD::TrackParticle*> jetTracks;
980 "TopObjectSelection::applyOverlapRemovalPostSelection() failed to retrieve jets for ghost matching");
982 unsigned int index= -1;
984 for (
const auto jetPtr : *xaod_jet_ga){
991 if (
std::find(goodJets.begin(), goodJets.end(),
index) == goodJets.end()){
997 std::vector<const xAOD::TrackParticle*> goodJetGhostTracks;
1000 if (jetTracks.size() != 0) {
1002 std::string passTopCuts =
"passPreORSelection";
1004 for (
auto&
track: jetTracks) {
1006 if (
track->auxdataConst<
char >(passTopCuts) == 1) {
1007 goodJetGhostTracks.push_back(
track);
1035 return StatusCode::SUCCESS;
1041 for (
auto iMu : goodSoftMuons) {
1050 std::vector<unsigned int>&
indices) {
1053 std::vector<unsigned int> tmpCopy;
1055 tmpCopy.push_back(
i);
1064 for (
auto i : tmpCopy) {
1076 std::vector<unsigned int>& goodElectrons,
1077 std::vector<unsigned int>& goodMuons,
1078 std::vector<unsigned int>& goodTrackJets) {
1081 std::vector<unsigned int> tmpGoodTrackJets;
1082 for (
auto i : goodTrackJets) {
1083 tmpGoodTrackJets.push_back(
i);
1087 goodTrackJets.clear();
1090 for (
auto jet : *xaod_tjet) {
1091 bool matchEl(
false);
1093 for (
auto el : *xaod_el) {
1094 if ((
std::find(goodElectrons.begin(), goodElectrons.end(), counterEl) != goodElectrons.end())) {
1095 if (
el->p4().DeltaR(
jet->p4()) < 0.2) {
1103 bool matchMu(
false);
1105 for (
auto mu : *xaod_mu) {
1106 if ((
std::find(goodMuons.begin(), goodMuons.end(), counterMu) != goodMuons.end())) {
1107 if (
mu->p4().DeltaR(
jet->p4()) < 0.2) {
1115 if (!(matchEl || matchMu)) goodTrackJets.push_back(counterTrk);
1122 float dRMin = 100.0;
1125 for (
auto iJet : goodJets) {
1143 bool UseLooseNJets =
false;
1145 if (
m_config->doLooseEvents() && !
m_config->doTightEvents()) UseLooseNJets =
true;
1147 if (UseLooseNJets && !isLoose)
return;
1153 eventInfo->
auxdecor<
int >(
"Njet") = nGoodJets;
1163 os <<
"TopObjectSelection configuration\n";
1166 os <<
"Electrons\n";
1167 os <<
" ContainerName: " <<
m_config->sgKeyElectrons() <<
"\n";
1169 os <<
" Selection: ";
1175 os <<
"FwdElectrons\n";
1176 os <<
" ContainerName: " <<
m_config->sgKeyFwdElectrons() <<
"\n";
1178 os <<
" Selection: ";
1185 os <<
" ContainerName: " <<
m_config->sgKeyPhotons() <<
"\n";
1187 os <<
" Selection: ";
1194 os <<
" ContainerName: " <<
m_config->sgKeyMuons() <<
"\n";
1196 os <<
" Selection: ";
1202 os <<
"SoftMuons\n";
1203 os <<
" ContainerName: " <<
m_config->sgKeySoftMuons() <<
"\n";
1205 os <<
" Selection: ";
1223 os <<
" ContainerName: " <<
m_config->sgKeyJets() <<
"\n";
1225 os <<
" Selection: ";
1231 os <<
"LargeJets\n";
1232 os <<
" ContainerName: " <<
m_config->sgKeyLargeRJets() <<
"\n";
1234 os <<
" Selection: ";
1240 os <<
"TrackJets\n";
1241 os <<
" ContainerName: " <<
m_config->sgKeyTrackJets() <<
"\n";
1243 os <<
" Selection: ";
1249 os <<
"GhostTracks\n";
1250 os <<
" ContainerName: " <<
m_config->decoKeyJetGhostTrack() <<
"\n";
1251 if (
m_config->useJetGhostTrack()) {
1252 os <<
" Selection: ";
1261 os <<
" ContainerName: " <<
m_config->sgKeyMissingEt() <<
"\n";
1264 os <<
"OverlapRemoval after object selection: ";