ATLAS Offline Software
TestHypoAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TestHypoAlg.h"
6 
7 namespace HLTTest {
8 
9  TestHypoAlg::TestHypoAlg( const std::string& name, ISvcLocator* pSvcLocator )
10  : ::HypoBase( name, pSvcLocator ) {}
11 
13 
15  ATH_MSG_INFO ("Initializing " << name() << "...");
16  ATH_MSG_DEBUG("Link name is "<<m_linkName.value());
17  if ( not m_recoInput.key().empty() )
18  CHECK( m_recoInput.initialize() );
19  CHECK( m_tools.retrieve() );
20  return StatusCode::SUCCESS;
21  }
22 
24  ATH_MSG_INFO( "Finalizing " << name() << "..." );
25  return StatusCode::SUCCESS;
26  }
27 
28 
29  StatusCode TestHypoAlg::execute( const EventContext& context ) const {
30  // new output decisions
32  auto decisions = outputHandle.ptr();
33 
34  ATH_MSG_DEBUG( "Executing " << name() << "..." );
35  if ( m_recoInput.key().empty() ) {
36  ATH_MSG_DEBUG( "No input configured, output decisions will be empty" );
37  return StatusCode::SUCCESS;
38  }
39 
40  auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
41  if( not previousDecisionsHandle.isValid() ) {//implicit
42  ATH_MSG_DEBUG( "No implicit RH for previous decisions "<< decisionInput().key()<<": is this expected?" );
43  return StatusCode::SUCCESS;
44  }
45 
46  ATH_MSG_DEBUG( "Running with "<< previousDecisionsHandle->size() <<" decisions from the input implicit ReadHandle");
47 
48  auto recoInput = SG::makeHandle(m_recoInput, context);
49  ATH_MSG_DEBUG( " and with "<< recoInput->size() <<" reco inputs");
50 
51 
52  // find features:
53  std::vector<const FeatureOBJ*> featureFromDecision;
54  for ( const auto previousDecision: *previousDecisionsHandle ) {
55  const auto linkInfo = TrigCompositeUtils::findLink<FeatureContainer>(previousDecision, m_linkName.value());
56  const auto featureLink = linkInfo.link;
57  CHECK( featureLink.isValid() );
58  const FeatureOBJ* feature = *featureLink;
59  featureFromDecision.push_back( feature);
60  }
61  ATH_MSG_DEBUG("Found "<<featureFromDecision.size()<<" features "<<m_linkName.value() <<" mapped from input decisions");
62 
63  //map reco object and decision: find in reco obejct the initial RoI and map it to the correct decision
64  size_t reco_counter = 0;
65  for (const auto recoobj: *recoInput){
66  const auto roiInfo = TrigCompositeUtils::findLink<TrigRoiDescriptorCollection>( recoobj, "initialRoI" );
67  const auto roiEL = roiInfo.link;
68  CHECK( roiEL.isValid() );
69 
70  const auto featureInfo = TrigCompositeUtils::findLink<FeatureContainer>( recoobj, m_linkName.value() );
71  const auto featurelink = featureInfo.link;
72  CHECK( featurelink.isValid() );
73  if ( not featurelink.isValid() ) {
74  ATH_MSG_ERROR( " Can not find reference to " + m_linkName.value() + " from the decision" );
75  return StatusCode::FAILURE;
76  }
77 
78  ATH_MSG_DEBUG(" Found link from the reco object to feature "<<m_linkName.value() );
79  const FeatureOBJ* feature = *featurelink;
80  // find the same roi in the previous decisions
81  bool foundFeatureInDecision=false;
82  size_t pos=distance(featureFromDecision.begin(), find(featureFromDecision.begin(), featureFromDecision.end(), feature));
83  if (pos < featureFromDecision.size()){
84  foundFeatureInDecision=true;
85  }
86 
87  if (foundFeatureInDecision){
88  ATH_MSG_DEBUG(" Found link from the reco object to the previous decision at position "<<pos);
89  auto d = newDecisionIn(decisions);
90  d->setObjectLink( "feature", ElementLink<xAOD::TrigCompositeContainer>(m_recoInput.key(), reco_counter) );// feature used by the Tool
91  d->setObjectLink( m_linkName.value(), featurelink );
93  }
94  else{
95  ATH_MSG_DEBUG( " Can not find reference to this feature " + m_linkName.value() + " from reco object " << reco_counter <<" in any previous decision" );
96  }
97  reco_counter++;
98  }
99 
100  if (decisions->size()>0){
101  for ( auto tool: m_tools ) {
102  CHECK( tool->decide( decisions ) );
103  }
104  }
105 
106  ATH_MSG_DEBUG( "Exiting with "<< outputHandle->size() <<" decisions");
107 
108  //debug
109  for (auto outh: *outputHandle){
111  TrigCompositeUtils::decisionIDs( outh, objDecisions );
112 
113  ATH_MSG_DEBUG("Number of positive decisions for this output: " << objDecisions.size() );
114 
115  for ( TrigCompositeUtils::DecisionID id : objDecisions ) {
116  ATH_MSG_DEBUG( " --- found decision " << HLT::Identifier( id ) );
117  }
118  }
119 
120  return StatusCode::SUCCESS;
121  }
122 
123 } //> end namespace HLTTest
HLTTest::TestHypoAlg::finalize
virtual StatusCode finalize() override
Definition: TestHypoAlg.cxx:23
TrigCompositeUtils::DecisionID
unsigned int DecisionID
Definition: TrigComposite_v1.h:27
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
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
hist_file_dump.d
d
Definition: hist_file_dump.py:137
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
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
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
HLTTest::TestHypoAlg::m_linkName
StringProperty m_linkName
Definition: TestHypoAlg.h:45
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
HLTTest::TestHypoAlg::m_recoInput
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_recoInput
Definition: TestHypoAlg.h:44
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TestHypoAlg.h
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
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
HLT::Identifier
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:20
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:101
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
HLTTest::TestHypoAlg::~TestHypoAlg
virtual ~TestHypoAlg()
Definition: TestHypoAlg.cxx:12
HypoBase
Hypothesis algorithms take the output of reco algorithms and the decision from the preceeding InputMa...
Definition: HypoBase.h:13
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
HLTTest::TestHypoAlg::initialize
virtual StatusCode initialize() override
Definition: TestHypoAlg.cxx:14
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
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::DecisionIDContainer
std::set< DecisionID > DecisionIDContainer
Definition: TrigComposite_v1.h:28
HLTTest::TestHypoAlg::TestHypoAlg
TestHypoAlg()
TrigCompositeUtils::decisionIDs
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
Definition: TrigCompositeUtilsRoot.cxx:67
HLTTest
Definition: ITestHypoTool.cxx:9
HLTTest::TestHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TestHypoAlg.cxx:29
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
HLTTest::TestHypoAlg::m_tools
ToolHandleArray< ITestHypoTool > m_tools
Definition: TestHypoAlg.h:43
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37