ATLAS Offline Software
TrigEgammaFastPhotonHypoAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 #include "AthViews/ViewHelper.h"
9 
10 namespace TCU = TrigCompositeUtils;
11 
13  ISvcLocator* pSvcLocator ) :
14  ::HypoBase( name, pSvcLocator ) {}
15 
16 
18 {
19  ATH_CHECK( m_hypoTools.retrieve() );
20  ATH_CHECK( m_photonsKey.initialize() );
21  renounce( m_photonsKey );// clusters are made in views, so they are not in the EvtStore: hide them
22 
23  return StatusCode::SUCCESS;
24 }
25 
26 StatusCode TrigEgammaFastPhotonHypoAlg::execute( const EventContext& context ) const {
27 
28  ATH_MSG_DEBUG ( "Executing " << name() << "..." );
29  auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
30  ATH_CHECK( previousDecisionsHandle.isValid() );
31  ATH_MSG_DEBUG( "Running with "<< previousDecisionsHandle->size() <<" previous decisions");
32 
33 
34  // map between cluster pointer and index
35 
36  std::map<const xAOD::TrigEMCluster*, size_t> clusterToIndexMap;
37  size_t clusterCounter = 0;
38  for ( auto previousDecision : *previousDecisionsHandle){
39  auto clusterELInfo = TCU::findLink<xAOD::TrigEMClusterContainer>( previousDecision, "feature" );
40 
41  if( not clusterELInfo.isValid() ) {
42  ATH_MSG_ERROR("Can not obtain the link to Cluster");
43  ATH_MSG_ERROR( TCU::dump( previousDecision, [](const xAOD::TrigComposite* tc){
44  return tc->name() + " " + (tc->object<xAOD::TrigEMCluster>("feature") == 0 ? "has no cluster": "has cluster");
45  }) );
46  return StatusCode::FAILURE;
47  }
48  const xAOD::TrigEMCluster* cluster = *(clusterELInfo.link);
49  clusterToIndexMap.insert( std::make_pair( cluster, clusterCounter ) );
50  clusterCounter++;
51  }
52  ATH_MSG_DEBUG( "Cluster ptr to decision map has size " << clusterToIndexMap.size() );
53 
54  // new output decisions
56  auto decisions = outputHandle.ptr();
57 
58  std::vector<TrigEgammaFastPhotonHypoTool::PhotonInfo> hypoToolInput;
59 
60  for ( auto previousDecision: *previousDecisionsHandle ) {
61  //previousDecision->objectLink< ViewContainer >( "view" );
62  const auto viewEL = previousDecision->objectLink<ViewContainer>( TCU::viewString() );
63 
64  ATH_CHECK( viewEL.isValid() );
65 
66  // get electron from that view:
67  size_t photonCounter = 0;
68  auto photonsHandle = ViewHelper::makeHandle( *viewEL, m_photonsKey, context );
69 
70  ATH_CHECK( photonsHandle.isValid() );
71  ATH_MSG_DEBUG ( "electron handle size: " << photonsHandle->size() << "..." );
72 
73  for ( auto photonIter = photonsHandle->begin(); photonIter != photonsHandle->end(); ++photonIter, photonCounter++ ) {
75  d->setObjectLink( TCU::featureString(), ViewHelper::makeLink<xAOD::TrigPhotonContainer>( *viewEL, photonsHandle, photonCounter ) );
76 
77  auto clusterPtr = (*photonIter)->emCluster();
78  ATH_CHECK( clusterPtr != nullptr );
79 
80  // now find matching cluster
81  // could use geometric matching but in fact the cluster owned by the decision object and the cluster owned by the photon should be the same
82  // since we have a map made in advance we can make use of the index lookup w/o the need for additional loop
83  auto origCluster = clusterToIndexMap.find( clusterPtr );
84  ATH_CHECK( origCluster != clusterToIndexMap.end() );
85  TCU::linkToPrevious( d, decisionInput().key(), origCluster->second );
86 
87  // now we have DecisionObject ready to be passed to hypo tool. it has link to photon,
88  // and decisions on clusters
89  // we shall avoid calling the tools for chains which were already rejected on certain cluster, but this is left to hypo tools
90  TCU::DecisionIDContainer clusterDecisionIDs;
91  TCU::decisionIDs( previousDecisionsHandle->at( origCluster->second ), clusterDecisionIDs );
92 
93  hypoToolInput.emplace_back( TrigEgammaFastPhotonHypoTool::PhotonInfo{ d, *photonIter, origCluster->first, clusterDecisionIDs } );
94  }
95  }
96 
97  for ( auto & tool: m_hypoTools ) {
98  ATH_CHECK( tool->decide( hypoToolInput ) );
99  }
100 
101 
102  ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
103 
104  return StatusCode::SUCCESS;
105 }
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
TrigCompositeUtils::hypoAlgNodeName
const std::string & hypoAlgNodeName()
Definition: TrigCompositeUtilsRoot.cxx:904
TrigEgammaFastPhotonHypoAlg::TrigEgammaFastPhotonHypoAlg
TrigEgammaFastPhotonHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigEgammaFastPhotonHypoAlg.cxx:12
ViewHelper::makeHandle
SG::ReadHandle< T > makeHandle(const SG::View *view, const SG::ReadHandleKey< T > &rhKey, const EventContext &context)
navigate from the TrigComposite to nearest view and fetch object from it
Definition: ViewHelper.h:259
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::renounce
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
Definition: AthCommonDataStore.h:380
xAOD::TrigComposite_v1::object
const OBJECT * object(const std::string &name) const
Get a bare pointer with the requested name.
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
TrigCompositeUtils.h
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
TrigEgammaFastPhotonHypoAlg::m_photonsKey
SG::ReadHandleKey< xAOD::TrigPhotonContainer > m_photonsKey
Definition: TrigEgammaFastPhotonHypoAlg.h:32
TrigEgammaFastPhotonHypoAlg::initialize
virtual StatusCode initialize() override
Definition: TrigEgammaFastPhotonHypoAlg.cxx:17
run_Egamma1_LArStrip_Fex.dump
dump
Definition: run_Egamma1_LArStrip_Fex.py:88
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
TrigEgammaFastPhotonHypoTool::PhotonInfo
Definition: TrigEgammaFastPhotonHypoTool.h:31
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
TrigEgammaFastPhotonHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrigEgammaFastPhotonHypoAlg.cxx:26
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:101
TrigCompositeContainer.h
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:884
TrigEgammaFastPhotonHypoAlg.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
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
TrigEgammaFastPhotonHypoAlg::m_hypoTools
ToolHandleArray< TrigEgammaFastPhotonHypoTool > m_hypoTools
Definition: TrigEgammaFastPhotonHypoAlg.h:29
xAOD::TrigComposite_v1::name
const std::string & name() const
Get a human-readable name for the object.
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
TrigCompositeUtils::decisionIDs
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
Definition: TrigCompositeUtilsRoot.cxx:67
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
xAOD::TrigEMCluster_v1
Description of a trigger EM cluster.
Definition: TrigEMCluster_v1.h:28
TrigCompositeUtils::viewString
const std::string & viewString()
Definition: TrigCompositeUtilsRoot.cxx:880
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
ViewContainer
Definition: View.h:158