ATLAS Offline Software
Loading...
Searching...
No Matches
IDCalibHypoAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3
4 * Trigger Hypo algorithm for IDCalib stream trigger
5 * author Kunihiro Nagano <kunihiro.nagano@cern.ch>
6*/
7#include "IDCalibHypoAlg.h"
10#include "GaudiKernel/SystemOfUnits.h"
12
27
28// ------------------------------------------------------------------------------------------------
29// ------------------------------------------------------------------------------------------------
30
31IDCalibHypoAlg::IDCalibHypoAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
32 ::HypoBase( name, pSvcLocator ) {}
33
34// ------------------------------------------------------------------------------------------------
35// ------------------------------------------------------------------------------------------------
36
38{
39 CHECK( m_hypoTools.retrieve() );
40
41 CHECK( m_tracksKey.initialize() );
42
43 if ( !m_monTool.empty() ) CHECK( m_monTool.retrieve() );
44
45 ATH_MSG_INFO( "initialization completed" );
46
47 return StatusCode::SUCCESS;
48}
49
50// ------------------------------------------------------------------------------------------------
51// ------------------------------------------------------------------------------------------------
52
53StatusCode IDCalibHypoAlg::execute( const EventContext& context ) const
54{
55 // previous decisions
56 ATH_MSG_DEBUG( "Retrieving previous decision: \"" << decisionInput().key() << "\"" );
57 auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
58 ATH_CHECK( previousDecisionsHandle.isValid() );
59
60 ATH_MSG_DEBUG( "Running with " << previousDecisionsHandle->size() << " previous decisions" );
61 if( previousDecisionsHandle->size()!=1 ) {
62 ATH_MSG_ERROR( "Previous decision handle size is not 1. It is" << previousDecisionsHandle->size() );
63 return StatusCode::FAILURE;
64 }
65 const Decision * previousDecision = previousDecisionsHandle->at(0);
66
68 TrigCompositeUtils::decisionIDs(previousDecision, previousDecisionIDs);
69 ATH_MSG_DEBUG( "IDs of active legs:" );
70 for(auto decisionID: previousDecisionIDs) { ATH_MSG_DEBUG( " " << decisionID ); }
71
72 // new output decisions
73 ATH_MSG_DEBUG( "Creating new output decision handle" );
75 auto outputDecisions = outputHandle.ptr();
76
77 // get tracks from the key
78 ATH_MSG_DEBUG( "Getting Track Handle " << m_tracksKey );
79 auto trackHandle = SG::makeHandle(m_tracksKey, context );
80 ATH_CHECK( trackHandle.isValid() );
81 ATH_MSG_DEBUG ( "Track handle size: " << trackHandle->size() << "..." );
82 const xAOD::TrackParticleContainer * trackContainer = trackHandle.get();
83
84 // monitoring
85 std::vector<float> mnt_pt;
86 auto mon_pt = Monitored::Collection("pt", mnt_pt);
87 auto monIDCalib = Monitored::Group(m_monTool, mon_pt);
88
89 // track loop
90 unsigned int itrk_passed = 0;
91 std::vector<IDCalibHypoTool::IDCalibHypoInfo> IDCalibHypoInputs;
92 for ( const xAOD::TrackParticle* track : *trackContainer ) {
93
94 if (track->pt()< 1*Gaudi::Units::GeV ) continue;
95 itrk_passed++;
96
97 mnt_pt.push_back(track->pt()/Gaudi::Units::GeV);
98
99 Decision* newDecision = TrigCompositeUtils::newDecisionIn( outputDecisions, previousDecision, TrigCompositeUtils::hypoAlgNodeName(), context);
100
102 ATH_CHECK( trackEL.isValid() );
103
105
106 IDCalibHypoTool::IDCalibHypoInfo hypoInfo{ newDecision, track, trackContainer, previousDecisionIDs };
107 IDCalibHypoInputs.push_back( hypoInfo );
108 }
109 ATH_MSG_DEBUG( "nr tracks = " << trackContainer->size() << " -> selected nr = " << itrk_passed );
110
111 // Loop over all hypoToolinputs and get their decisions
112 for ( auto & tool: m_hypoTools ) {
113 ATH_MSG_DEBUG( "+++++ Now computing decision for " << tool->name() );
114 ATH_CHECK( tool->decide( IDCalibHypoInputs ) );
115 }
116
117 DecisionContainer::iterator it = outputDecisions->begin();
118 while(it != outputDecisions->end()) {
119 if ( allFailed( *it ) ) {
120 ATH_MSG_DEBUG( "all failed, erasing for outputDecision: " << *it );
121 it = outputDecisions->erase(it);
122 } else {
123 ATH_MSG_DEBUG( "keeping outputDecision: " << *it );
124 ++it;
125 }
126 }
127
128 //
129 ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
130
131 //
132 return StatusCode::SUCCESS;
133}
134
135// ------------------------------------------------------------------------------------------------
136// ------------------------------------------------------------------------------------------------
137
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
Header file to be included by clients of the Monitored infrastructure.
bool allFailed(const Decision *d)
return true if there is no positive decision stored
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
size_type size() const noexcept
Returns the number of elements in the collection.
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
ToolHandle< GenericMonitoringTool > m_monTool
virtual StatusCode execute(const EventContext &context) const override
IDCalibHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_tracksKey
ToolHandleArray< IDCalibHypoTool > m_hypoTools
Group of local monitoring quantities and retain correlation when filling histograms
pointer_type ptr()
Dereference the pointer.
bool setObjectLink(const std::string &name, const ElementLink< CONTAINER > &link)
Set the link to an object.
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())
const std::string & viewString()
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()
xAOD::TrigCompositeAuxContainer DecisionAuxContainer
std::set< DecisionID > DecisionIDContainer
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
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.
bool allFailed(const Decision *d)
return true if there is no positive decision stored
LinkInfo< T > findLink(const Decision *start, const std::string &linkName, const bool suppressMultipleLinksWarning=false)
Perform a recursive search for ElementLinks of type T and name 'linkName', starting from Decision obj...
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22