ATLAS Offline Software
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 */
7 #include "TrigdEdxTrackHypoAlg.h"
8 #include "AthViews/ViewHelper.h"
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 
63 StatusCode 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 
77  TrigCompositeUtils::DecisionIDContainer previousDecisionIDs;
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 
131  ATH_CHECK( newDecision->setObjectLink<xAOD::TrigCompositeContainer>(TrigCompositeUtils::featureString(), dedxEL) );
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 // ------------------------------------------------------------------------------------------------
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
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
TrigCompositeUtils::DecisionContainer
xAOD::TrigCompositeContainer DecisionContainer
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigCompositeContainer.h:21
TrigCompositeUtils.h
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
xAOD::TrigComposite
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:16
TrigdEdxTrackHypoAlg::m_dEdxTrkKey
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_dEdxTrkKey
Definition: TrigdEdxTrackHypoAlg.h:33
TrigdEdxTrackHypoAlg::m_HPtdEdxTrkKey
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_HPtdEdxTrkKey
Definition: TrigdEdxTrackHypoAlg.h:35
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
TrigCompositeUtils::hypoAlgNodeName
const std::string & hypoAlgNodeName()
Definition: TrigCompositeUtilsRoot.cxx:906
skel.it
it
Definition: skel.GENtoEVGEN.py:423
TrigdEdxTrackHypoAlg.h
DataVector::get
const T * get(size_type n) const
Access an element, as an rvalue.
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
TrigdEdxTrackHypoAlg::m_dEdxHitKey
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_dEdxHitKey
Definition: TrigdEdxTrackHypoAlg.h:34
TrigdEdxTrackHypoAlg::createCandidates
StatusCode createCandidates(const xAOD::TrigCompositeContainer *, const xAOD::TrigCompositeContainer *, xAOD::TrigCompositeContainer *, int &) const
Definition: TrigdEdxTrackHypoAlg.cxx:201
TrigdEdxTrackHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrigdEdxTrackHypoAlg.cxx:63
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ViewHelper.h
TrigdEdxTrackHypoAlg::initialize
virtual StatusCode initialize() override
Definition: TrigdEdxTrackHypoAlg.cxx:38
xAOD::int16_t
setScaleOne setStatusOne setSaturated int16_t
Definition: gFexGlobalRoI_v1.cxx:55
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
TrigdEdxTrackHypoAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: TrigdEdxTrackHypoAlg.h:39
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
TrigdEdxTrackHypoTool::dEdxTrkHypoInfo
Definition: TrigdEdxTrackHypoTool.h:30
TrigdEdxTrackHypoAlg::TrigdEdxTrackHypoAlg
TrigdEdxTrackHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigdEdxTrackHypoAlg.cxx:31
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrigdEdxTrackHypoAlg::m_hypoTools
ToolHandleArray< TrigdEdxTrackHypoTool > m_hypoTools
Definition: TrigdEdxTrackHypoAlg.h:31
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
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
TrigCompositeUtils::DecisionAuxContainer
xAOD::TrigCompositeAuxContainer DecisionAuxContainer
Definition: TrigCompositeAuxContainer.h:20
TauGNNUtils::Variables::Track::trackPt
bool trackPt(const xAOD::TauJet &, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:470
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:886
TrigdEdxTrackHypoAlg::m_highdEdxHitDefNames
std::vector< std::string > m_highdEdxHitDefNames
Definition: TrigdEdxTrackHypoAlg.h:43
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
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:172
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
TrigdEdxTrackHypoAlg::m_highdEdxHitDefThres
std::vector< float > m_highdEdxHitDefThres
Definition: TrigdEdxTrackHypoAlg.h:42
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
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
TauGNNUtils::Variables::Track::trackPhi
bool trackPhi(const xAOD::TauJet &, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:480
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
TrigdEdxTrackHypoAlg::doMonitor
StatusCode doMonitor(const xAOD::TrigCompositeContainer *) const
Definition: TrigdEdxTrackHypoAlg.cxx:173
TrigCompositeUtils::viewString
const std::string & viewString()
Definition: TrigCompositeUtilsRoot.cxx:882
TauGNNUtils::Variables::Track::trackEta
bool trackEta(const xAOD::TauJet &, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:475
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37