ATLAS Offline Software
TrigMuonTLAHypoAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <algorithm>
6 #include "TrigMuonTLAHypoAlg.h"
10 
11 using namespace TrigCompositeUtils;
13 
14 TrigMuonTLAHypoAlg::TrigMuonTLAHypoAlg(const std::string &name, ISvcLocator *pSvcLocator) : ::HypoBase(name, pSvcLocator) {}
15 
17 {
18  // not used now
19  // ATH_CHECK(m_hypoTools.retrieve());
20  ATH_CHECK(m_TLAMuonsKey.initialize());
21 
22  if ( not m_monTool.name().empty() ) {
23  ATH_CHECK( m_monTool.retrieve() );
24  ATH_MSG_DEBUG("MonTool name: " << m_monTool);
25  }
26 
27  ATH_MSG_DEBUG("Initializing TrigMuonTLAHypoAlg");
28  return StatusCode::SUCCESS;
29 }
30 
31 StatusCode TrigMuonTLAHypoAlg::execute(const EventContext &ctx) const
32 {
33  ATH_MSG_DEBUG("Executing " << name() << "...");
34 
35  // create handles for TLA muons
37  //make the output muon container
38  ATH_CHECK(h_TLAMuons.record(std::make_unique<xAOD::MuonContainer>(),
39  std::make_unique<xAOD::MuonAuxContainer>()));
40 
41  auto previousDecisionHandle = SG::makeHandle(decisionInput(), ctx);
42  ATH_CHECK(previousDecisionHandle.isValid());
43  ATH_MSG_DEBUG("Running with " << previousDecisionHandle->size() << " previous decisions");
44 
45  // prepare output decisions
47  DecisionContainer *outputDecisions = outputHandle.ptr();
48 
49 
50  // the HypoTool needs a pair of <object*, decision*> as input
51  std::vector<std::pair<Decision *, const Decision *> > HypoInputs;
52 
53  // loops over previous decisions
54  int nDecision = 0;
55  for (const auto previousDecision : *previousDecisionHandle)
56  {
57  /* differnt behaviours are possibile
58  - 1) copy all muons linked by the decisions (those passing the chains)
59  - 2) copy only one muon per decision
60  Now follow 1), and at the end, to reduce the output colleciton, one can resolves overlaps between Views
61  */
62 
63  // get muons from the decision
64  const xAOD::Muon *muonPrev = nullptr;
65  auto prevMuons = TrigCompositeUtils::findLinks<xAOD::MuonContainer>(previousDecision, TrigCompositeUtils::featureString(), TrigDefs::lastFeatureOfType);
66  ATH_MSG_DEBUG("This decision has " << prevMuons.size() << " decisions");
67 
68  // verify that only one object is found per decision
69  if (prevMuons.size() != 1) {
70  ATH_MSG_DEBUG("Did not locate exactly one muon for this Decision Object, found " << prevMuons.size());
71  return StatusCode::FAILURE;
72  }
73 
74  auto prevMuLink = prevMuons.at(0).link;
75  ATH_CHECK(prevMuLink.isValid());
76  muonPrev = *prevMuLink;
77 
78  xAOD::Muon *copiedMuon = new xAOD::Muon();
79  h_TLAMuons->push_back(copiedMuon);
80  *copiedMuon = *muonPrev;
81 
82  // now go on with the normal Hypo, linking new decision with previous one
83  auto newDecision = newDecisionIn( outputDecisions, hypoAlgNodeName() );
84  TrigCompositeUtils::linkToPrevious( newDecision, previousDecision, ctx );
85  newDecision->setObjectLink(featureString(), ElementLink<xAOD::MuonContainer>(*h_TLAMuons, h_TLAMuons->size() - 1, ctx));
86 
87  ATH_MSG_DEBUG("Copied muon with pT: " << copiedMuon->pt() << " from decision " << nDecision);
88 
89  HypoInputs.push_back( std::make_pair(newDecision, previousDecision) );
90  nDecision++;
91  }
92 
93  // add monitor variables
94  auto Nmuons = Monitored::Scalar("Nmuon", -9999.);
95  Nmuons = h_TLAMuons->size();
96  auto muonPtMon = Monitored::Collection("Pt", *h_TLAMuons, []( const auto& t ) { return t->pt() * t->charge() / Gaudi::Units::GeV; });
97  auto muonEtaMon = Monitored::Collection("Eta", *h_TLAMuons, &xAOD::Muon::eta);
98  auto muonPhiMon = Monitored::Collection("Phi", *h_TLAMuons, &xAOD::Muon::phi);
99  auto muonAuthor = Monitored::Collection("Author", *h_TLAMuons, &xAOD::Muon::author);
100  auto monitorIt = Monitored::Group(m_monTool, Nmuons, muonPtMon, muonAuthor, muonEtaMon, muonPhiMon);
101 
102 
103  // this is bypassing any selectioon, remove if you want to apply HypoTools
104  for (auto& hypoPair: HypoInputs ){
105  TrigCompositeUtils::insertDecisionIDs(hypoPair.second, hypoPair.first);
106  }
107 
108  ATH_CHECK(hypoBaseOutputProcessing(outputHandle));
109 
110  return StatusCode::SUCCESS;
111 }
TrigMuonTLAHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrigMuonTLAHypoAlg.cxx:31
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
xAOD::MuonContainer
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
Definition: Event/xAOD/xAODMuon/xAODMuon/MuonContainer.h:14
TrigCompositeUtils::newDecisionIn
Decision * newDecisionIn(DecisionContainer *dc, const std::string &name)
Helper method to create a Decision object, place it in the container and return a pointer to it.
Definition: TrigCompositeUtilsRoot.cxx:46
xAOD::Muon_v1::phi
virtual double phi() const
The azimuthal angle ( ) of the particle.
TrigCompositeUtils::hypoAlgNodeName
const std::string & hypoAlgNodeName()
Definition: TrigCompositeUtilsRoot.cxx:904
xAOD::Muon_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
TrigCompositeUtils::insertDecisionIDs
void insertDecisionIDs(const Decision *src, Decision *dest)
Appends the decision IDs of src to the dest decision object.
Definition: TrigCompositeUtilsRoot.cxx:80
HypoBase::decisionInput
const SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > & decisionInput() const
methods for derived classes to access handles of the base class input other read/write handles may be...
Definition: HypoBase.cxx:16
TrigCompositeUtils::createAndStore
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
Definition: TrigCompositeUtilsRoot.cxx:30
xAOD::Muon_v1::author
Author author() const
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
HypoBase::decisionOutput
const SG::WriteHandleKey< TrigCompositeUtils::DecisionContainer > & decisionOutput() const
methods for derived classes to access handles of the base class output other read/write handles may b...
Definition: HypoBase.cxx:20
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
TrigMuonTLAHypoAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: TrigMuonTLAHypoAlg.h:35
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
MuonAuxContainer.h
TrigCompositeUtils.h
HypoBase::hypoBaseOutputProcessing
StatusCode hypoBaseOutputProcessing(SG::WriteHandle< TrigCompositeUtils::DecisionContainer > &outputHandle, MSG::Level lvl=MSG::DEBUG) const
Base class function to be called once slice specific code has finished. Handles debug printing and va...
Definition: HypoBase.cxx:33
TrigMuonTLAHypoAlg::TrigMuonTLAHypoAlg
TrigMuonTLAHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigMuonTLAHypoAlg.cxx:14
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::Muon_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:884
xAOD::Muon
Muon_v1 Muon
Reference the current persistent version:
Definition: Event/xAOD/xAODMuon/xAODMuon/Muon.h:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TrigMuonTLAHypoAlg.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TrigCompositeUtils::linkToPrevious
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
Definition: TrigCompositeUtilsRoot.cxx:139
TrigMuonTLAHypoAlg::initialize
virtual StatusCode initialize() override
Definition: TrigMuonTLAHypoAlg.cxx:16
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
TrigMuonTLAHypoAlg::m_TLAMuonsKey
SG::WriteHandleKey< xAOD::MuonContainer > m_TLAMuonsKey
Definition: TrigMuonTLAHypoAlg.h:31
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34