ATLAS Offline Software
MET.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // This source file implements all of the functions related to MET
6 // in the SUSYObjDef_xAOD class
7 
8 // Local include(s):
10 
11 #include "METInterface/IMETMaker.h"
16 
17 #ifndef XAOD_STANDALONE // For now metadata is Athena-only
19 #endif
20 
21 namespace ST {
22 
24  const xAOD::JetContainer* jet,
25  const xAOD::ElectronContainer* elec,
28  const xAOD::TauJetContainer* taujet,
29  bool doTST, bool doJVTCut,
30  const xAOD::IParticleContainer* invis) {
31  if (!m_tool_init) {
32  ATH_MSG_ERROR("SUSYTools was not initialized!!");
33  return StatusCode::FAILURE;
34  }
35 
36  const xAOD::MissingETContainer* metcore(nullptr);
37  if ( evtStore()->retrieve( metcore, m_inputMETCore ).isFailure() ) {
38  ATH_MSG_WARNING( "Unable to retrieve MET core container: " << m_inputMETCore );
39  return StatusCode::FAILURE;
40  }
41  const xAOD::MissingETAssociationMap* metMap(nullptr);
42  if ( evtStore()->retrieve(metMap, m_inputMETMap).isFailure() ) {
43  ATH_MSG_WARNING("Unable to retrieve MissingETAssociationMap: " << m_inputMETMap);
44  return StatusCode::FAILURE;
45  }
46  // Helper keeps track of object selection flags for this map
47  xAOD::MissingETAssociationHelper metHelper(&(*metMap));
48 
49  std::string softTerm = "SoftClus";
50  if (doTST) {
51  softTerm = "PVSoftTrk";
52  } else if (doJVTCut) {
53  ATH_MSG_WARNING( "Requested CST MET and a JVT cut. This is not a recommended configuration - please consider switching to TST." );
54  }
55 
56  metHelper.resetObjSelectionFlags();
57 
58  // allow creation of proxy MET by flagging objects for "neutrino/ification" as already selected
59  if (invis) {
60  ATH_CHECK( m_metMaker->markInvisible(invis, metHelper, &met) );
61  }
62 
63  if (elec) {
64  ATH_MSG_VERBOSE("Build electron MET");
66  for (const xAOD::Electron* el : *elec) {
67  // pass baseline selection
68  if (acc_baseline(*el)) {
69  bool veto(false);
70  if (invis) {
71  for (const xAOD::IParticle* ipart : *invis) {
72  if (ipart == el) {veto = true; break;}
73  }
74  }
75  if (!veto) metelectron.push_back(el);
76  }
77  }
79  }
80 
81  if (gamma) {
82  ATH_MSG_VERBOSE("Build photon MET");
84  for (const xAOD::Photon* ph : *gamma) {
85  // pass baseline selection
86  if (acc_baseline(*ph)) {
87  bool veto(false);
88  if (invis) {
89  for (const xAOD::IParticle* ipart : *invis) {
90  if (ipart == ph) {veto = true; break;}
91  }
92  }
93  if (!veto) metgamma.push_back(ph);
94  }
95  }
97  }
98 
99  if (taujet) {
100  ATH_MSG_VERBOSE("Build tau MET");
102  for (const xAOD::TauJet* tau : *taujet) {
103  // pass baseline selection
104  if (acc_baseline(*tau)) {
105  bool veto(false);
106  if (invis) {
107  for (const xAOD::IParticle* ipart : *invis) {
108  if (ipart == tau) {veto = true; break;}
109  }
110  }
111  if (!veto) mettau.push_back(tau);
112  }
113  }
115  }
116 
117  if (muon) {
118  ATH_MSG_VERBOSE("Build muon MET");
120  for (const xAOD::Muon* mu : *muon) {
121  bool veto(false);
122  // pass baseline selection
123  if (acc_baseline(*mu)) {
124  if (invis) {
125  for (const xAOD::IParticle* ipart : *invis) {
126  if (ipart == mu) {veto = true; break;}
127  }
128  }
129  if (!veto) metmuon.push_back(mu);
130  }
131  }
133  }
134 
135  if (!jet) {
136  ATH_MSG_WARNING("Invalid jet container specified for MET rebuilding!");
137  return StatusCode::SUCCESS;
138  }
139 
140  ATH_MSG_VERBOSE("Build jet/soft MET");
141  ATH_CHECK( m_metMaker->rebuildJetMET(m_jetTerm, softTerm, &met, jet, metcore, metHelper, doJVTCut) );
142 
143  if (!isData()) {
144  m_metSystTool->setRandomSeed(static_cast<int>(1e6*met[softTerm]->phi()));
145  ATH_MSG_VERBOSE("Original soft term " << met[softTerm]->name() << " (met: " << met[softTerm]->met() << ")" );
146  if ( m_metSystTool->applyCorrection(*met[softTerm], metHelper) != CP::CorrectionCode::Ok ) {
147  ATH_MSG_WARNING("GetMET: Failed to apply MET soft term systematics.");
148  }
149  ATH_MSG_VERBOSE("New soft term value: " << met[softTerm]->met() );
150  }
151 
152  ATH_MSG_VERBOSE("Build MET sum");
153  ATH_CHECK( met::buildMETSum(m_outMETTerm, &met, met[softTerm]->source()) );
154  ATH_MSG_VERBOSE( "Rebuilt MET: Missing Et (x,y): (" << met[m_outMETTerm]->mpx() << "," << met[m_outMETTerm]->mpy() << ")");
155  ATH_MSG_VERBOSE( "Done rebuilding MET." );
156 
157  return StatusCode::SUCCESS;
158 }
159 
160 
162  const xAOD::JetContainer* jet,
163  const xAOD::ElectronContainer* elec,
164  const xAOD::MuonContainer* muon) {
165  if (!m_tool_init) {
166  ATH_MSG_ERROR("SUSYTools was not initialized!!");
167  return StatusCode::FAILURE;
168  }
169 
170  const xAOD::MissingETContainer* metcore(nullptr);
171  if ( evtStore()->retrieve( metcore, m_inputMETCore ).isFailure() ) {
172  ATH_MSG_WARNING( "Unable to retrieve MET core container: " << m_inputMETCore );
173  return StatusCode::FAILURE;
174  }
175  const xAOD::MissingETAssociationMap* metMap(nullptr);
176  if ( evtStore()->retrieve(metMap, m_inputMETMap).isFailure() ) {
177  ATH_MSG_WARNING("Unable to retrieve MissingETAssociationMap: " << m_inputMETMap);
178  return StatusCode::FAILURE;
179  }
180  // Helper keeps track of object selection flags for this map
181  xAOD::MissingETAssociationHelper metHelper(&(*metMap));
182 
183  metHelper.resetObjSelectionFlags();
184 
185  if (elec) {
186  ATH_MSG_VERBOSE("Build electron MET");
188  for (const xAOD::Electron* el : *elec) {
189  // pass baseline selection
190  if (acc_baseline(*el)) metelectron.push_back(el);
191  }
193  }
194 
195  if (muon) {
196  ATH_MSG_VERBOSE("Build muon MET");
198  for (const xAOD::Muon* mu : *muon) {
199  // pass baseline selection
200  if (acc_baseline(*mu)) metmuon.push_back(mu);
201  }
203  }
204 
205  if (!jet) {
206  ATH_MSG_WARNING("Invalid jet container specified for MET rebuilding!");
207  return StatusCode::SUCCESS;
208  }
209  ATH_MSG_VERBOSE("Build jet/soft MET_Track");
210 
211  std::string softTerm = "PVSoftTrk";
212  ATH_CHECK( m_metMaker->rebuildTrackMET(m_jetTerm, softTerm, &met, jet, metcore, metHelper, true) );
213 
214  if (!isData()) {
215  m_metSystTool->setRandomSeed(static_cast<int>(1e6*met[softTerm]->phi()));
216 
217  if (m_trkMETsyst) {
218  ATH_MSG_VERBOSE("Apply trkMET systematics");
219  if ( m_metSystTool->applyCorrection(*met[softTerm],metHelper) != CP::CorrectionCode::Ok )
220  ATH_MSG_WARNING("GetMET: Failed to apply MET track (PVSoftTrk) systematics.");
221  }
222 
223  if (m_trkJetsyst) {
224  ATH_MSG_VERBOSE("Apply Ref Jet trkMET systematics");
226  ATH_MSG_WARNING("GetMET: Failed to apply MET track (RefJet) systematics.");
227  }
228 
229  }
230 
231  ATH_MSG_VERBOSE("Build MET sum");
232  ATH_CHECK( met::buildMETSum("Track", &met, met[softTerm]->source()) );
233  ATH_MSG_VERBOSE( "Done rebuilding MET." );
234 
235  ATH_MSG_VERBOSE( "Track MET: Missing Et (x,y): (" << met["Track"]->mpx() << "," << met["Track"]->mpy() << ")");
236 
237  return StatusCode::SUCCESS;
238 }
239 
241  double &metSignificance,
242  bool doTST, bool doJVTCut) {
243 
244  std::string softTerm = "SoftClus";
245  if (doTST) {
246  softTerm = "PVSoftTrk";
247  } else if (doJVTCut) {
248  ATH_MSG_WARNING( "Requested CST MET and a JVT cut. This is not a recommended configuration - please consider switching to TST." );
249  }
250 
251  const xAOD::EventInfo* evtInfo = nullptr;
252  ATH_CHECK( evtStore()->retrieve( evtInfo, "EventInfo" ) );
254  metSignificance = m_metSignif->GetSignificance();
255  ATH_MSG_VERBOSE( "Obtained MET Significance: " << metSignificance );
256 
257  return StatusCode::SUCCESS;
258 }
259 
260 // Crack region cleaning for PFlow jets: https://twiki.cern.ch/twiki/bin/view/AtlasProtected/HowToCleanJetsR21#EGamma_Crack_Electron_topocluste
262  const xAOD::PhotonContainer* gamma ) const {
263 
265  return true;
266  }
267 
268  bool passPFlowCVCleaning = true;
269 
270  if (elec) {
271  for (const xAOD::Electron* el : *elec) {
272  if (acc_passCrackVetoCleaning.isAvailable(*el)) {
273  if (!acc_passCrackVetoCleaning(*el)) {
274  passPFlowCVCleaning = false;
275  break;
276  }
277  } else {
278  ATH_MSG_WARNING("DFCommonCrackVetoCleaning variable is not available! Use p3830 onwards for PFlow jets!");
279  }
280  }
281  }
282 
283  if (passPFlowCVCleaning && gamma) {
284  for (const xAOD::Photon* ph : *gamma) {
285  if (acc_passCrackVetoCleaning.isAvailable(*ph)) {
286  if (!acc_passCrackVetoCleaning(*ph)) {
287  passPFlowCVCleaning = false;
288  break;
289  }
290  } else {
291  ATH_MSG_WARNING("DFCommonCrackVetoCleaning variable is not available! Use p3830 onwards for PFlow jets!");
292  }
293  }
294  }
295 
296  return passPFlowCVCleaning;
297 }
298 
299 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
ST::SUSYObjDef_xAOD::IsPFlowCrackVetoCleaning
bool IsPFlowCrackVetoCleaning(const xAOD::ElectronContainer *elec=nullptr, const xAOD::PhotonContainer *gamma=nullptr) const override final
Definition: MET.cxx:261
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
ST::SUSYObjDef_xAOD::m_jetTerm
std::string m_jetTerm
Definition: SUSYObjDef_xAOD.h:563
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
ST::SUSYObjDef_xAOD::m_outMETTerm
std::string m_outMETTerm
Definition: SUSYObjDef_xAOD.h:569
IMETMaker::rebuildJetMET
virtual StatusCode rebuildJetMET(const std::string &metJetKey, const std::string &metSoftKey, xAOD::MissingETContainer *metCont, const xAOD::JetContainer *jets, const xAOD::MissingETContainer *metCoreCont, xAOD::MissingETAssociationHelper &helper, bool doJetJVT)=0
IMETMaker::markInvisible
virtual StatusCode markInvisible(const xAOD::IParticleContainer *collection, xAOD::MissingETAssociationHelper &helper, xAOD::MissingETContainer *metCont)=0
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
IMETSystematicsTool::applyCorrection
virtual CP::CorrectionCode applyCorrection(xAOD::MissingET &met, const xAOD::MissingETAssociationHelper &helper) const =0
ST
Definition: Electrons.cxx:41
ST::SUSYObjDef_xAOD::m_jetInputType
int m_jetInputType
Definition: SUSYObjDef_xAOD.h:514
ST::SUSYObjDef_xAOD::GetMETSig
StatusCode GetMETSig(xAOD::MissingETContainer &met, double &metSignificance, bool doTST=true, bool doJVTCut=true) override final
Definition: MET.cxx:240
ST::SUSYObjDef_xAOD::m_metMaker
asg::AnaToolHandle< IMETMaker > m_metMaker
Definition: SUSYObjDef_xAOD.h:911
SUSYObjDef_xAOD.h
IMETMaker.h
ST::SUSYObjDef_xAOD::m_trkJetsyst
bool m_trkJetsyst
Definition: SUSYObjDef_xAOD.h:581
IMETSignificance::GetSignificance
virtual double GetSignificance() const =0
IMETSignificance.h
IMETSystematicsTool.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
ST::SUSYObjDef_xAOD::GetMET
StatusCode GetMET(xAOD::MissingETContainer &met, const xAOD::JetContainer *jet, const xAOD::ElectronContainer *elec=nullptr, const xAOD::MuonContainer *muon=nullptr, const xAOD::PhotonContainer *gamma=nullptr, const xAOD::TauJetContainer *taujet=nullptr, bool doTST=true, bool doJVTCut=true, const xAOD::IParticleContainer *invis=nullptr) override final
Definition: MET.cxx:23
ST::SUSYObjDef_xAOD::m_muonTerm
std::string m_muonTerm
Definition: SUSYObjDef_xAOD.h:564
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
IMETMaker::rebuildMET
virtual StatusCode rebuildMET(const std::string &metKey, xAOD::Type::ObjectType metType, xAOD::MissingETContainer *metCont, const xAOD::IParticleContainer *collection, xAOD::MissingETAssociationHelper &helper, MissingETBase::UsageHandler::Policy objScale=MissingETBase::UsageHandler::PhysicsObject)=0
ST::SUSYObjDef_xAOD::m_tool_init
bool m_tool_init
Definition: SUSYObjDef_xAOD.h:557
ST::SUSYObjDef_xAOD::m_eleTerm
std::string m_eleTerm
Definition: SUSYObjDef_xAOD.h:560
xAOD::MissingETAssociationMap_v1
Definition: MissingETAssociationMap_v1.h:29
ConstDataVector::asDataVector
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
ST::SUSYObjDef_xAOD::m_gammaTerm
std::string m_gammaTerm
Definition: SUSYObjDef_xAOD.h:561
met::buildMETSum
StatusCode buildMETSum(const std::string &totalName, xAOD::MissingETContainer *metCont)
Definition: METHelpers.cxx:64
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
METHelpers.h
met
Definition: IMETSignificance.h:24
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrigVtx::gamma
@ gamma
Definition: TrigParticleTable.h:26
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MissingETAuxContainer.h
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
ST::SUSYObjDef_xAOD::m_tauTerm
std::string m_tauTerm
Definition: SUSYObjDef_xAOD.h:562
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ST::SUSYObjDef_xAOD::m_metSystTool
asg::AnaToolHandle< IMETSystematicsTool > m_metSystTool
Definition: SUSYObjDef_xAOD.h:912
ST::SUSYObjDef_xAOD::isData
bool isData() const override final
Definition: SUSYObjDef_xAOD.h:156
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::JetInput::EMPFlow
@ EMPFlow
Definition: JetContainerInfo.h:64
ST::SUSYObjDef_xAOD::m_inputMETCore
std::string m_inputMETCore
Definition: SUSYObjDef_xAOD.h:567
xAOD::EventInfo_v1::averageInteractionsPerCrossing
float averageInteractionsPerCrossing() const
Average interactions per crossing for all BCIDs - for out-of-time pile-up.
Definition: EventInfo_v1.cxx:397
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
ST::SUSYObjDef_xAOD::GetTrackMET
StatusCode GetTrackMET(xAOD::MissingETContainer &met, const xAOD::JetContainer *jet, const xAOD::ElectronContainer *elec=nullptr, const xAOD::MuonContainer *muon=nullptr) override final
Definition: MET.cxx:161
ST::SUSYObjDef_xAOD::m_trkMETsyst
bool m_trkMETsyst
Definition: SUSYObjDef_xAOD.h:579
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
ConstDataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
IMETSystematicsTool::setRandomSeed
virtual void setRandomSeed(int seed) const =0
xAOD::MissingETAssociationHelper
Definition: MissingETAssociationHelper.h:26
xAOD::Electron_v1
Definition: Electron_v1.h:34
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
Muon
struct TBPatternUnitContext Muon
AthAnalysisHelper.h
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
ST::SUSYObjDef_xAOD::m_inputMETMap
std::string m_inputMETMap
Definition: SUSYObjDef_xAOD.h:566
xAOD::Photon_v1
Definition: Photon_v1.h:37
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
ST::SUSYObjDef_xAOD::m_metSignif
asg::AnaToolHandle< IMETSignificance > m_metSignif
Definition: SUSYObjDef_xAOD.h:913
xAODType::Tau
@ Tau
The object is a tau (jet)
Definition: ObjectType.h:49
IMETMaker::rebuildTrackMET
virtual StatusCode rebuildTrackMET(const std::string &metJetKey, const std::string &metSoftKey, xAOD::MissingETContainer *metCont, const xAOD::JetContainer *jets, const xAOD::MissingETContainer *metCoreCont, xAOD::MissingETAssociationHelper &helper, bool doJetJVT)=0
veto
std::vector< std::string > veto
these patterns are anded
Definition: listroot.cxx:191
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
xAOD::MissingETAssociationHelper::resetObjSelectionFlags
void resetObjSelectionFlags()
Definition: MissingETAssociationHelper.h:44
IMETSignificance::varianceMET
virtual StatusCode varianceMET(xAOD::MissingETContainer *metCont, float avgmu, const std::string &jetTermName, const std::string &softTermName, const std::string &totalMETName)=0