ATLAS Offline Software
xAODMETFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 
10 xAODMETFilter::xAODMETFilter(const std::string& name, ISvcLocator* pSvcLocator)
11  : GenFilter(name,pSvcLocator)
12 {
13  declareProperty("METCut",m_METmin = 10000.);
14  // Normally we'd include them, but this is unstable if using EvtGen
15  declareProperty("UseNeutrinosFromHadrons",m_useHadronicNu = false);
16 }
17 
18 
20 
21  // Retrieve TruthMET container from xAOD MET slimmer, contains (MC::isGenStable() && !MC::isInteracting()) particles
22  const xAOD::TruthParticleContainer* xTruthParticleContainer;
23  if (evtStore()->retrieve(xTruthParticleContainer, "TruthMET").isFailure()) {
24  ATH_MSG_ERROR("No TruthParticle collection with name " << "TruthMET" << " found in StoreGate!");
25  return StatusCode::FAILURE;
26  }
27 
28  double sumx(0), sumy(0);
29  unsigned int nParticles = xTruthParticleContainer->size();
30  for (unsigned int iPart=0; iPart<nParticles; ++iPart) {
31  const xAOD::TruthParticle* missingETparticle = (*xTruthParticleContainer)[iPart];
32  static const SG::ConstAccessor<bool> isPromptAcc ("isPrompt");
33  if (!m_useHadronicNu && MC::isNeutrino(missingETparticle->pdgId()) &&
34  !(isPromptAcc(*missingETparticle))) continue; // ignore neutrinos from hadron decays
35 
36  sumx += missingETparticle->px();
37  sumy += missingETparticle->py();
38 
39  }
40 
41  double met = std::sqrt(sumx*sumx + sumy*sumy);
42 #ifdef HEPMC3
43  const McEventCollection* mecc = 0;
44  if ( evtStore()->retrieve( mecc ).isFailure() || !mecc ){
45  setFilterPassed(false);
46  ATH_MSG_ERROR("Could not retrieve MC Event Collection - might not work");
47  return StatusCode::SUCCESS;
48  }
49 
50  McEventCollection* mec = const_cast<McEventCollection*> (&(*mecc));
51  for (unsigned int i = 0; i < mec->size(); ++i) {
52  if (!(*mec)[i]) continue;
53 
54  //for test filterHT->filterWeight
55  (*mec)[i]->add_attribute("filterMET", std::make_shared<HepMC3::DoubleAttribute>(met/1000.));
56  }
57 
58  setFilterPassed(met >= m_METmin || keepAll());
59 #else
60  setFilterPassed(met >= m_METmin);
61 #endif
62  return StatusCode::SUCCESS;
63 }
64 
65 
66 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAODMETFilter::filterEvent
virtual StatusCode filterEvent()
Definition: xAODMETFilter.cxx:19
xAODMETFilter.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
isNeutrino
bool isNeutrino(const T &p)
APID: the fourth generation neutrinos are neutrinos.
Definition: AtlasPID.h:152
xAOD::TruthParticle_v1::px
float px() const
The x component of the particle's momentum.
xAOD::TruthParticle_v1::py
float py() const
The y component of the particle's momentum.
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
xAODMETFilter::xAODMETFilter
xAODMETFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: xAODMETFilter.cxx:10
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
GenFilter
Base class for event generator filtering modules.
Definition: GenFilter.h:30
met
Definition: IMETSignificance.h:24
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAODMETFilter::m_useHadronicNu
bool m_useHadronicNu
Definition: xAODMETFilter.h:25
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAODMETFilter::m_METmin
double m_METmin
Definition: xAODMETFilter.h:24
HepMCHelpers.h