ATLAS Offline Software
TCTDecorCheckInTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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  m_trackClassificationTool("InDet::InDetTrkInJetType",this),
19  m_decoratorMethod("decorateTrack"),
20  m_jetCollection("") //AntiKt4EMPFlowJets
21  {
22  declareProperty("TrackClassificationTool", m_trackClassificationTool);
23  declareProperty("decoratorMethod", m_decoratorMethod);
24  declareProperty("JetCollection",m_jetCollection, "Type of JetContainer which should be decorated with TCT scores and TrackLinks");
25 
26 
27  }
28 
29 //Destructor---------------------------------------------------------------
31  ATH_MSG_DEBUG("TCTDecorCheckInTool destructor called");
32  }
33 
34 //Initialize---------------------------------------------------------------
36 
37 
39  ATH_CHECK( m_verticesKey.initialize() );
40  ATH_CHECK( m_jetsKey.initialize() );
41 
42  if(!m_jetCollection.empty())
43  {
44  //from https://acode-browser1.usatlas.bnl.gov/lxr/source/athena/Event/xAOD/xAODTrackingCnv/src/TrackParticleCnvAlg.cxx
45  m_trackReadDecorKeyTCTScore = "InDetTrackParticles.TCTScore_"+m_jetCollection;
46  m_trackReadDecorKeyJetLink = "InDetTrackParticles.TCTJetLink_"+m_jetCollection;
47 
50 
53 
54  ATH_CHECK( m_jetReadDecorKeyTCTScore.initialize());
56  }
57 
58  //-------
59  //check that the TrackClassificationTool can be accessed
60  if (m_trackClassificationTool.retrieve().isFailure()) {
61  ATH_MSG_DEBUG("Could not find InDet::InDetTrkInJetType");
62  return StatusCode::SUCCESS;
63  } else {
64  ATH_MSG_DEBUG("InDet::InDetTrkInJetType found");
65  }
66 
67  return StatusCode::SUCCESS;
68  }
69 
71  {
72  ATH_MSG_DEBUG("TCTDecorCheck finalize()");
73  return StatusCode::SUCCESS;
74  }
75 
77  {
78  ATH_MSG_DEBUG( "Executing..." );
79  if(m_jetCollection.empty()){ ATH_MSG_FATAL("No JetCollection selected! ");}
82 
83  //JetRead handles
86 
87 
88  // Retrieve the track particles:
90  if ( !trackTES.isValid() ) {
91  ATH_MSG_WARNING( "No TrackParticle container found in TDS" );
92  return StatusCode::SUCCESS; }
93  ATH_MSG_DEBUG( "TrackParticleContainer successfully retrieved" );
94 
96  if ( !pvTES.isValid() ) {
97  ATH_MSG_WARNING( "No Primary Vertices container found in TDS" );
98  return StatusCode::SUCCESS; }
99  ATH_MSG_DEBUG( "Primary Vertices container successfully retrieved" );
100  const xAOD::Vertex *primVertex=*(pvTES->begin());
101 
102 
103 
104  //==========================================================================
106  if ( !jetTES.isValid() ) {
107  ATH_MSG_WARNING( "No AntiKt4EMPflow jet container found in TDS" );
108  return StatusCode::SUCCESS; }
109  ATH_MSG_DEBUG( "AntiKt4EMPflow jet container successfully retrieved" );
110 
112  xAOD::TrackParticleContainer::const_iterator trackItrE = trackTES->end();
113 
114  xAOD::JetContainer::const_iterator jetItr = jetTES->begin();
115  xAOD::JetContainer::const_iterator jetItrE = jetTES->end();
116 
117  //decorator methods for decorating the tracks
118  if(m_decoratorMethod=="decorateTrack")
119  {
120  ATH_MSG_DEBUG("Using decorateTrack method ");
121  for(trackItr = trackTES->begin(); trackItr != trackItrE; ++trackItr){
122  const xAOD::TrackParticle* itrk = (*trackItr);
123  //first decorate the track with the InDetTrkInJetType method
124  //find closest jet to the track in Delta R
125  float minDeltaR=1.0;
126  const xAOD::Jet* closestJet = *(jetTES->begin());
127  for(jetItr = jetTES->begin(); jetItr != jetItrE; ++jetItr){
128  const xAOD::Jet* curJet = (*jetItr);
129  float curDeltaR = (itrk)->p4().DeltaR(curJet->p4());
130  if(curDeltaR < minDeltaR) {minDeltaR = curDeltaR; closestJet = curJet;}
131  }
132  m_trackClassificationTool->decorateTrack(itrk,*primVertex, *jetTES, closestJet);
133  }
134 
135  //loop over tracks and check if decoration was correctly added (using either decorateTrack)
136  for(trackItr = trackTES->begin(); trackItr != trackItrE; ++trackItr){
137  const xAOD::TrackParticle* itrk = (*trackItr);
138  std::vector<float> v_tctScoresDeco = trackReadDecorHandleTCTScore(*itrk);
139  const ElementLink<xAOD::JetContainer>& v_jetLinks = trackReadDecorHandleJetLink(*itrk);
140 
141  ATH_MSG_DEBUG("TCT score from decoration: " << v_tctScoresDeco.at(0) << ", " << v_tctScoresDeco.at(1) << ", "<< v_tctScoresDeco.at(2));
142  std::vector<float> v_tctScore = m_trackClassificationTool->trkTypeWgts(itrk,*primVertex,(*v_jetLinks)->p4());
143  ATH_MSG_DEBUG("Calculated TCT score: " << v_tctScore.at(0) << ", " << v_tctScore.at(1) << ", " << v_tctScore.at(2));
144 
145  for(int j=0; j<=2 ; j++) {assert(Athena_test::isEqual(v_tctScore.at(j),v_tctScoresDeco.at(j)));}
146 
147  }//end track loop
148  }//end if decorator methods for decorating tracks
149  else if(m_decoratorMethod=="decorateJet")
150  {
151  ATH_MSG_DEBUG("Using decorateJets method ");
152  for(jetItr = jetTES->begin(); jetItr != jetItrE; ++jetItr){
153  const xAOD::Jet* ijet = (*jetItr);
154  std::vector<const xAOD::TrackParticle*> trkparticles(0);
155  for(trackItr = trackTES->begin(); trackItr != trackItrE; ++trackItr){
156  const xAOD::TrackParticle* itrk = (*trackItr);
157  if((itrk)->p4().DeltaR(ijet->p4()) < 0.4) {trkparticles.push_back(itrk); }
158  }
159  m_trackClassificationTool->decorateJet(trkparticles,*trackTES,*primVertex, ijet);
160  }
161 
162  //loop over jets and check if decoration was correctly added
163  for(jetItr = jetTES->begin(); jetItr != jetItrE; ++jetItr){
164  const xAOD::Jet* ijet = (*jetItr);
165  std::vector<std::vector<float>> v_tctScoresDeco = jetReadDecorHandleTCTScore(*ijet);
166  std::vector<ElementLink<xAOD::TrackParticleContainer>> v_trackLinks = jetReadDecorHandleTrackLink(*ijet);
167 
168  for(unsigned int i=0; i<v_tctScoresDeco.size(); i++)
169  {
170  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));
171  std::vector<float> v_tctScore = m_trackClassificationTool->trkTypeWgts(*v_trackLinks.at(i),*primVertex,ijet->p4());
172  ATH_MSG_DEBUG("Calculated TCT score: " << v_tctScore.at(0) << ", " << v_tctScore.at(1) << ", " << v_tctScore.at(2));
173 
174  for(int j=0; j<=2 ; j++) {assert(Athena_test::isEqual(v_tctScore.at(j),v_tctScoresDeco.at(i).at(j)));}
175  }//end of tct vector loop
176  }//end of jet loop
177  }
178  else
179  {
180  ATH_MSG_ERROR("Specified decorator method not implemented in InDetTrkInJetType: " << m_decoratorMethod );
181  }
182 
183 
184  return StatusCode::SUCCESS;
185  }
186 
TCTDecorCheckInTool::m_jetReadDecorKeyTCTScore
SG::ReadDecorHandleKey< xAOD::JetContainer > m_jetReadDecorKeyTCTScore
The write key for adding TCT score as decoration to Jet objects.
Definition: TCTDecorCheckInTool.h:71
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
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:67
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
met::DeltaR
@ DeltaR
Definition: METRecoCommon.h:11
TCTDecorCheckInTool::initialize
virtual StatusCode initialize() override
Definition: TCTDecorCheckInTool.cxx:35
TCTDecorCheckInTool::m_trackReadDecorKeyTCTScore
SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > m_trackReadDecorKeyTCTScore
The read key for adding TCT score as decoration to TrackParticle objects.
Definition: TCTDecorCheckInTool.h:65
TCTDecorCheckInTool.h
TCTDecorCheckInTool::m_particlesKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_particlesKey
Definition: TCTDecorCheckInTool.h:60
TCTDecorCheckInTool::m_decoratorMethod
std::string m_decoratorMethod
Definition: TCTDecorCheckInTool.h:76
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:92
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:56
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:70
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:195
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:73
TCTDecorCheckInTool::~TCTDecorCheckInTool
virtual ~TCTDecorCheckInTool()
Definition: TCTDecorCheckInTool.cxx:30
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
TCTDecorCheckInTool::execute
virtual StatusCode execute() override
Definition: TCTDecorCheckInTool.cxx:76
TCTDecorCheckInTool::m_jetsKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetsKey
Definition: TCTDecorCheckInTool.h:59
TCTDecorCheckInTool::m_jetCollection
std::string m_jetCollection
Definition: TCTDecorCheckInTool.h:77
TCTDecorCheckInTool::m_verticesKey
SG::ReadHandleKey< xAOD::VertexContainer > m_verticesKey
Definition: TCTDecorCheckInTool.h:61
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.