ATLAS Offline Software
JetCnvTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "xAODJet/JetContainer.h"
9 
10 
11 #include "JetCnvTool.h"
12 
13 namespace xAODMaker {
14 
15 
16  JetCnvTool::JetCnvTool( const std::string& type,
17  const std::string& name,
18  const IInterface* parent )
19  : AthAlgTool( type, name, parent ) {
20 
21  // Declare the interface(s) provided by the tool:
22  declareInterface< IJetCnvTool >( this );
23  }
24 
35  xAOD::JetContainer* xaodCont,
36  DataLink<xAOD::IParticleContainer> xaodConstitCont,
37  bool constitSearch) const
38  {
39 
40 
43 
44  std::vector< std::string > momentKeys ;
45 
46  if( it != itE ) {
47  momentKeys= (*it)->getMomentKeys();
48 
49  if( xaodConstitCont.isDefault() &&
50  (*it)->begin() != (*it)->end() )
51  {
52  // try to retrieve its name from SG and the original jet
53 
54  // this doesn't work : getConstituents() is protected
55  // std::string key = (*it)->navigableBase().getConstituents()[0].key();
56  // StatusCode sc = evtStore()->retrieve(xaodConstitCont, key);
57  // if(sc.isFailure() ) ATH_MSG_DEBUG("Could not retrieve xaod constiuents with key "<< key );
58 
59  SG::DataProxy* proxy = evtStore()->proxy( (*it)->getContainer( (*it)->begin() ) );
60  if(proxy) {
61  xaodConstitCont.toIdentifiedObject (proxy->name());
62  if( !xaodConstitCont ) ATH_MSG_DEBUG("Could not retrieve xaod constiuents with key "<< proxy->name() );
63  }
64  }
65  }
66 
67 
68  for( ; it!= itE; ++it){
69  const Jet * jet = *it;
70  Jet::const_iterator cit = jet->begin();
71  Jet::const_iterator citE = jet->end();
72 
73  xAOD::Jet* xjet = new xAOD::Jet();
74  xaodCont->push_back( xjet );
75 
76  xjet->setJetP4( xAOD::JetFourMom_t(jet->pt(), jet->eta(), jet->phi(), jet->m() ) );
77 
78  // convert constituents if we have a valid xaod constituent container.
79  // If constitSearch is false, this assumes the ordering
80  // in aod and xaod containers are the same !
81  if(xaodConstitCont) {
82  for( ; cit!= citE; ++cit){
83  if (constitSearch) {
84  double min_dr2 = 0.1 * 0.1;
85  int iconstit = -1;
86  int ip = 0;
87  for (const xAOD::IParticle* p : *xaodConstitCont) {
88  double deta = p->eta() - (*cit)->eta();
89  double dphi = TVector2::Phi_mpi_pi (p->phi() - (*cit)->phi());
90  double dr2 = deta*deta + dphi*dphi;
91  if (dr2 < min_dr2) {
92  min_dr2 = dr2;
93  iconstit = ip;
94  }
95  ++ip;
96  }
97  if (iconstit >= 0)
98  xjet->addConstituent
99  (ElementLink<xAOD::IParticleContainer> (xaodConstitCont.key(), iconstit));
100  }
101  else {
102  size_t index;
103  if( jet->getIndex( cit , index) )
104  xjet->addConstituent
105  (ElementLink<xAOD::IParticleContainer> (xaodConstitCont.key(), index));
106  }
107  }
108  }
109 
110  for(size_t i=0;i<momentKeys.size(); i++){
111  xjet->setAttribute<float>( momentKeys[i], jet->getMoment( momentKeys[i]) );
112  }
113  ATH_MSG_DEBUG( "Converted " << jet << " into "<< xjet << " pt="<< xjet->pt()<< " numConst="<< xjet->numConstituents() );
114 
117  xjet->setJetP4( s, xAOD::JetFourMom_t( jet->pt(aod_s), jet->eta(aod_s) , jet->phi(aod_s), jet->m(aod_s) ) );
120  xjet->setJetP4( s, xAOD::JetFourMom_t( jet->pt(aod_s), jet->eta(aod_s) , jet->phi(aod_s), jet->m(aod_s) ) );
121 
122  P4SignalState::State aod_constit_s = jet->constituentSignalState() ;
123  xjet->setConstituentsSignalState( (xAOD::JetConstitScale) aod_constit_s );
124 
125  // // Track assoc if any :
126  // const Analysis::TrackAssociation * trackA = jet-> getAssociation<Analysis::TrackAssociation>("TrackAssoc");
127  // if (trackA) {
128  // Analysis::TrackAssociation::object_iter trk_it = trackA->begin();
129  // Analysis::TrackAssociation::object_iter trk_itE= trackA->end();
130  // size_t trk_index;
131  // for( ; trk_it != trk_itE ; ++trk_it){
132  // if( trackA->getIndex( trk_it, trk_index) )
133  // if( (*it)->pt() > m_trackMinPt && (m_jetvtxtrkHelper->trackInfo(*it).selected() ) )
134  // preSelTracks.push_back(*it);
135 
136  }
137 
138  return StatusCode::SUCCESS;
139  }
140 
141 
142 }
143 
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
Jet
Basic data class defines behavior for all Jet objects The Jet class is the principal data class for...
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:47
index
Definition: index.py:1
skel.it
it
Definition: skel.GENtoEVGEN.py:396
P4SignalState::JETEMSCALE
@ JETEMSCALE
Definition: ISignalState.h:33
xAODMaker
Definition: StoreGateSvc.h:72
xAODMaker::JetCnvTool::JetCnvTool
JetCnvTool(const std::string &type, const std::string &name, const IInterface *parent)
Regular AlgTool constructor.
Definition: JetCnvTool.cxx:16
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
Phi_mpi_pi
__HOSTDEV__ double Phi_mpi_pi(double)
Definition: GeoRegion.cxx:7
TruthTest.itE
itE
Definition: TruthTest.py:25
xAOD::Jet_v1::setJetP4
void setJetP4(const JetFourMom_t &p4)
Definition: Jet_v1.cxx:171
Jet::const_iterator
navigable_t::object_iter const_iterator
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:108
xAOD::JetConstitScaleMomentum
@ JetConstitScaleMomentum
Definition: JetTypes.h:29
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
P4SignalState::JETCONSTITUENTSCALE
@ JETCONSTITUENTSCALE
Definition: ISignalState.h:35
lumiFormat.i
int i
Definition: lumiFormat.py:85
JetCollection.h
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
xAOD::Jet_v1::setConstituentsSignalState
void setConstituentsSignalState(JetConstitScale t)
Set the state at which constituents were when this jet was found. This function is called by jet buil...
Definition: Jet_v1.cxx:141
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAOD::JetScale
JetScale
Definition: JetTypes.h:26
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
xAOD::Jet_v1::addConstituent
void addConstituent(const ElementLink< IParticleContainer > &link, float weight=1.0)
Add a constituent directly in the ElementLink format.
Definition: Jet_v1.cxx:111
xAOD::Jet_v1::setAttribute
void setAttribute(const std::string &name, const T &v)
xAOD::JetEMScaleMomentum
@ JetEMScaleMomentum
Definition: JetTypes.h:28
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
DataLinkBase::isDefault
bool isDefault() const
Test to see if we're in the default state.
Definition: DataLinkBase.cxx:31
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
xAOD::JetConstitScale
JetConstitScale
Definition: JetTypes.h:20
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
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
DeMoScan.index
string index
Definition: DeMoScan.py:364
JetContainer.h
JetCollection
Container for Jets
Definition: JetCollection.h:30
P4SignalState::State
State
Definition: ISignalState.h:28
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
JetAuxContainer.h
xAODMaker::JetCnvTool::convert
virtual StatusCode convert(const JetCollection *aodCont, xAOD::JetContainer *xaodCont, DataLink< xAOD::IParticleContainer > xaodConstitCont=DataLink< xAOD::IParticleContainer >(), bool constitSearch=false) const override
Function that fills an existing xAOD::MuonRoIContainer.
Definition: JetCnvTool.cxx:34
AthAlgTool
Definition: AthAlgTool.h:26
xAOD::Jet_v1::numConstituents
size_t numConstituents() const
Number of constituents in this jets (this is valid even when reading a file where the constituents ha...
Definition: Jet_v1.cxx:153
SG::DataProxy
Definition: DataProxy.h:45
xAOD::Jet_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
Definition: Jet_v1.cxx:44
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition: Event/xAOD/xAODJet/xAODJet/Jet.h:17
JetCnvTool.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.