ATLAS Offline Software
TCTDecorCheckInTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "TLorentzVector.h"
8 
9 #include <cassert>
10 #include "TestTools/FLOATassert.h"
11 //
12 //-------------------------------------------------
13 //
14 //Constructor--------------------------------------------------------------
16  ISvcLocator* pSvcLocator):
17  AthAlgorithm( name, pSvcLocator )
18  { }
19 
20 //Destructor---------------------------------------------------------------
22  ATH_MSG_DEBUG("TCTDecorCheckInTool destructor called");
23  }
24 
25 //Initialize---------------------------------------------------------------
27 
28 
30  ATH_CHECK( m_verticesKey.initialize() );
31  ATH_CHECK( m_jetsKey.initialize() );
32 
33  //from https://acode-browser1.usatlas.bnl.gov/lxr/source/athena/Event/xAOD/xAODTrackingCnv/src/TrackParticleCnvAlg.cxx
34  m_trackReadDecorKeyTCTScore = "InDetTrackParticles.TCTScore_"+m_jetsKey.key();
35  m_trackReadDecorKeyJetLink = "InDetTrackParticles.TCTJetLink_"+m_jetsKey.key();
36 
37  m_jetReadDecorKeyTCTScore = m_jetsKey.key()+ ".TCTScore";
38  m_jetReadDecorKeyTrackLink = m_jetsKey.key() +".TCTTrackLink";
39 
42 
43  ATH_CHECK( m_jetReadDecorKeyTCTScore.initialize());
45 
46  //-------
47  //check that the TrackClassificationTool can be accessed
48  if (m_trackClassificationTool.retrieve().isFailure()) {
49  ATH_MSG_DEBUG("Could not find InDet::InDetTrkInJetType");
50  return StatusCode::SUCCESS;
51  } else {
52  ATH_MSG_DEBUG("InDet::InDetTrkInJetType found");
53  }
54 
55  return StatusCode::SUCCESS;
56  }
57 
59  {
60  ATH_MSG_DEBUG("TCTDecorCheck finalize()");
61  return StatusCode::SUCCESS;
62  }
63 
65  {
66  ATH_MSG_DEBUG( "Executing..." );
69 
70  //JetRead handles
73 
74  // Retrieve the track particles:
76  if ( !trackTES.isValid() ) {
77  ATH_MSG_WARNING( "No TrackParticle container found in TDS" );
78  return StatusCode::SUCCESS; }
79  ATH_MSG_DEBUG( "TrackParticleContainer successfully retrieved" );
80 
82  if ( !pvTES.isValid() ) {
83  ATH_MSG_WARNING( "No Primary Vertices container found in TDS" );
84  return StatusCode::SUCCESS; }
85  ATH_MSG_DEBUG( "Primary Vertices container successfully retrieved" );
86  const xAOD::Vertex *primVertex=*(pvTES->begin());
87 
88 
89 
90  //==========================================================================
92  if ( !jetTES.isValid() ) {
93  ATH_MSG_WARNING( "No AntiKt4EMPflow jet container found in TDS" );
94  return StatusCode::SUCCESS; }
95  ATH_MSG_DEBUG( "AntiKt4EMPflow jet container successfully retrieved" );
96 
98  xAOD::TrackParticleContainer::const_iterator trackItrE = trackTES->end();
99 
100  xAOD::JetContainer::const_iterator jetItr = jetTES->begin();
101  xAOD::JetContainer::const_iterator jetItrE = jetTES->end();
102 
103  //decorator methods for decorating the tracks
104  if(m_decoratorMethod=="decorateTrack")
105  {
106  ATH_MSG_DEBUG("Using decorateTrack method ");
107  for(trackItr = trackTES->begin(); trackItr != trackItrE; ++trackItr){
108  const xAOD::TrackParticle* itrk = (*trackItr);
109  //first decorate the track with the InDetTrkInJetType method
110  //find closest jet to the track in Delta R
111  float minDeltaR=1.0;
112  const xAOD::Jet* closestJet = *(jetTES->begin());
113  for(jetItr = jetTES->begin(); jetItr != jetItrE; ++jetItr){
114  const xAOD::Jet* curJet = (*jetItr);
115  float curDeltaR = (itrk)->p4().DeltaR(curJet->p4());
116  if(curDeltaR < minDeltaR) {minDeltaR = curDeltaR; closestJet = curJet;}
117  }
118  m_trackClassificationTool->decorateTrack(itrk,*primVertex, *jetTES, closestJet);
119  }
120 
121  //loop over tracks and check if decoration was correctly added (using either decorateTrack)
122  for(trackItr = trackTES->begin(); trackItr != trackItrE; ++trackItr){
123  const xAOD::TrackParticle* itrk = (*trackItr);
124  std::vector<float> v_tctScoresDeco = trackReadDecorHandleTCTScore(*itrk);
125  const ElementLink<xAOD::JetContainer>& v_jetLinks = trackReadDecorHandleJetLink(*itrk);
126 
127  ATH_MSG_DEBUG("TCT score from decoration: " << v_tctScoresDeco.at(0) << ", " << v_tctScoresDeco.at(1) << ", "<< v_tctScoresDeco.at(2));
128  std::vector<float> v_tctScore = m_trackClassificationTool->trkTypeWgts(itrk,*primVertex,(*v_jetLinks)->p4());
129  ATH_MSG_DEBUG("Calculated TCT score: " << v_tctScore.at(0) << ", " << v_tctScore.at(1) << ", " << v_tctScore.at(2));
130 
131  for(int j=0; j<=2 ; j++) {assert(Athena_test::isEqual(v_tctScore.at(j),v_tctScoresDeco.at(j)));}
132 
133  }//end track loop
134  }//end if decorator methods for decorating tracks
135  else if(m_decoratorMethod=="decorateJet")
136  {
137  ATH_MSG_DEBUG("Using decorateJets method ");
138  for(jetItr = jetTES->begin(); jetItr != jetItrE; ++jetItr){
139  const xAOD::Jet* ijet = (*jetItr);
140  std::vector<const xAOD::TrackParticle*> trkparticles(0);
141  for(trackItr = trackTES->begin(); trackItr != trackItrE; ++trackItr){
142  const xAOD::TrackParticle* itrk = (*trackItr);
143  if((itrk)->p4().DeltaR(ijet->p4()) < 0.4) {trkparticles.push_back(itrk); }
144  }
145  m_trackClassificationTool->decorateJet(trkparticles,*trackTES,*primVertex, ijet);
146  }
147 
148  //loop over jets and check if decoration was correctly added
149  for(jetItr = jetTES->begin(); jetItr != jetItrE; ++jetItr){
150  const xAOD::Jet* ijet = (*jetItr);
151  std::vector<std::vector<float>> v_tctScoresDeco = jetReadDecorHandleTCTScore(*ijet);
152  std::vector<ElementLink<xAOD::TrackParticleContainer>> v_trackLinks = jetReadDecorHandleTrackLink(*ijet);
153 
154  for(unsigned int i=0; i<v_tctScoresDeco.size(); i++)
155  {
156  ATH_MSG_DEBUG("TCT score from decoration: " << v_tctScoresDeco.at(i).at(0) << ", " << v_tctScoresDeco.at(i).at(1) << ", "<< v_tctScoresDeco.at(i).at(2));
157  std::vector<float> v_tctScore = m_trackClassificationTool->trkTypeWgts(*v_trackLinks.at(i),*primVertex,ijet->p4());
158  ATH_MSG_DEBUG("Calculated TCT score: " << v_tctScore.at(0) << ", " << v_tctScore.at(1) << ", " << v_tctScore.at(2));
159 
160  for(int j=0; j<=2 ; j++) {assert(Athena_test::isEqual(v_tctScore.at(j),v_tctScoresDeco.at(i).at(j)));}
161  }//end of tct vector loop
162  }//end of jet loop
163  }
164  else
165  {
166  ATH_MSG_ERROR("Specified decorator method not implemented in InDetTrkInJetType: " << m_decoratorMethod );
167  }
168 
169 
170  return StatusCode::SUCCESS;
171  }
172 
TCTDecorCheckInTool::m_jetReadDecorKeyTCTScore
SG::ReadDecorHandleKey< xAOD::JetContainer > m_jetReadDecorKeyTCTScore
The write key for adding TCT score as decoration to Jet objects.
Definition: TCTDecorCheckInTool.h:72
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
TCTDecorCheckInTool::m_trackReadDecorKeyJetLink
SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > m_trackReadDecorKeyJetLink
Definition: TCTDecorCheckInTool.h:68
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
met::DeltaR
@ DeltaR
Definition: METRecoCommon.h:11
TCTDecorCheckInTool::initialize
virtual StatusCode initialize() override
Definition: TCTDecorCheckInTool.cxx:26
TCTDecorCheckInTool::m_trackReadDecorKeyTCTScore
SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > m_trackReadDecorKeyTCTScore
The read key for adding TCT score as decoration to TrackParticle objects.
Definition: TCTDecorCheckInTool.h:66
TCTDecorCheckInTool.h
TCTDecorCheckInTool::m_particlesKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_particlesKey
Definition: TCTDecorCheckInTool.h:61
TCTDecorCheckInTool::m_decoratorMethod
StringProperty m_decoratorMethod
Definition: TCTDecorCheckInTool.h:77
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Athena_test::isEqual
bool isEqual(double x1, double x2, double thresh=1e-6)
Definition: FLOATassert.h:26
TCTDecorCheckInTool::m_trackClassificationTool
ToolHandle< InDet::IInDetTrkInJetType > m_trackClassificationTool
Definition: TCTDecorCheckInTool.h:57
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
TCTDecorCheckInTool::finalize
virtual StatusCode finalize() override
Definition: TCTDecorCheckInTool.cxx:58
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
PathResolver.h
TCTDecorCheckInTool::TCTDecorCheckInTool
TCTDecorCheckInTool(const std::string &type, ISvcLocator *pSvcLocator)
Definition: TCTDecorCheckInTool.cxx:15
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
xAOD::Jet_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: Jet_v1.cxx:71
FLOATassert.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TCTDecorCheckInTool::m_jetReadDecorKeyTrackLink
SG::ReadDecorHandleKey< xAOD::JetContainer > m_jetReadDecorKeyTrackLink
Definition: TCTDecorCheckInTool.h:74
TCTDecorCheckInTool::~TCTDecorCheckInTool
virtual ~TCTDecorCheckInTool()
Definition: TCTDecorCheckInTool.cxx:21
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
TCTDecorCheckInTool::execute
virtual StatusCode execute() override
Definition: TCTDecorCheckInTool.cxx:64
TCTDecorCheckInTool::m_jetsKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetsKey
Definition: TCTDecorCheckInTool.h:60
TCTDecorCheckInTool::m_verticesKey
SG::ReadHandleKey< xAOD::VertexContainer > m_verticesKey
Definition: TCTDecorCheckInTool.h:62
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.