ATLAS Offline Software
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"
8 #include "AthViews/ViewHelper.h"
10 #include "GaudiKernel/SystemOfUnits.h"
12 
27 
28 // ------------------------------------------------------------------------------------------------
29 // ------------------------------------------------------------------------------------------------
30 
31 IDCalibHypoAlg::IDCalibHypoAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
32  ::HypoBase( name, pSvcLocator ) {}
33 
34 // ------------------------------------------------------------------------------------------------
35 // ------------------------------------------------------------------------------------------------
36 
38 {
39  CHECK( m_hypoTools.retrieve() );
40 
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 
53 StatusCode 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 
67  TrigCompositeUtils::DecisionIDContainer previousDecisionIDs;
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 
104  ATH_CHECK( newDecision->setObjectLink<xAOD::TrackParticleContainer>(TrigCompositeUtils::featureString(), trackEL) );
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 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
IDCalibHypoAlg.h
TrigCompositeUtils::DecisionContainer
xAOD::TrigCompositeContainer DecisionContainer
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigCompositeContainer.h:21
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TrigCompositeUtils.h
IDCalibHypoAlg::m_hypoTools
ToolHandleArray< IDCalibHypoTool > m_hypoTools
Definition: IDCalibHypoAlg.h:36
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
TrigCompositeUtils::hypoAlgNodeName
const std::string & hypoAlgNodeName()
Definition: TrigCompositeUtilsRoot.cxx:906
skel.it
it
Definition: skel.GENtoEVGEN.py:423
DataVector::get
const T * get(size_type n) const
Access an element, as an rvalue.
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
ViewHelper.h
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
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IDCalibHypoAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: IDCalibHypoAlg.h:37
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
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IDCalibHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: IDCalibHypoAlg.cxx:53
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
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
DataVector< xAOD::TrackParticle_v1 >
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
TrigCompositeUtils::DecisionAuxContainer
xAOD::TrigCompositeAuxContainer DecisionAuxContainer
Definition: TrigCompositeAuxContainer.h:20
IDCalibHypoTool::IDCalibHypoInfo
Definition: IDCalibHypoTool.h:28
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:886
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
HypoBase
Hypothesis algorithms take the output of reco algorithms and the decision from the preceeding InputMa...
Definition: HypoBase.h:13
TrigCompositeUtils::Decision
xAOD::TrigComposite Decision
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:20
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
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
TrigCompositeUtils::LinkInfo
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition: LinkInfo.h:28
TrigCompositeUtils::DecisionIDContainer
std::set< DecisionID > DecisionIDContainer
Definition: TrigComposite_v1.h:28
TrigCompositeUtils::findLink
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...
IDCalibHypoAlg::IDCalibHypoAlg
IDCalibHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: IDCalibHypoAlg.cxx:31
TrigCompositeUtils::allFailed
bool allFailed(const Decision *d)
return true if there is no positive decision stored
Definition: TrigCompositeUtilsRoot.cxx:103
TrigCompositeUtils::decisionIDs
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
Definition: TrigCompositeUtilsRoot.cxx:67
IDCalibHypoAlg::initialize
virtual StatusCode initialize() override
Definition: IDCalibHypoAlg.cxx:37
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
TrigCompositeUtils::viewString
const std::string & viewString()
Definition: TrigCompositeUtilsRoot.cxx:882
IDCalibHypoAlg::m_tracksKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_tracksKey
Definition: IDCalibHypoAlg.h:34
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37