ATLAS Offline Software
METRebuilder.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // METRebuilder.cxx
8 // Implementation file for class METRebuilder
9 // Author: T.J.Khoo<khoo@cern.ch>
11 
12 // METUtilities includes
15 
16 // MET EDM
21 
22 // EDM includes
26 #include "xAODTau/TauxAODHelpers.h"
27 #include "xAODMuon/MuonContainer.h"
28 #include "xAODJet/JetAttributes.h"
29 
30 // Egamma EDM
32 
33 // Tracking EDM
35 #ifdef ROOTCORE
37 #endif
38 
39 // Track errors
41 
44 
45 #ifndef ROOTCORE
46 #include "Gaudi/Interfaces/IOptionsSvc.h"
47 #endif
48 
49 namespace met {
50 
51  // Set up accessors to original object links in case of corrected copy containers
52  const static SG::AuxElement::Accessor<obj_link_t> objLinkAcc("originalObjectLink");
53 
54  using std::vector;
55 
56  using namespace xAOD;
57 
59  // Public methods:
61 
62  // Constructors
64  METRebuilder::METRebuilder(const std::string& name)
65  : AsgTool(name),
66  m_trkseltool("")
67  {
68  //
69  // Property declaration
70  //
71  declareProperty( "TrkSelTool", m_trkseltool );
72  }
73 
74  // Athena algtool's Hooks
77  {
78  ATH_MSG_INFO ("Initializing " << name() << "...");
79 
80  if( m_METMapKey.empty() ) {
81  ATH_MSG_FATAL("Input MissingETComponentMap name must be provided.");
82  return StatusCode::FAILURE;
83  }
84  ATH_MSG_INFO ("Input MET Map: " << m_METMapKey.key());
85 
86  if( m_OutMETKey.empty() ) {
87  ATH_MSG_FATAL("Output MissingETContainer name must be provided.");
88  return StatusCode::FAILURE;
89  }
90  ATH_MSG_INFO ("Output MET Container: " << m_OutMETKey.key());
91 
92  ATH_MSG_INFO ("Configured to rebuild following MET Terms:");
93  if( !m_eleTerm.value().empty() ) {
94  m_doEle = true;
95  if( !m_ElectronContainerKey.empty() ) {
96  m_rebuildEle = true;
97  ATH_MSG_INFO(" Electrons: " << m_ElectronContainerKey.key()
98  << " > " << m_eleTerm.value() );
99  }
100  }
101  if( !m_gammaTerm.value().empty() ) {
102  m_doGamma = true;
103  if( !m_PhotonContainerKey.empty() ) {
104  m_rebuildGamma = true;
105  ATH_MSG_INFO(" Photons: " << m_PhotonContainerKey.key()
106  << " > " << m_gammaTerm.value() );
107  }
108  }
109  if( !m_tauTerm.value().empty() ) {
110  m_doTau = true;
111  if( !m_TauJetContainerKey.empty() ) {
112  m_rebuildTau = true;
113  ATH_MSG_INFO(" Taus: " << m_TauJetContainerKey.key()
114  << " > " << m_tauTerm.value() );
115  }
116  }
117  if( !m_muonTerm.value().empty() ) {
118  m_doMuon = true;
119  if( !m_MuonContainerKey.empty() ) {
120  m_rebuildMuon = true;
121  ATH_MSG_INFO(" Muons: " << m_MuonContainerKey.key()
122  << " > " << m_muonTerm.value() );
123  }
124  }
125  if( !m_JetContainerKey.empty() && !m_jetTerm.value().empty()) {
126  ATH_MSG_INFO(" Jets: " << m_JetContainerKey.key()
127  << " > " << m_jetTerm.value() );
128  } else {
129  ATH_MSG_FATAL("Error in configuration -- jet input and term keys must both be specified.");
130  return StatusCode::FAILURE;
131  }
132  if(m_softTerm.empty()) {
133  if(m_softTermType=="TrackSoftTerm") {
134  m_softTerm = "PVSoftTrk";
135  m_jetDoJvf = true;
136  m_softJetScale = "JetTrackScale";
137  } else if(m_softTermType=="ClusterSoftTerm") {
138  m_softTerm = "SoftClus";
139  m_jetDoJvf = false;
140  m_softJetScale = "JetConstitScaleMomentum";
141  }
142  if(m_softTermType=="Reference") {
143  m_softTerm = "SoftClus";
144  m_jetDoJvf = false;
145  m_softJetScale = "JetConstitScaleMomentum";
146  m_jetPtCut = 0.;
147  }
148  }
149  ATH_MSG_INFO (" Soft: " << m_softTerm);
150 
152  m_pureTrkSoft = (m_softJetScale == "JetTrackScale");
153 
154  if(m_doTracks) {
155  if(m_trkseltool.empty()) {
156 #ifdef ROOTCORE
157  InDet::InDetTrackSelectionTool* trkSelTool = new InDet::InDetTrackSelectionTool("IDTrkSel_MET");
158  ATH_CHECK( trkSelTool->setProperty("maxZ0SinTheta",1.5) );
159  ATH_CHECK( trkSelTool->setProperty("maxD0overSigmaD0",3.) );
160  ATH_CHECK( trkSelTool->setProperty("CutLevel", "TightPrimary") );
161  ATH_CHECK( trkSelTool->initialize() );
162  m_trkseltool = ToolHandle<InDet::IInDetTrackSelectionTool>(trkSelTool);
163 #else
164  ServiceHandle<Gaudi::Interfaces::IOptionsSvc> josvc("JobOptionsSvc",name());
165  std::string toolName = "IDTrkSel_METUtil";
166  ATH_MSG_INFO("METRebuilder: Autoconfiguring " << toolName);
167  m_trkseltool.setTypeAndName("InDet::InDetTrackSelectionTool/"+toolName);
168  std::string fullToolName = "ToolSvc."+toolName;
169  josvc->set(fullToolName + ".maxZ0SinTheta", Gaudi::Utils::toString<float>(1.5));
170  josvc->set(fullToolName + ".maxD0overSigmaD0",Gaudi::Utils::toString<float>(1.5));
171  josvc->set(fullToolName + ".CutLevel","TightPrimary");
172 #endif
173  }
174  ATH_CHECK( m_trkseltool.retrieve() );
175  }
176 
177  // ReadHandleKey(s)
178  ATH_CHECK( m_METMapKey.initialize() );
180  ATH_CHECK( m_PhotonContainerKey.initialize() );
181  ATH_CHECK( m_TauJetContainerKey.initialize() );
182  ATH_CHECK( m_MuonContainerKey.initialize() );
183  ATH_CHECK( m_JetContainerKey.initialize() );
184  ATH_CHECK( m_PVKey.initialize() );
185  // WriteHandleKey(s)
186  ATH_CHECK( m_OutMETKey.initialize() );
187 
188  return StatusCode::SUCCESS;
189  }
190 
192  {
193  ATH_MSG_DEBUG ( name() << " in execute...");
194 
196  if (!METMap.isValid()) {
197  ATH_MSG_WARNING("Unable to retrieve MissingETComponentMap: " << METMap.key());
198  return StatusCode::SUCCESS;
199  }
200 
201  // Create a MissingETContainer with its aux store
203  std::unique_ptr<MissingETContainer> outCont = std::make_unique<xAOD::MissingETContainer>();
204  std::unique_ptr<MissingETAuxContainer> metAuxCont = std::make_unique<xAOD::MissingETAuxContainer>();
205  ATH_CHECK( OutMET.record(std::move(outCont),std::move(metAuxCont) ) );
206 
207  if(m_doEle) {
208  if(m_rebuildEle) {
210  if (!Electrons.isValid()) {
211  ATH_MSG_WARNING("Unable to retrieve ElectronContainer: " << Electrons.key());
212  return StatusCode::SUCCESS;
213  }
214  ATH_CHECK( rebuildMET(m_eleTerm, outCont.get(), Electrons.get(), METMap.get(), m_doTracks) );
215  } else {
216  ATH_CHECK( copyMET(m_eleTerm,outCont.get(),METMap.get()) );
217  }
218  }
219 
220  if(m_doGamma) {
221  if(m_rebuildGamma) {
223  if (!Gamma.isValid()) {
224  ATH_MSG_WARNING("Unable to retrieve GammaContainer: " << Gamma.key());
225  return StatusCode::FAILURE;
226  }
227  ATH_CHECK( rebuildMET(m_gammaTerm, outCont.get(), Gamma.get(), METMap.get(), m_doTracks) );
228  } else {
229  ATH_CHECK( copyMET(m_gammaTerm,outCont.get(),METMap.get()) );
230  }
231  }
232 
233  if(m_doTau) {
234  if(m_rebuildTau) {
236  if (!TauJets.isValid()) {
237  ATH_MSG_WARNING("Unable to retrieve TauJetContainer: " << TauJets.key());
238  return StatusCode::FAILURE;
239  }
240  ATH_CHECK( rebuildMET(m_tauTerm, outCont.get(), TauJets.get(), METMap.get(), m_doTracks) );
241  } else {
242  ATH_CHECK( copyMET(m_tauTerm,outCont.get(),METMap.get()) );
243  }
244  }
245 
246 
247  if(m_doMuon) {
248  if(m_rebuildMuon) {
249  // May need implementation of Eloss correction
250  // Place in separate tool (?)
252  if (!Muons.isValid()) {
253  ATH_MSG_WARNING("Unable to retrieve MuonContainer: " << Muons.key());
254  return StatusCode::FAILURE;
255  }
256  ATH_CHECK( rebuildMET(m_muonTerm, outCont.get(), Muons.get(), METMap.get(), m_doTracks) );
257  } else {
258  ATH_CHECK( copyMET(m_muonTerm,outCont.get(),METMap.get()) );
259  }
260  }
261 
262 
263  // Implementation of the jet/soft term rebuilding
264  // Place in separate tool (?)
266  if (!Jets.isValid()) {
267  ATH_MSG_WARNING("Unable to retrieve JetContainer: " << Jets.key());
268  return StatusCode::FAILURE;
269  }
270  ATH_CHECK( rebuildJetMET(m_jetTerm, m_softTerm, outCont.get(), Jets.get(), METMap.get(), m_doTracks) );
271  ATH_CHECK( buildMETSum(m_outMETTerm, outCont.get()) );
272 
273  return StatusCode::SUCCESS;
274  }
275 
276  StatusCode METRebuilder::copyMET(const std::string& metKey,
277  xAOD::MissingETContainer* metCont,
278  const xAOD::MissingETComponentMap* metMap) {
279 
280  MissingET* metterm = new MissingET();
281  const MissingET* metterm_ref = MissingETComposition::getMissingET(metMap,metKey);
282  metCont->push_back(metterm);
283  *metterm = *metterm_ref;
284 
285  return StatusCode::SUCCESS;
286  }
287 
288  // **** Rebuild generic MET term ****
289 
290  StatusCode METRebuilder::rebuildMET(const std::string& metKey,
291  xAOD::MissingETContainer* metCont,
292  const xAOD::IParticleContainer* collection,
293  const xAOD::MissingETComponentMap* metMap,
294  bool doTracks) {
295  ATH_MSG_DEBUG("Rebuild MET term: " << metKey);
296  const MissingETComponent* component = MissingETComposition::getComponent(metMap,metKey);
297  if(!component) {
298  ATH_MSG_WARNING("Could not find METComponent for " << metKey << " in MET Map!");
299  return StatusCode::FAILURE;
300  }
301  MissingET* met = nullptr; //= new MissingET(0.,0.,0.,metKey,component->metObject()->source());
302  if(fillMET(met, metCont, metKey, component->metObject()->source()) != StatusCode::SUCCESS){
303  ATH_MSG_ERROR("failed to fill MET term");
304  return StatusCode::FAILURE;
305  }
306  // metCont->push_back(met);
307  return rebuildMET(met,collection,component,doTracks);
308  }
309 
311  const xAOD::IParticleContainer* collection,
312  const xAOD::MissingETComponent* component,
313  bool doTracks) {
314 
315  if(component->empty()) return StatusCode::SUCCESS;
316 
317  ATH_MSG_VERBOSE("Rebuilding MET term " << component->metObject()->name());
318 
319  const IParticleContainer* testCollection = dynamic_cast<const IParticleContainer*>(component->objects().front()->container());
320  bool originalInputs = (testCollection == collection);
321  bool matchCollection = true;
322  if(!collection->empty()) {
323  // Consistency test: check that the collection supplied is the original one
324  // used for MET reconstruction, or is derived from this collection
325  if(!originalInputs) {
326  const IParticle* pObj = collection->front();
327  if(!objLinkAcc.isAvailable(*pObj)) {
328  ATH_MSG_WARNING("Modified container provided without originalObjectLink -- cannot proceed.");
329  matchCollection = false;
330  } else {
331  const IParticleContainer* sourceCollection = dynamic_cast<const IParticleContainer*>((*objLinkAcc(*pObj))->container());
332  matchCollection = (sourceCollection == testCollection);
333  }
334  }
335  if(!matchCollection) {
336  ATH_MSG_WARNING("Problem with input object container -- skipping this term.");
337  return StatusCode::SUCCESS;
338  }
339  }
340 
341  // Method flow:
342  // 1. Loop over the objects in the collection
343  // 2. Find them or their originals in the METComponent
344  // 3. Add to the MET term with appropriate weights
345 
346  for( IParticleContainer::const_iterator iObj=collection->begin();
347  iObj!=collection->end(); ++iObj ) {
348 
349  const IParticle* pObj = *iObj;
350  // check if this is a copy - if so, get the original object pointer
351  if(!originalInputs) pObj = *objLinkAcc(*pObj);
352 
353  if(component->findIndex(pObj) != MissingETBase::Numerical::invalidIndex()) {
354  MissingETBase::Types::weight_t objWeight = component->weight(pObj);
355  ATH_MSG_VERBOSE( "Object with pt " << (*iObj)->pt() << " has weight " << objWeight.wet() );
356 
357  if(doTracks) {
358  associateTracks(*iObj);
359  }
360 
361  met->add((*iObj)->pt()*cos((*iObj)->phi())*objWeight.wpx(),
362  (*iObj)->pt()*sin((*iObj)->phi())*objWeight.wpy(),
363  (*iObj)->pt()*objWeight.wet());
364  } // used object in MET
365  else {
366  ATH_MSG_VERBOSE( "Object with pt " << (*iObj)->pt() << " not found." );
367  }
368  }
369 
370  ATH_MSG_DEBUG( "Original " << component->metObject()->name() << " MET --"
371  << " mpx: " << component->metObject()->mpx()
372  << " mpy: " << component->metObject()->mpy()
373  );
374  ATH_MSG_DEBUG( "Rebuilt " << component->metObject()->name() << " MET --"
375  << " mpx: " << met->mpx()
376  << " mpy: " << met->mpy()
377  );
378 
379  return StatusCode::SUCCESS;
380  }
381 
382  // **** Rebuild jet & soft MET terms ****
383 
384  StatusCode METRebuilder::rebuildJetMET(const std::string& jetKey,
385  const std::string& softKey,
386  xAOD::MissingETContainer* metCont,
387  const xAOD::JetContainer* jets,
388  const xAOD::MissingETComponentMap* metMap,
389  bool doTracks,
390  bool doJvfCut,
391  bool pureTrkSoft,
392  const std::string& softJetScale) {
393  float dummy(0);
394  return rebuildJetMET(jetKey,softKey,metCont,jets,metMap,doTracks,
395  doJvfCut,pureTrkSoft,softJetScale,dummy);
396  }
397 
398  StatusCode METRebuilder::rebuildJetMET(const std::string& jetKey,
399  const std::string& softKey,
400  xAOD::MissingETContainer* metCont,
401  const xAOD::JetContainer* jets,
402  const xAOD::MissingETComponentMap* metMap,
403  bool doTracks,
404  bool doJvfCut,
405  bool pureTrkSoft,
406  const std::string& softJetScale,
407  float& stvf) {
408  const MissingETComponent* component = MissingETComposition::getComponent(metMap,jetKey);
409  if(!component) {
410  ATH_MSG_WARNING("Could not find METComponent for " << jetKey << " in MET Map!");
411  return StatusCode::FAILURE;
412  }
413  MissingET* metJet = nullptr; // new MissingET(0.,0.,0.,jetKey,component->metObject()->source());
414  if(fillMET(metJet, metCont, jetKey, component->metObject()->source()) != StatusCode::SUCCESS){
415  ATH_MSG_ERROR("failed to fill MET term");
416  return StatusCode::FAILURE;
417  }
418  // metCont->push_back(metJet);
419  ATH_CHECK( copyMET(softKey,metCont,metMap) );
420  // copy constructor needs correcting.
421  MissingET* metSoft = (*metCont)[softKey];
422  const MissingETComponent* comp_softtrk(nullptr);
423  if(m_doSTVF) {
425  if(!comp_softtrk) {
426  ATH_MSG_WARNING("Could not retrieve soft track component -- STVF calculation failed!");
427  return StatusCode::FAILURE;
428  }
429  }
430  return rebuildJetMET(metJet,metSoft,jets,component,doTracks,
431  doJvfCut,pureTrkSoft,softJetScale,
432  stvf,comp_softtrk);
433  }
434 
436  xAOD::MissingET* metSoft,
437  const xAOD::JetContainer* jets,
438  const xAOD::MissingETComponent* component,
439  bool doTracks,
440  bool doJvfCut,
441  bool pureTrkSoft,
442  const std::string& softJetScale,
443  float& stvf,
444  const xAOD::MissingETComponent* comp_softtrk) {
445 
446  if(component->empty()) return StatusCode::SUCCESS;
447 
448  // const VertexContainer* vtxCont = 0;
450 
451  const Vertex* pv = nullptr;
452 
453 
454  if(doJvfCut || (m_trk_doPVsel && doTracks)) {
455  if (!PV.isValid()) {
456  ATH_MSG_WARNING("Unable to retrieve input primary vertex container");
457 
458  return StatusCode::FAILURE;
459  }
460 
461  for(const auto *const vx : *PV) {
462  if(vx->vertexType()==VxType::PriVtx)
463 
464  {pv = vx; break;}
465 
466  }
467  if(!pv) {
468  ATH_MSG_WARNING("Event has no primary vertex");
469  return StatusCode::SUCCESS;
470  } else{
471  ATH_MSG_DEBUG("Main primary vertex has z = " << pv->z());
472  }
473  }
474 
475 
476  stvf = 0.;
477  float trksumpt_allsoft(0.);
478  if(m_doSTVF) {
479  if(!comp_softtrk) {
480  ATH_MSG_WARNING("Could not retrieve soft track component -- STVF calculation failed!");
481  return StatusCode::FAILURE;
482  }
483  trksumpt_allsoft += comp_softtrk->metObject()->sumet();
484  }
485 
486  const IParticleContainer* testCollection = static_cast<const IParticleContainer*>(component->objects().front()->container());
487  const IParticleContainer* collcast = static_cast<const IParticleContainer*>(jets);
488  bool originalInputs = (testCollection == collcast);
489  bool matchCollection = true;
490  if(!jets->empty()) {
491  // Consistency test: check that the collection supplied is the original one
492  // used for MET reconstruction, or is derived from this collection
493  if(!originalInputs) {
494  const IParticle* pJet = jets->front();
495  if(!objLinkAcc.isAvailable(*pJet)) {
496  ATH_MSG_WARNING("Modified container provided without originalObjectLink -- cannot proceed.");
497  matchCollection = false;
498  } else {
499  const IParticleContainer* sourceCollection = static_cast<const IParticleContainer*>((*objLinkAcc(*pJet))->container());
500  matchCollection = (sourceCollection == testCollection);
501  }
502  }
503  }
504  if(!matchCollection) {
505  ATH_MSG_WARNING("Problem with input object container -- skipping these terms.");
506  return StatusCode::SUCCESS;
507  }
508  // 1. Loop over the jets in the collection
509  // 2. Find them or their originals in the METComponent
510  // 3. Add to the MET term with appropriate weights
511  for( JetContainer::const_iterator iJet=jets->begin();
512  iJet!=jets->end(); ++iJet ) {
513 
514  const xAOD::IParticle* pJet = *iJet;
515  if(!originalInputs) pJet = *objLinkAcc(*pJet);
516 
517  if(component->findIndex(pJet) != MissingETBase::Numerical::invalidIndex()) {
518 
519  MissingETBase::Types::weight_t jetWeight = component->weight(pJet);
520  bool passJVF = true;
521  if(doJvfCut) {
522  vector<float> jvf;
523  (*iJet)->getAttribute<vector<float> >(xAOD::JetAttribute::JVF,jvf);
524  passJVF = (*iJet)->pt()>50e3 || fabs((*iJet)->eta())>2.4 || fabs(jvf[pv->index()])>m_jetJvfCut;
525  ATH_MSG_VERBOSE("Jet with pt " << (*iJet)->pt() << " has jvf = " << jvf[pv->index()]);
526  }
527 
528  if((*iJet)->pt()>m_jetPtCut && passJVF) {
529 
530  ATH_MSG_VERBOSE("Retain jet with pt " << (*iJet)->pt() << " at full scale.");
531 
532  metJet->add((*iJet)->px()*jetWeight.wpx(),
533  (*iJet)->py()*jetWeight.wpy(),
534  (*iJet)->pt()*jetWeight.wet());
535  } // minimum pt cut for jet calibration
536  else {
537  double trkjetpx(0), trkjetpy(0), trkjetpt(0);
538  if(doTracks) {
539  ATH_MSG_VERBOSE("Add tracks from jet with pt " << (*iJet)->pt());
540  vector<const TrackParticle*> jettracks = (*iJet)->getAssociatedObjects<TrackParticle>(xAOD::JetAttribute::GhostTrack);
541  ATH_MSG_VERBOSE("Got jet tracks");
542  for(const auto& trk : jettracks) {
543  if(!trk) continue;
544  bool badTrack = false;
545  if( (fabs((trk)->eta())<1.5 && (trk)->pt()>200e3) ||
546  (fabs((trk)->eta())>=1.5 && (trk)->pt()>120e3) ) {
547  // Get relative error on qoverp
548  float Rerr = Amg::error(trk->definingParametersCovMatrix(),4)/fabs(trk->qOverP());
549  // Simplified cut -- remove tracks that are more energetic than the jet
550  if(Rerr>0.4 || trk->pt()>2*(*iJet)->pt()) badTrack = true;
551  } // additional cuts against high pt mismeasured tracks
552  bool uniqueTrack = true;
553  uniqueTrack = !m_trkUsedDec(*trk);
554  if(!badTrack && uniqueTrack) {
555  if(acceptTrack(trk,pv)) {
556  ATH_MSG_VERBOSE(" + track with pt " << trk->pt());
557  trkjetpx += trk->pt()*cos(trk->phi());
558  trkjetpy += trk->pt()*sin(trk->phi());
559  trkjetpt += trk->pt();
560  } else {
561  ATH_MSG_VERBOSE(" - track failed badtrack/uniqueness/PV");
562  if(m_doSTVF && acceptTrack(trk,nullptr)) {
563  trksumpt_allsoft += trk->pt();
564  } // STVF
565  } // track selection
566  } // reject bad/duplicate tracks
567  } // track loop
568  } // track-based soft term
569  if(pureTrkSoft){
570  metSoft->add(trkjetpx,trkjetpy,trkjetpt);
571  } else {
572  // just add the weighted constituent-scale jet
573  xAOD::JetFourMom_t jetP = (*iJet)->jetP4(softJetScale);
574  ATH_MSG_VERBOSE("Soft jet pt = " << jetP.Pt() << ", track pt = " << trkjetpt);
575  if(trkjetpt>jetP.Pt() || !passJVF) { // use tracks if higher scale than calo jet or fail JVF cut in central region
576  ATH_MSG_VERBOSE("Add jet with pt " << (*iJet)->pt()
577  << " at track scale (pt = " << trkjetpt << ").");
578  metSoft->add(trkjetpx,trkjetpy,trkjetpt);
579  } else {
580  ATH_MSG_VERBOSE("Add jet with pt " << (*iJet)->pt()
581  << " at constituent scale (pt = " << jetP.Pt() << ").");
582  metSoft->add(jetP.Px()*jetWeight.wpx(),
583  jetP.Py()*jetWeight.wpy(),
584  jetP.Pt()*jetWeight.wet());
585  } // otherwise, use calo jet at chosen scale
586  } // cluster-based soft term
587  } // jets below threshold should be added to the soft terms
588  } // used jet in MET
589  }
590 
591  ATH_MSG_DEBUG( "Original jet MET --"
592  << " mpx: " << component->metObject()->mpx()
593  << " mpy: " << component->metObject()->mpy()
594  );
595  ATH_MSG_DEBUG( "Rebuilt jet MET --"
596  << " mpx: " << metJet->mpx()
597  << " mpy: " << metJet->mpy()
598  );
599 
600  ATH_MSG_DEBUG( "Rebuilt MET soft --"
601  << " mpx: " << metSoft->mpx()
602  << " mpy: " << metSoft->mpy()
603  );
604 
605  if(m_doSTVF) stvf = metSoft->sumet()/trksumpt_allsoft;
606 
607  return StatusCode::SUCCESS;
608  }
609 
611  // Protected methods:
613 
614  // Implement for now, but should move to common tools when possible
616  const xAOD::Vertex* pv) const
617  {
618 
619  // if(trk->d0()>m_trk_d0Max) return false;
620  // if(fabs(trk->z0()+trk->vz() - pv->z()) > m_trk_z0Max) return false;
621  if(m_trk_doPVsel && pv) {
622  return static_cast<bool>(m_trkseltool->accept( *trk, pv ));
623  }
624  else {
625  return static_cast<bool>(m_trkseltool->accept( trk ));
626  }
627  }
628 
630 
631  if(obj->type()==xAOD::Type::Electron) {
632  const xAOD::Electron* el = static_cast<const xAOD::Electron*>(obj);
633  for(size_t iTrk=0; iTrk<el->nTrackParticles(); ++iTrk) {
634  const TrackParticle* eltrk = xAOD::EgammaHelpers::getOriginalTrackParticleFromGSF(el->trackParticle(iTrk));
635  if(eltrk) m_trkUsedDec(*eltrk) = true;
636  }
637  }
638  if(obj->type()==xAOD::Type::Photon) {
639  const xAOD::Photon* ph = static_cast<const xAOD::Photon*>(obj);
640  for(size_t iVtx=0; iVtx<ph->nVertices(); ++iVtx) {
641  const xAOD::Vertex* phvx = ph->vertex(iVtx);
642 
643  if(phvx) {
644  for(size_t iTrk=0; iTrk<phvx->nTrackParticles(); ++iTrk) {
646  if(phtrk) m_trkUsedDec(*phtrk) = true;
647  }
648  }
649  }
650  }
651  if(obj->type()==xAOD::Type::Tau) {
652  const xAOD::TauJet* tau = static_cast<const xAOD::TauJet*>(obj);
654  //const std::vector< ElementLink< xAOD::TrackParticleContainer > >& trackLinks = tau->trackLinks();
655  //for(const auto& trklink : trackLinks) {
656  // if(trklink.isValid()) {m_trkUsedDec(**trklink) = true;}
657  // else { ATH_MSG_WARNING("Invalid tau track link"); }
658  //}
659  //const std::vector< ElementLink< xAOD::TrackParticleContainer > >& otherTrackLinks = tau->otherTrackLinks();
660  //for(const auto& trklink : otherTrackLinks) {
661  // if(trklink.isValid()) {
662  // double dR = (*tau->jetLink())->p4().DeltaR((*trklink)->p4());
663  // if(dR<0.2) {
664  // m_trkUsedDec(**trklink) = true;
665  // }
666  // } else { ATH_MSG_WARNING("Invalid tau track link"); }
667  //}
668 
669  // TauJet_v3
670  //all track links dR<0.2 no track quality
671  std::vector<ElementLink< xAOD::TrackParticleContainer> > trackLinks = xAOD::TauHelpers::trackParticleLinks(tau, xAOD::TauJetParameters::coreTrack);
672  for(const auto& trklink : trackLinks) {
673  if(trklink.isValid()) {m_trkUsedDec(**trklink) = true;}
674  else { ATH_MSG_WARNING("Invalid tau track link"); }
675  }
676  }
677  if(obj->type()==xAOD::Type::Muon) {
678  const xAOD::Muon* mu = static_cast<const xAOD::Muon*>(obj);
679  if(mu->inDetTrackParticleLink().isValid()) {
680  m_trkUsedDec(**mu->inDetTrackParticleLink()) = true;
681  }
682  }
683  }
684 
685 } //> end namespace met
met::METRebuilder::m_PVKey
SG::ReadHandleKey< xAOD::VertexContainer > m_PVKey
Definition: METRebuilder.h:157
xAOD::MissingETComponentMap_v1
Definition: MissingETComponentMap_v1.h:25
WriteHandle.h
Handle class for recording to StoreGate.
xAOD::Photon_v1::nVertices
size_t nVertices() const
Return the number xAOD::Vertex/vertices that match the photon candidate.
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition: Vertex_v1.cxx:270
met::METRebuilder::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: METRebuilder.cxx:76
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
met::METRebuilder::m_gammaTerm
Gaudi::Property< std::string > m_gammaTerm
Definition: METRebuilder.h:163
met::METRebuilder::m_trkUsedDec
SG::AuxElement::Decorator< char > m_trkUsedDec
Definition: METRebuilder.h:193
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
xAOD::MissingET_v1::sumet
float sumet() const
Returns.
xAOD::MissingETComponent_v1::weight
Weight weight(const IParticle *pPart) const
Get kinematic weight for a given object.
met::METRebuilder::m_doTau
bool m_doTau
Definition: METRebuilder.h:175
met::METRebuilder::m_METMapKey
SG::ReadHandleKey< xAOD::MissingETComponentMap > m_METMapKey
Definition: METRebuilder.h:151
met::METRebuilder::m_doGamma
bool m_doGamma
Definition: METRebuilder.h:174
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
EventPrimitivesHelpers.h
xAOD::MissingETComponent_v1::Weight::wet
double wet() const
Returns .
JetAttributes.h
test_pyathena.pt
pt
Definition: test_pyathena.py:11
ElectronxAODHelpers.h
InDet::InDetTrackSelectionTool::initialize
virtual StatusCode initialize() override
Function initialising the tool.
Definition: InDetTrackSelectionTool.cxx:241
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
met::METRebuilder::m_rebuildTau
bool m_rebuildTau
Definition: METRebuilder.h:180
VP1PartSpect::Gamma
@ Gamma
Definition: VP1PartSpectFlags.h:22
met::METRebuilder::m_jetJvfCut
Gaudi::Property< double > m_jetJvfCut
Definition: METRebuilder.h:186
MissingETBase::Numerical::invalidIndex
static size_t invalidIndex()
Access invalid index indicator.
Definition: MissingETBase.h:103
objLinkAcc
const ort::objLinkAccessor_t objLinkAcc("overlapObject")
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
MissingETBase::Source::idTrack
static Types::bitmask_t idTrack(Region reg=Region::FullAcceptance)
Bit pattern indicating a ID Track MET term.
Definition: MissingETBase.h:366
MissingETBase::Source::Type::SoftEvent
@ SoftEvent
Indicator for the MET term from reconstructed soft event signals (tracks, clusters) or MC truth parti...
met::METRebuilder::m_TauJetContainerKey
SG::ReadHandleKey< xAOD::TauJetContainer > m_TauJetContainerKey
Definition: METRebuilder.h:154
met::buildMETSum
StatusCode buildMETSum(const std::string &totalName, xAOD::MissingETContainer *metCont)
Definition: METHelpers.cxx:64
met::METRebuilder::m_softJetScale
Gaudi::Property< std::string > m_softJetScale
Definition: METRebuilder.h:187
xAOD::MissingETComposition::getComponent
static const MissingETComponent * getComponent(const MissingETComponentMap *pMap, const IParticle *pPart)
Access non-modifiable contribution object.
Definition: Event/xAOD/xAODMissingET/Root/MissingETComposition.cxx:122
met::METRebuilder::m_doEle
bool m_doEle
Definition: METRebuilder.h:173
met::METRebuilder::rebuildJetMET
virtual StatusCode rebuildJetMET(const std::string &jetKey, const std::string &softKey, xAOD::MissingETContainer *metCont, const xAOD::JetContainer *jets, const xAOD::MissingETComponentMap *metMap, bool doTracks=true) override
Definition: METRebuilder.h:96
METHelpers.h
met::METRebuilder::m_muonTerm
Gaudi::Property< std::string > m_muonTerm
Definition: METRebuilder.h:166
met
Definition: IMETSignificance.h:24
met::METRebuilder::m_jetDoJvf
Gaudi::Property< bool > m_jetDoJvf
Definition: METRebuilder.h:185
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
met::METRebuilder::m_softTerm
Gaudi::Property< std::string > m_softTerm
Definition: METRebuilder.h:167
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
ElectronContainer.h
met::METRebuilder::m_rebuildEle
bool m_rebuildEle
Definition: METRebuilder.h:178
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
vector< float >
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TauxAODHelpers.h
MissingETAuxContainer.h
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
met::METRebuilder::m_MuonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_MuonContainerKey
Definition: METRebuilder.h:155
met::METRebuilder::m_jetTerm
Gaudi::Property< std::string > m_jetTerm
Definition: METRebuilder.h:165
met::METRebuilder::m_JetContainerKey
SG::ReadHandleKey< xAOD::JetContainer > m_JetContainerKey
Definition: METRebuilder.h:156
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
met::METRebuilder::m_doTracks
bool m_doTracks
Definition: METRebuilder.h:188
DataVector::front
const T * front() const
Access the first element in the collection as an rvalue.
InDetTrackSelectionTool.h
xAOD::MissingET_v1
Principal data object for Missing ET.
Definition: MissingET_v1.h:25
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
xAOD::TauHelpers::trackParticleLinks
std::vector< ElementLink< xAOD::TrackParticleContainer > > trackParticleLinks(const xAOD::TauJet *tau, xAOD::TauJetParameters::TauTrackFlag flag=xAOD::TauJetParameters::TauTrackFlag::classifiedCharged)
Definition: TauxAODHelpers.cxx:22
xAOD::MissingETComposition::getMissingET
static const MissingET * getMissingET(const MissingETComponentMap *pMap, const IParticle *pPart)
Definition: Event/xAOD/xAODMissingET/Root/MissingETComposition.cxx:170
xAOD::MissingET_v1::mpx
float mpx() const
Returns .
met::METRebuilder::m_trk_doPVsel
Gaudi::Property< bool > m_trk_doPVsel
Definition: METRebuilder.h:195
python.xAODType.dummy
dummy
Definition: xAODType.py:4
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::JetAttribute::JVF
@ JVF
Definition: JetAttributes.h:99
xAOD::Vertex_v1::trackParticle
const TrackParticle * trackParticle(size_t i) const
Get the pointer to a given track that was used in vertex reco.
Definition: Vertex_v1.cxx:249
xAOD::TauJetParameters::coreTrack
@ coreTrack
Definition: TauDefs.h:403
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
METRebuilder.h
TauJetContainer.h
xAOD::MissingETComponent_v1::Weight::wpy
double wpy() const
Returns .
xAOD::MissingET_v1::name
const std::string & name() const
Identifier getters.
MissingET
Athena::TPCnvVers::Old Athena::TPCnvVers::Old MissingET
Definition: RecTPCnv.cxx:64
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::MissingET_v1::add
void add(const IParticle *particle)
Add particle kinematics to MET.
Definition: MissingET_v1.cxx:77
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
met::METRebuilder::copyMET
virtual StatusCode copyMET(const std::string &metKey, xAOD::MissingETContainer *metCont, const xAOD::MissingETComponentMap *metMap) override
Definition: METRebuilder.cxx:276
met::METRebuilder::m_doSTVF
Gaudi::Property< bool > m_doSTVF
Definition: METRebuilder.h:190
met::METRebuilder::m_eleTerm
Gaudi::Property< std::string > m_eleTerm
Definition: METRebuilder.h:162
Amg::error
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
Definition: EventPrimitivesHelpers.h:40
ReadHandle.h
Handle class for reading from StoreGate.
met::METRebuilder::m_doMuon
bool m_doMuon
Definition: METRebuilder.h:176
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::EgammaHelpers::getOriginalTrackParticleFromGSF
const xAOD::TrackParticle * getOriginalTrackParticleFromGSF(const xAOD::TrackParticle *trkPar)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the GSF Track Particle...
Definition: ElectronxAODHelpers.cxx:22
xAOD::MissingET_v1::source
MissingETBase::Types::bitmask_t source() const
MET object source tag.
xAOD::MissingETComponent_v1::findIndex
size_t findIndex(const IParticle *pPart) const
Find index of given object in contributing object store.
Definition: MissingETComponent_v1.cxx:213
xAOD::MissingETComponent_v1::Weight::wpx
double wpx() const
Returns .
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
xAOD::Electron_v1
Definition: Electron_v1.h:34
met::METRebuilder::rebuildMET
virtual StatusCode rebuildMET(const std::string &metKey, xAOD::MissingETContainer *metCont, const xAOD::IParticleContainer *collection, const xAOD::MissingETComponentMap *metMap, bool doTracks=true) override
Definition: METRebuilder.cxx:290
MuonContainer.h
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
Muon
struct TBPatternUnitContext Muon
met::METRebuilder::m_jetPtCut
Gaudi::Property< double > m_jetPtCut
Definition: METRebuilder.h:184
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
TrackParticle.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
met::METRebuilder::acceptTrack
bool acceptTrack(const xAOD::TrackParticle *trk, const xAOD::Vertex *pv) const
Definition: METRebuilder.cxx:615
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
xAOD::MissingETComponent_v1::metObject
const MissingET * metObject() const
Access MET object.
xAOD::Photon_v1
Definition: Photon_v1.h:37
MissingETComponentMap.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
met::METRebuilder::m_pureTrkSoft
bool m_pureTrkSoft
Definition: METRebuilder.h:189
python.changerun.pv
pv
Definition: changerun.py:81
InDet::InDetTrackSelectionTool
Implementation of the track selector tool.
Definition: InDetTrackSelectionTool.h:51
xAOD::MissingETComponent_v1::Weight
Kinematic weight descriptor.
Definition: MissingETComponent_v1.h:28
met::METRebuilder::m_rebuildGamma
bool m_rebuildGamma
Definition: METRebuilder.h:179
met::METRebuilder::m_softTermType
Gaudi::Property< std::string > m_softTermType
Definition: METRebuilder.h:168
xAODType::Tau
@ Tau
The object is a tau (jet)
Definition: ObjectType.h:49
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
met::fillMET
StatusCode fillMET(xAOD::MissingET *&met, xAOD::MissingETContainer *metCont, const std::string &metKey, const MissingETBase::Types::bitmask_t metSource)
Definition: METHelpers.cxx:123
met::METRebuilder::m_ElectronContainerKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_ElectronContainerKey
Definition: METRebuilder.h:152
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
met::METRebuilder::execute
virtual StatusCode execute() override
Definition: METRebuilder.cxx:191
met::METRebuilder::m_tauTerm
Gaudi::Property< std::string > m_tauTerm
Definition: METRebuilder.h:164
met::METRebuilder::m_rebuildMuon
bool m_rebuildMuon
Definition: METRebuilder.h:181
xAOD::MissingET_v1::mpy
float mpy() const
Returns .
xAOD::JetAttribute::GhostTrack
@ GhostTrack
Definition: JetAttributes.h:252
python.PyAthena.obj
obj
Definition: PyAthena.py:135
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
met::METRebuilder::m_OutMETKey
SG::WriteHandleKey< xAOD::MissingETContainer > m_OutMETKey
Definition: METRebuilder.h:159
xAOD::Photon_v1::vertex
const xAOD::Vertex * vertex(size_t index=0) const
Pointer to the xAOD::Vertex/es that match the photon candidate.
Definition: Photon_v1.cxx:46
PhotonContainer.h
MissingETComposition.h
met::METRebuilder::m_outMETTerm
Gaudi::Property< std::string > m_outMETTerm
Definition: METRebuilder.h:170
MissingETContainer.h
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
met::METRebuilder::m_trkseltool
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkseltool
Definition: METRebuilder.h:196
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
met::METRebuilder::m_PhotonContainerKey
SG::ReadHandleKey< xAOD::PhotonContainer > m_PhotonContainerKey
Definition: METRebuilder.h:153
met::METRebuilder::METRebuilder
METRebuilder()
Default constructor:
xAOD::MissingETComponent_v1
MET component descriptor contains object links and corresponding parameters.
Definition: MissingETComponent_v1.h:24
xAOD::MissingETComponent_v1::empty
bool empty() const
Empty list of contributing objects indicator.
ServiceHandle< Gaudi::Interfaces::IOptionsSvc >
met::METRebuilder::associateTracks
void associateTracks(const xAOD::IParticle *obj)
Definition: METRebuilder.cxx:629
xAOD::MissingETComponent_v1::objects
std::vector< const IParticle * > objects() const
Access contributing objects.
Definition: MissingETComponent_v1.cxx:295