ATLAS Offline Software
RpvMuonD0Tool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // RpvMuonD0Tool.cxx, (c) ATLAS Detector software
8 // Author: Mike Flowerdew (Michael.Flowerdew@cern.ch)
9 // Tool to write lepton d0 in a way accessible by derivation framwork tools
10 // Writes result to SG for later selection by string parser
11 
13 #include <vector>
14 #include <string>
15 
16 // Constructor
18  const std::string& n,
19  const IInterface* p ) :
20  AthAlgTool(t,n,p)
21  {
22  declareInterface<DerivationFramework::IAugmentationTool>(this);
23  }
24 
25 // Destructor
27 }
28 
29 // Athena initialize and finalize
31 {
32  ATH_MSG_VERBOSE("initialize() ...");
33  ATH_CHECK(m_collNameKey.initialize());
34  ATH_CHECK(m_collNameD0Key.initialize());
35  ATH_CHECK(m_collNameIsCombKey.initialize());
36  return StatusCode::SUCCESS;
37 }
39 {
40  ATH_MSG_VERBOSE("finalize() ...");
41  return StatusCode::SUCCESS;
42 }
43 
44 // Augmentation
46 {
47 
48  // Retrieve data
49  SG::ReadHandle<xAOD::MuonContainer> muons(m_collNameKey);
50  if( !muons.isValid() ) {
51  ATH_MSG_ERROR("Couldn't retrieve muon container with key: " << m_collNameKey);
52  return StatusCode::FAILURE;
53  }
54 
55  // Make a vector for the cut results
56  // Write decision to SG for access by downstream algs
57  SG::WriteHandle< std::vector<float> > d0vec(m_collNameD0Key);
58  ATH_CHECK(d0vec.record(std::make_unique< std::vector<float> >()));
59 
60  SG::WriteHandle< std::vector<int> > isCombinedVec(m_collNameIsCombKey);
61  ATH_CHECK(isCombinedVec.record(std::make_unique< std::vector<int> >()));
62 
63 
64  // Loop over muons, set decisions
65  for (xAOD::MuonContainer::const_iterator muIt = muons->begin(); muIt!=muons->end(); ++muIt) {
66 
67  float d0 = 9e99;
68 
69  // Alternative: (*muIt)->trackParticle( xAOD::Muon::InnerDetectorTrackParticle ) ?
70  if (*muIt && (*muIt)->primaryTrackParticle()) d0 = (*muIt)->primaryTrackParticle()->d0();
71  else ATH_MSG_WARNING("Problem accessing muon track!");
72 
73  d0vec->push_back(d0);
75  bool isGoodCombined = false;
76 
77  if ((*muIt)->muonType()==xAOD::Muon::Combined) {
78  float chi2 = 0.;
79  if (!(*muIt)->parameter(chi2, xAOD::Muon::msInnerMatchChi2)) ATH_MSG_WARNING("Problem accessing muon chisq!");
80  int dof = 1;
81  if (!(*muIt)->parameter(dof,xAOD::Muon::msInnerMatchDOF)) ATH_MSG_WARNING("Problem accessing muon DoF!");
82  if (dof == 0) dof = 1;
83  if (chi2/float(dof) < 5.) isGoodCombined = true;
84  }
85  if (isGoodCombined) {
86  isCombinedVec->push_back(1);
87  } else {
88  isCombinedVec->push_back(0);
89  }
90  }
91 
92  return StatusCode::SUCCESS;
93 }
94 
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
DerivationFramework::RpvMuonD0Tool::initialize
StatusCode initialize()
Definition: RpvMuonD0Tool.cxx:30
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
DerivationFramework::RpvMuonD0Tool::finalize
StatusCode finalize()
Definition: RpvMuonD0Tool.cxx:38
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DerivationFramework::RpvMuonD0Tool::~RpvMuonD0Tool
~RpvMuonD0Tool()
Destructor.
Definition: RpvMuonD0Tool.cxx:26
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:522
TRT::Track::d0
@ d0
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:62
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Trk::Combined
@ Combined
Definition: TrackSummaryTool.h:32
DerivationFramework::RpvMuonD0Tool::RpvMuonD0Tool
RpvMuonD0Tool(const std::string &t, const std::string &n, const IInterface *p)
Constructor with parameters.
Definition: RpvMuonD0Tool.cxx:17
RpvMuonD0Tool.h
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthAlgTool
Definition: AthAlgTool.h:26
DerivationFramework::RpvMuonD0Tool::addBranches
virtual StatusCode addBranches() const
Check that the current event passes this filter.
Definition: RpvMuonD0Tool.cxx:45
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.