15 #include "CLHEP/Units/SystemOfUnits.h"
25 const IInterface*
p) :
27 m_trigDecisionTool(
"Trig::TrigDecisionTool/TrigDecisionTool"),
31 declareInterface<DerivationFramework::ISkimmingTool>(
this);
130 if(m_trigDecisionTool.retrieve(DisableTool{m_skipTriggerRequirement}).isFailure()) {
131 ATH_MSG_FATAL(
"Failed to retrieve tool: " << m_trigDecisionTool);
132 return StatusCode::FAILURE;
136 return StatusCode::SUCCESS;
142 ATH_MSG_INFO(
"Processed " << m_ntot <<
" events, " << m_npass <<
" events passed filter ");
143 return StatusCode::SUCCESS;
150 bool acceptEvent(
false);
158 if(m_checkLArError) {
166 if(m_nElectrons>0 or m_nLeptons>0) {
170 if(this->checkElectronQuality(
el))
evt.goodElectrons.push_back(
el);
175 if(m_nMuons>0 or m_nLeptons>0) {
178 for(
const auto *
mu: *muons) {
179 if(this->checkMuonQuality(
mu))
evt.goodMuons.push_back(
mu);
188 if(this->checkJetQuality(
jet))
evt.goodJets.push_back(
jet);
191 for(
unsigned int type(0);
type<NUMBER_OF_MERGED_JET_TYPES;
type++) {
192 if(m_nMergedJets[
type]>0) {
196 if(this->checkMergedJetQuality(
jet,
type))
evt.goodMergedJets[
type].push_back(
jet);
205 for(
const auto *ph: *photons) {
206 if(this->checkPhotonQuality(ph))
evt.goodPhotons.push_back(ph);
214 for(
const auto *trk: *tracks) {
215 if(this->checkTrackQuality(trk))
evt.goodTracks.push_back(trk);
220 if(m_filterType==
"2L") {
221 if(this->check2L(
evt)) acceptEvent =
true;
222 }
else if(m_filterType==
"4L") {
223 if(this->check4L(
evt)) acceptEvent =
true;
224 }
else if(m_filterType==
"TP") {
225 if(this->
checkTP(evt)) acceptEvent =
true;
226 }
else if(m_filterType==
"2L2Q") {
227 if(this->check2L2Q(
evt)) acceptEvent =
true;
228 }
else if(m_filterType==
"JPSI") {
229 if(this->checkJPSI(
evt) or this->checkPHI(
evt)) acceptEvent =
true;
232 if(acceptEvent) m_npass++;
238 if(!
el)
return false;
240 const std::string electronQual(isTight ? m_tightElectronQual : m_electronQual);
241 const double electronEtCut(isTight ? m_tightElectronEtCut : m_electronEtCut);
243 if(electronQual!=
"any") {
246 if(electronQual==
"DFCommonElectronsLHVeryLoose" or
247 electronQual==
"DFCommonElectronsLHLoose" or
248 electronQual==
"DFCommonElectronsLHMedium" or
249 electronQual==
"DFCommonElectronsLHTight" or
250 electronQual==
"DFCommonElectronsML") {
257 value =
static_cast<bool>(qualAcc(*
el));
261 defined =
el->passSelection(
value, electronQual);
263 if(not(
value and defined))
return false;
273 ATH_MSG_WARNING(
"xAOD::TrackParticle does not give summaryValue correctly for xAOD::numberOfPixelHits");
278 ATH_MSG_WARNING(
"xAOD::TrackParticle does not give summaryValue correctly for xAOD::numberOfSCTHits");
289 double eta(trackParticle->
eta());
290 if(fabs(eta)>10.)
return false;
291 double et(caloCluster->
e()/cosh(eta));
293 if(
et<electronEtCut)
return false;
294 if(fabs(eta)>m_electronEtaCut)
return false;
301 if(!
mu)
return false;
303 const std::string muonQual(isTight ? m_tightMuonQual : m_muonQual);
304 const double muonPtCut(isTight ? m_tightMuonPtCut : m_muonPtCut);
306 if(muonQual==
"any") {
308 }
else if(muonQual==
"combined") {
310 }
else if(muonQual==
"standalone") {
311 if(
mu->muonType()!=xAOD::Muon::MuonStandAlone)
return false;
312 }
else if(muonQual==
"lowpt") {
313 if(
mu->muonType()!=xAOD::Muon::SegmentTagged)
return false;
314 }
else if(muonQual==
"combined+lowpt") {
316 }
else if(muonQual==
"inMS") {
317 if(
mu->muonType()==xAOD::Muon::MuonStandAlone and fabs(fabs(
mu->eta())-2.6)>0.12)
return false;
318 }
else if(muonQual==
"DFCommonGoodMuon") {
320 if(!DFCommonGoodMuonAcc.
withDefault(*
mu,
false))
return false;
321 }
else if(muonQual==
"DFCommonMuonsLoose") {
323 if(!DFCommonMuonsLooseAcc.
withDefault(*
mu,
false))
return false;
324 }
else if(muonQual==
"DFCommonMuonsMedium") {
326 if(!DFCommonMuonsMediumAcc.
withDefault(*
mu,
false))
return false;
327 }
else if(muonQual==
"DFCommonMuonsTight") {
329 if(!DFCommonMuonsTightAcc.
withDefault(*
mu,
false))
return false;
335 if(
mu->pt()<muonPtCut)
return false;
336 if(fabs(
mu->eta())>m_muonEtaCut)
return false;
337 if(muonQual!=
"DFCommonGoodMuon" and
338 (
mu->muonType()==xAOD::Muon::CaloTagged and fabs(
mu->eta())>m_caloMuonEtaCut))
return false;
345 if(!
jet)
return false;
347 if(m_jetQual!=
"any") {
351 TLorentzVector tlv(this->jetFourMomentum(
jet));
352 if(tlv.Pt()<m_jetPtCut)
return false;
353 if(fabs(tlv.Eta())>m_jetEtaCut)
return false;
360 if(!
jet)
return false;
362 if(m_mergedJetQual[
type]!=
"any") {
366 if(
jet->pt()<m_mergedJetPtCut[
type])
return false;
367 if(fabs(
jet->eta())>m_mergedJetEtaCut[
type])
return false;
374 if(!ph)
return false;
376 if(m_photonQual!=
"any") {
379 ATH_MSG_WARNING(
"xAOD::Photon does not have menu of " << m_photonQual);
382 if(!
value)
return false;
385 if(ph->
pt()<m_photonPtCut)
return false;
386 if(fabs(ph->
eta())>m_photonEtaCut)
return false;
393 if(!trk)
return false;
395 if(trk->
pt()<m_trackPtCut)
return false;
402 if(!(m_nLeptons>0 and
evt.goodElectrons.size()+
evt.goodMuons.size()>=m_nLeptons))
return false;
403 if(!(
evt.goodJets.size()>=m_nJets and
evt.goodPhotons.size()>=m_nPhotons))
return false;
405 bool isTriggerFired(m_trigger2L.empty() or m_skipTriggerRequirement);
406 for(
unsigned int i(0);
i<m_trigger2L.size();
i++) {
407 if(m_trigDecisionTool->isPassed(m_trigger2L.at(
i))) {
408 isTriggerFired =
true;
412 if(!isTriggerFired)
return false;
414 unsigned int nGoodLeptons(
evt.goodElectrons.size()+
evt.goodMuons.size());
415 std::vector<TLorentzVector> v_tlv(nGoodLeptons);
416 std::vector<bool> v_isElectron(nGoodLeptons);
417 std::vector<bool> v_isTight(nGoodLeptons);
419 for(
unsigned int el_i(0); el_i<
evt.goodElectrons.size(); el_i++) {
421 TLorentzVector tlv(this->electronFourMomentum(
el));
422 v_tlv.at(el_i) = tlv;
423 v_isElectron.at(el_i) =
true;
424 v_isTight.at(el_i) = this->checkElectronQuality(
el,
true);
427 for(
unsigned int mu_i(0); mu_i<
evt.goodMuons.size(); mu_i++) {
430 unsigned int mu_j(
evt.goodElectrons.size()+mu_i);
431 v_tlv.at(mu_j) = tlv;
432 v_isElectron.at(mu_j) =
false;
433 v_isTight.at(mu_j) = this->checkMuonQuality(
mu,
true);
436 for(
unsigned int i0(0); i0<nGoodLeptons; i0++) {
437 for(
unsigned int i1(i0+1); i1<nGoodLeptons; i1++) {
438 if(m_requireTightLeptons and (not (v_isTight.at(i0) or v_isTight.at(i1))))
continue;
440 TLorentzVector tlv_2lep(v_tlv.at(i0) + v_tlv.at(i1));
442 if(tlv_2lep.M()>m_invariantMassCut)
return true;
451 if(!(m_nLeptons>0 and
evt.goodElectrons.size()+
evt.goodMuons.size()>=m_nLeptons))
return false;
452 if(!(
evt.goodJets.size()>=m_nJets and
evt.goodPhotons.size()>=m_nPhotons))
return false;
454 unsigned int nGoodLeptons(
evt.goodElectrons.size()+
evt.goodMuons.size());
455 std::vector<TLorentzVector> v_tlv(nGoodLeptons);
456 std::vector<bool> v_pid(nGoodLeptons);
458 for(
unsigned int el_i(0); el_i<
evt.goodElectrons.size(); el_i++) {
460 TLorentzVector tlv(this->electronFourMomentum(
el));
461 v_tlv.at(el_i) = tlv;
465 if(m_primaryElectronQual4L.empty()) {
469 }
else if(m_primaryElectronQual4L==
"DFCommonElectronsLHVeryLoose" or
470 m_primaryElectronQual4L==
"DFCommonElectronsLHLoose" or
471 m_primaryElectronQual4L==
"DFCommonElectronsLHMedium" or
472 m_primaryElectronQual4L==
"DFCommonElectronsLHTight" or
473 m_primaryElectronQual4L==
"DFCommonElectronsML") {
480 value =
static_cast<bool>(primEleAcc(*
el));
484 defined =
el->passSelection(
value, m_primaryElectronQual4L);
487 v_pid.at(el_i) = (
value and defined);
490 for(
unsigned int mu_i(0); mu_i<
evt.goodMuons.size(); mu_i++) {
493 unsigned int mu_j(
evt.goodElectrons.size()+mu_i);
494 v_tlv.at(mu_j) = tlv;
495 v_pid.at(mu_j) =
true;
498 for(
unsigned int i0(0); i0<nGoodLeptons; i0++) {
499 for(
unsigned int i1(i0+1); i1<nGoodLeptons; i1++) {
500 for(
unsigned int i2(i1+1); i2<nGoodLeptons; i2++) {
501 for(
unsigned int i3(i2+1); i3<nGoodLeptons; i3++) {
502 TLorentzVector tlv_4lep(v_tlv.at(i0) + v_tlv.at(i1) + v_tlv.at(i2) + v_tlv.at(i3));
504 if(tlv_4lep.M()<m_invariantMassCut)
continue;
507 if(fabs((v_tlv.at(i0)+v_tlv.at(i1)).M()-s_MZ)<fabs((v_tlv.at(i2)+v_tlv.at(i3)).M()-s_MZ)) {
508 if(v_pid.at(i0) and v_pid.at(i1))
return true;
510 if(v_pid.at(i2) and v_pid.at(i3))
return true;
512 if(fabs((v_tlv.at(i0)+v_tlv.at(i2)).M()-s_MZ)<fabs((v_tlv.at(i1)+v_tlv.at(i3)).M()-s_MZ)) {
513 if(v_pid.at(i0) and v_pid.at(i2))
return true;
515 if(v_pid.at(i1) and v_pid.at(i3))
return true;
517 if(fabs((v_tlv.at(i0)+v_tlv.at(i3)).M()-s_MZ)<fabs((v_tlv.at(i1)+v_tlv.at(i2)).M()-s_MZ)) {
518 if(v_pid.at(i0) and v_pid.at(i3))
return true;
520 if(v_pid.at(i1) and v_pid.at(i2))
return true;
532 if(!(m_nLeptons>0 and
evt.goodElectrons.size()+
evt.goodMuons.size()>=m_nLeptons))
return false;
534 bool isTriggerFired(m_triggerTP.empty() or m_skipTriggerRequirement);
535 for(
unsigned int i(0);
i<m_triggerTP.size();
i++) {
536 if(m_trigDecisionTool->isPassed(m_triggerTP.at(
i))) {
537 isTriggerFired =
true;
541 if(!isTriggerFired)
return false;
543 unsigned int nGoodLeptons(
evt.goodElectrons.size()+
evt.goodMuons.size());
544 std::vector<TLorentzVector> v_tlv(nGoodLeptons);
545 std::vector<bool> v_isElectron(nGoodLeptons);
547 for(
unsigned int el_i(0); el_i<
evt.goodElectrons.size(); el_i++) {
549 TLorentzVector tlv(this->electronFourMomentum(
el));
550 v_tlv.at(el_i) = tlv;
551 v_isElectron.at(el_i) =
true;
554 for(
unsigned int mu_i(0); mu_i<
evt.goodMuons.size(); mu_i++) {
557 unsigned int mu_j(
evt.goodElectrons.size()+mu_i);
558 v_tlv.at(mu_j) = tlv;
559 v_isElectron.at(mu_j) =
false;
562 for(
unsigned int i0(0); i0<nGoodLeptons; i0++) {
563 for(
unsigned int i1(i0+1); i1<nGoodLeptons; i1++) {
564 if(v_isElectron.at(i0)!=v_isElectron.at(i1))
continue;
566 TLorentzVector tlv_2lep(v_tlv.at(i0) + v_tlv.at(i1));
568 if(tlv_2lep.M()<m_invariantMassCut)
continue;
571 if((v_tlv.at(i0).Pt()>v_tlv.at(i1).Pt() ? v_tlv.at(i0).Pt() : v_tlv.at(i1).Pt()) > (v_isElectron.at(i0) ? m_leadingElectronEtCut : m_leadingMuonPtCut))
return true;
580 if(!(m_nLeptons>0 and
evt.goodElectrons.size()+
evt.goodMuons.size()>=m_nLeptons))
return false;
582 bool isTriggerFired(m_trigger2L2Q.empty() or m_skipTriggerRequirement);
583 for(
unsigned int i(0);
i<m_trigger2L2Q.size();
i++) {
584 if(m_trigDecisionTool->isPassed(m_trigger2L2Q.at(
i))) {
585 isTriggerFired =
true;
589 if(!isTriggerFired)
return false;
591 bool checkGoodJets(
evt.goodJets.size()>=m_nJets and m_nJets>0);
592 for(
unsigned int type(0);
type<NUMBER_OF_MERGED_JET_TYPES;
type++) {
593 if(m_nMergedJets[
type]>0) {
594 checkGoodJets = (checkGoodJets or (
evt.goodMergedJets[
type].size()>=m_nMergedJets[
type]));
597 if(!checkGoodJets)
return false;
599 unsigned int nGoodLeptons(
evt.goodElectrons.size()+
evt.goodMuons.size());
600 std::vector<TLorentzVector> v_tlv(nGoodLeptons);
601 std::vector<bool> v_isElectron(nGoodLeptons);
602 std::vector<bool> v_isTight(nGoodLeptons);
604 for(
unsigned int el_i(0); el_i<
evt.goodElectrons.size(); el_i++) {
606 TLorentzVector tlv(this->electronFourMomentum(
el));
607 v_tlv.at(el_i) = tlv;
608 v_isElectron.at(el_i) =
true;
609 v_isTight.at(el_i) = this->checkElectronQuality(
el,
true);
612 for(
unsigned int mu_i(0); mu_i<
evt.goodMuons.size(); mu_i++) {
615 unsigned int mu_j(
evt.goodElectrons.size()+mu_i);
616 v_tlv.at(mu_j) = tlv;
617 v_isElectron.at(mu_j) =
false;
618 v_isTight.at(mu_j) = this->checkMuonQuality(
mu,
true);
621 for(
unsigned int i0(0); i0<nGoodLeptons; i0++) {
622 for(
unsigned int i1(i0+1); i1<nGoodLeptons; i1++) {
624 if(m_requireTightLeptons and (not (v_isTight.at(i0) or v_isTight.at(i1))))
continue;
626 TLorentzVector tlv_2lep(v_tlv.at(i0) + v_tlv.at(i1));
628 if(tlv_2lep.M()<m_invariantMassCut)
continue;
631 if(v_isElectron.at(i0)) {
632 unsigned int nGoodJetsWithDRCut(0);
633 unsigned int nGoodJets(
evt.goodJets.size());
634 for(
unsigned int j(0); j<nGoodJets; j++) {
636 TLorentzVector jet_tlv(this->jetFourMomentum(
jet));
639 if(dR_0<m_dRElectronJetCut)
continue;
642 if(dR_1<m_dRElectronJetCut)
continue;
644 nGoodJetsWithDRCut++;
647 bool checkGoodJetsWithDRCut(nGoodJetsWithDRCut>=m_nJets and m_nJets>0);
649 for(
unsigned int type(0);
type<NUMBER_OF_MERGED_JET_TYPES;
type++) {
650 if(m_nMergedJets[
type]>0) {
651 unsigned int nGoodMergedJetsWithDRCut(0);
652 unsigned int nGoodMergedJets(
evt.goodMergedJets[
type].size());
653 for(
unsigned int j(0); j<nGoodMergedJets; j++) {
657 if(dR_0<m_dRElectronJetCut)
continue;
660 if(dR_1<m_dRElectronJetCut)
continue;
662 nGoodMergedJetsWithDRCut++;
665 checkGoodJetsWithDRCut = (checkGoodJetsWithDRCut or (nGoodMergedJetsWithDRCut>=m_nMergedJets[
type]));
668 if(!checkGoodJetsWithDRCut)
return false;
672 if((v_tlv.at(i0).Pt()>v_tlv.at(i1).Pt() ? v_tlv.at(i0).Pt() : v_tlv.at(i1).Pt()) > (v_isElectron.at(i0) ? m_leadingElectronEtCut : m_leadingMuonPtCut))
return true;
681 if(!(m_nMuons>0 and
evt.goodMuons.size()>=m_nMuons))
return false;
682 if(!(
evt.goodPhotons.size()>=m_nPhotons))
return false;
684 bool isTriggerFired(m_triggerJPSI.empty() or m_skipTriggerRequirement);
685 for(
unsigned int i(0);
i<m_triggerJPSI.size();
i++) {
686 if(m_trigDecisionTool->isPassed(m_triggerJPSI.at(
i))) {
687 isTriggerFired =
true;
691 if(!isTriggerFired)
return false;
693 std::vector<TLorentzVector> v_tlv(
evt.goodMuons.size());
695 for(
unsigned int mu_i(0); mu_i<
evt.goodMuons.size(); mu_i++) {
698 v_tlv.at(mu_i) = tlv;
701 unsigned int nGoodLeptons(v_tlv.size());
702 for(
unsigned int i0(0); i0<nGoodLeptons; i0++) {
703 for(
unsigned int i1(i0+1); i1<nGoodLeptons; i1++) {
704 TLorentzVector tlv_2lep(v_tlv.at(i0) + v_tlv.at(i1));
707 if((tlv_2lep.M()<m_invariantMassJpsiLowCut or tlv_2lep.M()>m_invariantMassJpsiUpCut) and
708 (tlv_2lep.M()<m_invariantMassUpsilonLowCut or tlv_2lep.M()>m_invariantMassUpsilonUpCut))
continue;
711 if((v_tlv.at(i0).Pt()>v_tlv.at(i1).Pt() ? v_tlv.at(i0).Pt() : v_tlv.at(i1).Pt())>m_leadingMuonPtCut)
return true;
721 if(!(m_nTracks>0 and
evt.goodTracks.size()>=m_nTracks))
return false;
722 if(!(
evt.goodPhotons.size()>=m_nPhotons))
return false;
725 bool isTriggerFired(m_triggerPHI.empty() or m_skipTriggerRequirement);
726 for(
unsigned int i(0);
i<m_triggerPHI.size();
i++) {
727 if(m_trigDecisionTool->isPassed(m_triggerPHI.at(
i))) {
728 isTriggerFired =
true;
732 if(!isTriggerFired)
return false;
735 std::vector<TLorentzVector> v_tlv[2];
736 for(
unsigned int trk_i(0); trk_i<
evt.goodTracks.size(); trk_i++) {
739 tlv.SetPtEtaPhiM(trk->
pt(), trk->
eta(), trk->
phi(), s_MKplus);
740 v_tlv[trk->
charge()>0. ? 0 : 1].push_back(tlv);
744 unsigned int nGoodTracks[2];
745 nGoodTracks[0] = v_tlv[0].size();
746 nGoodTracks[1] = v_tlv[1].size();
747 for(
unsigned int i0(0); i0<nGoodTracks[0]; i0++) {
748 for(
unsigned int i1(0); i1<nGoodTracks[1]; i1++) {
749 TLorentzVector tlv_2trk(v_tlv[0].at(i0) + v_tlv[1].at(i1));
750 if(tlv_2trk.M()<m_invariantMassPhiLowCut or tlv_2trk.M()>m_invariantMassPhiUpCut)
continue;
761 tlv.SetPtEtaPhiE(
el->pt(),
el->eta(),
el->phi(),
el->e());
762 if(m_defaultElectronFourMomentum)
return tlv;
775 double eta(trackParticle->
eta());
776 double phi(trackParticle->
phi());
781 double e(caloCluster->
e());
782 double et(
e/cosh(eta));
784 tlv.SetPtEtaPhiE(
et, eta, phi,
e);
791 tlv.SetPtEtaPhiM(
mu->pt(),
mu->eta(),
mu->phi(),
mu->m());
798 if(m_DFCommonJetFourMomentum) {
804 const float&
pt =DFCommonJets_Calib_ptAcc(*
jet);
805 const float& eta=DFCommonJets_Calib_etaAcc(*
jet);
806 const float& phi=DFCommonJets_Calib_phiAcc(*
jet);
807 const float&
m =DFCommonJets_Calib_mAcc(*
jet);
808 tlv.SetPtEtaPhiM(
pt, eta, phi,
m);
811 tlv.SetPtEtaPhiM(
jet->pt(),
jet->eta(),
jet->phi(),
jet->m());
819 double dPhi(phi1 - phi2);