ATLAS Offline Software
Loading...
Searching...
No Matches
TrigdEdxTrackHypoAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
4 * Trigger Hypo Tool, that is aimed at triggering large dEdx tracks
5 * author Kunihiro Nagano <kunihiro.nagano@cern.ch> - KEK
6*/
10#include "GaudiKernel/SystemOfUnits.h"
12
27
28// ------------------------------------------------------------------------------------------------
29// ------------------------------------------------------------------------------------------------
30
32 ISvcLocator* pSvcLocator ) :
33 ::HypoBase( name, pSvcLocator ) {}
34
35// ------------------------------------------------------------------------------------------------
36// ------------------------------------------------------------------------------------------------
37
39{
40 CHECK( m_hypoTools.retrieve() );
41 CHECK( m_dEdxTrkKey.initialize() );
42 CHECK( m_dEdxHitKey.initialize() );
43 CHECK( m_HPtdEdxTrkKey.initialize());
44
45 if ( !m_monTool.empty() ) CHECK( m_monTool.retrieve() );
46
48 m_highdEdxHitDefThres.push_back(1.45); m_highdEdxHitDefNames.push_back("1p45");
49 m_highdEdxHitDefThres.push_back(1.50); m_highdEdxHitDefNames.push_back("1p50");
50 m_highdEdxHitDefThres.push_back(1.55); m_highdEdxHitDefNames.push_back("1p55");
51 m_highdEdxHitDefThres.push_back(1.60); m_highdEdxHitDefNames.push_back("1p60");
52 m_highdEdxHitDefThres.push_back(1.65); m_highdEdxHitDefNames.push_back("1p65");
53 m_highdEdxHitDefThres.push_back(1.70); m_highdEdxHitDefNames.push_back("1p70");
54 m_highdEdxHitDefThres.push_back(1.75); m_highdEdxHitDefNames.push_back("1p75");
55 m_highdEdxHitDefThres.push_back(1.80); m_highdEdxHitDefNames.push_back("1p80");
56
57 return StatusCode::SUCCESS;
58}
59
60// ------------------------------------------------------------------------------------------------
61// ------------------------------------------------------------------------------------------------
62
63StatusCode TrigdEdxTrackHypoAlg::execute( const EventContext& context ) const
64{
65 // previous decisions
66 ATH_MSG_DEBUG( "Retrieving pervious decision: \"" << decisionInput().key() << "\"" );
67 auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
68 ATH_CHECK( previousDecisionsHandle.isValid() );
69
70 ATH_MSG_DEBUG( "Running with " << previousDecisionsHandle->size() << " previous decisions" );
71 if( previousDecisionsHandle->size()!=1 ) {
72 ATH_MSG_ERROR( "Previous decision handle size is not 1. It is" << previousDecisionsHandle->size() );
73 return StatusCode::FAILURE;
74 }
75 const Decision * previousDecision = previousDecisionsHandle->at(0);
76
78 TrigCompositeUtils::decisionIDs(previousDecision, previousDecisionIDs);
79 ATH_MSG_VERBOSE( "IDs of active legs:" );
80 for(auto decisionID: previousDecisionIDs) { ATH_MSG_VERBOSE( " " << decisionID ); }
81
82 // new output decisions
83 ATH_MSG_DEBUG( "Creating new output decision handle" );
85 auto outputDecisions = outputHandle.ptr();
86
87 // input objects
88
89 // tracks
90 auto dEdxTrkHandle = SG::makeHandle(m_dEdxTrkKey, context );
91 ATH_CHECK( dEdxTrkHandle.isValid() );
92 ATH_MSG_DEBUG( "dEdxTrk handle size: " << dEdxTrkHandle->size() );
93
94 // hits
95 auto dEdxHitHandle = SG::makeHandle(m_dEdxHitKey, context );
96 ATH_CHECK( dEdxHitHandle.isValid() );
97 ATH_MSG_DEBUG( "dEdxHit handle size: " << dEdxHitHandle->size() );
98
99 const xAOD::TrigCompositeContainer * dEdxTrksContainer = dEdxTrkHandle.get();
100 const xAOD::TrigCompositeContainer * dEdxHitsContainer = dEdxHitHandle.get();
101
102 if( dEdxTrksContainer == nullptr ) {
103 ATH_MSG_ERROR( "ERROR Cannot get dEdxTrks container");
104 return StatusCode::FAILURE;
105 }
106 if( dEdxHitsContainer == nullptr ) {
107 ATH_MSG_ERROR( "ERROR Cannot get dEdxHits container");
108 return StatusCode::FAILURE;
109 }
110
111 // output EDM object
112 auto HPtdEdxTrkContainer = std::make_unique<xAOD::TrigCompositeContainer>();
113 auto HPtdEdxTrkContainerAux = std::make_unique<xAOD::TrigCompositeAuxContainer>();
114 HPtdEdxTrkContainer->setStore(HPtdEdxTrkContainerAux.get());
115
116 xAOD::TrigCompositeContainer* dedxContainer = HPtdEdxTrkContainer.get();
117
118 // Prepare inputs to HypoTool
119 int n_cands = 0;
120 ATH_CHECK( createCandidates(dEdxTrksContainer, dEdxHitsContainer, dedxContainer, n_cands) );
121 ATH_MSG_DEBUG( "nr of cands by createCandidates = " << n_cands );
122
123 std::vector<TrigdEdxTrackHypoTool::dEdxTrkHypoInfo> dEdxTrkHypoInputs;
124
125 for ( auto dedx : *dedxContainer ) {
126 Decision* newDecision = TrigCompositeUtils::newDecisionIn( outputDecisions, previousDecision, TrigCompositeUtils::hypoAlgNodeName(), context);
127
129 ATH_CHECK( dedxEL.isValid() );
130
132
133 dEdxTrkHypoInputs.emplace_back(newDecision, dedx, previousDecisionIDs);
134 }
135
136 // monitor
137 ATH_CHECK( doMonitor(dedxContainer) );
138
139 // Loop over all hypoToolinputs and get their decisions
140 for ( auto & tool: m_hypoTools ) {
141 ATH_MSG_VERBOSE( "+++++ Now computing decision for " << tool->name() );
142 ATH_CHECK( tool->decide( dEdxTrkHypoInputs ) );
143 }
144
145 DecisionContainer::iterator it = outputDecisions->begin();
146 while(it != outputDecisions->end()) {
147 ATH_MSG_VERBOSE( "+++++ outputDecision: " << *it << " +++++" );
148 if ( allFailed( *it ) ) {
149 ATH_MSG_VERBOSE( "---> all failed, erasing" );
150 it = outputDecisions->erase(it);
151 } else {
152 ATH_MSG_VERBOSE( "---> not all failed" );
153 ++it;
154 }
155 }
156
157 // record
159 ATH_CHECK( HPtdEdxTrkHandle.record( std::move( HPtdEdxTrkContainer ), std::move( HPtdEdxTrkContainerAux ) ) );
160 ATH_MSG_VERBOSE( "recorded HPtdEdxTrk object to SG" );
161
162 //
163 ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
164
165 //
166 return StatusCode::SUCCESS;
167}
168
169// ------------------------------------------------------------------------------------------------
170// ------------------------------------------------------------------------------------------------
171
173{
174 auto monTrackPtGeV = Monitored::Scalar( "trackPtGeV", -999. );
175 auto monTrackEta = Monitored::Scalar( "trackEta", -999. );
176 auto monTracka0beam = Monitored::Scalar( "tracka0beam", -999. );
177 auto monTrackdEdx = Monitored::Scalar( "trackdEdx", -999. );
178 auto monTrackNhighdEdxHits = Monitored::Scalar( "trackNhighdEdxHits", -999. );
179 auto monitorIt = Monitored::Group( m_monTool, monTrackdEdx, monTrackPtGeV, monTrackEta, monTracka0beam, monTrackNhighdEdxHits );
180
181 for ( const xAOD::TrigComposite* trk : *dedxContainer ) {
182 float trackPt = trk->getDetail<float>("HPtdEdxTrk_pt");
183 float trackEta = trk->getDetail<float>("HPtdEdxTrk_eta");
184 float tracka0beam = trk->getDetail<float>("HPtdEdxTrk_a0beam");
185 float trackdEdx = trk->getDetail<float>("HPtdEdxTrk_dedx");
186 int trackNhighdEdxHits = (int)trk->getDetail<int16_t>("HPtdEdxTrk_n_hdedx_hits_1p70");
187 monTrackPtGeV = trackPt / 1000.0;
188 monTrackEta = trackEta;
189 monTracka0beam = tracka0beam;
190 monTrackdEdx = trackdEdx;
191 monTrackNhighdEdxHits = trackNhighdEdxHits;
192 }
193
194 return StatusCode::SUCCESS;
195}
196
197// ------------------------------------------------------------------------------------------------
198// ------------------------------------------------------------------------------------------------
199
201 xAOD::TrigCompositeContainer* dedxContainer, int& n_trks) const
202{
203 n_trks = 0;
204
205 for ( const xAOD::TrigComposite* trk : *trksContainer ) {
206
207 ATH_MSG_VERBOSE("+++++ i_trk: " << n_trks << " +++++");
208
209 float trackPt = trk->getDetail<float>("dEdxTrk_pt");
210 float trackEta = trk->getDetail<float>("dEdxTrk_eta");
211 float trackPhi = trk->getDetail<float>("dEdxTrk_phi");
212 float tracka0beam = trk->getDetail<float>("dEdxTrk_a0beam");
213 float trackdEdx = trk->getDetail<float>("dEdxTrk_dedx");
214 int trackId = trk->getDetail<int> ("dEdxTrk_id");
215 ATH_MSG_VERBOSE( "track pt / eta / a0beam / dEdx / Id = " << trackPt << " / " << trackEta << " / " << tracka0beam << " / " << trackdEdx << " / " << trackId );
216
217 std::vector<int16_t> n_hdedx_hits;
218 for(unsigned int idef=0; idef<m_highdEdxHitDefThres.size(); ++idef) { n_hdedx_hits.push_back(0); }
219
220 for ( const xAOD::TrigComposite* hit : *hitsContainer ) {
221 int id = hit->getDetail<int>("dEdxHit_trkid");
222 if( id != trackId ) continue;
223 float dedx = hit->getDetail<float>("dEdxHit_dedx");
224 for(unsigned int idef=0; idef<m_highdEdxHitDefThres.size(); ++idef) {
225 if( dedx >= m_highdEdxHitDefThres[idef] ) n_hdedx_hits[idef]++;
226 }
227 }
228 for(unsigned int idef=0; idef<m_highdEdxHitDefThres.size(); ++idef) {
229 ATH_MSG_VERBOSE( m_highdEdxHitDefNames[idef] << ", thres=" << m_highdEdxHitDefThres[idef] << ": nr of high dEdx hits=" << n_hdedx_hits[idef] );
230 }
231
232 int16_t n_hits_innermost = (int16_t)trk->getDetail<int>("dEdxTrk_n_hits_innermost");
233 int16_t n_hits_inner = (int16_t)trk->getDetail<int>("dEdxTrk_n_hits_inner");
234 int16_t n_hits_pix = (int16_t)trk->getDetail<int>("dEdxTrk_n_hits_pix");
235 int16_t n_hits_sct = (int16_t)trk->getDetail<int>("dEdxTrk_n_hits_sct");
236
237 // create EDM object
238 ++n_trks;
240 dedx->makePrivateStore();
241 dedxContainer->push_back(dedx);
242
243 dedx->setDetail<float>("HPtdEdxTrk_pt", trackPt);
244 dedx->setDetail<float>("HPtdEdxTrk_eta", trackEta);
245 dedx->setDetail<float>("HPtdEdxTrk_phi", trackPhi);
246 dedx->setDetail<float>("HPtdEdxTrk_a0beam",tracka0beam);
247 dedx->setDetail<float>("HPtdEdxTrk_dedx", trackdEdx);
248 for(unsigned int idef=0; idef<m_highdEdxHitDefThres.size(); ++idef) {
249 std::string name = "HPtdEdxTrk_n_hdedx_hits_" + m_highdEdxHitDefNames[idef];
250 dedx->setDetail<int16_t>(name, n_hdedx_hits[idef]);
251 }
252 dedx->setDetail<int16_t>("HPtdEdxTrk_n_hits_innermost", n_hits_innermost);
253 dedx->setDetail<int16_t>("HPtdEdxTrk_n_hits_inner", n_hits_inner);
254 dedx->setDetail<int16_t>("HPtdEdxTrk_n_hits_pix", n_hits_pix);
255 dedx->setDetail<int16_t>("HPtdEdxTrk_n_hits_sct", n_hits_sct);
256 }
257
258 //
259 return StatusCode::SUCCESS;
260}
261
262// ------------------------------------------------------------------------------------------------
263// ------------------------------------------------------------------------------------------------
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define CHECK(...)
Evaluate an expression and check for errors.
bool hit(const Container &ids, int pdgId)
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
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
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
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
virtual StatusCode execute(const EventContext &context) const override
StatusCode createCandidates(const xAOD::TrigCompositeContainer *, const xAOD::TrigCompositeContainer *, xAOD::TrigCompositeContainer *, int &) const
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_dEdxTrkKey
virtual StatusCode initialize() override
std::vector< float > m_highdEdxHitDefThres
TrigdEdxTrackHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
std::vector< std::string > m_highdEdxHitDefNames
ToolHandleArray< TrigdEdxTrackHypoTool > m_hypoTools
ToolHandle< GenericMonitoringTool > m_monTool
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_HPtdEdxTrkKey
StatusCode doMonitor(const xAOD::TrigCompositeContainer *) const
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_dEdxHitKey
bool setObjectLink(const std::string &name, const ElementLink< CONTAINER > &link)
Set the link to an object.
bool setDetail(const std::string &name, const TYPE &value)
Set an TYPE detail on the object.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
const std::string & viewString()
xAOD::TrigComposite Decision
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.
LinkInfo< T > findLink(const EventContext &ctx, 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...
bool allFailed(const Decision *d)
return true if there is no positive decision stored
xAOD::TrigCompositeContainer DecisionContainer
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
TrigCompositeContainer_v1 TrigCompositeContainer
Declare the latest version of the container.
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22