ATLAS Offline Software
Loading...
Searching...
No Matches
TrigdEdxTrackHypoAlg.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 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 TrigdEdxTrackHypoTool::dEdxTrkHypoInfo hypoInfo{ newDecision, dedx, previousDecisionIDs };
134 dEdxTrkHypoInputs.push_back( hypoInfo );
135 }
136
137 // monitor
138 ATH_CHECK( doMonitor(dedxContainer) );
139
140 // Loop over all hypoToolinputs and get their decisions
141 for ( auto & tool: m_hypoTools ) {
142 ATH_MSG_VERBOSE( "+++++ Now computing decision for " << tool->name() );
143 ATH_CHECK( tool->decide( dEdxTrkHypoInputs ) );
144 }
145
146 DecisionContainer::iterator it = outputDecisions->begin();
147 while(it != outputDecisions->end()) {
148 ATH_MSG_VERBOSE( "+++++ outputDecision: " << *it << " +++++" );
149 if ( allFailed( *it ) ) {
150 ATH_MSG_VERBOSE( "---> all failed, erasing" );
151 it = outputDecisions->erase(it);
152 } else {
153 ATH_MSG_VERBOSE( "---> not all failed" );
154 ++it;
155 }
156 }
157
158 // record
160 ATH_CHECK( HPtdEdxTrkHandle.record( std::move( HPtdEdxTrkContainer ), std::move( HPtdEdxTrkContainerAux ) ) );
161 ATH_MSG_VERBOSE( "recorded HPtdEdxTrk object to SG" );
162
163 //
164 ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
165
166 //
167 return StatusCode::SUCCESS;
168}
169
170// ------------------------------------------------------------------------------------------------
171// ------------------------------------------------------------------------------------------------
172
174{
175 auto monTrackPtGeV = Monitored::Scalar( "trackPtGeV", -999. );
176 auto monTrackEta = Monitored::Scalar( "trackEta", -999. );
177 auto monTracka0beam = Monitored::Scalar( "tracka0beam", -999. );
178 auto monTrackdEdx = Monitored::Scalar( "trackdEdx", -999. );
179 auto monTrackNhighdEdxHits = Monitored::Scalar( "trackNhighdEdxHits", -999. );
180 auto monitorIt = Monitored::Group( m_monTool, monTrackdEdx, monTrackPtGeV, monTrackEta, monTracka0beam, monTrackNhighdEdxHits );
181
182 for ( const xAOD::TrigComposite* trk : *dedxContainer ) {
183 float trackPt = trk->getDetail<float>("HPtdEdxTrk_pt");
184 float trackEta = trk->getDetail<float>("HPtdEdxTrk_eta");
185 float tracka0beam = trk->getDetail<float>("HPtdEdxTrk_a0beam");
186 float trackdEdx = trk->getDetail<float>("HPtdEdxTrk_dedx");
187 int trackNhighdEdxHits = (int)trk->getDetail<int16_t>("HPtdEdxTrk_n_hdedx_hits_1p70");
188 monTrackPtGeV = trackPt / 1000.0;
189 monTrackEta = trackEta;
190 monTracka0beam = tracka0beam;
191 monTrackdEdx = trackdEdx;
192 monTrackNhighdEdxHits = trackNhighdEdxHits;
193 }
194
195 return StatusCode::SUCCESS;
196}
197
198// ------------------------------------------------------------------------------------------------
199// ------------------------------------------------------------------------------------------------
200
202 xAOD::TrigCompositeContainer* dedxContainer, int& n_trks) const
203{
204 n_trks = 0;
205
206 for ( const xAOD::TrigComposite* trk : *trksContainer ) {
207
208 ATH_MSG_VERBOSE("+++++ i_trk: " << n_trks << " +++++");
209
210 float trackPt = trk->getDetail<float>("dEdxTrk_pt");
211 float trackEta = trk->getDetail<float>("dEdxTrk_eta");
212 float trackPhi = trk->getDetail<float>("dEdxTrk_phi");
213 float tracka0beam = trk->getDetail<float>("dEdxTrk_a0beam");
214 float trackdEdx = trk->getDetail<float>("dEdxTrk_dedx");
215 int trackId = trk->getDetail<int> ("dEdxTrk_id");
216 ATH_MSG_VERBOSE( "track pt / eta / a0beam / dEdx / Id = " << trackPt << " / " << trackEta << " / " << tracka0beam << " / " << trackdEdx << " / " << trackId );
217
218 std::vector<int16_t> n_hdedx_hits;
219 for(unsigned int idef=0; idef<m_highdEdxHitDefThres.size(); ++idef) { n_hdedx_hits.push_back(0); }
220
221 for ( const xAOD::TrigComposite* hit : *hitsContainer ) {
222 int id = hit->getDetail<int>("dEdxHit_trkid");
223 if( id != trackId ) continue;
224 float dedx = hit->getDetail<float>("dEdxHit_dedx");
225 for(unsigned int idef=0; idef<m_highdEdxHitDefThres.size(); ++idef) {
226 if( dedx >= m_highdEdxHitDefThres[idef] ) n_hdedx_hits[idef]++;
227 }
228 }
229 for(unsigned int idef=0; idef<m_highdEdxHitDefThres.size(); ++idef) {
230 ATH_MSG_VERBOSE( m_highdEdxHitDefNames[idef] << ", thres=" << m_highdEdxHitDefThres[idef] << ": nr of high dEdx hits=" << n_hdedx_hits[idef] );
231 }
232
233 int16_t n_hits_innermost = (int16_t)trk->getDetail<int>("dEdxTrk_n_hits_innermost");
234 int16_t n_hits_inner = (int16_t)trk->getDetail<int>("dEdxTrk_n_hits_inner");
235 int16_t n_hits_pix = (int16_t)trk->getDetail<int>("dEdxTrk_n_hits_pix");
236 int16_t n_hits_sct = (int16_t)trk->getDetail<int>("dEdxTrk_n_hits_sct");
237
238 // create EDM object
239 ++n_trks;
241 dedx->makePrivateStore();
242 dedxContainer->push_back(dedx);
243
244 dedx->setDetail<float>("HPtdEdxTrk_pt", trackPt);
245 dedx->setDetail<float>("HPtdEdxTrk_eta", trackEta);
246 dedx->setDetail<float>("HPtdEdxTrk_phi", trackPhi);
247 dedx->setDetail<float>("HPtdEdxTrk_a0beam",tracka0beam);
248 dedx->setDetail<float>("HPtdEdxTrk_dedx", trackdEdx);
249 for(unsigned int idef=0; idef<m_highdEdxHitDefThres.size(); ++idef) {
250 std::string name = "HPtdEdxTrk_n_hdedx_hits_" + m_highdEdxHitDefNames[idef];
251 dedx->setDetail<int16_t>(name, n_hdedx_hits[idef]);
252 }
253 dedx->setDetail<int16_t>("HPtdEdxTrk_n_hits_innermost", n_hits_innermost);
254 dedx->setDetail<int16_t>("HPtdEdxTrk_n_hits_inner", n_hits_inner);
255 dedx->setDetail<int16_t>("HPtdEdxTrk_n_hits_pix", n_hits_pix);
256 dedx->setDetail<int16_t>("HPtdEdxTrk_n_hits_sct", n_hits_sct);
257 }
258
259 //
260 return StatusCode::SUCCESS;
261}
262
263// ------------------------------------------------------------------------------------------------
264// ------------------------------------------------------------------------------------------------
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
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.
void makePrivateStore()
Create a new (empty) private store for this object.
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()
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.
bool allFailed(const Decision *d)
return true if there is no positive decision stored
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...
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