ATLAS Offline Software
Loading...
Searching...
No Matches
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>
10
11using namespace TrigCompositeUtils;
13
14TrigMuonTLAHypoAlg::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
31StatusCode 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;
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
Header file to be included by clients of the Monitored infrastructure.
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:18
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:22
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:35
HypoBase(const std::string &name, ISvcLocator *pSvcLocator)
constructor, to be called by sub-class constructors
Definition HypoBase.cxx:12
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
SG::WriteHandleKey< xAOD::MuonContainer > m_TLAMuonsKey
virtual StatusCode initialize() override
ToolHandle< GenericMonitoringTool > m_monTool
virtual StatusCode execute(const EventContext &context) const override
TrigMuonTLAHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double phi() const
The azimuthal angle ( ) of the particle.
virtual double pt() const
The transverse momentum ( ) of the particle.
Author author() const
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
void insertDecisionIDs(const Decision *src, Decision *dest)
Appends the decision IDs of src to the dest decision object.
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.
const std::string & featureString()
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
void findLinks(const Decision *start, const std::string &linkName, std::vector< LinkInfo< T > > &links, unsigned int behaviour=TrigDefs::allFeaturesOfType, std::set< const xAOD::TrigComposite * > *fullyExploredFrom=nullptr)
search back the TC links for the object of type T linked to the one of TC (recursively) Populates pro...
const std::string & hypoAlgNodeName()
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
static const unsigned int lastFeatureOfType
Run 3 "enum". Only return the final feature along each route through the navigation.
Muon_v1 Muon
Reference the current persistent version:
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".