ATLAS Offline Software
TrigVSIHypoAlg.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TrigVSIHypoAlg.h"
6 
9 #include "AthViews/ViewHelper.h"
10 
25 
26 TrigVSIHypoAlg::TrigVSIHypoAlg(const std::string& name, ISvcLocator* pSvcLocator) :
27 ::HypoBase(name, pSvcLocator)
28 {
29 }
30 
32 {
33  ATH_CHECK(m_verticesKey.initialize());
34  ATH_CHECK(m_vtxCountKey.initialize());
36 
37  if (m_verticesKey.key() == "Undefined" || m_vtxCountKey.key() == "Undefined") {
38  ATH_MSG_ERROR("either vertex Key name or track count key name is undefined " );
39  return StatusCode::FAILURE;
40  }
41 
42  ATH_CHECK(m_hypoTools.retrieve());
43  if (!m_monTool.empty()) ATH_CHECK(m_monTool.retrieve());
44 
45  return StatusCode::SUCCESS;
46 }
47 
48 
49 StatusCode TrigVSIHypoAlg::execute(const EventContext& context) const
50 {
51  // previous decisions
52 
53  // Taken from FTFLRT
54  ATH_MSG_DEBUG ( "Executing " << name() << "..." );
55  auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
56 
57  ATH_CHECK( previousDecisionsHandle.isValid() );
58 
59  if (previousDecisionsHandle->size() == 0) {
60  ATH_MSG_DEBUG( "No previous decision, nothing to do.");
61  return StatusCode::SUCCESS;
62  }
63 
64  ATH_MSG_DEBUG( "Running with "<< previousDecisionsHandle->size() << " implicit ReadHandles for previous decisions. Looking for :" << viewString());
65  //end taken section
66 
67  // new output decisions
69  auto decisions = outputHandle.ptr();
70 
71  // monitoring
72  auto mon_nVtx = Monitored::Scalar( "nVtx", -999. );
73  auto mon_preselNVtx = Monitored::Scalar( "preselNVtx", -999. );
74  auto mon_maxVtxNTrk = Monitored::Scalar( "maxVtxNTrk", -999. );
75  auto mon_maxVtxMass = Monitored::Scalar( "maxVtxMass", -999. );
76  auto monitorIt = Monitored::Group( m_monTool, mon_nVtx, mon_preselNVtx, mon_maxVtxNTrk, mon_maxVtxMass );
77 
78  // Recording Data
79  auto vtxCountContainer = std::make_unique< xAOD::TrigCompositeContainer>();
80  auto vtxCountContainerAux = std::make_unique< xAOD::TrigCompositeAuxContainer>();
81  vtxCountContainer->setStore(vtxCountContainerAux.get());
82 
83  std::unordered_map<Decision*, size_t> mapDecVtxContIdx;
84 
85  for( const Decision* previousDecision : *previousDecisionsHandle ) {
86 
88 
89  if (m_isViewBased) {
90  const auto viewELInfo = findLink<ViewContainer>( previousDecision, viewString() );
91  ATH_CHECK( viewELInfo.isValid() );
92 
93  // get vertices from the key
94  ATH_MSG_DEBUG( "Getting Vertex Handle " << m_verticesKey);
95  vtxHandle = ViewHelper::makeHandle(*viewELInfo.link, m_verticesKey, context);
96  } else {
97  ATH_MSG_DEBUG( "Getting Vertex Handle " << m_verticesKey);
98  vtxHandle = SG::makeHandle(m_verticesKey, context );
99  }
100 
101  //ATH_CHECK( vtxHandle.isValid() );
102  if ( ! vtxHandle.isValid() ) {
103  ATH_MSG_DEBUG ( "Couldn't find " << m_verticesKey << "..." );
104  continue;
105  }
106 
107  ATH_MSG_DEBUG ( "vertex handle size: " << vtxHandle->size() << "..." );
108  int nVtx = vtxHandle->size();
109  const xAOD::VertexContainer* vtxContainer = vtxHandle.get();
110 
111  Decision* d = newDecisionIn(decisions, previousDecision, hypoAlgNodeName(), context);
112 
113  DecisionIDContainer prev;
114  decisionIDs( previousDecision, prev );
115 
116  std::vector<const xAOD::Vertex*> selectedVtx;
117  float maxVtxNTrk = 0.;
118  float maxVtxMass = 0.;
119 
120  static const SG::ConstAccessor<float> vsi_massAcc ("vsi_mass");
121  static const SG::ConstAccessor<float> vsi_pTAcc ("vsi_pT");
122 
123  // Loop over all vertices and combine them into the std::vector after preselection and create the input for the hypotool
124  for ( const xAOD::Vertex* vertex : *vtxContainer ) {
125  if (vertex == nullptr) continue;
126  const float mass = vsi_massAcc.withDefault(*vertex, 0);
127  const float pT = vsi_pTAcc.withDefault(*vertex, 0);
128  const size_t ntrk = vertex->nTrackParticles();
129 
130  const float x_ = vertex->position().x();
131  const float y_ = vertex->position().y();
132  const float r = std::sqrt(x_*x_+y_*y_);
133 
134  if ( pT > m_minPt
135  && r > m_minR
136  && ntrk >= m_requiredNTrks )
137  {
138  selectedVtx.push_back(vertex);
139  maxVtxNTrk = std::max(maxVtxNTrk, static_cast<float>(ntrk));
140  maxVtxMass = std::max(maxVtxMass, mass);
141  }
142  }
143 
144  // Monitor
145  mon_nVtx = nVtx;
146  mon_preselNVtx = selectedVtx.size();
147  mon_maxVtxNTrk = maxVtxNTrk;
148  mon_maxVtxMass = maxVtxMass;
149 
150  xAOD::TrigComposite* vtxCount = new xAOD::TrigComposite();
151  vtxCountContainer->push_back(vtxCount);
152  vtxCount->setDetail( "vsiHypo_nVtx", static_cast<float>(nVtx) );
153  vtxCount->setDetail( "vsiHypo_pTcut", static_cast<float>(m_minPt) );
154  vtxCount->setDetail( "vsiHypo_rCut", static_cast<float>(m_minR) );
155  vtxCount->setDetail( "vsiHypo_nTrkCut", static_cast<float>(m_requiredNTrks) );
156  vtxCount->setDetail( "vsiHypo_counts", static_cast<float>(selectedVtx.size()) );
157 
158  TrigVSIHypoTool::eventVtxInfo vtxinfo{d, selectedVtx, prev};
159 
160  for(auto &tool : m_hypoTools)
161  {
162  ATH_CHECK(tool->decide(vtxinfo));
163  }
164 
165  mapDecVtxContIdx.emplace( d, vtxCountContainer->size()-1 );
166 
167  }
168 
169  // Recording Data
171  ATH_CHECK(vtxCountHandle.record( std::move( vtxCountContainer ), std::move( vtxCountContainerAux ) ) );
172 
174  while(it != decisions->end()) {
175  ATH_MSG_DEBUG( "+++++ outputDecision: " << *it << " +++++" );
176  if ( allFailed( *it ) ) {
177  ATH_MSG_DEBUG( "---> all failed, erasing" );
178  it = decisions->erase(it);
179  } else {
180  ATH_MSG_DEBUG( "---> not all failed" );
181 
182  // Link hitDV object
183  auto decision = *it;
184  size_t idx = mapDecVtxContIdx.at(*it);
185 
187  ATH_CHECK( dvEL.isValid() );
188 
189  ATH_CHECK( decision->setObjectLink<xAOD::TrigCompositeContainer>( featureString(), dvEL ) );
190 
191  ATH_MSG_DEBUG(*decision);
192  ++it;
193  }
194  }
195 
196  ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
197  ATH_MSG_DEBUG(" TrigVSIHypoAlg:" << name() << " successfully executed. Returning StatusCode::SUCCESS.");
198  return StatusCode::SUCCESS;
199 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
beamspotman.r
def r
Definition: beamspotman.py:676
CalculateHighPtTerm.pT
pT
Definition: ICHEP2016/CalculateHighPtTerm.py:57
TrigVSIHypoAlg::m_verticesKey
SG::ReadHandleKey< xAOD::VertexContainer > m_verticesKey
Definition: TrigVSIHypoAlg.h:32
xAOD::TrigComposite_v1::setDetail
bool setDetail(const std::string &name, const TYPE &value)
Set an TYPE detail on the object.
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
max
#define max(a, b)
Definition: cfImp.cxx:41
TrigCompositeUtils::DecisionContainer
xAOD::TrigCompositeContainer DecisionContainer
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigCompositeContainer.h:21
xAOD::TrigComposite
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:16
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
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
hist_file_dump.d
d
Definition: hist_file_dump.py:137
TrigCompositeUtils::hypoAlgNodeName
const std::string & hypoAlgNodeName()
Definition: TrigCompositeUtilsRoot.cxx:906
TrigVSIHypoAlg::m_minR
Gaudi::Property< float > m_minR
Definition: TrigVSIHypoAlg.h:36
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:258
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
skel.it
it
Definition: skel.GENtoEVGEN.py:423
TrigVSIHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrigVSIHypoAlg.cxx:49
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
TrigVSIHypoTool::eventVtxInfo
Definition: TrigVSIHypoTool.h:26
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
SG::ConstAccessor< float >
ViewHelper.h
TrigVSIHypoAlg::m_minPt
Gaudi::Property< float > m_minPt
Definition: TrigVSIHypoAlg.h:35
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
TrigVSIHypoAlg::initialize
virtual StatusCode initialize() override
Definition: TrigVSIHypoAlg.cxx:31
dqt_zlumi_pandas.mass
mass
Definition: dqt_zlumi_pandas.py:170
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
TrackParticleAuxContainer.h
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.
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TrigVSIHypoAlg::m_requiredNTrks
Gaudi::Property< float > m_requiredNTrks
Definition: TrigVSIHypoAlg.h:37
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrigVSIHypoAlg::m_vtxCountKey
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_vtxCountKey
Definition: TrigVSIHypoAlg.h:33
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
TrigVSIHypoAlg::m_hypoTools
ToolHandleArray< TrigVSIHypoTool > m_hypoTools
Definition: TrigVSIHypoAlg.h:31
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:81
TrigCompositeUtils::DecisionAuxContainer
xAOD::TrigCompositeAuxContainer DecisionAuxContainer
Definition: TrigCompositeAuxContainer.h:20
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:886
TrigVSIHypoAlg::m_isViewBased
Gaudi::Property< bool > m_isViewBased
Definition: TrigVSIHypoAlg.h:34
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
TrigVSIHypoAlg::TrigVSIHypoAlg
TrigVSIHypoAlg()
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
TrigVSIHypoAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: TrigVSIHypoAlg.h:38
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
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
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
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
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...
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
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
TrigVSIHypoAlg.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrigCompositeUtils::viewString
const std::string & viewString()
Definition: TrigCompositeUtilsRoot.cxx:882
SG::ConstAccessor::withDefault
const_reference_type withDefault(const ELT &e, const T &deflt) const
Fetch the variable for one element, as a const reference, with a default.