ATLAS Offline Software
EgammaFSRForMuonsCollectorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // EgammaFSRForMuonsCollectorAlg
7 //
8 // Algorithm to collect photons and electrons which close in dR
9 // to muons as FSR candidates
11 
14 #include <xAODEgamma/Electron.h>
15 
17 
19 
20 namespace CP
21 {
22  EgammaFSRForMuonsCollectorAlg::EgammaFSRForMuonsCollectorAlg(const std::string &name, ISvcLocator *svcLoc)
23  : EL::AnaAlgorithm(name, svcLoc)
24  {
25  }
26 
28  {
29  // Greet the user:
30  ATH_MSG_INFO("Initialising");
31 
32  // WP ID selection
33  if (m_selectionName.empty()) {
34  ATH_MSG_ERROR("Empty string passed as WP selection flag!");
35  return StatusCode::FAILURE;
36  }
37 
41  m_wpDec = std::make_unique<SG::AuxElement::Decorator<uint32_t> > (m_selectionName.value());
42 
43  if (!m_vetoFSR) {
44  ATH_MSG_INFO("Reading container " << m_egammaContKey.getNamePattern() << " for FSR search for muons from " << m_muonContKey.getNamePattern() << ". Those passing " << m_selectionName.value() << " are also accepted.");
45  }
46  else {
47  ATH_MSG_INFO("Reading container " << m_egammaContKey.getNamePattern() << " for FSR search for muons from " << m_muonContKey.getNamePattern() << ". The electrons or photons matching FSR requirements with muons will be vetoed with " << m_selectionName.value());
48 
49  }
50 
51  // Return gracefully:
52  return StatusCode::SUCCESS;
53  }
54 
55 
57  {
58 
59  // const EventContext &ctx = Gaudi::Hive::currentContext();
60 
61  auto selDec = std::make_unique<SG::AuxElement::Decorator<uint32_t> > ("selectEta");
62  auto oqDec = std::make_unique<SG::AuxElement::Decorator<uint32_t> > ("goodOQ");
63  auto cleanDec = std::make_unique<SG::AuxElement::Decorator<uint32_t> > ("isClean");
64 
65  // Loop over systematics
66  for (const auto& sys : m_systematicsList.systematicsVector()) {
67 
68 
69  // Retrieve electrons or photons
70  const xAOD::IParticleContainer* egammaCont = nullptr;
71  ANA_CHECK (m_egammaContKey.retrieve (egammaCont, sys));
72 
73  // Retrieve muons
74  const xAOD::MuonContainer* muonCont = nullptr;
75  ANA_CHECK (m_muonContKey.retrieve (muonCont, sys));
76 
77  // Loop over each electron or photon. If already passing WP selection, decorate passWPorFSR as true
78  // If m_vetoFSR is set, then reverse logic is used - require electron or photon to pass WP selection,
79  // and then veto is if if passes the FSR selection
80  for ( auto eg : *egammaCont ) {
81  if (!m_vetoFSR) {
82  // Standard logic - If passes std WP, accept
83  if ((*m_wpDec)(*eg) == selectionAccept()) {
84  ATH_MSG_DEBUG("Eg passed WP - pt, eta: " << eg->type() << ", " << eg->pt()/1000. << ", " << eg->eta() << ", " << (*m_wpDec)(*eg) );
85  continue; // ok, skip to next el/ph
86  }
87  else ATH_MSG_DEBUG("Eg failed WP: " << m_selectionName.value() << ", " << (*m_wpDec)(*eg) );
88  }
89  else {
90  // Inverted logic - If passes std WP, continue with the FSR search
91  if ((*m_wpDec)(*eg) == selectionAccept()) {
92  ATH_MSG_DEBUG("Veto FSR: Eg passed WP - pt, eta: " << eg->type() << ", " << eg->pt()/1000. << ", " << eg->eta() << ", " << (*m_wpDec)(*eg) );
93 
94  }
95  else {
96  ATH_MSG_DEBUG("Veto FSR: Eg failed WP: " << m_selectionName.value() << ", " << (*m_wpDec)(*eg) << " skipping." );
97  continue; // ok, skip to next el/ph
98  }
99  }
100 
101  const xAOD::Electron* el = (eg->type() == xAODType::Electron) ? dynamic_cast<const xAOD::Electron*>(eg) : 0;
102 
103  ATH_MSG_DEBUG( "Incoming eg: pt, eta, phi " << eg->pt()/1000. << ", " << eg->eta() << ", " << eg->phi() << ", is electron " << (el != 0));
104 
105  // Loop over muons and check dR
106  for ( auto mu : *muonCont ) {
107 
108  float dR = xAOD::P4Helpers::deltaR(*eg, *mu);
109 
110  ATH_MSG_DEBUG( "dR with mu: pt, eta, phi " << dR << ", " << mu->pt()/1000. << ", " << mu->eta() << ", " << mu->phi() );
111 
112  if (dR < m_dRMax) {
113 
114  // if electron (not photon) check track matching
115  bool elmutrackmatchOK = true; // default true for photons
116  if (el) {
117  const xAOD::TrackParticle* electron_track = el->trackParticle();
119  const xAOD::TrackParticle* muon_track = mu->primaryTrackParticle();
120 
121  elmutrackmatchOK =
122  ( (std::abs(electron_track->theta()- muon_track->theta()) < 0.01) &&
123  (xAOD::P4Helpers::deltaPhi(electron_track->phi(), muon_track->phi()) < 0.01) );
124  ATH_MSG_DEBUG( "dtheta trk " << std::abs(electron_track->theta()- muon_track->theta()) << ", dphi trk "
125  << xAOD::P4Helpers::deltaPhi(electron_track->phi(), muon_track->phi()));
126  if (elOrig_track) ATH_MSG_DEBUG( "origTrk: dtheta trk " << std::abs(elOrig_track->theta()- muon_track->theta()) << ", dphi trk "
127  << xAOD::P4Helpers::deltaPhi(elOrig_track->phi(), muon_track->phi()));
128  if (elmutrackmatchOK) ATH_MSG_DEBUG( "track match OK");
129  else ATH_MSG_DEBUG( "track match NOT OK");
130  }
131  if (elmutrackmatchOK) {
132  (*m_wpDec)(*eg) = (m_vetoFSR) ? selectionReject() : selectionAccept();
133  ATH_MSG_DEBUG( "dR OK - wp " << (*m_wpDec)(*eg) );
134 
135  if (selDec->isAvailable(*eg)) ATH_MSG_DEBUG( "selectEta: " << (*selDec)(*eg) );
136  if (oqDec->isAvailable(*eg)) ATH_MSG_DEBUG( "goodOQ: " << (*oqDec)(*eg) );
137  if (cleanDec->isAvailable(*eg)) ATH_MSG_DEBUG( "isClean: " << (*cleanDec)(*eg) );
138 
139  break;
140  }
141  }
142  ATH_MSG_DEBUG( "dR not OK");
143  }
144  }
145  }
146 
147  ATH_MSG_DEBUG("Done !");
148 
149  return StatusCode::SUCCESS;
150  }
151 
152 }
CP::EgammaFSRForMuonsCollectorAlg::EgammaFSRForMuonsCollectorAlg
EgammaFSRForMuonsCollectorAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
Definition: EgammaFSRForMuonsCollectorAlg.cxx:22
CP::EgammaFSRForMuonsCollectorAlg::m_systematicsList
SysListHandle m_systematicsList
the systematics list we run
Definition: EgammaFSRForMuonsCollectorAlg.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ParticleTest.eg
eg
Definition: ParticleTest.py:29
xAODP4Helpers.h
CP::EgammaFSRForMuonsCollectorAlg::m_vetoFSR
Gaudi::Property< bool > m_vetoFSR
Definition: EgammaFSRForMuonsCollectorAlg.h:52
CP::EgammaFSRForMuonsCollectorAlg::m_wpDec
std::unique_ptr< SG::AuxElement::Decorator< uint32_t > > m_wpDec
Decorator for electron or photon working point - used to add additional el/ph.
Definition: EgammaFSRForMuonsCollectorAlg.h:55
CP::EgammaFSRForMuonsCollectorAlg::m_dRMax
Gaudi::Property< float > m_dRMax
Protected data:
Definition: EgammaFSRForMuonsCollectorAlg.h:39
ElectronxAODHelpers.h
xAOD::P4Helpers::deltaPhi
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition: xAODP4Helpers.h:69
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
CP::SysReadHandle::retrieve
::StatusCode retrieve(const T *&object, const CP::SystematicSet &sys) const
retrieve the object for the given name
CP::SysListHandle::systematicsVector
const std::vector< CP::SystematicSet > & systematicsVector() const
the list of systematics to loop over
Definition: SysListHandle.cxx:96
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
CP::EgammaFSRForMuonsCollectorAlg::initialize
StatusCode initialize() override
Definition: EgammaFSRForMuonsCollectorAlg.cxx:27
CP::SysReadHandle::initialize
StatusCode initialize(SysListHandle &sysListHandle)
initialize this handle
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CP::SysListHandle::initialize
::StatusCode initialize()
intialize this property
Definition: SysListHandle.cxx:69
xAOD::P4Helpers::deltaR
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
Definition: xAODP4Helpers.h:150
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
CP::EgammaFSRForMuonsCollectorAlg::m_egammaContKey
SysReadHandle< xAOD::IParticleContainer > m_egammaContKey
Definition: EgammaFSRForMuonsCollectorAlg.h:46
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
CP::selectionReject
constexpr SelectionType selectionReject()
the selection decoration to apply for objects that are rejected
Definition: SelectionHelpers.h:44
CP::EgammaFSRForMuonsCollectorAlg::m_muonContKey
SysReadHandle< xAOD::MuonContainer > m_muonContKey
Definition: EgammaFSRForMuonsCollectorAlg.h:48
CP::EgammaFSRForMuonsCollectorAlg::m_selectionName
Gaudi::Property< std::string > m_selectionName
Definition: EgammaFSRForMuonsCollectorAlg.h:50
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAODType::Electron
@ Electron
The object is an electron.
Definition: ObjectType.h:46
xAOD::Electron_v1
Definition: Electron_v1.h:34
EgammaFSRForMuonsCollectorAlg.h
CP::EgammaFSRForMuonsCollectorAlg::execute
StatusCode execute() override
Definition: EgammaFSRForMuonsCollectorAlg.cxx:56
xAOD::EgammaHelpers::getOriginalTrackParticle
const xAOD::TrackParticle * getOriginalTrackParticle(const xAOD::Electron *el)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the electron.
Definition: ElectronxAODHelpers.cxx:11
CP::selectionAccept
constexpr SelectionType selectionAccept()
the selection decoration to apply for objects that are selected
Definition: SelectionHelpers.h:35
CP::SysReadHandle::getNamePattern
virtual std::string getNamePattern() const override
get the name pattern before substitution
Electron.h
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
xAOD::TrackParticle_v1::theta
float theta() const
Returns the parameter, which has range 0 to .
xAOD::TrackParticle_v1::phi
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .)
SelectionHelpers.h